0% found this document useful (0 votes)
115 views4 pages

Adding Header To ALV

This report displays flight data from the SFLIGHT table in an ALV grid. It declares variables, builds the field catalog, retrieves data from the database, checks for an existing display variant, and displays the ALV grid. User selection of variants is supported through a selection screen parameter and F4 help. Report headers are added to the ALV grid.

Uploaded by

Armin Suljovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views4 pages

Adding Header To ALV

This report displays flight data from the SFLIGHT table in an ALV grid. It declares variables, builds the field catalog, retrieves data from the database, checks for an existing display variant, and displays the ALV grid. User selection of variants is supported through a selection screen parameter and F4 help. Report headers are added to the ALV grid.

Uploaded by

Armin Suljovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

*&---------------------------------------------------------------------*

*& Report ZAS_TEST2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zas_test2.

TABLES : sflight.
TYPE-POOLS : slis.
**INTERNAL TABLE DECLARTION
DATA : wa_sflight TYPE sflight,
       it_sflight TYPE TABLE OF sflight.
**DATA DECLARTION
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid,
      g_save TYPE c VALUE 'X',
      g_variant TYPE disvariant,
      gx_variant TYPE disvariant,
      g_exit TYPE c,
      ispfli TYPE TABLE OF spfli.
* To understand the importance of the following parameter, click here.
**SELECTION SCREEN DETAILS
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002 .
PARAMETERS: variant LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK b1.
**GETTING DEFAULT VARIANT
INITIALIZATION.
  gx_variant-report = sy-repid.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = g_save
    CHANGING
      cs_variant = gx_variant
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc = 0.
    variant = gx_variant-variant.
  ENDIF.
** F4 Help for Varient
AT SELECTION-SCREEN ON VALUE-REQUEST FOR variant.
**-- Display all existing variants
  g_variant-report = sy-repid.
* Utilizing the name of the report, this function module will search for a lis
t of
* variants and will fetch the selected one into the parameter field for varian
ts
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant = g_variant
      i_save     = g_save
    IMPORTING
      e_exit     = g_exit
      es_variant = gx_variant
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc = 2.
    MESSAGE ID sy-msgid TYPE 'S'      NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF g_exit = space.
      variant = gx_variant-variant.
    ENDIF.
  ENDIF.

**PERFORM DECLARATIONS
START-OF-SELECTION.
  PERFORM data_retrivel.
  PERFORM build_fieldcatalog.
  PERFORM check_variant.
  PERFORM display_alv_report.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
  fieldcatalog-fieldname   = 'CARRID'.
  fieldcatalog-seltext_m   = 'Airline Code'.
  fieldcatalog-col_pos     = 0.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'CONNID'.
  fieldcatalog-seltext_m   = 'Flight Connection Number'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.  fieldcatalog-fieldname   = 'FLDATE'.
  fieldcatalog-seltext_m   = 'Flight date'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.  fieldcatalog-fieldname   = 'PRICE'.
  fieldcatalog-seltext_m   = 'Airfare'.
  fieldcatalog-col_pos     = 3.
  fieldcatalog-outputlen   = 20.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
FORM display_alv_report .
  gd_repid = sy-repid.
  g_variant-variant = variant.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = gd_repid
      i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM
      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = fieldcatalog[]
      i_save                  = 'X'
      is_variant              = g_variant
    TABLES
      t_outtab                = it_sflight
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    "DISPLAY_ALV_REPORT" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIVEL
*&---------------------------------------------------------------------*
FORM data_retrivel .
  SELECT * FROM sflight INTO TABLE it_sflight.
ENDFORM.                    " DATA_RETRIVEL
*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top-of-page.
*ALV Header declarations
  DATA: t_header TYPE slis_t_listheader,
        wa_header TYPE slis_listheader,
        t_line LIKE wa_header-info,
        ld_lines TYPE i,
        ld_linesc(10) TYPE c.
* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'SFLIGHT Table Report'.
  APPEND wa_header TO t_header.
  CLEAR wa_header.
* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "Today's date
  APPEND wa_header TO t_header.
  CLEAR: wa_header.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
ENDFORM.                    "Top-of-page
*&---------------------------------------------------------------------*
*&      Form  CHECK_VARIANT
*&---------------------------------------------------------------------*
FORM check_variant .
  g_variant-variant = variant.
  g_variant-report  = sy-repid.
  CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK' "Check for display variant
  EXPORTING
      i_save               = space            "Variants Can be Saved
    CHANGING
      cs_variant           = g_variant        "Variant information
    EXCEPTIONS
      wrong_input          = 1                "Inconsistent input parameters
      not_found            = 2                "Variant not found
      program_error        = 3                "Program Errors
      .                                       "  LVC_VARIANT_EXISTENCE_CHECK
  IF sy-subrc = 2.
    MESSAGE 'Display Variant Not Found, Displaying Default Variant'
                                                              TYPE 'S'.
  ENDIF.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = g_save
    CHANGING
      cs_variant = gx_variant
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc = 0.
    variant = gx_variant-variant.
  ENDIF.
ENDFORM.                    "CHECK_VARIANT

You might also like