BC ABAP Programming PHẦN 7 pot

153 240 0
BC ABAP Programming PHẦN 7 pot

Đ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

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. [...]... contains event 936 December 1999 SAP AG BC - ABAP Programming Starting Lists from Screen Processing 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 December 1999 9 37 BC - ABAP Programming SAP AG Calling Screens... December 1999 941 BC - ABAP Programming SAP AG Printing Lists Printing Lists Drucksteuerung [Page 9 57] 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... ok_code CLEAR ok_code CASE save_ok 938 December 1999 SAP AG BC - ABAP Programming Calling Screens from List Processing 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 e0 47( sabapdocu) ELSE SET SCREEN 200 ENDIF ENDCASE ENDMODULE MODULE... December 1999 SAP AG BC - ABAP Programming Calling Screens from List Processing Airline Flight number Flight date Price Local currency Airline type Max occupancy Occupancy Save 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... 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 942 December 1999 SAP AG BC - ABAP Programming Printing a List after Creating it Printing a List after Creating it When printing a list after creating it, you do not use any of the print-specific statements... User''s Guide' NEW_LIST_ID = 'X' RECEIVER = 'KELLERH' RELEASE ='' SAP_COVER_PAGE = 'X' START-OF-SELECTION DO P TIMES WRITE / SY-INDEX ENDDO TOP-OF-PAGE WRITE: 'Page', SY-PAGNO ULINE December 1999 9 47 BC - ABAP Programming SAP AG Execute and Print END-OF-PAGE 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)... 948 December 1999 SAP AG BC - ABAP Programming Execute and Print 2 3 49 50 -End of 1 Second page: Page 2 -58 59 60 99 100 -End of 2 On each page, you can output up to 54 lines, including page header and footer lines Note that the system triggers page breaks and creates page headers and footers exactly as described in Creating Complex Lists [Page 8 17] If the user chooses Execute... 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 December 1999 931 BC - ABAP Programming SAP AG Modifying List Lines 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... 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: December 1999 939 BC - ABAP Programming SAP AG Calling Screens from List Processing Airline Flight number Flight date Continue and its flow logic is: PROCESS BEFORE OUTPUT MODULE STATUS_0100 PROCESS AFTER INPUT MODULE CANCEL... 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 932 December 1999 SAP AG BC - ABAP Programming Lists and Screens 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 . Detail Lists [Page 925] Set the Cursor from within the Program [Page 9 27] Modify List Lines [Page 930] SAP AG BC - ABAP Programming Scrolling in Detail Lists December 1999 925 Scrolling in Detail. function codes within the AT USER-COMMAND event. SAP AG BC - ABAP Programming Setting the Cursor from within the Program December 1999 9 27 Setting the Cursor from within the Program You can set. AT LINE-SELECTION. The program also contains event SAP AG BC - ABAP Programming Starting Lists from Screen Processing December 1999 9 37 blocks for TOP-OF-PAGE and TOP-OF-PAGE DURING LINE-SELECTION,

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

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan