Adding Button to REPORT to call a ALV report

Hi,
      I have a standard report RPT1. In this report I have a button in the application toolbar which I created using the statement.
<b>SELECTION-SCREEN FUNCTION KEY 1.</b>
         When I click on this button it should take me to an ALV report which is coded in the <u>same program RPT1</u> in a <i>subroutine f_alv_sub</i>.
     But when I click on the button it does not take me to the report.
      How do we go about it? Points will be awarded to the best answer.THANKS.
                    regards,
                       dev.

Hi,
Check this sample code.
tables:sscrfields. "Fields on selection screens
selection-screen function key 1.
selection-screen function key 2.
Initialization.
  sscrfields-functxt_01 = 'Report'.
  sscrfields-functxt_02 = 'Exit'.
at selection-screen.
   if sscrfields-ucomm = 'FC01'.
  perform f_alv_sub.
   elseif sscrfields-ucomm = 'FC02'.
   endif.
Hope it helps.

Similar Messages

  • How to call an alv report from another program and return back

         Hello ,
    I am calling one abap program (Prgm B) from another program (Prgrm A).
    Here, Prgm B is an ALV report. I have fetch some data from Prgem B that gets stored in an internal table.
    Now, I am using below code in Prgrm A,
      SUBMIT Prgrm B VIA SELECTION-SCREEN
                          WITH SELECTION-TABLE rspar
                          EXPORTING LIST TO MEMORY
                          AND RETURN.
    When Prgrm A executed, it lead me to selection screen of Prgrm B and when I click F8, it shows me the report output, In short, it doesnt return back to Prgrm A. It ends up showing me the alv report if Prgrm B even afetr using RETURN statement.
    I want to get back to Prgrm A by fetching some data from Prgrm B.
    Please let me know, if i am missing something.
    Regards,
    Seema

    Hi Seema,
    Refer below code.
    DATA: v_matnr LIKE mara-matnr.
    DATA: t_listobject TYPE abaplist OCCURS 0 WITH HEADER LINE.
    DATA: t_mara TYPE mara OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF t_ascilist OCCURS 0,
             line(200).
    DATA: END OF t_ascilist.
    data var(3) type c.
    SELECT-OPTIONS: s_matnr FOR v_matnr.
    var = '  3'.
    START-OF-SELECTION.
       SUBMIT ztestaks1 WITH s_matnr IN s_matnr EXPORTING LIST TO MEMORY
       AND RETURN.
       CALL FUNCTION 'LIST_FROM_MEMORY'
            TABLES
                 listobject = t_listobject
            EXCEPTIONS
                 not_found  = 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.
       ELSE.
         CALL FUNCTION 'LIST_TO_ASCI'
    *     EXPORTING
    *       LIST_INDEX               = -1
    *       WITH_LINE_BREAK          = ' '
           TABLES
             listasci                 = t_ascilist
             listobject               = t_listobject
           EXCEPTIONS
             empty_list               = 1
             list_index_invalid       = 2
             OTHERS                   = 3.
         IF sy-subrc <> 0.
           MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
         ELSE.
           WRITE:/ 'Below are the lines from the submitted program.'.
           LOOP AT t_ascilist.
             WRITE:/ t_ascilist-line.
           ENDLOOP.
           SKIP 2.
         ENDIF.
       ENDIF.
       IMPORT t_mara FROM MEMORY ID 'T_MARA'.
       WRITE:/
    'Here is the output from the table exported from the submitted program.'
       LOOP AT t_mara.
         WRITE:/ t_mara-matnr.
       ENDLOOP.
    Submitted program
    REPORT  ZTESTAKS1.
    DATA: v_matnr LIKE mara-matnr,
           v_maktx LIKE makt-maktx.
    DATA: t_mara TYPE mara OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF t_makt OCCURS 0,
             matnr LIKE makt-matnr.
    DATA: END OF t_makt.
    SELECT-OPTIONS: s_matnr FOR v_matnr,
                     s_maktx FOR v_maktx.
    START-OF-SELECTION.
       SELECT matnr INTO TABLE t_makt
                    FROM makt
                   WHERE matnr IN s_matnr
                     AND maktx IN s_maktx.
    if not t_makt[] is initial.
       SELECT * FROM mara
                INTO TABLE t_mara FOR ALL ENTRIES IN t_makt
               WHERE matnr = t_makt-matnr.
    endif.
       EXPORT t_mara TO MEMORY ID 'T_MARA'.
       WRITE:/ 'This list is from the submitted program'.
       SKIP 1.
       LOOP AT t_mara.
         WRITE:/ t_mara-mtart.
       ENDLOOP.
    Hopes this helps you.
    Thanks,
    Ashok.

  • Historical Report CSQ Call Distribution Summary Report

    You can filter the Contact Service Queue Call Distribution Summary Report by either of these parameters:
    -  Contact Service Queue Names
    -  Time Interval (sec) T
    can we filter this report with both paramters mentioned above together(CSQ & Time)
    or at least can we change the default value of "Time Interval(sec) T" from 15 sec to another value?
    it is urgent,
    regards,

    Excuse me but it seem you didn’t get my point,
    My question is to have one report filtered by two parameters simultaneously, CSQ name + Time Interval.
    and I was guessing, if there is no way to choose both parameters simultaneously in filtering the same report, if there is a way to set the default time parameter to for example 10 sec, so in a way if i choose the parameter CSQ name the interval taken is 10 sec and not 15 second (the default value for time).

  • Adding button in the secondary list and alv grid

    Hi all ,
                i have devloped an alv grid interactive report as below, my problem is i want to add some button in the secondary list and do some interactions. but i dont know how to do that. i m sending u my code below ,,, plzz suggest what can be done do add that.
    <code>
    *& Report  Z_demo_SALESDOC
    REPORT  z_demo_salesdoc.
    TABLES: vbak, vbap.
    TYPE-POOLS:slis.
    DATA: BEGIN OF it_vbak OCCURS 0,
           vbeln TYPE vbak-vbeln,
           ernam TYPE vbak-ernam,
           erdat TYPE vbak-erdat,
           auart TYPE vbak-auart,
           END OF it_vbak.
    DATA: BEGIN OF it_vbap OCCURS 0,
           vbeln TYPE vbap-vbeln,
           posnr TYPE vbap-vbeln,
           matnr TYPE vbap-matnr,
           zmeng TYPE vbap-zmeng,
           netwr TYPE vbap-netwr,
           END OF it_vbap.
    DATA:it_event TYPE slis_t_event.
    DATA: t_field TYPE slis_t_fieldcat_alv,
          w_field TYPE slis_fieldcat_alv,
          t_field1 TYPE slis_t_fieldcat_alv,
          w_field1 TYPE slis_fieldcat_alv,
          w_layout TYPE slis_layout_alv,
          t_sort TYPE slis_t_sortinfo_alv,
          w_sort TYPE slis_sortinfo_alv.
    CONSTANTS: c_top_of_page  TYPE slis_formname VALUE 'TOP_OF_PAGE',
               c_usercommand  TYPE slis_formname VALUE 'USER_COMMAND'.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: s_vbeln FOR vbak-vbeln MODIF ID m1,
                    s_erdat FOR vbak-erdat MODIF ID m2.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
    PARAMETERS:rb1 RADIOBUTTON GROUP g1 USER-COMMAND us1,
               rb2 RADIOBUTTON GROUP g1 DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK B2.
    AT SELECTION-SCREEN OUTPUT.
      IF rb1 = 'X'.
        LOOP AT SCREEN.
          IF screen-group1    = 'M1'.
         IF screen-name    CS 'S_VBELN'.
            screen-active    = '0'.
           screen-input     = '0'.
          screen-output    = '0'.
          screen-invisible = '1'.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF rb2 = 'X'.
        LOOP AT SCREEN.
          IF screen-group1    = 'M2'.
            screen-active    = '0'.
           screen-input     = '0'.
          screen-output    = '0'.
          screen-invisible = '0'.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
    AT SELECTION-SCREEN.
      DATA: v_vbeln LIKE vbak-vbeln.
      SELECT SINGLE vbeln
                      FROM vbak
                      INTO (v_vbeln)
                      WHERE vbeln IN s_vbeln .
      IF sy-subrc <> 0.
        MESSAGE e001(q) WITH 'Invalid Sales document'.
      ENDIF.
      DATA: v_erdat LIKE vbak-erdat.
      SELECT SINGLE erdat
                      FROM vbak
                      INTO (v_erdat)
                      WHERE erdat IN s_erdat.
      IF sy-subrc <> 0.
        MESSAGE e001(q) WITH 'No document available with given date'.
      ENDIF.
    START-OF-SELECTION.
      PERFORM get_data_vbak.
      PERFORM build_field_catalog.
    PERFORM fill_event.
      PERFORM print_data_vbak.
    END-OF-SELECTION.
    *&      Form  get_data_vbak
          text
    -->  p1        text
    <--  p2        text
    FORM get_data_vbak .
      SELECT vbeln ernam erdat auart
                                FROM vbak
                                INTO TABLE it_vbak
                                WHERE vbeln IN s_vbeln AND erdat IN s_erdat.
    ENDFORM.                    " get_data_vbak
    *&      Form  build_field_catalog
          text
    -->  p1        text
    <--  p2        text
    FORM build_field_catalog .
      w_field-col_pos = 1.
      w_field-fieldname = 'VBELN'.
      w_field-tabname = 'IT_VBAK'.
      w_field-seltext_m = 'Sales Order'.
      w_field-emphasize = 'C710'.
      APPEND w_field TO t_field.
      CLEAR w_field.
      w_field-col_pos = 2.
      w_field-fieldname = 'ERNAM'.
      w_field-tabname = 'IT_VBAK'.
      w_field-seltext_m = 'Created by'.
      w_field-emphasize = 'C710'.
      APPEND w_field TO t_field.
      CLEAR w_field.
      w_field-col_pos = 3.
      w_field-fieldname = 'ERDAT'.
      w_field-tabname = 'IT_VBAK'.
      w_field-seltext_m = 'Created Date'.
      w_field-emphasize = 'C710'.
      APPEND w_field TO t_field.
      CLEAR w_field.
      w_field-col_pos = 4.
      w_field-fieldname = 'AUART'.
      w_field-tabname = 'IT_VBAK'.
      w_field-seltext_m = 'Order type'.
      w_field-emphasize = 'C710'.
      APPEND w_field TO t_field.
      CLEAR w_field.
      w_sort-spos = 1.
      w_sort-fieldname = 'VBELN'.
      w_sort-up = 'X'.
      APPEND w_sort TO t_sort.
      w_layout-colwidth_optimize = 'X'.
    ENDFORM.                    " build_field_catalog
    *&      Form  user_command
          text
         -->RF_UCOMM     text
         -->RS_SELFIELD  text
    FORM user_command USING rf_ucomm    TYPE sy-ucomm
                            rs_selfield TYPE slis_selfield.
      CASE rf_ucomm.
        WHEN '&IC1'.
          IF rs_selfield-fieldname = 'VBELN'.
            READ TABLE it_vbak INDEX rs_selfield-tabindex.
            IF sy-subrc = 0.
              PERFORM get_data_vbap.
              PERFORM build_field_catalog2.
              PERFORM print_field_data.
            ENDIF.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  print_data_vbak
          text
    -->  p1        text
    <--  p2        text
    FORM print_data_vbak .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = sy-repid
      I_CALLBACK_PF_STATUS_SET          = ' '
       i_callback_user_command           = 'USER_COMMAND'
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  = I_STRUCTURE_NAME
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      = I_GRID_TITLE
      I_GRID_SETTINGS                   = I_GRID_SETTINGS
         is_layout                         = w_layout
       it_fieldcat                       = t_field[]
      IT_EXCLUDING                      = IT_EXCLUDING
      IT_SPECIAL_GROUPS                 = IT_SPECIAL_GROUPS
       it_sort                           = t_sort
      IT_FILTER                         = IT_FILTER
      IS_SEL_HIDE                       = IS_SEL_HIDE
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        = IS_VARIANT
      it_events                         = it_event[]
      IT_EVENT_EXIT                     = IT_EVENT_EXIT
      IS_PRINT                          = IS_PRINT
      IS_REPREP_ID                      = 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_ALV_GRAPHICS
      IT_HYPERLINK                      = IT_HYPERLINK
      IT_ADD_FIELDCAT                   = IT_ADD_FIELDCAT
      IT_EXCEPT_QINFO                   = IT_EXCEPT_QINFO
      IR_SALV_FULLSCREEN_ADAPTER        = IR_SALV_FULLSCREEN_ADAPTER
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           = E_EXIT_CAUSED_BY_CALLER
      ES_EXIT_CAUSED_BY_USER            = ES_EXIT_CAUSED_BY_USER
        TABLES
          t_outtab                          = it_vbak
    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.                    " print_data_vbak
    *&      Form  fill_event
          text
    FORM fill_event .
      DATA : st_event TYPE slis_alv_event.
    *- Clear.
      CLEAR : st_event, it_event[].
    *- Local variable
      DATA : l_tabix TYPE sy-tabix.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = it_event
        EXCEPTIONS
          list_type_wrong = 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.
    *- Read event table
      READ TABLE it_event WITH KEY name = slis_ev_user_command
                           INTO st_event.
    *- Clear
      CLEAR l_tabix.
      l_tabix = sy-tabix.
    *- Check subrc
      IF sy-subrc = 0.
        st_event-form = c_usercommand.
    *- Modify
        MODIFY it_event FROM st_event INDEX l_tabix.
    *- Clear
        CLEAR st_event.
      ENDIF.
    ENDFORM.                    " fill_event
    *&      Form  get_data_vbap
          text
    FORM get_data_vbap .
      IF NOT it_vbak[] IS INITIAL.
        SELECT vbeln
               posnr
               matnr
               zmeng
               netwr
            FROM vbap
            INTO TABLE it_vbap
            WHERE vbeln = it_vbak-vbeln.
        IF sy-subrc = 0.
          SORT it_vbap BY vbeln.
        ENDIF.
      ENDIF.
    ENDFORM.                    " get_data_vbap
    *&      Form  build_field_catalog2
          text
    FORM build_field_catalog2 .
      CLEAR:t_field1,w_field1.
      w_field1-col_pos = 1.
      w_field1-fieldname = 'VBELN'.
      w_field1-tabname = 'IT_VBAP'.
      w_field1-seltext_m = 'Sales Order'.
      w_field1-emphasize = 'C710'.
      APPEND w_field1 TO t_field1.
      CLEAR w_field1.
      w_field1-col_pos = 2.
      w_field1-fieldname = 'POSNR'.
      w_field1-tabname = 'IT_VBAP'.
      w_field1-seltext_m = 'Sales Doc Item'.
      w_field1-emphasize = 'C710'.
      APPEND w_field1 TO t_field1.
      CLEAR w_field1.
      w_field1-col_pos = 3.
      w_field1-fieldname = 'MATNR'.
      w_field1-tabname = 'IT_VBAP'.
      w_field1-seltext_m = 'Material No'.
      w_field1-emphasize = 'C710'.
      APPEND w_field1 TO t_field1.
      CLEAR w_field1.
      w_field1-col_pos = 4.
      w_field1-fieldname = 'ZMENG'.
      w_field1-tabname = 'IT_VBAP'.
      w_field1-seltext_m = 'Target quan units'.
      w_field1-emphasize = 'C710'.
      APPEND w_field1 TO t_field1.
      CLEAR w_field1.
      w_field1-col_pos = 5.
      w_field1-fieldname = 'NETWR'.
      w_field1-tabname = 'IT_VBAP'.
      w_field1-seltext_m = 'Net value dc cu'.
      w_field1-emphasize = 'C710'.
      APPEND w_field1 TO t_field1.
      CLEAR w_field1.
    ENDFORM.                    " build_field_catalog2
    *&      Form  print_field_data
          text
    FORM print_field_data .
    SET PF-STATUS 'VBAP'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = sy-repid
      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                  = I_STRUCTURE_NAME
      I_BACKGROUND_ID                   = ' '
         i_grid_title                      = 'VBAP DETAILS'
      I_GRID_SETTINGS                   = I_GRID_SETTINGS
      IS_LAYOUT                         = IS_LAYOUT
         it_fieldcat                       = t_field1[]
      IT_EXCLUDING                      = IT_EXCLUDING
      IT_SPECIAL_GROUPS                 = IT_SPECIAL_GROUPS
      IT_SORT                           = IT_SORT
      IT_FILTER                         = IT_FILTER
      IS_SEL_HIDE                       = IS_SEL_HIDE
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        = IS_VARIANT
      IT_EVENTS                         = IT_EVENTS
      IT_EVENT_EXIT                     = IT_EVENT_EXIT
      IS_PRINT                          = IS_PRINT
      IS_REPREP_ID                      = 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_ALV_GRAPHICS
      IT_HYPERLINK                      = IT_HYPERLINK
      IT_ADD_FIELDCAT                   = IT_ADD_FIELDCAT
      IT_EXCEPT_QINFO                   = IT_EXCEPT_QINFO
      IR_SALV_FULLSCREEN_ADAPTER        = IR_SALV_FULLSCREEN_ADAPTER
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           = E_EXIT_CAUSED_BY_CALLER
      ES_EXIT_CAUSED_BY_USER            = ES_EXIT_CAUSED_BY_USER
        TABLES
          t_outtab                          = it_vbap
       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.                    " print_field_data
    </code>

    Hi Satya..
    This is the Sample code...
    DATA : V_FORM_GUI TYPE SLIS_FORMNAME VALUE 'F_GUI'.  "Form name
    **Secondary List
    FORM print_field_data .
    SET PF-STATUS 'VBAP'.  "This statement will not work for ALV
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER = ' '
    I_BUFFER_ACTIVE = ' '
    i_callback_program = sy-repid
    <b> I_CALLBACK_PF_STATUS_SET = V_FORM_GUI  
                                                      "Subroutine in which GUI status is called</b>
    I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'   "To handle GUI
    I_CALLBACK_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_END_OF_LIST = ' '
    I_STRUCTURE_NAME = I_STRUCTURE_NAME
    I_BACKGROUND_ID = ' '
    i_grid_title = 'VBAP DETAILS'
    I_GRID_SETTINGS = I_GRID_SETTINGS
    IS_LAYOUT = IS_LAYOUT
    it_fieldcat = t_field1[]
    IT_EXCLUDING = IT_EXCLUDING
    IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS
    IT_SORT = IT_SORT
    IT_FILTER = IT_FILTER
    IS_SEL_HIDE = IS_SEL_HIDE
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT = IS_VARIANT
    IT_EVENTS = IT_EVENTS
    IT_EVENT_EXIT = IT_EVENT_EXIT
    IS_PRINT = IS_PRINT
    IS_REPREP_ID = 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_ALV_GRAPHICS
    IT_HYPERLINK = IT_HYPERLINK
    IT_ADD_FIELDCAT = IT_ADD_FIELDCAT
    IT_EXCEPT_QINFO = IT_EXCEPT_QINFO
    IR_SALV_FULLSCREEN_ADAPTER = IR_SALV_FULLSCREEN_ADAPTER
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER
    ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER
    TABLES
    t_outtab = it_vbap
    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. " print_field_data
    FORM F_GUI USING rt_extab TYPE slis_t_extab.
    SET PF-STATUS 'GUI_1'.  "Double click and Create this GUI status and add buttons
    ENDFORM.
    <b><REMOVED BY MODERATOR></b>
    Message was edited by:
            Alvaro Tejada Galindo

  • Screen calling in ALV report

    i m writing one ALV grid report...in the ouptut i have placed one checkbox for FLAG field,which is an editable field at output...
      fieldcatalog-fieldname   = 'FLAG'.
      fieldcatalog-seltext_m   = 'Selection Flag'.
      fieldcatalog-col_pos     = 1.
      fieldcatalog-outputlen   = 14.
      fieldcatalog-checkbox    = 'X'.
      fieldcatalog-edit        = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    so,when i run the report i will get some 20 records...user will select any 10 records as i have placed a checkbox...i have placed one pushbutton 'DELIVERY' when user clicks that DELIVERY button with 10 selected fields..VLMOVE tcode needs to be called and deleivery needs to be posted...
       WHEN 'DELIVERY'.
         IF rs_selfield-fieldname = 'FLAG'.
          READ TABLE it_FINAL INTO wa_FINAL INDEX rs_selfield-tabindex.
          SET PARAMETER ID 'MAT' FIELD wa_FINAL-FLAG.
          CALL TRANSACTION 'VLMOVE'.
         ENDIF.
    My probelm is how SAP knows what records i have selected?? any table is there to handle it..and how to post..

    LOOP AT IT_VEKP INTO WA_VEKP.
          ex-exidv = wa_vekp-exidv.
          append ex to exidv_g.
          CLEAR  ex.
          flag = '' .
              LOOP AT IT_VEPO INTO WA_VEPO WHERE venum = wa_vekp-venum.
             AT FIRST .
                IF FLAG = ''.
                  CLEAR : wa_move_to ,it_move_to .
                  IT_MOVE_TO-HUWBEVENT = HUEVENT."'0006'. "rec. event
                  IT_MOVE_TO-MATNR = WA_VEPO-MATNR." rec. matnr
                  IT_MOVE_TO-CHARG = WA_VEPO-CHARG."rec. batch
                  IT_MOVE_TO-WERKS = WA_VEPO-werks . " rec. plant
                  IT_MOVE_TO-LGORT = p_umlgo. " rec. storage location
                  IT_MOVE_TO-LGNUM = p_whsid."warehouse no.
                  IT_MOVE_TO-BWART = '311'."'311'."movement type
                  MOVE-CORRESPONDING it_move_to to wa_move_to.
             ENDAT .
                  flag = 'X'.
                  ENDIF.
                  WA_HU_ITEMS-VENUM    = wa_vekp-venum ."handling unit
                  WA_HU_ITEMS-VEPOS    = wa_vepo-vepos ."item no.
                  append wa_hu_items  TO wa_move_to-hu_items.
              ENDLOOP .
          APPEND wa_move_to to it_move_to_g.
          CALL FUNCTION 'HU_CREATE_GOODS_MOVEMENT'
           EXPORTING
             IF_EVENT             =
             IF_SIMULATE          = ' '
             IF_COMMIT            = ' '
             IF_TCODE             = 'VLMOVE'
             IS_IMKPF             =
             IT_MOVE_TO           = it_move_to_g
             IT_INTERNAL_ID       =
             IT_EXTERNAL_ID       = exidv_g
           IMPORTING
             EF_POSTED            = EF_POSTED
             ES_MESSAGE           = ES_MESSAGE
             ET_MESSAGES          = ET_MESSAGES
             ES_EMKPF             = ES_EMKPF
           CHANGING
           CT_IMSEG             =
          IF ES_MESSAGE IS NOT INITIAL .
              itab-exidv = wa_vekp-exidv .
              APPEND ITAB .
              CLEAR  itab  .
             IF sy-subrc = 0 .
               call function 'BAPI_TRANSACTION_COMMIT'
                EXPORTING
                  wait = 'X'.
             ENDIF.
          ENDIF.
         REFRESH : it_move_to_g,exidv_g .
         CLEAR : wa_vekp ,wa_vepo .
        ENDLOOP .
    Where VEKP and VEPO are handling unit header and item tables respectively. VEPO contains the material no. which is there in HU. You can use HU_CREATE_GOODS_MOVEMENT FM as specified to do VLMOVE in background.

  • Calling a ALV Report program via a Remote Function module.

    H All,
         The thing which I am looking out for is ,to know a technique to acheive this,
      To start with,
    For the transaction MB51-(Material Document List),which is a Report Program "RM07DOCS",I also observed that this uses a ALV to display the output.
    Now what I actually require is another extra field (from MARA table )  along with the standard output that is displayed from this report.
    Also this needs to be passed to a different UI system(build using VC ).
    So I have a RFC eg DisplayList(),where in I need to exeucte this report program ,get the output what it gives ,add my additional information what I want to and pass it as a export parameter,
    So this is the structure which I can visualise,
    FUNCTION ZFUN_MB51TXN.
    I would get all the import parameters here ,from who ever is calling my fun module,
    *Call the report program,pass the input  parameters required
    *get the output from this report program
    *send the output to the caller through export parameters
    ENDFUNCTION.
    So Here I need to know ,Can this be achieved something using Submit report or anything,Any guidelines to move further would be really of great help!

    Hi All,
    It would really be great if you can explain with the reference to the same report program,the same selection screen elemetns or something.
    Thanks,
    Archies!

  • Adding custom fields to standard Asset Accounting  ALV reports

    Hello,
    I have recently added some fields to the Asset Master table ANLU using the customizing include CI_ANLU.  I have also added some fields using an append structure to ANLZ.  I now need to have these fields available in the standard reports for Asset Accounting.  One example is the report generated for transaction S_ALR_87011963.  I need the new fields available in the 'Displayed Columns' list when clicking the Change Layout icon.  Any suggestions?
    Thanks,
    JR

    Hi Vignesh,
    Adding new fields is not possible, but custom subscreens can be added.
    Check enhancements QQMA0001 (subscreen for notification header) and QQMA0008 (subscreen for additional data).
    It might help you.
    Thanks & Regards,
    Swati

  • Puting buttons in the appl bar with alv reporting

    hai
    im trying to put buttons in alv in  applctn bar
    the coding i made is
    perform eventtab.
    form eventtab.
    wa_event-name='set_pf_status'.
    wa_event-form = 'status'.
    append wa_event to tab_event.
    endform.
    form status.
    set pf-status 'ystatus'.----
    >status havin buttons.
    endform.
    the result is
    program is geting run time error(shortdump)
    error is too many parameters in the perform.
    in coding itis pointing arroe mark like this
    >form status.
    plz help me how to add buttons in application bar
    tahnks in advance
    sindu.

    you should not populate FORM name of STATUS to EVENTS. instead you have to give the FORM name to the FUnction module.
    check this link,to know how to give our own GUI status.
    Re: own PF-Status for REUSE_ALV_GRID_DISPLAY
    FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
      CLEAR : WA_EXTAB,
              IT_EXTAB.
    *--Set the Modified PF status for the ALV.
      SET PF-STATUS 'STATUS_01' EXCLUDING RT_EXTAB.
    you have to copy any ALV related GUI status (from SE41 transaction) to STATUS_01. standard alv programs starts with BCALV*. so check it in SE41
    copy it and add your own button to the Application tool bar.
    ENDFORM.                               " SET_PF_STATUS
    Regards
    Srikanth
    Message was edited by: Srikanth Kidambi

  • How to resolve the error in bdc call transaction in ALV report

    Dear Experts, i am executing the alv report program and in alv report program one bdc is there..
    after executing output is showing in alv format but one button is there (update master)..when i am clicking update button the bdc is run but is not updated in the material master..after executing my bdc is not updated in mm02.
    how to resove it?
    CALL TRANSACTION 'MM02' USING BDCDATA MODE MODE
                                                              UPDATE 'S'
                                                      MESSAGES INTO MESSTAB.

    Hi Kaustav,
    Looking at the code you attached, it appears to me that your BDC (Form  USER_COMMAND) is not executed at all as you haven't passed the 'USER_COMMAND' in FM REUSE_ALV_GRID_DISPLAY for ALV display.
    You must pass the importing parameter  I_CALLBACK_USER_COMMAND of this FM as 'USER_COMMAND', only then this form will be executed and your BDC will run.
    Thereafter, in case your BDC update fails, you can put a break-point in the form (at CALL TRANSACTION statement) and analyze the message table MESSTAB.
    Hope it helps.
    Regards,
    Sapeksh

  • Possibility of calling ALV report

    hi experts,
    i have a requirement that i have to design an entry screen whcih contain pushbuttons (SAVE, CLEAR ,DISPLAY).
    whenever user pressed DISPLAY, he wants to call the selection screen of an alv report which is already exists.
    is that possible to call an alv report selection screen and execute it.
    any suggestions pls.
    thanks&regards
    maheshlap.
    Edited by: Thomas Zloch on Dec 17, 2011 11:07 PM

    Hi,
    Follow this code,
    *DISPLAY DYNAMIC PUSHBUTTON ON APP TOOLBAR ON USER CLICKS
    SELECTION-SCREEN: FUNCTION KEY 1,
                      FUNCTION KEY 2,
                      FUNCTION KEY 3.
    **EVENT ON SELECTION SCREEN FOR OUTPUT DISPLAY
    AT SELECTION-SCREEN OUTPUT.
    *CLICK OF FIRST RADIO BUTTON
      IF pa = 'X'.
        sscrfields-functxt_01 = 'Materials Management'.
        WRITE icon_plant AS ICON TO text_001.
    *CODE TO GET DYNAMICS BASED ON THE SELECTED RADIO
        LOOP AT SCREEN.
          IF screen-group1 = 'MOD'.
            screen-intensified = '1'.
            screen-active = 1.
            screen-display_3d = '1'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'RAD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'CAD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
    *CLICK OF SECOND RADIO
      IF pb = 'X'.
        sscrfields-functxt_02 = 'Sales And Distribution'.
        WRITE icon_ws_ship AS ICON TO text_001.
        LOOP AT SCREEN.
          IF screen-group1 = 'RAD'.
            screen-intensified = '1'.
            screen-active = 1.
            screen-display_3d = '1'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'MOD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'CAD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
    *CLICK OF THIRD RADIO
      IF pc = 'X'.
        sscrfields-functxt_03 = 'Human Resources'.
        WRITE icon_new_employee AS ICON TO text_001.
        LOOP AT SCREEN.
          IF screen-group1 = 'RAD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'MOD'.
            screen-intensified = '0'.
            screen-active = 0.
            screen-display_3d = '0'.
            MODIFY SCREEN.
          ENDIF.
          IF screen-group1 = 'CAD'.
            screen-intensified = '1'.
            screen-active = 1.
            screen-display_3d = '1'.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
    *CUSTOMISING THE TOOLBARS OF THE SELECTION SCREEN
    *WITH F8 BUTTON DISABLED
      APPEND :  'PRIN' TO it_ucomm,
                'SPOS' TO it_ucomm,
                'ONLI' TO it_ucomm.
      CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
        EXPORTING
          p_status  = sy-pfkey
        TABLES
          p_exclude = it_ucomm.
    Warm Regards,
    PavanKumar.G

  • Summation button in ALV report is giving shortdump

    Dear All,
    I have developed a ALV report. The report is a simple ALV report (Using REUSE_ALV_GRID_DISPLAY). When I am pressing the summation button at the top, it is giving a shortdump. The reason I have found out is the no. of columns are very large (45 to 50). Can anyone suggest how to handle this situation?
    Best wishes,
    Atanu

    Hi atanu,
    then you can use DO_SUM = 'X' (for the field which you want to sum option) in the fieldcat , this will try to sum while display it self.i mean in list display it will show the totals also.
    then you need not to explicitly click on SUM button.
    Regards
    vijay

  • Alv report please help

    Hi,
         Please help me in this.
    1) Create the selection screen with the following fields on it.
         S_REQUESTOR for ZSWAPHISTORY- REQUESTOR
         S_APPROVER for ZSWAPHISTORY- APPROVER providing range
         S_to_customer for ZSWAPHISTORY- to_customer providing range
         S_from_customer for ZSWAPHISTORY- from_customer providing range
         S_MRPC     for MARC-DISPO providing range
         S_MATNR     for MARA-MATNR providing range
         S_APPR_DATE for ZSWAPHISTORY- APPR_DATE Default to yesterdays date
         S_QUAN     for ZSWAPHISTORY-quan
    2) Validate the fields entered in the selection screen.
    3) Check the user authorizations for this report.
    4) Select the entries from the table ZSWAPHISTORY into an internal table based on the input from the selection screen and the value of the field ZSWAPHISTORY -STATUS is APPROVED.
    5) Then select the MRP Controller ID (DISPO) from the Table MARC for all entries in the internal table where MARC-MATNR equals to the internal table -material number.
    6) Move the field value of MRP Controller ID (DISPO) into the final internal table for the corresponding entries.
    7) Declare the Filed Catalogue with the fields that are to be displayed in the ALV
    Please help to create this , iam new to this area.
    Thanks
    Ali

    Hi
    See the sample code of ALV and do accordingly
    Since you are using a Z table it is not clear to create
    report ZRGRIRNA no standard page heading
           line-count 65
           line-size 255
           message-id mm.
                       GR IR Detail Report                               *
    Description          : The output has to be displayed
                           in the ALV Grid format with the Selection     *
                           screen appearing on the output. In The Output *
                           Subtotals for Vendor, Plant, Period, Material,*
                           Valuation Class, Purchase Order,Cost Center,  *
                           Cost Element and Receipt Date are displayed   *
                           after sorting the data by same fields.        *
    Declaration for Tables
    tables: t001,      " Company Codes
            t001w,     " Plants/Branches
            lfa1,      " Vendor Master
            ska1,      " GL Account Master
            mara,      " Material Master
            mbew,      " Material Valuation
            ekko,      " PO Header Data
            cska,      " Cost Elements
            csks,      " Cost Centers
            bsis,      " GL Accounts: Open Items Data
            bkpf.      " Accounting Doc: Header Data
    Type-pools
    Type pools for ALV display
    type-pools : slis.
    Global variables
    data: g_repid       like sy-repid,
          g_exit        type c,
          g_events      type slis_t_event,
          g_list_top_of_page type slis_t_listheader,
          g_exit_caused_by_caller,
          g_exit_caused_by_user type slis_exit_by_user,
          g_top_of_page  type slis_formname value 'TOP_OF_PAGE',
          g_variant like disvariant,
          g_save.
    Declaration for Constants
    constants : c_x  type c  value 'X',         " Flag
                c_c  type c  value 'C',         " Flag
                c_l  type c  value 'L',         " Flag
                c_a  type c  value 'A',         " Line Type
                c_h  type c  value 'H',         " Dr/Cr
                c_s  type c  value 'S',         " Line Type
                c_mkpf(4) type c value 'MKPF'.  " Table
    Declaration of Internal Tables
    Internal Table for BSIS Table data
    data: begin of i_bsis occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            hkont like bsis-hkont,          " GR IR Account
            gjahr like bsis-gjahr,          " Fiscal Year
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            budat like bsis-budat,          " Receipt Date(Posting)
            monat like bsis-monat,          " Period
          end of i_bsis.
    Internal Table for BSEG Table data
    data: begin of i_bseg occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            gjahr like bsis-gjahr,          " Fiscal Year
            shkzg like bseg-shkzg,          " Dr/Cr Indicator
            lifnr like bseg-lifnr,          " Vendor Code
            matnr like bseg-matnr,          " Material No
            ebeln like bseg-ebeln,          " Purchase Order
            ebelp like bseg-ebelp,          " PO Item
            werks like bseg-werks,          " Plant
            menge like bseg-menge,          " PO Quantity
            meins like bseg-meins,          " UOM
            dmbtr like bseg-dmbtr,          " Amount in Local Currency
            wrbtr like bseg-wrbtr,          " Amount in Trans.Currency
          end of i_bseg.
    Internal Table for BKPF Table data
    data: begin of i_bkpf occurs 0,
            bukrs like bkpf-bukrs,          " Company Code
            belnr like bkpf-belnr,          " Acc Document
            gjahr like bkpf-gjahr,          " Fiscal Year
            waers like bkpf-waers,          " Trans. Currency
            awkey like bkpf-awkey,          " Object Key
            awtyp like bkpf-awtyp,          " Reference Procedure
          end of i_bkpf.
    Internal Table for MSEG Table data
    data: begin of i_mseg occurs 0,
            mblnr like mseg-mblnr,          " Material Document
            mjahr like mseg-mjahr,          " Fiscal Year
            bwart like mseg-bwart,          " Movement Type
            matnr like mseg-matnr,          " Material No
            menge like mseg-menge,          " PO Quantity
            meins like mseg-meins,          " UOM
          end of i_mseg.
    Internal Table for MBEW Table data
    data: begin of i_mbew occurs 0,
            matnr like mbew-matnr,          " Material No
            werks like mbew-bwkey,          " Plant
            bklas like mbew-bklas,          " Valuation Class
          end of i_mbew.
    Internal Table for EKPO Table data
    data: begin of i_ekpo occurs 0,
            ebeln like ekpo-ebeln,          " Purchase Order
            ebelp like ekpo-ebelp,          " PO Item
            matnr like ekpo-matnr,          " Material No
            txz01 like ekpo-txz01,          " Material Text
          end of i_ekpo.
    Internal Table for EKKN Table data
    data: begin of i_ekkn occurs 0,
            ebeln like ekkn-ebeln,          " Purchase Order
            ebelp like ekkn-ebelp,          " PO Item
            kostl like ekkn-kostl,          " Cost Center
            sakto like ekkn-sakto,          " Cost Element
          end of i_ekkn.
    Internal Table for LFA1 Table data
    data: begin of i_lfa1 occurs 0,
            lifnr like lfa1-lifnr,          " Vendor
            name1 like lfa1-name1,          " Name
          end of i_lfa1.
    Declaration of Output Internal Table
    data: begin of i_final occurs 0,
            lifnr like lfa1-lifnr,     " Vendor
            werks like bseg-werks,     " Plant
            monat like bsis-monat,     " Period
            matnr like mara-matnr,     " Material Number
            bklas like mbew-bklas,     " Val Class
            ebeln like bseg-ebeln,     " PO
            kostl like ekkn-kostl,     " Cost Center
            sakto like ekkn-sakto,     " Cost Element
            budat like bsis-budat,     " Rec. Date
            name1 like lfa1-name1,     " Vendor Name
            belnr like bsis-belnr,     " FI Document
            bwart like mseg-bwart,     " Movement Type
            txz01 like ekpo-txz01,     " Material Text
            menge like bseg-menge,     " Quantity
            meins like bseg-meins,     " UOM
            dmbtr like bseg-dmbtr,     " Local Amount
            wrbtr like bseg-wrbtr,     " Tran.Amount
            waers like bkpf-waers,     " Tran.Currency
            status type c,             " Material Status
          end of i_final.
    Internal table to hold field catgory data
    data:  i_fldcat  type slis_t_fieldcat_alv.   " Table - field catgory
    Internal table to hold Sort/Subtotals criteria data
    data:  i_sort  type slis_t_sortinfo_alv.     " Table - sort/Subtotals
    Structure
    data:  x_layout   type slis_layout_alv,      " Structure-layout
           x_fldcat   like line of i_fldcat,     " Structure-field catagory
           x_sort     like line of i_sort.       " Structure-Sort/Subtotals
           Selection screen
    selection-screen : begin of block b1 with frame title text-000.
    parameters:
       p_bukrs like t001-bukrs obligatory,          " Company Code
       p_grira like ska1-saknr default '0241101000' obligatory. " Account
    select-options:
       s_budat for bkpf-budat,        " Posting Date
       s_werks for t001w-werks,       " Plant
       s_lifnr for lfa1-lifnr,        " Vendor
       s_matnr for mara-matnr,        " Material Number
       s_kostl for csks-kostl,        " Cost Center
       s_kstar for cska-kstar,        " Cost Element
       s_ebeln for ekko-ebeln,        " Purchase Order
       s_monat for bsis-monat.        " Period
    selection-screen skip.
    parameters:
       p_incmt as checkbox default 'X',
       p_incnm as checkbox default 'X'.
    selection-screen end of block b1.
    Initialization
    initialization.
      g_repid = sy-repid.
      perform layout_init using x_layout.
      perform eventtab_build using g_events[].
      g_variant-report = g_repid.
      g_save           = 'A'.
    At selection screen
    at selection-screen.
    Validation of Selection Screen Fields
      perform validate_screen.
    Start of selection
    start-of-selection.
    Read Data from Database Tables
      perform read_data.
    End of selection
    end-of-selection.
    Build layout report layout.
      perform populate_layout_stucture.
    Perform build_field_catalog and Sort Table
      perform build_field_catalog.
      perform build_sort_totals.
    List Header for Top-Of-Page
      perform comment_build using g_list_top_of_page[].
    Call list viewer function module
      perform call_list_viewer .
    ****************Form - Routines**************************************
          Form        : layout_init
          Description : Form to Build layout for list display
    form layout_init using rs_layout type slis_layout_alv.
      rs_layout-detail_popup      = c_x.
    endform.
    Form         : Eventtab_build
    Description  : Registration of events to happen during list display
    form eventtab_build using rt_events type slis_t_event.
    Registration of events to happen during list display
      data: ls_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = rt_events.
      read table rt_events with key name = slis_ev_top_of_page
                               into ls_event.
      if sy-subrc = 0.
        move g_top_of_page to ls_event-form.
        append ls_event to rt_events.
      endif.
    endform.                                   "eventtab_build
          Form : top_of_page
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
             I_LOGO             = 'ENJOYSAP_LOGO'
                it_list_commentary = g_list_top_of_page.
    endform.
          Form validate_screen
    Validation of Selection Screen fields
    form validate_screen.
    Validation of Company Code
      clear t001.
      if not p_bukrs is initial.
        select single bukrs
          into t001-bukrs
          from t001
          where bukrs eq p_bukrs.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Company Code'(012).
        endif.
      endif.
    Validation of GL Account (GR/IR)
      clear ska1.
      if not p_grira is initial.
        select saknr
          into ska1-saknr
          from ska1
          up to 1 rows
          where saknr eq p_grira.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid GR/IR Account'(013).
        endif.
      endif.
    Validation of Vendor Code
      clear lfa1.
      if not s_lifnr[] is initial.
        select single lifnr
          into lfa1-lifnr
          from lfa1
          where lifnr in s_lifnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Vendor'(001).
        endif.
      endif.
    Validation of Plant Code
      clear t001w.
      if not s_werks[] is initial.
        select single werks
          into t001w-werks
          from t001w
          where werks in s_werks.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Plant'(014).
        endif.
      endif.
    Validation of Material Code
      clear mara.
      if not s_matnr[] is initial.
        select single matnr
          into mara-matnr
          from mara
          where matnr in s_matnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Material'(015).
        endif.
      endif.
    Validation of Purchase Order
      clear ekko.
      if not s_ebeln[] is initial.
        select single ebeln
          into ekko-ebeln
          from ekko
          where ebeln in s_ebeln.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Purchase Order'(016).
        endif.
      endif.
    Validation of Cost Center
      clear csks.
      if not s_kostl[] is initial.
        select kostl
          into csks-kostl
          from csks
          up to 1 rows
          where kostl in s_kostl.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Center'(017).
        endif.
      endif.
    Validation of Cost Element
      clear cska.
      if not s_kstar[] is initial.
        select kstar
          into cska-kstar
          from cska
          up to 1 rows
          where kstar in s_kstar.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Element'(018).
        endif.
      endif.
    endform.                          "validate_screen
    *&      Form  read_data
    Read the Data from the database Tables
    form read_data.
    Get the Accounting Documents for the GR/IR Account Entered on
    Selection Screen
      clear i_bsis.
      refresh i_bsis.
      select bukrs           " Company Code
             hkont           " GR IR Account
             gjahr           " Fiscal Year
             belnr           " Acc Document
             buzei           " Item No
             budat           " Receipt Date(Posting)
             monat           " Period
       into table i_bsis
       from  bsis
       where  bukrs = p_bukrs
         and  hkont = p_grira
         and  budat in s_budat
         and  monat in s_monat .
      if sy-subrc <> 0.
        message i899 with 'No data found'(043).
        g_exit = c_x.
        stop.
      endif.
      sort i_bsis by bukrs hkont gjahr belnr buzei.
    Get the Vendor,PO,Material,Qty details from BSEG Table
      if not i_bsis[] is initial.
        clear i_bseg.
        refresh i_bseg.
        select bukrs           " Company Code
               belnr           " Acc Document
               buzei           " Item No
               gjahr           " Fiscal Year
               shkzg           " Dr/Cr Indicator
               lifnr           " Vendor Code
               matnr           " Material No
               ebeln           " Purchase Order
               ebelp           " PO Item
               werks           " Plant
               menge           " PO Quantity
               meins           " UOM
               dmbtr           " Amount in Local Currency
               wrbtr           " Amount in Trans.Currency
        into table i_bseg
        from   bseg
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr
        and    buzei = i_bsis-buzei
        and    lifnr in s_lifnr
        and    werks in s_werks
        and    matnr in s_matnr
        and    ebeln in s_ebeln.
        sort i_bseg by bukrs belnr buzei gjahr.
    Select the Trans.Currency from BKPF Table
        clear i_bkpf.
        refresh i_bkpf.
        select bukrs           " Company Code
               belnr           " Acc Document
               gjahr           " Fiscal Year
               waers           " Trans. Currency
               awkey           " Object Key
               awtyp           " Reference Procedure
        into table i_bkpf
        from   bkpf
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr.
      endif.
      sort i_bkpf by bukrs belnr gjahr.
    Get the Quantity and UOM of Material from MSEG Table
      if not i_bkpf[] is initial.
        clear i_mseg.
        refresh i_mseg.
        select mblnr           " Material Document
               mjahr           " Fiscal Year
               bwart           " Movement Type
               matnr           " Material No
               menge           " PO Quantity
               meins           " UOM
          into table i_mseg
          from   mseg
          for all entries in i_bkpf
          where  mblnr = i_bkpf-awkey(10).
      endif.
      sort i_mseg by mblnr mjahr.
    Get the Material And Description from EKPO Table
      if not i_bseg[] is initial.
        clear i_ekpo.
        refresh i_ekpo.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               matnr           " Material No
               txz01           " Material Text
        into table i_ekpo
        from   ekpo
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp.
        sort i_ekpo by ebeln ebelp.
    Get the Valuation Class from MBEW Table
        clear i_mbew.
        refresh i_mbew.
        select matnr           " Material No
               bwkey           " Plant
               bklas           " Valuation Class
        into table i_mbew
        from   mbew
        for all entries in i_bseg
        where  matnr = i_bseg-matnr
        and    bwkey = i_bseg-werks.
        sort i_mbew by matnr werks.
    Get the Cost Center and Cost Element of the PO from EKKN Table
        clear i_ekkn.
        refresh i_ekkn.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               kostl           " Cost Center
               sakto           " Cost Element
        into table i_ekkn
        from   ekkn
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp
        and    kostl in s_kostl
        and    sakto in s_kstar.
        sort i_ekkn by ebeln ebelp.
    Get the Vendor Name
        clear i_lfa1.
        refresh i_lfa1.
        select lifnr            " Vendor
               name1            " Name
        into table i_lfa1
        from   lfa1
        for all entries in i_bseg
        where  lifnr = i_bseg-lifnr.
      endif.
      sort i_lfa1 by lifnr.
    Move the data to Final Output Internal Table
      loop at i_bsis.
        i_final-belnr = i_bsis-belnr.     " FI Document
        i_final-monat = i_bsis-monat.     " Period
        i_final-budat = i_bsis-budat.     " Rec. Date
    Read the Transaction Currency from BKPF Internal Table
        read table i_bkpf with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   binary search.
        if sy-subrc = 0.
          i_final-waers = i_bkpf-waers.     " Tran.Currency
    Read the Movement Type for all Material Related
    Documents from MSEG Internal Table
          if i_bkpf-awtyp = c_mkpf.
            read table i_mseg with key mblnr = i_bkpf-awkey(10)
                                       mjahr = i_bkpf-awkey+10(4).
            if sy-subrc = 0.
              i_final-bwart = i_mseg-bwart.     " Movement Type
            endif.
          endif.
        endif.
    Read Vendor, Plant, PO Document, Local And Trans.Amounts
    from BSEG Internal Table
        read table i_bseg with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   buzei = i_bsis-buzei
                                   binary search.
        if sy-subrc = 0.
          i_final-lifnr = i_bseg-lifnr.     " Vendor
          i_final-werks = i_bseg-werks.     " Plant
          i_final-ebeln = i_bseg-ebeln.     " PO
          i_final-dmbtr = i_bseg-dmbtr.     " Local Amount
          i_final-wrbtr = i_bseg-wrbtr.     " Tran.Amount
          i_final-menge = i_bseg-menge.     " Quantity
          i_final-meins = i_bseg-meins.     " UOM
    For Credit Indicator(SHKZG = H) amounts should be (-)ve
          if i_bseg-shkzg = c_h.
            i_final-dmbtr = i_final-dmbtr * -1.
            i_final-wrbtr = i_final-wrbtr * -1.
            i_final-menge = i_final-menge * -1.
          endif.
    Read the Material and its Description from EKPO Internal Table
          read table i_ekpo with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     matnr = i_bseg-matnr
                                     binary search.
          if sy-subrc = 0.
            i_final-matnr = i_ekpo-matnr.     " Material Number
            i_final-txz01 = i_ekpo-txz01.     " Material Text
    Populate the Material Status depending on the Input Checkbox
    On Selection Screen
            if not i_ekpo-matnr is initial.
              i_final-status = c_x.
            endif.
          endif.
    Read the PO related Cost Element and Cost Centers
    from EKKN Internal Table
          read table i_ekkn with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     binary search.
          if sy-subrc = 0.
            i_final-kostl = i_ekkn-kostl.     " Cost Center
            i_final-sakto = i_ekkn-sakto.     " Cost Element
          endif.
    Read the Valuation Class from MBEW Internal Table
          read table i_mbew with key matnr = i_bseg-matnr
                                     werks = i_bseg-werks
                                     binary search.
          if sy-subrc = 0.
            i_final-bklas = i_mbew-bklas.     " Val Class
          endif.
    Read the Vendor Name from LFA1 Internal Table
          read table i_lfa1 with key lifnr = i_bseg-lifnr
                                     binary search.
          if sy-subrc = 0.
            i_final-name1 = i_lfa1-name1.     " Vendor Name
          endif.
        endif.
        append i_final.
        clear i_final.
      endloop.
      sort i_final by lifnr werks monat matnr.
    Depending on the check Box Selected display the data
      if p_incmt = c_x and p_incnm ne c_x.
        delete i_final where matnr eq space.
      elseif p_incnm = c_x and p_incmt ne c_x.
        delete i_final where matnr ne space.
      endif.
    endform.           "Read Data
         Form        : populate_layout_stucture
         Description : Populating the layout structure
    form populate_layout_stucture.
      clear x_layout .
    Layout properties
      x_layout-zebra                = c_x.
      x_layout-detail_popup         = c_x.
      x_layout-detail_initial_lines = c_x.
      x_layout-colwidth_optimize    = c_x.
    endform.                    " populate_layout_stucture
         Form        : build_field_catalog
         Description : Building the field catalog data
    form build_field_catalog.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
           exporting
                i_program_name         = g_repid
                i_internal_tabname     = 'I_FINAL'
                i_inclname             = g_repid
           changing
                ct_fieldcat            = i_fldcat
           exceptions
                inconsistent_interface = 1
                program_error          = 2
                others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    Getting the Header text for the coloums
      loop at i_fldcat into x_fldcat where fieldname = 'LIFNR' or
                                           fieldname = 'NAME1' or
                                           fieldname = 'WERKS' or
                                           fieldname = 'MONAT' or
                                           fieldname = 'MATNR' or
                                           fieldname = 'BKLAS' or
                                           fieldname = 'EBELN' or
                                           fieldname = 'KOSTL' or
                                           fieldname = 'SAKTO' or
                                           fieldname = 'BUDAT' or
                                           fieldname = 'BELNR' or
                                           fieldname = 'BWART' or
                                           fieldname = 'TXZ01' or
                                           fieldname = 'MENGE' or
                                           fieldname = 'MEINS' or
                                           fieldname = 'DMBTR' or
                                           fieldname = 'WRBTR' or
                                           fieldname = 'WAERS' or
                                           fieldname = 'STATUS'.
        if x_fldcat-fieldname = 'LIFNR'.
          x_fldcat-seltext_l   = 'Vendor'(003).
          x_fldcat-seltext_m   = 'Vendor'(003).
          x_fldcat-seltext_s   = 'Vendor'(003).
          x_fldcat-reptext_ddic = 'Vendor'(003).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'NAME1'.
          x_fldcat-seltext_l   = 'Vendor Name'(002).
          x_fldcat-seltext_m   = 'Vendor Name'(002).
          x_fldcat-seltext_s   = 'Vendor Name'(002).
          x_fldcat-reptext_ddic = 'Vendor Name'(002).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'WERKS'.
          x_fldcat-seltext_l   = 'Plant'(010).
          x_fldcat-seltext_m   = 'Plant'(010).
          x_fldcat-seltext_s   = 'Plant'(010).
          x_fldcat-reptext_ddic   = 'Plant'(010).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MONAT'.
          x_fldcat-seltext_l   = 'Period'(011).
          x_fldcat-seltext_m   = 'Period'(011).
          x_fldcat-seltext_s   = 'Period'(011).
          x_fldcat-reptext_ddic   = 'Period'(011).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MATNR'.
          x_fldcat-seltext_l   = 'Material'(004).
          x_fldcat-seltext_m   = 'Material'(004).
          x_fldcat-seltext_s   = 'Material'(004).
          x_fldcat-reptext_ddic   = 'Material'(004).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BKLAS'.
          x_fldcat-seltext_l   = 'Valuation Class'(009).
          x_fldcat-seltext_m   = 'Valuation Class'(009).
          x_fldcat-seltext_s   = 'Valuation Class'(009).
          x_fldcat-reptext_ddic   = 'Valuation Class'(009).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'EBELN'.
          x_fldcat-seltext_l   = 'Purchase Order'(005).
          x_fldcat-seltext_m   = 'Purchase Order'(005).
          x_fldcat-seltext_s   = 'Purchase Order'(005).
          x_fldcat-reptext_ddic   = 'Purchase Order'(005).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'KOSTL'.
          x_fldcat-seltext_l   = 'Cost Center'(006).
          x_fldcat-seltext_m   = 'Cost Center'(006).
          x_fldcat-seltext_s   = 'Cost Center'(006).
          x_fldcat-reptext_ddic   = 'Cost Center'(006).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'SAKTO'.
          x_fldcat-seltext_l   = 'Cost Element'(007).
          x_fldcat-seltext_m   = 'Cost Element'(007).
          x_fldcat-seltext_s   = 'Cost Element'(007).
          x_fldcat-reptext_ddic   = 'Cost Element'(007).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BUDAT'.
          x_fldcat-seltext_l   = 'Receipt Date'(008).
          x_fldcat-seltext_m   = 'Receipt Date'(008).
          x_fldcat-seltext_s   = 'Receipt Date'(008).
          x_fldcat-reptext_ddic   = 'Receipt Date'(008).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BELNR'.
          x_fldcat-seltext_l   = 'Acc.Document'(100).
          x_fldcat-seltext_m   = 'Acc.Document'(100).
          x_fldcat-seltext_s   = 'Acc.Document'(100).
          x_fldcat-reptext_ddic   = 'Acc.Document'(100).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BWART'.
          x_fldcat-seltext_l   = 'Movement Type'(101).
          x_fldcat-seltext_m   = 'Movement Type'(101).
          x_fldcat-seltext_s   = 'Movement Type'(101).
          x_fldcat-reptext_ddic   = 'Movement Type'(101).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'TXZ01'.
          x_fldcat-seltext_l   = 'Material Text'(102).
          x_fldcat-seltext_m   = 'Material Text'(102).
          x_fldcat-seltext_s   = 'Material Text'(102).
          x_fldcat-reptext_ddic   = 'Material Text'(102).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MENGE'.
          x_fldcat-seltext_l   = 'Quantity'(103).
          x_fldcat-seltext_m   = 'Quantity'(103).
          x_fldcat-seltext_s   = 'Quantity'(103).
          x_fldcat-reptext_ddic   = 'Quantity'(103).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'MEINS'.
          x_fldcat-seltext_l   = 'UOM'(104).
          x_fldcat-seltext_m   = 'UOM'(104).
          x_fldcat-seltext_s   = 'UOM'(104).
          x_fldcat-reptext_ddic   = 'UOM'(104).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'DMBTR'.
          x_fldcat-seltext_l   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_m   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_s   = 'Amount in Local Curr'(105).
          x_fldcat-reptext_ddic   = 'Amount in Local Curr'(105).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WRBTR'.
          x_fldcat-seltext_l   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_m   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_s   = 'Amount in Trans.Curr'(106).
          x_fldcat-reptext_ddic   = 'Amount in Trans.Curr'(106).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WAERS'.
          x_fldcat-seltext_l   = 'Trans.Currency'(107).
          x_fldcat-seltext_m   = 'Trans.Currency'(107).
          x_fldcat-seltext_s   = 'Trans.Currency'(107).
          x_fldcat-reptext_ddic   = 'Trans.Currency'(107).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'STATUS'.
          x_fldcat-seltext_l   = 'Material Status'(019).
          x_fldcat-seltext_m   = 'Material Status'(019).
          x_fldcat-seltext_s   = 'Material Status'(019).
          x_fldcat-reptext_ddic   = 'Material Status'(019).
          x_fldcat-ddictxt   = c_l.
        endif.
        modify i_fldcat from x_fldcat index sy-tabix.
      endloop.
    endform.                    " build_field_catalog
         Form        : build_sort_totals
         Description : Building the Criteria for Sort/Subtotals
    form build_sort_totals.
      x_sort-fieldname = 'LIFNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  1.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'WERKS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  2.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MONAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  3.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MATNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  4.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BKLAS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  5.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'EBELN'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  6.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'KOSTL'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  7.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'SAKTO'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  8.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BUDAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  9.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
    endform.                    " build_sort_totals
      Form        : comment_build
      Description : This form is used to display the Report Header(ALV)
    form comment_build using lt_top_of_page type
                                            slis_t_listheader.
      data: l_line type slis_listheader,
            l_heading1 like rs38m-repti,
            l_date(10), l_time(8).
      clear l_line.
      l_heading1 = 'GR/IR DETAIL REPORT'(021).
      g_repid = sy-repid.
      write sy-uzeit to l_time.
      write sy-datum to l_date.
      l_line-typ = c_h.
      move l_heading1 to l_line-info.
      append l_line to lt_top_of_page.
      clear l_line.
      l_line-typ  = c_s.
      concatenate 'System:'(023) sy-sysid
                  'Date:'(024) l_date
                  ' Time:'(025)
                  l_time into l_line-info.
      append l_line to lt_top_of_page.
      concatenate 'Report:'(026) g_repid
                  ' User:'(027) sy-uname into
                  l_line-info.
      append l_line to lt_top_of_page.
      l_line-typ = c_a.
      move 'SELECTION CRITERIA:'(028) to l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Company Code : '(029)
                  p_bukrs into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' GR/IR Account: '(030)
                  p_grira into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Posting Date : '(032) s_budat-low
                  ' To: '(031) s_budat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Plant : '(033) s_werks-low
                  ' To: '(031) s_werks-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Vendor: '(034) s_lifnr-low
                  ' To: '(031) s_lifnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Material: '(035) s_matnr-low
                  ' To: '(031) s_matnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Center : '(036) s_kostl-low
                  ' To: '(031) s_kostl-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Element: '(037) s_kstar-low
                  ' To: '(031) s_kstar-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Purchase Order: '(038) s_ebeln-low
                  ' To: '(031) s_ebeln-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Period : '(039) s_monat-low
                  ' To: '(031) s_monat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Material Items: '(040)
                  p_incmt into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Non-Material Items: '(041)
                  p_incnm into l_line-info.
      append l_line to lt_top_of_page.
    endform.
         Form        : call_list_viewer
         Description : This form is used to display the grid through ALV
    form call_list_viewer.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = g_repid
                is_layout               = x_layout
                it_fieldcat             = i_fldcat[]
                i_default               = c_x
                it_sort                 = i_sort[]
                i_save                  = g_save
                is_variant              = g_variant
                it_events               = g_events[]
           importing
                e_exit_caused_by_caller = g_exit_caused_by_caller
                es_exit_caused_by_user  = g_exit_caused_by_user
           tables
                t_outtab                = i_final
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
        write: / 'Problem in calling the ALV report'(042).
      endif.
    endform.                    " call_list_viewer
    Regards
    Anji

  • Multiple Internal tables in separate result sets in ALV report

    Hi All
    I need to create a program to display the 3 different Internal Tables in different boxes using ALV
    For example, say i am having the values in my internal table say ITAB1, ITAB2 & ITAB3 if you call the "REUSE_ALV_LIST_DISPLAY" by passing the "ITAB1" it will show you the output in 1 box,
    but we can't then display the ITAB2 and ITAB3 data.
    so i want to confirm 3 separate internal tables are displayed in separate boxes using ALV.
    Is it possible in ALV ?

    Hi Amol Sonaikar
    <b>1</b>.
    Displaying different ITABs one by one using ALV called BLOCKED ALV reports.
    <b>2</b>.
    For this we use 3 FMs
    <b>REUSE_ALV_BLOCK_LIST_INIT
    REUSE_ALV_BLOCK_LIST_APPEND
    REUSE_ALV_BLOCK_LIST_APPEND</b>
    <b>3</b>.
    Have a look at this Example .
    Just create and Execute .It displays 2 outputs.
    If u want display another one call  REUSE_ALV_BLOCK_LIST_APPEND FM and pass ur ITAB .
    REPORT  zvenkat_head1.
    DATA: BEGIN OF i_mard OCCURS 0,
            werks TYPE mard-werks,
            lgort TYPE mard-lgort,
            matnr TYPE mard-matnr,
            insme TYPE mard-insme,
            einme TYPE mard-einme,
            speme TYPE mard-speme,
          END OF i_mard.
    DATA: BEGIN OF i_makt OCCURS 0,
            matnr TYPE makt-matnr,
            maktx TYPE makt-maktx,
            maktg TYPE makt-maktg,
          END OF i_makt.
    *&      ALV Variables
    TYPE-POOLS :slis.
    DATA :i_field   TYPE slis_t_fieldcat_alv,
          w_field   LIKE LINE OF i_field,
          w_layout  TYPE slis_layout_alv,
          i_events  TYPE slis_t_event,
          w_events  LIKE LINE OF i_events.
    DATA :i_field1   TYPE slis_t_fieldcat_alv,
          w_field1   LIKE LINE OF i_field1,
          w_layout1  TYPE slis_layout_alv,
          i_events1  TYPE slis_t_event,
          w_events1  LIKE LINE OF i_events1.
    *&      START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM get_data_from_database .
    *&      END-OF-SELECTION
    END-OF-SELECTION.
      PERFORM build_fieldcatalog.
      PERFORM build_events.
      PERFORM display_data.
    *&      Form  build_fieldcatalog
    FORM build_fieldcatalog .
      CLEAR :
        w_field,
       i_field[].
      CLEAR :
        w_field1,
       i_field1[].
    Fieldcatalog 1
      w_field-fieldname = 'WERKS' .
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'Plant'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'LGORT' .
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'S.Location'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'MATNR'.
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'Mat No'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'INSME' .
      w_field-do_sum = 'X'.
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'quality Stock'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'EINME'.
      w_field-do_sum = 'X'.
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'Total Stock'.
      APPEND w_field TO i_field.
      CLEAR w_field.
      w_field-fieldname = 'SPEME'.
      w_field-do_sum = 'X'.
      w_field-tabname = 'I_MARD'.
      w_field-seltext_m = 'Blocked stock'.
      APPEND w_field TO i_field.
      CLEAR w_field.
    Fieldcatalog 2
      w_field1-fieldname = 'MATNR'.
      w_field1-tabname = 'I_MAKT'.
      w_field1-seltext_m = 'MATNR'.
      APPEND w_field1 TO i_field1.
      CLEAR w_field1.
      w_field1-fieldname = 'MAKTX'.
      w_field1-tabname = 'I_MAKT'.
      w_field1-seltext_m = 'MAKTX'.
      APPEND w_field1 TO i_field1.
      CLEAR w_field1.
      w_field1-fieldname = 'MAKTG'.
      w_field1-tabname = 'I_MAKT'.
      w_field1-seltext_m = 'MAKTG'.
      APPEND w_field1 TO i_field1.
      CLEAR w_field1.
    ENDFORM.                    " build_fieldcatalog
    *&      Form  build_events
    FORM build_events .
      CLEAR:
        w_events,
        i_events[],
        w_events1,
        i_events1[].
      w_events-name = 'TOP_OF_PAGE' .
      w_events-form = 'TOP_OF_PAGE' .
      APPEND w_events TO i_events.
      CLEAR w_events.
      w_events1-name = 'TOP_OF_PAGE' .
      w_events1-form = 'TOP_OF_PAGE' .
      APPEND w_events1 TO i_events1.
      CLEAR w_events1.
    ENDFORM.                    " build_events
    *&      Form  display_data
    FORM display_data .
      DATA :program LIKE sy-repid VALUE sy-repid.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
        EXPORTING
          i_callback_program             = program
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      IT_EXCLUDING                   =
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = w_layout
          it_fieldcat                      = i_field
          i_tabname                        = 'I_MARD'
          it_events                        = i_events
      IT_SORT                          =
      I_TEXT                           = ' '
        TABLES
          t_outtab                         = i_mard
    EXCEPTIONS
      PROGRAM_ERROR                    = 1
      MAXIMUM_OF_APPENDS_REACHED       = 2
      OTHERS                           = 3
      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 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = w_layout
          it_fieldcat                      = i_field1
          i_tabname                        = 'I_MAKT'
          it_events                        = i_events1
      IT_SORT                          =
      I_TEXT                           = ' '
        TABLES
          t_outtab                         = i_makt
    EXCEPTIONS
      PROGRAM_ERROR                    = 1
      MAXIMUM_OF_APPENDS_REACHED       = 2
      OTHERS                           = 3
      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 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK             = ' '
      IS_PRINT                      =
      I_SCREEN_START_COLUMN         = 0
      I_SCREEN_START_LINE           = 0
      I_SCREEN_END_COLUMN           = 0
      I_SCREEN_END_LINE             = 0
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER       =
      ES_EXIT_CAUSED_BY_USER        =
    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
    *&      Form  get_data_from_database
          text
    FORM get_data_from_database .
      SELECT werks lgort matnr insme einme speme
      FROM mard
      INTO CORRESPONDING FIELDS OF TABLE i_mard
      UP TO 20 ROWS
      WHERE werks = 'WF01'.
      SELECT  matnr
              maktx
              maktg
        FROM makt
        INTO TABLE i_makt
        UP TO 20 ROWS.
    ENDFORM.                    " get_data_from_database
    *&      Form  top_of_page
          text
    FORM top_of_page.
      DATA: inc_colnum TYPE i.
      ULINE .
      inc_colnum = sy-linsz - 60.
      WRITE: / 'Report: ', sy-repid(18).
      WRITE AT 30(inc_colnum) sy-title CENTERED.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Page: ', (11) sy-pagno RIGHT-JUSTIFIED.
      WRITE: / 'Client: ', sy-mandt.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Date: ', sy-datum.
      WRITE: / 'User  : ', sy-uname.
      inc_colnum = sy-linsz - 60.
      WRITE AT 30(inc_colnum) 'Blocked ALV' CENTERED.
      inc_colnum = sy-linsz - 20.
      WRITE: AT inc_colnum 'Time: ', (10) sy-uzeit RIGHT-JUSTIFIED.
      ULINE .
    ENDFORM.                    "top_of_page
    I think that example will solve ur problem.
    <b>Thanks,
    Venkat.O</b>

  • Hi ragarding ALV Reports

    Hi.....
    how we maintain list headings in case of alv interactive reporting.
    please provide some logic hints if possible.

    Hi
    See the sample report..Reward points for the same as per SDN rules and regulations
    report ZRGRIRNA no standard page heading
           line-count 65
           line-size 255
           message-id mm.
                       GR IR Detail Report                               *
    Description          : The output has to be displayed
                           in the ALV Grid format with the Selection     *
                           screen appearing on the output. In The Output *
                           Subtotals for Vendor, Plant, Period, Material,*
                           Valuation Class, Purchase Order,Cost Center,  *
                           Cost Element and Receipt Date are displayed   *
                           after sorting the data by same fields.        *
    Declaration for Tables
    tables: t001,      " Company Codes
            t001w,     " Plants/Branches
            lfa1,      " Vendor Master
            ska1,      " GL Account Master
            mara,      " Material Master
            mbew,      " Material Valuation
            ekko,      " PO Header Data
            cska,      " Cost Elements
            csks,      " Cost Centers
            bsis,      " GL Accounts: Open Items Data
            bkpf.      " Accounting Doc: Header Data
    Type-pools
    Type pools for ALV display
    type-pools : slis.
    Global variables
    data: g_repid       like sy-repid,
          g_exit        type c,
          g_events      type slis_t_event,
          g_list_top_of_page type slis_t_listheader,
          g_exit_caused_by_caller,
          g_exit_caused_by_user type slis_exit_by_user,
          g_top_of_page  type slis_formname value 'TOP_OF_PAGE',
          g_variant like disvariant,
          g_save.
    Declaration for Constants
    constants : c_x  type c  value 'X',         " Flag
                c_c  type c  value 'C',         " Flag
                c_l  type c  value 'L',         " Flag
                c_a  type c  value 'A',         " Line Type
                c_h  type c  value 'H',         " Dr/Cr
                c_s  type c  value 'S',         " Line Type
                c_mkpf(4) type c value 'MKPF'.  " Table
    Declaration of Internal Tables
    Internal Table for BSIS Table data
    data: begin of i_bsis occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            hkont like bsis-hkont,          " GR IR Account
            gjahr like bsis-gjahr,          " Fiscal Year
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            budat like bsis-budat,          " Receipt Date(Posting)
            monat like bsis-monat,          " Period
          end of i_bsis.
    Internal Table for BSEG Table data
    data: begin of i_bseg occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            gjahr like bsis-gjahr,          " Fiscal Year
            shkzg like bseg-shkzg,          " Dr/Cr Indicator
            lifnr like bseg-lifnr,          " Vendor Code
            matnr like bseg-matnr,          " Material No
            ebeln like bseg-ebeln,          " Purchase Order
            ebelp like bseg-ebelp,          " PO Item
            werks like bseg-werks,          " Plant
            menge like bseg-menge,          " PO Quantity
            meins like bseg-meins,          " UOM
            dmbtr like bseg-dmbtr,          " Amount in Local Currency
            wrbtr like bseg-wrbtr,          " Amount in Trans.Currency
          end of i_bseg.
    Internal Table for BKPF Table data
    data: begin of i_bkpf occurs 0,
            bukrs like bkpf-bukrs,          " Company Code
            belnr like bkpf-belnr,          " Acc Document
            gjahr like bkpf-gjahr,          " Fiscal Year
            waers like bkpf-waers,          " Trans. Currency
            awkey like bkpf-awkey,          " Object Key
            awtyp like bkpf-awtyp,          " Reference Procedure
          end of i_bkpf.
    Internal Table for MSEG Table data
    data: begin of i_mseg occurs 0,
            mblnr like mseg-mblnr,          " Material Document
            mjahr like mseg-mjahr,          " Fiscal Year
            bwart like mseg-bwart,          " Movement Type
            matnr like mseg-matnr,          " Material No
            menge like mseg-menge,          " PO Quantity
            meins like mseg-meins,          " UOM
          end of i_mseg.
    Internal Table for MBEW Table data
    data: begin of i_mbew occurs 0,
            matnr like mbew-matnr,          " Material No
            werks like mbew-bwkey,          " Plant
            bklas like mbew-bklas,          " Valuation Class
          end of i_mbew.
    Internal Table for EKPO Table data
    data: begin of i_ekpo occurs 0,
            ebeln like ekpo-ebeln,          " Purchase Order
            ebelp like ekpo-ebelp,          " PO Item
            matnr like ekpo-matnr,          " Material No
            txz01 like ekpo-txz01,          " Material Text
          end of i_ekpo.
    Internal Table for EKKN Table data
    data: begin of i_ekkn occurs 0,
            ebeln like ekkn-ebeln,          " Purchase Order
            ebelp like ekkn-ebelp,          " PO Item
            kostl like ekkn-kostl,          " Cost Center
            sakto like ekkn-sakto,          " Cost Element
          end of i_ekkn.
    Internal Table for LFA1 Table data
    data: begin of i_lfa1 occurs 0,
            lifnr like lfa1-lifnr,          " Vendor
            name1 like lfa1-name1,          " Name
          end of i_lfa1.
    Declaration of Output Internal Table
    data: begin of i_final occurs 0,
            lifnr like lfa1-lifnr,     " Vendor
            werks like bseg-werks,     " Plant
            monat like bsis-monat,     " Period
            matnr like mara-matnr,     " Material Number
            bklas like mbew-bklas,     " Val Class
            ebeln like bseg-ebeln,     " PO
            kostl like ekkn-kostl,     " Cost Center
            sakto like ekkn-sakto,     " Cost Element
            budat like bsis-budat,     " Rec. Date
            name1 like lfa1-name1,     " Vendor Name
            belnr like bsis-belnr,     " FI Document
            bwart like mseg-bwart,     " Movement Type
            txz01 like ekpo-txz01,     " Material Text
            menge like bseg-menge,     " Quantity
            meins like bseg-meins,     " UOM
            dmbtr like bseg-dmbtr,     " Local Amount
            wrbtr like bseg-wrbtr,     " Tran.Amount
            waers like bkpf-waers,     " Tran.Currency
            status type c,             " Material Status
          end of i_final.
    Internal table to hold field catgory data
    data:  i_fldcat  type slis_t_fieldcat_alv.   " Table - field catgory
    Internal table to hold Sort/Subtotals criteria data
    data:  i_sort  type slis_t_sortinfo_alv.     " Table - sort/Subtotals
    Structure
    data:  x_layout   type slis_layout_alv,      " Structure-layout
           x_fldcat   like line of i_fldcat,     " Structure-field catagory
           x_sort     like line of i_sort.       " Structure-Sort/Subtotals
           Selection screen
    selection-screen : begin of block b1 with frame title text-000.
    parameters:
       p_bukrs like t001-bukrs obligatory,          " Company Code
       p_grira like ska1-saknr default '0241101000' obligatory. " Account
    select-options:
       s_budat for bkpf-budat,        " Posting Date
       s_werks for t001w-werks,       " Plant
       s_lifnr for lfa1-lifnr,        " Vendor
       s_matnr for mara-matnr,        " Material Number
       s_kostl for csks-kostl,        " Cost Center
       s_kstar for cska-kstar,        " Cost Element
       s_ebeln for ekko-ebeln,        " Purchase Order
       s_monat for bsis-monat.        " Period
    selection-screen skip.
    parameters:
       p_incmt as checkbox default 'X',
       p_incnm as checkbox default 'X'.
    selection-screen end of block b1.
    Initialization
    initialization.
      g_repid = sy-repid.
      perform layout_init using x_layout.
      perform eventtab_build using g_events[].
      g_variant-report = g_repid.
      g_save           = 'A'.
    At selection screen
    at selection-screen.
    Validation of Selection Screen Fields
      perform validate_screen.
    Start of selection
    start-of-selection.
    Read Data from Database Tables
      perform read_data.
    End of selection
    end-of-selection.
    Build layout report layout.
      perform populate_layout_stucture.
    Perform build_field_catalog and Sort Table
      perform build_field_catalog.
      perform build_sort_totals.
    List Header for Top-Of-Page
      perform comment_build using g_list_top_of_page[].
    Call list viewer function module
      perform call_list_viewer .
    ****************Form - Routines**************************************
          Form        : layout_init
          Description : Form to Build layout for list display
    form layout_init using rs_layout type slis_layout_alv.
      rs_layout-detail_popup      = c_x.
    endform.
    Form         : Eventtab_build
    Description  : Registration of events to happen during list display
    form eventtab_build using rt_events type slis_t_event.
    Registration of events to happen during list display
      data: ls_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = rt_events.
      read table rt_events with key name = slis_ev_top_of_page
                               into ls_event.
      if sy-subrc = 0.
        move g_top_of_page to ls_event-form.
        append ls_event to rt_events.
      endif.
    endform.                                   "eventtab_build
          Form : top_of_page
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
             I_LOGO             = 'ENJOYSAP_LOGO'
                it_list_commentary = g_list_top_of_page.
    endform.
          Form validate_screen
    Validation of Selection Screen fields
    form validate_screen.
    Validation of Company Code
      clear t001.
      if not p_bukrs is initial.
        select single bukrs
          into t001-bukrs
          from t001
          where bukrs eq p_bukrs.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Company Code'(012).
        endif.
      endif.
    Validation of GL Account (GR/IR)
      clear ska1.
      if not p_grira is initial.
        select saknr
          into ska1-saknr
          from ska1
          up to 1 rows
          where saknr eq p_grira.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid GR/IR Account'(013).
        endif.
      endif.
    Validation of Vendor Code
      clear lfa1.
      if not s_lifnr[] is initial.
        select single lifnr
          into lfa1-lifnr
          from lfa1
          where lifnr in s_lifnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Vendor'(001).
        endif.
      endif.
    Validation of Plant Code
      clear t001w.
      if not s_werks[] is initial.
        select single werks
          into t001w-werks
          from t001w
          where werks in s_werks.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Plant'(014).
        endif.
      endif.
    Validation of Material Code
      clear mara.
      if not s_matnr[] is initial.
        select single matnr
          into mara-matnr
          from mara
          where matnr in s_matnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Material'(015).
        endif.
      endif.
    Validation of Purchase Order
      clear ekko.
      if not s_ebeln[] is initial.
        select single ebeln
          into ekko-ebeln
          from ekko
          where ebeln in s_ebeln.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Purchase Order'(016).
        endif.
      endif.
    Validation of Cost Center
      clear csks.
      if not s_kostl[] is initial.
        select kostl
          into csks-kostl
          from csks
          up to 1 rows
          where kostl in s_kostl.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Center'(017).
        endif.
      endif.
    Validation of Cost Element
      clear cska.
      if not s_kstar[] is initial.
        select kstar
          into cska-kstar
          from cska
          up to 1 rows
          where kstar in s_kstar.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Element'(018).
        endif.
      endif.
    endform.                          "validate_screen
    *&      Form  read_data
    Read the Data from the database Tables
    form read_data.
    Get the Accounting Documents for the GR/IR Account Entered on
    Selection Screen
      clear i_bsis.
      refresh i_bsis.
      select bukrs           " Company Code
             hkont           " GR IR Account
             gjahr           " Fiscal Year
             belnr           " Acc Document
             buzei           " Item No
             budat           " Receipt Date(Posting)
             monat           " Period
       into table i_bsis
       from  bsis
       where  bukrs = p_bukrs
         and  hkont = p_grira
         and  budat in s_budat
         and  monat in s_monat .
      if sy-subrc <> 0.
        message i899 with 'No data found'(043).
        g_exit = c_x.
        stop.
      endif.
      sort i_bsis by bukrs hkont gjahr belnr buzei.
    Get the Vendor,PO,Material,Qty details from BSEG Table
      if not i_bsis[] is initial.
        clear i_bseg.
        refresh i_bseg.
        select bukrs           " Company Code
               belnr           " Acc Document
               buzei           " Item No
               gjahr           " Fiscal Year
               shkzg           " Dr/Cr Indicator
               lifnr           " Vendor Code
               matnr           " Material No
               ebeln           " Purchase Order
               ebelp           " PO Item
               werks           " Plant
               menge           " PO Quantity
               meins           " UOM
               dmbtr           " Amount in Local Currency
               wrbtr           " Amount in Trans.Currency
        into table i_bseg
        from   bseg
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr
        and    buzei = i_bsis-buzei
        and    lifnr in s_lifnr
        and    werks in s_werks
        and    matnr in s_matnr
        and    ebeln in s_ebeln.
        sort i_bseg by bukrs belnr buzei gjahr.
    Select the Trans.Currency from BKPF Table
        clear i_bkpf.
        refresh i_bkpf.
        select bukrs           " Company Code
               belnr           " Acc Document
               gjahr           " Fiscal Year
               waers           " Trans. Currency
               awkey           " Object Key
               awtyp           " Reference Procedure
        into table i_bkpf
        from   bkpf
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr.
      endif.
      sort i_bkpf by bukrs belnr gjahr.
    Get the Quantity and UOM of Material from MSEG Table
      if not i_bkpf[] is initial.
        clear i_mseg.
        refresh i_mseg.
        select mblnr           " Material Document
               mjahr           " Fiscal Year
               bwart           " Movement Type
               matnr           " Material No
               menge           " PO Quantity
               meins           " UOM
          into table i_mseg
          from   mseg
          for all entries in i_bkpf
          where  mblnr = i_bkpf-awkey(10).
      endif.
      sort i_mseg by mblnr mjahr.
    Get the Material And Description from EKPO Table
      if not i_bseg[] is initial.
        clear i_ekpo.
        refresh i_ekpo.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               matnr           " Material No
               txz01           " Material Text
        into table i_ekpo
        from   ekpo
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp.
        sort i_ekpo by ebeln ebelp.
    Get the Valuation Class from MBEW Table
        clear i_mbew.
        refresh i_mbew.
        select matnr           " Material No
               bwkey           " Plant
               bklas           " Valuation Class
        into table i_mbew
        from   mbew
        for all entries in i_bseg
        where  matnr = i_bseg-matnr
        and    bwkey = i_bseg-werks.
        sort i_mbew by matnr werks.
    Get the Cost Center and Cost Element of the PO from EKKN Table
        clear i_ekkn.
        refresh i_ekkn.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               kostl           " Cost Center
               sakto           " Cost Element
        into table i_ekkn
        from   ekkn
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp
        and    kostl in s_kostl
        and    sakto in s_kstar.
        sort i_ekkn by ebeln ebelp.
    Get the Vendor Name
        clear i_lfa1.
        refresh i_lfa1.
        select lifnr            " Vendor
               name1            " Name
        into table i_lfa1
        from   lfa1
        for all entries in i_bseg
        where  lifnr = i_bseg-lifnr.
      endif.
      sort i_lfa1 by lifnr.
    Move the data to Final Output Internal Table
      loop at i_bsis.
        i_final-belnr = i_bsis-belnr.     " FI Document
        i_final-monat = i_bsis-monat.     " Period
        i_final-budat = i_bsis-budat.     " Rec. Date
    Read the Transaction Currency from BKPF Internal Table
        read table i_bkpf with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   binary search.
        if sy-subrc = 0.
          i_final-waers = i_bkpf-waers.     " Tran.Currency
    Read the Movement Type for all Material Related
    Documents from MSEG Internal Table
          if i_bkpf-awtyp = c_mkpf.
            read table i_mseg with key mblnr = i_bkpf-awkey(10)
                                       mjahr = i_bkpf-awkey+10(4).
            if sy-subrc = 0.
              i_final-bwart = i_mseg-bwart.     " Movement Type
            endif.
          endif.
        endif.
    Read Vendor, Plant, PO Document, Local And Trans.Amounts
    from BSEG Internal Table
        read table i_bseg with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   buzei = i_bsis-buzei
                                   binary search.
        if sy-subrc = 0.
          i_final-lifnr = i_bseg-lifnr.     " Vendor
          i_final-werks = i_bseg-werks.     " Plant
          i_final-ebeln = i_bseg-ebeln.     " PO
          i_final-dmbtr = i_bseg-dmbtr.     " Local Amount
          i_final-wrbtr = i_bseg-wrbtr.     " Tran.Amount
          i_final-menge = i_bseg-menge.     " Quantity
          i_final-meins = i_bseg-meins.     " UOM
    For Credit Indicator(SHKZG = H) amounts should be (-)ve
          if i_bseg-shkzg = c_h.
            i_final-dmbtr = i_final-dmbtr * -1.
            i_final-wrbtr = i_final-wrbtr * -1.
            i_final-menge = i_final-menge * -1.
          endif.
    Read the Material and its Description from EKPO Internal Table
          read table i_ekpo with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     matnr = i_bseg-matnr
                                     binary search.
          if sy-subrc = 0.
            i_final-matnr = i_ekpo-matnr.     " Material Number
            i_final-txz01 = i_ekpo-txz01.     " Material Text
    Populate the Material Status depending on the Input Checkbox
    On Selection Screen
            if not i_ekpo-matnr is initial.
              i_final-status = c_x.
            endif.
          endif.
    Read the PO related Cost Element and Cost Centers
    from EKKN Internal Table
          read table i_ekkn with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     binary search.
          if sy-subrc = 0.
            i_final-kostl = i_ekkn-kostl.     " Cost Center
            i_final-sakto = i_ekkn-sakto.     " Cost Element
          endif.
    Read the Valuation Class from MBEW Internal Table
          read table i_mbew with key matnr = i_bseg-matnr
                                     werks = i_bseg-werks
                                     binary search.
          if sy-subrc = 0.
            i_final-bklas = i_mbew-bklas.     " Val Class
          endif.
    Read the Vendor Name from LFA1 Internal Table
          read table i_lfa1 with key lifnr = i_bseg-lifnr
                                     binary search.
          if sy-subrc = 0.
            i_final-name1 = i_lfa1-name1.     " Vendor Name
          endif.
        endif.
        append i_final.
        clear i_final.
      endloop.
      sort i_final by lifnr werks monat matnr.
    Depending on the check Box Selected display the data
      if p_incmt = c_x and p_incnm ne c_x.
        delete i_final where matnr eq space.
      elseif p_incnm = c_x and p_incmt ne c_x.
        delete i_final where matnr ne space.
      endif.
    endform.           "Read Data
         Form        : populate_layout_stucture
         Description : Populating the layout structure
    form populate_layout_stucture.
      clear x_layout .
    Layout properties
      x_layout-zebra                = c_x.
      x_layout-detail_popup         = c_x.
      x_layout-detail_initial_lines = c_x.
      x_layout-colwidth_optimize    = c_x.
    endform.                    " populate_layout_stucture
         Form        : build_field_catalog
         Description : Building the field catalog data
    form build_field_catalog.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
           exporting
                i_program_name         = g_repid
                i_internal_tabname     = 'I_FINAL'
                i_inclname             = g_repid
           changing
                ct_fieldcat            = i_fldcat
           exceptions
                inconsistent_interface = 1
                program_error          = 2
                others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    Getting the Header text for the coloums
      loop at i_fldcat into x_fldcat where fieldname = 'LIFNR' or
                                           fieldname = 'NAME1' or
                                           fieldname = 'WERKS' or
                                           fieldname = 'MONAT' or
                                           fieldname = 'MATNR' or
                                           fieldname = 'BKLAS' or
                                           fieldname = 'EBELN' or
                                           fieldname = 'KOSTL' or
                                           fieldname = 'SAKTO' or
                                           fieldname = 'BUDAT' or
                                           fieldname = 'BELNR' or
                                           fieldname = 'BWART' or
                                           fieldname = 'TXZ01' or
                                           fieldname = 'MENGE' or
                                           fieldname = 'MEINS' or
                                           fieldname = 'DMBTR' or
                                           fieldname = 'WRBTR' or
                                           fieldname = 'WAERS' or
                                           fieldname = 'STATUS'.
        if x_fldcat-fieldname = 'LIFNR'.
          x_fldcat-seltext_l   = 'Vendor'(003).
          x_fldcat-seltext_m   = 'Vendor'(003).
          x_fldcat-seltext_s   = 'Vendor'(003).
          x_fldcat-reptext_ddic = 'Vendor'(003).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'NAME1'.
          x_fldcat-seltext_l   = 'Vendor Name'(002).
          x_fldcat-seltext_m   = 'Vendor Name'(002).
          x_fldcat-seltext_s   = 'Vendor Name'(002).
          x_fldcat-reptext_ddic = 'Vendor Name'(002).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'WERKS'.
          x_fldcat-seltext_l   = 'Plant'(010).
          x_fldcat-seltext_m   = 'Plant'(010).
          x_fldcat-seltext_s   = 'Plant'(010).
          x_fldcat-reptext_ddic   = 'Plant'(010).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MONAT'.
          x_fldcat-seltext_l   = 'Period'(011).
          x_fldcat-seltext_m   = 'Period'(011).
          x_fldcat-seltext_s   = 'Period'(011).
          x_fldcat-reptext_ddic   = 'Period'(011).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MATNR'.
          x_fldcat-seltext_l   = 'Material'(004).
          x_fldcat-seltext_m   = 'Material'(004).
          x_fldcat-seltext_s   = 'Material'(004).
          x_fldcat-reptext_ddic   = 'Material'(004).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BKLAS'.
          x_fldcat-seltext_l   = 'Valuation Class'(009).
          x_fldcat-seltext_m   = 'Valuation Class'(009).
          x_fldcat-seltext_s   = 'Valuation Class'(009).
          x_fldcat-reptext_ddic   = 'Valuation Class'(009).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'EBELN'.
          x_fldcat-seltext_l   = 'Purchase Order'(005).
          x_fldcat-seltext_m   = 'Purchase Order'(005).
          x_fldcat-seltext_s   = 'Purchase Order'(005).
          x_fldcat-reptext_ddic   = 'Purchase Order'(005).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'KOSTL'.
          x_fldcat-seltext_l   = 'Cost Center'(006).
          x_fldcat-seltext_m   = 'Cost Center'(006).
          x_fldcat-seltext_s   = 'Cost Center'(006).
          x_fldcat-reptext_ddic   = 'Cost Center'(006).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'SAKTO'.
          x_fldcat-seltext_l   = 'Cost Element'(007).
          x_fldcat-seltext_m   = 'Cost Element'(007).
          x_fldcat-seltext_s   = 'Cost Element'(007).
          x_fldcat-reptext_ddic   = 'Cost Element'(007).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BUDAT'.
          x_fldcat-seltext_l   = 'Receipt Date'(008).
          x_fldcat-seltext_m   = 'Receipt Date'(008).
          x_fldcat-seltext_s   = 'Receipt Date'(008).
          x_fldcat-reptext_ddic   = 'Receipt Date'(008).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BELNR'.
          x_fldcat-seltext_l   = 'Acc.Document'(100).
          x_fldcat-seltext_m   = 'Acc.Document'(100).
          x_fldcat-seltext_s   = 'Acc.Document'(100).
          x_fldcat-reptext_ddic   = 'Acc.Document'(100).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BWART'.
          x_fldcat-seltext_l   = 'Movement Type'(101).
          x_fldcat-seltext_m   = 'Movement Type'(101).
          x_fldcat-seltext_s   = 'Movement Type'(101).
          x_fldcat-reptext_ddic   = 'Movement Type'(101).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'TXZ01'.
          x_fldcat-seltext_l   = 'Material Text'(102).
          x_fldcat-seltext_m   = 'Material Text'(102).
          x_fldcat-seltext_s   = 'Material Text'(102).
          x_fldcat-reptext_ddic   = 'Material Text'(102).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MENGE'.
          x_fldcat-seltext_l   = 'Quantity'(103).
          x_fldcat-seltext_m   = 'Quantity'(103).
          x_fldcat-seltext_s   = 'Quantity'(103).
          x_fldcat-reptext_ddic   = 'Quantity'(103).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'MEINS'.
          x_fldcat-seltext_l   = 'UOM'(104).
          x_fldcat-seltext_m   = 'UOM'(104).
          x_fldcat-seltext_s   = 'UOM'(104).
          x_fldcat-reptext_ddic   = 'UOM'(104).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'DMBTR'.
          x_fldcat-seltext_l   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_m   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_s   = 'Amount in Local Curr'(105).
          x_fldcat-reptext_ddic   = 'Amount in Local Curr'(105).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WRBTR'.
          x_fldcat-seltext_l   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_m   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_s   = 'Amount in Trans.Curr'(106).
          x_fldcat-reptext_ddic   = 'Amount in Trans.Curr'(106).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WAERS'.
          x_fldcat-seltext_l   = 'Trans.Currency'(107).
          x_fldcat-seltext_m   = 'Trans.Currency'(107).
          x_fldcat-seltext_s   = 'Trans.Currency'(107).
          x_fldcat-reptext_ddic   = 'Trans.Currency'(107).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'STATUS'.
          x_fldcat-seltext_l   = 'Material Status'(019).
          x_fldcat-seltext_m   = 'Material Status'(019).
          x_fldcat-seltext_s   = 'Material Status'(019).
          x_fldcat-reptext_ddic   = 'Material Status'(019).
          x_fldcat-ddictxt   = c_l.
        endif.
        modify i_fldcat from x_fldcat index sy-tabix.
      endloop.
    endform.                    " build_field_catalog
         Form        : build_sort_totals
         Description : Building the Criteria for Sort/Subtotals
    form build_sort_totals.
      x_sort-fieldname = 'LIFNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  1.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'WERKS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  2.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MONAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  3.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MATNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  4.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BKLAS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  5.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'EBELN'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  6.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'KOSTL'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  7.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'SAKTO'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  8.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BUDAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  9.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
    endform.                    " build_sort_totals
      Form        : comment_build
      Description : This form is used to display the Report Header(ALV)
    form comment_build using lt_top_of_page type
                                            slis_t_listheader.
      data: l_line type slis_listheader,
            l_heading1 like rs38m-repti,
            l_date(10), l_time(8).
      clear l_line.
      l_heading1 = 'GR/IR DETAIL REPORT'(021).
      g_repid = sy-repid.
      write sy-uzeit to l_time.
      write sy-datum to l_date.
      l_line-typ = c_h.
      move l_heading1 to l_line-info.
      append l_line to lt_top_of_page.
      clear l_line.
      l_line-typ  = c_s.
      concatenate 'System:'(023) sy-sysid
                  'Date:'(024) l_date
                  ' Time:'(025)
                  l_time into l_line-info.
      append l_line to lt_top_of_page.
      concatenate 'Report:'(026) g_repid
                  ' User:'(027) sy-uname into
                  l_line-info.
      append l_line to lt_top_of_page.
      l_line-typ = c_a.
      move 'SELECTION CRITERIA:'(028) to l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Company Code : '(029)
                  p_bukrs into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' GR/IR Account: '(030)
                  p_grira into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Posting Date : '(032) s_budat-low
                  ' To: '(031) s_budat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Plant : '(033) s_werks-low
                  ' To: '(031) s_werks-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Vendor: '(034) s_lifnr-low
                  ' To: '(031) s_lifnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Material: '(035) s_matnr-low
                  ' To: '(031) s_matnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Center : '(036) s_kostl-low
                  ' To: '(031) s_kostl-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Element: '(037) s_kstar-low
                  ' To: '(031) s_kstar-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Purchase Order: '(038) s_ebeln-low
                  ' To: '(031) s_ebeln-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Period : '(039) s_monat-low
                  ' To: '(031) s_monat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Material Items: '(040)
                  p_incmt into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Non-Material Items: '(041)
                  p_incnm into l_line-info.
      append l_line to lt_top_of_page.
    endform.
         Form        : call_list_viewer
         Description : This form is used to display the grid through ALV
    form call_list_viewer.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = g_repid
                is_layout               = x_layout
                it_fieldcat             = i_fldcat[]
                i_default               = c_x
                it_sort                 = i_sort[]
                i_save                  = g_save
                is_variant              = g_variant
                it_events               = g_events[]
           importing
                e_exit_caused_by_caller = g_exit_caused_by_caller
                es_exit_caused_by_user  = g_exit_caused_by_user
           tables
                t_outtab                = i_final
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
        write: / 'Problem in calling the ALV report'(042).
      endif.
    endform.                    " call_list_viewer
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Sample ALV Report

    Hi,
    Please help me with some sample ALV reports for SAP HR.
    Rgds
    Preeti Saun

    Hi,
    See the sample report and design with HR data
    report ZRGRIRNA no standard page heading
           line-count 65
           line-size 255
           message-id mm.
                       GR IR Detail Report                               *
    Description          : The output has to be displayed
                           in the ALV Grid format with the Selection     *
                           screen appearing on the output. In The Output *
                           Subtotals for Vendor, Plant, Period, Material,*
                           Valuation Class, Purchase Order,Cost Center,  *
                           Cost Element and Receipt Date are displayed   *
                           after sorting the data by same fields.        *
    Declaration for Tables
    tables: t001,      " Company Codes
            t001w,     " Plants/Branches
            lfa1,      " Vendor Master
            ska1,      " GL Account Master
            mara,      " Material Master
            mbew,      " Material Valuation
            ekko,      " PO Header Data
            cska,      " Cost Elements
            csks,      " Cost Centers
            bsis,      " GL Accounts: Open Items Data
            bkpf.      " Accounting Doc: Header Data
    Type-pools
    Type pools for ALV display
    type-pools : slis.
    Global variables
    data: g_repid       like sy-repid,
          g_exit        type c,
          g_events      type slis_t_event,
          g_list_top_of_page type slis_t_listheader,
          g_exit_caused_by_caller,
          g_exit_caused_by_user type slis_exit_by_user,
          g_top_of_page  type slis_formname value 'TOP_OF_PAGE',
          g_variant like disvariant,
          g_save.
    Declaration for Constants
    constants : c_x  type c  value 'X',         " Flag
                c_c  type c  value 'C',         " Flag
                c_l  type c  value 'L',         " Flag
                c_a  type c  value 'A',         " Line Type
                c_h  type c  value 'H',         " Dr/Cr
                c_s  type c  value 'S',         " Line Type
                c_mkpf(4) type c value 'MKPF'.  " Table
    Declaration of Internal Tables
    Internal Table for BSIS Table data
    data: begin of i_bsis occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            hkont like bsis-hkont,          " GR IR Account
            gjahr like bsis-gjahr,          " Fiscal Year
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            budat like bsis-budat,          " Receipt Date(Posting)
            monat like bsis-monat,          " Period
          end of i_bsis.
    Internal Table for BSEG Table data
    data: begin of i_bseg occurs 0,
            bukrs like bsis-bukrs,          " Company Code
            belnr like bsis-belnr,          " Acc Document
            buzei like bsis-buzei,          " Item No
            gjahr like bsis-gjahr,          " Fiscal Year
            shkzg like bseg-shkzg,          " Dr/Cr Indicator
            lifnr like bseg-lifnr,          " Vendor Code
            matnr like bseg-matnr,          " Material No
            ebeln like bseg-ebeln,          " Purchase Order
            ebelp like bseg-ebelp,          " PO Item
            werks like bseg-werks,          " Plant
            menge like bseg-menge,          " PO Quantity
            meins like bseg-meins,          " UOM
            dmbtr like bseg-dmbtr,          " Amount in Local Currency
            wrbtr like bseg-wrbtr,          " Amount in Trans.Currency
          end of i_bseg.
    Internal Table for BKPF Table data
    data: begin of i_bkpf occurs 0,
            bukrs like bkpf-bukrs,          " Company Code
            belnr like bkpf-belnr,          " Acc Document
            gjahr like bkpf-gjahr,          " Fiscal Year
            waers like bkpf-waers,          " Trans. Currency
            awkey like bkpf-awkey,          " Object Key
            awtyp like bkpf-awtyp,          " Reference Procedure
          end of i_bkpf.
    Internal Table for MSEG Table data
    data: begin of i_mseg occurs 0,
            mblnr like mseg-mblnr,          " Material Document
            mjahr like mseg-mjahr,          " Fiscal Year
            bwart like mseg-bwart,          " Movement Type
            matnr like mseg-matnr,          " Material No
            menge like mseg-menge,          " PO Quantity
            meins like mseg-meins,          " UOM
          end of i_mseg.
    Internal Table for MBEW Table data
    data: begin of i_mbew occurs 0,
            matnr like mbew-matnr,          " Material No
            werks like mbew-bwkey,          " Plant
            bklas like mbew-bklas,          " Valuation Class
          end of i_mbew.
    Internal Table for EKPO Table data
    data: begin of i_ekpo occurs 0,
            ebeln like ekpo-ebeln,          " Purchase Order
            ebelp like ekpo-ebelp,          " PO Item
            matnr like ekpo-matnr,          " Material No
            txz01 like ekpo-txz01,          " Material Text
          end of i_ekpo.
    Internal Table for EKKN Table data
    data: begin of i_ekkn occurs 0,
            ebeln like ekkn-ebeln,          " Purchase Order
            ebelp like ekkn-ebelp,          " PO Item
            kostl like ekkn-kostl,          " Cost Center
            sakto like ekkn-sakto,          " Cost Element
          end of i_ekkn.
    Internal Table for LFA1 Table data
    data: begin of i_lfa1 occurs 0,
            lifnr like lfa1-lifnr,          " Vendor
            name1 like lfa1-name1,          " Name
          end of i_lfa1.
    Declaration of Output Internal Table
    data: begin of i_final occurs 0,
            lifnr like lfa1-lifnr,     " Vendor
            werks like bseg-werks,     " Plant
            monat like bsis-monat,     " Period
            matnr like mara-matnr,     " Material Number
            bklas like mbew-bklas,     " Val Class
            ebeln like bseg-ebeln,     " PO
            kostl like ekkn-kostl,     " Cost Center
            sakto like ekkn-sakto,     " Cost Element
            budat like bsis-budat,     " Rec. Date
            name1 like lfa1-name1,     " Vendor Name
            belnr like bsis-belnr,     " FI Document
            bwart like mseg-bwart,     " Movement Type
            txz01 like ekpo-txz01,     " Material Text
            menge like bseg-menge,     " Quantity
            meins like bseg-meins,     " UOM
            dmbtr like bseg-dmbtr,     " Local Amount
            wrbtr like bseg-wrbtr,     " Tran.Amount
            waers like bkpf-waers,     " Tran.Currency
            status type c,             " Material Status
          end of i_final.
    Internal table to hold field catgory data
    data:  i_fldcat  type slis_t_fieldcat_alv.   " Table - field catgory
    Internal table to hold Sort/Subtotals criteria data
    data:  i_sort  type slis_t_sortinfo_alv.     " Table - sort/Subtotals
    Structure
    data:  x_layout   type slis_layout_alv,      " Structure-layout
           x_fldcat   like line of i_fldcat,     " Structure-field catagory
           x_sort     like line of i_sort.       " Structure-Sort/Subtotals
           Selection screen
    selection-screen : begin of block b1 with frame title text-000.
    parameters:
       p_bukrs like t001-bukrs obligatory,          " Company Code
       p_grira like ska1-saknr default '0241101000' obligatory. " Account
    select-options:
       s_budat for bkpf-budat,        " Posting Date
       s_werks for t001w-werks,       " Plant
       s_lifnr for lfa1-lifnr,        " Vendor
       s_matnr for mara-matnr,        " Material Number
       s_kostl for csks-kostl,        " Cost Center
       s_kstar for cska-kstar,        " Cost Element
       s_ebeln for ekko-ebeln,        " Purchase Order
       s_monat for bsis-monat.        " Period
    selection-screen skip.
    parameters:
       p_incmt as checkbox default 'X',
       p_incnm as checkbox default 'X'.
    selection-screen end of block b1.
    Initialization
    initialization.
      g_repid = sy-repid.
      perform layout_init using x_layout.
      perform eventtab_build using g_events[].
      g_variant-report = g_repid.
      g_save           = 'A'.
    At selection screen
    at selection-screen.
    Validation of Selection Screen Fields
      perform validate_screen.
    Start of selection
    start-of-selection.
    Read Data from Database Tables
      perform read_data.
    End of selection
    end-of-selection.
    Build layout report layout.
      perform populate_layout_stucture.
    Perform build_field_catalog and Sort Table
      perform build_field_catalog.
      perform build_sort_totals.
    List Header for Top-Of-Page
      perform comment_build using g_list_top_of_page[].
    Call list viewer function module
      perform call_list_viewer .
    ****************Form - Routines**************************************
          Form        : layout_init
          Description : Form to Build layout for list display
    form layout_init using rs_layout type slis_layout_alv.
      rs_layout-detail_popup      = c_x.
    endform.
    Form         : Eventtab_build
    Description  : Registration of events to happen during list display
    form eventtab_build using rt_events type slis_t_event.
    Registration of events to happen during list display
      data: ls_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = rt_events.
      read table rt_events with key name = slis_ev_top_of_page
                               into ls_event.
      if sy-subrc = 0.
        move g_top_of_page to ls_event-form.
        append ls_event to rt_events.
      endif.
    endform.                                   "eventtab_build
          Form : top_of_page
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
             I_LOGO             = 'ENJOYSAP_LOGO'
                it_list_commentary = g_list_top_of_page.
    endform.
          Form validate_screen
    Validation of Selection Screen fields
    form validate_screen.
    Validation of Company Code
      clear t001.
      if not p_bukrs is initial.
        select single bukrs
          into t001-bukrs
          from t001
          where bukrs eq p_bukrs.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Company Code'(012).
        endif.
      endif.
    Validation of GL Account (GR/IR)
      clear ska1.
      if not p_grira is initial.
        select saknr
          into ska1-saknr
          from ska1
          up to 1 rows
          where saknr eq p_grira.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid GR/IR Account'(013).
        endif.
      endif.
    Validation of Vendor Code
      clear lfa1.
      if not s_lifnr[] is initial.
        select single lifnr
          into lfa1-lifnr
          from lfa1
          where lifnr in s_lifnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Vendor'(001).
        endif.
      endif.
    Validation of Plant Code
      clear t001w.
      if not s_werks[] is initial.
        select single werks
          into t001w-werks
          from t001w
          where werks in s_werks.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Plant'(014).
        endif.
      endif.
    Validation of Material Code
      clear mara.
      if not s_matnr[] is initial.
        select single matnr
          into mara-matnr
          from mara
          where matnr in s_matnr.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Material'(015).
        endif.
      endif.
    Validation of Purchase Order
      clear ekko.
      if not s_ebeln[] is initial.
        select single ebeln
          into ekko-ebeln
          from ekko
          where ebeln in s_ebeln.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Purchase Order'(016).
        endif.
      endif.
    Validation of Cost Center
      clear csks.
      if not s_kostl[] is initial.
        select kostl
          into csks-kostl
          from csks
          up to 1 rows
          where kostl in s_kostl.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Center'(017).
        endif.
      endif.
    Validation of Cost Element
      clear cska.
      if not s_kstar[] is initial.
        select kstar
          into cska-kstar
          from cska
          up to 1 rows
          where kstar in s_kstar.
        endselect.
        if sy-subrc <> 0.
          message e899 with 'Enter Valid Cost Element'(018).
        endif.
      endif.
    endform.                          "validate_screen
    *&      Form  read_data
    Read the Data from the database Tables
    form read_data.
    Get the Accounting Documents for the GR/IR Account Entered on
    Selection Screen
      clear i_bsis.
      refresh i_bsis.
      select bukrs           " Company Code
             hkont           " GR IR Account
             gjahr           " Fiscal Year
             belnr           " Acc Document
             buzei           " Item No
             budat           " Receipt Date(Posting)
             monat           " Period
       into table i_bsis
       from  bsis
       where  bukrs = p_bukrs
         and  hkont = p_grira
         and  budat in s_budat
         and  monat in s_monat .
      if sy-subrc <> 0.
        message i899 with 'No data found'(043).
        g_exit = c_x.
        stop.
      endif.
      sort i_bsis by bukrs hkont gjahr belnr buzei.
    Get the Vendor,PO,Material,Qty details from BSEG Table
      if not i_bsis[] is initial.
        clear i_bseg.
        refresh i_bseg.
        select bukrs           " Company Code
               belnr           " Acc Document
               buzei           " Item No
               gjahr           " Fiscal Year
               shkzg           " Dr/Cr Indicator
               lifnr           " Vendor Code
               matnr           " Material No
               ebeln           " Purchase Order
               ebelp           " PO Item
               werks           " Plant
               menge           " PO Quantity
               meins           " UOM
               dmbtr           " Amount in Local Currency
               wrbtr           " Amount in Trans.Currency
        into table i_bseg
        from   bseg
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr
        and    buzei = i_bsis-buzei
        and    lifnr in s_lifnr
        and    werks in s_werks
        and    matnr in s_matnr
        and    ebeln in s_ebeln.
        sort i_bseg by bukrs belnr buzei gjahr.
    Select the Trans.Currency from BKPF Table
        clear i_bkpf.
        refresh i_bkpf.
        select bukrs           " Company Code
               belnr           " Acc Document
               gjahr           " Fiscal Year
               waers           " Trans. Currency
               awkey           " Object Key
               awtyp           " Reference Procedure
        into table i_bkpf
        from   bkpf
        for all entries in i_bsis
        where  bukrs = p_bukrs
        and    belnr = i_bsis-belnr
        and    gjahr = i_bsis-gjahr.
      endif.
      sort i_bkpf by bukrs belnr gjahr.
    Get the Quantity and UOM of Material from MSEG Table
      if not i_bkpf[] is initial.
        clear i_mseg.
        refresh i_mseg.
        select mblnr           " Material Document
               mjahr           " Fiscal Year
               bwart           " Movement Type
               matnr           " Material No
               menge           " PO Quantity
               meins           " UOM
          into table i_mseg
          from   mseg
          for all entries in i_bkpf
          where  mblnr = i_bkpf-awkey(10).
      endif.
      sort i_mseg by mblnr mjahr.
    Get the Material And Description from EKPO Table
      if not i_bseg[] is initial.
        clear i_ekpo.
        refresh i_ekpo.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               matnr           " Material No
               txz01           " Material Text
        into table i_ekpo
        from   ekpo
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp.
        sort i_ekpo by ebeln ebelp.
    Get the Valuation Class from MBEW Table
        clear i_mbew.
        refresh i_mbew.
        select matnr           " Material No
               bwkey           " Plant
               bklas           " Valuation Class
        into table i_mbew
        from   mbew
        for all entries in i_bseg
        where  matnr = i_bseg-matnr
        and    bwkey = i_bseg-werks.
        sort i_mbew by matnr werks.
    Get the Cost Center and Cost Element of the PO from EKKN Table
        clear i_ekkn.
        refresh i_ekkn.
        select ebeln           " Purchase Order
               ebelp           " PO Item
               kostl           " Cost Center
               sakto           " Cost Element
        into table i_ekkn
        from   ekkn
        for all entries in i_bseg
        where  ebeln = i_bseg-ebeln
        and    ebelp = i_bseg-ebelp
        and    kostl in s_kostl
        and    sakto in s_kstar.
        sort i_ekkn by ebeln ebelp.
    Get the Vendor Name
        clear i_lfa1.
        refresh i_lfa1.
        select lifnr            " Vendor
               name1            " Name
        into table i_lfa1
        from   lfa1
        for all entries in i_bseg
        where  lifnr = i_bseg-lifnr.
      endif.
      sort i_lfa1 by lifnr.
    Move the data to Final Output Internal Table
      loop at i_bsis.
        i_final-belnr = i_bsis-belnr.     " FI Document
        i_final-monat = i_bsis-monat.     " Period
        i_final-budat = i_bsis-budat.     " Rec. Date
    Read the Transaction Currency from BKPF Internal Table
        read table i_bkpf with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   binary search.
        if sy-subrc = 0.
          i_final-waers = i_bkpf-waers.     " Tran.Currency
    Read the Movement Type for all Material Related
    Documents from MSEG Internal Table
          if i_bkpf-awtyp = c_mkpf.
            read table i_mseg with key mblnr = i_bkpf-awkey(10)
                                       mjahr = i_bkpf-awkey+10(4).
            if sy-subrc = 0.
              i_final-bwart = i_mseg-bwart.     " Movement Type
            endif.
          endif.
        endif.
    Read Vendor, Plant, PO Document, Local And Trans.Amounts
    from BSEG Internal Table
        read table i_bseg with key bukrs = i_bsis-bukrs
                                   belnr = i_bsis-belnr
                                   gjahr = i_bsis-gjahr
                                   buzei = i_bsis-buzei
                                   binary search.
        if sy-subrc = 0.
          i_final-lifnr = i_bseg-lifnr.     " Vendor
          i_final-werks = i_bseg-werks.     " Plant
          i_final-ebeln = i_bseg-ebeln.     " PO
          i_final-dmbtr = i_bseg-dmbtr.     " Local Amount
          i_final-wrbtr = i_bseg-wrbtr.     " Tran.Amount
          i_final-menge = i_bseg-menge.     " Quantity
          i_final-meins = i_bseg-meins.     " UOM
    For Credit Indicator(SHKZG = H) amounts should be (-)ve
          if i_bseg-shkzg = c_h.
            i_final-dmbtr = i_final-dmbtr * -1.
            i_final-wrbtr = i_final-wrbtr * -1.
            i_final-menge = i_final-menge * -1.
          endif.
    Read the Material and its Description from EKPO Internal Table
          read table i_ekpo with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     matnr = i_bseg-matnr
                                     binary search.
          if sy-subrc = 0.
            i_final-matnr = i_ekpo-matnr.     " Material Number
            i_final-txz01 = i_ekpo-txz01.     " Material Text
    Populate the Material Status depending on the Input Checkbox
    On Selection Screen
            if not i_ekpo-matnr is initial.
              i_final-status = c_x.
            endif.
          endif.
    Read the PO related Cost Element and Cost Centers
    from EKKN Internal Table
          read table i_ekkn with key ebeln = i_bseg-ebeln
                                     ebelp = i_bseg-ebelp
                                     binary search.
          if sy-subrc = 0.
            i_final-kostl = i_ekkn-kostl.     " Cost Center
            i_final-sakto = i_ekkn-sakto.     " Cost Element
          endif.
    Read the Valuation Class from MBEW Internal Table
          read table i_mbew with key matnr = i_bseg-matnr
                                     werks = i_bseg-werks
                                     binary search.
          if sy-subrc = 0.
            i_final-bklas = i_mbew-bklas.     " Val Class
          endif.
    Read the Vendor Name from LFA1 Internal Table
          read table i_lfa1 with key lifnr = i_bseg-lifnr
                                     binary search.
          if sy-subrc = 0.
            i_final-name1 = i_lfa1-name1.     " Vendor Name
          endif.
        endif.
        append i_final.
        clear i_final.
      endloop.
      sort i_final by lifnr werks monat matnr.
    Depending on the check Box Selected display the data
      if p_incmt = c_x and p_incnm ne c_x.
        delete i_final where matnr eq space.
      elseif p_incnm = c_x and p_incmt ne c_x.
        delete i_final where matnr ne space.
      endif.
    endform.           "Read Data
         Form        : populate_layout_stucture
         Description : Populating the layout structure
    form populate_layout_stucture.
      clear x_layout .
    Layout properties
      x_layout-zebra                = c_x.
      x_layout-detail_popup         = c_x.
      x_layout-detail_initial_lines = c_x.
      x_layout-colwidth_optimize    = c_x.
    endform.                    " populate_layout_stucture
         Form        : build_field_catalog
         Description : Building the field catalog data
    form build_field_catalog.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
           exporting
                i_program_name         = g_repid
                i_internal_tabname     = 'I_FINAL'
                i_inclname             = g_repid
           changing
                ct_fieldcat            = i_fldcat
           exceptions
                inconsistent_interface = 1
                program_error          = 2
                others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    Getting the Header text for the coloums
      loop at i_fldcat into x_fldcat where fieldname = 'LIFNR' or
                                           fieldname = 'NAME1' or
                                           fieldname = 'WERKS' or
                                           fieldname = 'MONAT' or
                                           fieldname = 'MATNR' or
                                           fieldname = 'BKLAS' or
                                           fieldname = 'EBELN' or
                                           fieldname = 'KOSTL' or
                                           fieldname = 'SAKTO' or
                                           fieldname = 'BUDAT' or
                                           fieldname = 'BELNR' or
                                           fieldname = 'BWART' or
                                           fieldname = 'TXZ01' or
                                           fieldname = 'MENGE' or
                                           fieldname = 'MEINS' or
                                           fieldname = 'DMBTR' or
                                           fieldname = 'WRBTR' or
                                           fieldname = 'WAERS' or
                                           fieldname = 'STATUS'.
        if x_fldcat-fieldname = 'LIFNR'.
          x_fldcat-seltext_l   = 'Vendor'(003).
          x_fldcat-seltext_m   = 'Vendor'(003).
          x_fldcat-seltext_s   = 'Vendor'(003).
          x_fldcat-reptext_ddic = 'Vendor'(003).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'NAME1'.
          x_fldcat-seltext_l   = 'Vendor Name'(002).
          x_fldcat-seltext_m   = 'Vendor Name'(002).
          x_fldcat-seltext_s   = 'Vendor Name'(002).
          x_fldcat-reptext_ddic = 'Vendor Name'(002).
          x_fldcat-inttype   = c_c.
        endif.
        if x_fldcat-fieldname = 'WERKS'.
          x_fldcat-seltext_l   = 'Plant'(010).
          x_fldcat-seltext_m   = 'Plant'(010).
          x_fldcat-seltext_s   = 'Plant'(010).
          x_fldcat-reptext_ddic   = 'Plant'(010).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MONAT'.
          x_fldcat-seltext_l   = 'Period'(011).
          x_fldcat-seltext_m   = 'Period'(011).
          x_fldcat-seltext_s   = 'Period'(011).
          x_fldcat-reptext_ddic   = 'Period'(011).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MATNR'.
          x_fldcat-seltext_l   = 'Material'(004).
          x_fldcat-seltext_m   = 'Material'(004).
          x_fldcat-seltext_s   = 'Material'(004).
          x_fldcat-reptext_ddic   = 'Material'(004).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BKLAS'.
          x_fldcat-seltext_l   = 'Valuation Class'(009).
          x_fldcat-seltext_m   = 'Valuation Class'(009).
          x_fldcat-seltext_s   = 'Valuation Class'(009).
          x_fldcat-reptext_ddic   = 'Valuation Class'(009).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'EBELN'.
          x_fldcat-seltext_l   = 'Purchase Order'(005).
          x_fldcat-seltext_m   = 'Purchase Order'(005).
          x_fldcat-seltext_s   = 'Purchase Order'(005).
          x_fldcat-reptext_ddic   = 'Purchase Order'(005).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'KOSTL'.
          x_fldcat-seltext_l   = 'Cost Center'(006).
          x_fldcat-seltext_m   = 'Cost Center'(006).
          x_fldcat-seltext_s   = 'Cost Center'(006).
          x_fldcat-reptext_ddic   = 'Cost Center'(006).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'SAKTO'.
          x_fldcat-seltext_l   = 'Cost Element'(007).
          x_fldcat-seltext_m   = 'Cost Element'(007).
          x_fldcat-seltext_s   = 'Cost Element'(007).
          x_fldcat-reptext_ddic   = 'Cost Element'(007).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BUDAT'.
          x_fldcat-seltext_l   = 'Receipt Date'(008).
          x_fldcat-seltext_m   = 'Receipt Date'(008).
          x_fldcat-seltext_s   = 'Receipt Date'(008).
          x_fldcat-reptext_ddic   = 'Receipt Date'(008).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BELNR'.
          x_fldcat-seltext_l   = 'Acc.Document'(100).
          x_fldcat-seltext_m   = 'Acc.Document'(100).
          x_fldcat-seltext_s   = 'Acc.Document'(100).
          x_fldcat-reptext_ddic   = 'Acc.Document'(100).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'BWART'.
          x_fldcat-seltext_l   = 'Movement Type'(101).
          x_fldcat-seltext_m   = 'Movement Type'(101).
          x_fldcat-seltext_s   = 'Movement Type'(101).
          x_fldcat-reptext_ddic   = 'Movement Type'(101).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'TXZ01'.
          x_fldcat-seltext_l   = 'Material Text'(102).
          x_fldcat-seltext_m   = 'Material Text'(102).
          x_fldcat-seltext_s   = 'Material Text'(102).
          x_fldcat-reptext_ddic   = 'Material Text'(102).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'MENGE'.
          x_fldcat-seltext_l   = 'Quantity'(103).
          x_fldcat-seltext_m   = 'Quantity'(103).
          x_fldcat-seltext_s   = 'Quantity'(103).
          x_fldcat-reptext_ddic   = 'Quantity'(103).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'MEINS'.
          x_fldcat-seltext_l   = 'UOM'(104).
          x_fldcat-seltext_m   = 'UOM'(104).
          x_fldcat-seltext_s   = 'UOM'(104).
          x_fldcat-reptext_ddic   = 'UOM'(104).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'DMBTR'.
          x_fldcat-seltext_l   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_m   = 'Amount in Local Curr'(105).
          x_fldcat-seltext_s   = 'Amount in Local Curr'(105).
          x_fldcat-reptext_ddic   = 'Amount in Local Curr'(105).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WRBTR'.
          x_fldcat-seltext_l   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_m   = 'Amount in Trans.Curr'(106).
          x_fldcat-seltext_s   = 'Amount in Trans.Curr'(106).
          x_fldcat-reptext_ddic   = 'Amount in Trans.Curr'(106).
          x_fldcat-ddictxt   = c_l.
          x_fldcat-do_sum    = c_x.
        endif.
        if x_fldcat-fieldname = 'WAERS'.
          x_fldcat-seltext_l   = 'Trans.Currency'(107).
          x_fldcat-seltext_m   = 'Trans.Currency'(107).
          x_fldcat-seltext_s   = 'Trans.Currency'(107).
          x_fldcat-reptext_ddic   = 'Trans.Currency'(107).
          x_fldcat-ddictxt   = c_l.
        endif.
        if x_fldcat-fieldname = 'STATUS'.
          x_fldcat-seltext_l   = 'Material Status'(019).
          x_fldcat-seltext_m   = 'Material Status'(019).
          x_fldcat-seltext_s   = 'Material Status'(019).
          x_fldcat-reptext_ddic   = 'Material Status'(019).
          x_fldcat-ddictxt   = c_l.
        endif.
        modify i_fldcat from x_fldcat index sy-tabix.
      endloop.
    endform.                    " build_field_catalog
         Form        : build_sort_totals
         Description : Building the Criteria for Sort/Subtotals
    form build_sort_totals.
      x_sort-fieldname = 'LIFNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  1.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'WERKS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  2.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MONAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  3.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'MATNR'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  4.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BKLAS'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  5.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'EBELN'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  6.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'KOSTL'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  7.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'SAKTO'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  8.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
      x_sort-fieldname = 'BUDAT'.
      x_sort-tabname   = 'I_FINAL'.
      x_sort-spos      =  9.
      x_sort-up        =  c_x.
      x_sort-subtot    = c_x.
      append x_sort to i_sort.
      clear  x_sort.
    endform.                    " build_sort_totals
      Form        : comment_build
      Description : This form is used to display the Report Header(ALV)
    form comment_build using lt_top_of_page type
                                            slis_t_listheader.
      data: l_line type slis_listheader,
            l_heading1 like rs38m-repti,
            l_date(10), l_time(8).
      clear l_line.
      l_heading1 = 'GR/IR DETAIL REPORT'(021).
      g_repid = sy-repid.
      write sy-uzeit to l_time.
      write sy-datum to l_date.
      l_line-typ = c_h.
      move l_heading1 to l_line-info.
      append l_line to lt_top_of_page.
      clear l_line.
      l_line-typ  = c_s.
      concatenate 'System:'(023) sy-sysid
                  'Date:'(024) l_date
                  ' Time:'(025)
                  l_time into l_line-info.
      append l_line to lt_top_of_page.
      concatenate 'Report:'(026) g_repid
                  ' User:'(027) sy-uname into
                  l_line-info.
      append l_line to lt_top_of_page.
      l_line-typ = c_a.
      move 'SELECTION CRITERIA:'(028) to l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Company Code : '(029)
                  p_bukrs into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' GR/IR Account: '(030)
                  p_grira into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Posting Date : '(032) s_budat-low
                  ' To: '(031) s_budat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Plant : '(033) s_werks-low
                  ' To: '(031) s_werks-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Vendor: '(034) s_lifnr-low
                  ' To: '(031) s_lifnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Material: '(035) s_matnr-low
                  ' To: '(031) s_matnr-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Center : '(036) s_kostl-low
                  ' To: '(031) s_kostl-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Cost Element: '(037) s_kstar-low
                  ' To: '(031) s_kstar-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Purchase Order: '(038) s_ebeln-low
                  ' To: '(031) s_ebeln-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Period : '(039) s_monat-low
                  ' To: '(031) s_monat-high into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Material Items: '(040)
                  p_incmt into l_line-info.
      append l_line to lt_top_of_page.
      concatenate ' Include Non-Material Items: '(041)
                  p_incnm into l_line-info.
      append l_line to lt_top_of_page.
    endform.
         Form        : call_list_viewer
         Description : This form is used to display the grid through ALV
    form call_list_viewer.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = g_repid
                is_layout               = x_layout
                it_fieldcat             = i_fldcat[]
                i_default               = c_x
                it_sort                 = i_sort[]
                i_save                  = g_save
                is_variant              = g_variant
                it_events               = g_events[]
           importing
                e_exit_caused_by_caller = g_exit_caused_by_caller
                es_exit_caused_by_user  = g_exit_caused_by_user
           tables
                t_outtab                = i_final
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
        write: / 'Problem in calling the ALV report'(042).
      endif.
    endform.                    " call_list_viewer
    reward if useful
    regards,
    Anji

Maybe you are looking for

  • Regarding Logical systems

    Hi all,           when i was trying to create new logical systems in trnsaction code BD54. It is said that you are not authorization to create logical systems. To get authorize what should i required? venkat

  • Sliding Window Table Partitioning Problems with RANGE RIGHT, SPLIT, MERGE using Multiple File Groups

    There is misleading information in two system views (sys.data_spaces & sys.destination_data_spaces) about the physical location of data after a partitioning MERGE and before an INDEX REBUILD operation on a partitioned table. In SQL Server 2012 SP1 CU

  • Check when method "PAYMENT_TERMS_SET" is processed for "Paymnt" tab of MIRO

    Hi All, I am using the method "PAYMENT_TERMS_SET " of BADI "MRM_PAYMENT_TERMS". However, i want a functionity to happen only when the method is called during processing of "Payment" tab. The subscreen called is 6310. How do i access the tab details/s

  • Looking for multiple graph logging suggestions

    I have a "host program" that is attached to a cRIO platform used for precision controlling of some heavy machinery.  The current host is used to set parameters, but primarily to read values and display trends for the operators and maintenance personn

  • Update sales statistics

    Hi all,        I have to update sales statisitc for older sales orders and older invoices because the field "Sales Group"(VKGRP) was valued with a bad value. I'd like to update the standard table S002. I found the standard transactions OLI7 for order