ALV  program

i have written a code below. i am facing problem in the select statement.
i want to all the data of it_vbap and it_vbep to be transferred to it_final, this code is giving some error.
kindly help. the main problem im facing in linking the fields of vbap and vbep
REPORT  zdan_demo_alv12.
TYPE-POOLS: slis.
*break hopflabap1.
TYPES: BEGIN OF ty_vbap,
  matnr TYPE vbap-matnr, " material number
  posnr TYPE vbap-posnr, " SO item
  arktx TYPE vbap-arktx, " text for so item
j_3apgnr TYPE vbap-j_3apgnr, " grid number
  zmeng   TYPE vbap-zmeng, " target quantity
  vbeln   TYPE vbap-vbeln, " SO
  END OF ty_vbap.
TYPES : BEGIN OF ty_vbep,
  j_3asize TYPE vbep-j_3asize,
  vbeln1 TYPE vbep-vbeln,
posnr1 TYPE     vbep-posnr,
  END OF ty_vbep.
TYPES : BEGIN OF ty_final,
  matnr TYPE vbap-matnr,
  posnr TYPE vbap-posnr,
  arktx TYPE vbap-arktx,
j_3apgnr TYPE vbap-j_3apgnr,
  zmeng   TYPE vbap-zmeng,
  vbeln   TYPE vbap-vbeln,
j_3asize TYPE vbep-j_3asize,
  vbeln1 TYPE vbep-vbeln,
posnr1 type vbep-posnr,
  END OF ty_final.
DATA : it_vbap TYPE TABLE OF ty_vbap    ,
       wa_vbap type ty_vbap ,
     it_vbep TYPE TABLE OF ty_vbep  ,
     wa_vbep TYPE ty_vbep,
     it_final TYPE TABLE OF ty_final  ,
       wa_final TYPE ty_final.
DATA : it_fclog TYPE slis_t_fieldcat_alv,
     wa_fclog LIKE LINE OF it_fclog,
     gd_layout    TYPE slis_layout_alv,
     gd_print TYPE slis_print_alv,
     gd_repid     LIKE sy-repid,
     gt_events   TYPE slis_t_event..
break hopflabap1.
SELECTION-SCREEN BEGIN OF BLOCK sodisp WITH FRAME TITLE text-001.
PARAMETERS : matnr TYPE vbap-matnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK sodisp.
START-OF-SELECTION.
  PERFORM data_retv.
  PERFORM fclog.
  PERFORM disp_rpt.
*break hopflabap1.
FORM data_retv.
  SELECT matnr posnr arktx j_3apgnr zmeng vbeln
    FROM vbap  INTO wa_vbap WHERE matnr EQ  matnr.
  SELECT  j_3asize
   FROM vbep INTO wa_vbep where  it_vbep-vbeln1 = vbeln.
   loop at it_final INTO wa_final.
READ TABLE it_vbap INTO wa_final WITH KEY matnr = matnr.
READ TABLE it_vbep INTO wa_final WITH KEY posnr = it_vbep-posnr.
COLLECT wa_final INTO it_final.
endloop.
*break hopflabap1.
ENDFORM.                    "data_retv
*&      Form  disp_rpt
      text
FORM disp_rpt.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
            i_callback_program      = gd_repid
           i_callback_user_command  = 'USER_COMMAND'
           is_print              = gd_print
           i_callback_pf_status_set  = 'SET_STATUS'
           i_callback_top_of_page   = 'TOP-OF-PAGE'
            is_layout               = gd_layout
            it_fieldcat             = it_fclog[]
           it_sort                   = it_sort[]
           i_save                  = 'X'
            IT_EVENTS               = GT_EVENTS[]
    TABLES
              t_outtab                = it_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
*&      Form  fclog
      text
FORM fclog.
  wa_fclog-fieldname   = 'MATNR'.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'Material Num'.
  wa_fclog-outputlen   = 15.
  wa_fclog-col_pos     = 2.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = 'POSNR '.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'SO Item'.
  wa_fclog-outputlen   = 15.
  wa_fclog-col_pos     = 3.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = 'ARKTX'.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'Description'.
  wa_fclog-outputlen   = 20.
  wa_fclog-col_pos     = 4.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = 'J_3APGNR'.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'Grid Number'.
  wa_fclog-outputlen   = 20.
  wa_fclog-col_pos     = 5.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = ' ZMENG'.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'Target quantity'.
  wa_fclog-outputlen   = 20.
  wa_fclog-col_pos     = 6.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = ' VBELN'.
  wa_fclog-tabname     = 'IT_VBAP'.
  wa_fclog-seltext_m   = 'SO'.
  wa_fclog-outputlen   = 20.
  wa_fclog-col_pos     = 6.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
  wa_fclog-fieldname   = 'J_3ASIZE'.
  wa_fclog-tabname     = 'IT_VBEP'.
  wa_fclog-seltext_m   = 'Grid Value'.
  wa_fclog-outputlen   = 20.
  wa_fclog-col_pos     = 6.
  APPEND wa_fclog TO it_fclog.
  CLEAR  wa_fclog.
ENDFORM.                    "fclog

you can update the same thread. why are you opening the new thread for the same program.
When you are selecting you also select the common fields, so that you can use these and populate the final table.
change the definitions of the tables accordingly...
SELECT matnr posnr arktx j_3apgnr zmeng vbeln
FROM vbap INTO wa_vbap WHERE matnr EQ matnr.
SELECT vbeln j_3asize
FROM vbep posnr INTO table it_vbep
for all entries in it_vbap
where vbeln = it_vbap-vbeln and posnr = it_vbap-posnr.
loop at it_vbap into wa_vbap.
"move all the data  of wa_vbap into wa_final
"since you are not using full key you may get more than one record
loop at it_vbep INTO wa_vbep Where vbeln = it_vbap-vbeln  and posnr = it_vbep-posnr.
"move the information from wa_vbep to wa_final
endloop.
append wa_final to it_final.
clear wa_final.
endloop.

Similar Messages

  • How to place header and footer  in OO-ALV program using class

    How to place header and footer  in OO-ALV program using class tell me wat r the class we shold use and their attributes as well

    Hi Venkatesh,
    Take a look at this how to [ABAP Objects - ALV Model - Using Header and Footer|https://wiki.sdn.sap.com/wiki/x/xdw]
    it's explaining how to define the classes and use it for display an ALV with Header and Footer.
    Regards,
    Marcelo Ramos

  • ALV Programming and Sapscript...

    Hi,
    Till date i have only worked in standard reports, now i have to work on ALV report and Sapscript, so if any one have any basic tutorial on ALV and Sapscript, pls email me.
    Thanks in advance.

    Hi arup,
    1. This is the most simple form of alv.
    2. Minimum, this much coding is required for a normal alv.
    The two main FMs for any alv programming are.
    <b>REUSE_ALV_LIST_DISPLAY
    REUSE_ALV_FIELDCATALOG_MERGE</b>
    3. just copy paste to get a taste of it.
    4.
    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.
    IMPORTANT
      LOOP AT ALVFC INTO ALVFCWA.
        IF ALVFCWA-FIELDNAME = 'USTYP'.
          ALVFCWA-NO_CONVEXT = 'X'.
          MODIFY ALVFC FROM ALVFCWA.
        ENDIF.
      ENDLOOP.
    Display
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          it_fieldcat   = alvfc
        TABLES
          t_outtab      = itab
        EXCEPTIONS
          program_error = 1
          OTHERS        = 2.
    regards,
    amit m.

  • How to check the layout defined for an ALV program

    Hi All,
    I have an ALV-program which uses radio buttons to display the list either in an Hierarchical format or in a Simple list format. In the selection screen there is a field for specifying the layout.
    Now the problem is, if a layout is created for Hierachical display and that layout is used to display the list in a simple list format the program doesn't give the desired output and vice versa.
    So i need to put a check in the program, to check whether the layout given in the selection screen is meant for a Simple List display or for an Hierarchical display and accordingly throw an error message regarding the mismatch if any.
    Is there any standard Function Module to check whether the layout is defined for a Simple List display or an Hieracrchical List display? Or is there any other way to do this checking????
    Thanks in Advance!!!
    Anindya

    Hi Venkat,
    The problem is:
    I need to know whether the LAYOUT(given in the selection screen) is defined for a SIMPLE LIST DISPLAY or an HIERARCHICAL LIST DISPLAY. Now say for example user has selected a layout which has been defined for a Hierarchical List display but by mistake he has selected the radio button for a Simple List display. So, here is a mismatch and the program should detect this and throw some error message. Instead it is now displaying a wrong output which is resulting from the mismatch.

  • Why do we use cl_gui_cfw= flush method in Object Oriented ALV programming

    Dear Friends,
    Please solve my query regarding control framework. Why do we use cl_gui_cfw=>flush method in Object Oriented ALV programming. I studied and found that this method transfers automation queue to Front end.  But I could not find any further update on this.
    Thanks & Regards
    Amit Sharma

    Generally this is to restrict the traffic b/w frontend and backend. This means that every operation in Control Framework should be first buffered in the backend and synchronized with the frontend at certain points (one of this point is calling synchronization method cl_gui_cfw=>flush ). This explicit order of synchronization is due to RFC call needed for every communication b/w front/back end. So to avoid to many RFC calls we do it only at certain time.
    Please refer [Automation Queue|http://help.sap.com/saphelp_wp/helpdata/en/9b/d080ba9fc111d2bd68080009b4534c/frameset.htm]. I think it explains the concept quite well.
    Regards
    Marcin

  • All ALV Programs

    Dear Gurus,
                I am new to ABAP . Please provide me sample report code for all possible combinations in ALV like grid , hierachical , basic , intreactive & combination of all...etc..
                Thanks in advance . Points will be rewarded
    Regards,
    Lakshmiraj

    Check the below links :
    http://www.sap-img.com/abap/sample-programs-on-alv-grid.htm
    http://www.sap-img.com/abap-function.htm
    http://www.sap-basis-abap.com/sapab034.htm
    http://www.erpgenie.com/abap/example_code.htm
    These all are very simple ALV programs ,good luck
    Thanks
    Seshu

  • Concrete example of (whole ALV program )

    Hi
    i did some modification in the ALV program before .  like changing field catalog etc...  but i have never write a whole program in ALV and would like to try one by myself .
    could you please in just 2 3 words write the step, and is there a sample program where all that apply to ALV is coded like hotspot , drill down, color, check box etc...

    Hi,
    go through this code.
    Complete code for the ALV grid example
    This example shows and ALV grid with flights. After selecting a line a change button can be pushed to display a change screen. After the changes have been saved, the ALV grid screen is displayed again, and the grid is updated with the changes.
    The example shows:
    How to setup the ALV grid
    How to ste focus to the grid
    How to set the title of the grid
    How to allow a user to save and reuse a grid layout (Variant)
    How to customize the ALV grid toolbar
    Refresh the grid
    Set and get row selection and read line contents
    Make and exception field (Traffic light)
    Coloring a line
    Steps:
    Create screen 100 with the ALV grid. Remember to include an exit button
    Add a change button to the ALV grid toolbar
    Create screen 200 the Change screen
    The screens:
    The code:
       REPORT sapmz_hf_alv_grid .
    Type pool for icons - used in the toolbar
       TYPE-POOLS: icon.
       TABLES: zsflight.
    To allow the declaration of o_event_receiver before the
    lcl_event_receiver class is defined, decale it as deferred in the
    start of the program
       CLASS lcl_event_receiver DEFINITION DEFERRED.
    G L O B A L   I N T E R N  A L   T A B L E S
       *DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
    To include a traffic light and/or color a line the structure of the
    table must include fields for the traffic light and/or the color
       TYPES: BEGIN OF st_sflight.
               INCLUDE STRUCTURE zsflight.
          Field for traffic light
       TYPES:  traffic_light TYPE c.
          Field for line color
       types:  line_color(4) type c.
       TYPES: END OF st_sflight.
       TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
       DATA: gi_sflight TYPE tt_sflight.
    G L O B A L   D A T A
       DATA: ok_code         LIKE sy-ucomm,
        Work area for internal table
             g_wa_sflight    TYPE st_sflight,
        ALV control: Layout structure
             gs_layout       TYPE lvc_s_layo.
    Declare reference variables to the ALV grid and the container
       DATA:
         go_grid             TYPE REF TO cl_gui_alv_grid,
         go_custom_container TYPE REF TO cl_gui_custom_container,
         o_event_receiver    TYPE REF TO lcl_event_receiver.
       DATA:
    Work area for screen 200
         g_screen200 LIKE zsflight.
    Data for storing information about selected rows in the grid
       DATA:
    Internal table
         gi_index_rows TYPE lvc_t_row,
    Information about 1 row
         g_selected_row LIKE lvc_s_row.
    C L A S S E S
       CLASS lcl_event_receiver DEFINITION.
         PUBLIC SECTION.
           METHODS:
            handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
              IMPORTING
                e_object e_interactive,
            handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
              IMPORTING e_ucomm.
       ENDCLASS.
          CLASS lcl_event_receiver IMPLEMENTATION
       CLASS lcl_event_receiver IMPLEMENTATION.
         METHOD handle_toolbar.
    Event handler method for event toolbar.
           CONSTANTS:
    Constants for button type
             c_button_normal           TYPE i VALUE 0,
             c_menu_and_default_button TYPE i VALUE 1,
             c_menu                    TYPE i VALUE 2,
             c_separator               TYPE i VALUE 3,
             c_radio_button            TYPE i VALUE 4,
             c_checkbox                TYPE i VALUE 5,
             c_menu_entry              TYPE i VALUE 6.
           DATA:
               ls_toolbar  TYPE stb_button.
      Append seperator to the normal toolbar
           CLEAR ls_toolbar.
           MOVE c_separator TO ls_toolbar-butn_type..
           APPEND ls_toolbar TO e_object->mt_toolbar.
      Append a new button that to the toolbar. Use E_OBJECT of
      event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
      This class has one attribute MT_TOOLBAR which is of table type
      TTB_BUTTON. The structure is STB_BUTTON
           CLEAR ls_toolbar.
           MOVE 'CHANGE'        TO ls_toolbar-function.
           MOVE  icon_change    TO ls_toolbar-icon.
           MOVE 'Change flight' TO ls_toolbar-quickinfo.
           MOVE 'Change'        TO ls_toolbar-text.
           MOVE ' '             TO ls_toolbar-disabled.
           APPEND ls_toolbar    TO e_object->mt_toolbar.
         ENDMETHOD.
         METHOD handle_user_command.
      Handle own functions defined in the toolbar
           CASE e_ucomm.
             WHEN 'CHANGE'.
               PERFORM change_flight.
           LEAVE TO SCREEN 0.
           ENDCASE.
         ENDMETHOD.
       ENDCLASS.
    S T A R T - O F - S E L E C T I O N.
       START-OF-SELECTION.
         SET SCREEN '100'.
       *&      Module  USER_COMMAND_0100  INPUT
       MODULE user_command_0100 INPUT.
         CASE ok_code.
           WHEN 'EXIT'.
             LEAVE TO SCREEN 0.
         ENDCASE.
       ENDMODULE.                 " USER_COMMAND_0100  INPUT
       *&      Module  STATUS_0100  OUTPUT
       MODULE status_0100 OUTPUT.
         DATA:
      For parameter IS_VARIANT that is sued to set up options for storing
      the grid layout as a variant in method set_table_for_first_display
           l_layout TYPE disvariant,
      Utillity field
           l_lines TYPE i.
    After returning from screen 200 the line that was selected before
    going to screen 200, should be selected again. The table gi_index_rows
    was the output table from the GET_SELECTED_ROWS method in form
    CHANGE_FLIGHT
         DESCRIBE TABLE gi_index_rows LINES l_lines.
         IF l_lines > 0.
           CALL METHOD go_grid->set_selected_rows
               EXPORTING
                 it_index_rows = gi_index_rows.
           CALL METHOD cl_gui_cfw=>flush.
           REFRESH gi_index_rows.
         ENDIF.
    Read data and create objects
         IF go_custom_container IS INITIAL.
      Read data from datbase table
           PERFORM get_data.
      Create objects for container and ALV grid
           CREATE OBJECT go_custom_container
             EXPORTING container_name = 'ALV_CONTAINER'.
           CREATE OBJECT go_grid
             EXPORTING
               i_parent = go_custom_container.
      Create object for event_receiver class
      and set handlers
           CREATE OBJECT o_event_receiver.
           SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
           SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
      Layout (Variant) for ALV grid
           l_layout-report = sy-repid. "Layout fo report
    Setup the grid layout using a variable of structure lvc_s_layo
      Set grid title
           gs_layout-grid_title = 'Flights'.
      Selection mode - Single row without buttons
      (This is the default  mode
           gs_layout-sel_mode = 'B'.
      Name of the exception field (Traffic light field) and the color
      field + set the exception and color field of the table
           gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
           gs_layout-info_fname = 'LINE_COLOR'.
           LOOP AT gi_sflight INTO g_wa_sflight.
             IF g_wa_sflight-paymentsum < 100000.
          Value of traffic light field
               g_wa_sflight-traffic_light = '1'.
          Value of color field:
          C = Color, 6=Color 1=Intesified on, 0: Inverse display off
               g_wa_sflight-line_color    = 'C610'.
             ELSEIF g_wa_sflight-paymentsum => 100000 AND
                    g_wa_sflight-paymentsum < 1000000.
               g_wa_sflight-traffic_light = '2'.
             ELSE.
               g_wa_sflight-traffic_light = '3'.
             ENDIF.
             MODIFY gi_sflight FROM g_wa_sflight.
           ENDLOOP.
      Grid setup for first display
           CALL METHOD go_grid->set_table_for_first_display
             EXPORTING i_structure_name = 'SFLIGHT'
                       is_variant       = l_layout
                       i_save           = 'A'
                       is_layout        = gs_layout
             CHANGING  it_outtab        = gi_sflight.
       *-- End of grid setup -
      Raise event toolbar to show the modified toolbar
           CALL METHOD go_grid->set_toolbar_interactive.
      Set focus to the grid. This is not necessary in this
      example as there is only one control on the screen
           CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
         ENDIF.
       ENDMODULE.                 " STATUS_0100  OUTPUT
       *&      Module  USER_COMMAND_0200  INPUT
       MODULE user_command_0200 INPUT.
         CASE ok_code.
           WHEN 'EXIT200'.
             LEAVE TO SCREEN 100.
             WHEN'SAVE'.
             PERFORM save_changes.
         ENDCASE.
       ENDMODULE.                 " USER_COMMAND_0200  INPUT
       *&      Form  get_data
       FORM get_data.
    Read data from table SFLIGHT
         SELECT *
           FROM zsflight
           INTO TABLE gi_sflight.
       ENDFORM.                    " load_data_into_grid
       *&      Form  change_flight
    Reads the contents of the selected row in the grid, ans transfers
    the data to screen 200, where it can be changed and saved.
       FORM change_flight.
         DATA:l_lines TYPE i.
         REFRESH gi_index_rows.
         CLEAR   g_selected_row.
    Read index of selected rows
         CALL METHOD go_grid->get_selected_rows
           IMPORTING
             et_index_rows = gi_index_rows.
    Check if any row are selected at all. If not
    table  gi_index_rows will be empty
         DESCRIBE TABLE gi_index_rows LINES l_lines.
         IF l_lines = 0.
           CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
                EXPORTING
                     textline1 = 'You must choose a line'.
           EXIT.
         ENDIF.
    Read indexes of selected rows. In this example only one
    row can be selected as we are using gs_layout-sel_mode = 'B',
    so it is only ncessary to read the first entry in
    table gi_index_rows
         LOOP AT gi_index_rows INTO g_selected_row.
           IF sy-tabix = 1.
            READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
           ENDIF.
         ENDLOOP.
    Transfer data from the selected row to screenm 200 and show
    screen 200
         CLEAR g_screen200.
         MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
         LEAVE TO SCREEN '200'.
       ENDFORM.                    " change_flight
       *&      Form  save_changes
    Changes made in screen 200 are written to the datbase table
    zsflight, and to the grid table gi_sflight, and the grid is
    updated with method refresh_table_display to display the changes
       FORM save_changes.
         DATA: l_traffic_light TYPE c.
    Update traffic light field
    Update database table
         MODIFY zsflight FROM g_screen200.
    Update grid table , traffic light field and color field.
    Note that it is necessary to use structure g_wa_sflight
    for the update, as the screen structure does not have a
    traffic light field
         MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
         IF g_wa_sflight-paymentsum < 100000.
           g_wa_sflight-traffic_light = '1'.
      C = Color, 6=Color 1=Intesified on, 0: Inverse display off
           g_wa_sflight-line_color    = 'C610'.
         ELSEIF g_wa_sflight-paymentsum => 100000 AND
                g_wa_sflight-paymentsum < 1000000.
           g_wa_sflight-traffic_light = '2'.
           clear g_wa_sflight-line_color.
         ELSE.
           g_wa_sflight-traffic_light = '3'.
           clear g_wa_sflight-line_color.
         ENDIF.
         MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
    Refresh grid
         CALL METHOD go_grid->refresh_table_display.
         CALL METHOD cl_gui_cfw=>flush.
         LEAVE TO SCREEN '100'.
       ENDFORM.                    " save_changes

  • ALV program with Field Catalog

    Hi ,
    Can any body please provide me sample ALV programs with Field Catalog and GRID DISPLAY. and also please give me the steps for writing the program.
    Thanks in advance.
    KP

    Hi,
    For ALV GRID DISPLAY (using <b>OOPS</b>),
    1)Create an object of the <b>container</b>(an instance of a class like cl_gui_custom_container).
    2)Create an object of the <b>ALV using class cl_gui_alv_grid</b> and give the CONTAINER name that you define in your screen layout as the parent of the ALV.
    3)Call the method <b>SET_TABLE_FOR_FIRST_DISPLAY</b> of the class cl_gui_alv_grid.
    4)<b>Field catalog</b> is used when you want a variation of the standard structure to be displayed on your ALV.A  variable of table type <b>LVC_T_FCAT</b> is defined and variations can be made as per the requirements.The variable is then passed in the method SET_TABLE_FOR_FIRST_DISPLAY.
    <b>A SAMPLE PROGRAM:</b>
    REPORT SAMPLE:
    *-- GLOBAL DATA DECLARATIONS FOR ALV
    <b>DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.</b>
    DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
    <b>DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.</b>
    DATA gt_fieldcat TYPE lvc_t_fcat.
    Data:i_spfli type table of spfli.
    *The value CC_ALV is given to the custom container in the screen layout
    START-OF-SELECTION.
    select * from spfli into table i_spfli.
    Call screen 100.
    MODULE STATUS_0100 OUTPUT
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
    *Create container
    <b>CREATE OBJECT gr_ccontainer
    EXPORTING container_name = gc_custom_control_name.</b>
    *Create ALV
    <b>CREATE OBJECT gr_alvgrid
    EXPORTING i_parent = gr_ccontainer.</b>
    *field catalog
    <b>PERFORM prepare_field_catalog CHANGING gt_fieldcat.</b>
    *to display the ALV
    <b>CALL METHOD gr_alvgrid->set_table_for_first_display</b>
    EXPORTING
      I_STRUCTURE_NAME              = 'SPFLI'
    CHANGING
    it_outtab = i_spfli[]
    it_fieldcatalog = gt_fieldcat.
    ENDMODULE.                    "display_alv OUTPUT
    MODULE USER_COMMAND_0100 INPUT
    MODULE user_command_0100 INPUT.
    IF sy-ucomm = 'BACK' OR
         sy-ucomm = 'EXIT' OR
         sy-ucomm = 'CANCEL'.
        LEAVE PROGRAM.
      ENDIF.
    ENDMODULE.
    *& Form prepare_field_catalog
    FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
    DATA ls_fcat TYPE lvc_s_fcat.
    ls_fcat-ref_table = 'SPFLI'.
    ls_fcat-fieldname = 'CARRID'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'CONNID'.
    ls_fcat-ref_table = 'SPFLI'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'DEPTIME'.
    ls_fcat-ref_table = 'SPFLI'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    ls_fcat-fieldname = 'ARRTIME'.
    ls_fcat-ref_table = 'SPFLI'.
    APPEND ls_fcat TO pt_fieldcat.
    CLEAR ls_fcat.
    endform.
    <b>For more sample programs refer:</b>http://www.geocities.com/victorav15/sapr3/abap_ood.html#d_grid
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
    http://www.sapdevelopment.co.uk/reporting/alvhome.htm
    <b>-->download the PDF from following link.</b>
    www.abap4.it/download/ALV.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
    <b>Some more:</b>
    http://www.sap-hefte.de/download/dateien/1025/087_leseprobe.pdf
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907
    http://www.alvgmbh.de/dwnload/gonio_t.pdfhttp://
    <b>You can get all demo programs for ALV:</b>Go to se38 and type BCALV* and press F4 for all demo porgrams.
    Regards,
    Beejal
    **Reward if this helps

  • How to write code  for totals and subtotals in alv programing?

    how to write code  for totals and subtotals in alv programing?

    hi,
    1. <u><b>TOTAL.</b></u>
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm
    2. <u><b>How do I add subtotals</b></u>
    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
    Regards
    Anver

  • Problem in alv program

    hi all,
    the following code is for an alv grid. The program is working fine. But after execution when the report is displayed the code is going for a dump when the back button is clicked. Could anyone tell as to whats going wrong. And when the highlighted part in the code is commented it is not giving a dump. The highligted part was used to include the row selection in the alv because
    <b>s_layout-sel_mode = 'A'</b>.
    was not working.
    *& Report  ZFI_9KE0
    REPORT  zfi_9ke0.
    *TYPE-POOLS
    TYPE-POOLS : slis.
    *DATA
    DATA: BEGIN OF wa,
           blart LIKE bsis-blart,
           hkont LIKE bsis-hkont,
           budat LIKE bsis-budat,
           wrbtr LIKE bsis-wrbtr,
           prctr LIKE bsis-prctr,
           pprct LIKE bsis-pprct,
           sgtxt LIKE bsis-sgtxt,
         END OF wa.
    DATA: v_counter TYPE i.
    *ALV SPECIFIC DECLARATIONS
    DATA : t_events TYPE slis_t_event.
    DATA : t_fieldcat TYPE slis_t_fieldcat_alv.
    DATA : t_list TYPE slis_t_listheader.
    DATA : v_repid TYPE sy-repid.
    DATA : v_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
    DATA : v_user_command TYPE slis_formname VALUE 'USER_COMMAND'.
    DATA : s_getinfo TYPE slis_keyinfo_alv.
    DATA : s_layout TYPE slis_layout_alv.
    *&INTERNAL TABLE
    DATA: itab LIKE STANDARD TABLE OF wa WITH HEADER LINE.
    *&SELECTION SCREEN
    *SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    *PARAMETER: p_acc type bsis-hkont.
    *SELECTION-SCREEN : END OF BLOCK blk1.
    *&INITIALIZATION.
    INITIALIZATION.
      PERFORM init.
    *&START-OF-SELECTION.
    START-OF-SELECTION.
      PERFORM get_data.
    *&END-OF-SELECTION.
    END-OF-SELECTION.
      PERFORM sub_comment_write.
      PERFORM sub_layout.
      PERFORM sub_call_alv.
    *&      Form  billing_init
          text
    -->  p1        text
    <--  p2        text
    FORM init .
      v_repid = sy-repid.
      PERFORM sub_events.
      PERFORM sub_fieldcat.
    ENDFORM.                    " BILLING_INIT
    *&      Form  SUB_EVENTS
          text
    FORM sub_events .
      DATA : wa_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = t_events.
      SORT t_events.
      READ TABLE t_events WITH KEY name = slis_ev_top_of_page BINARY SEARCH
                          INTO wa_event.
      MOVE v_top_of_page TO wa_event-form.
      IF sy-subrc EQ 0.
        APPEND wa_event TO t_events.
      ENDIF.
      SORT t_events.
    READ TABLE t_events WITH KEY name = slis_ev_user_command BINARY SEARCH
                         INTO wa_event.
    MOVE v_user_command TO wa_event-form.
    IF sy-subrc EQ 0.
       APPEND wa_event TO t_events.
    ENDIF.
    ENDFORM.                    " SUB_EVENTS
    *&      Form  SUB_FIELDCAT
          text
    FORM sub_fieldcat .
      PERFORM insert_field USING :
      'BLART'      'DOCUMENT TYPE'                     'X'      20 ,
      'HKONT'      'GL DOCUMENT'                       space    20 ,
      'BUDAT'      'DOCUMENT DATE'                     space    20 ,
      'WRBTR'      'PROFIT AMOUNT'                     space    20 ,
      'PRCTR'      'MATERIAL RECIEVED PROFIT CENTER'   space    40 ,
      'PPRCTR'     'MATERIAL SEND PROFIT CENTER'       space    40 ,
      'SGTXT'      'TEXT'                              space    40.
    ENDFORM.                    " SUB_FIELDCAT
    *&      Form  INSERT_FIELD
          text
    FORM insert_field  USING    value(p_fname)
                                value(p_tname)
                                value(p_key)
                                value(p_length).
      DATA : wa_fieldcat TYPE slis_fieldcat_alv.
      v_counter = v_counter + 1.
      wa_fieldcat-col_pos = v_counter.
      wa_fieldcat-fieldname = p_fname.
      wa_fieldcat-seltext_m = p_tname.
      wa_fieldcat-key = p_key.
      wa_fieldcat-outputlen = p_length.
      IF wa_fieldcat-col_pos = 6.
        wa_fieldcat-do_sum = 'X'.
      ENDIF.
      APPEND wa_fieldcat TO t_fieldcat.
    ENDFORM.                    " INSERT_FIELD
    *&      Form  GET_DATA
          text
    FORM get_data .
      CLEAR: itab.
      SELECT blart
             hkont
             budat
             wrbtr
             prctr
             pprct
             sgtxt
        FROM bsis
        INTO TABLE itab
       WHERE blart = 'WA'.
        AND hkont EQ p_acc.
        OR  hkont EQ '277500000'.
    ENDFORM.                    " GET_DATA
    *&      Form  SUB_COMMENT_WRITE
          text
    FORM sub_comment_write .
      DATA : wa_list TYPE slis_listheader.
      wa_list-typ = 'H'.
      wa_list-info = 'FI DOCUMENT POSTING '.
      APPEND wa_list TO t_list.
    ENDFORM.                    " SUB_COMMENT_WRITE
    *&      Form  SUB_LAYOUT
          text
    FORM sub_layout .
      s_layout-detail_popup = 'X'.
    s_layout-sel_mode = 'A'.
      s_layout-zebra = 'X'.
      s_layout-colwidth_optimize = 'X'.
    <b>  s_layout-box_fieldname = 'SELECT'.
      s_layout-box_tabname = 'itab'.</b>
    ENDFORM.                    " SUB_LAYOUT
    *&      Form  SUB_CALL_ALV
          text
    FORM sub_call_alv .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = v_repid
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
         is_layout                         = s_layout
         it_fieldcat                       = t_fieldcat[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      it_sort                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
         it_events                         = t_events[]
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          = itab
    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.                    " SUB_CALL_ALV
    *&      Form  TOP_OF_PAGE
          text
    FORM top_of_page .
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = t_list
          i_logo             = 'ENJOYSAP_LOGO'.
    ENDFORM.                    "top_of_page

    JUST ADD THIS
    DATA: BEGIN OF wa,
    <b>SELECT,</b>
    blart LIKE bsis-blart,
    hkont LIKE bsis-hkont,
    budat LIKE bsis-budat,
    wrbtr LIKE bsis-wrbtr,
    prctr LIKE bsis-prctr,
    pprct LIKE bsis-pprct,
    sgtxt LIKE bsis-sgtxt,
    END OF wa.
    IN
    s_layout-box_fieldname = 'SELECT'.
    *s_layout-box_tabname = 'ITAB'.
    ADD THE BOX FIELD  IN WA
    REGARDS
    SHIBA DUTTA

  • Want an alv program that contains events

    **Hello experts**
    **I am new to abap  practicing alv i can write simle alv proram using  reuse_alv_grid_display ,but i have doubt in events**
    **i.e how to use it .If possible please send some program using slis_t_event and slis_alv_event.**
                                                                                    **Thanks in advance**
                                                                                    **Chitta Ranjan Mahato**

    Hi Mahatoji, welcome to SDN, and please stop using ***! If you want to write all in bold, you shouldn't (and uppercase is forbidden).
    REUSE_ALV_GRID_DISPLAY is one way to handle ALVs. There are lots of demo programs, so just look at them.
    You'll find more info in that wiki: http://wiki.sdn.sap.com/wiki/display/ABAP/ALV

  • Alv programming

    Hi , can we insert data into database using ALV reporting?

    Yep, see programs which start with BCALV_EDIT*
    Regards,
    RIch Heilman

  • ALV Program errors

    Hello all,
       I've have a strange error, when trying to use buttons from top of an ALV list(eg. print). An error message appear with text "Program errors", but only when one button is used, in rest the list is ok.
      Do you have an ideea why?
      Thank you!
      Bogdan
      Here is the code, if is helping:
      IF g_cont_alv2 IS INITIAL.
          CREATE OBJECT g_cont_alv2
                 EXPORTING container_name = 'G_CONT_ALV2'.
        CREATE OBJECT g_grid2
               EXPORTING i_parent = g_cont_alv2.
      ENDIF.
      l_layout-cwidth_opt = 'X'.
      l_layout-sel_mode = 'D'.
      l_layout-totals_bef = 'X'.
      CALL METHOD g_grid2->set_table_for_first_display
           EXPORTING is_variant = l_variant
                     i_save = 'A'
                     i_default = 'X'
                     is_layout = l_layout
                    it_toolbar_excluding = lt_exclude
           CHANGING it_outtab = lt_stats
                    it_fieldcatalog = lt_fcat.
      LEAVE TO SCREEN 200.

    Hi,
    It seems your data table <b>lt_stats</b> is a local internal table declared inside a subroutine and not a global internal table declared in TOP include or if it is a report then at the top.
    Normally ALV Grid stores a reference of the internal table for accessing it later (in your case, for printing). If it is a local internal table then ALV will not be access it and hence the error message.
    So try declaring your <b>lt_stats</b> table in the TOP include (for modulepools or function groups) or at the top (if it is a report).
    <b>Did you try this out?</b> <b>You need to declare your internal table at GLOBAL level.</b>
    Hope this helps..
    Sri
    Message was edited by: Srikanth Pinnamaneni

  • Alv programes

    can any body tell what is the use of disvariant in the alv programm.
    how to use it.
    i hav created a structure for disvariant, a parameter for disvariant,and pass the values like reportid and parameters(by refering to an other prg) but i am not getting how it is going happen
    please help me out wit a sample code and example.
    whanks and regards

    Hi,
    execute this code.u can understand very well about disvarient from this code.
    REPORT Z_PICK_LIST .
    TABLES: RESB.
    SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1.
    SELECT-OPTIONS: S_WERKS FOR RESB-WERKS," Plant
                    S_AUFNR FOR RESB-AUFNR," Order number
                    S_BDTER FOR RESB-BDTER." Req. date
    SELECTION-SCREEN END OF BLOCK BL1.
    PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT DEFAULT '/STANDARD'.
    DATA: BEGIN OF OUT OCCURS 10,
            AUFNR LIKE RESB-AUFNR,         " Order number
            MATNR LIKE RESB-MATNR,         " Material
            BDMNG LIKE RESB-BDMNG,         " Requirements in UM
            MEINS LIKE RESB-MEINS,         " Unit of Measure (UM)
            ERFMG LIKE RESB-ERFMG,         " Requirements in UE
            ERFME LIKE RESB-ERFME,         " Unit of Entry (UE)
            MAKTX LIKE MAKT-MAKTX,         " Mat. description
          END OF OUT.
    INCLUDE Z_ALV_VARIABLES.
    INITIALIZATION.
      REPNAME = SY-REPID.
      PERFORM INITIALIZE_FIELDCAT USING FIELDTAB[].
      PERFORM BUILD_EVENTTAB USING EVENTS[].
      PERFORM BUILD_COMMENT USING HEADING[].
      PERFORM INITIALIZE_VARIANT.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
      PERFORM F4_FOR_VARIANT.
    AT SELECTION-SCREEN.
      PERFORM PAI_OF_SELECTION_SCREEN.
    START-OF-SELECTION.
      PERFORM GET_ORDERS.
      PERFORM GET_MATERIAL_DESCRIPTION.
    END-OF-SELECTION.
      PERFORM BUILD_LAYOUT USING LAYOUT.
      PERFORM BUILD_PRINT  USING PRINTS.
      PERFORM WRITE_USING_ALV.
          FORM INITIALIZE_FIELDCAT                               *
    -->  P_TAB                                                         *
    FORM INITIALIZE_FIELDCAT USING P_TAB TYPE SLIS_T_FIELDCAT_ALV.
      DATA: CAT TYPE SLIS_FIELDCAT_ALV.
      CLEAR CAT.
    ENDFORM.                               " INITIALIZE_FIELDCAT
    *&      Form  GET_ORDERS
          text
    FORM GET_ORDERS.
      SELECT AUFNR MATNR BDMNG MEINS ERFMG ERFME
             FROM RESB
             APPENDING TABLE OUT
             WHERE XLOEK EQ SPACE          " deletion indicator
             AND   XWAOK EQ 'X'            " goods movement indicator
             AND   WERKS IN S_WERKS        " plant
             AND   BDTER IN S_BDTER        " req. date
             AND   AUFNR IN S_AUFNR.       " pr. order
    ENDFORM.                               " GET_ORDERS
    *&      Form  GET_MATERIAL_DESCRIPTION
          text
    FORM GET_MATERIAL_DESCRIPTION.
      SORT OUT BY MATNR.
      LOOP AT OUT.
        SELECT SINGLE MAKTX
               INTO OUT-MAKTX
               FROM MAKT
               WHERE MATNR EQ OUT-MATNR
               AND   SPRAS EQ 'EN'.
        MODIFY OUT.
      ENDLOOP.
      SORT OUT BY AUFNR MATNR.
    ENDFORM.                               " GET_MATERIAL_DESCRIPTION
          FORM TOP_OF_PAGE                                              *
    FORM TOP_OF_PAGE.
      DATA: L_POS TYPE P.
    first line
      WRITE:/ TEXT-001.                    " Plant:
      IF S_WERKS-HIGH NE SPACE.
        WRITE: S_WERKS-LOW, TEXT-TO1, S_WERKS-HIGH.
      ELSEIF S_WERKS-LOW NE SPACE.
        LOOP AT S_WERKS.
          WRITE: S_WERKS-LOW.
        ENDLOOP.
      ELSEIF S_WERKS-LOW EQ SPACE.
        WRITE: TEXT-ALL.
      ENDIF.
      L_POS = ( SY-LINSZ DIV 2 ) - ( STRLEN( TEXT-TIT ) DIV 2 ).
      POSITION L_POS. WRITE: TEXT-TIT.
      L_POS = SY-LINSZ - 20.
      POSITION L_POS. WRITE: TEXT-011, SY-UNAME RIGHT-JUSTIFIED.  " User:
    second line
      WRITE:/ TEXT-002.                    " Order:
      IF S_AUFNR-HIGH NE SPACE.
        WRITE: S_AUFNR-LOW, TEXT-TO1, S_AUFNR-HIGH.
      ELSEIF S_AUFNR-LOW NE SPACE.
        LOOP AT S_AUFNR.
          WRITE: S_AUFNR-LOW.
        ENDLOOP.
      ELSEIF S_AUFNR-LOW EQ SPACE.
        WRITE: TEXT-ALL.
      ENDIF.
      L_POS = SY-LINSZ - 20.
      POSITION L_POS. WRITE: TEXT-012,SY-DATUM.      " Date:
    third line
      WRITE:/ TEXT-003.                    " Req. Date:
      IF S_BDTER-HIGH(1) NE '0'.
        WRITE: S_BDTER-LOW, TEXT-TO1, S_BDTER-HIGH.
      ELSEIF S_BDTER-LOW(1) NE '0'.
        LOOP AT S_BDTER.
          WRITE: S_BDTER-LOW.
        ENDLOOP.
      ELSEIF S_BDTER-LOW(1) EQ '0'.
        WRITE: TEXT-ALL.
      ENDIF.
      L_POS = SY-LINSZ - 20.
      POSITION L_POS. WRITE: TEXT-013, SY-PAGNO.   " Page:
    ENDFORM.                               " TOP_OF_PAGE
          FORM END_OF_LIST                                              *
    FORM END_OF_LIST.
      DATA: L_POS TYPE P.
      ULINE.
      WRITE:/ '|', TEXT-021.      " Delivered by:
      L_POS = SY-LINSZ DIV 2.
      POSITION L_POS. WRITE: '|', TEXT-031.            " Received by:
      L_POS = SY-LINSZ.
      POSITION L_POS. WRITE: '|'.
      WRITE:/ '|'.
      L_POS = SY-LINSZ DIV 2.
      POSITION L_POS. WRITE: '|'.
      L_POS = SY-LINSZ.
      POSITION L_POS. WRITE: '|'.
      ULINE.
      WRITE:/ '|', TEXT-012.      " Date:
      L_POS = SY-LINSZ DIV 2.
      POSITION L_POS. WRITE: '|', TEXT-012.            " Date:
      L_POS = SY-LINSZ.
      POSITION L_POS. WRITE: '|'.
      WRITE:/ '|'.
      L_POS = SY-LINSZ DIV 2.
      POSITION L_POS. WRITE: '|'.
      L_POS = SY-LINSZ.
      POSITION L_POS. WRITE: '|'.
      ULINE.
    ENDFORM.                               " END_OF_LIST
    *&      Form  WRITE_USING_ALV
          text
    FORM WRITE_USING_ALV.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                I_PROGRAM_NAME     = REPNAME
                I_INTERNAL_TABNAME = 'OUT'
                I_INCLNAME         = REPNAME
           CHANGING
                CT_FIELDCAT        = FIELDTAB.
      IF SY-SUBRC <> 0.
        WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_FIELDCATALOG_MERGE'.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM       = REPNAME
               i_callback_pf_status_set = 'PF_STATUS_SET'
               i_callback_user_command  = 'USER_COMMAND'
                I_STRUCTURE_NAME         = 'OUT'
                IS_LAYOUT                = LAYOUT
                IT_FIELDCAT              = FIELDTAB
                I_DEFAULT                = 'A'
                I_SAVE                   = G_SAVE
                IS_VARIANT               = G_VARIANT
                IT_EVENTS                = EVENTS[]
                IS_PRINT                 = PRINTS
           TABLES
                T_OUTTAB                 = OUT.
      IF SY-SUBRC <> 0.
        WRITE: 'SY-SUBRC: ', SY-SUBRC, 'REUSE_ALV_LIST_DISPLAY'.
      ENDIF.
    ENDFORM.                               " WRITE_USING_ALV
    THESE LINES ARE FOR THE INCLUDE ***
    ***INCLUDE Z_ALV_VARIABLES .
    TYPE-POOLS: SLIS.
    DATA: FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,
          HEADING  TYPE SLIS_T_LISTHEADER,
          LAYOUT   TYPE SLIS_LAYOUT_ALV,
          EVENTS   TYPE SLIS_T_EVENT,
          REPNAME  LIKE SY-REPID,
          F2CODE   LIKE SY-UCOMM VALUE  '&ETA',
          PRINTS   TYPE SLIS_PRINT_ALV,
          TITLE(40) TYPE C,
          G_SAVE(1) TYPE C,
          G_EXIT(1) TYPE C,
          G_VARIANT LIKE DISVARIANT,
          GX_VARIANT LIKE DISVARIANT.
    CONSTANTS: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
               FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE',
               FORMNAME_END_OF_LIST TYPE SLIS_FORMNAME VALUE 'END_OF_LIST',
               FORMNAME_BEFORE_LINE TYPE SLIS_FORMNAME VALUE 'BEFORE_LINE',
               FORMNAME_AFTER_LINE TYPE SLIS_FORMNAME VALUE 'AFTER_LINE'.
          FORM MAIN_STATEMENTS                                          *
    THIS IS THE CODE THAT MUST BE INSERTED IN THE MAIN PROGRAM
    FORM MAIN_STATEMENTS.
    Declare the parameter P_VARI wherever you want it. If you don't
    want it, hide it with NO-DISPLAY, but it must exist.
    parameters: p_vari like disvariant-variant. " ALV Variant
    You have to add the following line after the data and parameter
    declaration:
    include z_alv_variables.
    Then, after the data/parameter declaration, add these lines:
    *initialization.
    repname = sy-repid.
    perform initialize_fieldcat using fieldtab[].
    perform build_eventtab using events[].
    perform build_comment using heading[].
    perform initialize_variant.
    If you are using the variable P_VARI (ALV Variant), also add this:
    *at selection-screen on value-request for p_vari.
    perform f4_for_variant.
    *at selection-screen.
    perform pai_of_selection_screen.
    After the "END-OF-SELECTION" statement, add these lines:
    perform build_layout using layout.
    perform build_print  using prints.
    perform write_using_alv.
    You also have to create the following forms: (you can find samples
    in this program)
    INITIALIZE_FIELDCAT
    USER_COMMAND     (only if you are creating a STATUS)
    WRITE_USING_ALV
    ENDFORM.
    *&      Form  INITIALIZE_FIELDCAT_SAMPLE
          THIS IS A SAMPLE, DO NOT USE THIS FORM IN YOUR PROGRAM
         -->P_FIELDTAB[]  text                                           *
    FORM INITIALIZE_FIELDCAT_SAMPLE USING P_TAB TYPE SLIS_T_FIELDCAT_ALV.
      DATA: CAT TYPE SLIS_FIELDCAT_ALV.
      CLEAR CAT.                           " Always clear before use
      CAT-TABNAME = 'I'.                   " Your internal table
      CAT-REF_TABNAME = 'ZCUSTMAS'.  " The data dictionary reference table
      CAT-FIELDNAME = 'KUNNR'.       " Name of your field in the itable.
      CAT-COL_POS   = 1.                   " Output position
      APPEND CAT TO P_TAB.
      CAT-FIELDNAME = 'NAME1'.             " Next field
      CAT-COL_POS   = 2.
      APPEND CAT TO P_TAB.
      CAT-FIELDNAME = 'STRAS'.             " and the next
      CAT-COL_POS   = 3.
      APPEND CAT TO P_TAB.
      CAT-FIELDNAME = 'LOEVM'.
      CAT-SELTEXT_S = 'Del'.         " You can always override the descrip-
      CAT-SELTEXT_M = 'Delivery'.          " tion (short, medium, large)
      CAT-SELTEXT_L = 'Delivery Num'.
      CAT-COL_POS   = 4.
      APPEND CAT TO P_TAB.
      CAT-FIELDNAME = 'FKIMG'.
      CAT-DO_SUM    = 'X'.                 " You want totals calculated.
      CAT-NO_OUT    = 'X'.                 " and hidden.
      APPEND CAT TO P_TAB.
    ENDFORM.                               " INITIALIZE_FIELDCAT
    *&      Form  BUILD_EVENTTAB
          THIS IS THE SAME FOR ALL THE PROGRAMS
         -->P_EVENTS[]  text                                             *
    FORM BUILD_EVENTTAB USING P_EVENTS TYPE SLIS_T_EVENT.
      DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           EXPORTING
                I_LIST_TYPE = 0
           IMPORTING
                ET_EVENTS   = P_EVENTS.
      READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
        APPEND LS_EVENT TO P_EVENTS.
      ENDIF.
      CLEAR LS_EVENT.
      READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_END_OF_LIST
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE FORMNAME_END_OF_LIST TO LS_EVENT-FORM.
        APPEND LS_EVENT TO P_EVENTS.
      ENDIF.
      CLEAR LS_EVENT.
      READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_BEFORE_LINE_OUTPUT
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE FORMNAME_BEFORE_LINE TO LS_EVENT-FORM.
        APPEND LS_EVENT TO P_EVENTS.
      ENDIF.
      CLEAR LS_EVENT.
      READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_AFTER_LINE_OUTPUT
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE FORMNAME_AFTER_LINE TO LS_EVENT-FORM.
        APPEND LS_EVENT TO P_EVENTS.
      ENDIF.
      CLEAR LS_EVENT.
      READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
        APPEND LS_EVENT TO P_EVENTS.
      ENDIF.
    ENDFORM.                               " BUILD_EVENTTAB
    *&      Form  BUILD_COMMENT
    NOT REALLY NEEDED, BUT I'LL LEAVE IT THERE, JUST IN CASE...
         -->P_HEADING[]  text                                            *
    FORM BUILD_COMMENT USING P_HEADING TYPE SLIS_T_LISTHEADER.
      DATA: HLINE TYPE SLIS_LISTHEADER,
            TEXT(60) TYPE C,
            SEP(20) TYPE C.
      CLEAR: HLINE, TEXT.
      HLINE-TYP  = 'H'.
    write: text-101 to text+23.
      HLINE-INFO = TEXT.
      APPEND HLINE TO P_HEADING.
    ENDFORM.                               " BUILD_COMMENT
    *&      Form  INITIALIZE_VARIANT
    VERY IMPORTANT WHEN YOU USE VARIANTS!!!
    FORM INITIALIZE_VARIANT.
      G_SAVE = 'A'.
      CLEAR G_VARIANT.
      G_VARIANT-REPORT = REPNAME.
      GX_VARIANT = G_VARIANT.
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
           EXPORTING
                I_SAVE     = G_SAVE
           CHANGING
                CS_VARIANT = GX_VARIANT
           EXCEPTIONS
                NOT_FOUND  = 2.
      IF SY-SUBRC = 0.
        P_VARI = GX_VARIANT-VARIANT.
      ENDIF.
    ENDFORM.                               " INITIALIZE_VARIANT
    *&      Form  PAI_OF_SELECTION_SCREEN
    ALSO FOR VARIANTS
    FORM PAI_OF_SELECTION_SCREEN.
      IF NOT P_VARI IS INITIAL.
        MOVE G_VARIANT TO GX_VARIANT.
        MOVE P_VARI TO GX_VARIANT-VARIANT.
        CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
             EXPORTING
                  I_SAVE     = G_SAVE
             CHANGING
                  CS_VARIANT = GX_VARIANT
             EXCEPTIONS
                  WRONG_INPUT   = 1
                  NOT_FOUND     = 2
                  PROGRAM_ERROR = 3.
        IF SY-SUBRC EQ 0.
          G_VARIANT = GX_VARIANT.
        ELSE.
          PERFORM INITIALIZE_VARIANT.
        ENDIF.
      ELSE.
        PERFORM INITIALIZE_VARIANT.
      ENDIF.
    ENDFORM.                               " PAI_OF_SELECTION_SCREEN
    *&      Form  F4_FOR_VARIANT
          text
    FORM F4_FOR_VARIANT.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
           EXPORTING
                IS_VARIANT = G_VARIANT
                I_SAVE     = G_SAVE
           IMPORTING
                E_EXIT     = G_EXIT
                ES_VARIANT = GX_VARIANT
           EXCEPTIONS
                NOT_FOUND  = 2.
      IF SY-SUBRC = 2.
        MESSAGE ID SY-MSGID TYPE 'S'      NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ELSE.
        IF G_EXIT = SPACE.
          P_VARI = GX_VARIANT-VARIANT.
        ENDIF.
      ENDIF.
    ENDFORM.                               " F4_FOR_VARIANT
    *&      Form  BUILD_LAYOUT
    STANDARD LAYOUT
         -->P_LAYOUT  text                                               *
    FORM BUILD_LAYOUT USING P_LAYOUT TYPE SLIS_LAYOUT_ALV.
      P_LAYOUT-F2CODE       = F2CODE.
      P_LAYOUT-ZEBRA        = 'X'.
    p_layout-detail_popup = 'X'.
      P_LAYOUT-TOTALS_TEXT  = SPACE.
      P_LAYOUT-SUBTOTALS_TEXT = SPACE.
    ENDFORM.                               " BUILD_LAYOUT
          FORM BUILD_PRINT                                              *
    STANDARD PRINT OPTIONS                                             *
    -->  P_PRINT                                                       *
    FORM BUILD_PRINT USING P_PRINT TYPE SLIS_PRINT_ALV.
      P_PRINT-NO_PRINT_LISTINFOS = 'X'.
      P_PRINT-NO_PRINT_SELINFOS  = ' '.
    ENDFORM.                               " BUILD_PRINT
          FORM PF_STATUS_SET                                            *
    NAME YOUR STATUS ALV. IF YOU NEED IT..                             *
    FORM PF_STATUS_SET USING EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'ALV' EXCLUDING EXTAB.
    ENDFORM.                               " PF_STATUS_SET
          FORM USER_COMMAND_SAMPLE                                      *
    -->  UCOMM                                                         *
    -->  SELFIELD                                                      *
    FORM USER_COMMAND_SAMPLE USING UCOMM    LIKE SY-UCOMM
                               SELFIELD TYPE SLIS_SELFIELD.
      CASE UCOMM.
        WHEN 'MSXL'.                       " Export to Excel
         perform set_excel_export.
          CLEAR UCOMM.
        WHEN 'MM03'.
         set parameter id 'MAT' field selfield-value.
         call transaction 'MM03' and skip first screen.
          CLEAR UCOMM.
        WHEN 'BGR1'.
         perform fill_available.
         perform graph_available.
          CLEAR UCOMM.
        WHEN 'DOCU'.
         call function 'Z_HELP' exporting repname = repname.
      ENDCASE.
    ENDFORM.                               " USER_COMMAND
    *&      Form  WRITE_USING_ALV_SAMPLE
    *THIS IS A SAMPLE AND MUST BE WRITTEN DIRECTLY IN THE MAIN PROGRAM
    FORM WRITE_USING_ALV_SAMPLE.
    YOU CAN MERGE WITH A DATA DICTIONARY TABLE USING THIS:
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
          exporting
               i_program_name     = repname
               i_internal_tabname = 'I'
               i_inclname         = repname
          changing
               ct_fieldcat        = fieldtab.
    if sy-subrc <> 0.
       write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_FIELDCATALOG_MERGE'.
    endif.
    OR JUST DISPLAY IT USING THIS:
    call function 'REUSE_ALV_LIST_DISPLAY'
          exporting
               i_callback_program       = repname
               i_callback_pf_status_set = 'PF_STATUS_SET'
               i_callback_user_command  = 'USER_COMMAND'
               i_structure_name         = 'I'
               is_layout                = layout
               it_fieldcat              = fieldtab
               i_default                = 'A'
               i_save                   = g_save
               is_variant               = g_variant
               it_events                = events[]
               is_print                 = prints
          tables
               t_outtab                 = i.
    if sy-subrc <> 0.
       write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_LIST_DISPLAY'.
    endif.
    ENDFORM.                               " WRITE_USING_ALV
    regards,
    bharat.

  • Error in ALV program

    Hi all,
    for the following code i'm getting a short dump GETWA_NOT_ASSIGNED.
    Can anyone please tell me where exactly is the error.
    REPORT  Z_PK_REPORT10.
    TABLES: ZEMPLOYEE.
    TYPE-POOLS: SLIS.
    DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
    DATA: GT_ZEMPTAB TYPE ZEMPLOYEE OCCURS 0 WITH HEADER LINE.
    DATA: G_REPID LIKE SY-REPID.
    INITIALIZATION.
      G_REPID = SY-REPID.
    START-OF-SELECTION.
    PERFORM FIELDCAT_INIT USING GT_FIELDCAT.
    END-OF-SELECTION.
    SELECT * FROM ZEMPLOYEE INTO TABLE GT_ZEMPTAB.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
              I_CALLBACK_PROGRAM    =   G_REPID
              IT_FIELDCAT           =   GT_FIELDCAT
          TABLES
              T_OUTTAB              =   GT_ZEMPTAB.
    *&      Form  FIELDCAT_INIT
    FORM FIELDCAT_INIT USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
    TABLES: ZEMPLOYEE.
      DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
      DATA: POS TYPE I VALUE 1.
      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-COL_POS         =  POS.
      LS_FIELDCAT-FIELDNAME       =  'EMPLOYEE NO'.
      LS_FIELDCAT-REF_FIELDNAME   =  ZEMPLOYEE-EMPNO.
      LS_FIELDCAT-REF_TABNAME     =  ZEMPLOYEE.
      APPEND LS_FIELDCAT TO  RT_FIELDCAT.
      CLEAR LS_FIELDCAT.
      POS = POS + 1.
      LS_FIELDCAT-COL_POS         =  POS.
      LS_FIELDCAT-FIELDNAME       =  'EMPLOYEE NAME'.
      LS_FIELDCAT-REF_FIELDNAME   =  ZEMPLOYEE-EMPNAME.
      LS_FIELDCAT-REF_TABNAME     = ZEMPLOYEE.
      APPEND LS_FIELDCAT TO  RT_FIELDCAT.
      CLEAR LS_FIELDCAT.
      POS = POS + 1.
      LS_FIELDCAT-COL_POS         =  POS.
      LS_FIELDCAT-FIELDNAME       =  'EMPLOYEE CITY'.
      LS_FIELDCAT-REF_FIELDNAME   =  ZEMPLOYEE-EMPCITY.
      LS_FIELDCAT-REF_TABNAME     =  ZEMPLOYEE.
      APPEND LS_FIELDCAT TO  RT_FIELDCAT.

    GETWA_NOT_ASSIGNED => Some problem with the fieldcatalog. You can easily check the consistency of the ALV..
    Anyways looking at your code i see the problem
    LS_FIELDCAT-COL_POS = POS.
    LS_FIELDCAT-FIELDNAME = 'EMPNO'. "'EMPLOYEE NO'.
    LS_FIELDCAT-REF_FIELDNAME = 'EMPNO'. "ZEMPLOYEE-EMPNO.
    LS_FIELDCAT-REF_TABNAME = 'ZEMPLOYEE'. "ZEMPLOYEE.
    LS_FIELDCAT-SELTEXT_L = 'EMPLOYEE NO'.
    APPEND LS_FIELDCAT TO RT_FIELDCAT.
    BR,
    Suhas
    PS: Check this excellent blog by Rainer on [ALV Consistency Check|/people/rainer.hbenthal/blog/2009/09/25/sos--my-alv-report-is-not-working].

Maybe you are looking for

  • Pricing procedure not to bill customer but revenue recognition

    I'm looking for guidance on how to setup a pricing procedure conditions.   First let me explain the situation.  What happens is the customer buys say 2000 software licenses on a sales order. The customer is billed and the customer account is debited

  • Field and tables hide

    i am doing  msc2n tcode. processorder type:  unrestricted type and restricted type fields not showing. after few days my techincal person do some work. after few days i was got a table and feilds. what is the solution. regards satish

  • Color change when transferring image from Photoshop to After Effects

    Hi everyone, I am trying to import a logo from photoshop CS6 to After Effects CS6, however the black color within the image changes to a dark grey when it gets into AE. I noticed on the color picker in PS that it changes to the same grey color that i

  • Support for IE 11

    My flex application is not support for IE 11 please suggest me with best solution.

  • FM to Update delivery schedule lines in transaction ME38

    Hi All, Please let me know the Function Module to update Schedule agreement, Delivery schedule lines in the transaction ME38. Thanks, Swamy Mantha