Posted: Mon Sep 10, 2007 7:51 pm Post subject: TOP-OF-PAGE
Take a look at this alv-sample-code. It defines the event TOP-OF-PAGE in which you can print anything you want, including SO_...-low to SO_...-high, which you can insert at *()*
Code:
REPORT ZALV_SAMPLE.
* NO STANDARD PAGE HEADING
* LINE-COUNT 58
* LINE-SIZE 220.
TYPE-POOLS: SLIS. "for 'REUSE_ALV...list&grids'
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
TABLES: KNA1. "General Data in Customer Master
.
*----------------------------------------------------------------------*
* Internal data *
*----------------------------------------------------------------------*
DATA: BEGIN OF LT_ALVTABLE OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
NAME2 LIKE KNA1-NAME2,
STRAS LIKE KNA1-STRAS,
PSTLZ LIKE KNA1-PSTLZ,
ORT01 LIKE KNA1-ORT01,
UMSA1 LIKE KNA1-UMSA1,
KTOKD LIKE KNA1-KTOKD,
END OF LT_ALVTABLE.
* data-statements that are necessary for the use of the ALV-grid
DATA: GT_XEVENTS TYPE SLIS_T_EVENT.
DATA: XS_EVENT TYPE SLIS_ALV_EVENT.
DATA: REPID TYPE SY-REPID.
DATA: ZTA_PRINT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA: LO_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: LO_ITABNAME TYPE SLIS_TABNAME.
DATA: LS_VARIANT TYPE DISVARIANT.
*----------------------------------------------------------------------*
* Initialization *
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* Parameters and select-options *
*----------------------------------------------------------------------*
SELECT-OPTIONS SO_KUNNR FOR KNA1-KUNNR DEFAULT '2000' TO '2300'.
SELECT-OPTIONS SO_NAME FOR KNA1-NAME1.
PARAMETERS: PA_PSTCD AS CHECKBOX DEFAULT 'X'.
PARAMETERS: PA_VAR AS CHECKBOX DEFAULT 'X'.
*----------------------------------------------------------------------*
* Start of main program *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM SELECT_RECORDS.
PERFORM PRINT_ALVLIST.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form select_records
*&---------------------------------------------------------------------*
FORM SELECT_RECORDS.
SELECT * FROM KNA1 INTO CORRESPONDING FIELDS OF LT_ALVTABLE
WHERE KUNNR IN SO_KUNNR
AND NAME1 IN SO_NAME.
APPEND LT_ALVTABLE.
ENDSELECT.
ENDFORM. " select_records
*&--------------------------------------------------------------------*
*& Form print_alvlist
*&--------------------------------------------------------------------*
FORM PRINT_ALVLIST.
REPID = SY-REPID.
LO_ITABNAME = 'LT_ALVTABLE'. "NB: ONLY USE CAPITALS HERE!
* Fill the variables of the ALV-grid.
PERFORM SET_LAYOUT USING LO_LAYOUT. "Change layout-settings
PERFORM SET_EVENTS USING GT_XEVENTS."Set the events (top-page etc)
PERFORM FILL_STRUCTURE. "Read the structure of the itab
PERFORM MODIFY_STRUCTURE. "Modify itab's field-properties
* Sort the table
SORT LT_ALVTABLE BY KUNNR.
* Present the table using the ALV-grid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPID
IT_FIELDCAT = ZTA_PRINT[]
IS_LAYOUT = LO_LAYOUT
IT_EVENTS = GT_XEVENTS
I_SAVE = 'A'
IS_VARIANT = LS_VARIANT
TABLES
T_OUTTAB = LT_ALVTABLE.
ENDFORM. " print_alvlist
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
FORM SET_LAYOUT USING PA_LAYOUT TYPE SLIS_LAYOUT_ALV.
* Minimize the columnwidth
PA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
* Give the table a striped pattern
PA_LAYOUT-ZEBRA = 'X'.
* Set the text of the line with totals
PA_LAYOUT-TOTALS_TEXT = 'Total:'.
* Set the text of the line with subtotals
PA_LAYOUT-SUBTOTALS_TEXT = 'Subtotal:'.
* Set the variant, as requested via the checkbox
IF PA_VAR = 'X'.
LS_VARIANT-VARIANT = '/ZLAYOUT'.
ELSE.
CLEAR LS_VARIANT-VARIANT.
ENDIF.
ENDFORM. " SET_LAYOUT
*&--------------------------------------------------------------------
*& Form Set_events
*&--------------------------------------------------------------------
* Appends the values of the events to the events-variable that is
* used by REUSE_ALV_LIST_DISPLAY
*&--------------------------------------------------------------------
FORM SET_EVENTS USING PA_EVENTS TYPE SLIS_T_EVENT.
XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.
XS_EVENT-FORM = 'XTOP_OF_LIST'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_END_OF_LIST.
XS_EVENT-FORM = 'XEND_OF_LIST'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.
XS_EVENT-FORM = 'XTOP_OF_PAGE'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.
XS_EVENT-FORM = 'XEND_OF_PAGE'.
APPEND XS_EVENT TO PA_EVENTS.
ENDFORM.
*&--------------------------------------------------------------------*
*& Form XTOP_OF_LIST
*&--------------------------------------------------------------------*
FORM XTOP_OF_LIST.
DATA LO_DATE(8).
CONCATENATE SY-DATUM+6(2) '.'
SY-DATUM+4(2) '.'
SY-DATUM+2(2)
INTO LO_DATE.
WRITE: AT 1 'Report:'(T01), 20 'Reportname'(T02).
WRITE: AT 50 'Date:'(T03), LO_DATE.
NEW-LINE.
WRITE: AT 1 'Abap-name report: '(T04), SY-REPID.
WRITE: AT 50 'Page:'(T05), SY-CPAGE.
ENDFORM. "xtop_of_list
*&--------------------------------------------------------------------*
*& Form XEND_OF_LIST
*&--------------------------------------------------------------------*
FORM XEND_OF_LIST.
WRITE: 'Footer of the list'(002).
ENDFORM. "xend_of_list
*&---------------------------------------------------------------------*
*& Form XTOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM XTOP_OF_PAGE.
WRITE:/ 'Top of the page.'(003).
*()*Here your selection-criteria can be printed
ENDFORM. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form XEND_OF_PAGE
*&---------------------------------------------------------------------*
FORM XEND_OF_PAGE.
WRITE:/ 'End of the page.'(004).
ENDFORM. "xtop-of-page
*&---------------------------------------------------------------------*
*& Form FILL_STRUCTURE
*&---------------------------------------------------------------------*
FORM FILL_STRUCTURE.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.