Step-loops in Module Pool Programming

Click here for the step-by-step tutorial

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 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image