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.

Similar Messages

  • Print Selection Screen Parameters in ALV report only once

    Does anyone know how to print the selection screen within a ALV report.
    I've tried everything. I have the code to capture the selection parameters into a internal table. I can use top_of_page but I only want it printed once.

    Hi,
      If you have captured the selection screen entries in an internal table, then you could display it once by using the BLOCK LIST ALV.
    Check the function module.
    REUSE_ALV_BLOCK_LIST_DISPLAY
    Using this function module more than 1 alv could be display in the report.
    In our case ..there will be two alvs ...one for the selection screen n other for the main report output.
    Check the following example on the block List ALV....
    <b>BALVBT01</b>.
    Regards,
    Vara

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

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

  • How to Print Selection-Screen along with ALV Report output

    Hi,
    I have a requirement wherein i need to also print the Selection Screen of a report when I print the ALV report output.
    Basically i need to print the ALV output along with selection screen.
    Could you plz suggest me the way.
    Regards,
    Nitin

    Hi,
    My selection Screen is a very big one. It contains around 30 select-options.
    So is their any standard method in which you can choose whether you want to take the output printout with or without Selection screen.
    Regards,
    Nitin

  • Displaying selection screen details in Alv Report  output display as Header

    Hi all,
    May be somebody knows how I can show selected values with select-options in top_of_page using REUSE_ALV_GRID_DISPLAY.
    This shoud work for all the reports and diff selection screens .
    I need one dynamic process which will for display any report selection screen selected details.(Basically varient information of report).
    Small example if possible, please.
    Thanks in advance,
    Rimas

    Hi Thiru,
    Thanks for the input.
    This is my exact requirement.
    Hi Experts,
    I would like to Display / Print  Select-options selected details in ALV Header.
    Ex: Say suppose here i enter kunnr as 1000
                                            lifnr as    2000 to 4000
                                            p_langu as  'EN'.
                                           p_dir  as 'C:\TEMP,
                                           p_upda as 'X'
    for selection screen below.                    
    SELECTION-SCREEN :BEGIN OF BLOCK blk1 WITH FRAME TITLE text-000.
    SELECT-OPTIONS : s_kunnr FOR kna1-kunnr.
    SELECT-OPTIONS : s_lifnr FOR lfa1-lifnr.
    PARAMETER      : p_lanuge LIKE t002-spras DEFAULT sy-langu.
    PARAMETER: p_dir  LIKE rlgrap-filename
               DEFAULT text-003 LOWER CASE.
    PARAMETERS: p_upd AS CHECKBOX DEFAULT 'X'.
    I dont want to Hard code selection screen values like
    DATA: header TYPE slis_t_listheader,
    wa TYPE slis_listheader,
    wa-typ = 'S'(093).
      wa-key = s_lifnr .
      wa-info = 'Vendor no".
      APPEND wa TO header.
    I want dynamic process for all of my selection screen values selected
    hard code may be it will be fine small selection screen it will work.
    Fur that i got one process to get dynamically through fm
    Ex: DATA: irsparams TYPE rsparams OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
    EXPORTING
    curr_report = program
    TABLES
    selection_table = irsparams
    EXCEPTIONS
    not_found = 1
    no_report = 2
    OTHERS = 3.
    loop at irsparams.
    write : / irsparams-SELNAME.
    write : / irsparams-SIGN.
    write : / irsparams-OPTION.
    write : / irsparams-LOW.
    write : / irsparams-HIGH.
    endloop.
    I have done my requirement partially but i am failed to achive my full  requirement.
    Because
    rsparams  strcture is diff from  slis_t_listheader.
    Can any one help me for further assistence to display irsparams strcture data in alv header.
    Thanks
    Nag

  • 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!

  • Variants on tabbed selection screen for ALV reports

    Scenario: We use a tabbed selection screen for an ALV report. We create a variant, make a selection field on the second tab mandatory & save it without a value. When we run the report with the saved variant it does not check that the required field on the second tab is populated before it executes.
    Question: How can I code such a check?
    Edited by: Alridge Tom on Jul 4, 2008 3:43 PM

    Hi,
    try inserting this code apropietly in you program. (1 parameter + Initialization + At-selection-screen + 2 forms)
    START HERE
    PARAMETERS: pa_vari TYPE disvariant-variant.
    INITIALIZATION.
      g_repid = sy-repid.
      CLEAR e_variant.
      e_variant-report   = sy-cprog.
      e_variant-username = sy-uname.
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
        EXPORTING
          i_save     = 'A'
        CHANGING
          cs_variant = e_variant
        EXCEPTIONS
          not_found  = 2.
      IF sy-subrc = 0.
        pa_vari = e_variant-variant.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
      PERFORM alv_variant_f4 CHANGING pa_vari.
    *&      Form  ALV_VARIANT_F4
    FORM alv_variant_f4 CHANGING pa_vari.
      DATA: l_exit(1) TYPE c.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant       = e_variant
          i_tabname_header = 'ANYTHING'
          i_save           = 'A'
        IMPORTING
          e_exit           = l_exit
          es_variant       = e_variant
        EXCEPTIONS
          not_found        = 2.
      IF sy-subrc = 2.
        MESSAGE ID sy-msgid TYPE 'S'  NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        IF l_exit = space.
          pa_vari = e_variant-variant.
        ENDIF.
      ENDIF.
    ENDFORM.                               " ALV_VARIANT_F4
    END
    Hope iy helps!
    Alfonso

  • 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

  • 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

  • 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

  • ALV Report Event

    Hi All
    Can you please tell me 'under which event do we write fieldcatalog ' in ALV Report.
    Thanks in Advance!
    Kiran

    Hi
    We fetch the data in start-of-selection and write the ALV related data in end of selection
    See the sample report
    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

  • Screen Text in ALV selection screen

    A user has asked me to add some text at the bottom of a selection screen in an ALV report program. In se80 I double clicked the screen (1000) and then went into the layout and added a text field with some text in it. The system then requested a transport and added a LIMU DYNP screen object to it. The only other object in the transport is the Report Source Code.
    When I run the transport to another system the new text fields disappear from the screen object although double clicking the screen object in the transport shows they are there.
    Any ideas why they disappear??

    I have tried selection-screen comment but there appears to be a limit to the size of the text string (83) and this is not long enough for our purpose as the next needs to go right accross the page. Thanks for replying.

  • 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>

Maybe you are looking for

  • How to use one query against multiple table and recieve one report?

    I have duplicate tables, (except for their names of course) with commodities prices. They have the same column headings, but the data is different of course. I have a query that gives me a certain piece of information I am looking for but now I need

  • How to make executeable jar

    can someone teach me how to make jar, step by step to make jar in windows xp. Why the dos(command prompt) cannot recognized the the jar command?

  • Propose item packaging data for customs declaration

    Hi All, My requirement is to update packaging data information as mentioned below in the item level of Customs declaration 1. CNTNO  (Container Number) 2. PGETY   (Package Type)       3. PGESU   (Number of Packages) 4. PGEX1    (External Package Numb

  • Need to know where I can save config & bookmarks data

    I'm using a notebook without a hdd, running a linux live cd from the cdrom drive with 512 MB of RAM. D/L FF 4.01 as PET file which resides in a CFCard. In my previous FF I used to update some files in Default/Preferences folder & in that way I kept t

  • Regarding hiding Selection screen block

    hi all , i have 2 blocks in the selection screen. the First block has 4 radiobuttons and the second block has 4 parameters. i need to hide the block 2 based on the radiobutton checked in the initail block. if radiobutton 1 or 2 is selected then the b