Sei sulla pagina 1di 12

Step-loops in Module Pool Programming

Step-loops in Module Pool Programming Step-loops are actually the predecessors to Table Control concepts and from programming point of view they are quite similar. Step loops are objects for screen table display that are added to a screen in the Screen Painter. They are preferred in cases of Radio-frequency applications where ALV displays or table controls pose a hindrance with respect to small displays and navigational issues. 1. Introduction to Step Loops This article throws light on the concept of Step-loops in Module screen programming. Step-loops are a very old concept and their use has been drastically reduced after the onset of Table control. But in certain applications such as Radio Frequency there is no other alternative than using step-loops. The pre-requisite to understanding and design of step-loops is to have a fair idea over module pool programming. Step-loops are of 2 types: Fixed Step-loops Incase of Fixed step-loops, the number of lines of records would be fixed as when designed. You can increase the number of records at runtime. Although the number of records can be decreased as per programming logic if number of records in table to be displayed are less than fixed number. Variable Step-loops In case of variable step-loops, at runtime we can increase the number of repetitive blocks depending on the size of the screen. 2. Requirement to be designed We will look into a requirement where we have display records in a step-loop on screen in such a manner that we will keep the step-loop fixed to 5 rows for simplicity and based on the number of records; the records will flow onto the next screens. Also if there are only 2 records to be displayed then only 2 rows will appear on the screen with no buttons for navigation. So the navigation buttons Page Up and Page Down would be handling dynamically based on the records to be displayed. 3. How to design Step-loops? A step loop is defined in the screen painter transaction SE51; these are unlike the table control elements which can be spread over multiple lines and can be combined into one group which would be repeated within the step loop. It is important to note that whichever attributes we assign to the first group are replicated to the entire step loop. In the screen painter, we can define whether the size of a step loop is fixed or variable. The vertical size of variable step loops changes if the user changes the vertical size of the window. For every screen, any number of fixed step loops can be defined but only one variable step loop. Every vertical size change triggers PAI if a variable step loop is defined on the screen. For fixed step loops the number of repetition groups has to be predefined. To place step-loops in the module pool screen, we need to place input/output fields for the number of columns required and text-fields for the number of column headers. As described, we would first place the input-output fields and text-fields as per the number of columns to be displayed as shown below:

Later in order to convert these into step-loops, select the input/output fields together for all required columns and follow the steps as shown below in the screenshot with the menu path as Edit -> Grouping -> Step Loop -> Define.

In the below screenshot, Column1 and Column2 denote the column headers, Page up and Down are the buttons which would help us in scrolling the records. In this case we have kept step-loop as fixed up to 5 rows for simplicity. The column1 and column 2 are simple text fields.

On double Clicking you will find the following step-loop property where Height is restricted to 5 rows. See below screenshot.

The step-loop column field properties would be as below:

The buttons Page up and Page down would be given function codes as PGUP and PGDN and their properties would be as follows:

4. Flow-logic for Step-loops Once the processing for the records to be displayed is done, then in the flow logic of the screen 0100 which we have designed we need to include the code shown below:

Its important to note that the LOOP must exist for every step loop, both in the PBO and the PAI processing block. During the loops, the contents of the step loop are transported back and forth between identically-named fields of the ABAP program and the screen. Note that step loop fields defined with Dictionary reference must be defined in the ABAP program, as before, with TABLES as interface work areas. The order the step loops are processed in the individual loops of the flow logic depends on the step loop order on the screen. The order on the screen depends primarily on the lines and secondarily on the rows. The system fields SY-STPL and SY-LOOPC are also filled within the loops. In the PBO module we have looped the cursor C from N1 to N2 since we want to display on screen only as many as rows as many number of records are there to be present on the screen. Thus if there are only 2 records then N1 = 1 and N2 =2; so that 2 step loops appear on the screen. This would ensure dynamicity of the step-loops. The table structure for the records to be displayed in step-loops would be as follows:

a. The module STATUS_0100 would contain the PF status and PF Title to be maintained in the screen.

In the PF status needs to be activated for function keys BACK, PGUP and PGDN so that these buttons on the keyboard can be used and so also on the Radio-frequency (RF) application handset.

b. The module PGUP_DOWN contains the logic for navigation from one page to another depending on the number of records to be displayed. This would basically contain the logic to hide/show the buttons for page up and down depending on the records which overflow on the page. For example, on first page the button for page up would be hidden and on last page the button for page down would be hidden. c. The module TRANSP_ITAB_OUT contains the logic to transfer the contents of the internal table into the step-loop screen elements during PBO processing.

d. The module TRANSP_ITAB_IN contains the logic to transfer the contents from internal table into the step-loop screen elements during PAI processing.

e. The module USER_COMMAND_0100 would help to handle the navigation and processing at the click on the buttons Page Up and Page Down. Please see source code extract for further details for handling the button clicks. REPORT ystep_loop_test. * Number of records to be displayed PARAMETERS : p_num TYPE i. * Types to declare the internal table for records TYPES: BEGIN OF t_itab, col1 TYPE i, col2 TYPE i, END OF t_itab. * Internal table for the records DATA: itab TYPE STANDARD TABLE OF t_itab, * Work area for the records wa LIKE LINE OF itab. DATA: * Index of the row of step-loop idx TYPE i, * Current Line to be displayed line TYPE i, * Total Rows of step-loop to be displayed on single page lines TYPE i, * Final Limit of step loop rows that can be displayed limit TYPE i, * Cursor position c TYPE i, * Lower limit of the record index to be displayed on a page n1 TYPE i VALUE 1, * Upper limit of the record index to be displayed on a page n2 TYPE i, * Variable to handle next page navigation y_v_next TYPE i, * Variable to handle previous page navigation y_v_prev TYPE i, y_v_limit TYPE i. DATA: ok_code TYPE sy-ucomm, save_ok TYPE sy-ucomm.

START-OF-SELECTION. * Building the records to be displayed as per the selection screen entry DO p_num TIMES. wa-col1 = sy-index. wa-col2 = sy-index ** 2. APPEND wa TO itab. ENDDO. IF p_num < 0. n2 = p_num. ELSE. n2 = 5. ENDIF.

CALL SCREEN 100. *----------------------------------------------------------------------* * MODULE status_0100 OUTPUT *----------------------------------------------------------------------* * *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_100'. ENDMODULE. "status_0100 OUTPUT *----------------------------------------------------------------------* * MODULE transp_itab_out OUTPUT *----------------------------------------------------------------------* * *----------------------------------------------------------------------* MODULE transp_itab_out OUTPUT. idx = sy-stepl + line. READ TABLE itab INTO wa INDEX idx. ENDMODULE. "transp_itab_out OUTPUT *----------------------------------------------------------------------* * MODULE transp_itab_in INPUT *----------------------------------------------------------------------* * *----------------------------------------------------------------------* MODULE transp_itab_in INPUT. lines = sy-loopc. idx = sy-stepl + line. MODIFY itab FROM wa INDEX idx. ENDMODULE. "transp_itab_in INPUT *----------------------------------------------------------------------* * MODULE user_command_0100 INPUT *----------------------------------------------------------------------* * *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. DATA : y_v_index TYPE sy-index. DATA : y_lv_d TYPE f, y_lv_div TYPE i, y_curr_p_num TYPE i. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'BACK'. LEAVE TO SCREEN 0. * When Page Down is Hit WHEN 'PGDN'. * Number of screens required for output if 5 records per screen y_lv_d = p_num / 5. y_lv_div = CEIL( y_lv_d ). y_curr_p_num = y_lv_div * 5. y_v_index = y_v_next + 1. IF y_v_next < y_lv_div. y_v_next = y_v_next + 1. ELSE. y_v_next = y_lv_div. ENDIF. y_v_prev = y_v_next. IF y_v_next <> y_lv_div. n2 = p_num - 5 * y_v_next. IF n2 > 5. n2 = 5 * y_v_next. ENDIF. n1 = 1.

line = line + lines. limit = y_curr_p_num - lines. IF line > limit. line = limit. ENDIF. ELSE. y_v_next = y_v_next - 1. ENDIF. * When Page Up is Hit WHEN 'PGUP'. n2 = 5 * y_v_next. IF n1 < 0. n1 = 1. ENDIF. IF y_v_next > 0. y_v_next = y_v_next - 1. ELSE. y_v_next = 0. ENDIF. y_v_prev = y_v_next. IF line NE 0 AND y_curr_p_num GT 5. line = y_v_next * 5. ELSE. line = 0. y_v_index = y_v_next - 1. ENDIF. IF line < 0. line = 0. ENDIF. ENDCASE. ENDMODULE. "user_command_0100 INPUT *----------------------------------------------------------------------* * MODULE cancel INPUT *----------------------------------------------------------------------* * *----------------------------------------------------------------------* MODULE cancel INPUT. LEAVE PROGRAM. ENDMODULE. "cancel INPUT *&---------------------------------------------------------------------* *& Module PGUP_DOWN OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE pgup_down OUTPUT. DATA : y_v_div TYPE i, y_v_d TYPE f, y_v_temp TYPE i. DESCRIBE TABLE itab[] LINES p_num. y_v_d = p_num / 5. y_v_limit = CEIL( y_v_d ). y_v_temp = y_v_limit - 1. IF p_num LE 5. PERFORM y_f_hide_field USING 'RLMOB-PPGDN'. PERFORM y_f_hide_field USING 'RLMOB-PPGUP'. ELSEIF y_v_next = y_v_limit . PERFORM y_f_hide_field USING 'RLMOB-PPGDN'. PERFORM y_f_show_field USING 'RLMOB-PPGUP'. ELSEIF y_v_prev IS INITIAL. PERFORM y_f_hide_field USING 'RLMOB-PPGUP'. ELSEIF y_v_next GT y_v_limit. PERFORM y_f_hide_field USING 'RLMOB-PPGDN'.

ELSEIF y_v_temp = y_v_next. PERFORM y_f_hide_field USING 'RLMOB-PPGDN'. ENDIF. ENDMODULE. " PGUP_DOWN OUTPUT *&---------------------------------------------------------------------* *& Form Y_F_HIDE_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0372 text *----------------------------------------------------------------------* FORM y_f_hide_field USING value(p_name). LOOP AT SCREEN. IF screen-name = p_name. screen-active = '0'. screen-invisible = '1'. MODIFY SCREEN. EXIT. ENDIF. ENDLOOP. ENDFORM. " Y_F_HIDE_FIELD *&---------------------------------------------------------------------* *& Form Y_F_SHOW_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0388 text *----------------------------------------------------------------------* FORM y_f_show_field USING value(p_name). LOOP AT SCREEN. IF screen-name = p_name. screen-active = '1'. MODIFY SCREEN. EXIT. ENDIF. ENDLOOP. ENDFORM. " Y_F_SHOW_FIELD

Potrebbero piacerti anche