ALV - set_table_for_first_display to include report header

Question: Hope someone can help me with this. I am farely new to ALV.

I have an internal table which I use for alv report using set_table_for_first_display.

It works well but I need to include report header such as the title, username, date and time, pgm name etc. How do I do that? Any help apprecited. Thanks.

Answer:
If you mean that you want to control the header title then here's an example that I just pulled from some code. You could build title to be anything that you want, although I would look at the other properties of the lvc_s_layo type. I'm assuming that you're using the OO method when creating ALV's.

Dr Sidewalk

Extract:

* Control the layout by populating ls_layout. See structure for
* layout configuration options
  DATA ls_layout TYPE lvc_s_layo.
  ls_layout-grid_title  = 'Global attribute'.
  ls_layout-zebra       = 'X'.
  ls_layout-cwidth_opt  = 'X'.

* Generate GUI report (Once only)
  PERFORM f_generate_alv_report
     USING gc_fieldcat1                   "Dictionary structure name
           ls_layout                      "Layout controls
           gt_outtab1                     "Data to display
           'BCALV_GRID_0100_CONT1'        "Screen container name
           '0100_CONT1'.     

FORM f_generate_alv_report  USING fp_fieldcat  TYPE lvc_fname
                                  fp_layout    TYPE lvc_s_layo
                                  fp_outtab    TYPE TABLE
                                  fp_container TYPE CHAR100
                                  fp_screen    TYPE CHAR10.

* Definitions/constants for ALV GRID usage
  DATA: lt_fcat              TYPE lvc_t_fcat,
        lw_struct_name       TYPE dd02l-tabname,
        lw_name(40)          TYPE C.

  FIELD-SYMBOLS:
  <fs_cont> TYPE REF TO cl_gui_custom_container,
  <fs_grid> TYPE REF TO cl_gui_alv_grid.


  CONCATENATE 'gr_container_' fp_screen INTO lw_name.
  ASSIGN (lw_name) TO <fs_cont>.
  IF sy-subrc NE 0. " data not declared
   EXIT.
  ENDIF.
  CONCATENATE 'gr_grid_' fp_screen INTO lw_name.
  ASSIGN (lw_name) TO <fs_grid>.
  IF sy-subrc NE 0. " data not declared
   EXIT.
  ENDIF.

  IF <fs_cont> IS INITIAL.
*   Detect whether running in background or not. If we are then we
*   should not create the container for the screen display, otherwise
*   the code will shortdump. Without this container defined the ALV GRID
*   output will default to LIST output and will appear okay within the
*   spool file.
    IF cl_gui_alv_grid=>offline( ) IS INITIAL.
      create object <fs_cont>
        exporting container_name = fp_container.
    ENDIF.
*     Link object to screen container (empty if in run in background)
      CREATE OBJECT <fs_grid>
             EXPORTING i_parent = <fs_cont>.

*   Build field catalog dynamically, based on source data structure
    IF fp_fieldcat IS INITIAL.
*     Insert code to generate the field catalog dynamicaly rather than
*     use the DDIC strcuture.
    ENDIF.

*   Build Field Catalog based on Dictonary Structure
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name       = fp_fieldcat
      CHANGING
        ct_fieldcat            = lt_fcat[]
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        others                 = 3.
    IF sy-subrc NE 0.
      MESSAGE id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

*   Display ALV GRID
    lw_struct_name = fp_fieldcat.
    CALL METHOD <fs_grid>->set_table_for_first_display
      EXPORTING
        i_structure_name    = lw_struct_name
        is_layout           = fp_layout
      CHANGING
        it_outtab           = fp_outtab
        it_fieldcatalog     = lt_fcat.

  ENDIF. "IF <fs_cont> IS INITIAL.

ENDFORM.                    " f_generate_alv_report
_________________
"In the middle of difficulty lies opportunity" - Albert Einstein
"Money isn't everything in life, unless you don't have it". David King
"Fail to plan, plan to fail"
"Success is a journey, not a destination."
Copyright ?2007 - 2008 www.jt77.com