Step_loop

Embed Size (px)

Citation preview

  • 7/27/2019 Step_loop

    1/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 screenin the Screen Painter. They are preferred in cases of Radio-frequency applications where ALVdisplays 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 avery old concept and their use has been drastically reduced after the onset of Table control. But incertain 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 poolprogramming.

    Step-loops are of 2 types:

    Fixed Step-loopsIncase of Fixed step-loops, the number of lines of records would be fixed as when designed. You canincrease the number of records at runtime. Although the number of records can be decreased as perprogramming logic if number of records in table to be displayed are less than fixed number.

    Variable Step-loopsIn case of variable step-loops, at runtime we can increase the number of repetitive blocks dependingon 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 amanner that we will keep the step-loop fixed to 5 rows for simplicity and based on the number ofrecords; 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 nobuttons for navigation. So the navigation buttons Page Up and Page Down would be handlingdynamically 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 controlelements which can be spread over multiple lines and can be combined into one group which wouldbe repeated within the step loop. It is important to note that whichever attributes we assign to the firstgroup are replicated to the entire step loop.

    In thescreen painter, we can define whether the size of a step loop is fixed or variable. The verticalsize of variable step loops changes if the user changes the vertical size of the window. For everyscreen, any number of fixed step loops can be defined but only one variable step loop. Every verticalsize change triggers PAI if a variable step loop is defined on the screen. For fixed step loops thenumber 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 ofcolumns 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:

    http://help.sap.com/saphelp_nw04/helpdata/en/d1/801c13454211d189710000e8322d00/frameset.htmhttp://help.sap.com/saphelp_nw04/helpdata/en/d1/801c13454211d189710000e8322d00/frameset.htmhttp://help.sap.com/saphelp_nw04/helpdata/en/d1/801c13454211d189710000e8322d00/frameset.htm
  • 7/27/2019 Step_loop

    2/12

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

  • 7/27/2019 Step_loop

    3/12

    In the below screenshot, Column1 and Column2 denote the column headers, Page up and Down arethe buttons which would help us in scrolling the records. In this case we have kept step-loop as fixedup 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.

  • 7/27/2019 Step_loop

    4/12

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

  • 7/27/2019 Step_loop

    5/12

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

  • 7/27/2019 Step_loop

    6/12

    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 0100which we have designed we need to include the code shown below:

  • 7/27/2019 Step_loop

    7/12

    Its important to note that the LOOP must exist for every step loop, both in the PBO and the PAIprocessing block. During the loops, the contents of the step loop are transported back and forthbetween identically-named fields of the ABAP program and the screen. Note that step loop fieldsdefined with Dictionary reference must be defined in the ABAP program, as before, with TABLES asinterface work areas. The order the step loops are processed in the individual loops of the flow logicdepends on the step loop order on the screen. The order on the screen depends primarily on the linesand secondarily on the rows. The system fields SY-STPL and SY-LOOPC are also filled within theloops.

    In the PBO module we have looped the cursor C from N1 to N2 since we want to display on screenonly as many as rows as many number of records are there to be present on the screen. Thus if thereare only 2 records then N1 = 1 and N2 =2; so that 2 step loops appear on the screen. This wouldensure 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 thescreen.

  • 7/27/2019 Step_loop

    8/12

    In the PF status needs to be activated for function keys BACK, PGUP and PGDNso 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 anotherdepending on the number of records to be displayed.

    This would basically contain the logic to hide/show the buttons for page up and downdepending on the records which overflow on the page. For example, on first page the buttonfor 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 internaltable into the step-loop screen elements during PBO processing.

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

  • 7/27/2019 Step_loop

    9/12

    e. The module USER_COMMAND_0100 would help to handle the navigation and processing atthe click on the buttons Page Up and Page Down. Please see source code extract for furtherdetails for handling the button clicks.

    REPORT ystep_loop_test.

    * Number of records to be displayedPARAMETERS : p_num TYPE i.

    * Types to declare the internal table for recordsTYPES: BEGIN OF t_itab,

    col1 TYPE i,col2 TYPE i,

    END OF t_itab.* Internal table for the recordsDATA: itab TYPE STANDARD TABLE OF t_itab,* Work area for the records

    wa LIKE LINE OF itab.DATA:

    * Index of the row of step-loopidx TYPE i,

    * Current Line to be displayedline TYPE i,

    * Total Rows of step-loop to be displayed on single pagelines TYPE i,

    * Final Limit of step loop rows that can be displayedlimit TYPE i,

    * Cursor positionc TYPE i,

    * Lower limit of the record index to be displayed on a pagen1 TYPE i VALUE 1,

    * Upper limit of the record index to be displayed on a page

    n2 TYPE i,* Variable to handle next page navigationy_v_next TYPE i,

    * Variable to handle previous page navigationy_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.

  • 7/27/2019 Step_loop

    10/12

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

    * Number of screens required for output if 5 records per screeny_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.

  • 7/27/2019 Step_loop

    11/12

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

  • 7/27/2019 Step_loop

    12/12

    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