Report: ALV with example

HI,
do you have some samplecode for report with ALV Output ?
do you have some information hot wo use ALV ?
thx.
Gordon

Hi
  You can referece the sample code.
TYPE-POOLS: slis.
TYPES:
  BEGIN OF ty_test,
    name TYPE syuname,
    start_date TYPE sydate,
    end_date TYPE sydate,
  END OF ty_test.
TYPES:
  ty_tb_test TYPE STANDARD TABLE OF ty_test.
DATA:
  i_test TYPE ty_tb_test,
  w_test TYPE ty_test,
  i_fieldcat TYPE slis_t_fieldcat_alv,
  w_fieldcat TYPE LINE OF    slis_t_fieldcat_alv,
  i_header TYPE slis_t_listheader,
  w_header TYPE LINE OF slis_t_listheader.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
  PARAMETERS: name TYPE syuname,
              start TYPE sydate,
              end TYPE sydate.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
  PERFORM fill_data.
  PERFORM field_define.
  PERFORM display_alv.
FORM fill_data.
  w_test-name = 'MBOORE'.
  w_test-start_date = '20080701'.
  w_test-end_date = '20080731'.
  APPEND w_test to i_test.
  CLEAR w_test.
  w_test-name = 'JDUFFY'.
  w_test-start_date = '20080715'.
  w_test-end_date = '20080810'.
  APPEND w_test to i_test.
  CLEAR w_test.
  w_test-name = 'JVNSOLD'.
  w_test-start_date = '20080601'.
  w_test-end_date = '20080720'.
  APPEND w_test to i_test.
  CLEAR w_test.
ENDFORM.
FORM field_define.
  w_fieldcat-fieldname = 'NAME'.
  w_fieldcat-seltext_l = 'name'.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'START_DATE'.
  w_fieldcat-seltext_l = 'start_date'.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'END_DATE'.
  w_fieldcat-seltext_l = 'end_date'.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.
ENDFORM.
FORM display_alv.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program                = sy-repid
      i_callback_top_of_page            = 'DISPLAY_HEADER'
      IT_FIELDCAT                       = i_fieldcat
    TABLES
      t_outtab                          = i_test
    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.
FORM display_header.
  w_header-typ = 'H'.
  w_header-info = 'This test case has been passed'.
  APPEND w_header TO i_header.
  CLEAR w_header.
  w_header-typ = 'S'.
  CONCATENATE 'Where User Name - ' name INTO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.
  w_header-typ = 'S'.
  CONCATENATE 'Start Date - ' start INTO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.
  w_header-typ = 'S'.
  CONCATENATE 'End Date - ' end INTO w_header-info.
  APPEND w_header TO i_header.
  CLEAR w_header.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = i_header
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
ENDFORM.

Similar Messages

  • Any one pls send me documentation on blocked and hierachi alv with example

    hi experts,
    any one pls send me documentation on blocked and hierachi alv with example
    rewad points.........

    Hi,
    Check this prg:
    BCALV_TEST_HIERSEQ_LIST
    Regards,
    Subramanian

  • Format of Column in report ALV.

    Dear Experts.
    I am creating a report ALV with the tables ANLA, ANLB, ANLC, and this work fine with the data that this display.
    The problem that i have is the following:
    The columns KANSW , KNAFA of the table ANLC that I display in te report  When the currency is USD, I should show the datas with 2 decimals, but with currency  COL, I should show this fields without decimals.
    In the report ALV this data are show all in the same report ALV, in the same column.
    When I am creating the catalog, i use :
    gt_fieldcat-decimals_out = 2. and this show good the values when the currency is USD, but the other already show the two decilmals,
    How can solve this issue.
    Regards

    Hi,
    Firstly, Go to transaction OY04 to check how many decimal place will print depend on currency code.
    Then, while building your fieldcat you should link currency amount to currency unit as below:
    gs_fieldcat-fieldname = 'KANSW'.
    gs_fieldcat-tabname = 'ITAB'. "assume your internal table while pass to REUSE_ALV...
    gs_fieldcat-cfieldname = 'WAERS'. "your currency unit in ITAB
    gs_fieldcat-ctabname = 'ITAB'.
    *gt_fieldcat-decimals_out = 2 "try to comment this line
    append gs_fieldcat to gt_fieldcat.
    Please check.
    Good luck.

  • Is there any help for ALV report development with  funcation modules?

    Hi,
    please tell me any help or example to understand the ALV function module.

    Hi neha,
    1. very simple alv
       (with minimum code)
    2. just copy paste
    3.
    report abc.
    TYPE-POOLS : slis.
    DATA : alvfc TYPE slis_t_fieldcat_alv.
    DATA : alvfcwa TYPE slis_fieldcat_alv.
    data : begin of itab occurs 0.
            include structure usr02.
    data : end of itab.
    START-OF-SELECTION.
      select * from usr02
      into table itab.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = sy-repid
          i_internal_tabname     = 'ITAB'
          i_inclname             = sy-repid
        CHANGING
          ct_fieldcat            = alvfc
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
    Display
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          it_fieldcat   = alvfc
        TABLES
          t_outtab      = itab
        EXCEPTIONS
          program_error = 1
          OTHERS        = 2.
    regards,
    amit m.

  • COPA Report Layout with Object List (ALV)

    Hi,
    I have question about the COPA report layout with object list (ALV). Everytime I executed the report with ALV format, the amount for quantity column always shows with 3 decimal number, menwhile for amount column always follow by 2 decimal number.
    Can anyone help me regarding this matter? I do not know how to turn off the decimal number to be 0 in this type of layout, although in the form itself I already put 0 decimal number.
    Thanks.

    Hi,
    Better to raise this issue in CO Forum. You can expect some solution.
    regards

  • FI report with example !!!

    Can anyone of you please give me few examples of FI ALV reports, I have asked this question before also but nobody replied. I have an interview tommorow, so any help will really be appreciated.
    Thanks,
    Rajeev !!!

    Try transaction FBL5N (report RFITEMAR) for example, which is customer items..or FBL1N (report RFITEMAP) for vendors...  but it's probably more important understanding how the FI database tables fit together (BKPF, BSEG, BSIK, BSID and all their friends), and how ALV works in general (plenty of examples on SDN already).
    Jonathan

  • Carl's Report Row with Detail Example

    Hi,
    Hoping someone can assist, I am looking at using Carl's "Report Row with Detail" example at:
    http://apex.oracle.com/pls/otn/f?p=11933:1
    The only thing that I am unsure about is that , instead of using the words show comments/hide comments, I would actually like use an image that will toggle, i.e initially have a plus.gif (+) image to expand row and then toggle to a minus.gif (-) image to hide the row.
    Using Carl's example, would really appreciate some help on achieving this. I tried replacing the innerhtml with an image file but had no luck.
    Thanks.
    Tony.

    Hello,
    There you go http://apex.oracle.com/pls/otn/f?p=11933:107 just make sure the images have a plus and a minus in the filename,
    Regards,
    Carl
    blog : http://carlback.blogspot.com/
    apex examples : http://apex.oracle.com/pls/otn/f?p=11933:5

  • Heirarchical ALV with OOPS

    Can anyone help me with the code of Heirarchical ALV with OOPS in module pool programming.

    hi,
    <i>link</i>
    http://www.sap-img.com/abap/how-to-use-alv-for-hierarchical-lists.htm
    <i>Check this example report :</i> BALVHD01
    <i>chk a sample code.</i>
    REPORT  ZTEST_HIER LINE-COUNT 65
                                 LINE-SIZE 200
                                 NO STANDARD PAGE HEADING
                                 MESSAGE-ID ZZ.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF TY_HEAD,
          VBELN LIKE VBAK-VBELN,
          KUNNR LIKE VBAK-KUNNR,
          NAME  LIKE KNA1-NAME1,
          END OF TY_HEAD.
    TYPES: BEGIN OF TY_ITEM,
           VBELN LIKE VBAP-VBELN,
           POSNR LIKE VBAP-POSNR,
           MATNR LIKE VBAP-MATNR,
           MAKTX LIKE MAKT-MAKTX,
           CHECK(1),
           END OF TY_ITEM.
    DATA: IT_ITEM TYPE TABLE OF TY_ITEM.
    DATA: IT_HEADER TYPE TABLE OF TY_HEAD,
           IT_EVENTS TYPE SLIS_T_EVENT,          "Events.
           IT_FIELDCAT      TYPE SLIS_T_FIELDCAT_ALV.
    DATA: X_LAYOUT         TYPE SLIS_LAYOUT_ALV,
          X_FIELDCAT       TYPE SLIS_FIELDCAT_ALV,
          X_KEY           TYPE SLIS_KEYINFO_ALV,
          X_EVENTS TYPE SLIS_ALV_EVENT,      "Event
          X_VBELN LIKE VBAK-VBELN,
          X_ITEM TYPE TY_ITEM.
    CONSTANTS: C_S(1) VALUE '/'.
    DATA: V_FLAG.
    *                   SELECTION-SCREEN                                  *
    SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_VBELN FOR X_VBELN.      "Sales order Number
    SELECTION-SCREEN END OF BLOCK BLK.
    AT SELECTION-SCREEN.
      IF NOT S_VBELN[] IS INITIAL.
        SELECT SINGLE VBELN
               INTO X_VBELN
               FROM VBAK
               WHERE VBELN IN S_VBELN.
        IF SY-SUBRC <> 0.
          MESSAGE E002 WITH 'Please enter valid Sales Order'(020).
        ENDIF.
      ENDIF.
    *       CLASS lcl_bill_complete DEFINITION
    CLASS LCL_BILL_COMPLETE DEFINITION.
      PUBLIC SECTION.
        METHODS:GET_HEADER_DATA,
                GET_ITEM_DATA,
                SHOW_DATA,
                FILL_FIELDCAT,
                FILL_EVENTS,
                TOP_OF_PAGE.
    ENDCLASS.                    "lcl_bill_complete DEFINITION
    *       CLASS lcl_bill_complete IMPLEMENTATION
    CLASS LCL_BILL_COMPLETE IMPLEMENTATION.
      METHOD GET_HEADER_DATA.
        DATA:X_HEADER LIKE LINE OF IT_HEADER.
        X_HEADER-VBELN = '12345'.
        X_HEADER-KUNNR = '1234'.
        X_HEADER-NAME = 'Test'.
        APPEND X_HEADER TO IT_HEADER.
        X_HEADER-VBELN = '12346'.
        X_HEADER-KUNNR = '1236'.
        X_HEADER-NAME = 'Test'.
        APPEND X_HEADER TO IT_HEADER.
        X_HEADER-VBELN = '12347'.
        X_HEADER-KUNNR = '1235'.
        X_HEADER-NAME = 'Test'.
        APPEND X_HEADER TO IT_HEADER.
      ENDMETHOD.                    "get_header_data
      METHOD GET_ITEM_DATA.
        DATA:X_ITEM LIKE LINE OF IT_ITEM.
        X_ITEM-VBELN = '12345'.
        X_ITEM-POSNR = '0010'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
        X_ITEM-VBELN = '12345'.
        X_ITEM-POSNR = '0020'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
        X_ITEM-VBELN = '12346'.
        X_ITEM-POSNR = '0010'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
        X_ITEM-VBELN = '12346'.
        X_ITEM-POSNR = '0020'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
        X_ITEM-VBELN = '12347'.
        X_ITEM-POSNR = '0010'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
        X_ITEM-VBELN = '12347'.
        X_ITEM-POSNR = '0020'.
        X_ITEM-MATNR = 'TESTMATNR'.
        X_ITEM-MAKTX = 'TESTMAT'.
        APPEND X_ITEM TO IT_ITEM.
      ENDMETHOD.                    "get_item_data
      METHOD SHOW_DATA.
        X_KEY-HEADER01 = 'VBELN'.
        X_KEY-ITEM01   = 'VBELN'.
        X_KEY-ITEM02   = 'POSNR'.
        CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
          EXPORTING
            I_CALLBACK_PROGRAM = SY-REPID
            IS_LAYOUT          = X_LAYOUT
            IT_FIELDCAT        = IT_FIELDCAT[]
            I_TABNAME_HEADER   = 'IT_HEADER'
            I_TABNAME_ITEM     = 'IT_ITEM'
            IS_KEYINFO         = X_KEY
            IT_EVENTS          = IT_EVENTS
          TABLES
            T_OUTTAB_HEADER    = IT_HEADER
            T_OUTTAB_ITEM      = IT_ITEM
          EXCEPTIONS
            PROGRAM_ERROR      = 1
            OTHERS             = 2.
      ENDMETHOD.                    "show_data
      METHOD FILL_FIELDCAT.
        DATA: L_POS TYPE I.
        X_LAYOUT-HEADER_TEXT      = 'HEADER'.
        X_LAYOUT-ITEM_TEXT        = 'ITEM'.
        X_LAYOUT-DEFAULT_ITEM     = ' '.
        X_LAYOUT-NO_KEYFIX        = 'X'.
        X_LAYOUT-BOX_TABNAME      = 'IT_ITEM'.
        L_POS = L_POS + 1.
    *- Sales Order Number
        X_FIELDCAT-FIELDNAME   = 'VBELN'.
        X_FIELDCAT-TABNAME    = 'IT_HEADER'.
        X_FIELDCAT-SELTEXT_M   = 'Sales Order'(017).
        X_FIELDCAT-OUTPUTLEN  = 11.
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'KUNNR'.
        X_FIELDCAT-TABNAME    = 'IT_HEADER'.
        X_FIELDCAT-SELTEXT_M   = 'Sold-to Party'(010).
        X_FIELDCAT-OUTPUTLEN  = 13.
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'NAME'.
        X_FIELDCAT-TABNAME    = 'IT_HEADER'.
        X_FIELDCAT-OUTPUTLEN  = 15.
        X_FIELDCAT-SELTEXT_M   = 'Sold-to name'(011).
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'CHECK'.
        X_FIELDCAT-TABNAME    = 'IT_ITEM'.
        X_FIELDCAT-CHECKBOX   = 'X'.
        X_FIELDCAT-INPUT  = 'X'.
        X_FIELDCAT-EDIT  = 'X'.
        X_FIELDCAT-SELTEXT_M   = ' '.
        X_FIELDCAT-OUTPUTLEN  = 2.
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'VBELN'.
        X_FIELDCAT-TABNAME    = 'IT_ITEM'.
        X_FIELDCAT-SELTEXT_M   = 'Sales Order'(017).
        X_FIELDCAT-OUTPUTLEN  = 11.
        X_FIELDCAT-TECH = 'X'.
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
    *- Sales Order Item
        X_FIELDCAT-FIELDNAME   = 'POSNR'.
        X_FIELDCAT-TABNAME    = 'IT_ITEM'.
        X_FIELDCAT-SELTEXT_M   = 'SO Item'(018).
        X_FIELDCAT-OUTPUTLEN  = 7.
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'MATNR'.
        X_FIELDCAT-TABNAME    = 'IT_ITEM'.
        X_FIELDCAT-OUTPUTLEN  = 18.
        X_FIELDCAT-SELTEXT_M   = 'Material number'(012).
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
        L_POS = L_POS + 1.
        X_FIELDCAT-FIELDNAME   = 'MAKTX'.
        X_FIELDCAT-TABNAME    = 'IT_ITEM'.
        X_FIELDCAT-OUTPUTLEN  = 40.
        X_FIELDCAT-SELTEXT_M   = 'Material Description'(013).
        X_FIELDCAT-COL_POS     = L_POS.
        APPEND X_FIELDCAT TO IT_FIELDCAT.
        CLEAR  X_FIELDCAT.
      ENDMETHOD.                    "fill_fieldcat
    *--Fill the events table
      METHOD FILL_EVENTS.
    *-  Top of page
        X_EVENTS-NAME =  'TOP_OF_PAGE'.
        X_EVENTS-FORM =  'TOP_OF_PAGE'.
        APPEND X_EVENTS TO IT_EVENTS.
      ENDMETHOD.                    "fill_events
      "fill_events
      METHOD TOP_OF_PAGE.
    *-  Call Steelcase Standard Header
        WRITE 'top_of_page here'.
      ENDMETHOD.                    "top_of_page
    ENDCLASS.                    "lcl_bill_complete IMPLEMENTATION
    START-OF-SELECTION.
      DATA: OBJ TYPE REF TO LCL_BILL_COMPLETE.
      CREATE OBJECT OBJ.
      CALL METHOD OBJ->GET_HEADER_DATA.
      CALL METHOD OBJ->GET_ITEM_DATA.
      CALL METHOD OBJ->FILL_FIELDCAT.
      CALL METHOD OBJ->FILL_EVENTS.
      CALL METHOD OBJ->SHOW_DATA.
    *&      Form  top_of_page
    *      TOP_OF_PAGE
    FORM TOP_OF_PAGE.
    *-To show the top of page
      CALL METHOD OBJ->TOP_OF_PAGE.
    ENDFORM.                    "top_of_page
    if hlped plsmark points.
    rgds
    Anver

  • ALV with dynamic columns and description labels in header titles

    Hi everybody,
    I have to implement an ALV whose columns are not defined until runtime. Is it possible to do that in some simple way? Is it necessary to use objects to define this kind of ALV's?
    And another one query, is it possible to add description labels to column headers so that when the user points with the cursor in them he/she gets a little explanation about the detail of the column (for example, description name of the product hierarchy when pointing to the column named with one of the existing hierarchies, i.e 010102102)
    Thanks in advance,

    for your first question check this
    Just check this sample from one of the SAP site
    ABAP Code Sample for Dynamic Table for ALV with Cell Coloring
    Applies To:
    ABAP / ALV Grid
    Article Summary
    ABAP Code Sample that uses dynamic programming techniques to build a dynamic internal table for display in an ALV Grid with Cell Coloring.
    Code Sample
    REPORT zcdf_dynamic_table.
    * Dynamic ALV Grid with Cell Coloring.
    * Build a field catalog dynamically and provide the ability to color
    * the cells.
    * To test, copy this code to any program name and create screen 100
    * as described in the comments. After the screen is displayed, hit
    * enter to exit the screen.
    * Tested in 4.6C and 6.20
    * Charles Folwell - [email protected] - Feb 2, 2005
    DATA:
    r_dyn_table TYPE REF TO data,
    r_wa_dyn_table TYPE REF TO data,
    r_dock_ctnr TYPE REF TO cl_gui_docking_container,
    r_alv_grid TYPE REF TO cl_gui_alv_grid,
    t_fieldcat1 TYPE lvc_t_fcat, "with cell color
    t_fieldcat2 TYPE lvc_t_fcat, "without cell color
    wa_fieldcat LIKE LINE OF t_fieldcat1,
    wa_cellcolors TYPE LINE OF lvc_t_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:
    <t_dyn_table> TYPE STANDARD TABLE,
    <wa_dyn_table> TYPE ANY,
    <t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    START-OF-SELECTION.
    * Build field catalog based on your criteria.
    wa_fieldcat-fieldname = 'FIELD1'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 1'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    wa_fieldcat-fieldname = 'FIELD2'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 2'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Before adding cell color table, save fieldcatalog to pass
    * to ALV call. The ALV call needs a fieldcatalog without
    * the internal table for cell coloring.
    t_fieldcat2[] = t_fieldcat1[].
    * Add cell color table.
    * CALENDAR_TYPE is a structure in the dictionary with a
    * field called COLTAB of type LVC_T_SCOL. You can use
    * any structure and field that has the type LVC_T_SCOL.
    wa_fieldcat-fieldname = 'T_CELLCOLORS'.
    wa_fieldcat-ref_field = 'COLTAB'.
    wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Create dynamic table including the internal table
    * for cell coloring.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = t_fieldcat1
    IMPORTING
    ep_table = r_dyn_table
    EXCEPTIONS
    generate_subpool_dir_full = 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.
    * Get access to new table using field symbol.
    ASSIGN r_dyn_table->* TO <t_dyn_table>.
    * Create work area for new table.
    CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
    * Get access to new work area using field symbol.
    ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
    * Get data into table from somewhere. Field names are
    * known at this point because field catalog is already
    * built. Read field names from the field catalog or use
    * COMPONENT <number> in a DO loop to access the fields. A
    * simpler hard coded approach is used here.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'ABC'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'XYZ'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'TUV'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'DEF'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    * Color cells based on your criteria. In this example, a test on
    * FIELD2 is used to decide on color.
    LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    * Get access to internal table used to color cells.
    ASSIGN COMPONENT 'T_CELLCOLORS'
    OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
    CLEAR wa_cellcolors.
    wa_cellcolors-fname = 'FIELD2'.
    IF <w_field> = 'DEF'.
    wa_cellcolors-color-col = '7'.
    ELSE.
    wa_cellcolors-color-col = '5'.
    ENDIF.
    APPEND wa_cellcolors TO <t_cellcolors>.
    MODIFY <t_dyn_table> FROM <wa_dyn_table>.
    ENDLOOP.
    * Display screen. Define screen 100 as empty, with next screen
    * set to 0 and flow logic of:
    * PROCESS BEFORE OUTPUT.
    * MODULE initialization.
    * PROCESS AFTER INPUT.
    CALL SCREEN 100.
    * MODULE initialization OUTPUT
    MODULE initialization OUTPUT.
    * Set up for ALV display.
    IF r_dock_ctnr IS INITIAL.
    CREATE OBJECT r_dock_ctnr
    EXPORTING
    side = cl_gui_docking_container=>dock_at_left
    ratio = '90'.
    CREATE OBJECT r_alv_grid
    EXPORTING i_parent = r_dock_ctnr.
    * Set ALV controls for cell coloring table.
    wa_is_layout-ctab_fname = 'T_CELLCOLORS'.
    * Display.
    CALL METHOD r_alv_grid->set_table_for_first_display
    EXPORTING
    is_layout = wa_is_layout
    CHANGING
    it_outtab = <t_dyn_table>
    it_fieldcatalog = t_fieldcat2.
    ELSE. "grid already prepared
    * Refresh display.
    CALL METHOD r_alv_grid->refresh_table_display
    EXPORTING
    i_soft_refresh = ' '
    EXCEPTIONS
    finished = 1
    OTHERS = 2.
    ENDIF.
    ENDMODULE. " initialization OUTPUT

  • ALV with Check Boxes

    Can I get a sample program of ALV (oops) with check boxes in it. thank you.

    Types: begin of lt_io.
    include structure mara. " Your Structure
    Types: style_table type lvc_t_style.
    Types: end of lt_io.
    data: lt_io type table of lt_io,
    ls_layout type lvc_s_layo,
    lt_fcat type lvc_t_fcat,
    lo_grid type ref to cl_gui_alv_grid.
    field-symbols: <io> type lt_io,
    <fcat> type lvc_s_fcat.
    ... fill your output table ....
    ls_layout-stylefname = 'STYLE_TABLE'.
    loop at lt_io assigning <io>.
    PERFORM set_style USING 'CHECKBOX' "Your Filename
    CHANGING <io>.
    endloop.
    ... Fill Your Field Catalog lt_fcat
    read table lt_fcat assigning <fcat>
    where fieldname = 'CHECKBOX'.
    <fcat>-checkbox = 'X'.
    create grid control lo_grid.
    CALL METHOD lo_grid->set_table_for_first_display
    EXPORTING
    is_layout = ls_layout
    CHANGING
    it_fieldcatalog = lt_fcat
    it_outtab = lt_io[].
    FORM set_button_to_line
    USING iv_fieldname TYPE lvc_fname
    CHANGING cs_io TYPE io.
    DATA: ls_style TYPE lvc_s_styl,
    lt_style TYPE lvc_t_styl.
    ls_style-fieldname = iv_fieldname.
    if cs_io-checkbox = ' '.
    ls_style-style = cl_gui_alv_grid=>mc_style_enabled.
    else.
    ls_style-style = cl_gui_alv_grid=>mc_style_disabled.
    endif.
    ls_style-maxlen = 2.
    INSERT ls_style INTO TABLE io-style_table.
    ENDFORM. "set_icon_to_status_line
    [/code].
    A classical report is a program that generates a single list, which must contain all of the required detail information.
    1) This procedure may result in extensive lists from which the user has to pick the relevant data.
    2) For background processing, this is the only possible method. After starting a background job, there is no way of influencing the program.
    3) The desired selections must be made beforehand and the list must provide detailed information.
    4) For dialog sessions, there are no such restrictions.
    5) The user is present during the execution of the program and can control and manipulate the program flow directly.
    6) To be able to use all advantages of the online environment, classical reporting was developed into interactive reporting.
    ALV is Application List viewer. Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length. In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output. The report output can contain up to 90 columns in the display with the wide array of display options.
    Advantages.
    Collapse multiple reports into one, drastically cutting down your report development time
    Save many hours using built-in ALV sorting, subtotaling and filtering capabilities
    Add conditional structures into your ALV report: No programming required!
    Combine ALV with display variants to meet a wide range of reporting requirements more easily
    Dynamically reorder column layouts and add/subtract fields
    Enable users and analysts to save their own personalized variants
    All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.
    1. SIMPLE REPORT.
    The important function modules are
    a. Reuse_alv_list_display
    b. Reuse_alv_fieldcatalog_merge
    c. Reuse_alv_events_get
    d. Reuse_alv_commentary_write
    e. Reuse_alv_grid_display
    A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.
    The important parameters are :
    I. Export :
    i. I_callback_program : report id
    ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status
    iii. I_callback_user_command : routine where the function codes are handled
    iv. I_structure name : name of the dictionary table
    v. Is_layout : structure to set the layout of the report
    vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE
    vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.
    II. Tables :
    i. t_outtab : internal table with the data to be output
    B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.
    The Important Parameters are :
    I. Export :
    i. I_program_name : report id
    ii. I_internal_tabname : the internal output table
    iii. I_inclname : include or the report name where all the dynamic forms are handled.
    II Changing
    ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is
    declared in the type pool SLIS.
    C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type
    Parameters :
    I. Import :
    Et_Events : The event table is returned with all possible CALLBACK events
    for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.
    II. Export :
    I_List_type :
    0 = simple list REUSE_ALV_LIST_DISPLAY
    1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY
    2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND
    3 = hierarchical-sequential block list
    REUSE_ALV_BLOCK_LIST_HS_APPEND
    D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.
    Parameters :
    I. it_list_commentary : internal table with the headings of the type slis_t_listheader.
    This internal table has three fields :
    Typ : ‘H’ – header, ‘S’ – selection , ‘A’ - action
    Key : only when typ is ‘S’.
    Info : the text to be printed
    E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.
    Parameters : same as reuse_alv_list_display
    This is an example for simple list.
    2. BLOCK REPORT
    This is used to have multiple lists continuously.
    The important functions used in this report are:
    A. REUSE_ALV_BLOCK_LIST_INIT
    B. REUSE_ALV_BLOCK_LIST_APPEND
    C. REUSE_ALV_BLOCK_LIST_HS_APPEND
    D. REUSE_ALV_BLOCK_LIST_DISPLAY
    A. REUSE_ALV_BLOCK_LIST_INIT
    Parameters:
    I. I_CALLBACK_PROGRAM
    II. I_CALLBACK_PF_STATUS_SET
    III. I_CALLBACK_USER_COMMAND
    This function module is used to set the default gui status etc.
    B. REUSE_ALV_BLOCK_LIST_APPEND
    Parameters :
    Export :
    I. is_layout : layout settings for block
    II. it_fieldcat : field catalog
    III. i_tabname : internal table name with output data
    IV. it_events : internal table with all possible events
    Tables :
    i. t_outtab : internal table with output data.
    This function module adds the data to the block.
    Repeat this function for all the different blocks to be displayed one after the other.
    C. REUSE_ALV_BLOCK_LIST_HS_APPEND
    This function module is used for hierarchical sequential blocks.
    D. REUSE_ALV_BLOCK_LIST_DISPLAY
    Parameters : All the parameters are optional.
    This function module display the list with data appended by the above function.
    Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.
    3. Hierarchical reports :
    Hierarchical sequential list output.
    The function module is
    A. REUSE_ALV_HIERSEQ_LIST_DISPLAY
    Parameters:
    I. Export:
    i. I_CALLBACK_PROGRAM
    ii. I_CALLBACK_PF_STATUS_SET
    iii. I_CALLBACK_USER_COMMAND
    iv. IS_LAYOUT
    v. IT_FIELDCAT
    vi. IT_EVENTS
    vii. i_tabname_header : Name of the internal table in the program containing the
    output data of the highest hierarchy level.
    viii. i_tabname_item : Name of the internal table in the program containing the
    output data of the lowest hierarchy level.
    ix. is_keyinfo : This structure contains the header and item table field
    names which link the two tables (shared key).
    II. Tables
    i. t_outtab_header : Header table with data to be output
    ii. t_outtab_item : Name of the internal table in the program containing the
    output data of the lowest hierarchy level.
    slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.
    Important Attributes :
    A. col_pos : position of the column
    B. fieldname : internal fieldname
    C. tabname : internal table name
    D. ref_fieldname : fieldname (dictionary)
    E. ref_tabname : table (dictionary)
    F. key(1) : column with key-color
    G. icon(1) : icon
    H. symbol(1) : symbol
    I. checkbox(1) : checkbox
    J. just(1) : (R)ight (L)eft (C)ent.
    K. do_sum(1) : sum up
    L. no_out(1) : (O)blig.(X)no out
    M. outputlen : output length
    N. seltext_l : long key word
    O. seltext_m : middle key word
    P. seltext_s : short key word
    Q. reptext_ddic : heading (ddic)
    R. ddictxt(1) : (S)hort (M)iddle (L)ong
    S. datatype : datatype
    T. hotspot(1) : hotspot
    declarations for spl.group.
    GT_SP_GROUP TYPE SLIS_T_SP_GROUP_ALV
    GT_SORT TYPE SLIS_T_SORTINFO_ALV, "for sort
    DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
      CLEAR LS_SORT.
      LS_SORT-FIELDNAME = 'FIELD1'.
      LS_SORT-SPOS      = 1.
      LS_SORT-UP        = 'X'.
      ls_sort-subtot    = 'X'. "subtotal
      APPEND LS_SORT TO E06_LT_SORT.
      APPEND LS_SORT TO E06_LT_SORT.
      LS_SORT-FIELDNAME = 'FIELD2'.
      LS_SORT-SPOS      = 2.
      LS_SORT-UP        = 'X'.
      ls_sort-subtot    = 'X'. "subtotal
      APPEND LS_SORT TO E06_LT_SORT.
    for creating the group..
      DATA: LS_SP_GROUP TYPE SLIS_SP_GROUP_ALV.
      CLEAR  LS_SP_GROUP.
      LS_SP_GROUP-SP_GROUP = 'A'.
      LS_SP_GROUP-TEXT     = TEXT-005.
      APPEND LS_SP_GROUP TO E07_LT_SP_GROUP.
    and pass this info to FM...
    layout-sUBTOTALS_TEXT = 'SUbt...'
    and pass spl group info to fieldcatalog also...
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM      = G_REPID
                IS_LAYOUT               = GS_LAYOUT
                IT_FIELDCAT             = GT_FIELDCAT[]
                IT_SPECIAL_GROUPS       = GT_SP_GROUP[]
                IT_SORT                 = GT_SORT[]
    TYPES :
      BEGIN OF ty_vbak,
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        vbeln TYPE vbak-vbeln,             " Sales document
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
        waerk TYPE vbak-waerk,             " Document currency
      END OF ty_vbak.
    DATA:
      vbak    TYPE vbak,
      gt_vbak TYPE TABLE OF ty_vbak.
    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.
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
         Form  f_read_data
    FORM f_read_data.
      SELECT vkorg kunnr vbeln netwr waerk
          UP TO p_max ROWS
        INTO TABLE gt_vbak
        FROM vbak
       WHERE kunnr IN s_kunnr
         AND vbeln IN s_vbeln
         AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA
         Form  f_display_data
    FORM f_display_data.
      TYPE-POOLS: slis.                    " ALV Global types
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = 'VBAK'.
        ls_fieldcat-do_sum      = &2.
        ls_fieldcat-cfieldname  = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        ls_sort-subtot    = &2.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_layout   TYPE slis_layout_alv.
      m_fieldcat 'VKORG' ''  ''.
      m_fieldcat 'KUNNR' ''  ''.
      m_fieldcat 'VBELN' ''  ''.
      m_fieldcat 'NETWR' 'X' 'WAERK'.
      m_fieldcat 'WAERK' ''  ''.
      m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
      m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
      m_sort 'VBELN' ''.                   " Sort by vbeln
      ls_layout-cell_merge = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = gt_vbak.
    ENDFORM.                  
    Check out these sample programs
    BCALV_GRID_01
    This program illustrates how the events for print processing PRINT_TOP_OF_PAGE,
    PRINT_END_OF_PAGE, PRINT_TOP_OF_LIST,PRINT_END_OF_LIST are handled. The
    corresponding handler methods control the appearance of the list printed.
    BCALV_GRID_02
    Show a detail list in an amodal window. There is no second dynro needed in contrast to
    BCALV_GRID_03.
    BCALV_GRID_03
    This program implements a function on event DOUBLE_CLICK. According to the selected line data
    from table SBOOK is selected and displayed by a second ALV Control in a dialog dynpro.
    BCALV_GRID_04
    Illustrates the use of exceptions (lights or leds). According to the values of SFLIGHT-SEATSOCC, the
    lights are set to 1 (red), 2 (yellow) or 3 (green).
    BCALV_GRID_05
    Demonstrate the creation of an own toolbar button.
    BCALV_GRID_06
    Demonstrate the creation of an own context menu.
    BCALV_GRID_07
    Append a menu button to the standard toolbar.
    BCALV_GRID_08
    Append a menu with default button to the standard toolbar. It is exactly the same as
    BCALVC_TB_WITH_MENU except for methods HANDLE_MENU_BUTTON and HANDLE_TOOLBAR.
    Editable ALV grids
    BCALV_EDIT_01
    This report illustrates the simplest case of using an editable/noneditable ALV Grid Control.
    BCALV_EDIT_02
    This report illustrates how to set chosen cells of an ALV Grid Control editable.
    BCALV_EDIT_03
    In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.
    The report checks the input value(s) semantically and provides protocol messages in case of error
    BCALV_EDIT_04
    This report illustrates how to add and remove lines to a table using the ALV Grid Control and how to
    implement the saving of the new data.
    BCALV_EDIT_05
    This example shows how to use checkboxes within an ALV Grid Control. You learn:
    (1) how to define a column for editable checkboxes for an attribute of your list
    (2) how to evaluate the checked checkboxes
    (3) how to switch between editable and non-editable checkboxes
    BCALV_EDIT_06
    This example shows how to define a dropdown listbox for all cells of one column in an editable ALV
    Grid Control.
    BCALV_EDIT_07
    This example shows how to define dropdown listboxes for particular cells of your output table.
    BCALV_EDIT_08
    This report implements an ALV Grid Control with an application specific F4 help. The following aspects
    are dealt with:
    (1) how to replace the standard f4 help
    (2) how to pass the selected value to the ALV Grid Control
    (3) how to build an f4 help, whose value range depend on a value of another cell.
    Check this link tooo
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/07/23/oopsALVin+ABAP&showComments=true
    The ALV Grid Control is a tool with which you can output non-hierarchical lists in a
    standardized format. The list data is displayed as a table on the screen.
    The ALV Grid Control offers a range of interactive standard list functions that users need
    frequently (find, sort, filter, calculate totals and subtotals, print, print preview, send list,
    export list (in different formats), and so on. These functions are implemented in the
    proxy object class. You as the programmer have the possibility to turn off functions not
    needed. In most cases the implementations of the standard functions provided by the
    control are sufficient. However, if required, you can adjust these implementations to
    meet application-specific needs.
    You can add self-defined functions to the toolbar, if necessary.
    The ALV Grid Control allows users to adjust the layout of lists to meet their individual
    requirements (for example, they can swap columns, hide columns, set filters for the
    data to be displayed, calculate totals, and so on). The settings (list customizing) made
    by a specific user are called a display variant. Display variants can be saved on a userspecific
    or on a global basis. If such display variants exist for a list, they can be offered
    to the user for selection. If a display variant is set as the default variant, the associated
    list is always displayed based on the settings of this variant.
    2. REUSE_ALV_LIST_DISPLAY
    REUSE_ALV_GRID_DISPLAY
    REUSE_ALV_FIELDCATALOG_MERGE
    REUSE_ALV_COMMENTARY_WRITE
    3. Use of Field Catalog is to determines the technical properties & add formating information of the column.
    6. all the definition of internal table, structure, constants are declared in a type-pool called SLIS.
    7.fieldcat-fieldname
    fieldcat-ref_fieldname
    fieldcat-tabname
    fieldcat-seltext_m
    5. Form user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield.
    Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.
    In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.
    The report output can contain up to 90 columns in the display with the wide array of display options.
    The commonly used ALV functions used for this purpose are;
    1. REUSE_ALV_VARIANT_DEFAULT_GET
    2. REUSE_ALV_VARIANT_F4
    3. REUSE_ALV_VARIANT_EXISTENCE
    4. REUSE_ALV_EVENTS_GET
    5. REUSE_ALV_COMMENTARY_WRITE
    6. REUSE_ALV_FIELDCATALOG_MERGE
    7. REUSE_ALV_LIST_DISPLAY
    8. REUSE_ALV_GRID_DISPLAY
    9. REUSE_ALV_POPUP_TO_SELECT
    Purpose of the above Functions are differ not all the functions are required in all the ALV Report.
    But either no.7 or No.8 is there in the Program.
    How you call this function in your report?
    After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.
    Then use follwing function module.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = 'Prog.name'
    I_STRUCTURE_NAME = 'I_ITAB'
    I_DEFAULT = 'X'
    I_SAVE = 'A'
    TABLES
    T_OUTTAB = I_ITAB.
    IF SY-SUBRC <> 0.
    WRITE: 'SY-SUBRC: ', SY-SUBRC .
    ENDIF.
    ENDFORM. " GET_FINAL_DATA
    The object F_IT_ALV has a field, the activity ACTVT, which can
    contain four permitted values: 01, 02, 03 and 70. Each of the
    activities 01, 02 and 70 controls the availability of particular
    functions (in the menu and the toolbar) of the ALV line item list:
    a) 01: "Settings -> Display variant -> Save..."
    b) 02: "Settings -> Display variant -> Current..." and
    "Settings -> Display variant -> Current header rows "
    c) 70: "Settings -> Display variant -> Administration..."
    Activity 03 corresponds to the minimum authorization, which is the
    most restricted one: The user can only select layouts which have
    been configured already. In particular, all of the other functions
    named above are inactive with activity 03.
    Now if you want to permit a user to change the column selection and
    the headers as well as to save the layout thus created, for example,
    but if you do not want to permit the user to administrate the
    layouts, you grant him or her the authorization for activities 01
    and 02.
    Check this link it will be mosty usefull for u
    http://www.sap-img.com/fu017.htm
    check this link
    http://abapprogramming.blogspot.com/
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5dc3e690-0201-0010-1ebf-b85b3bed962d
    Changing width of a custom container dynamically
    Display Page numbers in ALV
    Insert picture in selection screen.
    Logo in OO ALV Grid
    check these links
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    Try these links
    Simple ALV report
    http://www.sapgenie.com/abap/controls/alvgrid.htm
    http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
    ALV
    1. Please give me general info on ALV.
    http://www.sapfans.com/forums/viewtopic.php?t=58286
    http://www.sapfans.com/forums/viewtopic.php?t=76490
    http://www.sapfans.com/forums/viewtopic.php?t=20591
    http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
    2. How do I program double click in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=11601
    http://www.sapfans.com/forums/viewtopic.php?t=23010
    3. How do I add subtotals (I have problem to add them)...
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    4. How to add list heading like top-of-page in ABAP lists?
    http://www.sapfans.com/forums/viewtopic.php?t=58775
    http://www.sapfans.com/forums/viewtopic.php?t=60550
    http://www.sapfans.com/forums/viewtopic.php?t=16629
    5. How to print page number / total number of pages X/XX in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
    6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
    http://www.sapfans.com/forums/viewtopic.php?t=64320
    http://www.sapfans.com/forums/viewtopic.php?t=44477
    7. How can I set the cell color in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=52107
    8. How do I print a logo/graphics in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=81149
    http://www.sapfans.com/forums/viewtopic.php?t=35498
    http://www.sapfans.com/forums/viewtopic.php?t=5013
    9. How do I create and use input-enabled fields in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=84933
    http://www.sapfans.com/forums/viewtopic.php?t=69878
    10. How can I use ALV for reports that are going to be run in background?
    http://www.sapfans.com/forums/viewtopic.php?t=83243
    http://www.sapfans.com/forums/viewtopic.php?t=19224
    11. How can I display an icon in ALV? (Common requirement is traffic light icon).
    http://www.sapfans.com/forums/viewtopic.php?t=79424
    http://www.sapfans.com/forums/viewtopic.php?t=24512
    12. How can I display a checkbox in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=88376
    http://www.sapfans.com/forums/viewtopic.php?t=40968
    http://www.sapfans.com/forums/viewtopic.php?t=6919
    For More alv report examples check these Tcodes LIBS, BIBS Here u can find more number of examples on alv reports of different kinds
    check this sample code for intercative alv report
    TYPE-POOLS: SLIS.
    *type declaration for values from ekko
    TYPES: BEGIN OF I_EKKO,
           EBELN LIKE EKKO-EBELN,
           AEDAT LIKE EKKO-AEDAT,
           BUKRS LIKE EKKO-BUKRS,
           BSART LIKE EKKO-BSART,
           LIFNR LIKE EKKO-LIFNR,
           END OF I_EKKO.
    DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,
          WA_EKKO TYPE I_EKKO.
    *type declaration for values from ekpo
    TYPES: BEGIN OF I_EKPO,
           EBELN LIKE EKPO-EBELN,
           EBELP LIKE EKPO-EBELP,
           MATNR LIKE EKPO-MATNR,
           MENGE LIKE EKPO-MENGE,
           MEINS LIKE EKPO-MEINS,
           NETPR LIKE EKPO-NETPR,
           END OF I_EKPO.
    DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,
          WA_EKPO TYPE I_EKPO .
    *variable for Report ID
    DATA: V_REPID LIKE SY-REPID .
    *declaration for fieldcatalog
    DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.
    declaration for events table where user comand or set PF status will
    be defined
    DATA: V_EVENTS TYPE SLIS_T_EVENT,
          WA_EVENT TYPE SLIS_ALV_EVENT.
    declartion for layout
    DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
    declaration for variant(type of display we want)
    DATA: I_VARIANT TYPE DISVARIANT,
          I_VARIANT1 TYPE DISVARIANT,
          I_SAVE(1) TYPE C.
    *PARAMETERS : p_var TYPE disvariant-variant.
    *Title displayed when the alv list is displayed
    DATA:  I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
    DATA:  I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.
    INITIALIZATION.
      V_REPID = SY-REPID.
      PERFORM BUILD_FIELDCATLOG.
      PERFORM EVENT_CALL.
      PERFORM POPULATE_EVENT.
    START-OF-SELECTION.
      PERFORM DATA_RETRIEVAL.
      PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
      PERFORM DISPLAY_ALV_REPORT.
    *&      Form  BUILD_FIELDCATLOG
          Fieldcatalog has all the field details from ekko
    FORM BUILD_FIELDCATLOG.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'EBELN'.
      WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'AEDAT'.
      WA_FIELDCAT-SELTEXT_M = 'DATE.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'BUKRS'.
      WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'BUKRS'.
      WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'IT_EKKO'.
      WA_FIELDCAT-FIELDNAME = 'LIFNR'.
      WA_FIELDCAT-NO_OUT    = 'X'.
      WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCATLOG
    *&      Form  EVENT_CALL
      we get all events - TOP OF PAGE or USER COMMAND in table v_events
    FORM EVENT_CALL.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
       IMPORTING
         ET_EVENTS             = V_EVENTS
    EXCEPTIONS
       LIST_TYPE_WRONG       = 1
       OTHERS                = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "EVENT_CALL
    *&      Form  POPULATE_EVENT
         Events populated for TOP OF PAGE & USER COMAND
    FORM POPULATE_EVENT.
      READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'TOP_OF_PAGE'.
        MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-FORM.
      ENDIF.
      READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'USER_COMMAND'.
        MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
    WA_EVENT-NAME.
      ENDIF.
    ENDFORM.                    "POPULATE_EVENT
    *&      Form  data_retrieval
      retreiving values from the database table ekko
    FORM DATA_RETRIEVAL.
      SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.
    ENDFORM.                    "data_retrieval
    *&      Form  bUild_listheader
          text
         -->I_LISTHEADEtext
    FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
      DATA HLINE TYPE SLIS_LISTHEADER.
      HLINE-INFO = 'this is my first alv pgm'.
      HLINE-TYP = 'H'.
    ENDFORM.                    "build_listheader
    *&      Form  display_alv_report
          text
    FORM DISPLAY_ALV_REPORT.
      V_REPID = SY-REPID.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM                = V_REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
         I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
         I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
         I_GRID_TITLE                      = I_TITLE_EKKO
      I_GRID_SETTINGS                   =
      IS_LAYOUT                         = ALV_LAYOUT
         IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
        i_default                         = 'ZLAY1'
         I_SAVE                            = 'A'
        is_variant                        = i_variant
         IT_EVENTS                         = V_EVENTS
        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  TOP_OF_PAGE
          text
    FORM TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY       = IT_LISTHEADER
       i_logo                   =
       I_END_OF_LIST_GRID       =
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  USER_COMMAND
          text
         -->R_UCOMM    text
         -->,          text
         -->RS_SLEFIELDtext
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
      CASE R_UCOMM.
        WHEN '&IC1'.
          READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
          PERFORM BUILD_FIELDCATLOG_EKPO.
          PERFORM EVENT_CALL_EKPO.
          PERFORM POPULATE_EVENT_EKPO.
          PERFORM DATA_RETRIEVAL_EKPO.
          PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
          PERFORM DISPLAY_ALV_EKPO.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  BUILD_FIELDCATLOG_EKPO
          text
    FORM BUILD_FIELDCATLOG_EKPO.
      WA_FIELDCAT-TABNAME = 'IT_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'EBELN'.
      WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'IT_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'EBELP'.
      WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MATNR'.
      WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MENGE'.
      WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'MEINS'.
      WA_FIELDCAT-SELTEXT_M = 'UOM'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    WA_FIELDCAT-TABNAME = 'I_EKPO'.
      WA_FIELDCAT-FIELDNAME = 'NETPR'.
      WA_FIELDCAT-SELTEXT_M = 'PRICE'.
      APPEND WA_FIELDCAT TO I_FIELDCAT.
      CLEAR WA_FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCATLOG_EKPO
    *&      Form  event_call_ekpo
      we get all events - TOP OF PAGE or USER COMMAND in table v_events
    FORM EVENT_CALL_EKPO.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
       IMPORTING
         ET_EVENTS             = V_EVENTS
    EXCEPTIONS
      LIST_TYPE_WRONG       = 1
      OTHERS                = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH

  • ALV with classes for selected fields

    Hi ALL,
            Please can anybody will give the example code for
    <b>ALV with classes for selected fields</b> from database table .

    Hi,
    *& Report  YR_TANS_ALVTEST                                             *
    REPORT  yr_tans_alvtest                         .
    INCLUDE ya_yr_tans_alvtest_top.
    TABLES yttans_test.
    DATA itab LIKE yttans_test OCCURS 0.
    DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
    DATA gc_custom_control_name TYPE scrfname.
    gc_custom_control_name = 'CC_ALV'.
    DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .
    DATA gt_fieldcat TYPE lvc_t_fcat .
    DATA gs_layout TYPE lvc_s_layo .
    data wa_itab like line of itab.
    TYPES : BEGIN OF ty_help,
              roll_no LIKE yttans_test-roll_no,
              name LIKE yttans_test-name,
            END OF ty_help.
    DATA: git_returntab TYPE TABLE OF ddshretval INITIAL SIZE 0.
          CLASS lcl_event_handler DEFINITION
    CLASS lcl_event_handler DEFINITION .
      PUBLIC SECTION .
        METHODS:
    handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING
        e_row e_column es_row_no.
      PRIVATE SECTION.
    ENDCLASS.                    "lcl_event_handler DEFINITION
    DATA gr_event_handler TYPE REF TO lcl_event_handler .
    *&      Form  handle_double_click
          text
         -->I_ROW      text
         -->I_COLUMN   text
         -->IS_ROW_NO  text
    FORM handle_double_click USING i_row TYPE lvc_s_row i_column TYPE
    lvc_s_col is_row_no TYPE lvc_s_roid.
    leave to list-processing.
    read table itab index is_row_no-row_id into wa_itab.
    write:/ 'Roll no: ', wa_itab-roll_no, /'Name: ', wa_itab-name,
    /'Marks: ', wa_itab-marks.
    LEAVE SCREEN.
    ENDFORM .                    "handle_double_click
          CLASS lcl_event_handler IMPLEMENTATION
    CLASS lcl_event_handler IMPLEMENTATION .
    *--Handle Double Click
      METHOD handle_double_click .
        PERFORM handle_double_click USING e_row e_column es_row_no .
      ENDMETHOD .                    "lcl_event_handler
    ENDCLASS .                    "lcl_event_handler IMPLEMENTATION
    SELECT-OPTIONS roll FOR yttans_test-roll_no .
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR roll-low.
      DATA: lit_help TYPE TABLE OF ty_help.
      DATA: wa_returntab LIKE LINE OF git_returntab.
      SELECT roll_no name INTO TABLE lit_help FROM yttans_test.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          retfield        = 'ROLL_NO'
          dynpprog        = sy-repid
          dynpnr          = sy-dynnr
          dynprofield     = 'roll-low'
          value_org       = 'S'
        TABLES
          value_tab       = lit_help
          return_tab      = git_returntab
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 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.
      READ TABLE git_returntab INTO wa_returntab INDEX 1.
      roll-low = wa_returntab-fieldval.
    AT SELECTION-SCREEN.
      SELECT * FROM yttans_test INTO TABLE itab WHERE roll_no IN roll.
    START-OF-SELECTION.
      CREATE OBJECT gr_event_handler .
      CALL SCREEN '9000'.
    *&      Module  STATUS_9000  OUTPUT
          text
    MODULE status_9000 OUTPUT.
      SET PF-STATUS 'STATUS_9000'.
      SET TITLEBAR 'TITLE_9000'.
    ENDMODULE.                 " STATUS_9000  OUTPUT
    *&      Module  USER_COMMAND_9000  INPUT
          text
    MODULE user_command_9000 INPUT.
      DATA: ok_code TYPE sy-ucomm,
            save_ok TYPE sy-ucomm.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'BACK' OR '%EX' OR 'RW'.
          CALL METHOD gr_ccontainer->free.
         CALL METHOD cl_gui_cfw=>flush.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPUT
    *&      Module  alv_display_9000  OUTPUT
          text
    MODULE alv_display_9000 OUTPUT.
      PERFORM display_alv .
    ENDMODULE.                 " alv_display_9000  OUTPUT
    *&      Form  display_alv
          text
    FORM display_alv .
      IF gr_alvgrid IS INITIAL .
        CREATE OBJECT gr_ccontainer
          EXPORTING
       PARENT                      =
            container_name              = gc_custom_control_name
       STYLE                       =
       LIFETIME                    = lifetime_default
       REPID                       =
       DYNNR                       =
       NO_AUTODEF_PROGID_DYNNR     =
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5
            OTHERS                      = 6
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        CREATE OBJECT gr_alvgrid
          EXPORTING
       I_SHELLSTYLE      = 0
       I_LIFETIME        =
            i_parent          = gr_ccontainer
       I_APPL_EVENTS     = space
       I_PARENTDBG       =
       I_APPLOGPARENT    =
       I_GRAPHICSPARENT  =
       I_NAME            =
          EXCEPTIONS
            error_cntl_create = 1
            error_cntl_init   = 2
            error_cntl_link   = 3
            error_dp_create   = 4
            OTHERS            = 5
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .
        PERFORM prepare_field_catalog CHANGING gt_fieldcat .
        PERFORM prepare_layout CHANGING gs_layout .
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
       I_BUFFER_ACTIVE               =
       I_BYPASSING_BUFFER            =
       I_CONSISTENCY_CHECK           =
       I_STRUCTURE_NAME              =
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = 'X'
             is_layout                     = gs_layout
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING          =
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
       IT_EXCEPT_QINFO               =
          CHANGING
            it_outtab                     = itab[]
            it_fieldcatalog               = gt_fieldcat
       IT_SORT                       =
       IT_FILTER                     =
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4
        IF sy-subrc <> 0.
          LEAVE TO LIST-PROCESSING.
          WRITE 'error'.
        ENDIF.
      ELSE.
        CALL METHOD gr_alvgrid->refresh_table_display
    EXPORTING
       IS_STABLE      =
       I_SOFT_REFRESH =
          EXCEPTIONS
            finished       = 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.
      ENDIF.
    ENDFORM.                    "display_alv
    *&      Form  prepare_field_catalog
          text
         <--P_GT_FIELDCAT  text
    FORM prepare_field_catalog  CHANGING p_gt_fieldcat TYPE lvc_t_fcat .
      DATA ls_fcat TYPE lvc_s_fcat .
      ls_fcat-fieldname = 'ROLL_NO'.
      ls_fcat-coltext = 'ROLL No.'.
      APPEND ls_fcat TO p_gt_fieldcat.
      ls_fcat-fieldname = 'NAME'.
      ls_fcat-coltext = 'NAME'.
      APPEND ls_fcat TO p_gt_fieldcat.
      ls_fcat-fieldname = 'MARKS'.
      ls_fcat-coltext = 'MARKS'.
      APPEND ls_fcat TO p_gt_fieldcat.
    ENDFORM.                    " prepare_field_catalog
    *&      Form  prepare_layout
          text
         <--P_GS_LAYOUT  text
    FORM prepare_layout  CHANGING ps_layout TYPE lvc_s_layo.
      ps_layout-zebra = 'X' .
      ps_layout-grid_title = 'Students Details'.
      ps_layout-smalltitle = 'X' .
    ENDFORM.                    " prepare_layout
    Regards,
    Tanveer.
    Mark helpful answers
    Message was edited by: Tanveer Shaikh

  • ALV With Page No.

    Please give the Code(If Possible with Example) which is useful to disply the page no in ALV Report.
    Thanks
    Prashanth.

    Hi,
    The following function is called from top of page
    FORM TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    I_LOGO = 'ENJOYSAP_LOGO'
    IT_LIST_COMMENTARY = SD_HEADING.
    ENDFORM. "TOP_OF_PAGE
    Pageno has been appended to the table sd_heading passed in the above function call.
    Pls chk this out and reward points if useful.
    Regards,
    Aswin

  • Editable ALV with SAVE option

    Hi experts,
    Could you plz provede me an example for an EDITABLE ALV with the SAVE option. i.e. i could edit the ALV output and after the changes i should save the changes i made by clicking SAVE button.
    Thanks in advance
    Regards,
    Ram

    hi,
    check the sample code
    REPORT ZLAXMI_REPORT6 NO STANDARD PAGE HEADING
    MESSAGE-ID ZZ
    LINE-SIZE 132
    LINE-COUNT 65 .
    TABLES: MARA.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF T_MARA,
    MATNR TYPE MARA-MATNR, "Material Number
    ERSDA TYPE MARA-ERSDA, "Creation date
    BRGEW TYPE MARA-BRGEW, "Gross weight
    NTGEW TYPE MARA-NTGEW, "Net weight
    MTART TYPE MARA-MTART, "Material type
    MBRSH TYPE MARA-MBRSH, "Industry Sector
    REC_SEL TYPE C , "checkbox
    END OF T_MARA.
    V A R I A B L E S
    DATA: V_REPID LIKE SY-REPID,
    V_FLAG(1) TYPE C.
    CONSTANTS :
    C_X(1) TYPE C VALUE 'X',
    C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS',
    C_FC_DELETE(6) TYPE C VALUE 'DELETE',
    C_FC_MODIFY(6) TYPE C VALUE 'MODIFY',
    C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'F_USER_COMMAND',
    C_USER_COMMAND_MODIFY TYPE SLIS_FORMNAME
    VALUE 'F_USER_COMMAND_MODIFY',
    C_ICON_DELETE TYPE ICON-NAME VALUE 'ICON_DELETE', " Icon,Delete'
    C_ICON_CANCEL TYPE ICON-NAME VALUE 'ICON_CANCEL', " Icon,Cancel'
    C_FC_SAVE(4) TYPE C VALUE 'SAVE'.
    *internal table declarations.
    DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
    IT_MODIFY TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
    IT_TEMP TYPE STANDARD TABLE OF MARA WITH HEADER LINE,
    *-ALV Internal Tables.
    *--Field Catalog
    IT_FIELDCAT TYPE STANDARD TABLE OF
    SLIS_FIELDCAT_ALV WITH HEADER LINE,
    *--Layout
    WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
    *--Sort
    IT_SORT TYPE SLIS_T_SORTINFO_ALV,
    WA_SORT TYPE SLIS_SORTINFO_ALV ,
    **-Structure for excluding function codes
    WA_EXTAB TYPE SLIS_EXTAB,
    **-To hold function codes to be excluded in ALV toolbar
    IT_EXTAB TYPE SLIS_T_EXTAB.
    *selection screen.
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
    S_ERSDA FOR MARA-ERSDA.
    SELECTION-SCREEN: END OF BLOCK B1.
    *--Radio buttons to select either Display/Delete/Modify
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME
    TITLE TEXT-002.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-003.
    PARAMETERS: P_DISP RADIOBUTTON GROUP RAD1 DEFAULT 'X'.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-005.
    PARAMETERS: P_UPD RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN : BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) TEXT-004.
    PARAMETERS: P_DEL RADIOBUTTON GROUP RAD1.
    SELECTION-SCREEN : END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2 .
    AT SELECTION-SCREEN.
    PERFORM VALIDATE_SCREEN.
    *start of selection
    START-OF-SELECTION.
    *clear the internal tables to be used.
    CLEAR: IT_MARA,IT_MARA[],
    V_FLAG.
    *get the data
    PERFORM GET_DATA.
    *end of selection
    END-OF-SELECTION.
    IF IT_MARA[] IS INITIAL.
    MESSAGE I000 WITH
    'No Records found for the given Selection Criteria'(012).
    ELSE.
    *do alv process
    V_REPID = SY-REPID.
    *--Sort the Output Fields
    PERFORM SORT_FIELDS.
    *--Build Field catalog for the Output fields
    PERFORM BUILD_FIELDCAT.
    *--Set the Layout for ALV
    PERFORM SET_LAYOUT.
    IF P_DISP = C_X.
    *--Exclude any Buttons on the Appn tool bar
    perform change_default_pf_status.
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ELSEIF P_UPD = C_X.
    *--Exclude DELETE Button on the appn tool bar
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ELSEIF P_DEL = C_X.
    *--Exclude MODIFY button on appn tool bar
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDIF.
    *--Exclude SAVE button for all options
    MOVE 'SAVE' TO WA_EXTAB-FCODE. " SAVE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    *--Display ALV output
    PERFORM LIST_DISPLAY TABLES IT_MARA
    USING C_USER_COMMAND.
    ENDIF.
    *& Form get_data
    text
    --> p1 text
    <-- p2 text
    FORM GET_DATA .
    SELECT MATNR
    ERSDA
    BRGEW
    NTGEW
    MTART
    MBRSH
    FROM MARA
    INTO TABLE IT_MARA
    WHERE MATNR IN S_MATNR
    AND ERSDA IN S_ERSDA.
    IF SY-SUBRC <> 0.
    *no records selected leave processing
    STOP.
    ENDIF.
    SORT IT_MARA.
    ENDFORM. " get_data
    *& Form sort_fields
    text
    --> p1 text
    <-- p2 text
    FORM SORT_FIELDS .
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'MATNR'.
    WA_SORT-SPOS = '1'.
    WA_SORT-UP = 'X'.
    APPEND WA_SORT TO IT_SORT.
    CLEAR WA_SORT.
    WA_SORT-FIELDNAME = 'ERSDA'.
    WA_SORT-SPOS = '2'.
    WA_SORT-UP = 'X'.
    APPEND WA_SORT TO IT_SORT.
    ENDFORM. " sort_fields
    *& Form build_fieldcat
    text
    --> p1 text
    <-- p2 text
    FORM BUILD_FIELDCAT .
    IT_FIELDCAT-COL_POS = '1'.
    IT_FIELDCAT-FIELDNAME = 'MATNR'.
    IT_FIELDCAT-KEY = 'X'.
    IT_FIELDCAT-OUTPUTLEN = '15'.
    IT_FIELDCAT-SELTEXT_L = 'Material number'(022).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '2'.
    IT_FIELDCAT-FIELDNAME = 'ERSDA'.
    IT_FIELDCAT-KEY = 'X'.
    IT_FIELDCAT-OUTPUTLEN = '10'.
    IT_FIELDCAT-SELTEXT_L = 'Created on'(023).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '3'.
    IT_FIELDCAT-FIELDNAME = 'BRGEW'.
    IT_FIELDCAT-OUTPUTLEN = '10'.
    IT_FIELDCAT-SELTEXT_L = 'GROSS WEIGHT'(024).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '4'.
    IT_FIELDCAT-FIELDNAME = 'NTGEW'.
    IT_FIELDCAT-OUTPUTLEN = '15'.
    IT_FIELDCAT-SELTEXT_L = 'NET WEIGHT'(025).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '5'.
    IT_FIELDCAT-FIELDNAME = 'MTART'.
    IT_FIELDCAT-OUTPUTLEN = '3'.
    IT_FIELDCAT-SELTEXT_L = 'Material type'(026).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-COL_POS = '6'.
    IT_FIELDCAT-FIELDNAME = 'MBRSH'.
    IT_FIELDCAT-OUTPUTLEN = '25'.
    IT_FIELDCAT-SELTEXT_L = 'Industry sector'(027).
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    IT_FIELDCAT-FIELDNAME = 'REC_SEL'.
    IT_FIELDCAT-NO_OUT = C_X.
    APPEND IT_FIELDCAT.
    CLEAR IT_FIELDCAT.
    ENDFORM. " build_fieldcat
    *& Form list_display
    text
    -->P_IT_MARA text
    -->P_C_USER_COMMAND text
    FORM LIST_DISPLAY TABLES P_IT_MARA
    USING P_USER_COMMAND TYPE SLIS_FORMNAME.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = V_REPID
    I_CALLBACK_PF_STATUS_SET = C_PF_STATUS
    I_CALLBACK_USER_COMMAND = P_USER_COMMAND
    IS_LAYOUT = WA_LAYOUT
    IT_FIELDCAT = IT_FIELDCAT[]
    IT_EXCLUDING = IT_EXTAB[]
    IT_SORT = IT_SORT[]
    TABLES
    T_OUTTAB = P_IT_MARA
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " list_display
    *& Form F_SET_PF_STATUS
    Set PF_STATUS STANDARD modifying the standard toolbar
    by excluding some buttons
    -->P_IT_EXTAB -- TABLE OF EXCLUDING FUNCTIONS
    FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
    CLEAR : WA_EXTAB,
    IT_EXTAB.
    *--Set the Modified PF status for the ALV.
    SET PF-STATUS 'ALV_STATUS_01' EXCLUDING RT_EXTAB.
    ENDFORM. " SET_PF_STATUS
    *& Form f_user_command
    Handle user action on ALV toolbar
    FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    RS_SELFIELD-REFRESH = C_X.
    IF R_UCOMM = C_FC_DELETE.
    *--User Selected DELETE button.
    PERFORM DELETE_SELECTED_RECORDS.
    ELSEIF R_UCOMM = C_FC_MODIFY.
    *--If user selects MODIFY button.
    PERFORM CHANGE_RECORDS.
    ENDIF.
    ENDFORM. "F_USER_COMMAND
    *& Form POP_UP_CONFIRMATION
    text
    <--P_ANSWER text
    FORM POP_UP_CONFIRMATION
    CHANGING P_ANSWER TYPE C.
    DATA:
    L_TITLE(14) TYPE C, " Title of pop-up
    L_TXT_QUESTION(52) TYPE C, " Text displayed in pop-up
    L_DISP_CANCEL TYPE C, " Display 'Cancel' button?
    L_BTN1 TYPE ICON-NAME, " Icon on button 1
    L_BTN2 TYPE ICON-NAME. " Icon on button 2
    L_TITLE = 'Delete'(017). " delete
    L_TXT_QUESTION = 'Are you sure to delete?'(018).
    L_BTN1 = C_ICON_DELETE.
    L_BTN2 = C_ICON_CANCEL.
    **-Display pop-up asking user for confirmation
    CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
    TITLEBAR = L_TITLE
    TEXT_QUESTION = L_TXT_QUESTION
    TEXT_BUTTON_1 = 'Yes'
    ICON_BUTTON_1 = L_BTN1
    TEXT_BUTTON_2 = 'No'
    ICON_BUTTON_2 = L_BTN2
    DEFAULT_BUTTON = '2'
    DISPLAY_CANCEL_BUTTON = 'X'
    IMPORTING
    ANSWER = P_ANSWER
    EXCEPTIONS
    TEXT_NOT_FOUND = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE E000 WITH 'Error executing function module:'(019)
    'POPUP_TO_CONFIRM'.
    ENDIF.
    ENDFORM. "pop_up_confirmation
    *& Form set_layout
    text
    --> p1 text
    <-- p2 text
    FORM SET_LAYOUT .
    IF P_DEL = C_X OR P_UPD = C_X.
    *--Allow Input only if user choose 'UPDATE'/ 'DELETE' radio buttons
    WA_LAYOUT-BOX_FIELDNAME = 'REC_SEL'.
    WA_LAYOUT-BOX_TABNAME = 'IT_MARA'.
    ENDIF.
    *--Display Header based on the user selection
    IF P_DISP = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Display '(036).
    ELSEIF P_DEL = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Delete '(037).
    ELSEIF P_UPD = C_X.
    WA_LAYOUT-WINDOW_TITLEBAR =
    'Change '(038).
    ENDIF.
    ENDFORM. " set_layout
    *& Form change_default_pf_status
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_DEFAULT_PF_STATUS .
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM. " change_default_pf_status
    *& Form f_user_command
    Handle user action on ALV toolbar
    FORM F_USER_COMMAND_MODIFY USING R_UCOMM LIKE SY-UCOMM "#EC *
    RS_SELFIELD TYPE SLIS_SELFIELD.
    DATA : L_ANSWER TYPE C. "#EC *
    IF R_UCOMM = C_FC_SAVE.
    *user selected save button
    READ TABLE IT_MODIFY WITH KEY REC_SEL = 'X'.
    *check if user selected atleast one line.
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
    EXIT.
    ENDIF.
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    *--Check the entered values are valid or not.
    IF NOT ( it_modify-status = 'A' OR
    it_modify-status = 'C' OR
    it_modify-status = 'E' ).
    *--User Entered invalid value for STATUS field,so Display Error Msg
    CLEAR R_UCOMM.
    MESSAGE e000 WITH 'Invalid value '''(031)
    '' for Status in the Record # '(032)
    sy-tabix.
    ENDIF.
    ENDLOOP.
    CLEAR: IT_TEMP,
    IT_TEMP[].
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    MOVE-CORRESPONDING IT_MODIFY TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    *--start new code
    DATA : IT_TEMP2 LIKE STANDARD TABLE OF MARA WITH HEADER LINE.
    SELECT * FROM MARA
    INTO TABLE IT_TEMP2
    FOR ALL ENTRIES IN IT_TEMP
    WHERE MATNR = IT_TEMP-MATNR.
    IF SY-SUBRC = 0.
    LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.
    READ TABLE IT_TEMP2 WITH KEY MATNR = IT_MODIFY-MATNR.
    IF SY-SUBRC = 0.
    IT_TEMP2-NTGEW = IT_MODIFY-NTGEW.
    IT_TEMP2-BRGEW = IT_MODIFY-BRGEW.
    MODIFY IT_TEMP2 INDEX SY-TABIX.
    ENDIF.
    ENDLOOP.
    ENDIF.
    *modify mara table with the changed values
    MODIFY MARA FROM TABLE IT_TEMP2 .
    *--end new code
    IF SY-SUBRC = 0.
    COMMIT WORK AND WAIT.
    *--Display message with Success in Updating database
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) has been Updated'(020).
    CLEAR :
    IT_MARA,
    IT_MARA[].
    *get-data again from database.
    PERFORM GET_DATA.
    RS_SELFIELD-REFRESH = C_X.
    ELSE.
    *--Error occurred
    MESSAGE I000 WITH 'Error occured in Modifying the database'(021).
    ENDIF.
    ENDIF.
    ENDFORM. "f_user_command_modify
    *& Form validate_screen
    text
    --> p1 text
    <-- p2 text
    FORM VALIDATE_SCREEN .
    DATA : LV_MATNR LIKE MARA-MATNR.
    *--validate product
    IF NOT S_MATNR[] IS INITIAL.
    SELECT MATNR
    INTO MARA-MATNR
    FROM MARA
    WHERE MATNR IN S_MATNR.
    ENDSELECT.
    IF SY-SUBRC <> 0.
    *--Error
    MESSAGE E000 WITH 'Invalid Material'(034).
    ENDIF.
    ENDIF.
    ENDFORM. " validate_screen
    *& Form delete_records
    text
    --> p1 text
    <-- p2 text
    FORM DELETE_RECORDS .
    LOOP AT IT_MARA.
    MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    DELETE MARA FROM TABLE IT_TEMP.
    IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
    COMMIT WORK AND WAIT.
    *--Display Success Message to the user
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) deleted Successfully'(010).
    ELSE.
    *--Error occured in deletion
    MESSAGE I000 WITH 'Error occured in Deleting the Record(s)'(011).
    ENDIF.
    CLEAR: IT_MARA,
    IT_MARA[],
    IT_TEMP,
    IT_TEMP[].
    V_FLAG = C_X.
    STOP.
    ENDFORM. " delete_records
    *& Form delete_selected_records
    text
    --> p1 text
    <-- p2 text
    FORM DELETE_SELECTED_RECORDS .
    DATA : L_ANSWER(1) TYPE C.
    READ TABLE IT_MARA WITH KEY REC_SEL = C_X.
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Delete'(013).
    EXIT.
    ELSE.
    *--Ask for delete confirmation
    PERFORM POP_UP_CONFIRMATION
    CHANGING L_ANSWER.
    IF L_ANSWER = '1'. " 'Yes'
    CLEAR: IT_TEMP,
    IT_TEMP[].
    LOOP AT IT_MARA WHERE REC_SEL = 'X'.
    MOVE-CORRESPONDING IT_MARA TO IT_TEMP.
    APPEND IT_TEMP.
    CLEAR IT_TEMP.
    ENDLOOP.
    DELETE MARA FROM TABLE IT_TEMP.
    IF SY-SUBRC = 0.
    *--Successfully selected records Deleted.
    COMMIT WORK AND WAIT.
    *--Display completed work information to the user
    MESSAGE I000 WITH SY-DBCNT
    ' Record(s) deleted Successfully'(014).
    *--Clear the Internal tables
    CLEAR: IT_MARA,
    IT_MARA[].
    *--Reselects entries from Database again & display in ALV
    PERFORM GET_DATA.
    ELSE.
    *--Error occured
    MESSAGE I000 WITH
    'Error occured in Deleting the Record(s)'(015).
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " delete_selected_records
    *& Form change_records
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_RECORDS .
    READ TABLE IT_MARA WITH KEY REC_SEL = 'X'.
    *--check user selected at least 1 record to MODIFY or not
    IF SY-SUBRC <> 0.
    MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).
    EXIT.
    ELSE.
    CLEAR : IT_MODIFY,
    IT_MODIFY[].
    LOOP AT IT_MARA WHERE REC_SEL = 'X'.
    IT_MODIFY = IT_MARA.
    APPEND IT_MODIFY.
    CLEAR IT_MODIFY.
    ENDLOOP.
    *--Change PF status for this new ALV list.
    PERFORM CHANGE_PF_STATUS_AGAIN.
    *--Change Field Catalog to make INPUT enabled.
    READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'NTGEW'.
    IT_FIELDCAT-INPUT = C_X.
    MODIFY IT_FIELDCAT INDEX SY-TABIX.
    *--Call ALV LIST DISPLAY with this new values.
    PERFORM LIST_DISPLAY TABLES IT_MODIFY
    USING C_USER_COMMAND_MODIFY.
    ENDIF.
    ENDFORM. " change_records
    *& Form change_pf_status_again
    text
    --> p1 text
    <-- p2 text
    FORM CHANGE_PF_STATUS_AGAIN .
    MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV
    APPEND WA_EXTAB TO IT_EXTAB.
    ENDFORM. " change_pf_status_again

  • Editable ALV with dynamically growing columns

    Hi Gurus,
    I have one Parameter table and another data (transaction) table
    When I fetch the data from data table I have put a when condition to one of date field in data table with between sy-datum and sy-datum + need to run days in parameter table
    Its working properly
    So my requirement is …. &#61516;
    There are three key fields (fixed) and
    when the parameter value = 4 ALV columns must be 7
    when the parameter value = 6 ALV columns must be 9
    like that.
    So I want to know how can I do this?
    My second question is when the ALV displaying, user need to change there value in ALV list, so therefore ALV should be editable.
    Please help me o solve these problems.

    below  is the program  to  make   an  parameter  as  Editable in the ALV Grid  .  example <b> Net price</b>  .
    see the field catalog   statement  for    netprice   * edit  parameter for  that  field .
    *& Report  ZDEMO_ALVGRID_EDIT                                          *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic ALV grid, Enhanced to display specific fields as          *
    *& editable depending on field value                                   *
    REPORT  ZDEMO_ALVGRID_EDIT                 .
    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,
      field_style  TYPE lvc_t_styl, "FOR DISABLE
    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.
    DATA: it_fieldcat TYPE lvc_t_fcat,     "slis_t_fieldcat_alv WITH HEADER LINE,
          wa_fieldcat TYPE lvc_s_fcat,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE lvc_s_layo,     "slis_layout_alv,
          gd_repid     LIKE sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM set_specific_field_attributes.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      wa_fieldcat-fieldname   = 'EBELN'.
      wa_fieldcat-scrtext_m   = 'Purchase Order'.
      wa_fieldcat-col_pos     = 0.
      wa_fieldcat-outputlen   = 10.
      wa_fieldcat-emphasize   = 'X'.
      wa_fieldcat-key         = 'X'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'EBELP'.
      wa_fieldcat-scrtext_m   = 'PO Item'.
      wa_fieldcat-col_pos     = 1.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'STATU'.
      wa_fieldcat-scrtext_m   = 'Status'.
      wa_fieldcat-col_pos     = 2.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'AEDAT'.
      wa_fieldcat-scrtext_m   = 'Item change date'.
      wa_fieldcat-col_pos     = 3.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MATNR'.
      wa_fieldcat-scrtext_m   = 'Material Number'.
      wa_fieldcat-col_pos     = 4.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MENGE'.
      wa_fieldcat-scrtext_m   = 'PO quantity'.
      wa_fieldcat-col_pos     = 5.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'MEINS'.
      wa_fieldcat-scrtext_m   = 'Order Unit'.
      wa_fieldcat-col_pos     = 6.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'NETPR'.
    wa_fieldcat-scrtext_m   = 'Net Price'.
      <b>wa_fieldcat-edit        = 'X'. "sets whole column to be editable</b>
      wa_fieldcat-col_pos     = 7.
      wa_fieldcat-outputlen   = 15.
      wa_fieldcat-datatype     = 'CURR'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
      wa_fieldcat-fieldname   = 'PEINH'.
      wa_fieldcat-scrtext_m   = 'Price Unit'.
      wa_fieldcat-col_pos     = 8.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR  wa_fieldcat.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    FORM build_layout.
    * Set layout field for field attributes(i.e. input/output)
      gd_layout-stylefname = 'FIELD_STYLE'.
      gd_layout-zebra             = 'X'.
    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'
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
           EXPORTING
                i_callback_program      = gd_repid
    *            i_callback_user_command = 'USER_COMMAND'
                is_layout_lvc               = gd_layout
                it_fieldcat_lvc             = it_fieldcat
                i_save                  = 'X'
           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  CORRESPONDING FIELDS OF TABLE it_ekko.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  set_specific_field_attributes
    *       populate FIELD_STYLE table with specific field attributes
    form set_specific_field_attributes .
      DATA ls_stylerow TYPE lvc_s_styl .
      DATA lt_styletab TYPE lvc_t_styl .
    * Populate style variable (FIELD_STYLE) with style properties
    * The NETPR field/column has been set to editable in the fieldcatalog...
    * The following code sets it to be disabled(display only) if 'NETPR'
    * is gt than 10.
      LOOP AT it_ekko INTO wa_ekko.
        IF wa_ekko-netpr GT 10.
          ls_stylerow-fieldname = 'NETPR' .
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
                                                 "set field to disabled
          APPEND ls_stylerow  TO wa_ekko-field_style.
          MODIFY it_ekko FROM wa_ekko.
        ENDIF.
      ENDLOOP.
    endform.           
    reward  points if it is usefull ....
    Girish

  • How to trigger New page while using ALV with classes/oops?

    Hi All
    I am trying to print a report which has to show the data in two pages.
    I am using ALV with classes/oops.
    Though I am able to print the report but a new page is not coming. Whole of the data is coming in one single page.
    Please tell me as to how to trigger a NEW PAGE while using ALV with classes/oops.
    Please send some code samples also if available.
    Thanks in advance.
    Jerry

    using sort option you can do it. in case of grid/oo alv class ALV you can view that only in print mode/preview mode.
    in case of list you can view that directly.
    sort-fieldname = 'FIELDNAME'.
    sort-group = '*'  "triggers new page
    sort-up = 'X'.
    append sort to it_sort.

Maybe you are looking for

  • General Error While Making a Call-N900

    I cant make calls when I cange the sim. Every time I try it says General Error. Now I have to change my number, and I cant because of the Phone problem(General Error). with changed sim card I can send text and receive calls but cant make any. please

  • Excise values are not updating in billing

    hi all, In RG23D register BED, AED, ECS values are showing correctly, but in order (VA02) or in billing (VF01) excise values are not showing. So, what could be the reason and what need to be checked? thanks.

  • Adobe AIR not playing sound from swf, but Flex-app in browser does. Why?

    Hi Why won't Adobe AIR play the sound in an swf animation I've got? It plays perfectly as an Flex Application in a browser. This works good (Animation is shown and sound is played): <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="htt

  • Any trick to custom Captions?

    Hi - I created five files "Comitblack1.bmp . . . Comitblack5.bmp" and saved them in the Gallery\Captions folder.   I created these files in Fireworks and they consist of a black background with a black rectangle at 100%.  The size is 100 x 50 pixels

  • Group by colum wise data in adobe form

    Hi,   I have a requirement to print data in adobe form thru webdynpro for abap. example; i have a table data getting from webdynpro like below. date               empno   activity. 11-11-2008     p101       x1. 11-11-2008     p101       x2. 11-11-200