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

BC ABAP Programming PHẦN 7 pot

153 242 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

This statement writes for list level the page number on which the list line number isfound into the variable.. If the Print function function code PRI in the status of the user interfa

Trang 1

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 ashotspot on the output screen If the user positions the cursor on a list line and selects it, adialog box appears containing the results of the GET CURSOR statements in the ATLINE-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 canuse 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 alist 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> isfound 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 withnumber <pag>, it is 4 Otherwise, it is 0

The <options> of the statement are:

Trang 2

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.

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

Trang 3

December 1999 923

FIRST-LINE lin1 TOP-LINES top TITLE-LINES tit HEAD-LINES head END-LINES end.

WRITE: 'Properties of Page', (1) pag, ':',

This program creates a two-page list of five lines per page Two lines are used for the defined page header and one line for the page footer If the user selects a line, a dialogbox appears containing the list attributes

self-While creating the secondary list, all variants of the DESCRIBE LIST statement apply tothe basic list The system displays the results in the dialog window The lines and pages to

be described are addressed dynamically using SY-LILLI

Trang 4

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]

Trang 5

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 thefirst output statement of a list, it does not affect the list If you use SCROLL after the firstoutput statement of a list, it affects the entire list, that is, all subsequent output statements aswell

• 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 beingcreated

• You can use the INDEX option to scroll explicitly on existing list levels To do this, the listsneed not be displayed When the user displays the list again, it is scrolled to the specifiedposition 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 onlytakes effect at the end of the event, regardless of where you change it in the processingblock 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 functioncodes (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.

Trang 6

SELECT, the function code SELE (text (SELECT) is assigned to function key F2and 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

Trang 7

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 fieldsoccur 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 mostrecently-created list While the basic list is being created, this is always the basic list itself For adetail 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 outsidethe displayed area, it ignores the statement To set the cursor to a part of the list currently notdisplayed, you must scroll the list first

You can set the cursor only to lines that contain list output These include lines skipped with theSKIP statement, but no underlines If <lin> is below the bottom list line, the system sets thecursor to the bottom line

REPORT demo_list_set_cursor_1 NO STANDARD PAGE HEADING SIZE 80.

LINE-SET PF-STATUS 'SCROLLING'.

Trang 8

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 inputfield 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 fieldappears more than once on a line, the system sets the cursor to the first field If the field does notappear on the line or if it is outside the displayed area, the system ignores the statement Youcan 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> = 0indicates 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.

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 thesefunctions, the system triggers the AT USER-COMMAND event It places the

cursor on the corresponding input field

Trang 9

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 doesnot appear in the list or in the visible area of the window You can use the SCROLL statement toscroll 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 firstcolumn 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'.

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 usesDESCRIBE LIST to take into account the size of the page header Note that thisexample makes excessive use of automatic type conversion

Trang 10

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:

– 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 (pagenumber 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 ofthe READ LINE statement

Without the option <modifications>, the above statements fill the current contents of the LISEL system field into the specified line The line's HIDE area is overwritten by the currentvalues of the corresponding fields However, this does not influence the displayed values

SY-If the system succeeded in modifying the specified line, it sets SY-SUBRC to 0, otherwise to avalue 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 theMODIFY statement as follows:

MODIFY LINE FORMAT <option1> <option2>

This statement sets the output format of the entire modified line according to the format specifiedwith <optioni> 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 FIELDVALUE of the MODIFY statement:

MODIFY FIELD VALUE <f1> [FROM <g1>] <f2> [FROM <g2>]

This statement overwrites the contents of the fields <fi> in the list line with the current contents ofthe fields <fi> or <gi> If necessary, the system converts the field type to type C

If a field <fi> occurs more than once in the line, the system modifies only the first If a field <fi>does not occur in the line at all, the system ignores the option

Trang 11

December 1999 931

The system modifies existing fields <fi> regardless of the current contents you write from LISEL into the line If you made changes to the line at the output position of a field <fi> using SY-LISEL, the FIELD VALUE option overwrites them

SY-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 <f1> <options1> <f2> <options2>

This statement sets the output format of the fields <fi> occurring in the line according to theformat specified in <optionsi> You can specify formats from the FORMAT statement in

<optionsi>.

The option FIELD FORMAT overwrites the specifications of the LINE FORMAT option for thecorresponding field(s) If a field <fi> occurs more than once in the line, the system modifies onlythe first If a field <fi> 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'.

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.

ADD 1 TO c.

sy-lisel(2) = '**'.

MODIFY CURRENT LINE FIELD VALUE c.

This program creates an output line, in which the user can modify the field C byselecting the line At the same time, the system overwrites the first two characters ofthe 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.

Trang 12

SET PF-STATUS 'CHECK'.

DO 5 TIMES.

num = sy-index.

WRITE: / box AS CHECKBOX, 'Line', num.

HIDE: box, num.

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 READLINE It continues processing the selected lines on a secondary list When returning tothe basic list, the system deletes the marks in the checkboxes of the selected linesusing MODIFY LINE and sets the format INPUT OFF to the checkboxes In addition, itchanges the format of field NUM

The user can now mark only those lines that have not yet been changed

Trang 13

December 1999 933

Lists and Screens

When you run an executable program, the list processor is automatically started at the end of thelast 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]

Trang 14

Starting Lists from Screen Processing

This section describes how to switch from screen processing to list processing It contains a shorttechnical 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 usingCALL 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 followingstatement 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 listprocessor and display the basic list after the PAI processing of the current screen The basiclist contains any list output from all PBO and PAI modules that have been executed up to thatpoint

If detail lists are defined in the corresponding event blocks of the ABAP program (AT SELECTION, AT USER-COMMAND), user actions on the basic list will lead to the detail list, andfurther interaction will lead to further list levels

LINE-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 thisoccurs, the entire list system is initialized Any subsequent list output statements in PBO andPAI modules apply to an empty basic list

By default, the dialog processor returns to the PBO processing of the screen from which the listprocessor was called The optional addition AND RETURN TO SCREEN allows you to specify adifferent 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 foreach list system that you want to call This screen encapsulates the creation and display of thebasic 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, andonly a single PBO module In the PBO module, you define the basic list of the list system and callthe list processor

Trang 15

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 leavingthe 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 liststatus 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 inyour 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 thisusing SY-DYNNR, since the container screen for a list is always number 120 Instead, you couldassign a different GUI status to each list, and distinguish between the list systems using thevalue of SY-PFKEY, or you could place some unique information in the HIDE area of each listsystem

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'.

MODULE call_list_500 OUTPUT.

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.

SET PF-STATUS space.

SUPPRESS DIALOG.

Trang 16

FROM spfli INTO CORRESPONDING FIELDS OF wa_spfli WHERE carrid = sdyn_conn-carrid.

WRITE: / wa_spfli-carrid, wa_spfli-connid,

TOP-OF-PAGE DURING LINE-SELECTION.

WRITE sy-lisel COLOR COL_HEADING.

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 ABAPDictionary structure SDYN_CONN

It has the following flow logic:

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

PROCESS AFTER INPUT.

MODULE CANCEL AT EXIT-COMMAND.

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-screenscreen 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 achievedthrough the event block AT LINE-SELECTION The program also contains event

Trang 17

December 1999 937

blocks for TOP-OF-PAGE and TOP-OF-PAGE DURING LINE-SELECTION, whichdefine 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

Trang 18

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 ScreenSequences [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 thedialog processor returns control to the list processor, and processing carries on after the CALLSCREEN statement

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.

CLEAR: spfli-carrid, spfli-connid.

MODULE cancel INPUT.

LEAVE PROGRAM.

ENDMODULE.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

Trang 19

connid = demo_conn-connid AND fldate = demo_conn-fldate.

MODULE status_0200 OUTPUT.

SET PF-STATUS 'SCREEN_200'.

MESSAGE i888(sabapdocu) WITH text-002.

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 Thelayout of screen 100 is:

Trang 20

AirlineFlight 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:

Trang 21

December 1999 941

AirlineFlight numberFlight date

Save

PriceLocal currency Airline typeMax occupancyOccupancy

and its flow logic is:

PROCESS BEFORE OUTPUT.

MODULE STATUS_0200.

PROCESS AFTER INPUT.

MODULE CANCEL AT EXIT-COMMAND.

Equally, if you choose Back (function code BACK) on either of the two screens,

control returns to the basic list

Trang 22

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 usethe spool system to store a list temporarily, or to store lists in an optical archive instead of printingit

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 StoringABAP Lists [Extern] documentation

Trang 23

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 PrintParameters - 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 suitablefor printing, for the following reasons:

− A list on an output screen usually consists of a single page (see notes in Setting thePage Length [Page 832]) When printing, the system 'cuts' this logical page into severalphysical pages whose format depends on the print parameters specified The systemplaces the page header on each of these print pages If the page header contains a pagenumber, this number is the same on all pages (SY-PAGNO) This means that you cannotnumber the pages

− If the list contains page breaks programmed using NEW-PAGE (see Unconditional PageBreaks), these page breaks are not adapted to the format of the print pages, which maylead to further automatic page breaks For a print page created by an automatic pagebreak, the system uses the same page header as for the previous page, since onlyNEW-PAGE increases the system field SY-PAGNO

− If the list consists of several pages due to the LINE-COUNT option in the REPORT orNEW-PAGE statement (see Lists with Several Pages [Page 836]), you can either notprint 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 255columns (see Setting the List Width [Page 828]) This list width is not adapted to a printerformat For example, a normal printer prints lists wider than 132 columns with the samesmall 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 intothe 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 onlycreate index information for optical archiving while the list is being created (see IndexingPrint 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 areal program-controlled printout Use this method for testing purposes only, or for lists whoseformats are acceptable to the printer You should print complex lists (like lists with extensive pageheaders that should not appear on each printed page) from the program (see Printing a ListDuring Creation [Page 945])

Trang 24

If you want to offer the user the possibility of starting a program-controlled printprocess from the output screen, use the methods of interactive reporting (see UserActions 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])

Trang 25

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 thelist according to the requirements of the printer The system sets list width and page lengthaccording 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 theprogram

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 ONstatement

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 thespool system and then deletes it The length of a printed list, therefore, is restrictedonly by the capacity of the spool system In contrast to lists for display, the systemdoes not store list levels when printing Since an entire list in printing never exists,you cannot refer to the contents of previous pages

Trang 26

Print Parameters

Drucklisten für die optische Archivierung indizieren [Page 964]

You must set print parameters before the printing process starts

When printing lists after creating them, the system uses the print format specified in the printparameters to split the completed list and fit it onto the print pages, truncating it if necessary.When printing lists while creating them, the system uses the print format to actually format thelist in the program

Print parameters are set either interactively by the user or from within the program

Print Parameters - Overview

Print Parameters - Setting Default Values

Setting Print Parameters in a Program

Trang 27

December 1999 947

Execute and Print

The easiest way of printing a list while creating it, is for the user to choose Execute + print on the

report's selection screen The user can choose between displaying the list on the screen

(choosing Execute) or printing it directly without displaying it (choosing Execute + print).

If the user chooses Execute + print on the selection screen of the report, the system displays the

Print List Output dialog window before creating the list The user enters the print parameters Thefunction module SET_PRINT_PARAMETERS allows you to set default values for the dialog box.For further information, refer to Print Parameters - Setting Default Values

Consequently, you must program the list in such a way that it can both be displayed and printed.Therefore, in the REPORT statement, do not specify the page width wider than 132 characters(LINE-SIZE option) and do not set the page length (LINE-COUNT option) at all

Using Execute + print, the user can print only the basic list of the report To print secondary lists

that you create during interactive events on the displayed list, use NEW-PAGE PRINT ON (seePrinting from Within the Program [Page 950])

REPORT SAPMZTST NO STANDARD PAGE HEADING LINE-COUNT 0(2)

Trang 28

ULINE.

WRITE: 'End of', SY-PAGNO

After executing this program, the user can enter a value for parameter P on the

selection screen (for example 100) and choose Execute + print The following dialog

box appears:

The function module SET_PRINT_PARAMETERS fills the input fields with the

default values Because of the function module, the Lines field is ready for input,

even though the LINE-COUNT addition is used in the REPORT statement Theoption, in this case, is needed to reserve space for two footer lines

After choosing Print on the Print List Output dialog window, the system displays the

Archive Parameters dialog box, since the import parameter ARCHIV_MODE sets the

archiving mode to Print and archive.

If the user enters 100 for the parameter P on the selection screen, the system

creates an SAP cover page and two print pages that look like this

First page:

Page 1

1

Trang 29

If the user chooses Execute on the selection screen instead of Execute + print, the

system displays the list as one page and without page footer on the output screen

Trang 30

Printing from within the Program

To start the printing process from within the program while creating a list, use the NEW-PAGEstatement with the PRINT ON option:

Syntax

NEW-PAGE PRINT ON [NEW-SECTION]

[<params> | PARAMETERS <pripar>]

[ARCHIVE PARAMETERS <arcpar>]

[NO DIALOG]

All output after this statement is placed on a new page (see Unconditional Page Break), and thesystem interprets all subsequent output statements as print statements In other words, startingfrom NEW-PAGE PRINT ON, the system no longer creates the list for display but for the spoolsystem

If you use the NEW-PAGE PRINT ON statement without the NEW-SECTION option while

already creating a list for the spool system, the statement is of no effect

If you use the NEW-SECTION option, you reset pagination (SY-PAGNO system field) to 1 If thesystem is already creating a list for the spool system, NEW-SECTION may have two effects:

• If the print parameters specified match the parameters of the current list and the printparameter PRNEW equals SPACE, the system does not create a new spool request

• If the print parameters specified do not match the parameters of the current list or theprint parameter PRNEW is unequal to SPACE, the system closes the current spoolrequest and creates a new spool request

The other options determine the print parameters (see below)

The end of a processing block (events during data retrieval or interactive events) automaticallyends the print process To stop creating the list for the spool system explicitly, use the PRINTOFF option of the NEW-PAGE statement:

Syntax

NEW-PAGE PRINT OFF

This statement creates a page break and sends the last page to the spool system Any outputstatements following this statement appear in the list on the output screen

Determining Print Parameters

To determine the print parameters for printed output following the NEW- PAGE PRINT ONstatement, use the options of the statement

You can use several options <params> to specify each print parameter (for example

DESTINATION <dest>) The keyword documentation explains each option Use the NO DIALOG

option to tell the system whether to display or suppress the Print List Output dialog box This

method of setting print parameters has its disadvantages, since the system does not checkwhether the parameters specified are complete Incomplete print parameters are detected only if

you use the Print List Output dialog box However this is not possible for background jobs If the

print parameters are incomplete and you use the NO DIALOG option, the system sends a

warning after the syntax check, but it does not stop processing This may cause unpredictableresults when executing the program

Trang 31

December 1999 951

SAP, therefore, recommends not to use the <params> options Use the PARAMETERS optioninstead, and the ARCHIVE PARAMETERS option if necessary To create the correspondingarguments <pripar> and <arcpar>, use the export parameters of the function module

GET_PRINT_PARAMETERS (see Setting Print Parameters from the Program) This is the onlymethod that guarantees a complete set of print parameters and an executable print request.Since the function module GET_PRINT_PARAMETERS has its own user dialog, always use the

NO DIALOG option in the NEW-PAGE PRINT ON statement

REPORT SAPMZTST NO STANDARD PAGE HEADING

DATA: VAL,

PRIPAR LIKE PRI_PARAMS,

ARCPAR LIKE ARC_PARAMS,

LAY(16), LINES TYPE I, ROWS TYPE I

CALL FUNCTION 'GET_PRINT_PARAMETERS'

IF VAL <> SPACE AND SY-SUBRC = 0

SET PF-STATUS 'PRINT'

WRITE ' Select a format!'

ENDIF

TOP-OF-PAGE DURING LINE-SELECTION

WRITE: 'Page', SY-PAGNO

Trang 32

This program immediately calls the function module GET_PRINT_PARAMETERS

without passing import parameters In the Print List Output dialog box, the user can

enter the print and archiving parameters for this program The system passes theseparameters, using the export parameters of the function module, to the structuresPRIPAR and ARCPAR To guarantee that the parameters are complete and

consistent, the program runs the user dialog and checks the return value of VALID.After completing the dialog, the system displays the following basic list:

In the status PRINT of the basic list, the function codes PORT and LAND are

assigned to the function keys F5 and F6, and to two pushbuttons of the applicationtoolbar (see Defining Individual User Interfaces) If the user chooses one of thesefunctions, the AT USER-COMMAND event occurs, assigning to the variables LAY,LINES, and ROWS the values for portrait or landscape output format and calling thesubroutine FORMAT

The subroutine FORMAT calls the function module GET_PRINT_PARAMETERS.When it does so, it passes the parameters PRIPAR and ARCPAR as import

parameters The values from LAY, LINES, and ROWS are assigned to the importparameters LAYOUT, LINE_COUNT and LINE_SIZE respectively There is no user

Trang 33

To view the stored spool requests, the user can choose System Services Print requests After choosing PORTRAIT, the spool request may look like this:

After choosing LANDSCAPE, however, the spool request looks like this:

Trang 34

Printing Lists from a Called Program

Druckparameter [Page 946]

To send the output of reports you call from within your program using SUBMIT to the spoolsystem, you must include the TO SAP-SPOOL option into the SUBMIT statement:

Syntax

SUBMIT <rep> TO SAP-SPOOL

[<params>|SPOOL PARAMETERS <pripar>]

[ARCHIVE PARAMETERS <arcpar>]

[WITHOUT SPOOL DYNPRO]

The SUBMIT statement is described in detail in the section Calling Executable Programs [Page1059] If you use the TO SAP-SPOOL option, the list is formatted for printing while it is beingcreated, and then sent to the spool system The remaining additions set the print parameters

Setting the Print Parameters

The same applies to setting the print parameters as described for the NEW-PAGE PRINT ONstatement (see Printing from within the Program)

Although you can set each print parameter individually using one of the <params> additions(refer to the keyword documentation ), or by using a user dialog in the SUBMIT statement, youshould only retrieve the parameters using the function module GET_PRINT_PARAMETERS.(For further information, refer to Setting Print Parameters from within the Program) The functionmodule GET_PRINT_PARAMETERS decouples the user dialog from the SUBMIT statement,and guarantees a complete parameter set even without executing the user dialog To determinethe parameters, use only the options SPOOL PARAMETERS and ARCHIVE PARAMETERSand, to suppress the user dialog of the SUBMIT statement, use the WITHOUT SPOOL DYNPROoption

The following executable program is connected to the logical database F1S:

REPORT SAPMZTS1

TABLES SPFLI

GET SPFLI

NEW-LINE

WRITE: SPFLI-MANDT, SPFLI-CARRID, SPFLI-CONNID,

SPFLI-CITYFROM, SPFLI-AIRPFROM, SPFLI-CITYTO,

SPFLI-AIRPTO, SPFLI-FLTIME, SPFLI-DEPTIME, SPFLI-ARRTIME,

SPFLI-DISTANCE, SPFLI-DISTID, SPFLI-FLTYPE

The following program calls SAPMZTS1 and sends the output to the spool system:REPORT SAPMZTST NO STANDARD PAGE HEADING

DATA: VAL,

PRIPAR LIKE PRI_PARAMS,

ARCPAR LIKE ARC_PARAMS

Trang 35

IF VAL <> SPACE AND SY-SUBRC = 0.

SUBMIT SAPMZTS1 TO SAP-SPOOL

SPOOL PARAMETERS PRIPAR

ARCHIVE PARAMETERS ARCPAR

WITHOUT SPOOL DYNPRO

ENDIF

After starting the program, the function module GET_PRINT_PARAMETERS triggers

a user dialog, displaying the area Output format of the Print List Output dialog

window filled with the values from the import parameters:

After the user has entered and confirmed the print parameters, SAPMZTS1 is called

In the call, the export parameters of GET_PRINT_PARAMETERS are passed asprint and archiving parameters SAPMZTS1 creates neither a screen display nor auser dialog It sends the created list directly to the spool system The user can view

the stored spool request choosing System Services Print requests. Using theoutput format specified above, the spool request may look like this:

Trang 37

December 1999 957

Print Control

You can manipulate the output of a list during the print process from within the executable

program (report) The statements SET MARGIN and PRINT-CONTROL, described in the topicsbelow, take effect only if the list is directly sent to the spool The statements do not affect a list

that is displayed on the screen and printed from there using List Print

Setting the Left and Upper Margin [Page 958]

Setting the Print Format [Page 960]

Indexing Print Lists for Optical Archiving [Page 964]

Trang 38

Determining Left and Upper Margins

To determine the size of the left and of the upper margin of a print page, use this statement:

Syntax

SET MARGIN <x> [<y>]

This statement causes the current print page to be sent to the spool system with <x> columns ofspace on the left page margin and, if specified, with <y> lines of space on the upper page

margin

The statement sets the contents of the system fields SY-MACOL and SY-MAROW to <x> and

<y> For printouts, these system fields determine the number of columns on the left margin andthe number of lines on the upper margin

The values you set apply to all subsequent pages, until you use another SET MARGIN

statement If you specify more than one SET MARGIN statement on one page, the systemalways uses the last one

The following executable program (report) is connected to the logical database F1S.REPORT SAPMZTST LINE-SIZE 60

TABLES SPFLI

SET MARGIN 5 3

GET SPFLI

WRITE: / SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM,

SPFLI-AIRPFROM, SPFLI-CITYTO, SPFLI-AIRPTO

If, after starting the report, the user chooses Execute on the selection screen, the

following list appears on the output screen:

The SET MARGIN statement has no effect on the display

If, after starting the report, the user chooses Execute + print on the selection screen,

the list is printed while it is created The user can view the stored spool request using

System Services Print requests:

Trang 39

December 1999 959

The list is shifted to the right by five columns and to the bottom by three lines

Trang 40

Determining the Print Format

BC - SAP-Druckhandbuch [Extern]

To determine the print format, use the PRINT-CONTROL statement:

Syntax

PRINT-CONTROL <formats> [LINE <lin>] [POSITION <col>]

Without using the options LINE and POSITION, this statement sets the print format specified in

<formats> for all characters that are printed starting from the current output position (systemfields SY-COLNO and SY-LINNO) The LINE option sets the print format to start from line <lin>.The POSITION option sets the print format to start from column <pos>

In <formats>, you can specify several different print formats The system converts the values into

a printer-independent code, the so-called print-control code When printing, the system translatesthe print-control code to printer-specific control characters of the selected printer

The table below lists the valid <formats> options and the corresponding print-control codes:

<formats> Code Meaning

CPI <cpi> CI<cpi> Characters per inch

LPI <lpi> LI<lpi> Lines per inch

COLOR BLACK CO001 Color black

COLOR RED CO002 Color red

COLOR BLUE CO003 Color blue

COLOR GREEN CO004 Color green

COLOR YELLOW CO005 Color yellow

COLOR PINK CO006 Color pink

LEFT MARGIN <lfm> LM<lfm> Space from the left margin

FONT <fnt> FO<fnt> Font

FUNCTION <code> <code> For directly specifying a code

There are many more print-control codes than <formats> options Therefore, you can specify anyprint-control code directly using the FUNCTION option

Use the print formats only to set formats that are either not possible or not

reasonable when formatting output for the output screen (for example, size

specifications or fonts) You should set all other formats as described in FormattingOptions [Page 806] or Formatting the Output [Page 867] These formats

automatically apply for printing as well as for display (provided the specified printersupports them)

To find the codes supported by a certain printer, choose Tools Administration Spool

Spool administration This takes you to the screen Spool Administration (transaction SPAD).

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

TỪ KHÓA LIÊN QUAN

TRÍCH ĐOẠN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN