Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This program illustrates how the events for print processing
* - PRINT_TOP_OF_PAGE
* - PRINT_END_OF_PAGE
* - PRINT_TOP_OF_LIST
* - PRINT_END_OF_LIST
*
* are handled. The corresponding handler methods control the
* appearance of the list printed.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Print the list shown (It has got only three pages).
* Remark: If you choose "Druckansicht" (preview?!) before printing,
* the output for event PRINT_END_OF_PAGE is left out due
* to scrolling.
* Create a spool entry and preview your printout by calling
* TA sp01 to reduce paper output please.
*-----------------------------------------------------------------
* Essential steps (Search for '§')
* ~~~~~~~~~~~~~~~
* 1. Define a (local) class for event handling
* 2. Define a method for each print event you need.
* 3. Implement your event handler methods. Use WRITE to provide output.
* 4. Link used print events and event handler methods.
* 5. In case of PRINT_END_OF_PAGE, you must set 'reservelns' to
* the number of reserved lines at the end of a page.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&
*********
* Predefine a local class for event handling to allow the
* declaration of a reference variable.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*
*********
PUBLIC SECTION.
* § 2. Define a method for each print event you need.
METHODS:
HANDLE_TOP_OF_PAGE
FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,
HANDLE_END_OF_PAGE
FOR EVENT PRINT_END_OF_PAGE OF CL_GUI_ALV_GRID,
HANDLE_TOP_OF_LIST
FOR EVENT PRINT_TOP_OF_LIST OF CL_GUI_ALV_GRID,
HANDLE_END_OF_LIST
FOR EVENT PRINT_END_OF_LIST OF CL_GUI_ALV_GRID.
PRIVATE SECTION.
DATA: PAGENUM TYPE I.
ENDCLASS.
*
* c_event_receiver (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class c_event_receiver (Implementation)
*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
*§ 3. Implement your event handler methods. Use WRITE to provide output.
METHOD HANDLE_TOP_OF_PAGE.
DATA: TABLENAME(30) TYPE C.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_TOP_OF_PAGE'(001),
'Table: '(002),TABLENAME.
ENDMETHOD. "handle_top_of_page
*-------------------------------------------
METHOD HANDLE_END_OF_PAGE.
DATA: TABLENAME(30) TYPE C.
ENDMETHOD. "handle_end_of_page
*-------------------------------------------
METHOD HANDLE_TOP_OF_LIST.
DATA: TABLENAME(30) TYPE C.
CLEAR PAGENUM.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_TOP_OF_LIST'(005),
TEXT-002,TABLENAME.
ENDMETHOD. "handle_top_of_list
*-------------------------------------------
METHOD HANDLE_END_OF_LIST.
DATA: TABLENAME(30) TYPE C.
PERFORM GET_TABLENAME CHANGING TABLENAME.
WRITE: /,'Event: PRINT_END_OF_LIST'(006),
TEXT-002,TABLENAME.
ENDMETHOD. "handle_end_of_list
*-------------------------------------------
ENDCLASS.
*
* c_event_receiver (Implementation)
*===================================================================
START-OF-SELECTION.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT up to g_max rows.
*
END-OF-SELECTION.
G_REPID = SY-REPID.
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
MODULE PBO OUTPUT.
SET PF-STATUS 'MAIN100'.
IF CUSTOM_CONTAINER IS INITIAL.
* create a custom container control for our ALV Control
CREATE OBJECT CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = MYCONTAINER
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
IF SY-SUBRC NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = G_REPID
TXT2 = SY-SUBRC
TXT1 = 'The control could not be created'(010).
ENDIF.
* create an instance of alv control
CREATE OBJECT GRID1
EXPORTING I_PARENT = CUSTOM_CONTAINER.
*
* Set a titlebar for the grid control
*
GS_LAYOUT-GRID_TITLE = 'Flights'(100).
********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
* § 4. Link used print events and event handler methods.
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_LIST FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_TOP_OF_PAGE FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_LIST FOR GRID1.
SET HANDLER EVENT_RECEIVER->HANDLE_END_OF_PAGE FOR GRID1.
*
********
ENDIF.
* Controls are not integrated into the TAB-Order
* Call "set_focus" if you want to make sure that 'the cursor'
* is active in your control.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID1.