Defining a Range in Module Pool Program

...Previous

Step10 : Write the following code…………..
*&---------------------------------------------------------------------*
*& Module Pool       ZSAPMZ_RANGE_IN_MPP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM  ZSAPMZ_RANGE_IN_MPP.
TYPE-POOLS:SLIS.
TABLES : MARA .
DATA :MLOW(18),MHIGH(18).
DATA :MLOW1(18),MHIGH1(18).
DATA: BEGIN OF T_MARA OCCURS 1,
        MATNR TYPE MARA-MATNR,
        ERSDA TYPE MARA-ERSDA,
        ERNAM TYPE MARA-ERNAM,
        PSTAT TYPE MARA-PSTAT,
        MBRSH TYPE MARA-MBRSH,
      END OF T_MARA.
DATA : BEGIN OF RANGE OCCURS 0 ,
       SIGN(1),
       OPTION(2),
       LOW(18),
       HIGH(18),
       END OF RANGE .
DATA : T_FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV ,
       W_FCAT TYPE SLIS_FIELDCAT_ALV ,
       W_LAYO TYPE SLIS_LAYOUT_ALV .
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
  CASE SY-UCOMM.
    WHEN ''."FC-CODE OF ENTER BUTTON
      CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' "CONVERSION ROUTINE FOR MLOW
        EXPORTING
          INPUT              = MLOW
       IMPORTING
         OUTPUT             = MLOW1
       EXCEPTIONS
         LENGTH_ERROR       = 1
         OTHERS             = 2
                .
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'"CONVERSION ROUTINE FOR MHIGH
        EXPORTING
          INPUT              = MHIGH
       IMPORTING
         OUTPUT             = MHIGH1
       EXCEPTIONS
         LENGTH_ERROR       = 1
         OTHERS             = 2
                .
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
******************************************************************
* LOGICALLY BUILD A INTERNAL TABLE (RANGE)
******************************************************************
      RANGE-SIGN = 'I'. " I OR E
      RANGE-OPTION = 'BT'.
      RANGE-LOW = MLOW1 .
      RANGE-HIGH = MHIGH1 .
      APPEND RANGE ."APPEND DATA IN INTERNAL TABLE
******************************************************************
      PERFORM FETCH_DATA .
      PERFORM DISPLAY_DATA .
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FETCH_DATA .
          SELECT  MATNR
                  ERNAM
                  ERSDA
                  PSTAT
                  MBRSH
                  FROM MARA
                  INTO CORRESPONDING FIELDS OF TABLE T_MARA
                  WHERE MATNR IN RANGE .
ENDFORM.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
  LEAVE TO LIST-PROCESSING .
  W_FCAT-TABNAME = 'MARA'.
  W_FCAT-FIELDNAME = 'MATNR'.
  W_FCAT-SELTEXT_M = 'Material No'.
  APPEND w_fcat to t_Fcat .
    W_FCAT-TABNAME = 'MARA'.
  W_FCAT-FIELDNAME = 'ERSDA'.
  W_FCAT-SELTEXT_M = 'Created On'.
  APPEND w_fcat to t_Fcat .
    W_FCAT-TABNAME = 'MARA'.
  W_FCAT-FIELDNAME = 'ERNAM'.
  W_FCAT-SELTEXT_M = 'Name of Person'.
  APPEND w_fcat to t_Fcat .
    W_FCAT-TABNAME = 'MARA'.
  W_FCAT-FIELDNAME = 'PSTAT'.
  W_FCAT-SELTEXT_M = 'Maintenance status'.
  APPEND w_fcat to t_Fcat .
    W_FCAT-TABNAME = 'MARA'.
  W_FCAT-FIELDNAME = 'MBRSH'.
  W_FCAT-SELTEXT_M = 'Industry sector'.
  APPEND w_fcat to T_FCAT.
  W_LAYO-ZEBRA = 'X'.
  W_LAYO-COLWIDTH_OPTIMIZE = 'X'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME             = 'MARA'
*   I_BACKGROUND_ID                   = ' '
     I_GRID_TITLE                      ='MATERIAL REPORT'
*   I_GRID_SETTINGS                   =
   IS_LAYOUT                         = W_LAYO
   IT_FIELDCAT                       = T_FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
    TABLES
      T_OUTTAB                          = T_MARA[]
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " DISPLAY_DATA

Step11: After coding save & activate the program.

Step12: go to T-code SE93 and create T-code for program ZSAPMZ_RANGE_IN_MPP

And fill required information

Step13: Write program name and screen no of program and save it .

Step14 : Execute the t-code  ZMPP_RANGE.

Step15: After filling Material No range, Press Enter Button.

Result:

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