Screen Fields with Dictionary Reference

Một phần của tài liệu BC ABAP Programming PHẦN 4 pptx (Trang 81 - 86)

If your input/output fields are required in more than one program, and you want to use

information from the ABAP Dictionary, such as field labels, field help, and input help, you should copy [Extern] fields from the ABAP Dictionary. You can refer to both structures and database tables.

You must then declare identically-named fields as an interface work area in the ABAP program using the TABLES statement. Declaring an identically-named field using a TYPES reference to the data type in the ABAP Dictionary is insufficient for data to be transferred between the screen and the ABAP program.

To avoid naming conflicts between screen fields, work areas in programs, and database tables, it is often worth defining your own ABAP Dictionary structure for screens, containing all of the input/output fields you want to use for one or more screens of a program, or even for a whole development class. The work areas that you declare with TABLES in the ABAP program then function exclusively as an interface between the program and the screen. If necessary, you can assign values between program fields and the interface work area.

The advantage of referring to ABAP Dictionary data types is that both the screen fields and the fields in the ABAP program are updated automatically if the data type changes.

Local program fields

PROGRAM DEMO_DYNPRO_INPUT_OUTPUT.

Processing Input/Output Fields

December 1999 543

DATA: INPUT TYPE I, OUTPUT TYPE I,

RADIO1, RADIO2, RADIO3, BOX1, BOX2, BOX3, EXIT.

CALL SCREEN 100.

MODULE INIT_SCREEN_100 OUTPUT.

CLEAR INPUT.

RADIO1 = 'X'.

CLEAR: RADIO2, RADIO3.

ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.

OUTPUT = INPUT.

BOX1 = RADIO1.

BOX2 = RADIO2.

BOX3 = RADIO3.

IF EXIT NE SPACE.

LEAVE PROGRAM.

ENDIF.

ENDMODULE.

The next screen (statically defined) for screen 100 is itself. It has the following layout:

Radio button 1 Checkbox 1 Radio button 2 Checkbox 2 Radio button 3 Checkbox 3 Cancel

0

The part of the element list relevant for the screen fields is as follows:

Name Type defLg Format

INPUT I/O 9 INT4

OUTPUT I/O 11 INT4

RADIO1 Radio 1 CHAR

BOX1 Check 1 CHAR

RADIO2 Radio 1 CHAR

BOX2 Check 1 CHAR

Processing Input/Output Fields

RADIO3 Radio 1 CHAR

BOX3 Check 1 CHAR

EXIT Check 1 CHAR

OK 20 OK

The screen fields OUTPUT, BOX1, BOX2, and BOX3 cannot accept user input.

The length of INPUT is such that the user can enter a nine-digit integer without thousand separators. However, the display in the OUTPUT field contains up to two thousand separators. Had we left the length of INPUT at 11 digits, a runtime error could have occurred.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

MODULE INIT_SCREEN_100.

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

The entries in the input fields are passed to the ABAP program in the PAI event, and assigned to the output fields in the dialog module USER_COMMAND_100. The next time the screen appears, the screen fields have been filled appropriately. The input fields are set in the PBO dialog module INT_SCREEN_100. If the user selects the screen field EXIT (value ‘X’), the program ends.

Screen fields with Dictionary reference PROGRAM DEMO_DYNPRO_DICTIONARY.

TABLES SDYN_CONN.

DATA WA_SPFLI TYPE SPFLI.

CALL SCREEN 100.

MODULE INIT_SCREEN_100 OUTPUT.

CLEAR SDYN_CONN-MARK.

MOVE-CORRESPONDING WA_SPFLI TO SDYN_CONN.

CLEAR WA_SPFLI.

ENDMODULE.

MODULE USER_COMMAND_0100 INPUT.

IF SDYN_CONN-MARK = 'X'.

LEAVE PROGRAM.

ENDIF.

MOVE-CORRESPONDING SDYN_CONN TO WA_SPFLI.

SELECT SINGLE

CITYFROM AIRPFROM CITYTO AIRPTO FLTIME DEPTIME ARRTIME INTO CORRESPONDING FIELDS OF WA_SPFLI

FROM SPFLI

WHERE CARRID = WA_SPFLI-CARRID AND CONNID = WA_SPFLI-CONNID.

Processing Input/Output Fields

December 1999 545

ENDMODULE.

The statically-defined next screen for screen 100 is 100. It uses components of the structure SDYN_CONN, copied [Extern] from the ABAP Dictionary, and looks like this:

Cancel Airline

Flight number

From airport From

To airport To

Departure time

Duration 0:00

00:00:00 Arrival time 00:00:00

The structure SDYN_CONN exists in the ABAP Dictionary specially for screens that use the flight data model. It contains the components of the database table SPFLI, but also a component MARK. MARK uses the domain S_FLAG, which may only have the values SPACE and X. On the above screen, the ABAP Dictionary text for MARK has been overwritten with ‘Cancel’. For all other fields, the ABAP Dictionary texts have been retained. The input attribute of some of the fields has been switched off in the Screen Painter.

Users can enter values for the airline and flight number. Automatic field checks against check tables in the ABAP Dictionary, field help, and input help are

automatically available. The field checks are performed automatically before any of the dialog modules in the ABAP program are called. Users cannot enter values for the airline that do not exist in the check table SCARR, values for the flight number that are not in SPFLI, or values for MARK other than SPACE and X. There is no need to program any of these checks in the ABAP program.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

MODULE INIT_SCREEN_100.

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

Processing Input/Output Fields

The module USER_COMMAND_100 in the ABAP program reads data from the database table with the key fields specified (and checked) on the screen, and sends them back to the screen in the PBO module INIT_SCREEN_100. The work area SDYN_CONN, defined using the TABLES statement, serves as an interface between the program and the screen. Meanwhile the data from the database is processed in the work area WA_SPFLI. If the user selects the screen field ‘Cancel’ (value ‘X’), the program ends.

Một phần của tài liệu BC ABAP Programming PHẦN 4 pptx (Trang 81 - 86)

Tải bản đầy đủ (PDF)

(153 trang)