1. Trang chủ
  2. » Công Nghệ Thông Tin

BC ABAP Programming PHẦN 6 pot

153 343 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 153
Dung lượng 7,74 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Subscreens and Tabstrip Controls on Selection ScreensSubscreens and Tabstrip Controls on Selection Screens Some of the complex screen elements [Page 641] that you can create in the Scree

Trang 1

Processing Radio Buttons

Processing Radio Buttons

In the PAI event of the selection screen, the event

AT SELECTION-SCREEN ON RADIOBUTTON GROUP <radi>

is triggered when the contents of all of the fields in a radio button group are passed from theselection screen to the ABAP program To define a radio button group <radi>, use the additionRADIOBUTTON GROUP <radi> in the corresponding PARAMETERS statements This eventblock allows you to check the whole group If an error message occurs within this event block,the radio button group is made ready for input again on the selection screen The individualfields of radio button groups do not trigger the event AT SELECTION-SCREEN ON <field>

REPORT EVENT_DEMO.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.

PARAMETERS: R1 RADIOBUTTON GROUP RAD1 DEFAULT 'X',

R2 RADIOBUTTON GROUP RAD1, R3 RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.

PARAMETERS: R4 RADIOBUTTON GROUP RAD2 DEFAULT 'X',

R5 RADIOBUTTON GROUP RAD2, R6 RADIOBUTTON GROUP RAD2.

SELECTION-SCREEN END OF BLOCK B2.

AT SELECTION-SCREEN ON RADIOBUTTON GROUP RAD1.

W: This is the default setting!

R3

R4R5R6

Trang 2

Processing Radio Buttons

Trang 3

Processing Multiple Selections

Processing Multiple Selections

If the user opens the Multiple selections dialog box for a selection option, the same events are

triggered in the PAI of the selection screen as if the user had chosen Execute The user can then enter the required multiple selections In the Multiple selections dialog box, user actions either

lead to input help or trigger the PAI event of the dialog box At first, the

AT SELECTION-SCREEN ON <seltab>

event is triggered for the current line of the selection table It can then be processed like a singlefield [Page 765]

Next, the

AT SELECTION-SCREEN ON END OF <seltab>

event is triggered This event block allows you to check the whole selection table <seltab>.Warning messages are displayed as dialog boxes, not in the status line

The program below is connected to the logical database F1S:

Trang 4

Processing Multiple Selections

Multiple Selection for SEL_OPT1

Single vals Intervals Single vals Intervals

X

ToToToToTo

Trang 5

Defining Field Help

Defining Field Help

If the data type of an input field declared in an executable program is defined in the ABAP

Dictionary, the documentation of the underlying data element is automatically displayed if theuser positions the cursor in that field and presses F1 To create help for input fields that have noDictionary reference, or to override the help normally linked to the field, you can create an eventblock for the event

AT SELECTION-SCREEN ON HELP-REQUEST FOR <field>

The event is triggered when the user calls the F1 help for the field <field> If no correspondingevent block has been defined, the help from the ABAP Dictionary is displayed, or none at all if thefield has no Dictionary reference If a corresponding event block exists, it takes precedence overthe default help mechanism It is then up to the programmer to ensure that appropriate help isdisplayed

You cannot declare the event block AT SELECTION-SCREEN ON HELP-REQUEST for inputfields on the selection screen that are declared within a logical database You cannot overridethe help mechanism of a logical database within the program You can define separate helpwithin the logical database program using the HELP-REQUEST option in the PARAMETERS andSELECT-OPTIONS statements

REPORT SELECTION_SCREEN_F1_DEMO.

PARAMETERS: P_CARR_1 TYPE S_CARR_ID,

P_CARR_2 TYPE S_CARR_ID.

AT SELECTION-SCREEN ON HELP-REQUEST FOR P_CARR_2.

CALL SCREEN 100 STARTING AT 10 5

ENDING AT 60 10.

This program declares a selection screen with two parameters that both refer to thedata element S_CARR_ID in the ABAP Dictionary The documentation from theABAP Dictionary is used for P_CARR_1, and a help screen 100 is called for

P_CARR_2 The help screen is defined in the Screen Painter as a modal dialog boxwith next screen 0 It contains the help text defined as help texts The screen doesnot require any flow logic

Trang 6

Defining Field Help

P_CARR_1P_CARR_2

Airline code This field contains the code of the airline

The field contains the code of an airline that collaborates with other airlines

ABAP-

Dictionary

Trang 7

Defining Input Help

Defining Input Help

Suchhilfe für Parameter [Page 709]

If a field in an executable program is defined with reference to an ABAP Dictionary field for whichpossible entries help is defined, the values from the ABAP Dictionary help are automaticallydisplayed when the user calls the F4 help for that field To create possible values help for inputfields that have no Dictionary reference, or to override the help normally linked to the field, youcan create an event block for the event

AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field>

The event is triggered when the user calls the F4 help for the field <field> If no correspondingevent block has been defined, the possible values help from the ABAP Dictionary is displayed, ornone at all if the field has no Dictionary reference If a corresponding event block exists, it takesprecedence over the default possible values help mechanism It is then up to the programmer toensure that an appropriate list of values is displayed, and that the user can choose a value fromit

You cannot declare the event block AT SELECTION-SCREEN ON VALUE-REQUEST for inputfields on the selection screen that are declared within a logical database You cannot overridethe possible values help mechanism of a logical database within the program You can defineseparate help within the logical database program using the VALUE-REQUEST option in thePARAMETERS and SELECT-OPTIONS statements

REPORT SELECTION_SCREEN_F4_DEMO.

PARAMETERS: P_CARR_1 TYPE SPFLI-CARRID,

P_CARR_2 TYPE SPFLI-CARRID.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_CARR_2.

CALL SCREEN 100 STARTING AT 10 5

ENDING AT 50 10.

MODULE VALUE_LIST OUTPUT.

SUPPRESS DIALOG.

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.

SET PF-STATUS SPACE.

Trang 8

Defining Input Help P_CARR_2 = 'THA'.

4 WRITE: / P_CARR_2 COLOR COL_KEY, 'Thai International'.

PROCESS BEFORE OUTPUT.

MODULE VALUE_LIST.

PROCESS AFTER INPUT.

The dialog module VALUE_LIST suppresses the dialog of screen 100 and switches

to list processing The list contains values for the parameter P_CARR_2 Thesevalues are also placed in the HIDE area When the user selects a line from the valuelist, the AT LINE-SELECTION event is triggered, and the selected value is

transferred from the HIDE area into the field P_CARR_2 If the user selects a validline, the system switches directly from the event block AT LINE-SELECTION back tothe selection screen, and fills the corresponding input field

Trang 9

Defining Input Help

P_CARR_1P_CARR_2

Airline code

ABAP

Dictionary

AAACAFAZBABLCO

American AirlinesAir CanadaAir FranceAlitaliaBritish Airways

Pacific AirlinesContinental Arlines

Star Alliance

ACLHSASTHAUA

Air CanadaLufthansaSASThai InternationalUnited Airlines

User-Defined Value Help

Trang 10

Subscreens and Tabstrip Controls on Selection Screens

Subscreens and Tabstrip Controls on Selection Screens

Some of the complex screen elements [Page 641] that you can create in the Screen Painter forscreens can also be defined in ABAP programs for selection screens For example, you can nowuse tabstrip controls on selection screens Since you need subscreens to work with tabstripcontrols, you can also now define selection screens as subscreens

Selection Screens as Subscreens [Page 778]

Tabstrip Controls on Selection Screens [Page 783]

Subscreens on Selection Screens [Page 787]

Trang 11

Selection Screens as Subscreens

Selection Screens as Subscreens

In the same way that you can define a screen as a subscreen [Page 653] in the Screen Painter, it

is now possible to define selection screens as subscreens in an ABAP program:

SELECTION-SCREEN BEGIN OF SCREEN <scrn> AS SUBSCREEN

[NO INTERVALS]

[NESTING LEVEL <n>]

SELECTION-SCREEN END OF SCREEN <scrn>

Selection screens that you define in this way can be included in:

• Subscreens [Page 653] on screens

• Tabstrip Controls [Page 660] on screens

• Tabstrip Controls on Selection Screens [Page 783]

You cannot call them using CALL SELECTION-SCREEN.

If you use the NO INTERVALS addition, the subscreen is made smaller and the selection criteriaare all displayed with single input fields

The NESTING LEVEL also reduces the size of the subscreen You can use it to prevent

scrollbars from appearing when you use the subscreen in a tabstrip control on the selectionscreen and the tabstrip already has a frame If there is no frame around the tabstrip control, useNESTING LEVEL 0 For each frame around the tabstrip control, increase NESTING LEVEL byone

When you include a selection screen as a subscreen on a screen or in a tabstrip control on ascreen, you should remember that the CALL SUBSCREEN statement is executed in both thePBO and PAI events in the screen flow logic Although you cannot program PAI modules forselection screens as subscreens, the CALL SUBSCREEN statement ensures that the input data

is transferred to the ABAP program in the PAI event

As on normal selection screens, the usual permitted user actions [Page 752] trigger the usualselection screen processing [Page 759] This allows you to check user input or process functioncodes

Examples

Selection screens as subscreens on screens

REPORT demo_sel_screen_as_subscreen.

SELECTION-SCREEN BEGIN OF SCREEN 1100 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010 PARAMETERS: p1(10) TYPE c,

p2(10) TYPE c, p3(10) TYPE c.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 1100.

SELECTION-SCREEN BEGIN OF SCREEN 1200 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.

Trang 12

Selection Screens as Subscreens PARAMETERS: q1(10) TYPE c OBLIGATORY,

q2(10) TYPE c OBLIGATORY, q3(10) TYPE c OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF SCREEN 1200.

DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm.

DATA: number(4) TYPE n VALUE '1100'.

START-OF-SELECTION.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

MESSAGE s888(sabapdocu) WITH text-030 sy-dynnr.

This defines two selection screens – 1100 and 1200 – as subscreens

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

Trang 13

Selection Screens as Subscreens

Subscreen 1 Subscreen 2

The screen contains a subscreen area AREA and two pushbuttons with the functioncodes BUTTON1 and BUTTON2

The screen flow logic for screen 100 is as follows:

PROCESS BEFORE OUTPUT.

MODULE status_0100.

CALL SUBSCREEN area INCLUDING sy-repid number.

PROCESS AFTER INPUT.

MODULE cancel AT EXIT-COMMAND.

CALL SUBSCREEN area.

MODULE user_command_0100.

When you run the program, a screen appears on which selection screen 1100 isdisplayed as a subscreen You can display either selection screen in the subscreenarea, using the pushbuttons to switch between them Before you switch from

selection screen 1200 to 1100, you must fill out the obligatory fields The data youenter is available to the program in the parameters in the PAI event

Selection screens as subscreens in a tabstrip control on a screen

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 1100.

Trang 14

Selection Screens as Subscreens SELECTION-SCREEN BEGIN OF SCREEN 1200 AS SUBSCREEN

NO INTERVALS.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020 PARAMETERS: q1(10) TYPE c OBLIGATORY,

q2(10) TYPE c OBLIGATORY, q3(10) TYPE c OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF SCREEN 1200.

CONTROLS mytabstrip TYPE TABSTRIP.

DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm.

DATA: number(4) TYPE n VALUE '1100'.

START-OF-SELECTION.

mytabstrip-activetab = 'BUTTON1'.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

MESSAGE s888(sabapdocu) WITH text-030 sy-dynnr.

This defines two selection screens – 1100 and 1200 – as subscreens

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

Trang 15

Selection Screens as Subscreens

Tab title 1 Tab title 2

The screen contains a tabstrip area called MYTABSTRIP with three tab titles

BUTTON1, BUTTON2 and BUTTON3 The function codes have the same name, and

no special function type All of the tab titles are assigned to a single subscreen areaAREA

The screen flow logic for screen 100 is as follows:

PROCESS BEFORE OUTPUT.

MODULE status_0100.

CALL SUBSCREEN area INCLUDING sy-repid number.

PROCESS AFTER INPUT.

MODULE cancel AT EXIT-COMMAND.

CALL SUBSCREEN area.

MODULE user_command_0100.

This example is programmed in almost exactly the same way as the last one, andbehaves in the same way The only difference is that the pushbuttons have beenreplaced with tab titles, and the control MYTABSTRIP has been declared and filled.Scrolling between the tab pages is programmed in the ABAP program Each timethe user chooses a tab title, the function code from the OK_CODE field is assigned

to the ACTIVETAB component of structure MYTABSTRIP At the same time, thevariable NUMBER is filled with the screen number of the subscreen that has to bedisplayed in the subscreen area AREA of the tabstrip control

Trang 16

Tabstrip Controls on Selection Screens

Tabstrip Controls on Selection Screens

As with screens, you can now use tabstrip controls [Page 660] on selection screens To do this,you must define a tabstrip area and the associated tab pages, and assign a subscreen to the tabpages You do not have to (indeed, cannot) declare the tabstrip control or program the screenflow logic in your ABAP program, since both are automatically generated

To define a tabstrip area with tab pages, use the following statements in your selection screendefinition:

SELECTION-SCREEN: BEGIN OF TABBED BLOCK <tab_area> FOR <n> LINES,

TAB (<len>) <tab1> USER-COMMAND <ucom1>

[DEFAULT [PROGRAM <prog>] SCREEN <scrn>],

TAB (<len>) <tab2> USER-COMMAND <ucom2>

[DEFAULT [PROGRAM <prog>] SCREEN <scrn>],

END OF BLOCK <tab_area>

This defines a tabstrip control <tab_area> with size <n> The tab pages <tab1>, <tab2>… areassigned to the tab area <len> defines the width of the tab title You must assign a functioncode <ucom> area to each tab title You can find out the function code from the field SY-UCOMM

in the AT SELECTION-SCREEN event

For each tab title, the system automatically creates a character field in the ABAP program withthe same name Before the selection screen is displayed, you can assign a text to the field Thisthen appears as the title of the corresponding tab page on the selection screen

You must assign a subscreen to each tab title This will be displayed in the tab area when theuser chooses that title You can assign one of the following as a subscreen:

• A subscreen screen [Page 653] defined using the Screen Painter

• A selection screen subscreen [Page 778], defined in an ABAP program

You can make the assignment either statically in the program or dynamically at runtime If, atruntime, one of the tab titles has no subscreen assigned, a runtime error occurs

• Static assignment

Use the DEFAULT addition when you define the tab title You can specify an ABAPprogram and one of its subscreens If you do not specify a program, the system looks forthe subscreen in the current program When the user chooses the tab title, it is

activated, and the subscreen is assigned to the tabstrip area The static assignment isvalid for the entire duration of the program, but can be overwritten dynamically before theselection screen is displayed

• Dynamic assignment

For each tab area, the system automatically creates a structure in the ABAP programwith the same name This structure has three components – PROG, DYNNR, andACTIVETAB When you assign the subscreens statically, the structure contains thename of the ABAP program containing the subscreen, the number of the subscreen, andthe name of the tab title currently active on the selection screen (and to which thesevalues are assigned) The default active tab page is the first page You can assignvalues to the fields of the structure before the selection screen is displayed, and so set asubscreen dynamically

Trang 17

Tabstrip Controls on Selection Screens

If you assign a normal subscreen screen to a tab title, the dialog modules containing its flow logicmust be defined in the current ABAP program If the subscreen is a selection screen, useractions will trigger the AT SELECTION-SCREEN event and its variants (see Selection ScreenProcessing [Page 759]) This includes when the user chooses a tab title If one selection screen

is included on another, AT SELECTION-SCREEN will be triggered at least twice – firstly for the

“included” selection screen, then for the selection screen on which it appears

REPORT demo_sel_screen_with_tabstrip.

DATA flag(1) TYPE c.

* SUBSCREEN 1

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

PARAMETERS: p1(10) TYPE c,

p2(10) TYPE c, p3(10) TYPE c.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.

PARAMETERS: q1(10) TYPE c OBLIGATORY,

q2(10) TYPE c OBLIGATORY, q3(10) TYPE c OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF SCREEN 200.

* STANDARD SELECTION SCREEN

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,

TAB (20) button1 USER-COMMAND push1, TAB (20) button2 USER-COMMAND push2, TAB (20) button3 USER-COMMAND push3

DEFAULT SCREEN 300, END OF BLOCK mytab.

Trang 18

Tabstrip Controls on Selection Screens mytab-dynnr = 200.

MODULE user_command_0100 INPUT.

MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.

This program defines two selection screens – 100 and 200, as subscreens, andplaces a tabstrip control area with three tab pages on the standard selection screen

A subscreen screen 300 (from the same program) is assigned statically to the thirdtab page

The layout of screen 300 is:

Trang 19

Tabstrip Controls on Selection Screens

The screen flow logic for screen 300 is as follows:

PROCESS BEFORE OUTPUT.

MODULE init_0100.

PROCESS AFTER INPUT.

MODULE user_command_0100.

Both dialog modules are defined in the ABAP program

When you run the program, the standard selection screen appears In the

INITIALIZATION event, the texts are defined on the tab titles, the subscreen

selection screen 100 is assigned to the tab area, and the first tab title is activated.User actions on the selection screen are processed in the AT SELECTION-SCREENevent block In particular, it is here that the subscreens are assigned and tab titlesactivated when the user chooses one of the first two tab titles This is not necessaryfor the third tab title, since the dynamic assignment (screen 300) is always placed inthe structure MYTAB when the user chooses it

Before the subscreen screen is displayed, the PBO module INIT_100 is executed.User actions on the subscreen screen trigger the PAI module This includes whenthe user chooses a tab title After that, the AT SELECTION-SCREEN event istriggered

Messages in the status line show where an action has been processed

Trang 20

Subscreens on Selection Screens

Subscreens on Selection Screens

Displaying a subscreen in a subscreen area on a selection screen is a special case of a tabstripcontrol on a selection screen [Page 783] To define a subscreen area on a selection screen, usethese statements:

SELECTION-SCREEN: BEGIN OF TABBED BLOCK <sub_area> FOR <n> LINES,

END OF BLOCK <sub_area>

Defining a subscreen area is the equivalent of defining a tabstrip area without tab titles Beforethe selection screen is displayed, you must assign a subscreen to the subscreen area

<sub_area> To do this, use the components PROG and DYNNR of the structure <sub_area>,which is created automatically when you define the subscreen area Assign the program name

of the subscreen screen to the component PROG, and its screen number to DYNNR You canuse the following subscreens:

• A subscreen screen [Page 653] defined using the Screen Painter

• A selection screen subscreen [Page 778], defined in an ABAP program

If you have not assigned a subscreen when the selection screen is displayed, a runtime erroroccurs

REPORT demo_sel_screen_with_subscreen.

TABLES sscrfields.

* SUBSCREEN 1

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010 PARAMETERS: p1(10) TYPE c,

p2(10) TYPE c, p3(10) TYPE c.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-020 PARAMETERS: q1(10) TYPE c,

q2(10) TYPE c, q3(10) TYPE c.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF SCREEN 200.

* SUBSCREEN 3

SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-030 PARAMETERS: r1(10) TYPE c,

r2(10) TYPE c, r3(10) TYPE c.

SELECTION-SCREEN END OF BLOCK b3.

Trang 21

Subscreens on Selection Screens

* STANDARD SELECTION SCREEN

SELECTION-SCREEN: FUNCTION KEY 1,

FUNCTION KEY 2.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK sub FOR 10 LINES,

END OF BLOCK sub.

This program defines three subscreen selection screens, 100, 200, and 300 It alsodefines a subscreen area SUB on the standard selection screen There are twopushbuttons in the application toolbar

In the INITIALIZATION event, the subscreen selection screen 100 is assigned to thesubscreen area In the AT SELECTION-SCREEN event, the function keys areprocessed, and one of the other subscreens is assigned according to the user’schoice

Trang 22

Using Selection Criteria

Using Selection Criteria

When you define selection criteria, selection tables of the same name are declared in the

program The selections that the user specifies on the selection screen are stored in the rows ofthese tables in a standardized format So that the program must not explicitly process the

structure of the selection tables [Page 719] and their contents, selection tables can be addressed

as a whole in certain ABAP statements In these statements, complex selections are analyzed in

a selection table The programmer does not have to deal with their logic

Selection Tables in the WHERE Clause [Page 790]

Selection Tables in Logical Expressions [Page 791]

Selection Tables in GET Events [Page 794]

Trang 23

Selection Tables in the WHERE Clause

Selection Tables in the WHERE Clause

The WHERE clause is an addition to Open SQL statements SELECT, UPDATE, and DELETE,and is used to restrict the values read during database accesses [Page 1078]

To use a selection table in the WHERE clause, you write:

WHERE <f> IN <seltab>

<f> is the name of a database column, and <seltab> is the selection table that is assigned to thisfield The relevant Open SQL statement accesses only those rows of the database table, wherethe contents of field <f> meet the selection criteria stored in <seltab>

REPORT DEMO.

DATA WA_CARRID TYPE SPFLI-CARRID.

SELECT-OPTIONS AIRLINE FOR WA_CARRID.

SELECT CARRID FROM SPFLI INTO WA_CARRID WHERE CARRID IN

If the selection table is filled as follows:

SIGN OPTION LOW HIGH

Then the database rows for all airlines between DL and UA except LH are read

Trang 24

Selection Tables in Logical Expressions

Selection Tables in Logical Expressions

To check if the value of a field meets the conditions in a selection table, you can use the followingspecial logical expression [Page 226]:

DATA WA_CARRID TYPE SPFLI-CARRID.

SELECT-OPTIONS AIRLINE FOR WA_CARRID.

WRITE: 'Inside', 'Outside'.

SELECT CARRID FROM SPFLI INTO WA_CARRID.

If the selection table is filled as follows:

SIGN OPTION LOW HIGH

The list output appears as follows:

Trang 25

Selection Tables in Logical Expressions

Selection tables in logical expressions 1Inside Outside

AA

AA AA AZ AZ AZ

AZ AZDL

DL

LH LH LH LH

In the SELECT loop, all rows are read from database table SPFLI If the IF statement

is used, the program flow is branched into two statement blocks depending on thelogical expression The shortened form IF AIRLINE is also possible in this program

REPORT DEMO.

DATA WA_SPFLI TYPE SPFLI.

SELECT-OPTIONS: S_CARRID FOR WA_SPFLI-CARRID,

S_CITYFR FOR WA_SPFLI-CITYFROM, S_CITYTO FOR WA_SPFLI-CITYTO, S_CONNID FOR WA_SPFLI-CONNID.

SELECT * FROM SPFLI INTO WA_SPFLI.

CHECK: S_CARRID,

S_CITYFR, S_CITYTO, S_CONNID.

WRITE: / WA_SPFLI-CARRID, WA_SPFLI-CONNID,

WA_SPFLI-CITYFROM, WA_SPFLI-CITYTO.

ENDSELECT.

After starting the program, the selection screen appears, on which the user might fillthe input fields as follows:

Trang 26

Selection Tables in Logical Expressions

The list then appears as follows:

Selection tables in logical expressions

LH 0400 FRANKFURT NEW YORK

LH 0402 FRANKFURT NEW YORK

shortened forms of the logical expressions The long forms are:

CHECK: WA_SPFLI-CARRID IN S_CARRID,

WA_SPFLI-CITYFR IN S_CITYFR, WA_SPFLI-CITYTO IN S_CITYTO, SPFLI-CONNID IN S_CONNID.

Trang 27

Selection Tables in GET Events

Selection Tables in GET Events

When database tables are read using logical databases, you can use a special variant of theCHECK statement in the event blocks for GET [Page 999] events

CHECK SELECT-OPTIONS

The statement checks if the contents of the interface work area [Page 131] that has been filled bythe logical database for the current GET event, meets the conditions in all selection tables that

are linked to the database table read

This variant of the CHECK statement only works in conjunction with selection criteria that arelinked to database tables, and should only be used for GET events

Since the CHECK statement cannot be used until after a row has been read by the logical

database, you should use this variant only if the selections provided by the logical database arenot sufficient to meet your requirements, and the relevant table is not designated for dynamicselections

The following program is linked to logical database F1S

REPORT DEMO.

NODES: SPFLI,SFLIGHT.

SELECT-OPTIONS: MAX FOR SFLIGHT-SEATSMAX,

OCC FOR SFLIGHT-SEATSOCC.

GET SFLIGHT.

WRITE: / SPFLI-CARRID, SPFLI-CONNID.

CHECK SELECT-OPTIONS.

WRITE: SFLIGHT-SEATSMAX, SFLIGHT-SEATSOCC.

After the program has been started, the selection screen appears, on which the usermight fill the input fields as follows:

Trang 28

Selection Tables in GET Events

Airline carrierDep airportDest airport

toConnections

The list output appears as follows:

CHECK in GET events

of SEATSMAX and SEATSOCC onto the screen

Trang 29

Selection Tables in GET Events

Trang 30

Lists

Selection screens are one of the three types of screen in the R/3 System, along with dialogscreens and lists They are used to display data, and also allow user interaction You create lists

using ABAP statements They can be output to the screen, but also to a printer

Unlike screens, which contain defined elements like input/output fields and pushbuttons, each ofwhich is identified by a name, and where data is exchanged with the ABAP program by means ofidentically-named fields, lists provide a freely-definable area that you fill using the WRITE,ULINE; and SKIP statements

Creating and Displaying Lists

The ABAP statements that create lists actually create the list on the application server, where it isbuffered The list is then displayed either when the LEAVE TO LIST-PROCESSING statementoccurs in the program, or, for executable programs, automatically In executable programs, the

list that you create is displayed (at the latest) after the last event block in the program

When the list is displayed, the system calls the list processor, which displays the list on a specialcontainer screen (number 120) The container screen temporarily replaces the previous screen ofthe calling program It inherits the same position, size, and GUI status However, you can set aspecial GUI status for list processing before the list is displayed In an executable program, thecontainer screen replaces the standard selection screen (screen 1000), and automatically hasthe default list status

User Actions and Detail Lists

When a list is displayed, the list processor has control of the program Interactive user actions on

a list trigger events in the ABAP program Output statements in these event blocks create detaillists, which are then automatically displayed at the end of the event block You can create up to

19 detail lists for a single basic list Detail lists temporarily replace the previous list on the

container screen A basic list and its detail lists form a list system of up to twenty levels Userscan navigate between the different levels

Trang 31

List system

Screen

Lists and Screens

From a screen, you can call the list processor and display up to twenty lists in a list system usingthe LEAVE TO LIST-PROCESSING statement When you start processing a screen, the listsystem is always initialized This means that all list output statements apply to the basic list, andthere are not yet any detail lists If you start a new screen sequence [Page 1041] during listprocessing (CALL SCREEN statement), the list system of the original screen is retained At theend of the screen sequence, the program returns to the last list level to have been displayed

Creating Lists [Page 799]

User Actions and Detail Lists [Page 891]

Lists and Screens [Page 933]

Printing Lists [Page 942]

Trang 32

Creating Lists

Creating Lists

The following sections describe how to create lists in ABAP Lists are always displayed using theautomatic list display functions in executable programs

Creating Simple Lists with the WRITE Statement [Page 800]

Creating Complex Lists [Page 817]

Trang 33

Creating Simple Lists with the WRITE Statement

Creating Simple Lists with the WRITE Statement

This section describes how to create simple output lists on the screen To do this, you use ABAPstatements WRITE, ULINE and SKIP

This section includes the following topics:

The WRITE Statement [Page 801]

Positioning WRITE Output on the Screen [Page 804]

Formatting Options [Page 806]

Displaying Symbols and Icons on the Screen [Page 809]

Lines and Blank Lines on the Output Screen [Page 810]

Displaying Field Contents as Checkboxes [Page 812]

Using WRITE via a Statement Structure [Page 813]

When you run executable programs (reports), the system automatically displays the list

generated by the program when program processing is completed When running a dialogprogram (module pool), you can send the list to the screen using the LEAVE TO LIST-

PROCESSING statement

ABAP allows you to generate more complex and effective output lists, both on the screen and onpaper, than that covered here The following sections are based on this introduction

Trang 34

The WRITE Statement

The WRITE Statement

The basic ABAP statement for displaying data on the screen is WRITE

Syntax

WRITE <f>.

This statement writes field <f> to the current list in its standard output format By default, the list

is displayed on the screen

Field <f> can be

• any data object (see Data Objects [Page 119])

• a field symbol or formal parameter (see Working with Field Symbols [Page 202])

• a text symbol (see Maintaining Text Elements [Extern])

You can print the current output list directly from the output screen by choosing Print.

If a selection screen is defined for the program (see Selection Screens [Page 691]),

you can choose Execute and print on the selection screen Then, the list is not

displayed on the screen, but sent directly to a printer

PROGRAM sapmztst.

WRITE 'Hello, here I am!'.

When you start this program, the system leaves the current screen (this may be the

ABAP Editor:Initial Screen) and branches to the output screen:

The name of the output screen is identical to the title of the program specified in theprogram attributes (see Maintaining Program Attributes [Page 75])

The first line on the screen contains the list header By default, the list header isidentical to the title of the program However, you can maintain the list header aloneoutside the actual program without affecting the program title For more information onthis topic, see Maintaining Text Elements [Extern] The current page number (1)appears on the right

A horizontal line is displayed, then the actual list begins

You can choose Search to search for specific patterns.

Trang 35

The WRITE Statement

On the screen, the output is normally left-justified If you use several WRITE statements, theoutput fields are displayed one after the other, each separated by one column (that is, oneblank) If there is not enough space for an output field in the current line, a new line is started

PROGRAM sapmtest.

TABLES spfli.

WRITE: 'COMPANY: ', spfli-carrid.

Note the use of the colon and the commas The example contains two WRITE

statements that are combined into a statement chain

In the above example, two fields, literal 'COMPANY: ' and component CARRID of tablework area SPFLI, are displayed on the screen

COMPANY: AA

The format of the data fields on the output screen depends on their data type (see PredefinedElementary Data Types [Page 97])

Output format of predefined data types

Data Type Output length Positioning

C field length left-justified

N field length left-justified

P 2 * field length (+1) right-justified

X 2 * field length left-justified

The numeric data types F, I, and P are right-justified and padded with blanks on the left If there

is sufficient space, thousands separators are also displayed If a type P field contains decimalplaces, the default output length is increased by one

With data type D, the internal format of a date differs from its output format When youuse the WRITE statement for displaying data, the system automatically converts dates

of type D based on the format specified in the user’s master record (for example,DD/MM/YYYY or MM/DD/YYYY)

PROGRAM sapmtest.

DATA number TYPE p VALUE '-1234567.89' DECIMALS 2.

WRITE: 'Number', number, 'is packed'.

The output appears as follows:

Number 1,234,567.89- is packed

Trang 36

The WRITE Statement

The field NUMBER has a total length of 13, made up of 9 digits, decimal point, minussign, and two thousand separators The output length of the NUMBER field is

2*8+1=17 because the field length of a type P field is 8 The remaining characters arefilled up with spaces This means that there are five blanks between the literal

'Number' and the number itself

Trang 37

Positioning WRITE Output on the List

Positioning WRITE Output on the List

You can position the output of a WRITE statement on the list by making a format specificationbefore the field name as follows:

Syntax

WRITE AT [/][<pos>][(<len>)] <f>.

where

• the slash '/' denotes a new line,

• <pos> is a number or variable up to three digits long denoting the position on the screen,

• <len> is a number or variable up to three digits long denoting the output length

If the format specification contains only direct values (that is, no variables), you can omit thekeyword AT

WRITE 'First line.'.

WRITE 'Still first line.'

WRITE / 'Second line.'

WRITE /13 'Third line.'

This generates the following output on the screen:

First Line Still first line

Second line

Third line

If you specify a certain position <pos>, the field is always placed in that position regardless ofwhether or not there is enough space available or whether other fields are overwritten

DATA: len TYPE i VALUE 10,

pos TYPE i VALUE 11, text(10) TYPE c VALUE '1234567890' WRITE 'The text - appears in the text.'.

WRITE AT pos(len) text.

This produces the following output:

The text -1234567890- appears in the text

If the output length <len> is too short, fewer characters are displayed Numeric fields are

truncated on the left and prefixed with an asterisk (*) All other fields are truncated on the right,but no indication is given that the field is shorter

DATA: number TYPE i VALUE 1234567890,

text(10) TYPE c VALUE 'abcdefghij'.

Trang 38

Positioning WRITE Output on the List WRITE: (5) number, /(5) text.

This produces the following output:

This produces the following output:

One

Two

The system suppresses lines that contain nothing but blanks

Trang 39

LEFT-JUSTIFIED Output is left-justified.

CENTERED Output is centered

RIGHT-JUSTIFIED Output is right-justified

UNDER <g> Output starts directly under field <g>

NO-GAP The blank after field <f> is omitted

USING EDIT MASK <m> Specifies format template <m>

USING NO EDIT MASK Deactivates a format template specified in the ABAP Dictionary.NO-ZERO If a field contains only zeros, these are replaced by blanks For type

C and N fields, leading zeros are replaced automatically

Formatting options for numeric fields

Option Function

NO-SIGN The leading sign is not displayed on the screen

DECIMALS <d> <d> defines the number of digits after the decimal point

EXPONENT <e> In type F fields, the exponent is defined in <e>

ROUND <r> Type P fields are multiplied by 10**(-r) and then rounded

CURRENCY <c> Format according to currency <c> in table TCURX

UNIT <u> The number of decimal places is fixed according to unit <u> specified in

table T006 for type P fields

Formatting options for date fields

Option Function

DD/MM/YY Separators as defined in user’s master record

MM/DD/YY Separators as defined in user’s master record

DD/MM/YYYY Separators as defined in user’s master record

MM/DD/YYYY Separators as defined in user’s master record

Trang 40

Formatting Options

DDMMYY No separators

MMDDYY No separators

YYMMDD No separators

For more information on formatting options and the exclusion principles for some of these

options, see the keyword documentation of the WRITE statement

Below are some examples of formatting options For more examples, see Creating Complex Lists[Page 817] The decimal character and thousands separators (period or comma) of numericfields are defined in the user’s master record

DATA: g(5) TYPE c VALUE 'Hello',

f(5) TYPE c VALUE 'Dolly'.

DATA time TYPE t VALUE '154633'.

WRITE float EXPONENT 3.

123456,789E+03

DATA pack TYPE p VALUE '123.456'

DECIMALS 3.

WRITE pack DECIMALS 2.

WRITE: / pack ROUND -2,

/ pack ROUND -1, / pack ROUND 1, / pack ROUND 2.

123,4612.345,6001.234,56012,3461,235

WRITE: sy-datum,

/ sy-datum yymmdd. 27.06.1995950627

Apart from the formatting options shown in the above tables, you can also use the formattingoptions of the FORMAT statement These options allow you to specify the intensity and color ofyour output For more information, see The FORMAT Statement [Page 868]

Ngày đăng: 09/08/2014, 14:20

TỪ KHÓA LIÊN QUAN