Sales requirement report using ALV

Sales Register Requirement Specifications:----
1.Fields on selection screen (input screen) : Plant Code From to , Distributional Channel  from to , Division from to , Customer Code from to , Period From to , Material Code (can be used using *) .
2.Field in the output List : Exc. Invoice No, Customer Code , Customer Name , Material Code , Material Description , Invoice Qty, Pack/Forward  , Basic Price 
3.Canceled Invoice should be included in the list
4.ALV Display is to used

Hi,
All we can say is take the data from
Sales order details - VBAK, VBAP
Customer details -  KNA1
Material description -  MAKT
Invoice details - VBRK, VBRP
Basic Price - KONP
Excise invoice details - J1_IEXCHDR
Excise invoice line times - J1_IEXCDTL.
<b>Reward if useful.</b>
Regards,
Pritha.

Similar Messages

  • I Need Sales Order Status Reports using ALV

    Hi I Need Sales Order Status Reports using ALV.

    HI!
    For alv use REUSE_ALV_GRID_DSPLAY function module.
    For the given report fetch data from the tables:
    VBAK - sales order header
    VBAP - sales order details
    VBUK - sales order header status
    VBUP - sales order items status
    Regards
    Tamá

  • How we add & grandtotal of sales order report in alv

    hi guru how we add & grandtotal of sales order report in alv
    regards
    subhasis

    hi subhasis,
    since u want the grand total in ALV use the following code...
    clear gs_fieldcat.
    gs_fieldcat-fieldname = field.
    gs_fieldcat-tabname = DB table
    gs_fieldcat-seltext_m = text.
    gs_fieldcat-do_sum = 'X'
    gs_fieldcat-datatype = data type (Curr or Quant)
    gs_fieldcat-ref_fieldname = reference field name
    gs_fieldcat-ref_tabname  = reference table name
    append gs_fieldcat to gt_fieldcat.
    hope this will work...
    please reward points in case usefull
    regards,
    prashant

  • Interactive report using alv.

    Hello all,
    I want to create an interactive report using alv grid display.I tried it using the normal method,as in using hide n sy-lsind but could not get the display.Canu please help me out with the problem.
    Thanks and Regards.
    Seema.

    hai Seema,
    for interactivereporting u can use get cursor fieldstatement.
    GET CURSOR FIELD <f> [VALUE <val>] .
    or try this one using the user command function.
    EXAMPLE:
    DEFINE m_fieldcat.
      add 1 to ls_fieldcat-col_pos.
      ls_fieldcat-fieldname   = &1.
      ls_fieldcat-ref_tabname = &2.
      append ls_fieldcat to lt_fieldcat.
    END-OF-DEFINITION.
    TABLES : vbak.                         " Sales Document: Header Data
    TYPE-POOLS: slis.                      " ALV Global types
    SELECT-OPTIONS :
      s_vkorg FOR vbak-vkorg,              " Sales organization
      s_kunnr FOR vbak-kunnr,              " Sold-to party
      s_vbeln FOR vbak-vbeln.              " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    DATA:
    Data displayed in the first list
      BEGIN OF gt_vbak OCCURS 0,
        vkorg LIKE vbak-vkorg,             " Sales organization
        kunnr LIKE vbak-kunnr,             " Sold-to party
        vbeln LIKE vbak-vbeln,             " Sales document
        netwr LIKE vbak-netwr,             " Net Value of the Sales Order
      END OF gt_vbak,
    Data displayed in the second list
      BEGIN OF gt_vbap OCCURS 0,
        vbeln  LIKE vbap-vbeln,            " Sales document
        posnr  LIKE vbap-posnr,            " Sales document item
        matnr  LIKE vbap-matnr,            " Material number
        arktx  LIKE vbap-arktx,            " Short text for sales order item
        kwmeng LIKE vbap-kwmeng,           " Order quantity
        netwr  LIKE vbap-netwr,            " Net value of the order item
      END OF gt_vbap.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data_vbak.
      PERFORM f_display_data_vbak.
         Form  f_read_data_vbak
    FORM f_read_data_vbak.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
               FROM vbak
                 UP TO p_max ROWS
              WHERE kunnr IN s_kunnr
                AND vbeln IN s_vbeln
                AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA_VBAK
         Form  f_display_data_vbak
    FORM f_display_data_vbak.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    Build the field catalog
      m_fieldcat 'VKORG' 'VBAK'.
      m_fieldcat 'KUNNR' 'VBAK'.
      m_fieldcat 'VBELN' 'VBAK'.
      m_fieldcat 'NETWR' 'VBAK'.
    Display the first list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = sy-cprog
                i_callback_user_command = 'USER_COMMAND'
                it_fieldcat             = lt_fieldcat
           TABLES
                t_outtab                = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA_VBAK
          FORM USER_COMMAND                                             *
    FORM user_command USING u_ucomm     LIKE sy-ucomm
                            us_selfield TYPE slis_selfield.     "#EC CALLED
      CASE u_ucomm.
        WHEN '&IC1'.
          READ TABLE gt_vbak INDEX us_selfield-tabindex.
          CHECK sy-subrc EQ 0.
          PERFORM f_read_data_vbap.        " Read data from VBAP
          PERFORM f_display_data_vbap.
      ENDCASE.
    ENDFORM.                               " USER_COMMAND
         Form  f_read_data_vbap
    FORM f_read_data_vbap.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbap
               FROM vbap
              WHERE vbeln = gt_vbak-vbeln.
    ENDFORM.                               " F_READ_DATA_VBAP
         Form  f_display_data_vbap
    FORM f_display_data_vbap.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    Build the field catalog
      m_fieldcat 'VBELN'  'VBAP'.
      m_fieldcat 'POSNR'  'VBAP'.
      m_fieldcat 'MATNR'  'VBAP'.
      m_fieldcat 'ARKTX'  'VBAP'.
      m_fieldcat 'KWMENG' 'VBAP'.
      m_fieldcat 'NETWR'  'VBAP'.
    Display the second list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                it_fieldcat = lt_fieldcat
           TABLES
                t_outtab    = gt_vbap.
    ENDFORM.   
    regards,
    praba.

  • Is it possible to put colors while displaying report using ALVs?

    Gayathri

    hi
    i think the following code is the ur solution
    TABLES VBAK.
    TYPE-POOLS SLIS.
    * Data Declaration
    TYPES: BEGIN OF T_VBAK,
          VBELN TYPE VBAK-VBELN,
          ERDAT TYPE VBAK-ERDAT,
          ERNAM TYPE VBAK-ERNAM,
          AUDAT TYPE VBAK-AUDAT,
          VBTYP TYPE VBAK-VBTYP,
          NETWR TYPE VBAK-NETWR,
          VKORG TYPE VBAK-VKORG,
          VKGRP TYPE VBAK-VKGRP,
         <b> LINE_COLOR(4) TYPE C,</b>
          END OF T_VBAK.
    DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
          WA_VBAK TYPE T_VBAK.
    * ALV Data Declaration
    DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
          GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
          GD_REPID TYPE SY-REPID.
    *      I_EVENTS TYPE SLIS_T_EVENT,
    *      W_EVENTS LIKE LINE OF I_EVENTS.
    START-OF-SELECTION.
    PERFORM DATA_RETRIEVAL.
    PERFORM BLD_FLDCAT.
    PERFORM BLD_LAYOUT.
    PERFORM DISPLAY_ALV_REPORT.
    * Build Field Catalog for ALV Report
    FORM BLD_FLDCAT.
    FLDCAT-FIELDNAME = 'VBELN'.
    FLDCAT-SELTEXT_M = 'Sales Document'.
    FLDCAT-COL_POS = 0.
    *FLDCAT-EMPHASIZE = 'C411'.
    FLDCAT-OUTPUTLEN = 20.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERDAT'.
    FLDCAT-SELTEXT_L = 'Record Date created'.
    FLDCAT-COL_POS = 1.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERNAM'.
    FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'AUDAT'.
    FLDCAT-SELTEXT_M = 'Document Date'.
    FLDCAT-COL_POS = 3.
    FLDCAT-EMPHASIZE = 'C110'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VBTYP'.
    FLDCAT-SELTEXT_L = 'SD Document category'.
    FLDCAT-COL_POS = 4.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'NETWR'.
    FLDCAT-SELTEXT_L = 'Net Value of the SO in Document Currency'.
    FLDCAT-COL_POS = 5.
    FLDCAT-OUTPUTLEN = 60.
    FLDCAT-DO_SUM = 'X'.
    FLDCAT-DATATYPE = 'CURR'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKORG'.
    FLDCAT-SELTEXT_L = 'Sales Organization'.
    FLDCAT-COL_POS = 6.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKGRP'.
    FLDCAT-SELTEXT_M = 'Sales Group'.
    FLDCAT-COL_POS = 7.
    FLDCAT-EMPHASIZE = 'C801'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    ENDFORM.
    * Build Layout for ALV Grid Report
    FORM BLD_LAYOUT.
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
    GD_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.
    *GD_LAYOUT-TOTALS_TEXT = 'GRAND TOTAL'.
    ENDFORM.
    * Display report using ALV grid
    FORM DISPLAY_ALV_REPORT.
    DATA T_EVENT TYPE SLIS_T_EVENT.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
       I_LIST_TYPE           = 0
    IMPORTING
       ET_EVENTS             = T_EVENT.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    GD_REPID = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = GD_REPID
       IS_LAYOUT                         = GD_LAYOUT
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
       I_GRID_TITLE                      = 'SALES DOCUMENT HEADER'
       IT_FIELDCAT                       = FLDCAT[]
       I_SAVE                            = 'X'
      TABLES
        T_OUTTAB                          = IT_VBAK
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    * Retrieve data from VBAK table and populate itab IT_VBAK
    FORM DATA_RETRIEVAL.
    <b>DATA LD_COLOR(1) TYPE C.</b>
    SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG
    UP TO 20 ROWS
    FROM VBAK
    INTO TABLE IT_VBAK.
    <b>LOOP AT IT_VBAK INTO WA_VBAK.
    LD_COLOR = LD_COLOR + 1.
    IF LD_COLOR = 8.
      LD_COLOR = 1.
    ENDIF.
    CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.
    MODIFY IT_VBAK FROM WA_VBAK.
    ENDLOOP.</b>
    ENDFORM.
    FORM TOP_OF_PAGE.
    DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
          W_HEADER TYPE SLIS_LISTHEADER.
    W_HEADER-TYP = 'H'.
    W_HEADER-INFO = 'WELCOME HEADER LIST'.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'REPORT:'.
    W_HEADER-INFO = SY-REPID.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'DATE:'.
    CONCATENATE SY-DATUM+6(2) ' / ' SY-DATUM+4(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.
    APPEND W_HEADER TO T_HEADER.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = T_HEADER.
    ENDFORM.
    reward points,if it is useful

  • Interactive reports using ALV

    can i make interactive reports using ALV, like - using push putton, radio button, check boxes in ALV???
    if yes, then can i find any example of them??

    Search the SCN before posting the basic questions.

  • Intractive report using ALV fm's

    Hai This is Srik,
       I am trying to develop an intractive report using ALV fm's...
        Can anybody help me with some sample code and the needed FM's.
    Thanks in advance.
    Srik

    Srikanth,
    *& Report Z_INTERACTIVE *
    REPORT Z_INTERACTIVE no standard page heading line-count 200 message-id zp.
    TABLES: MARA, MAKT, MARC, MARD,T001W.
    DATA: BEGIN OF IT_MARA_MAKT_MARD OCCURS 0,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
    MEINS LIKE MARA-MEINS,
    MAKTX LIKE MAKT-MAKTX,
    LABST LIKE MARD-LABST,
    END OF IT_MARA_MAKT_MARD.
    DATA: BEGIN OF IT_MARC_MARD1 OCCURS 0,
    WERKS LIKE MARC-WERKS,
    LABST LIKE MARD-LABST,
    NAME1 LIKE T001W-NAME1,
    END OF IT_MARC_MARD1.
    DATA: BEGIN OF IT_MARC_MARD OCCURS 0,
    LGORT LIKE MARD-LGORT,
    LABST LIKE MARD-LABST,
    END OF IT_MARC_MARD.
    SELECT-OPTIONS: s_matnr FOR MARA-MATNR.
    AT SELECTION-SCREEN.
    REFRESH IT_MARA_MAKT_MARD.
    SELECT MATNR MTART MEINS INTO CORRESPONDING FIELDS OF IT_MARA_MAKT_MARD FROM MARA WHERE MATNR IN s_matnr.
    SELECT SINGLE MAKTX INTO IT_MARA_MAKT_MARD-MAKTX FROM MAKT WHERE MATNR = IT_MARA_MAKT_MARD-MATNR.
    SELECT SUM( LABST ) INTO IT_MARA_MAKT_MARD-LABST FROM MARD WHERE MATNR = IT_MARA_MAKT_MARD-MATNR.
    APPEND IT_MARA_MAKT_MARD.
    CLEAR IT_MARA_MAKT_MARD.
    ENDSELECT.
    IF SY-SUBRC <> 0.
    MESSAGE I008.
    ENDIF.
    START-OF-SELECTION.
    SORT IT_MARA_MAKT_MARD.
    WRITE:/ 'MATERIAL NUMBER' COLOR 2, 20 'DESCRIPTION' COLOR 2, 50 'TYPE' COLOR 2, 70 'UOM' COLOR 2, 100 'STOCK' COLOR 2.
    ULINE.
    SKIP 4.
    LOOP AT IT_MARA_MAKT_MARD.
    WRITE:/ IT_MARA_MAKT_MARD-MATNR, 20 IT_MARA_MAKT_MARD-MAKTX, 50 IT_MARA_MAKT_MARD-MTART, 70 IT_MARA_MAKT_MARD-MEINS, 90 IT_MARA_MAKT_MARD-LABST.
    HIDE: IT_MARA_MAKT_MARD-MATNR, IT_MARA_MAKT_MARD-MAKTX, IT_MARA_MAKT_MARD-MTART, IT_MARA_MAKT_MARD-MEINS, IT_MARA_MAKT_MARD-LABST.
    ENDLOOP.
    AT LINE-SELECTION.
    CASE: SY-LSIND.
    WHEN 1.
    WINDOW STARTING AT 1 20 ENDING AT 120 120.
    REFRESH IT_MARC_MARD1.
    CLEAR IT_MARC_MARD1.
    SELECT pWERKS QNAME1 INTO CORRESPONDING FIELDS OF IT_MARC_MARD1 FROM MARC AS p INNER JOIN T001W AS q ON pWERKS = qWERKS WHERE p~MATNR = IT_MARA_MAKT_MARD-MATNR.
    SELECT SUM( LABST ) INTO IT_MARC_MARD1-LABST FROM MARD WHERE MATNR = IT_MARA_MAKT_MARD-MATNR AND WERKS = IT_MARC_MARD1-WERKS.
    APPEND IT_MARC_MARD1.
    CLEAR IT_MARC_MARD1.
    ENDSELECT.
    SORT IT_MARC_MARD1.
    WRITE:/ 'MATERIAL NUMBER' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MATNR COLOR 4.
    WRITE:/ 'DESCRIPTION' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MAKTX COLOR 4.
    WRITE:/ 'TYPE' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MTART COLOR 4.
    WRITE:/ 'UNIT OF MEASUREMENT' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MEINS COLOR 4.
    WRITE:/ 'MATERIAL QUANTITY' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-LABST COLOR 4.
    ULINE.
    SKIP 4.
    WRITE:/ 'PLANT CODE' COLOR 2, 20 'PLANT NAME' COLOR 2, 60 'STOCK' COLOR 2.
    LOOP AT IT_MARC_MARD1.
    WRITE:/ IT_MARC_MARD1-WERKS COLOR 4, 20 IT_MARC_MARD1-NAME1 COLOR 4, 41 IT_MARC_MARD1-LABST.
    HIDE: IT_MARC_MARD1-WERKS.
    HIDE: IT_MARA_MAKT_MARD-MATNR, IT_MARA_MAKT_MARD-MAKTX, IT_MARA_MAKT_MARD-MTART, IT_MARA_MAKT_MARD-MEINS, IT_MARA_MAKT_MARD-LABST.
    AT LAST.
    SUM.
    WRITE:/30 'TOTAL STOCK', 60 IT_MARC_MARD1-LABST.
    ENDAT.
    ENDLOOP.
    WHEN 2.
    WINDOW STARTING AT 1 20 ENDING AT 120 120.
    REFRESH IT_MARC_MARD.
    CLEAR IT_MARC_MARD.
    SELECT LGORT LABST INTO CORRESPONDING FIELDS OF IT_MARC_MARD FROM MARD WHERE MATNR = IT_MARA_MAKT_MARD-MATNR AND WERKS = IT_MARC_MARD1-WERKS.
    APPEND IT_MARC_MARD.
    CLEAR IT_MARC_MARD.
    ENDSELECT.
    SORT IT_MARC_MARD.
    WRITE:/ 'MATERIAL NUMBER' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MATNR COLOR 4.
    SKIP 1.
    WRITE:/ 'DESCRIPTION' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MAKTX COLOR 4.
    SKIP 1.
    WRITE:/ 'TYPE' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MTART COLOR 4.
    SKIP 1.
    WRITE:/ 'UNIT OF MEASUREMENT' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-MEINS COLOR 4.
    SKIP 1.
    WRITE:/ 'MATERIAL QUANTITY' COLOR 3.
    WRITE: IT_MARA_MAKT_MARD-LABST COLOR 4.
    SKIP 1.
    ULINE.
    SKIP 1.
    WRITE:/ 'PLANT CODE' COLOR 2, 40 'PLANT NAME' COLOR 2.
    WRITE:/ IT_MARC_MARD1-WERKS, 40 IT_MARC_MARD1-NAME1.
    SKIP 3.
    ULINE.
    WRITE:/20 'STORAGE LOCATION' COLOR 5, 50 'STOCK' COLOR 5.
    SKIP 4.
    LOOP AT IT_MARC_MARD.
    WRITE:/20 IT_MARC_MARD-LGORT, 50 IT_MARC_MARD-LABST.
    AT LAST.
    SUM.
    WRITE:/30 'TOTAL STOCK', 60 IT_MARC_MARD-LABST.
    ENDAT.
    ENDLOOP.
    WHEN OTHERS.
    WINDOW STARTING AT 1 20 ENDING AT 20 50.
    WRITE:/40 'SORRY'.
    ENDCASE.
    TOP-OF-PAGE.
    WRITE:/ 'XYZ LIMITED' COLOR 2, 90 'DATE:' COLOR 2, SY-DATUM.
    ULINE.
    ULINE.
    TOP-OF-PAGE DURING LINE-SELECTION.
    WRITE:/ 'XYZ LIMITED' COLOR 2, 90 'DATE:' COLOR 2, SY-DATUM.
    ULINE.
    interactive ALV code
    ALV-INTERACTIVE.
    Interactive ALV
    http://www.sap-img.com/abap/an-interactive-alv-report.htm
    http://www.sapgenie.com/abap/drill_down_reports.htm
    Pls. reward if useful

  • Required Sample Programs on Tree Reports using ALV and Reports

    Hi Pals,
       I require sample progrms on Tree Reports using Function Modules for both ALV and Classical Reports. Send the list of sample programs and function modules used for tree reports.
    Regards,
    Pradeep.g
    <removed by moderator>

    Check these threads..U can find sample programs.
    tree type report
    ALVtree reports - Example code and information on creating ALV tree reports
    http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htmhttps://alv tree
    ALso check this DEMO Program
    SAPCOLUMN_TREE_CONTROL_DEMO
    CL_GUI_ALV_COLUMN_TREE
    Sample code:
    http://www.geocities.com/victorav15/sapr3/utilities/zvvooa3.txt

  • Interactive report using ALV's

    Hi Gurus,
         Here i have sales header details and item details, what exactly i am looking is i displayed sales document details using RESUE_ALV_GRID_DISPLAY..and when i click on Particular VBELN i want to display in the next liss as item details for clicked particular VBELN.........using ALV....Gurus,,,,,, i need very urgent ,it will be great help to me....can you please post the code if possible....
    Thanks
    Venkat

    Hi,
    Check this example fo interactive ALV..Initially the sales orders will be displayed..There will be a hotspot for the sales order number..If you press it , the sales order line items will be displayed..
    The hotspot related code is marked in bold..
    TYPE-POOLS: slis.
    DATA: BEGIN OF itab1 OCCURS 0,
    vbeln TYPE vbeln,
    bstnk TYPE vbak-bstnk,
    erdat TYPE vbak-erdat,
    kunnr TYPE vbak-kunnr,
    END OF itab1.
    DATA: BEGIN OF itab2 OCCURS 0,
    vbeln TYPE vbeln,
    matnr TYPE vbap-matnr,
    netpr TYPE vbap-netpr,
    kwmeng TYPE vbap-kwmeng,
    END OF itab2.
    DATA: t_fieldcatalog1 TYPE slis_t_fieldcat_alv.
    DATA: t_fieldcatalog2 TYPE slis_t_fieldcat_alv.
    DATA: v_repid TYPE syrepid.
    v_repid = sy-repid.
    Get the fieldcatalog1
    PERFORM get_fieldcat1.
    Get the fieldcatalog2
    PERFORM get_fieldcat2.
    SELECT vbeln bstnk erdat kunnr UP TO 10 ROWS
    INTO TABLE itab1
    FROM vbak.
    IF NOT itab1[] IS INITIAL.
    SELECT vbeln matnr netpr kwmeng UP TO 10 ROWS
    INTO TABLE itab2
    FROM vbap
    FOR ALL ENTRIES IN itab1
    WHERE vbeln = itab1-vbeln.
    ENDIF.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = v_repid
    i_callback_user_command = 'DISPLAY_DETAIL'
    it_fieldcat = t_fieldcatalog1
    TABLES
    t_outtab = itab1.
    FORM display_detail *
    --> UCOMM *
    --> SELFIELD *
    FORM display_detail USING ucomm LIKE sy-ucomm
    selfield TYPE slis_selfield.
    DATA: itab2_temp LIKE itab2 OCCURS 0 WITH HEADER LINE.
    IF ucomm = '&IC1'.
    READ TABLE itab1 INDEX selfield-tabindex.
    IF sy-subrc = 0.
    LOOP AT itab2 WHERE vbeln = itab1-vbeln.
    MOVE itab2 TO itab2_temp.
    APPEND itab2_temp.
    ENDLOOP.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_callback_program = v_repid
    it_fieldcat = t_fieldcatalog2
    TABLES
    t_outtab = itab2_temp.
    ENDIF.
    ENDIF.
    ENDFORM.
    FORM GET_FIELDCAT1 *
    FORM get_fieldcat1.
    DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
    s_fieldcatalog-col_pos = '1'.
    s_fieldcatalog-fieldname = 'VBELN'.
    s_fieldcatalog-tabname = 'ITAB1'.
    s_fieldcatalog-rollname = 'VBELN'.
    s_fieldcatalog-hotspot = 'X'.
    APPEND s_fieldcatalog TO t_fieldcatalog1.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '2'.
    s_fieldcatalog-fieldname = 'BSTNK'.
    s_fieldcatalog-tabname = 'ITAB1'.
    s_fieldcatalog-rollname = 'BSTNK'.
    APPEND s_fieldcatalog TO t_fieldcatalog1.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '3'.
    s_fieldcatalog-fieldname = 'ERDAT'.
    s_fieldcatalog-tabname = 'ITAB1'.
    s_fieldcatalog-rollname = 'ERDAT'.
    APPEND s_fieldcatalog TO t_fieldcatalog1.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '4'.
    s_fieldcatalog-fieldname = 'KUNNR'.
    s_fieldcatalog-tabname = 'ITAB1'.
    s_fieldcatalog-rollname = 'KUNNR'.
    APPEND s_fieldcatalog TO t_fieldcatalog1.
    CLEAR s_fieldcatalog.
    ENDFORM.
    FORM GET_FIELDCAT2 *
    FORM get_fieldcat2.
    DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
    s_fieldcatalog-col_pos = '1'.
    s_fieldcatalog-fieldname = 'VBELN'.
    s_fieldcatalog-tabname = 'ITAB2'.
    s_fieldcatalog-rollname = 'VBELN'.
    APPEND s_fieldcatalog TO t_fieldcatalog2.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '2'.
    s_fieldcatalog-fieldname = 'MATNR'.
    s_fieldcatalog-tabname = 'ITAB2'.
    s_fieldcatalog-rollname = 'MATNR'.
    APPEND s_fieldcatalog TO t_fieldcatalog2.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '3'.
    s_fieldcatalog-fieldname = 'NETPR'.
    s_fieldcatalog-tabname = 'ITAB2'.
    s_fieldcatalog-rollname = 'NETPR'.
    APPEND s_fieldcatalog TO t_fieldcatalog2.
    CLEAR s_fieldcatalog.
    s_fieldcatalog-col_pos = '4'.
    s_fieldcatalog-fieldname = 'KWMENG'.
    s_fieldcatalog-tabname = 'ITAB2'.
    s_fieldcatalog-rollname = 'KWMENG'.
    APPEND s_fieldcatalog TO t_fieldcatalog2.
    CLEAR s_fieldcatalog.
    ENDFORM.
    Thanks,
    Naren

  • ALV report using the field catalog

    which is the quickest way to generate an ALV report using the field catalog merge.  without needing to build the field catalog manually .
    is it easier to create a structure and passe it in the field catalog merge .  if yes can i have an example plzzzz

    hI
    Supports the creation of the field catalog for the ALV function modules
    based either on a structure or table defined in the ABAP Data
    Dictionary, or a program-internal table.
    The program-internal table must either be in a TOP Include or its
    Include must be specified explicitly in the interface.
    The variant based on a program-internal table should only be used for
    rapid prototyping since the following restrictions apply:
    o Performance is affected since the code of the table definition must
    always be read and interpreted at runtime.
    o Dictionary references are only considered if the keywords LIKE or
    INCLUDE STRUCTURE (not TYPE) are used.
    If the field catalog contains more than 90 fields, the first 90 fields
    are output in the list by default whereas the remaining fields are only
    available in the field selection.
    If the field catalog is passed with values, they are merged with the
    'automatically' found information.
    Below is an example ABAP program which will populate a simple internal table(it_ekpo) with data and
    display it using the basic ALV grid functionality(including column total). The example details the main
    sections of coding required to implement the ALV grid functionality:
                             Data declaration
                             Data retrieval
                             Build fieldcatalog
                             Build layout setup
    *& Report  ZDEMO_ALVGRID                                               *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic requirement for this demo is to display a number of       *
    *& fields from the EKKO table.                                         *
    REPORT  zdemo_alvgrid                 .
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    *  gd_layout-totals_only        = 'X'.
    *  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
    *                                         "click(press f2)
    *  gd_layout-zebra             = 'X'.
    *  gd_layout-group_change_edit = 'X'.
    *  gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
    *       Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
    *            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
    *            i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
    *            IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
    *            is_variant              = z_template
           tables
                t_outtab                = it_ekko
           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_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
    select ebeln ebelp statu aedat matnr menge meins netpr peinh
    up to 10 rows
      from ekpo
      into table it_ekko.
    endform.                    " DATA_RETRIEVAL

  • Modification in report into ALV Format

    Hi Experts
    How can I modify this report in ALV Format with Top of page and Parameters should be display on runtime.
    Can anyone modify my program please
    Thanks in advanced.
    REPORT FZEL LINE-SIZE  220 LINE-COUNT 75
             NO STANDARD PAGE HEADING.
    TABLES : equi,
             equz,
             imptt,
             imrg,
             eqkt,
             iloa.
    TYPES:  BEGIN OF ty_data  ,
             equnr      type equnr,         " Euipment no
             eqktx      type eqkt-eqktx,    " Equipment Text
             eqfnr       type iloa-eqfnr,     " Equipment Sort field
             idate      type imrg-idate,    " Measuring Date
             recdu      type imrg-recdu,    " Unit of measuring ='KM','L','H'
             recdv      type imrg-recdv,    " Counter reading data
             cancl       type imrg-cancl,
           END OF ty_data.
    TYPES: BEGIN OF ty_final,
             equnr           type equnr,            "  Equipment no
             eqktx           type eqkt-eqktx,       "  Equipment Text
             eqfnr           type iloa-eqfnr,       "  Equipment Sort field
             idate               type imrg-idate,       "  Measuring Date
             min_date_km     type imrg-idate,       "  Min Date
             min_km          type imrg-recdv,       "  Max Km
             max_date_km     type imrg-idate,
             max_km          type imrg-recdv,       "  Min km
             t_max_min_km    type imrg-recdv,       "  Total min_km-max_km
             min_date_hr     type imrg-idate,       "  Max Date
             min_hr          type imrg-recdv,       "  Max hr
             max_date_hr     type imrg-idate,
             max_hr          type imrg-recdv,       "  Min hr
             t_max_min_hr    type imrg-recdv,                "  Total min_hr-max_hr
             min_date_lit    type imrg-idate,
             min_lit         type imrg-recdv,       "  Min lit
             max_date_lit    type imrg-idate,
             max_lit         type imrg-recdv,       "  Max lit
             fuel_con        type imrg-recdv,       "  Total_hrs / t_max_min_hr
             fuel_con2       type imrg-recdv,       "  Total_hrs / t_max_min_hr
             km_l            type imrg-recdv,       "  t max_min_km / t_max_min_lit
             l_p             type imrg-recdv ,          "  t_max_min_lit / t_max_min_hr
             l_p2            type imrg-recdv ,
           END OF ty_final.
    DATA: i_data TYPE TABLE OF ty_data, " internal table
    wa_data TYPE ty_data, " work area
    i_final TYPE TABLE OF ty_final, " internal table
    wa_final TYPE ty_final. " work area
    SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: p_equnr FOR equi-equnr OBLIGATORY, "no-extension no intervals,
                    p_idate FOR imrg-idate.  "NO-EXTENSION NO INTERVALS OBLIGATORY,
                   "p_recdu FOR imrg-recdu." NO-EXTENSION NO INTERVALS ."default 'M3'" OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK blk1.
    SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
    SELECTION-SCREEN END OF BLOCK blk2.
    SELECTION-SCREEN END OF BLOCK blk.
    TOP-OF-PAGE.
      FORMAT INTENSIFIED ON.
      WRITE:/55(40) ' WAGNERS INVESTMENT LIMITED  '.
      WRITE:/50(40) ' VEHICLE FUEL CONSUMPTION REPORT ' CENTERED   ,
              2 'Page', sy-pagno.
      FORMAT INTENSIFIED OFF.
      WRITE:/50(40) '----
    ' CENTERED .
      FORMAT INTENSIFIED ON.
      WRITE:/2 sy-datum COLOR 3, sy-uzeit .
      "WRITE:/1 S903-SPMON ."p_yearf.
      ULINE.
      "CENTERED.
    write: /2 'Equipment No :'left-justified,p_equnr-low  color 2 , '  to   '  , p_equnr-high color 2.
    write: /2 'Date From    :', p_idate-low color 2 ,  ' to  '  , p_idate-high color 2.
    "write: /2 'Sort Field:'left-justified,p_eqfnr-low  color 2 , '  to   '  , p_eqfnr-high color 2.
    SKIP.
      ULINE.
    WRITE:/1 sy-vline,
        2   ' EQUIP#',                10 sy-vline ,
        11  ' NAME',                  40 sy-vline,
        41  ' SORT',                  60 sy-vline,
        61  ' START DATE',            74 sy-vline,
        75  ' END DATE',               87 sy-vline,
        88  ' START KM',              100 sy-vline,
        101 ' END KM' ,               113 sy-vline,
        114 ' TOTAL KM',              126 sy-vline,
        127 ' START HR',              139 sy-vline,
        140 ' END HR',                152 sy-vline,
        153 ' TOTAL HR',              167 sy-vline,
        168 ' FUEL CON ',             180 sy-vline,
        181 ' KM L',                  193 sy-vline,
        194 ' LIT PER HR ',           206 sy-vline,
        207 ' EQUIP NO',              220 sy-vline,
        223 'KM L',                  232 sy-vline,
        233 'LIT PER KM',            245 sy-vline,
        246 'TOTAL L/HR',            258 sy-vline.
      FORMAT COLOR 3 ON.
      ULINE.
    END-OF-PAGE.
    START-OF-SELECTION.
    select aequnr deqktx feqfnr eidate erecdu erecdv
    into table i_data
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate and
    e~cancl ne 'X'.
    loop  at i_data into wa_data.
    CLEAR: wa_final.
      READ TABLE i_final into wa_final
               with key equnr = wa_data-equnr." BINARY SEARCH.
        if sy-subrc EQ 0.
          PERFORM F_GET_MAX_DATA.
          PERFORM F_GET_MAX_HOURS.
          PERFORM F_GET_MAX_LIT.
          PERFORM prepare_final_rec USING'M'. " Modify Existing Record
         ElSE.
          PERFORM prepare_final_rec USING'A'. " Append New Record.
        ENDIF.
        ENDLOOP.
        LOOP AT i_final into wa_final.
    on change of wa_final-equnr.
    WRITE:/1 sy-vline,
    2  wa_final-equnr                                                       , 10 sy-vline,
    11 wa_final-eqktx                                                       , 40 sy-vline,
    41 wa_final-eqfnr                                                       , 60 sy-vline,
    61 wa_final-min_date_km  color 2                                        , 74 sy-vline,
    75 wa_final-max_date_km  color 2 LEFT-JUSTIFIED                         , 87 sy-vline,
    88 wa_final-min_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED   color 3       , 100 sy-vline,
    101 wa_final-max_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED   color 3      , 113 sy-vline,
    114 wa_final-t_max_min_km EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED          , 126 sy-vline,
    127 wa_final-min_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED color 4        , 139 sy-vline,
    140 wa_final-max_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED color 4        , 152 sy-vline,
    153 wa_final-t_max_min_hr EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED          , 167 sy-vline,
    168 wa_final-fuel_con2 EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED             , 180 sy-vline,
    181 wa_final-km_l EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED            ,193 sy-vline,
    194 wa_final-l_p2 EXPONENT 0 DECIMALS 2 LEFT-JUSTIFIED  color  2        , 206 sy-vline,
    207 wa_final-equnr                                                      ,220 sy-vline.
    endon.
    endloop.
    refresh i_final.
    clear i_final.
    FORM F_GET_MAX_DATA.
    select single MAX( eidate ) Min( eidate ) MAX( erecdv ) MIN( erecdv )
    into  corresponding fields of (wa_final-max_date_km,wa_final-min_date_km,wa_final-max_km ,wa_final-min_km)
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne 'X' and
    e~recdu =  'KM'
    AND a~equnr = wa_data-equnr.
    ENDFORM.
    FORM F_GET_MAX_HOURS.
    select single MAX( erecdv ) MIN( erecdv )
    into corresponding fields of (wa_final-max_hr, wa_final-min_hr)
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne  'X' and
    e~recdu =  'H'
    AND a~equnr = wa_data-equnr  .
    ENDFORM.
    FORM F_GET_MAX_LIT.
    select SUM( e~recdv )
    into corresponding fields of (wa_final-fuel_con2)
    from equi AS a
    inner join eqkt as b
    on bequnr = aequnr
    inner join imptt as c
    on cmpobj = aobjnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne  'X' and
    e~recdu =  'L'
    AND a~equnr = wa_data-equnr.
    ENDFORM.
    FORM prepare_final_rec  USING    p_mode TYPE char1.
    wa_final-t_max_min_km = wa_final-max_km - wa_final-min_km .
    wa_final-t_max_min_hr = wa_final-max_hr - wa_final-min_hr.
    if  wa_final-t_max_min_km <> 0 .
    wa_final-km_l =  ( wa_final-max_km - wa_final-min_km )  /  ( wa_final-fuel_con2 ) .
    ELSE.
    wa_final-km_l = 0.
    endif.
    if  wa_final-t_max_min_hr <> 0  .
    wa_final-l_p2 = ( wa_final-fuel_con2 ) / (  wa_final-t_max_min_hr ) .
    ELSE.
    wa_final-l_p2 = 0.
    endif.
      IF p_mode = 'A'.
        wa_final-equnr = wa_data-equnr.
        wa_final-eqktx = wa_data-eqktx.
        wa_final-eqfnr = wa_data-eqfnr.
        wa_final-t_max_min_km = wa_final-min_km - wa_final-max_km .
        wa_final-t_max_min_hr = wa_final-max_hr - wa_final-min_hr.
        wa_final-km_l =  ( wa_final-max_km - wa_final-min_km ) /  ( wa_final-fuel_con2 ).
        wa_final-l_p2 = ( wa_final-fuel_con2 ) / (  wa_final-t_max_min_hr ) .
        APPEND wa_final TO i_final  .
      ELSE.
        MODIFY i_final FROM wa_final
          TRANSPORTING
              eqfnr
              max_date_km
              min_date_km
              max_date_lit
              min_date_lit
              max_date_hr
              min_date_hr
              max_km
              min_km
              max_hr
              min_hr
              t_max_min_km
              t_max_min_hr
              fuel_con2
              km_l
              l_p2
              where equnr = wa_data-equnr.
      ENDIF.
    ENDFORM.                    " PREPARE_FINAL_REC

    Hi Guys
    Thanks for your reply, I know how to implement the FM for ALV but little confused where to call , See my correction below it is displaying the result in different way that ie...first displaying Equipment no, name,.correctly but the other values such as km,L,HR all are displaying zero first, when I press back then it is displying the value twice thrise........keep on displaying duplicate records continuesly when back back is press can anyone correct this please
    REPORT  XYZ LINE-SIZE  220 LINE-COUNT 75
             NO STANDARD PAGE HEADING.
    TABLES : equi,
             equz,
             imptt,
             imrg,
             eqkt,
             iloa.
    type-pools: slis.                                 "ALV Declarations
    TYPES:  BEGIN OF ty_data  ,
             equnr      type equnr,         " Euipment no
             eqktx      type eqkt-eqktx,    " Equipment Text
             eqfnr       type iloa-eqfnr,     " Equipment Sort field
             idate      type imrg-idate,    " Measuring Date
             recdu      type imrg-recdu,    " Unit of measuring ='KM','L','H'
             recdv      type imrg-recdv,    " Counter reading data
             cancl       type imrg-cancl,
           END OF ty_data.
    TYPES: BEGIN OF ty_final,
             equnr           type equnr,            "  Equipment no
             eqktx           type eqkt-eqktx,       "  Equipment Text
             eqfnr           type iloa-eqfnr,       "  Equipment Sort field
             idate               type imrg-idate,       "  Measuring Date
             min_date_km     type imrg-idate,       "  Min Date
             min_km          type P DECIMALS 2,       "  Max Km
             max_date_km     type imrg-idate,
             max_km          type P DECIMALS 2,       "  Min km
             t_max_min_km    type P DECIMALS 2,       "  Total min_km-max_km
             min_date_hr     type imrg-idate,       "  Max Date
             min_hr          type P DECIMALS 2,       "  Max hr
             max_date_hr     type imrg-idate,
             max_hr          type P DECIMALS 2,       "  Min hr
             t_max_min_hr    type P DECIMALS 2,                "  Total min_hr-max_hr
             min_date_lit    type imrg-idate,
             min_lit         type P DECIMALS 2,       "  Min lit
             max_date_lit    type imrg-idate,
             max_lit         type P DECIMALS 2,       "  Max lit
             fuel_con        type P DECIMALS 2,       "  Total_hrs / t_max_min_hr
             fuel_con2       type P DECIMALS 2,       "  Total_hrs / t_max_min_hr
             km_l            type P DECIMALS 2,       "  t max_min_km / t_max_min_lit
             l_p             type P DECIMALS 2 ,      "  t_max_min_lit / t_max_min_hr
             l_p2            type P DECIMALS 2 ,
           END OF ty_final.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    DATA: i_data TYPE TABLE OF ty_data, " internal table
    wa_data TYPE ty_data, " work area
    i_final TYPE TABLE OF ty_final, " internal table
    wa_final TYPE ty_final. " work area
    SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: p_equnr FOR equi-equnr OBLIGATORY, "no-extension no intervals,
                    p_idate FOR imrg-idate.  "NO-EXTENSION NO INTERVALS OBLIGATORY,
                   "p_recdu FOR imrg-recdu." NO-EXTENSION NO INTERVALS ."default 'M3'" OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK blk1.
    SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
    SELECTION-SCREEN END OF BLOCK blk2.
    SELECTION-SCREEN END OF BLOCK blk.
    TOP-OF-PAGE.
      FORMAT INTENSIFIED ON.
      WRITE:/55(40) ' WAGNERS INVESTMENT LIMITED  '.
      WRITE:/50(40) ' VEHICLE FUEL CONSUMPTION REPORT ' CENTERED   ,
              2 'Page', sy-pagno.
      FORMAT INTENSIFIED OFF.
      WRITE:/50(40) '----
    ' CENTERED .
      FORMAT INTENSIFIED ON.
      WRITE:/2 sy-datum COLOR 3, sy-uzeit .
      "WRITE:/1 S903-SPMON ."p_yearf.
      ULINE.
      "CENTERED.
    write: /2 'Equipment No :'left-justified,p_equnr-low  color 2 , '  to   '  , p_equnr-high color 2.
    write: /2 'Date From    :', p_idate-low color 2 ,  ' to  '  , p_idate-high color 2.
    END-OF-PAGE.
    START-OF-SELECTION.
    select aequnr deqktx feqfnr eidate erecdu erecdv
    into table i_data
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate and
    e~cancl ne 'X'.
    loop  at i_data into wa_data.
    CLEAR: wa_final.
      READ TABLE i_final into wa_final
               with key equnr = wa_data-equnr." BINARY SEARCH.
        if sy-subrc EQ 0.
          PERFORM F_GET_MAX_DATA.
          PERFORM F_GET_MAX_HOURS.
          PERFORM F_GET_MAX_LIT.
          PERFORM prepare_final_rec USING'M'. " Modify Existing Record
         ElSE.
          PERFORM prepare_final_rec USING'A'. " Append New Record.
          perform build_fieldcatalog.
          perform build_layout.
          perform display_alv_report.
        ENDIF.
       ENDLOOP.
    refresh i_final.
    clear i_final.
    FORM F_GET_MAX_DATA.
    select single MAX( eidate ) Min( eidate ) MAX( erecdv ) MIN( erecdv )
    into   corresponding fields of (wa_final-max_date_km,wa_final-min_date_km,wa_final-max_km ,wa_final-min_km)
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne 'X' and
    e~recdu =  'KM'
    AND a~equnr = wa_data-equnr.
    ENDFORM.
    FORM F_GET_MAX_HOURS.
    select single MAX( erecdv ) MIN( erecdv )
    into corresponding fields of (wa_final-max_hr, wa_final-min_hr)
    from equi AS a
    inner join equz as b
    on aequnr = bequnr
    inner join iloa as f
    on biloan = filoan
    inner join imptt as c
    on aobjnr = cmpobj
    inner join eqkt as d
    on aequnr = dequnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne  'X' and
    e~recdu =  'H'
    AND a~equnr = wa_data-equnr  .
    ENDFORM.
    FORM F_GET_MAX_LIT.
    select SUM( e~recdv )
    into corresponding fields of (wa_final-fuel_con2)
    from equi AS a
    inner join eqkt as b
    on bequnr = aequnr
    inner join imptt as c
    on cmpobj = aobjnr
    inner join imrg as e
    on epoint = cpoint
    where a~equnr in p_equnr
    and
    e~idate in p_idate
    and
    e~cancl ne  'X' and
    e~recdu =  'L'
    AND a~equnr = wa_data-equnr.
    ENDFORM.
    FORM prepare_final_rec  USING    p_mode TYPE char1.
    wa_final-t_max_min_km = wa_final-max_km - wa_final-min_km .
    wa_final-t_max_min_hr = wa_final-max_hr - wa_final-min_hr.
    if  wa_final-t_max_min_km <> 0 .
    wa_final-km_l =  ( wa_final-max_km - wa_final-min_km )  /  ( wa_final-fuel_con2 ) .
    ELSE.
    wa_final-km_l = 0.
    endif.
    if  wa_final-t_max_min_hr <> 0  .
    wa_final-l_p2 = ( wa_final-fuel_con2 ) / (  wa_final-t_max_min_hr ) .
    ELSE.
    wa_final-l_p2 = 0.
    endif.
      IF p_mode = 'A'.
        wa_final-equnr = wa_data-equnr.
        wa_final-eqktx = wa_data-eqktx.
        wa_final-eqfnr = wa_data-eqfnr.
        wa_final-t_max_min_km = wa_final-min_km - wa_final-max_km .
        wa_final-t_max_min_hr = wa_final-max_hr - wa_final-min_hr.
        wa_final-km_l =  ( wa_final-max_km - wa_final-min_km ) /  ( wa_final-fuel_con2 ).
      gd_repid = sy-repid.
        wa_final-l_p2 = ( wa_final-fuel_con2 ) / (  wa_final-t_max_min_hr ) .
        APPEND wa_final TO i_final  .
      ELSE.
        MODIFY i_final FROM wa_final
          TRANSPORTING
              eqfnr
              max_date_km
              min_date_km
              max_date_lit
              min_date_lit
              max_date_hr
              min_date_hr
              max_km
              min_km
              max_hr
              min_hr
              t_max_min_km
              t_max_min_hr
              fuel_con2
              km_l
              l_p2
              where equnr = wa_data-equnr.
      ENDIF.
    ENDFORM.                    " PREPARE_FINAL_REC
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
                  I.e. Field type may be required in-order for
                       the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EQUNR'.
      fieldcatalog-seltext_m   = 'Equip no'.
      fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EQKTX'.
      fieldcatalog-seltext_m   = 'Description'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 1.
    append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EQFNR'.
      fieldcatalog-seltext_m   = 'Sortfield'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MIN_DATE_KM'.
      fieldcatalog-seltext_m   = 'Min Date'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MAX_DATE_KM'.
      fieldcatalog-seltext_m   = 'Max Date'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MIN_KM' .
      fieldcatalog-seltext_m   = 'Min KM'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MAX_KM' .
      fieldcatalog-seltext_m   = 'Max KM'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'T_MAX_MIN_KM' .
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-seltext_m   = 'Total KM'.
      fieldcatalog-col_pos     = 7.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    fieldcatalog-fieldname   = 'MIN_HR' .
      fieldcatalog-seltext_m   = 'Min Hr'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MAX_HR' .
      fieldcatalog-seltext_m   = 'Max Hr'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 9.
    append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'T_MAX_MIN_HR' .
      fieldcatalog-seltext_m   = 'Total HR'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 10.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'FUEL_CON2' .
      fieldcatalog-seltext_m   = 'Km/L'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 11.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'L_P2' .
      fieldcatalog-seltext_m   = 'Lit/HR'.
        fieldcatalog-tabname     =  'i_final'.
      fieldcatalog-col_pos     = 12.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
               i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
               is_variant              = z_template
           tables
                t_outtab                = i_final
                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_ALV_REPORT

  • Using ALV

    Hi all,
    I need to generate a report using ALV which displays certain fields. After displaying this output, I have a requirement as mentioned below :
    Each line should have a checkbox present in the first column.  Multiple checkboxes can be selected, and upon execution all selected documents will print.  A status field will be found at the end of the row and will reflect the current status of the print documents.  After printing occurs, the screen should refresh and processing status reflected to show post-print status.  The user will then be able to see what documents printed immediately.  Any documents that did not successfully print will need to be reprinted through the .PDF files stored in the shared directory.
    I am unable to proceed further.
    Pointers would be helpful.
    Thanks in advance.
    Regards,
    Nikhil.

    Hi Nikhil,
    Your whole requirement is very vast. If I look the same then I can broadly divide the same in following area:
    1. Introducing checkbox in ALV.
    2. Take only those documents which are selected
    3. Status field of every document selected should the print status of the document.
    4. Saving the whole selected data in the .pdf file.
    Now for first one use the following code:
             checkbox TYPE c.                       "Declare a checkbox in your internal table
    FORM fill_fieldcatalog .                          "Use this code form ALV display.
      CLEAR i_fieldcat[].
      i_fieldcat-fieldname = 'CHECKBOX'.
      i_fieldcat-tabname = 'I_OUTPUT'.
      i_fieldcat-col_pos = 1.
      i_fieldcat-col_opt = 'X'.
      i_fieldcat-checkbox = 'X'.
      i_fieldcat-edit = 'X'.
      APPEND i_fieldcat.
      CLEAR i_fieldcat.
    Endform.
    Siddarth

  • Interactive reporting in alv

    hi experts ..
    i has a query of how to do interactive reporting in alv,s what are the function modules i can use to attain interactiveness. .?
    Regards,
    sujatha

    Hi,
    Check the below code... u will get some idea...
    REPORT  zmms_alv_1 NO STANDARD PAGE HEADING
    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE slis_layout_alv,
          gd_repid     LIKE sy-repid,
          gt_events     TYPE slis_t_event,
          gd_prntparams TYPE slis_print_alv.
    *Start-of-selection.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM build_events.
      PERFORM build_print_params.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
      fieldcatalog-hotspot     = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    *  gd_layout-totals_only        = 'X'.
    *  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
    *                                         "click(press f2)
    *  gd_layout-zebra             = 'X'.
    *  gd_layout-group_change_edit = 'X'.
    *  gd_layout-header_text       = 'helllllo'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
    *       Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
                i_callback_pf_status_set = 'PF_STATUS_SET'
                i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
                it_events               = gt_events
                is_print                = gd_prntparams
                i_save                  = 'X'
    *            is_variant              = z_template
           TABLES
                t_outtab                = it_ekko
           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_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekko.
    ENDFORM.                    " DATA_RETRIEVAL
    * Form  TOP-OF-PAGE                                                 *
    * ALV Report Header                                                 *
    FORM top-of-page.
    *ALV Header declarations
      DATA: t_header TYPE slis_t_listheader,
            wa_header TYPE slis_listheader,
            t_line LIKE wa_header-info,
            ld_lines TYPE i,
            ld_linesc(10) TYPE c.
    * Title
      wa_header-typ  = 'H'.
      wa_header-info = 'EKKO Table Report'.
      APPEND wa_header TO t_header.
      CLEAR wa_header.
    * Date
      wa_header-typ  = 'S'.
      wa_header-key = 'Date: '.
      CONCATENATE  sy-datum+6(2) '.'
                   sy-datum+4(2) '.'
                   sy-datum(4) INTO wa_header-info.   "todays date
      APPEND wa_header TO t_header.
      CLEAR: wa_header.
    * Total No. of Records Selected
      DESCRIBE TABLE it_ekko LINES ld_lines.
      ld_linesc = ld_lines.
      CONCATENATE 'Total No. of Records Selected: ' ld_linesc
                        INTO t_line SEPARATED BY space.
      wa_header-typ  = 'A'.
      wa_header-info = t_line.
      APPEND wa_header TO t_header.
      CLEAR: wa_header, t_line.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_header
          i_logo             = 'HCL'.
    ENDFORM.                    "top-of-page
    *       FORM USER_COMMAND                                          *
    *       --> R_UCOMM                                                *
    *       --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    * Check function code
      CASE r_ucomm.
        WHEN '&IC1' or '&NFO'.
    *   Check field clicked on within ALVgrid report
          IF rs_selfield-fieldname = 'EBELN'.
    *     Read data table, using index of row user clicked on
            READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    *     Set parameter ID for transaction screen field
            SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    *     Sxecute transaction ME23N, and skip initial data entry screen
            CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  BUILD_EVENTS
    *       Build events table
    FORM build_events.
      DATA: ls_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = gt_events[].
      READ TABLE gt_events WITH KEY name =  slis_ev_end_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE 'END_OF_PAGE' TO ls_event-form.
        APPEND ls_event TO gt_events.
      ENDIF.
      READ TABLE gt_events WITH KEY name =  slis_ev_end_of_list
                             INTO ls_event.
      IF sy-subrc = 0.
        MOVE 'END_OF_LIST' TO ls_event-form.
        APPEND ls_event TO gt_events.
      ENDIF.
    ENDFORM.                    " BUILD_EVENTS
    *&      Form  BUILD_PRINT_PARAMS
    *       Setup print parameters
    FORM build_print_params.
      gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
      gd_prntparams-no_coverpage = 'X'.
    ENDFORM.                    " BUILD_PRINT_PARAMS
    *&      Form  END_OF_PAGE
    FORM end_of_page.
      DATA: listwidth TYPE i,
            ld_pagepos(10) TYPE c,
            ld_page(10)    TYPE c.
      WRITE: sy-uline(50).
      SKIP.
      WRITE:/40 'Page:', sy-pagno .
    ENDFORM.                    "END_OF_PAGE
    *&      Form  END_OF_LIST
    FORM end_of_list.
      DATA: listwidth TYPE i,
            ld_pagepos(10) TYPE c,
            ld_page(10)    TYPE c.
      SKIP.
      WRITE:/40 'Page:', sy-pagno .
    ENDFORM.                    "END_OF_LIST
    *&      Form  PF_STATUS_SET
    *       text
    *      -->RT_EXTAB   text
    FORM pf_status_set USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'STANDARD'.
    ENDFORM.                    "PF_STATUS_SET
    Reward Points if it is Useful.
    Thanks,
    Manjunath MS

  • Normal report to alv

    Hi Friends..
    I have create report using some table.
    Finally i have stored the result in one itab,from that itab only i have displayed results.
    But i want to display the result in ALV Format, in that place what can i do
    send any sample program or give any suggestion..
    Thanks in Advance
    Gowrishankar

    Hi,
    *& Report  ZDEMO_ALVGRID                                               *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic requirement for this demo is to display a number of       *
    *& fields from the EKKO table.                                         *
    REPORT  zdemo_alvgrid                 .
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15. 
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    *  gd_layout-totals_only        = 'X'.
    *  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
    *                                         "click(press f2)
    *  gd_layout-zebra             = 'X'.
    *  gd_layout-group_change_edit = 'X'.
    *  gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
    *       Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
    *            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
    *            i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
    *            IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
    *            is_variant              = z_template
           tables
                t_outtab                = it_ekko
           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_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
    select ebeln ebelp statu aedat matnr menge meins netpr peinh
    up to 10 rows
      from ekpo
      into table it_ekko.
    endform.                    " DATA_RETRIEVAL
    http://www.erpgenie.com/abap/code/abap28.htm
    http://sap.niraj.tripod.com/id64.html
    http://www.erpgenie.com/abap/controls/alvgrid.htm
    Regards
    Sudheer

  • Sales analysis report - in query form?

    Good afternoon. Looking for a bit if help/advice.
    I'm not a complete novice to SAP but what I need is confusing me slightly. I understand the sales analysis report uses many different table as part of its calculations. A company I've recently began working for, who has had SAP for a while, has used sales analysis reports alongside some bespoke reports that are reporting different data.
    Here is their report:
    SELECT T0.[DocNum] AS 'Invoice No.',  CONVERT(VARCHAR(10),T0.[DocDate], 103) AS 'Invoice Date', T0.[NumAtCard] AS 'Cust Order No.', T4.[ItemCode], T5.[U_MSKU] AS 'Manuf SKU', T4.[Dscription] AS 'Description', T6.[ItmsGrpNam] AS 'Item Group', T4.[Quantity], T4.[Price] AS 'Net Unit Price', T4.[LineTotal] AS 'Net/Line Total', T0.[U_ClientNam] AS 'Client Name', T2.[Name] AS 'Division', T1.[Name] AS 'Business Unit', T3.[StreetS] AS 'Ship-to Street', T3.[CityS] AS 'Ship-to City', T3.[ZipCodeS] AS 'Ship-to Postcode'
    FROM OINV T0
    LEFT JOIN [dbo].[@BUSINESSUNITS]  T1 ON T0.U_Bizunits = T1.Code
    LEFT JOIN [dbo].[@DIVISIONS]  T2 ON T0.U_Division = T2.Code
    INNER JOIN INV12 T3 ON T0.DocEntry = T3.DocEntry
    INNER JOIN INV1 T4 ON T0.DocEntry = T4.DocEntry
    INNER JOIN OITM T5 ON T4.ItemCode = T5.ItemCode
    INNER JOIN OITB T6 ON T5.ItmsGrpCod = T6.ItmsGrpCod
    WHERE T0.[DocDate] BETWEEN [%0] AND [%1]  AND T0.[CardCode] = [%2]
    It just doesn't give the same totals as the sales analysis report but I can't reproduce the sales analysis report. How would I go about getting the right figures? Because what we ideally need is to filter the sales analysis results by some of our custom fields:
    [U_ClientNam], [Name] etc.
    How would I go about this? Can I extract parts of the sales analysis report somehow and run it as a query I can manipulate?
    Thanks.

    Hi, not sure if you meant to link to a thread? Based on the query you have given on this thread no totals appear to match however it is much closer than the simple query.
    SELECT Div, BusUnit, isnull([1],0) as Jan, isnull([2],0) as Feb, [3] as Mar, isnull([4],0) as Apr, isnull([5],0) as May, isnull([6],0) as june, isnull([7],0) as July, isnull([8],0) as Aug, isnull([9],0) as Sept, isnull([10],0) as Oct, isnull([11],0) as Nov, isnull([12],0) as Dec
    from
    (SELECT T1.[LineTotal] as Total, month(T0.[DocDate])as month, T8.[Name] AS BusUnit, T9.[Name] AS Div FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[@BUSINESSUNITS]  T8 ON T0.U_Bizunits = T8.Code INNER JOIN [dbo].[@DIVISIONS]  T9 ON T0.U_Division = T9.Code
    WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = 'NOR0001'
    union all
    (SELECT -T1.[LineTotal] as Total, month(T0.[DocDate])as month, T8.[Name] AS BusUnit, T9.[Name] AS Div FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[@BUSINESSUNITS]  T8 ON T0.U_Bizunits = T8.Code INNER JOIN [dbo].[@DIVISIONS]  T9 ON T0.U_Division = T9.Code
    WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = 'NOR0001')) S
    Pivot
    (sum(S.Total) For Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    Is what I've just used. Still well off the mark though.

Maybe you are looking for