Tải bản đầy đủ (.pdf) (153 trang)

BC ABAP Programming PHẦN 7 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.74 MB, 153 trang )

SAP AG BC - ABAP Programming
Passing Data by Program Statements
December 1999 921
GET CURSOR FIELD F OFFSET OFF
LINE LIN VALUE VAL LENGTH LEN.
WRITE: 'Result of GET CURSOR FIELD: '.
ULINE AT /(28).
WRITE: / 'Field: ', F,
/ 'Offset:', OFF,
/ 'Line: ', LIN,
/ 'Value: ', (10) VAL,
/ 'Length:', LEN.
SKIP.
GET CURSOR LINE LIN OFFSET OFF VALUE VAL LENGTH LEN.
WRITE: 'Result of GET CURSOR LINE: '.
ULINE AT /(27).
WRITE: / 'Offset:', OFF,
/ 'Value: ', VAL,
/ 'Length:', LEN.
In this program, the HOTSPOT field is assigned to the field symbol <FS> and displayed as
hotspot on the output screen. If the user positions the cursor on a list line and selects it, a
dialog box appears containing the results of the GET CURSOR statements in the AT
LINE-SELECTION event.
Note that after GET CURSOR FIELD, the name of the field assigned to the field symbol
<FS> is stored in F, and not the name of the field symbol.
Determining the Attributes of Lists
If you need to know the attributes of list levels that are not stored in system variables, you can
use the DESCRIBE LIST statement.
To retrieve the number of lines or pages of a list, use:
DESCRIBE LIST NUMBER OF LINES|PAGES <n> [INDEX <idx>].
This statement writes the number of lines or pages of the list level <idx> into the variable <n>. If a


list with index <idx> does not exist, the system sets SY-SUBRC unequal to 0, otherwise to 0.
To retrieve the page number for a certain line number, use:
DESCRIBE LIST LINE <lin> PAGE <pag> [INDEX <idx>].
This statement writes for list level <idx> the page number on which the list line number <lin> is
found into the variable <pag>. SY-SUBRC is set as follows: If there is no list with the index <idx>,
it is 8. If there is no line with number <line>, it is 4. Otherwise, it is 0.
To retrieve the attributes of a certain page, use:
DESCRIBE LIST PAGE <pag> [INDEX <idx>] [<options>]
This statement retrieves for list level <idx> the attributes specified in <options> for page <pag>.
SY-SUBRC is set as follows: If there is no list with the index <idx>, it is 8. If there is no page with
number <pag>, it is 4. Otherwise, it is 0.
The <options> of the statement are:
• LINE-SIZE <col>
writes the page width into the variable <col>.
• LINE-COUNT <len>
writes the page length into the variable <len>.
BC - ABAP Programming SAP AG
Passing Data by Program Statements
922 December 1999
• LINES <lin>
writes the number of displayed lines into the variable <lin>.
• FIRST-LINE <lin1>
writes the absolute number of the first line into the variable <lin1>.
• TOP-LINES <top>
writes the number of page header lines into the variable <top>.
• TITLE-LINES <ttl>
writes the number of list header lines of the standard page header into the variable <ttl>.
• HEAD-LINES <head>
writes the number of column header lines of the standard page header into the variable
<head>.

• END-LINES <end>
writes the number of page footer lines into the variable <end>.
Use DESCRIBE LIST for completed lists only, since for lists in creation (index is SY-LSIND)
some attributes are not up to date.
REPORT demo_list_describe_list NO STANDARD PAGE HEADING
LINE-SIZE 40 LINE-COUNT 5(1).
DATA: lin TYPE i, pag TYPE i,
col TYPE i, len TYPE i, lin1 TYPE i,
top TYPE i, tit TYPE i, head TYPE i, end TYPE i.
DO 4 TIMES.
WRITE / sy-index.
ENDDO.
TOP-OF-PAGE.
WRITE 'Demonstration of DESCRIBE LIST statement'.
ULINE.
END-OF-PAGE.
ULINE.
AT LINE-SELECTION.
NEW-PAGE LINE-COUNT 0.
WINDOW STARTING AT 1 13 ENDING AT 40 25.
DESCRIBE LIST: NUMBER OF LINES lin INDEX 0,
NUMBER OF PAGES pag INDEX 0.
WRITE: 'Results of DESCRIBE LIST: '.
ULINE AT /(25).
WRITE: / 'Lines: ', lin,
/ 'Pages: ', pag.
SKIP.
DESCRIBE LIST LINE sy-lilli PAGE pag INDEX 0.
WRITE: / 'Line', (1) sy-lilli, 'is on page', (1) pag.
SKIP.

DESCRIBE LIST PAGE pag INDEX 0 LINE-SIZE col
LINE-COUNT len
LINES lin
SAP AG BC - ABAP Programming
Passing Data by Program Statements
December 1999 923
FIRST-LINE lin1
TOP-LINES top
TITLE-LINES tit
HEAD-LINES head
END-LINES end.
WRITE: 'Properties of Page', (1) pag, ':',
/ 'Width: ', col,
/ 'Length: ', len,
/ 'Lines: ', lin,
/ 'First Line: ', lin1,
/ 'Page Header: ', top,
/ 'Title Lines: ', tit,
/ 'Header Lines:', head,
/ 'Footer Lines:', end.
This program creates a two-page list of five lines per page. Two lines are used for the self-
defined page header and one line for the page footer. If the user selects a line, a dialog
box appears containing the list attributes.
While creating the secondary list, all variants of the DESCRIBE LIST statement apply to
the basic list. The system displays the results in the dialog window. The lines and pages to
be described are addressed dynamically using SY-LILLI.
BC - ABAP Programming SAP AG
Manipulating Detail Lists
924 December 1999
Manipulating Detail Lists

This section describes how you can manipulate the appearance and attributes of detail lists.
Scrolling through Detail Lists [Page 925]
Set the Cursor from within the Program [Page 927]
Modify List Lines [Page 930]
SAP AG BC - ABAP Programming
Scrolling in Detail Lists
December 1999 925
Scrolling in Detail Lists
You can scroll in a detail list using the SCROLL statement. The Scrolling in Lists [Page 847]
section contains a full description of the statement and how to use it for basic lists.
When you use the SCROLL statement with detail lists, you must remember the following:
• You can only use the SCROLL statement for completed lists. If you use SCROLL before the
first output statement of a list, it does not affect the list. If you use SCROLL after the first
output statement of a list, it affects the entire list, that is, all subsequent output statements as
well.
• When you create a secondary list, a SCROLL statement without INDEX option always refers
to the previously displayed list on which the interactive event occurred (index SY-LISTI).
• Only when creating the basic list does the SCROLL statement refer to the list currently being
created.
• You can use the INDEX option to scroll explicitly on existing list levels. To do this, the lists
need not be displayed. When the user displays the list again, it is scrolled to the specified
position. If the specified list level does not exist, the system sets SY-SUBRC to 8.
• If, during an interactive event, you want to scroll through the list you are currently creating,
use SY-LSIND as the index in the SCROLL statement. Note that changing SY-LSIND only
takes effect at the end of the event, regardless of where you change it in the processing
block. If you want to set the list level explicitly, you can change SY-LSIND in the last
statement of the processing block. This ensures that a SCROLL statement within the
processing block accesses the correct list.
Another way of scrolling interactive lists from within the program is to use the SET USER-
COMMAND [Page 905] statement in conjunction with the corresponding predefined function

codes (P ).
REPORT demo_list_scroll NO STANDARD PAGE HEADING LINE-SIZE
50.
SET PF-STATUS 'SELECT'.
WRITE 'Create a secondary list by choosing SELECT'.
AT USER-COMMAND.
NEW-PAGE LINE-SIZE 200.
CASE sy-ucomm.
WHEN 'SELE'.
SET PF-STATUS 'SCROLLING'.
DO 200 TIMES. WRITE sy-index. ENDDO.
SCROLL LIST RIGHT BY 48 PLACES INDEX sy-lsind.
sy-lsind = sy-lsind - 1.
WHEN 'LEFT'.
SCROLL LIST LEFT BY 12 PLACES.
WHEN 'RGHT'.
SCROLL LIST RIGHT BY 12 PLACES.
ENDCASE.
BC - ABAP Programming SAP AG
Scrolling in Detail Lists
926 December 1999
This program creates a basic list of one line with the status SELECT. In the status
SELECT, the function code SELE (text (
SELECT) is assigned to function key F2
and to a pushbutton in the application toolbar.
After choosing
SELECT, the system triggers the AT USER-COMMAND event and
creates a detail list with status SCROLLING. In the status SCROLLING, the
function codes
LEFT (text LEFT) and RGTH (text RIGHT) are assigned to the

function keys
F5 and F6 and to the application toolbar. The detail list is 200
characters wide. The SCROLL statement scrolls the detail list (SY-LSIND = 1) by
48 columns to the right after it has been created. Then, SY-LSIND is decreased
by 1 and the scrolled list replaces the basic list.
By clicking on
LEFT and RIGHT, the user can scroll to the left and to the right in
the displayed list. The SCROLL statements are programmed for the
corresponding function codes within the AT USER-COMMAND event.
SAP AG BC - ABAP Programming
Setting the Cursor from within the
Program
December 1999 927
Setting the Cursor from within the Program
You can set the cursor on the current list dynamically from within your program. You can do this
to support the user with entering values into input fields or selecting fields or lines. If input fields
occur on a list, the system by default places the cursor into the first input field.
To set the cursor, use the SET CURSOR statement. This statement sets the cursor in the most
recently-created list. While the basic list is being created, this is always the basic list itself. For a
detail list, it is the previous list.
With SET CURSOR, you can set the cursor to an absolute position, to a field, or to a line.
Setting the Cursor Explicitly
To set the cursor to a certain position in the output window, use:
SET CURSOR <col> <lin>.
This statement sets the cursor to column <col> of line <lin> of the output window.
The system sets the cursor only to positions that are visible in the display. For positions outside
the displayed area, it ignores the statement. To set the cursor to a part of the list currently not
displayed, you must scroll the list first.
You can set the cursor only to lines that contain list output. These include lines skipped with the
SKIP statement, but no underlines. If <lin> is below the bottom list line, the system sets the

cursor to the bottom line.
REPORT demo_list_set_cursor_1 NO STANDARD PAGE HEADING LINE-
SIZE 80.
SET PF-STATUS 'SCROLLING'.
NEW-LINE NO-SCROLLING.
WRITE 'Input Fields:'.
NEW-LINE NO-SCROLLING.
WRITE ' '.
NEW-LINE.
DO 5 TIMES.
WRITE: ' Input', (1) sy-index, ' ' INPUT ON NO-GAP.
ENDDO.
FORMAT INPUT OFF.
SET CURSOR 11 3.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'LEFT'.
IF sy-staco > 1.
SCROLL LIST LEFT BY 12 PLACES.
ENDIF.
WHEN 'RGHT'.
IF sy-staco < 40.
SCROLL LIST RIGHT BY 12 PLACES.
BC - ABAP Programming SAP AG
Setting the Cursor from within the Program
928 December 1999
ENDIF.
ENDCASE.
SET CURSOR 11 3.
This program creates a basic list that contains five input fields. The cursor is set

to the first input field. The user can use the pushbuttons
LEFT and RIGHT to
scroll the list horizontally. After each scroll movement, the cursor is set to an input
field again.
Setting the Cursor to a Field
To set the cursor to a certain field on a line of the displayed list, use:
SET CURSOR FIELD <f> LINE <lin> [OFFSET <off>].
This statement sets the cursor on line <lin> onto the field whose name is stored in <f>. If a field
appears more than once on a line, the system sets the cursor to the first field. If the field does not
appear on the line or if it is outside the displayed area, the system ignores the statement. You
can use the SCROLL statement to scroll the line into the visible area of the screen.
Use the OFFSET option to set the cursor to position <off> of the field stored in <f>. <off> = 0
indicates the first position.
When you set the cursor, you must take into account the header lines of the list.
REPORT demo_list_set_cursor_2 LINE-SIZE 50.
DATA: input1(5) TYPE c VALUE '*****',
input2(5) TYPE c VALUE '*****',
input3(5) TYPE c VALUE '*****'.
SET PF-STATUS 'INPUT'.
WRITE 'Input Fields:'.
WRITE / ' '.
SKIP.
WRITE: 'Input 1', input1 INPUT ON,
/ 'Input 2', input2 INPUT ON,
/ 'Input 3', input3 INPUT ON.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'INP1'.
SET CURSOR FIELD 'INPUT1' LINE 6 OFFSET 4.
WHEN 'INP2'.

SET CURSOR FIELD 'INPUT2' LINE 7 OFFSET 4.
WHEN 'INP3'.
SET CURSOR FIELD 'INPUT3' LINE 8 OFFSET 4.
ENDCASE.
This program creates a basic list containing three input fields. In the status
INPUT, the function codes INP1, INP2, and INP3 are assigned to the function
keys
F5, F6, and F7 and to the application toolbar. When you choose one of these
functions, the system triggers the AT USER-COMMAND event. It places the
cursor on the corresponding input field.
SAP AG BC - ABAP Programming
Setting the Cursor from within the
Program
December 1999 929
Setting the Cursor to a Line
To set the cursor to a certain line of the list in the output window, use:
SET CURSOR LINE <lin> [OFFSET <off>].
This statement sets the cursor to line <lin>. The system ignores the statement, if the line does
not appear in the list or in the visible area of the window. You can use the SCROLL statement to
scroll the line into the visible area of the screen.
Use the OFFSET option to set the cursor to column <off> of line <lin>. <off> = 0 indicates the first
column. The system ignores the statement, if the position is outside the visible area of the list.
When you set the cursor, you must take into account the header lines of the list.
REPORT demo_list_set_cursor_3 LINE-SIZE 30
NO STANDARD PAGE HEADING.
DATA: inp(2) TYPE c, top(2) TYPE c.
SET PF-STATUS 'LINE_NUMBER'.
DO 50 TIMES.
WRITE: / 'Line ', (2) sy-index.
ENDDO.

TOP-OF-PAGE.
WRITE: 'Line number:', inp INPUT ON.
ULINE.
SKIP.
AT USER-COMMAND.
DESCRIBE LIST PAGE 1 TOP-LINES top.
CASE sy-ucomm.
WHEN 'LINE'.
READ LINE 1 FIELD VALUE inp.
SCROLL LIST TO PAGE 1 LINE inp.
inp = inp + top.
SET CURSOR LINE inp OFFSET 6.
ENDCASE.
This program creates a basic list with an input field and a set of lines.
In the status LINE_NUMBER, the function code LINE (text
LINE NUMBER) is
assigned to function key
F5 and to a pushbutton of the application toolbar. If the
user enters a number into the input field and chooses
LINE NUMBER, the system
scrolls to the specified number and sets the cursor to it:
The system reads the input field using READ LINE. For setting the cursor, it uses
DESCRIBE LIST to take into account the size of the page header. Note that this
example makes excessive use of automatic type conversion.
BC - ABAP Programming SAP AG
Modifying List Lines
930 December 1999
Modifying List Lines
To modify the lines of a completed list from within the program, use the MODIFY LINE statement.
There are two ways to specify the line you want to modify:

• Explicitly:
MODIFY LINE <n> [INDEX <idx>|OF CURRENT PAGE|OF PAGE <p>]
[<modifications>].
Without the first line of options, this statement modifies line <n> of the list on which an
interactive event occurred (index SY-LISTI). With the options of the first line, you can
specify the line you want to modify as follows:
– Use INDEX <idx> to specify line <n> of the list level with the index <idx>.
– Use OF CURRENT PAGE to specify line <n> of the currently displayed page (page
number SY-CPAGE) .
– Use OF PAGE <p> to specify line <n> of page <p>.
You can refer to the line most recently read:
MODIFY CURRENT LINE [<modifications>].
This statement modifies the line most recently read by means of line selection (F2) or of
the READ LINE statement.
Without the option <modifications>, the above statements fill the current contents of the SY-
LISEL system field into the specified line. The line's HIDE area is overwritten by the current
values of the corresponding fields. However, this does not influence the displayed values.
If the system succeeded in modifying the specified line, it sets SY-SUBRC to 0, otherwise to a
value unequal to 0.
Apart from the ones described above, the option <modifications> contains several other
possibilities to modify the line.
Modifying Line Formatting
To modify the formatting of the line you want to change, use the option LINE FORMAT of the
MODIFY statement as follows:
MODIFY LINE FORMAT <option
1
> <option
2
> .
This statement sets the output format of the entire modified line according to the format specified

with <option
i
>. You can specify the same format options as for the FORMAT statement.
Modifying Field Contents
To explicitly modify the contents of fields in the line you want to change, use the option FIELD
VALUE of the MODIFY statement:
MODIFY FIELD VALUE <f
1
> [FROM <g
1
>] <f
2
> [FROM <g
2
>] .
This statement overwrites the contents of the fields <f
i
> in the list line with the current contents of
the fields <f
i
> or <g
i
>. If necessary, the system converts the field type to type C.
If a field <f
i
> occurs more than once in the line, the system modifies only the first. If a field <f
i
>
does not occur in the line at all, the system ignores the option.
SAP AG BC - ABAP Programming

Modifying List Lines
December 1999 931
The system modifies existing fields <f
i
> regardless of the current contents you write from SY-
LISEL into the line. If you made changes to the line at the output position of a field <f
i
> using SY-
LISEL, the FIELD VALUE option overwrites them.
Changing Field Formatting
To modify the formatting of fields in the line you want to change, use the option FIELD FORMAT
of the MODIFY statement as follows:
MODIFY FIELD FORMAT <f
1
> <options
1
><f
2
> <options
2
> .
This statement sets the output format of the fields <f
i
> occurring in the line according to the
format specified in <options
i
>. You can specify formats from the FORMAT statement in
<options
i>.
The option FIELD FORMAT overwrites the specifications of the LINE FORMAT option for the

corresponding field(s). If a field <f
i
> occurs more than once in the line, the system modifies only
the first. If a field <f
i
> does not occur in the line at all, the system ignores the option.
Examples
Example of line formatting.
REPORT demo_list_modify_line_format LINE-SIZE 40
NO STANDARD PAGE HEADING.
DATA c TYPE i VALUE 1.
WRITE 'Select line to modify the background'.
AT LINE-SELECTION.
IFc=8.
c=0.
ENDIF.
MODIFY CURRENT LINE LINE FORMAT COLOR = c.
ADD1TOc.
This program creates an output line whose background color the user can change by
selecting the line again and again:
Example for field contents.
REPORT demo_list_modify_field_value LINE-SIZE 40
NO STANDARD PAGE HEADING.
DATA c TYPE i.
WRITE: ' Number of selections:', (2) c.
AT LINE-SELECTION.
ADD1TOc.
sy-lisel(2) = '**'.
MODIFY CURRENT LINE FIELD VALUE c.
This program creates an output line, in which the user can modify the field C by

selecting the line. At the same time, the system overwrites the first two characters of
the line with two asterisks '**' due to the modification of SY-LISEL.
Example for field formatting.
REPORT demo_list_modify_field_format NO STANDARD PAGE HEADING.
BC - ABAP Programming SAP AG
Modifying List Lines
932 December 1999
DATA: box(1) TYPE c, lines TYPE i, num(1) TYPE c.
SET PF-STATUS 'CHECK'.
DO 5 TIMES.
num = sy-index.
WRITE: / box AS CHECKBOX, 'Line', num.
HIDE: box, num.
ENDDO.
lines = sy-linno.
TOP-OF-PAGE.
WRITE 'Select some checkboxes'.
ULINE.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'READ'.
SET PF-STATUS 'CHECK' EXCLUDING 'READ'.
box = space.
DO lines TIMES.
READ LINE sy-index FIELD VALUE box.
IF box = 'X'.
WRITE: / 'Line', num, 'was selected'.
box = space.
MODIFY LINE sy-index
FIELD VALUE box

FIELD FORMAT box INPUT OFF
num COLOR 6 INVERSE ON.
ENDIF.
ENDDO.
ENDCASE.
This program creates a basic list with the status CHECK. In the status CHECK,
function code READ (text
Read Lines) is assigned to function key F5 and to a
pushbutton. The user can mark checkboxes and then choose
Read Lines.
In the AT USER-COMMAND event, the system reads the lines of the list using READ
LINE. It continues processing the selected lines on a secondary list. When returning to
the basic list, the system deletes the marks in the checkboxes of the selected lines
using MODIFY LINE and sets the format INPUT OFF to the checkboxes. In addition, it
changes the format of field NUM.
The user can now mark only those lines that have not yet been changed.
SAP AG BC - ABAP Programming
Lists and Screens
December 1999 933
Lists and Screens
When you run an executable program, the list processor is automatically started at the end of the
last processing block, and the basic list created during the program is displayed.
If you want to display lists during screen processing, you must program it explicitly. Conversely,
you can switch to screen processing from list processing.
Starting Lists from Screen Processing [Page 934]
Calling Screens from List Processing [Page 938]
BC - ABAP Programming SAP AG
Starting Lists from Screen Processing
934 December 1999
Starting Lists from Screen Processing

This section describes how to switch from screen processing to list processing. It contains a short
technical introduction, followed by a recommended procedure.
Switching Between Screen and List Processing
Screen processing always involves a screen sequence [Page 1041] that you start either using
CALL SCREEN or a transaction code. During screen processing, the ABAP program is
controlled by the dialog processor. In the ABAP program, the PBO and PAI modules are
executed as they are called from the screen flow logic.
To pass control from the dialog processor to the list processor, you must include the following
statement in one of the dialog modules:
LEAVE TO LIST-PROCESSING [AND RETURN TO SCREEN <nnnn>].
You can include this statement in either the PBO or the PAI event. Its effect is to start the list
processor and display the basic list
after the PAI processing of the current screen. The basic
list contains any list output from all PBO and PAI modules that have been executed up to that
point.
If detail lists are defined in the corresponding event blocks of the ABAP program (AT LINE-
SELECTION, AT USER-COMMAND), user actions on the basic list will lead to the detail list, and
further interaction will lead to further list levels.
You can leave list processing in two ways:
• By leaving the basic list using the Back, Exit, or Cancel function.
• By using the following statement during list processing:
LEAVE LIST-PROCESSING.
In both cases, control returns from the list processor to the dialog processor. Each time this
occurs, the
entire list system is initialized. Any subsequent list output statements in PBO and
PAI modules apply to an empty basic list.
By default, the dialog processor returns to the PBO processing of the screen from which the list
processor was called. The optional addition AND RETURN TO SCREEN allows you to specify a
different screen in the current screen sequence at whose PBO event you want to resume
processing. In particular, the statement

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
can be used to end the current screen sequence and return to the point from which it had
originally been called.
Recommended Procedure
If you want to display lists during screen processing, you should create a separate screen for
each list system that you want to call. This screen
encapsulates the creation and display of the
basic list. It can then be called from anywhere in the program using CALL SCREEN.
The actual screen mask of this screen can remain empty. You do not need any PAI modules, and
only a single PBO module. In the PBO module, you define the basic list of the list system and call
the list processor.
SAP AG BC - ABAP Programming
Starting Lists from Screen Processing
December 1999 935
1. First, use the
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
statement to call the list display at the end of the screen, and to ensure that, after leaving
the list, you return to the point from which the screen was called.
2. Next, set a GUI status for the list; for example, the default list status SPACE or a list
status of your own.
3. Use one of the following statements to ensure that the empty screen is not displayed:
SUPPRESS DIALOG.
or
LEAVE SCREEN. Instead, the list is displayed immediately at the end of the screen.
4. Now define the
entire basic list, and place any necessary data in the HIDE area.
If you want to process user actions on the list, you need to define the relevant event blocks in
your ABAP program. If you want to call more than one independent list system in the program,
you must ensure that you can tell them apart in the list event processing. You cannot do this
using SY-DYNNR, since the container screen for a list is always number 120. Instead, you could

assign a different GUI status to each list, and distinguish between the list systems using the
value of SY-PFKEY, or you could place some unique information in the HIDE area of each list
system.
Example
REPORT demo_leave_to_list_processing .
TABLES sdyn_conn.
DATA: wa_spfli TYPE spfli,
flightdate TYPE sflight-fldate.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
ENDMODULE.
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE user_command_0100.
CALL SCREEN 500.
SET SCREEN 100.
ENDMODULE.
MODULE call_list_500 OUTPUT.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS space.
SUPPRESS DIALOG.
BC - ABAP Programming SAP AG
Starting Lists from Screen Processing
936 December 1999
SELECT carrid connid cityfrom cityto
FROM spfli
INTO CORRESPONDING FIELDS OF wa_spfli
WHERE carrid = sdyn_conn-carrid.

WRITE: / wa_spfli-carrid, wa_spfli-connid,
wa_spfli-cityfrom, wa_spfli-cityto.
HIDE: wa_spfli-carrid, wa_spfli-connid.
ENDSELECT.
CLEAR: wa_spfli-carrid.
ENDMODULE.
TOP-OF-PAGE.
WRITE text-001 COLOR COL_HEADING.
ULINE.
TOP-OF-PAGE DURING LINE-SELECTION.
WRITE sy-lisel COLOR COL_HEADING.
ULINE.
AT LINE-SELECTION.
CHECK not wa_spfli-carrid is initial.
SELECT fldate
FROM sflight
INTO flightdate
WHERE carrid = wa_spfli-carrid AND
connid = wa_spfli-connid.
WRITE / flightdate.
ENDSELECT.
CLEAR: wa_spfli-carrid.
This example switches to list processing during the screen processing for screen
100. Screen 100 has a single input field - the component CARRID from the ABAP
Dictionary structure SDYN_CONN.
It has the following flow logic:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.

MODULE USER_COMMAND_0100.
The PAI module USER_COMMAND_100 calls screen 500 using the CALL SCREEN
statement. This screen encapsulates a basic list. It has the following flow logic:
PROCESS BEFORE OUTPUT.
MODULE CALL_LIST_500.
PROCESS AFTER INPUT.
The module CALL_LIST_500 defines the basic list and switches to list processing.
Since the next screen after list processing is screen 0, screen 500 is a one-screen
screen chain. After list processing, control returns to the position in
USER_COMMAND_100 from which screen 500 was called.
If the user selects a line on the basic list, a detail list appears. This is achieved
through the event block AT LINE-SELECTION. The program also contains event
SAP AG BC - ABAP Programming
Starting Lists from Screen Processing
December 1999 937
blocks for TOP-OF-PAGE and TOP-OF-PAGE DURING LINE-SELECTION, which
define page headers for both the basic list and detail list.
Since there is only one list system in this program, there is no need for case
distinctions within the list events.
BC - ABAP Programming SAP AG
Calling Screens from List Processing
938 December 1999
Calling Screens from List Processing
To call a screen from list processing, use the statement
CALL SCREEN <nnnn>.
This inserts a screen sequence into the program flow as described in the section Calling Screen
Sequences [Page 1048]. The list processor passes control to the dialog processor.
The context from the time of the call is retained. If you call a screen sequence during processing
of a particular list level, it is processed until the end of a screen with next screen 0. Then the
dialog processor returns control to the list processor, and processing carries on after the CALL

SCREEN statement.
Example
The following program is connected to the logical database F1S.
REPORT demo_call_screen_from_list.
NODES spfli.
TABLES demo_conn.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
TOP-OF-PAGE.
WRITE 'Liste von Flügen'(001) COLOR COL_HEADING.
ULINE.
GET spfli FIELDS carrid connid.
WRITE: / spfli-carrid, spfli-connid.
HIDE: spfli-carrid, spfli-connid.
END-OF-SELECTION.
CLEAR: spfli-carrid, spfli-connid.
AT LINE-SELECTION.
CHECK not spfli-carrid is initial.
demo_conn-carrid = spfli-carrid.
demo_conn-connid = spfli-connid.
CALL SCREEN 100.
CLEAR: spfli-carrid, spfli-connid.
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
ENDMODULE.
MODULE user_command_0100 INPUT.
save_ok = ok_code.

CLEAR ok_code.
CASE save_ok.
SAP AG BC - ABAP Programming
Calling Screens from List Processing
December 1999 939
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
SELECT SINGLE *
FROM sflight
INTO CORRESPONDING FIELDS OF demo_conn
WHERE carrid = demo_conn-carrid AND
connid = demo_conn-connid AND
fldate = demo_conn-fldate.
IF sy-subrc ne 0.
MESSAGE e047(sabapdocu).
ELSE.
SET SCREEN 200.
ENDIF.
ENDCASE.
ENDMODULE.
MODULE status_0200 OUTPUT.
SET PF-STATUS 'SCREEN_200'.
ENDMODULE.
MODULE user_command_0200 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'BACK'.
LEAVE TO SCREEN 100.

WHEN 'SAVE'.
"e.g. update records in database
MESSAGE i888(sabapdocu) WITH text-002.
SET SCREEN 0.
ENDCASE.
ENDMODULE.
When you run the program, you can enter selections on the selection screen of the
logical database, after which a basic list is displayed.
If you select a list line, the AT LINE-SELECTION event is triggered, and screen 100
is called. The contents of two of the screen fields are set in the ABAP program. The
layout of screen 100 is:
BC - ABAP Programming SAP AG
Calling Screens from List Processing
940 December 1999
Airline
Flight number
Flight date
Continue
and its flow logic is:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
FIELD DEMO_CONN-FLDATE MODULE USER_COMMAND_0100.
You can enter a flight date for the flight that you chose from the list. If you then
choose
Continue, the corresponding data is read from table SFLIGHT, and screen
200 is set as the next screen. The layout of screen 200 is:
SAP AG BC - ABAP Programming
Calling Screens from List Processing

December 1999 941
Airline
Flight number
Flight date
Save
Price
Local currency
Airline type
Max. occupancy
Occupancy
and its flow logic is:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0200.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
MODULE USER_COMMAND_0200.
The user can change and save data for the selected flight. (The programming for the
database update is not shown in this example.)
After the screen has been processed, the next screen is set to 0, concluding the
screen sequence. The system returns to the basic list.
Equally, if you choose
Back (function code BACK) on either of the two screens,
control returns to the basic list.
BC - ABAP Programming SAP AG
Printing Lists
942 December 1999
Printing Lists
Drucksteuerung [Page 957]
BC - SAP-Druckhandbuch [Extern]
You use lists to output structured, formatted data. By default, the system sends a list (basic list

and secondary lists) to the output screen after creating it. This section describes how to send lists
to the SAP spool system instead of the output screen.
Within ABAP, sending a list to the SAP spool system is generally called 'printing lists'. This,
however, must not necessarily mean that the list is actually printed on a printer. You can also use
the spool system to store a list temporarily, or to store lists in an optical archive instead of printing
it.
ABAP offers two possibilities to print a list:
You can print a list
after and while creating it.
Printing a List after Creating it [Page 943]
Printing a List while Creating it [Page 945]
Additional Information about this Section
For more comprehensive information about spool administration, refer to the Printing Guide.
For further information about archiving lists, refer to the SAP ArchiveLink [Extern] and Storing
ABAP Lists [Extern] documentation.
SAP AG BC - ABAP Programming
Printing a List after Creating it
December 1999 943
Printing a List after Creating it
When printing a list after creating it, you do not use any of the print-specific statements described
in the topics below to send the list from within the program to the SAP spool system.
By default, the system sends the completed list to the output screen. If the
Print function (function
code PRI) in the status of the user interface for the list has been activated, the user can send the
screen list to the SAP spool system by choosing
Print (see Printing Output Lists). The system
requests the print parameters in the
Print Screen List dialog box (see Print Parameters [Page
946]). For information about how to change the default values on this screen, refer to Print
Parameters - Setting Default Values.

Printing a list after creating it has the following problems:
• The list is formatted for screen display, and not for printing. This is not always suitable
for printing, for the following reasons:
− A list on an output screen usually consists of a single page (see notes in Setting the
Page Length [Page 832]). When printing, the system 'cuts' this logical page into several
physical pages whose format depends on the print parameters specified. The system
places the page header on each of these print pages. If the page header contains a page
number, this number is the same on all pages (SY-PAGNO). This means that you cannot
number the pages.
− If the list contains page breaks programmed using NEW-PAGE (see Unconditional Page
Breaks), these page breaks are not adapted to the format of the print pages, which may
lead to further automatic page breaks. For a print page created by an automatic page
break, the system uses the same page header as for the previous page, since only
NEW-PAGE increases the system field SY-PAGNO.
− If the list consists of several pages due to the LINE-COUNT option in the REPORT or
NEW-PAGE statement (see Lists with Several Pages [Page 836]), you can either not
print the list at all, since the page length specified exceeds the maximum page length of
a print page, or you do not make full use of the physical print page.
− You can set the width of a list on an output screen to any value between 1 and 255
columns (see Setting the List Width [Page 828]). This list width is not adapted to a printer
format. For example, a normal printer prints lists wider than 132 columns with the same
small letter size as lists of 255 columns because there is no print format in between.
• When creating a list for screen output, you cannot include print control statements into
the list (see Print Control [Page 957]).
• You cannot output footer lines defined in the program at the end of each printed page.
However, you can instead select
Footer line in the Print Screen List dialog box. The
system then reserves one line on each page for the system-defined footer line.
• Screen lists do not contain any index information for optical archiving. You can only
create index information for optical archiving while the list is being created (see Indexing

Print Lists for Optical Archiving [Page 964]).
The printout of a completed list from the output screen is a hard copy of the screen rather than a
real program-controlled printout. Use this method for testing purposes only, or for lists whose
formats are acceptable to the printer. You should print complex lists (like lists with extensive page
headers that should not appear on each printed page) from the program (see Printing a List
During Creation [Page 945]).
BC - ABAP Programming SAP AG
Printing a List after Creating it
944 December 1999

If you want to offer the user the possibility of starting a program-controlled print
process from the output screen, use the methods of interactive reporting (see User
Actions on Lists [Page 891]). For example, you first create a list for the output
screen. Use a user interface of your own in which you replace function code PRI with
a different function code. You can then recreate the list for the spool system in the
AT USER-COMMAND event (see Printing a List During Creation [Page 945]).
SAP AG BC - ABAP Programming
Printing a List while Creating it
December 1999 945
Printing a List while Creating it
When you print a list while creating it, you receive best print output, since the system formats the
list according to the requirements of the printer. The system sets list width and page length
according to the print format. This prevents lines from being wider than the print format in use.
Page breaks occur at the end of a physical print page.
The program must know the print format before it starts creating the list. The print format is part
of the print parameters. Print parameters are set either interactively by the user or from within the
program.
Print Parameters [Page 946]
You can print a list while creating it in one of the following ways:
• If your program displays a selection screen, the user can choose Execute + print on the

selection screen.
Execute and Print [Page 947]
• You can start print output from within your program using the NEW-PAGE PRINT ON
statement.
Printing from Within a Program [Page 950]
• You can call an executable program using the SUBMIT TO SAP-SPOOL statement.
Printing Lists of Called Executable Programs [Page 954]
• You can include a report into a background job using the function module JOB_SUBMIT.
For further information about background jobs and the function module JOB_SUBMIT,
refer to the Basis Programming Interfaces [Extern] documentation.
When printing a list while creating it, you can manipulate the print format:
Print Control

When printing a list while creating it, the system sends each completed page to the
spool system and then deletes it. The length of a printed list, therefore, is restricted
only by the capacity of the spool system. In contrast to lists for display, the system
does not store list levels when printing. Since an entire list in printing never exists,
you cannot refer to the contents of previous pages.

×