Reporte alv - ejemplo

Solo disponible en BuenasTareas
  • Páginas : 10 (2278 palabras )
  • Descarga(s) : 0
  • Publicado : 23 de septiembre de 2010
Leer documento completo
Vista previa del texto
A Simple ABAP ALV LIST VIEWER Example
This ALV program have all the basic report requirements such as page heading, page no, sub-total and a grand total.
* This is a basic ALV with the followings:-
* - Page Heading
* - Page No
* - Sub-Total
* - Grand Total
REPORT ZALV.
TYPE-POOLS: SLIS.
DATA: G_REPID LIKE SY-REPID,
GS_PRINT            TYPE SLIS_PRINT_ALV,
GT_LIST_TOP_OF_PAGE TYPESLIS_T_LISTHEADER,
GT_EVENTS           TYPE SLIS_T_EVENT,
GT_SORT             TYPE SLIS_T_SORTINFO_ALV,
GS_LAYOUT           TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT         TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,
COL_POS TYPE I.
DATA: BEGIN OF ITAB,
  FIELD1(5) TYPE C,
  FIELD2(5) TYPE C,
  FIELD3(5) TYPE P DECIMALS 2,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0.
  INCLUDESTRUCTURE ITAB.
DATA: END OF ITAB1.
DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.
  INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB_FIELDCAT.
* Print Parameters
PARAMETERS:
            P_PRINT  AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE
            P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO
            P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE
            P_NONEWP AS CHECKBOX DEFAULT' ', "NO NEW PAGE
            P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO
            P_RESERV TYPE I.                  "NO OF FOOTER LINE
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM PRINT_BUILD    USING GS_PRINT.      "Print PARAMETERS
START-OF-SELECTION.
* TEST DATA
MOVE 'TEST1' TO ITAB1-FIELD1.
MOVE 'TEST1' TO ITAB1-FIELD2.
MOVE '10.00' TO ITAB1-FIELD3.
APPEND ITAB1.
MOVE'TEST2' TO ITAB1-FIELD1.
MOVE 'TEST2' TO ITAB1-FIELD2.
MOVE '20.00' TO ITAB1-FIELD3.
APPEND ITAB1.
DO 50 TIMES.
  APPEND ITAB1.
ENDDO.
END-OF-SELECTION.
PERFORM BUILD.
PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.
PERFORM COMMENT_BUILD  CHANGING GT_LIST_TOP_OF_PAGE.
PERFORM CALL_ALV.
FORM BUILD.
* DATA FIELD CATALOG
* Explain Field Description to ALV
DATA: FIELDCAT_IN TYPESLIS_FIELDCAT_ALV.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD1'.
FIELDCAT_LN-TABNAME   = 'ITAB1'.
*FIELDCAT_LN-NO_OUT    = 'X'.  "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
FIELDCAT_LN-KEY       = ' '.   "SUBTOTAL KEY
FIELDCAT_LN-NO_OUT    = ' '.
FIELDCAT_LN-SELTEXT_L = 'HEAD1'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD2'.
FIELDCAT_LN-TABNAME   ='ITAB1'.
FIELDCAT_LN-NO_OUT    = 'X'.
FIELDCAT_LN-SELTEXT_L = 'HEAD2'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME     = 'FIELD3'.
FIELDCAT_LN-TABNAME       = 'ITAB1'.
FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "P_EVENTS[]  text                                             *
*----------------------------------------------------------------------*
FORM BUILD_EVENTTABUSING P_EVENTS TYPE SLIS_T_EVENT.
  DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
            I_LIST_TYPE = 0
       IMPORTING
            ET_EVENTS   = P_EVENTS.
  READ TABLE P_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
                           INTO LS_EVENT.
  IF SY-SUBRC = 0.
    MOVE FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
    APPENDLS_EVENT TO P_EVENTS.
  ENDIF.
ENDFORM.                               " BUILD_EVENTTAB
*&---------------------------------------------------------------------*
*&      Form  BUILD_COMMENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_HEADING[] text                                            *
*----------------------------------------------------------------------*
FORM BUILD_COMMENT USING P_HEADING TYPE SLIS_T_LISTHEADER.
  DATA: HLINE TYPE SLIS_LISTHEADER,
        TEXT(60) TYPE C,
        SEP(20) TYPE C.
  CLEAR: HLINE, TEXT.
  HLINE-TYP  = 'H'.
  WRITE: TEXT-101 TO TEXT+23.
  HLINE-INFO = TEXT.
  APPEND HLINE TO P_HEADING.
  CLEAR TEXT.
  WRITE:...
tracking img