Saturday, December 18, 2010
Use function module REUSE_ALV_GRID_DISPLAY function module to create ALV report.
Steps to create simple ALV program
  1. Pass an internal table with the set of output information
  2. Pass a field catalog as an internal table  
  3. Pass a structure with general list layout details

REPORT  ZTEST_ALV_2_GRID_DESCRIPTION.
TYPES:
    BEGIN OF T_MARD,
    WERKS TYPE MARD-WERKS,
    LGORT TYPE MARD-LGORT,
    MATNR TYPE MARD-MATNR,
    INSME TYPE MARD-INSME,
    EINME TYPE MARD-EINME,
    SPEME TYPE MARD-SPEME,
    END OF T_MARD.
DATA:
    W_MARD TYPE T_MARD.
DATA:
    I_MARD TYPE STANDARD TABLE OF T_MARD.
*&---------------------------------------------------------------------*
" ALV Declarations
"&---------------------------------------------------------------------*
"     ALV internal tables and Structures
"     ----------------------------------
"     To refer ALV tables(slis tables) and structures.SLIS must be
"     declared under TYPE-POOLS(see below).SLIS is a Type group which is
"     defined in Dictionary.Internal tables and structures and constants
"     are defined under type group.(Double click on SLIS).
*&---------------------------------------------------------------------*
* Types Pools
TYPE-POOLS:
    SLIS.
* Types
TYPES:
    T_FIELDCAT         TYPE SLIS_FIELDCAT_ALV,
    T_EVENTS           TYPE SLIS_ALV_EVENT,
    T_LAYOUT           TYPE SLIS_LAYOUT_ALV.
* Workareas
DATA:
    W_FIELDCAT         TYPE T_FIELDCAT,
    W_EVENTS           TYPE T_EVENTS,
    W_LAYOUT           TYPE T_LAYOUT.
* Internal Tables
DATA:
    I_FIELDCAT         TYPE STANDARD TABLE OF T_FIELDCAT,
    I_FIELDCAT1        TYPE STANDARD TABLE OF T_FIELDCAT,
    I_EVENTS           TYPE STANDARD TABLE OF T_EVENTS.
*&---------------------------------------------------------------------*
*&      START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM GET_DATA_FROM_DATABASE .

*&---------------------------------------------------------------------*
  "      END-OF-SELECTION
  "     Steps to create simple ALV program
  "     ----------------------------------
  "      1. Pass an internal table with the set of output information
  "      2. Pass a field catalog as an internal table
  "      3. Pass a structure with general list layout details
*&---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM BUILD_FIELDCATALOG.
  PERFORM BUILD_EVENTS.
  PERFORM BUILD_LAYOUT.
  PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
  "      Form  build_fieldcatalog
  "     Fieldcatalog Internal table
  "     --------------------------
  "    1. It contains descriptions of the list output fields
  "       (usually a subset of the internal output table fields).
  "    2. A field catalog is required for every ALV list output.
*&---------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .
  CLEAR :
  W_FIELDCAT,
  I_FIELDCAT[].

  PERFORM BUILD_FCAT USING:
  "Field   Int.Table Column headings
  'WERKS' 'I_MARD' 'WERKS',
  'LGORT' 'I_MARD' 'LGORT',
  'MATNR' 'I_MARD' 'MATNR',
  'INSME' 'I_MARD' 'INSME',
  'EINME' 'I_MARD' 'EINME',
  'SPEME' 'I_MARD' 'SPEME'.
ENDFORM.                    " build_fieldcatalog

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM DISPLAY_DATA .
  DATA :PROGRAM LIKE SY-REPID VALUE SY-REPID.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = PROGRAM
      IS_LAYOUT          = W_LAYOUT
      IT_FIELDCAT        = I_FIELDCAT
      IT_EVENTS          = I_EVENTS
    TABLES
      T_OUTTAB           = I_MARD.
  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_data

*&---------------------------------------------------------------------*
*&      Form  get_data_from_database
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA_FROM_DATABASE .
  CLEAR :I_MARD,
  I_MARD[].

  SELECT WERKS LGORT MATNR INSME EINME SPEME
  FROM MARD
  INTO CORRESPONDING FIELDS OF TABLE I_MARD
  UP TO 100 ROWS.


ENDFORM.                    " get_data_from_database

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.

  DATA :
  I_HEADER TYPE SLIS_T_LISTHEADER,
  W_HEADER LIKE LINE OF I_HEADER.

  DATA:L_DATE1 TYPE DATUM,
  L_DATE2 TYPE DATUM.

  W_HEADER-TYP = 'S'.
  W_HEADER-INFO = SY-TITLE.
  APPEND W_HEADER TO I_HEADER.
  CLEAR W_HEADER.

  W_HEADER-TYP = 'H'.
  W_HEADER-INFO = SY-REPID.
  APPEND W_HEADER TO I_HEADER.
  CLEAR W_HEADER.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = I_HEADER
      I_LOGO             = 'ENJOYSAP_LOGO'.

ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT
*&---------------------------------------------------------------------*

FORM BUILD_FCAT  USING  L_FIELD L_TAB L_TEXT.

  W_FIELDCAT-FIELDNAME = L_FIELD.
  W_FIELDCAT-TABNAME   = L_TAB.
  W_FIELDCAT-SELTEXT_M = L_TEXT.
  APPEND W_FIELDCAT TO I_FIELDCAT.
  CLEAR W_FIELDCAT.

ENDFORM.                    " BUILD_FCAT
*&---------------------------------------------------------------------*
"      Form  build_events
"     Events
"     ------
"    1. When we use ALV,certain events TOP-OF-PAGE ,END-OF-PAGE,
"       AT LINE-SELECTION,AT USER-COMMANDs are not triggered.
"    2. To perform those Functions ,we have to build Events table and
"       pass this table through REUSE_ALV_LIST_DISPALY Function.
*&---------------------------------------------------------------------*
FORM BUILD_EVENTS .
  CLEAR :
  W_EVENTS,I_EVENTS[].

  W_EVENTS-NAME = 'TOP_OF_PAGE'.
  W_EVENTS-FORM = 'TOP_OF_PAGE'.
  APPEND W_EVENTS TO I_EVENTS.
  CLEAR W_EVENTS.
ENDFORM.                    " build_events
*&---------------------------------------------------------------------*
"&      Form  build_layout
"     Layouts
"     -------
"  Use :We change the display of our list using layouts.
"  ===
"  Features
"  ========
"    The layouts that you can use vary according to the type of list:
"   1-->In all lists, you can do the following:
"       (a).Choose one of the std layouts supplied with the std system.
"       (b).Change the current layout of the list .
"   2-->In lists that use only the standard layouts in the std system
"       you cannot save your changes to the current layout.When you
"       choose the layouts, only the standard layouts will be proposed.
"   3-->In some lists, you can also save the layouts that you have
"       defined as our own layouts.
"      User-defined layouts are generally saved for all users. They can
"       then be used by all users. All users will be able to choose from
"       the user-defined layouts as well as the standard layouts.
"   4-->In some lists, you can also save user-specific layouts that you
"       have defined . When you choose the current layout,only these
"       layouts are available to you.
"   5-->You can delete or transport layouts, or define them as initial
"       layouts
"   6-->STRUCTURE :SLIS_LAYOUT_ALV.
*&---------------------------------------------------------------------*
FORM BUILD_LAYOUT .
  CLEAR:
  W_LAYOUT.
  W_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM.                    " build_layout


4 comments:

  1. Excellent stuff :). Keep giving Posting....

    ReplyDelete
    Replies
    1. i am using i_callback_html_top_of_page.

      how do i get the header info printed on page ?
      its displaying on screen but not printing on page

      Delete
  2. nice information or tutorial
    guys must try incredibly fresh or new website called papaclassifieds for advertising online
    post free classified ads without any registration

    ReplyDelete
  3. Thoughtful suggestions ! I am thankful for the insight - Does someone know if my business could locate a fillable WI WB-16 copy to use ?

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.