Exploring ABAP Classical Report Events: Start Of Selection, End Of Selection, Top of Page, and End of Page
Welcome back everyone, We have started Classical report events in the last blog. so, Let’s continue it.
3. Start Of Selection
- This event calls when user clicks execute button on the selection screen.
- The selection logic is the part of this event.
Let’s create a type structure for our header table in our program, which we have seen in the last blog.
Implementation :-
Note :- Please go to the debug mode and check which events are triggering at what time, It will help everyone to understand the entire concept.
Code :-
***********************************************
*Start of Program
***********************************************
*Declaring type strcuture
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
currency TYPE zar_curency,
END OF ty_header.
****************
*Internal Table and Work Area
DATA : lt_header type table of ty_header,
ls_header type ty_header.
****************************************
DATA : lv_pm TYPE zar_payment_mode,
lv_curr TYPE zar_curency,
lv_date TYPE zar_order_date.
SELECT-OPTIONS : s_odate FOR lv_date NO-EXTENSION.
SELECT-OPTIONS : s_pm FOR lv_pm NO INTERVALS.
SELECT-OPTIONS : s_curr FOR lv_curr NO INTERVALS.
****************************
*Initializaton Events.
INITIALIZATION.
*****************
*For Date
s_odate-sign = 'I'.
s_odate-option = 'BT'.
s_odate-low = sy-datum - 100.
s_odate-high = sy-datum.
APPEND s_odate.
********
*For Payement Mode
* s_pm-low = 'C'.
* APPEND s_pm.
***************
*Currency
s_curr-low = 'INR'.
APPEND s_curr.
***********************************
*At Selection Screen
AT SELECTION-SCREEN.
IF s_pm-low IS INITIAL.
IF s_pm-low <> 'C'.
MESSAGE 'Payment mode is not entered' TYPE 'E'.
ENDIF.
ENDIF.
**********************************
*Start Of Selection.
START-OF-SELECTION.
Select ORDER_NUMBER ORDER_DATE PAYMENT_MODE CURRENCY
from ZAR_HEADER
into TABLE lt_header
where currency in s_curr.
***********************************
*Displaying data
LOOP at lt_header into ls_header.
WRITE :/ ls_header-ORDER_NUMBER,
ls_header-ORDER_DATE,
ls_header-PAYMENT_MODE,
ls_header-CURRENCY.
ENDLOOP.
*****************************************
*End OF Program
****************************************
Input Screen :-
Output Screen :-
4. End Of Selection :-
- When our Selection Process ends, SAP automatically call the event End of Selection.
- This event calls when selection process ends.
- This event helps to identify the end of data/records.
Implementation :-
Code :-
***********************************************
*Start of Program
***********************************************
*Declaring type strcuture
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
currency TYPE zar_curency,
END OF ty_header.
****************
*Internal Table and Work Area
DATA : lt_header type table of ty_header,
ls_header type ty_header.
****************************************
DATA : lv_pm TYPE zar_payment_mode,
lv_curr TYPE zar_curency,
lv_date TYPE zar_order_date.
SELECT-OPTIONS : s_odate FOR lv_date NO-EXTENSION.
SELECT-OPTIONS : s_pm FOR lv_pm NO INTERVALS.
SELECT-OPTIONS : s_curr FOR lv_curr NO INTERVALS.
****************************
*Initializaton Events.
INITIALIZATION.
*****************
*For Date
s_odate-sign = 'I'.
s_odate-option = 'BT'.
s_odate-low = sy-datum - 100.
s_odate-high = sy-datum.
APPEND s_odate.
********
*For Payement Mode
* s_pm-low = 'C'.
* APPEND s_pm.
***************
*Currency
s_curr-low = 'INR'.
APPEND s_curr.
***********************************
*At Selection Screen
AT SELECTION-SCREEN.
IF s_pm-low IS INITIAL.
IF s_pm-low <> 'C'.
MESSAGE 'Payment mode is not entered' TYPE 'E'.
ENDIF.
ENDIF.
**********************************
*Start Of Selection.
START-OF-SELECTION.
Select ORDER_NUMBER ORDER_DATE PAYMENT_MODE CURRENCY
from ZAR_HEADER
into TABLE lt_header
where currency in s_curr.
***********************************
*Displaying data
LOOP at lt_header into ls_header.
WRITE :/ ls_header-ORDER_NUMBER,
ls_header-ORDER_DATE,
ls_header-PAYMENT_MODE,
ls_header-CURRENCY.
ENDLOOP.
*******************************
*End of Selection.
END-OF-SELECTION.
WRITE :/ TEXT-001.
*****************************************
*End OF Program
****************************************
Output :-
5. Top of Page :-
- TOP-OF-PAGE event calls when the first write statement occurs in a program.
- The purpose of this event is to provide title/header of a new page.
Implementation :-
Code :-
***********************************************
*Start of Program
***********************************************
*Declaring type strcuture
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
currency TYPE zar_curency,
END OF ty_header.
****************
*Internal Table and Work Area
DATA : lt_header type table of ty_header,
ls_header type ty_header.
****************************************
DATA : lv_pm TYPE zar_payment_mode,
lv_curr TYPE zar_curency,
lv_date TYPE zar_order_date.
SELECT-OPTIONS : s_odate FOR lv_date NO-EXTENSION.
SELECT-OPTIONS : s_pm FOR lv_pm NO INTERVALS.
SELECT-OPTIONS : s_curr FOR lv_curr NO INTERVALS.
****************************
*Initializaton Events.
INITIALIZATION.
*****************
*For Date
s_odate-sign = 'I'.
s_odate-option = 'BT'.
s_odate-low = sy-datum - 100.
s_odate-high = sy-datum.
APPEND s_odate.
********
*For Payement Mode
* s_pm-low = 'C'.
* APPEND s_pm.
***************
*Currency
s_curr-low = 'INR'.
APPEND s_curr.
***********************************
*At Selection Screen
AT SELECTION-SCREEN.
IF s_pm-low IS INITIAL.
IF s_pm-low <> 'C'.
MESSAGE 'Payment mode is not entered' TYPE 'E'.
ENDIF.
ENDIF.
**********************************
*Start Of Selection.
START-OF-SELECTION.
Select ORDER_NUMBER ORDER_DATE PAYMENT_MODE CURRENCY
from ZAR_HEADER
into TABLE lt_header
where currency in s_curr.
***********************************
*Displaying data
LOOP at lt_header into ls_header.
WRITE :/ ls_header-ORDER_NUMBER,
ls_header-ORDER_DATE,
ls_header-PAYMENT_MODE,
ls_header-CURRENCY.
ENDLOOP.
*******************************
*End of Selection.
END-OF-SELECTION.
WRITE :/ TEXT-001.
***********************************
*Top of Page
TOP-OF-PAGE.
WRITE :/ TEXT-002, sy-pagno.
*****************************************
*End OF Program
****************************************
Output :-
6. End of Page :-
- END-OF-PAGE event calls when the last WRITE statement occurs in a program for a page.
- The purpose of this event is to provide footer or some information at the beginning of a new page.
- For end of page event to trigger, we need to provide the line count.
- Example :- LINE COUNT 5(2), It means the total number of lines on a page is 5 and out of that 3 are reserved for end of page.
Implementation :-
- If there are 10 lines, in a page then last 2 lines will be reserved for end of page.
Code :-
REPORT zar_classical_events LINE-COUNT 10(2).
***********************************************
*Start of Program
***********************************************
*Declaring type strcuture
TYPES: BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
currency TYPE zar_curency,
END OF ty_header.
****************
*Internal Table and Work Area
DATA : lt_header type table of ty_header,
ls_header type ty_header.
****************************************
DATA : lv_pm TYPE zar_payment_mode,
lv_curr TYPE zar_curency,
lv_date TYPE zar_order_date.
SELECT-OPTIONS : s_odate FOR lv_date NO-EXTENSION.
SELECT-OPTIONS : s_pm FOR lv_pm NO INTERVALS.
SELECT-OPTIONS : s_curr FOR lv_curr NO INTERVALS.
****************************
*Initializaton Events.
INITIALIZATION.
*****************
*For Date
s_odate-sign = 'I'.
s_odate-option = 'BT'.
s_odate-low = sy-datum - 100.
s_odate-high = sy-datum.
APPEND s_odate.
********
*For Payement Mode
* s_pm-low = 'C'.
* APPEND s_pm.
***************
*Currency
s_curr-low = 'INR'.
APPEND s_curr.
***********************************
*At Selection Screen
AT SELECTION-SCREEN.
IF s_pm-low IS INITIAL.
IF s_pm-low <> 'C'.
MESSAGE 'Payment mode is not entered' TYPE 'E'.
ENDIF.
ENDIF.
**********************************
*Start Of Selection.
START-OF-SELECTION.
Select ORDER_NUMBER ORDER_DATE PAYMENT_MODE CURRENCY
from ZAR_HEADER
into TABLE lt_header
where currency in s_curr.
***********************************
*Displaying data
LOOP at lt_header into ls_header.
WRITE :/ ls_header-ORDER_NUMBER,
ls_header-ORDER_DATE,
ls_header-PAYMENT_MODE,
ls_header-CURRENCY.
ENDLOOP.
*******************************
*End of Selection.
END-OF-SELECTION.
WRITE :/ TEXT-001.
***********************************
*Top of Page
TOP-OF-PAGE.
WRITE :/ TEXT-002, sy-pagno.
*************************************
*End of Page
END-OF-PAGE.
WRITE :/ 'END Of page Number', sy-pagno.
*****************************************
*End OF Program
****************************************
Output :-
- In the output we can see our first page is only of 8 lines and rest ones have been transferred to the second page.
- Also for the first page last 2 lines have been used for End of Page event.
So, that’s enough for today.
We will continue the rest part tomorrow
Comments
Post a Comment