How to use ALV Grid?

Hi,
I am totally new to ALV Grids. Could you give a full example of creating a ALV Grid with 2 columns, thinking there is a internal table itab with itab-col1 & itab-col2. Please start from initialising variables and onwards.
Thanks,
Kishan

Hi,
Simple example of how to implement an ALV grid
Note that this example uses table ZSFLIGHT. The table is equivalent to the table SFLIGHT.
Steps:
1.        Create an executable program (Report)
2.        Create a screen (100) and place a custom container named ALV_CONTAINER on the screen
3.        Create a Pushbutton. Give it the text Exit and the functioncode EXIT
REPORT sapmz_hf_alv_grid .
TABLES: zsflight.
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.
G L O B A L   D A T A
DATA: ok_code LIKE sy-ucomm,
g_wa_sflight LIKE sflight.
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.
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.
Create objects
IF go_custom_container IS INITIAL.
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
  i_parent = go_custom_container.
PERFORM load_data_into_grid.
ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&      Form  load_data_into_grid
FORM load_data_into_grid.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
Load data into the grid and display them
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING  it_outtab        = gi_sflight.
ENDFORM.                    " load_data_into_grid
Allow the user to save and reuse the layout
A button can be shown on the grid toolbar, allowing the user to save and reuse a layout. The button looks like this: 
See also example in SAP standard program BCALV_GRID_09.
To do this use the parameters IS_VARIANT and I_SAVE of the set_table_for_first_display method. Note that the IS_VARIANT
parameter must have the structure DISVARIANT.
The I_SAVE "Options for saving layouts" parameter can have the following values:
·        U Only user specific layouts can be saved
·        X Only global layouts can be saved
·        A Both user specific and global layouts can be saved
·        Space Layouts can not be saved
Add the following code to the example:
FORM load_data_into_grid.
DATA:
  For parameter IS_VARIANT
l_layout TYPE disvariant.
Code..........    
Load data into the grid and display them
l_layout-report = sy-repid.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
     is_variant       = l_layout
     i_save           = 'A'
CHANGING  it_outtab        = gi_
Integrate user defined functions in the grid toolbar
Possibilities:
·        Replace existing functions in the toolbar or context men with user defined functions
·        Add new functions to the toolbar or context menu
Note that the whole toolbar can be removed using the IT_TOOLBAR_EXCLUDING parameter of the set_table_for_first_display
method.
See also example in SAP standard program BCALV_GRID_05
1) To get access to the icons insert the following statement in the top of the program:
TYPE-POOLS: icon.
2) To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the start of
the program
To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
3) Declare reference to the event handler class
DATA:
o_event_receiver TYPE REF TO lcl_event_receiver.
4) Class for event receiver. This class adds the new button to the toolbar and handles the event when the button is pushed
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'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
5) In the PBO module, crate object for event handler and set handler
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.
6) In the PBO module after the CALL METHOD go_grid->set_table_for_first_display, raise event
toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid
After CALL METHOD go_grid->set_table_for_first_display insert the following statement:
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
Set the title of the grid
Fill the grid_title field of structure lvc_s_layo.
Note that the structure lvc_s_layo can be used for to customize the grid appearance in many ways.
DATA:
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Set grid title
gs_layout-grid_title = 'Flights'.
CALL METHOD go_grid->set_table_for_first_display
   EXPORTING i_structure_name = 'SFLIGHT'
                           is_layout               = gs_layout
   CHANGING   it_outtab               = gi_sflight.
Customize the appearence of the grid
The structure lvc_s_layo contains fields for setting graphical properties, displaying exceptions, calculating totals and enabling specific
interaction options.
Fill the apporpiate fields of structure lvc_s_layo and insert it as a parameter in the CALL METHOD
go_grid->set_table_for_first_display. See the example under Set the title of the grid.
If you want to change apperance after list output, use the methods get_frontend_layout and set_frontend_layout.
Examples of fields in structure lvc_s_layo:
GRID_TITLE Setting the title of the grid
SEL_MODE. Selection mode, determines how rows can be selected. Can have the following values:
·        A Multiple columns, multiple rows with selection buttons.
·        B Simple selection, listbox, Single row/column
·        C Multiple rows without buttons
·        D Multiple rows with buttons and select all ICON
Setting and getting selected rows (Columns) and read line contents
You can read which rows of the grid that has been selected, and dynamic select rows of the grid using methods get_selected_rows
and set_selected_rows. There are similar methods for columns.
Note that the grid table always has the rows in the same sequence as displayed in the grid, thus you can use the index of the selected
row(s) to read the information in the rows from the table. In the examples below the grid table is named gi_sflight.
Data declaration:
DATA:
Internal table for indexes of selected rows
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
Example 1: Reading index of selected row(s) and using it to read the grid table
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
     textline1 = 'You must choose a valid line'.
EXIT.
ENDIF.
LOOP AT gi_index_rows INTO g_selected_row.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Example 2: Set selected row(s).
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.
ENDIF.
Make an Exception field ( = Traffic lights)
There can be defined a column in the grid for display of traffic lights. This field is of type Char 1, and can contain the following values:
·        1 Red
·        2 Yellow
·        3 Green
The name of the traffic light field is supplied inh the gs_layout-excp_fname used by method set_table_for_first_display.
Example
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
TYPES:  traffic_light TYPE c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
  Set the exception field of the table
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
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.
  Name of the exception field (Traffic light field)
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
  Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
                     is_layout               = gs_layout
CHANGING  it_outtab                 = gi_sflight.
Color a line
The steps for coloring a line i the grid is much the same as making a traffic light.
To color a line the structure of the  table must include a  Char 4 field  for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
      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.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color    = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
                    is_layout                = gs_layout
CHANGING  it_outtab                 = gi_sflight.
Refresh grid display
Use the grid method REFRESH_TABLE_DISPLAY
Example:
CALL METHOD go_grid->refresh_table_display.
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
rgds,
latheesh

Similar Messages

  • How to Display Sub-Columns using ALV Grid

    Hi ,
      Could someone tell me how to display sub-columns under a parent column using ALV Grid. Do we have any standard Program which has this scenario. Please let me know.
    Thanks,
    Abaper.
    Message was edited by:
            ABAP'er

    you can check all with <b>BCALV* or RSDEMO*</b> in SE38 for all Std
    check below
    BCALV_DND_01                   Drag ALV Row to Tree Folder
    BCALV_DND_02                   Drag Icons from Tree to Rows of the Grid
    BCALV_GRID_DND_TREE            ALV Grid: Drag and Drop with ALV Tree
    BCALV_GRID_DND_TREE_SIMPLE     ALV GRID: Drag and drop with ALV tree (simple)
    BCALV_TEST_COLUMN_TREE         Program BCALV_TEST_COLUMN_TREE
    Rewards if useful............
    Minal

  • How to add ALV button using OO in module pool program using ALV grid

    Hello Gurus!!!
                  Want some tips related how to add button using ALV Grid(OO).
    I want to display the button for search, sort ....
                 Please suggest the step -by-step procedure for implementation of these button.
                 I am designing the code for transaction FB03. Header data has been displayed but want to display the line items.
                 Kindly suggest your answers.
    Thanks,
    Sachin

    Hi,
    CLASS SELSCR_APPLICATION DEFINITION DEFERRED.
    CLASS SELSCR_APPLICATION 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.        "SELSCR_APPLICATION DEFINITION
    CLASS SELSCR_APPLICATION IMPLEMENTATION.
      METHOD HANDLE_TOOLBAR.
        DATA: LS_TOOLBAR  TYPE STB_BUTTON.
    append SAVE icon
        CLEAR LS_TOOLBAR.
        MOVE 'SAVE' TO LS_TOOLBAR-FUNCTION.
        MOVE ICON_SYSTEM_SAVE TO LS_TOOLBAR-ICON.
        MOVE 'Save' TO LS_TOOLBAR-QUICKINFO.
        MOVE ' '  TO LS_TOOLBAR-DISABLED.
        APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
        CLEAR LS_TOOLBAR.
      ENDMETHOD.                    "handle_toolbar
      METHOD HANDLE_USER_COMMAND.
        CASE E_UCOMM.
          WHEN 'SAVE'.
              PERFORM UPDATE_FIELDS.
        ENDCASE.
      ENDMETHOD.
    ENDCLASS.                 "SELSCR_APPLICATION IMPLEMENTATION
    these lines should be after calling method SET_TABLE_FOR_FIRST_DISPLAY
    SET HANDLER G_APPLICATION1->HANDLE_TOOLBAR FOR GRID1.
            CALL METHOD grid1->set_toolbar_interactive.
    rgds,
    bharat.

  • Want to display more than 300 charcters in a column using ALV grid display

    Hi Guru's,
    I am trying to display more than 500 charcters in a column using alv grid display but it in the output it is showing only 128 characters. Can you help me to display all the characters in particular column Or is there any limitation in maximum of no of charcters for a column?
    Thanks,
    Radha.

    Hi Paurl,
    Define a work area say
    wa_layout type slis_layout_alv.
    then fill this work area as
    wa_layout-zebra = X
    wa_layout-colwidth_optimize = X.
    wa_layout-max_linesize = 300.
    Then in FM 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    is_layout = wa_layout
    etc.
    you provided this for the field which is displayed in alv grid will have more than 128 characters.
    from this code i want,how it refers to particular field.
    when i mentioned field catalog-OUTPUTLEN = '300'.
    it is not displayed the field morethan 128 characters.
    it only displays 128 characters.
    please provide me clear and breif information with suitable code.
    i am trying what your sending but it is not displayed more than 128 characters.
    if you don't mind please spend for me some time for this and
    give me clear and breif information with suitable code.
    Thanks & Regards,
    Radhakrishna.

  • How to send ALV Grid report to Email?

    hai all,
    How to send ALV Grid report to Email.
    please its very urgent.....

    Hi,
    when u run the Alv, u will button 'Mail Recepiant' in tool bar.When u click it and enter to new screen, go to the Recipient Tab(down) enter ur maild id and click 'Send' button on tool bar.
    or.
    if u want to send the Alv content to mail id thru prg, go thru the following code.
                              TABLES
    TABLES: BSID. " Accounting: Secondary Index for Customers.
                              TYPE-POOLS
    TYPE-POOLS: SLIS.
                              INTERNAL TABLES
        Internal table to hold Customer data.
    DATA: BEGIN OF TB_BSID OCCURS 0,
            BUKRS   LIKE BSID-BUKRS,    " Company code
            KUNNR   LIKE BSID-KUNNR,    " Customer number
            AUGDT   LIKE BSID-AUGDT,    " Clearing Date
            BLDAT   LIKE BSID-BLDAT,    " Doc date in document
            SHKZG   LIKE BSID-SHKZG,    " Debit/credit indicator
            DMBTR   LIKE BSID-DMBTR,    " Amount in local currency
            ZFBDT   LIKE BSID-ZFBDT,    " Baseline date for due date calc
            ZBD1T   LIKE BSID-ZBD1T,    " Cash discount days 1
            ZBD2T   LIKE BSID-ZBD2T,    " Cash discount days 2
            ZBD3T   LIKE BSID-ZBD3T,    " Net Payment Terms Period
            REBZG   LIKE BSID-REBZG,    " No Of the Inv the Tran Belongs to
            REBZT   LIKE BSID-REBZT,    " Follow-On Document Type
          END OF TB_BSID.
        Internal table to hold Open Items.
    DATA: TB_BSID_OPEN LIKE TABLE OF TB_BSID WITH HEADER LINE.
        Internal table to hold Cleared Items.
    DATA: TB_BSAD_CLEAR LIKE TABLE OF TB_BSID WITH HEADER LINE.
        Internal table to hold General Data in Customer Master
    DATA: BEGIN OF TB_KNA1 OCCURS 0,
            KUNNR LIKE KNA1-KUNNR,      " Customer Number
            NAME1 LIKE KNA1-NAME1,      " Name Line 1
            TELF1 LIKE KNA1-TELF1,      " Telephone Number
            ADRNR LIKE KNA1-ADRNR,      " Address
          END OF TB_KNA1.
        Internal table to hold Customer Master (Company Code)
    DATA: BEGIN OF TB_KNB1 OCCURS 0,
            KUNNR LIKE KNB1-KUNNR,     " Customer Number
            BUKRS LIKE KNB1-BUKRS,     " Company code
            ERDAT LIKE KNB1-ERDAT,     " Rec Created Date
            ZAMIB LIKE KNB1-ZAMIB,     " DMS Managed Indicator
          END OF TB_KNB1.
        Internal table to hold Final Output Data
    DATA: BEGIN OF TB_FINAL OCCURS 0,
            KUNNR           LIKE KNA1-KUNNR, " Customer Number
            NAME1           LIKE KNA1-NAME1, " Name Line 1
            ADDRESS1(25)    TYPE C,          " Address line 1
            ADDRESS2(25)    TYPE C,          " Address line 2
            ADDRESS3(25)    TYPE C,          " Address line 3
            ADDRESS4(25)    TYPE C,          " Address line 4
            PHONE           LIKE KNA1-TELF1, " Telephone Number
            DAYS_SLOW(3)    TYPE C,          " Days Slow
            LAST_DATE(8)    TYPE C,          " Date of Last Invoice
            AVG(4)          TYPE C,          " Average Days to Pay
            CURRENT(10)     TYPE N,          " Current
            AVG_1_30(10)    TYPE N,          " 1-30 past due
            AVG_31_60(10)   TYPE N,          " 31-60 past due
            AVG_61_90(10)   TYPE N,          " 61-90 past due
            AVG_90G(10)     TYPE N,          " 90+ past due
          END OF TB_FINAL.
         ALV Internal tables
    DATA : TB_FIELDCAT       TYPE SLIS_T_FIELDCAT_ALV,  " Field Catalog
           TB_EVENTS         TYPE SLIS_T_EVENT,         " ALV Events
           TB_COMMENTS       TYPE SLIS_T_LISTHEADER.    " Comment
        Internal tables for the sending mail data
    DATA: TB_OBJPACK  TYPE SOPCKLSTI1 OCCURS 2  WITH HEADER LINE,
          TB_OBJHEAD  TYPE SOLISTI1   OCCURS 1  WITH HEADER LINE,
          TB_OBJTXT   TYPE SOLISTI1   OCCURS 10 WITH HEADER LINE,
          TB_RECLIST  TYPE SOMLRECI1  OCCURS 5  WITH HEADER LINE,
          TB_OBJBIN   LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
          TB_DOC_CHNG TYPE SODOCCHGI1.
        Internal table to get mail Receivers Address
    DATA: TB_ZRECEIVE LIKE YSMTP_ADDRESS OCCURS 0 WITH HEADER LINE.
                               STRUCTURES
    DATA: X_SADR            TYPE SADR,                 " For Address
          X_FIELDCAT        TYPE SLIS_FIELDCAT_ALV,    " For Field Catalog
          X_LAYOUT          TYPE SLIS_LAYOUT_ALV,      " For Layout
          X_EVENTS          TYPE SLIS_ALV_EVENT,       " For Events
          X_COMMENTS        TYPE SLIS_LISTHEADER,      " For Comments
          X_ADDR1_SEL       LIKE ADDR1_SEL,            " For Address
          WA_FAEDE          TYPE FAEDE.                " For FAEDE struct
                               VARIABLES
    DATA: G_REPID        LIKE SY-REPID,             " Prog ID
          G_DAYS_SLOW(3) TYPE N,                    " Days Slow
          G_OPEN         TYPE I,                    " Counter
          G_AVG(4)       TYPE C,                    " Avg Days
          G_COUNT        TYPE I,                    " Counter
          G_TITLE        TYPE SOLISTI1-LINE,        " Description
          G_TAB_LINES    TYPE SY-TABIX,             " Internal data count
          G_REC_COUNT    TYPE I,                    " Total records
          G_CURR_BAL     TYPE N,                    " Account balance
          G_FILE_NAME    LIKE EDI_PATH-PTHNAM.      " Output File Name
                               CONSTANTS
    CONSTANTS: C_D            TYPE C VALUE 'D',     " Account type
               C_X            TYPE C VALUE 'X',     " Check Value
               C_0(4)         TYPE N VALUE '0.00',  " Constant for char
               C_1(2)         TYPE C VALUE '01',    " Posting key const
               C_H            TYPE C VALUE 'H',     " For Commenet-Type
               C_TXT(3)       TYPE N VALUE 'TXT',   " File type
               C_RAW(3)       TYPE C VALUE 'RAW',   " File type
               C_DELIMITER    TYPE X VALUE '09',    " ASCII CODE LINE
               C_TOP_OF_PAGE  TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
               C_INTERFACE    TYPE YWFSALOFFICNOTIF-INTERFACE_ID VALUE 'AP',
               C_FILENAME(20) TYPE N VALUE 'TEXT.TXT'," File name
               C_TITLE(30)    TYPE N VALUE 'Z21614_DB_CREDIT_AGENCY',
               C_Z001 TYPE RF035-RASID VALUE 'Z001'." Net 30/60/90/120/150
                               SELECTION SCREEN.
    Selection Screen for Selection Criteria.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-T01.
    SELECT-OPTIONS:  S_BUKRS FOR  BSID-BUKRS OBLIGATORY,    " Company Code
                     S_BLDAT FOR  BSID-BLDAT," OBLIGATORY,  " Doc Date
                     S_KUNNR FOR  BSID-KUNNR,               " Cust No
                     S_ZUONR FOR  BSID-ZUONR.               " Assignment
    PARAMETERS:      P_GRACE(2)   TYPE N OBLIGATORY,        " Grace Days
                     P_ZAMIB LIKE KNB1-ZAMIB AS CHECKBOX.   " DMS Indicator
    SELECTION-SCREEN END OF BLOCK B1.
    Selection Screen for Output Options.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-T02.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 01.
    PARAMETERS: P_REPORT RADIOBUTTON GROUP R1.             " Report Only
    SELECTION-SCREEN COMMENT 5(25) TEXT-016.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 01.
    PARAMETERS: P_DOWN RADIOBUTTON GROUP R1.               " Dwnld to Unix
    SELECTION-SCREEN COMMENT 5(25) TEXT-017.
    SELECTION-SCREEN POSITION 30.
    PARAMETERS: P_FILE LIKE FILENAME-FILEINTERN DEFAULT
                                 'Z21614_DB_CREDIT_AGENCY'. " File Name
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
    Selection Screen for E-mail.
    SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-T03.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 01.
    PARAMETERS: P_EMAIL AS CHECKBOX.                        " E-mail
    SELECTION-SCREEN COMMENT 5(25) TEXT-018.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B3.
                               INITIALIZATION
    INITIALIZATION.
      G_REPID = SY-REPID.
                   AT SELECTION SCREEN.                                  *
    AT SELECTION-SCREEN.
    Validation of selection screen entries
    perform validate_data.
                               START-OF-SELECTION
    START-OF-SELECTION.
    Select Data from Customer Master (Company Code)
      PERFORM SELECT_KNB1.
    Select Custmer Open Items.
      PERFORM SELECT_CUSTOMER_OPEN_ITEMS.
    Select Custmer Cleared Items.
      PERFORM SELECT_CUSTOMER_CLEARED_ITEMS.
    Select General Data in Customer Master
      PERFORM SELECT_KNA1.
    Populate Final Output Data.
      PERFORM POPULATE_TB_FINAL.
                       End of selection                                  *
    END-OF-SELECTION.
    If both display report and send email is checked
      IF P_REPORT = C_X AND P_EMAIL  = C_X.
        MESSAGE E999 WITH
          'Select One Among Report Only & Send E-mail'(023).
    When Radiobutton for Email or if the program is run background
      ELSEIF ( P_EMAIL = C_X OR SY-BATCH = C_X ).
      To send the mail
        PERFORM SEND_EMAIL.
      ELSEIF P_REPORT = C_X .
      To display the Final Output data using ALV's
        PERFORM DISPLAY_ALV_REPORT.
      ENDIF.
    Transfering data to file when downloading to Unix
      IF P_DOWN = C_X.
        IF G_REC_COUNT IS INITIAL.
          MESSAGE I999 WITH
            'No Records Found For Selection Criteria'(024).
          EXIT.
        ELSE.
          IF NOT G_FILE_NAME IS INITIAL.
          Trasefering data to file
            PERFORM TRANSFER_DATA_FILE.
          Interface Audit report
            PERFORM WRITE_REPORT.
          ENDIF.
        ENDIF.
      ENDIF.
                              F O R M S
    *&      Form  VALIDATE_DATA
          Validating selection-screen entries
    FORM VALIDATE_DATA.
    Local variables
      DATA : L_BUKRS LIKE BSEG-BUKRS,          " For Company Code
             L_KUNNR LIKE BSEG-KUNNR.          " For Customer Number
    Validate the Company code.
      SELECT SINGLE BUKRS
        INTO L_BUKRS
        FROM T001
       WHERE BUKRS IN S_BUKRS.
      IF SY-SUBRC <> 0.
        MESSAGE E999 WITH 'Enter valid Company Code'(025).
      ENDIF.
    Validate the Customer number
      IF NOT S_KUNNR[] IS INITIAL.
        SELECT SINGLE KUNNR
          INTO L_KUNNR
          FROM KNA1
         WHERE KUNNR IN S_KUNNR.
        IF SY-SUBRC <> 0.
          MESSAGE E999 WITH 'Enter valid Customer Number'(026).
        ENDIF.
      ENDIF.
    ENDFORM.                    " VALIDATE_DATA
    *&      Form  SELECT_KNB1
          Select Data from Customer Master (Company Code)
    FORM SELECT_KNB1 .
      CLEAR: TB_KNB1,
             TB_KNB1[].
      SELECT KUNNR
             BUKRS
             ERDAT
             ZAMIB
             FROM KNB1
             INTO TABLE TB_KNB1
             WHERE BUKRS IN S_BUKRS
               AND KUNNR IN S_KUNNR.
      IF SY-SUBRC = 0.
      Sort TB_KNB1 by Customer no & Rec Created Date
        SORT TB_KNB1 BY KUNNR ERDAT DESCENDING.
      ENDIF.
    ENDFORM.                    " SELECT_KNB1
    *&      Form  SELECT_CUSTOMER_OPEN_ITEMS
          Select Custmer Open Items.
    FORM SELECT_CUSTOMER_OPEN_ITEMS .
      CLEAR: TB_BSID,
             TB_BSID[].
      SELECT  A~BUKRS
              B~KUNNR
              B~AUGDT
              B~BLDAT
              B~SHKZG
              B~DMBTR
              B~ZFBDT
              B~ZBD1T
              B~ZBD2T
              B~ZBD3T
              B~REBZG
              B~REBZT
         INTO TABLE TB_BSID
         FROM BKPF AS A JOIN BSID AS B
           ON ABUKRS = BBUKRS
          AND ABELNR = BBELNR
          AND AGJAHR = BGJAHR
        WHERE A~BUKRS IN S_BUKRS
          AND A~BLDAT IN S_BLDAT
          AND B~KUNNR IN S_KUNNR
          AND B~ZUONR IN S_ZUONR
          AND B~BSCHL = C_1.
      IF SY-SUBRC = 0.
      DMS Managed Indicator  = ‘X’.
        IF P_ZAMIB = C_X.
          LOOP AT TB_KNB1 WHERE ZAMIB = SPACE.
            DELETE TB_BSID WHERE BUKRS = TB_KNB1-BUKRS
                             AND KUNNR = TB_KNB1-KUNNR.
          ENDLOOP.
        ENDIF.
      Transfering Open Items from TB_BSID to TB_BSID_OPEN
        TB_BSID_OPEN[] = TB_BSID[].
      ENDIF.
    ENDFORM.                    " SELECT_CUSTOMER_OPEN_ITEMS
    *&      Form  SELECT_CUSTOMER_CLEARED_ITEMS
          Select Custmer Cleared Items.
    FORM SELECT_CUSTOMER_CLEARED_ITEMS .
      CLEAR: TB_BSAD_CLEAR,
             TB_BSAD_CLEAR[].
      SELECT   A~BUKRS
               B~KUNNR
               B~AUGDT
               B~BLDAT
               B~SHKZG
               B~DMBTR
               B~ZFBDT
               B~ZBD1T
               B~ZBD2T
               B~ZBD3T
               B~REBZG
               B~REBZT
          INTO TABLE TB_BSAD_CLEAR
          FROM BKPF AS A JOIN BSAD AS B
            ON ABUKRS = BBUKRS
          AND  ABELNR = BBELNR
          AND  AGJAHR = BGJAHR
         WHERE A~BUKRS IN S_BUKRS
           AND A~BLDAT IN S_BLDAT
           AND B~KUNNR IN S_KUNNR
           AND B~ZUONR IN S_ZUONR
           AND B~BSCHL = C_1.
      IF SY-SUBRC = 0.
      DMS Managed Indicator = ‘X’.
        IF P_ZAMIB = C_X.
          LOOP AT TB_KNB1 WHERE ZAMIB = SPACE.
            DELETE TB_BSID WHERE BUKRS = TB_KNB1-BUKRS
                             AND KUNNR = TB_KNB1-KUNNR.
          ENDLOOP.
        ENDIF.
      Sort TB_BSID_CLEAR by Customer number
        SORT TB_BSAD_CLEAR BY KUNNR.
      ENDIF.
    Append lines of TB_BSID_CLEAR to table TB_BSID
      APPEND LINES OF TB_BSAD_CLEAR TO TB_BSID.
    Sort TB_BSID by Cust num AND Doc date in document
      SORT TB_BSID BY KUNNR BLDAT.
    ENDFORM.                    " SELECT_CUSTOMER_CLEARED_ITEMS
    *&      Form  SELECT_KNA1
          Select General Data in Customer Master
    FORM SELECT_KNA1.
      CLEAR: TB_KNA1,
             TB_KNA1[].
      SELECT  KUNNR
              NAME1
              TELF1
              ADRNR
         INTO TABLE TB_KNA1
         FROM KNA1
        WHERE KUNNR IN S_KUNNR.
      IF SY-SUBRC <> 0.
      ENDIF.
    ENDFORM.                    " SELECT_KNA1
    *&      Form  POPULATE_TB_FINAL
          Populate Final Output Data.
    FORM POPULATE_TB_FINAL.
    Local variable
      DATA: L_DAYS_SLOW(3) TYPE N.       " Days Slow
      CLEAR: TB_FINAL,
             TB_FINAL[].
      LOOP AT TB_KNA1.
      Move-corresponding TB_KNA1 to TB_FINAL.
        TB_FINAL-KUNNR = TB_KNA1-KUNNR.  " Customer Number
        TB_FINAL-NAME1 = TB_KNA1-NAME1.  " Name Line 1
        TB_FINAL-PHONE = TB_KNA1-TELF1.  " Telephone Number
      To get Customer Address.
        PERFORM GET_CUSTOMER_ADDRESS.
      To get Date of Last Invoice.
        READ TABLE TB_BSID WITH KEY KUNNR = TB_KNA1-KUNNR.
        IF SY-SUBRC = 0.
          TB_FINAL-LAST_DATE = TB_BSID-BLDAT.
        ENDIF.
      To get past due and current details.
        PERFORM GET_PAST_DUE_CURRENT.
      To get Days Slow.
        CLEAR WA_FAEDE .
        LOOP AT TB_BSID_OPEN WHERE KUNNR = TB_KNA1-KUNNR.
          WA_FAEDE-SHKZG = TB_BSID-SHKZG.
          WA_FAEDE-ZFBDT = TB_BSID-ZFBDT.
          WA_FAEDE-ZBD1T = TB_BSID-ZBD1T.
          WA_FAEDE-ZBD2T = TB_BSID-ZBD2T.
          WA_FAEDE-ZBD3T = TB_BSID-ZBD3T.
          WA_FAEDE-REBZG = TB_BSID-REBZG.
          WA_FAEDE-REBZT = TB_BSID-REBZT.
          WA_FAEDE-KOART = C_D.
        To Determine Due Date.
          CALL FUNCTION 'DETERMINE_DUE_DATE'
               EXPORTING
                    I_FAEDE                    = WA_FAEDE
               IMPORTING
                    E_FAEDE                    = WA_FAEDE
               EXCEPTIONS
                    ACCOUNT_TYPE_NOT_SUPPORTED = 1
                    OTHERS                     = 2.
          IF SY-SUBRC <> 0.
            CLEAR WA_FAEDE.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CLEAR: L_DAYS_SLOW.
          L_DAYS_SLOW = SY-DATUM - WA_FAEDE-NETDT - P_GRACE.
          G_DAYS_SLOW = G_DAYS_SLOW + ABS( L_DAYS_SLOW ).
          G_OPEN      = G_OPEN + 1.
        ENDLOOP.
        IF G_OPEN IS INITIAL.
          TB_FINAL-DAYS_SLOW = G_DAYS_SLOW / G_OPEN.  " Days Slow
        ENDIF.
      To get Average days to Pay.
        PERFORM GET_AVG_DAYS_PAY.
      Calculating total records .
        G_REC_COUNT = G_REC_COUNT + 1.
        APPEND TB_FINAL.
        CLEAR  TB_FINAL.
      ENDLOOP.
    Current account balance.
      G_CURR_BAL   = TB_FINAL-CURRENT + TB_FINAL-AVG_1_30  +
                                        TB_FINAL-AVG_31_60 +
                                        TB_FINAL-AVG_61_90 +
                                        TB_FINAL-AVG_90G   .
    ENDFORM.                    " POPULATE_TB_FINAL
    *&      Form  GET_PAST_DUE_CURRENT
          To get past due and current details.
    FORM GET_PAST_DUE_CURRENT.
        Local Varaibles.
      DATA: L_RF035_SFAE1 TYPE RF035-SFAE1,
            L_RF035_SFAE2 TYPE RF035-SFAE2,
            L_RF035_SFAE3 TYPE RF035-SFAE3,
            L_RF035_SFAE4 TYPE RF035-SFAE4,
            L_RF035_SFAE5 TYPE RF035-SFAE5,
            L_RF035_SFAE6 TYPE RF035-SFAE6,
            L_RF035_SFAEL TYPE RF035-SFAEL,
            L_RF035_SNFA1 TYPE RF035-SNFA1,
            L_RF035_SNFA2 TYPE RF035-SNFA2,
            L_RF035_SNFA3 TYPE RF035-SNFA3,
            L_RF035_SNFA4 TYPE RF035-SNFA4,
            L_RF035_SNFA5 TYPE RF035-SNFA5,
            L_RF035_SNFA6 TYPE RF035-SNFA6,
            L_RF035_SNFAE TYPE RF035-SNFAE.
      LOOP AT TB_KNB1 WHERE KUNNR = TB_KNA1-KUNNR.
        CALL FUNCTION 'CUSTOMER_DUE_DATE_ANALYSIS'
             EXPORTING
                  BUKRS          = TB_KNB1-BUKRS
                KKBER          = ' '
                  KUNNR          = TB_KNB1-KUNNR
                  RASID          = C_Z001
             IMPORTING
                  SFAE1          = L_RF035_SFAE1
                  SFAE2          = L_RF035_SFAE2
                  SFAE3          = L_RF035_SFAE3
                  SFAE4          = L_RF035_SFAE4
                  SFAE5          = L_RF035_SFAE5
                  SFAE6          = L_RF035_SFAE6
                  SFAEL          = L_RF035_SFAEL
                  SNFA1          = L_RF035_SNFA1
                  SNFA2          = L_RF035_SNFA2
                  SNFA3          = L_RF035_SNFA3
                  SNFA4          = L_RF035_SNFA4
                  SNFA5          = L_RF035_SNFA5
                  SNFA6          = L_RF035_SNFA6
                  SNFAE          = L_RF035_SNFAE
             EXCEPTIONS
                  INVALID_RASTER = 1
                  NO_OPEN_ITEMS  = 2
                  OTHERS         = 3
        IF SY-SUBRC = 0.
          TB_FINAL-AVG_1_30  = TB_FINAL-AVG_1_30  + L_RF035_SFAE1.
          TB_FINAL-AVG_31_60 = TB_FINAL-AVG_31_60 + L_RF035_SFAE2.
          TB_FINAL-AVG_61_90 = TB_FINAL-AVG_61_90 + L_RF035_SFAE3.
          TB_FINAL-AVG_90G   = TB_FINAL-AVG_90G   + L_RF035_SFAE4
                                                  + L_RF035_SFAE5
                                                  + L_RF035_SFAE6.
          TB_FINAL-CURRENT  = TB_FINAL-CURRENT    + L_RF035_SNFAE.
        ELSE.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " GET_PAST_DUE_CURRENT
    *&      Form  GET_CUSTOMER_ADDRESS
          To get Customer Address.
    FORM GET_CUSTOMER_ADDRESS.
      X_ADDR1_SEL-ADDRNUMBER = TB_KNA1-ADRNR.
      CALL FUNCTION 'ADDR_GET'
           EXPORTING
                ADDRESS_SELECTION = X_ADDR1_SEL
           IMPORTING
                SADR              = X_SADR
           EXCEPTIONS
                PARAMETER_ERROR   = 1
                ADDRESS_NOT_EXIST = 2
                VERSION_NOT_EXIST = 3
                INTERNAL_ERROR    = 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.
      ADDRESS LINE 1.
      TB_FINAL-ADDRESS1 = X_SADR-STRAS.
      ADDRESS LINE 2.
      CONCATENATE X_SADR-PFACH 'CODE' X_SADR-PSTL2 INTO TB_FINAL-ADDRESS2
                                                      SEPARATED BY SPACE.
      ADDRESS LINE 3.
      CONCATENATE  X_SADR-ORT01 X_SADR-ORT02 ',' X_SADR-REGIO X_SADR-PSTLZ
                                INTO TB_FINAL-ADDRESS3 SEPARATED BY SPACE.
      ADDRESS LINE 4.
      TB_FINAL-ADDRESS4 = X_SADR-LAND1.
    ENDFORM.                    " GET_CUSTOMER_ADDRESS
    *&      Form  GET_AVG_DAYS_PAY
          To get Average days to Pay.
    FORM GET_AVG_DAYS_PAY.
    *Local variable
      DATA: L_DAYS TYPE N .                            " Number of Days
      LOOP AT TB_BSAD_CLEAR WHERE KUNNR = TB_KNA1-KUNNR.
        L_DAYS  = TB_BSAD_CLEAR-AUGDT - TB_BSAD_CLEAR-BLDAT.
        G_AVG   = G_AVG + L_DAYS.
        G_COUNT = G_COUNT + 1.
      ENDLOOP.
      IF NOT G_COUNT IS INITIAL.
        TB_FINAL-AVG = G_AVG / G_COUNT. " Average days to Pay.
      ENDIF.
    ENDFORM.                    " GET_AVG_DAYS_PAY
    *&      Form  DISPLAY_ALV_REPORT
          text
    FORM DISPLAY_ALV_REPORT.
    For Populating Field Catalog.
      PERFORM RPT_BUILD_FIELDCATLOG.
    For Modifying Field Catalog.
      PERFORM RPT_MODIFY_FIELDCATLOG.
    For TOP_OF_PAGE Event.
      PERFORM RPT_GET_EVENTS.
    For Displaying Output in Grid Format.
      PERFORM RPT_GRID_DISPLAY.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  RPT_BUILD_FIELDCATLOG
          text
    FORM RPT_BUILD_FIELDCATLOG.
    To build the Field Catlog.
      DATA : L_TABNAME TYPE SLIS_TABNAME.  " Table Name
      L_TABNAME = 'TB_FINAL'.
      REFRESH : TB_FIELDCAT.
      CLEAR   : TB_FIELDCAT.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                I_PROGRAM_NAME         = G_REPID
                I_INTERNAL_TABNAME     = L_TABNAME
                I_INCLNAME             = G_REPID
           CHANGING
                CT_FIELDCAT            = TB_FIELDCAT
           EXCEPTIONS
                INCONSISTENT_INTERFACE = 1
                PROGRAM_ERROR          = 2
                OTHERS                 = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " RPT_BUILD_FIELDCATLOG
    *&      Form  RPT_MODIFY_FIELDCATLOG
          text
    FORM RPT_MODIFY_FIELDCATLOG.
    Getting the Header Text for the Coloumns
      DATA : L_TABIX LIKE SY-TABIX,            " Index
             L_DDICTXT TYPE C  VALUE 'L'.      " Flag
    Getting the Header Text for the Coloumns
      LOOP AT TB_FIELDCAT INTO X_FIELDCAT.
        CLEAR L_TABIX.
        L_TABIX = SY-TABIX.
        CASE X_FIELDCAT-FIELDNAME.
          WHEN 'KUNNR'.                                   " Customer Number
            X_FIELDCAT-SELTEXT_L = 'Customer Number'(001).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'NAME1'.                                   " Name Line 1
            X_FIELDCAT-SELTEXT_L = 'Name'(002).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'ADDRESS1'.                                " Address line 1
            X_FIELDCAT-SELTEXT_L = 'Address 1'(003).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'ADDRESS2'.                                " Address line 2
            X_FIELDCAT-SELTEXT_L = 'Address 2'(004).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'ADDRESS3'.                                " Address line 3
            X_FIELDCAT-SELTEXT_L = 'Address 3'(005).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'ADDRESS4'.                                " Address line 4
            X_FIELDCAT-SELTEXT_L = 'Address 4'(006).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'PHONE'.                                   " Telephone Number
            X_FIELDCAT-SELTEXT_L = 'Telephone Number'(007).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'DAYS_SLOW'.                               " Days Slow
            X_FIELDCAT-SELTEXT_L = 'Days Slow'(008).
            X_FIELDCAT-DDICTXT      =  L_DDICTXT.
          WHEN 'LAST_DATE'.                         " Date of Last Invoice
            X_FIELDCAT-SELTEXT_L = 'Date of Last Invoice'(009).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'AVG'.                               " Average Days to Pay
            X_FIELDCAT-SELTEXT_L = 'Average Days to Pay'(010).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'CURRENT'.                  " Current
            X_FIELDCAT-SELTEXT_L = 'Aging Category 1'(011).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'AVG_1_30'.                  " 1-30 past due
            X_FIELDCAT-SELTEXT_L = 'Aging Category 2'(012).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'AVG_31_60'.                  " 31-60 past due
            X_FIELDCAT-SELTEXT_L = 'Aging Category 3'(013).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'AVG_61_90'.                  " 61-90 past due
            X_FIELDCAT-SELTEXT_L = 'Aging Category 4'(014).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
          WHEN 'AVG_90G'.                  " 90+ past due
            X_FIELDCAT-SELTEXT_L = 'Aging Category 5'(015).
            X_FIELDCAT-DDICTXT   =  L_DDICTXT.
        ENDCASE.
        MODIFY TB_FIELDCAT FROM X_FIELDCAT INDEX L_TABIX.
      ENDLOOP.
    ENDFORM.                    " RPT_MODIFY_FIELDCATLOG
    *&      Form  RPT_GET_EVENTS
          text
    FORM RPT_GET_EVENTS.
      DATA : L_TABIX TYPE SY-TABIX.                " Index
      CLEAR   : TB_EVENTS,
                TB_EVENTS[].
    To get the events from this function module
    for ALV display
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           EXPORTING
                I_LIST_TYPE     = 0
           IMPORTING
                ET_EVENTS       = TB_EVENTS
           EXCEPTIONS
                LIST_TYPE_WRONG = 1
                OTHERS          = 2.
      IF SY-SUBRC <> 0.
        MESSAGE I999 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Modifing Top of Page event
      READ TABLE TB_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
                          INTO X_EVENTS.
      IF SY-SUBRC = 0.
        CLEAR L_TABIX.
        L_TABIX = SY-TABIX.
        X_EVENTS-FORM = C_TOP_OF_PAGE.
        MODIFY TB_EVENTS FROM X_EVENTS INDEX L_TABIX.
        CLEAR  X_EVENTS.
      ENDIF.
    ENDFORM.                    " RPT_GET_EVENTS
    *&      Form  TOP_OF_PAGE
          Top Of Page for the ALV format
    FORM  TOP_OF_PAGE.
      REFRESH TB_COMMENTS.
    For heading
      CLEAR   X_COMMENTS.
      X_COMMENTS-TYP  = C_H.
      X_COMMENTS-INFO = 'D&B Credit Agency Interface'(019).
      APPEND X_COMMENTS TO TB_COMMENTS.
    This module outputs formatted simple header information at TOP-OF-PAGE
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                IT_LIST_COMMENTARY = TB_COMMENTS.
    ENDFORM.                          " TOP_OF_PAGE
    *&      Form  RPT_GRID_DISPLAY
          text
    FORM RPT_GRID_DISPLAY.
    Layout Settings
      CLEAR X_LAYOUT.
      X_LAYOUT-ZEBRA = 'X'.
      X_LAYOUT-COLWIDTH_OPTIMIZE = C_X.
      X_LAYOUT-NO_COLHEAD        = SPACE.
    To Display the Output in ALV Format
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM = G_REPID
                IS_LAYOUT          = X_LAYOUT
                IT_FIELDCAT        = TB_FIELDCAT
                IT_EVENTS          = TB_EVENTS
           TABLES
                T_OUTTAB           = TB_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.                    " RPT_GRID_DISPLAY
    *&      Form  SEND_EMAIL
          text
    -->  p1        text
    <--  p2        text
    FORM SEND_EMAIL.
    Prepare the mail
      PERFORM SEND_MAIL USING C_INTERFACE.
    Sending the mail to Receivers
      PERFORM SENDING_MAIL.
    ENDFORM.                    " SEND_EMAIL
    *&      Form  SEND_MAIL
         Sending the Mail
    FORM SEND_MAIL USING  P_C_INTERFACE TYPE YWFSALOFFICNOTIF-INTERFACE_ID.
    Populating Report name
      G_TITLE = C_TITLE.
      PERFORM POPULATE_EMAIL_REF_DATA USING G_TITLE.
      IF NOT G_REC_COUNT IS INITIAL.
      To populate the data to table tb_objbin
        PERFORM POPULATE_DATA_OBJBIN.
      To get the attached file for the mail
        CLEAR G_TAB_LINES.
        DESCRIBE TABLE TB_OBJBIN LINES G_TAB_LINES.
        TB_OBJHEAD = C_FILENAME.
        APPEND TB_OBJHEAD.
        CLEAR TB_OBJHEAD.
      Creation of the entry for the mail
        TB_OBJPACK-TRANSF_BIN = C_X.
        TB_OBJPACK-HEAD_START = C_1.
        TB_OBJPACK-HEAD_NUM   = C_1.
        TB_OBJPACK-BODY_START = C_1.
        TB_OBJPACK-BODY_NUM   = G_TAB_LINES.
        TB_OBJPACK-DOC_TYPE   = C_TXT.
        TB_OBJPACK-OBJ_NAME   = G_REPID.
        TB_OBJPACK-OBJ_DESCR  = 'Interface Audit Report'(020).
        TB_OBJPACK-DOC_SIZE   = G_TAB_LINES * 255.
        APPEND TB_OBJPACK.
      ENDIF.
    ENDFORM.                    " SEND_MAIL
    *&      Form  SENDING_MAIL
    FORM SENDING_MAIL.
    Function Module to send mail along with attached file
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           EXPORTING
                DOCUMENT_DATA              = TB_DOC_CHNG
           TABLES
                PACKING_LIST               = TB_OBJPACK
                OBJECT_HEADER              = TB_OBJHEAD
                CONTENTS_BIN               = TB_OBJBIN
                CONTENTS_TXT               = TB_OBJTXT
                RECEIVERS                  = TB_RECLIST
           EXCEPTIONS
                TOO_MANY_RECEIVERS         = 1
                DOCUMENT_NOT_SENT          = 2
                DOCUMENT_TYPE_NOT_EXIST    = 3
                OPERATION_NO_AUTHORIZATION = 4
                PARAMETER_ERROR            = 5
                X_ERROR                    = 6
                ENQUEUE_ERROR              = 7
                OTHERS                     = 8.
      CASE SY-SUBRC.
        WHEN 0.
          MESSAGE S999 WITH 'Mail has been sucessfully sent'(029).
        WHEN 1.
          MESSAGE S999 WITH 'Too Many Parameters'(030).
        WHEN 2.
          MESSAGE S999 WITH 'Doc Could Not Be Sent'(031).
        WHEN 4.
          MESSAGE S999 WITH 'No Authority To Send'(032).
        WHEN 99.
          MESSAGE S999 WITH 'Error While Sending'(033).
      ENDCASE.
    ENDFORM.                    " SENDING_MAIL
    *&      Form  POPULATE_EMAIL_REF_DATA
       Poplulating the body of the mail
    FORM POPULATE_EMAIL_REF_DATA USING TEXT TYPE SOLISTI1-LINE.
    Setting up Mail Subject
      TB_DOC_CHNG-OBJ_DESCR = 'Interface Audit Report'(020).
    Populating body of the mail
      TB_OBJTXT-LINE = 'Interface Audit Report'(020).
      APPEND TB_OBJTXT.
      CLEAR: TB_OBJTXT.
      DESCRIBE TABLE TB_OBJTXT LINES G_TAB_LINES.
      READ TABLE TB_OBJTXT INDEX G_TAB_LINES.
    *To determine the document size
    TB_DOC_CHNG-DOC_SIZE = ( G_TAB_LINES - 1 ) * 255 + STRLEN( TB_OBJTXT ).
    Creation of the entry for the Mail Contents
      CLEAR TB_OBJPACK-TRANSF_BIN.
      TB_OBJPACK-HEAD_START = C_1.
      TB_OBJPACK-HEAD_NUM = C_0.
      TB_OBJPACK-BODY_START = C_1.
      TB_OBJPACK-BODY_NUM = G_TAB_LINES.
      TB_OBJPACK-DOC_TYPE = C_RAW.
      APPEND TB_OBJPACK.
    ENDFORM.                    " POPULATE_EMAIL_REF_DATA
    *&      Form  POPULATE_DATA_OBJBIN
          Populating table for file attachment

  • How to download alv grid output(with field catalog) into excel file format

    Hi all,
    How to download alv grid output(with field catalogs) into excel file format and same file has to download to application server.
    Please help.
    Regards,
    Satya.

    Hi,
    On list where alv is displayed, select export icon( green color -> ),select spread sheet.
    This will display records in Excel sheet.

  • Regarding output using alv grid display

    Hi experts,
        i have a program
    FS_TAB1-A = P_T1.
    IF P_T1 = 0.
      TEMP1 = 1.
      DO TEMP1 TIMES.
        FS_TAB1-A = P_T1 * DUMMY1.
        APPEND FS_TAB1 TO T_TAB1.
        DUMMY1 = DUMMY1  + 1.
      ENDDO.
    now i have to diplay the p_t1*dummy1 using alv grid display like it goes into thew  loop for ten times then i have to show it 10 times like
    10 1  102 103 104 111 112  like that can u help me

    hi,
        you have to get the result of the multiplication at each row and then concatenate the result and the factor to show the final result in multiples value and multiplication factor...

  • How to append ALV grid output to LIST output

    Hi,
    I am working with Basis AUDIT MANUAL report for which i have to integrate around 50 standard transactions (SM37,SM35...etc) output and make it into one single report.
    On execution of my report i have to get all the 50 transaction outputs sequentially.
    Some standard transactions have ALV list display output and some have GRID display.I can able to append only list outputs by submit program and exporting list to memory.
    Please suggest me how to get Alv grid output in midst of list output.
    Regards
    Kalpana.

    You should post your question to the ABAP forum:
    ABAP Development

  • Dynamically change in size of the custom container using ALV GRID (OOPS)

    Hi Gurus!!!!
    I have an issue with the output of the report which is developed using ALV GRID (OOPS). I have used the custom container occupying full screen (Screen painter). When I execute the report using my PC the output displays report as expected in full screen. The problem is when we execute this report in 19 INCH monitor then there is always gap below the report.
    As per my understanding we should have a code to change the size of custom container dynamically.
    Please suggest some help on this.
    Thanks,
    Hemal Shah

    Hi,
    If you set the attributes, Resizing - Vertical and Horizontal for the customer container, than system will resize the size of the custome continer as per the resolution.
    Hope it helps,
    Sumana

  • Require some tutorials to use ALV grids to access database

    I am new to ALV grids
    I want step by step method to use ALV grids in ABAP reports to access database.

    Hi,
    pls go throgugh this link.
    http://www.erpgenie.com/abap/controls/alvgrid.htm
    sample program
    Sample programs on ALV Grid
    report zbnstest.
    TABLES AND DATA DECLARATION.
    *TABLES: mara,makt.",marc.
    data syrepid like sy-repid.
    data sydatum(10). " LIKE sy-datum.
    data sypagno(3) type n.
    WHEN USING MORE THAN ONE TABLE IN ALV WE NEEED TO DECLARE THE TYPE
    GROUP (TYPE-POOLS--------->SLIS)
    type-pools : slis.
    INTERNAL TABLE DECLARATION.
    INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE
    data: begin of t_mara occurs 0,
    matnr like mara-matnr,
    meins like mara-meins,
    mtart like mara-mtart,
    matkl like mara-matkl,
    end of t_mara.
    INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE
    data : begin of t_marc occurs 0,
    matnr like mara-matnr,
    werks like marc-werks,
    minbe like marc-minbe.
    data: end of t_marc.
    INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE.
    data : begin of t_makt occurs 0,
    matnr like mara-matnr,
    maktx like makt-maktx,
    spras like makt-spras,
    end of t_makt.
    INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.
    data: begin of itab1 occurs 0,
    matnr like mara-matnr,
    meins like mara-meins,
    maktx like makt-maktx,
    spras like makt-spras,
    werks like marc-werks,
    minbe like marc-minbe,
    end of itab1.
    THE FOLLOWING DECLARATION IS USED FOR DEFINING THE FIELDCAT
    AND THE LAYOUT FOR THE ALV.
    HERE AS slis_t_fieldcat_alv IS A INTERNAL TABLE WITHOUT A HEADER LINE
    WE EXPLICITELY DEFINE AN INTERNAL TABLE OF THE SAME STRUCTURE AS THAT
    OF slis_t_fieldcat_alv BUT WITH A HEADER LINE IN THE DEFINITION.
    THIS IS DONE TO MAKE THE CODE SIMPLER.
    OTHERWISE WE MAY HAVE TO DEFINE THE STRUCTURE AS IN THE NORMAL SAP
    PROGRAMS.
    IN THE FIELDCATALOG TABLE WE ACTUALLY PASS THE FIELDS FROM ONE OR
    MORE TABLES AND CREATE A STRUCTURE
    IN THE LAYOUT STRUCTURE WE BASICALLY DEFINE THE FORMATTING OPTIONS
    LIKE DISPLAY IN THE ZEBRA PATTERN ,THE HOTSPOT OPTIONS ETC.
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
    fieldlayout type slis_layout_alv.
    DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE
    TOP-OF-PAGE ETC.
    data : eventstab type slis_t_event with header line.
    DECLARING AN INTERNAL TABLE TO HOLD THE DATA FOR THE TOP-OF-PAGE
    data : heading type slis_t_listheader with header line.
    data : heading1 type slis_t_listheader with header line.
    data : heading2 type slis_t_listheader with header line.
    data : heading3 type slis_t_listheader with header line.
    data : heading4 type slis_t_listheader with header line.
    data : heading5 type slis_t_listheader with header line.
    data : heading6 type slis_t_listheader with header line.
    data : heading7 type slis_t_listheader with header line.
    data : heading8 type slis_t_listheader with header line.
    STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY.
    data : colorstruct type slis_coltypes.
    INITIALIZATION. *
    initialization.
    syrepid = sy-repid.
    sypagno = sy-pagno.
    clear fieldcatalog.
    START-OF-SELECTION. *
    start-of-selection.
    SUBROUTINE TO POPULATE THE COLORSTRUCT
    perform fill_colorstruct using colorstruct.
    SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE
    perform populate_fieldcatalog.
    SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE
    INTERNAL TABLE.
    perform selectdata_and_sort.
    SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE.
    perform populate_layout using fieldlayout.
    SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY.
    perform merge_fieldcatalog.
    SUBROUTINE TO POPULATE THE EVENTSTAB.
    perform fill_eventstab tables eventstab.
    SUBROUTINE TO POPULATE THE HEADING TABLES.
    perform fill_headingtable tables heading using 'HEADING'.
    perform fill_headingtable tables heading1 using 'HEADING1'.
    perform fill_headingtable tables heading2 using 'HEADING2'.
    perform fill_headingtable tables heading3 using 'HEADING3'.
    perform fill_headingtable tables heading4 using 'HEADING4'.
    perform fill_headingtable tables heading5 using 'HEADING5'.
    perform fill_headingtable tables heading6 using 'HEADING6'.
    perform fill_headingtable tables heading7 using 'HEADING7'.
    perform fill_headingtable tables heading8 using 'HEADING8'.
    SUBROUTINE TO DISPLAY THE LIST.
    perform display_alv_list.
    FORMS
    IN THIS SUBROUTINE WE POPULATE THE FIELDCATALOG TABLE WITH THE NAMES
    OF THE TABLE,FIELDNAME,WHETHER IT IS KEY FIELD OR NOT,HEADING AND
    COLUMN JUSTIFICATION.
    form populate_fieldcatalog.
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MATNR' 'X' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MEINS' ' '.
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MAKTX' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MTART' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MATKL' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'SPRAS' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'WERKS' ' ' .
    perform fill_fields_of_fieldcatalog tables fieldcatalog
    using 'ITAB1' 'MINBE' ' ' .
    endform. " POPULATE_FIELDCATALOG
    FORM FILL_FIELDS_OF_FIELDCATALOG *
    --> FIELDCATALOG *
    --> P_TABNAME *
    --> P_FIELDNAME *
    --> P_KEY *
    --> P_KEY *
    form fill_fields_of_fieldcatalog tables fieldcatalog
    structure fieldcatalog
    using p_tabname
    p_fieldname
    p_key.
    p_no_out.
    fieldcatalog-tabname = p_tabname.
    fieldcatalog-fieldname = p_fieldname.
    fieldcatalog-key = p_key.
    fieldcatalog-emphasize = '1234'.
    *fieldcatalog-no_out = p_no_out.
    append fieldcatalog.
    endform. " FILL_FIELDSOFFIELDCATALOG
    FORM POPULATE_LAYOUT *
    --> FIELDLAYOUT *
    form populate_layout using fieldlayout type slis_layout_alv.
    fieldlayout-f2code = '&ETA' .
    fieldlayout-zebra = 'X'.
    FOR THE WINDOW TITLE.
    fieldlayout-window_titlebar = 'ALV with Events'.
    fieldlayout-colwidth_optimize = 'X'.
    fieldlayout-no_vline = ' '.
    *fieldlayout-no_input = 'X'.
    fieldlayout-confirmation_prompt = ''.
    fieldlayout-key_hotspot = 'X'.
    This removes the column headings if the flag is set to 'X'
    fieldlayout-no_colhead = ' '.
    *fieldlayout-hotspot_fieldname = 'MAKTX'.
    fieldlayout-detail_popup = 'X'.
    fieldlayout-coltab_fieldname = 'X'.
    endform. " POPULATE_LAYOUT
    FORM SELECTDATA_AND_SORT *
    form selectdata_and_sort.
    select matnr meins mtart matkl from mara
    into corresponding fields of t_mara
    up to 500 rows .
    select matnr maktx spras from makt
    into corresponding fields of t_makt
    where matnr = t_mara-matnr and
    spras = sy-langu.
    select matnr werks minbe from marc
    into corresponding fields of t_marc
    where matnr = t_mara-matnr.
    append t_marc.
    endselect.
    append t_makt.
    endselect.
    append t_mara.
    endselect.
    perform populate_itab1.
    sort itab1 by matnr.
    endform. " SELECTDATA_AND_SORT
    FORM MERGE_FIELDCATALOG *
    form merge_fieldcatalog.
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    exporting
    i_program_name = syrepid
    i_internal_tabname = 'ITAB1'
    i_structure_name = 'COLORSTRUCT'
    I_CLIENT_NEVER_DISPLAY = 'X'
    i_inclname = syrepid
    changing
    ct_fieldcat = fieldcatalog[]
    exceptions
    inconsistent_interface = 1
    program_error = 2
    others = 3.
    endform. " MERGE_FIELDCATALOG
    IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS
    FOLLOWS:-
    i_callback_program --> CALLING PROGRAM NAME
    i_structure_name --> STRUCTURE NAME.
    is_layout --> LAYOUT NAME.
    it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE
    form display_alv_list.
    call function 'REUSE_ALV_LIST_DISPLAY'
    exporting
    I_INTERFACE_CHECK = ' '
    i_callback_program = syrepid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    i_structure_name = 'ITAB1'
    is_layout = fieldlayout
    it_fieldcat = fieldcatalog[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD
    TOOL BAR
    i_save = 'A'
    IS_VARIANT = ' '
    it_events = eventstab[]
    IT_EVENT_EXIT =
    IS_PRINT =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    tables
    t_outtab = itab1
    exceptions
    program_error = 1
    others = 2.
    endform. " DISPLAY_ALV_LIST
    *& Form POPULATE_ITAB1
    text
    --> p1 text
    <-- p2 text
    form populate_itab1.
    loop at t_mara.
    loop at t_makt where matnr = t_mara-matnr.
    loop at t_marc where matnr = t_mara-matnr.
    move-corresponding t_mara to itab1.
    move-corresponding t_makt to itab1.
    move-corresponding t_marc to itab1.
    append itab1.
    endloop.
    endloop.
    endloop.
    endform. " POPULATE_ITAB1
    *& Form FILL_EVENTSTAB
    text
    -->P_EVENTSTAB text *
    form fill_eventstab tables p_eventstab structure eventstab.
    WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE
    INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME.
    AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14
    EVENTS NAME.
    call function 'REUSE_ALV_EVENTS_GET'
    exporting
    i_list_type = 0
    importing
    et_events = p_eventstab[]
    exceptions
    list_type_wrong = 1
    others = 2.
    BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH
    THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW.
    WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER.
    FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM
    IS DYNAMICALY CALLED.
    read table p_eventstab with key name = slis_ev_top_of_page.
    if sy-subrc = 0 .
    move 'TOP_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_top_of_coverpage.
    if sy-subrc = 0 .
    move 'TOP_OF_COVERPAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_coverpage .
    if sy-subrc = 0 .
    move 'END_OF_COVERPAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_foreign_top_of_page.
    if sy-subrc = 0 .
    move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_foreign_end_of_page.
    if sy-subrc = 0 .
    move 'FOREIGN_END_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_list_modify.
    if sy-subrc = 0 .
    move 'LIST_MODIFY' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_top_of_list.
    if sy-subrc = 0 .
    move 'TOP_OF_LIST' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_page.
    if sy-subrc = 0 .
    move 'END_OF_PAGE' to p_eventstab-form.
    append p_eventstab.
    endif.
    read table p_eventstab with key name = slis_ev_end_of_list .
    if sy-subrc = 0 .
    move 'END_OF_LIST' to p_eventstab-form.
    append p_eventstab.
    endif.
    endform. " FILL_EVENTSTAB
    *& Form FILL_HEADINGTABLE
    text
    -->P_HEADING text *
    form fill_headingtable tables p_heading structure heading
    using tablename.
    case tablename.
    when 'HEADING'.
    p_heading-typ = 'H'.
    concatenate
    ' REPORT NAME:-' syrepid
    ' ABB Industry Pte Ltd' into p_heading-info.
    append p_heading.
    write sy-datum using edit mask '__/__/____' to sydatum.
    concatenate
    ' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno
    into p_heading-info.
    append p_heading.
    when 'HEADING1'.
    p_heading-typ = 'H'.
    p_heading-info = 'TOP-OF-COVER-PAGE'.
    append p_heading.
    when 'HEADING2'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-COVER-PAGE'.
    append p_heading.
    when 'HEADING3'.
    p_heading-typ = 'H'.
    p_heading-info = 'FOREIGN-TOP-OF-PAGE'.
    append p_heading.
    when 'HEADING4'.
    p_heading-typ = 'H'.
    p_heading-info = 'FOREIGN-END-OF-PAGE'.
    append p_heading.
    WHEN 'HEADING5'.
    P_HEADING-TYP = 'H'.
    P_HEADING-INFO = 'LIST-MODIFY'.
    APPEND P_HEADING.
    when 'HEADING6'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-PAGE'.
    append p_heading.
    when 'HEADING7'.
    p_heading-typ = 'H'.
    p_heading-info = 'END-OF-LIST'.
    append p_heading.
    when 'HEADING8'.
    p_heading-typ = 'H'.
    p_heading-info = 'TOP-OF-LIST'.
    append p_heading.
    endcase.
    endform. " FILL_HEADINGTABLE
    FORM TOP_OF_PAGE *
    form top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading[]
    exceptions
    others = 1.
    endform.
    *& Form FILL_COLORSTRUCT
    text
    -->P_COLORSTRUCT text *
    form fill_colorstruct using p_colorstruct type slis_coltypes .
    p_colorstruct-heacolfir-col = 6.
    p_colorstruct-heacolfir-int = 1.
    p_colorstruct-heacolfir-inv = 1.
    endform. " FILL_COLORSTRUCT
    FORM TOP_OF_COVERPAGE *
    form top_of_coverpage.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading1[]
    exceptions
    others = 1.
    endform.
    FORM END_OF_COVERPAGE *
    form end_of_coverpage.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading2[]
    exceptions
    others = 1.
    endform.
    FORM FOREIGN_TOP_OF_PAGE *
    form foreign_top_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading3[]
    exceptions
    others = 1.
    endform.
    FORM FOREIGN_END_OF_PAGE *
    form foreign_end_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading4[]
    exceptions
    others = 1.
    endform.
    FORM LIST_MODIFY *
    *FORM LIST_MODIFY.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = HEADING5[]
    EXCEPTIONS
    OTHERS = 1.
    *ENDFORM.
    FORM END_OF_PAGE *
    form end_of_page.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading6[]
    exceptions
    others = 1.
    endform.
    FORM END_OF_LIST *
    form end_of_list.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading7[]
    exceptions
    others = 1.
    endform.
    FORM TOP_OF_LIST *
    form top_of_list.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = heading8[]
    exceptions
    others = 1.
    endform.
    *--- End of Program
    Thanks,
    Shankar

  • How to use alv in progrmm

    hi all
    thanks in advance
    how to use alv in programm please can any one send me simple example of alv
    thanks

    Hi,
    Refer this code. If u find it useful, reward points.
    TYPE-POOLS: slis.
         Data Declaration
    DATA: wa_layout       TYPE slis_layout_alv, "Layout structure
          it_fieldcatalog TYPE slis_t_fieldcat_alv, " Fieldcatlog IT
          wa_fieldcatalog TYPE slis_fieldcat_alv, " Fieldcatlog WA
          lt_event TYPE slis_t_event, "for capturing page events
          ls_event TYPE slis_alv_event. " WA for Page Events
    Data: l_syrep type sy-repid,
          l_tcode type sy-tcode.
    *& I N I T I A L I Z A T I O N                                         *
    INITIALIZATION .
    l_syrep = sy-repid.
    l_tcode = sy-tcode.
    *&               AT SELECTION-SCREEN                                   *
    AT SELECTION-SCREEN.
    *&               START-OF-SELECTION                                    *
    START-OF-SELECTION.
    *&               END-OF-SELECTION                                      *
    END-OF-SELECTION.
       PERFORM build_layout.
       PERFORM build_catlog.
       PERFORM build_events.
    *&               AT LINE-SELECTION                                     *
    AT LINE-SELECTION.
    *&      Form  build_layout
          Building the Layout
    FORM build_layout .
    wa_layout-ZEBRA = 'X'.
    wa_layout-NO_VLINE = 'X'.
    wa_layout-NO_HLINE = 'X'.
    wa_layout-CELL_MERGE = 'X'.
    wa_layout-EDIT = 'X'.
    wa_layout-WINDOW_TITLEBAR = ''.
    wa_layout-NO_ULINE_HS = 'X'.
    wa_layout-LIGHTS_FIELDNAME = ''.
    wa_layout-LIGHTS_TABNAME = ''.
    wa_layout-LIGHTS_ROLLNAME = ''.
    wa_layout-LIGHTS_CONDENSE = 'X'.
    wa_layout-NO_TOTALLINE = 'X'.
    wa_layout-NO_SUBTOTALS = 'X'.
    wa_layout-TOTALS_BEFORE_ITEMS = 'X'.
    wa_layout-TOTALS_ONLY = 'X'.
    wa_layout-TOTALS_TEXT = ''.
    wa_layout-SUBTOTALS_TEXT = ''.
    wa_layout-BOX_FIELDNAME = ''.
    wa_layout-BOX_TABNAME = ''.
    wa_layout-BOX_ROLLNAME = ''.
    wa_layout-CONFIRMATION_PROMPT = 'X'.
    wa_layout-HEADER_TEXT = ''.
    ENDFORM.                    " build_layout
    *&      Form  build_catlog
          Building the Field Catlog
    FORM build_catlog .
    wa_fieldcatalog-ROW_POS = 0.
    wa_fieldcatalog-COL_POS = 0.
    wa_fieldcatalog-FIELDNAME = ''.
    wa_fieldcatalog-TABNAME = ''.
    wa_fieldcatalog-CHECKBOX = 'X'.
    wa_fieldcatalog-DO_SUM = 'X'.
    wa_fieldcatalog-OUTPUTLEN = ''.
    wa_fieldcatalog-wa_fieldcatalog-OFFSET = ''.
    wa_fieldcatalog-SELTEXT_L = ''.
    wa_fieldcatalog-SELTEXT_M =''.
    wa_fieldcatalog-SELTEXT_S =''.
    wa_fieldcatalog-REF_FIELDNAME =''.
    wa_fieldcatalog-REF_TABNAME = ''.
    wa_fieldcatalog-NO_SUM ='X'.
    wa_fieldcatalog-EDIT ='X'.
    wa_fieldcatalog-HOTSPOT = 'X'.
    APPEND  wa_fieldcatalog TO it_fieldcatalog.
    CLEAR   wa_fieldcatalog.
    ENDFORM.                    " build_catlog
    *&      Form  build_events
          Building the Events
    FORM build_events .
    Get all possible events
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = lt_event
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
      ENDIF.
    Specify events used in selection screen
      READ TABLE lt_event WITH KEY name = slis_ev_top_of_page
                         INTO ls_event.
      IF sy-subrc = 0.
        ls_event-form = 'TOP_OF_PAGE'.
        MODIFY lt_event FROM ls_event INDEX sy-tabix.
        CLEAR ls_event.
      ENDIF.
      READ TABLE lt_event WITH KEY name = slis_ev_end_of_list
                         INTO ls_event.
      IF sy-subrc = 0.
        ls_event-form = 'END_OF_LIST'.
        MODIFY lt_event FROM ls_event INDEX sy-tabix.
        CLEAR ls_event.
      ENDIF.
    ENDFORM.                    " build_events
    *&      Form  TOP_OF_PAGE
    To display top of the page
    FORM top_of_page .
    data: lt_top_of_page type slis_t_listheader,
           ls_line type slis_listheader.
      clear ls_line.
      ls_line-typ  = 'H'.
      ls_line-info = ''.
      append ls_line to lt_top_of_page.
      clear ls_line.
      ls_line-typ  = 'S'.
      ls_line-key  = ''.
      ls_line-info = ''.
      append ls_line to lt_top_of_page.
      clear ls_line.
      ls_line-typ  = 'A'.
      ls_line-info = ''.
      append ls_line to  lt_top_of_page.
      clear ls_line.
       CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = lt_top_of_page
      I_LOGO                   =
      I_END_OF_LIST_GRID       =
    ENDFORM.                    " TOP_OF_PAGE
    *&      Form  end-of-list
    To display the totals at the end of the list
    FORM end_of_list .
    ENDFORM.                    " end-of-list
    *&      Form  set_pf_status
          Set the Pf Status
    FORM pf_status USING pa_extab TYPE slis_t_extab.
       SET PF-STATUS 'ZXXXX'.
    ENDFORM.                    "SET_PF_STATUS
    *&      Form  user_command
          To Catch the User Events
         -->PA_UCOMM     text
         -->PA_SELFIELD  text
    FORM user_command USING pa_ucomm TYPE syucomm
                            pa_selfield TYPE slis_selfield.
      CASE pa_ucomm.
          WHEN '&IC1'.
              CLEAR gs_output .
              READ TABLE gt_output INTO gs_output INDEX pa_selfield-tabindex .
              CASE pa_selfield-fieldname .
              ENDCASE.
          WHEN 'XXX'.
          WHEN 'XXX'.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND

  • Using ALV Grid for data Input

    Hi experts.
    Can someone assist me with information on using ALV grid for data input. Please give a simple example if possible.
    I am mainly interested in the part in which we can transfer data from the grid changing the internal table's data.

    Try this code:
    REPORT z_demo_alv_jg.
    TYPE-POOLS                                                          *
    TYPE-POOLS: slis.
    INTERNAL TABLES/WORK AREAS/VARIABLES                                *
    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
          i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
          w_field TYPE slis_fieldcat_alv,
          p_table LIKE dd02l-tabname,
          dy_table TYPE REF TO data,
          dy_tab TYPE REF TO data,
          dy_line TYPE REF TO data.
    FIELD-SYMBOLS                                                       *
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa> TYPE ANY,
                   <dyn_field> TYPE ANY,
                   <dyn_tab_temp> TYPE STANDARD TABLE.
    SELECTION SCREEN                                                    *
    PARAMETERS: tabname(30) TYPE c,
                lines(5)  TYPE n.
    START-OF-SELECTION                                                  *
    START-OF-SELECTION.
    Storing table name
      p_table = tabname.
    Create internal table dynamically with the stucture of table name
    entered in the selection screen
      CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_table->* TO <dyn_table>.
      IF sy-subrc <> 0.
        MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
        LEAVE TO LIST-PROCESSING.
      ENDIF.
    Create workarea for the table
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    Create another temp. table
      CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_tab->* TO <dyn_tab_temp>.
      SORT i_fieldcat BY col_pos.
    Select data from table
      SELECT * FROM (p_table)
      INTO TABLE <dyn_table>
      UP TO lines ROWS.
      REFRESH <dyn_tab_temp>.
    Display report
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid
          i_structure_name         = p_table
          i_callback_user_command  = 'USER_COMMAND'
          i_callback_pf_status_set = 'SET_PF_STATUS'
        TABLES
          t_outtab                 = <dyn_table>
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
      ENDIF.
    *&      Form  SET_PF_STATUS
          Setting custom PF-Status
         -->RT_EXTAB   Excluding table
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'Z_STANDARD'.
    ENDFORM.                    "SET_PF_STATUS
    *&      Form  user_command
          Handling custom function codes
         -->R_UCOMM      Function code value
         -->RS_SELFIELD  Info. of cursor position in ALV
    FORM user_command  USING    r_ucomm LIKE sy-ucomm
                               rs_selfield TYPE slis_selfield.
    Local data declaration
      DATA: li_tab TYPE REF TO data,
            l_line TYPE REF TO data.
    Local field-symbols
      FIELD-SYMBOLS:<l_tab> TYPE table,
                    <l_wa>  TYPE ANY.
    Create table
      CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN li_tab->* TO <l_tab>.
    Create workarea
      CREATE DATA l_line LIKE LINE OF <l_tab>.
      ASSIGN l_line->* TO <l_wa>.
      CASE r_ucomm.
      When a record is selected
        WHEN '&IC1'.
        Read the selected record
          READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
          rs_selfield-tabindex.
          IF sy-subrc = 0.
          Store the record in an internal table
            APPEND <dyn_wa> TO <l_tab>.
          Fetch the field catalog info
            CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
              EXPORTING
                i_program_name         = 'Z_DEMO_PDF_JG'
                i_structure_name       = p_table
              CHANGING
                ct_fieldcat            = i_fieldcat
              EXCEPTIONS
                inconsistent_interface = 1
                program_error          = 2
                OTHERS                 = 3.
            IF sy-subrc = 0.
            Make all the fields input enabled except key fields*
              w_field-input = 'X'.
              MODIFY i_fieldcat FROM w_field TRANSPORTING input
              WHERE key IS INITIAL.
            ENDIF.
          Display the record for editing purpose
            CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
              EXPORTING
                i_callback_program    = sy-repid
                i_structure_name      = p_table
                it_fieldcat           = i_fieldcat
                i_screen_start_column = 10
                i_screen_start_line   = 15
                i_screen_end_column   = 200
                i_screen_end_line     = 20
              TABLES
                t_outtab              = <l_tab>
              EXCEPTIONS
                program_error         = 1
                OTHERS                = 2.
            IF sy-subrc = 0.
            Read the modified data
              READ TABLE <l_tab> INDEX 1 INTO <l_wa>.
            If the record is changed then track its index no.
            and populate it in an internal table for future
            action
              IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
                <dyn_wa> = <l_wa>.
                i_index = rs_selfield-tabindex.
                APPEND i_index.
              ENDIF.
            ENDIF.
          ENDIF.
      When save button is pressed
        WHEN 'SAVE'.
        Sort the index table
          SORT i_index.
        Delete all duplicate records
          DELETE ADJACENT DUPLICATES FROM i_index.
          LOOP AT i_index.
          Find out the changes in the internal table
          and populate these changes in another internal table
            READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
            IF sy-subrc = 0.
              APPEND <dyn_wa> TO <dyn_tab_temp>.
            ENDIF.
          ENDLOOP.
        Lock the table
          CALL FUNCTION 'ENQUEUE_E_TABLE'
            EXPORTING
              mode_rstable   = 'E'
              tabname        = p_table
            EXCEPTIONS
              foreign_lock   = 1
              system_failure = 2
              OTHERS         = 3.
          IF sy-subrc = 0.
          Modify the database table with these changes
            MODIFY (p_table) FROM TABLE <dyn_tab_temp>.
            REFRESH <dyn_tab_temp>.
          Unlock the table
            CALL FUNCTION 'DEQUEUE_E_TABLE'
              EXPORTING
                mode_rstable = 'E'
                tabname      = p_table.
          ENDIF.
      ENDCASE.
      rs_selfield-refresh = 'X'.
    ENDFORM.                    "user_command

  • How to display field of 250 character length using ALV Grid display

    Hello Experts,
    Currently I'm using 4.6 version.
    I got to insert a new field of length 250 characters into an existing ALV grid display.
    I passed a value of length 250 chars into the field and assigned it to the itab passing to the fn module
    'REUSE_ALV_GRID_DISPLAY'.
    But in the ALV display I am able to view only 132 chars only. I increased the line-size of the report also accordingly. But I'm unable to view all the 250 chars.
    Kindly help me out in fixing this issue.

    you just can't do that
    I suggest that you put the first characters in cell and allow user to double-click on cell in order to view the full value in a popup window

  • How to Destroy ALV Grid..

    Hi All..
    I am using the type-pools SLIS..is it possible to destroy an alv grid so that all the contents are deleted and i could fill it with the new contents.
    Thanks in Advance,
    rama

    Hi
    See this
    refreshing alv but how?
    Aditya

  • Simple tutorial for using alv-grid for data entry into table, please!

    Hi friends,
    I urgently need a basic, simple tutorial or step-by-step or sample code on the following:
    I want to have a alv-grid like entry list where i can add/remove additional lines/entries that then are saved into an internal table. Please help me with that, as i studied already some documents but do not really get the idea of how to do - <REMOVED BY MODERATOR>
    Thanks in advance,
    Edited by: Alvaro Tejada Galindo on Jan 11, 2008 6:18 PM

    hi clemens,
    follow this link it may be useful to u
    http://www.sap-basis-abap.com/sapab033.htm
    http://www.abapprogramming.blogspot.com/2007/04/alv-details.html
    for tutorial on alv:
    http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/ALV_tutorial.html
    i have pdf material also ican give it to you if u give your email id.
    hope this helps you
    regards,
    sravanthi

Maybe you are looking for

  • Error while starting listener on my database TNS-1255,TNS-12560, TNS-00525

    Hi All, I am newbie to oracle and i have been struggling from last one week to get this error corrected on my database. Listener services are not working due to which i'm unable to proceed my work. Please provide ur help as i really want to learn. Ed

  • CUPS printer sharing across subnets?

    I am trying to set up my local network printer so that everyone in the house can print from it. However I have two subnets in the house and I don't see how to connect to the Linux server through a Windows 7 client. My network is like so: Upstairs: [M

  • Unable to select multiple messages in Mail.

    Hi, I can't select multiple messages in Mail app. After selecting few, all of them automatically deselects. This is really annoying. I'm on 6.1.2 iP5, and this is happening from the begining. Never happened before on my iP4. The other problem with ma

  • Place Excel file; retain strokes

    InDesign CS6 and CC tables are not retaining strokes from imported Excel worksheets. I have searched all over for a solution with no luck. I am placing Excel worksheets (financials) into InDesign (tried every method), tried copy/paste. Looks like I h

  • Smartofrms: add final page with LOGO (print invoice)

    Hi all, In Smartforms, I would like to insert a final page with the LOGO of the company in whole page size. I already used &PAGE1(first) and  &PAGE2(next) but I am not able of to call a third and final page (ENDPG).  I followed this steps: - created