Pages

Tuesday, November 27, 2012

Classical Report in SAP


Classical Reports

Events in Classical report
Events associated with classical report are as follows and each one will be discussed in
detail.

1. INITIALIZATION
2. AT SELECTION-SCREEN
3. AT SELECTION-SCREEN ON
4. START-OF-SELECTION
5. TOP-OF-PAGE
6. END-OF-SELECTION
7. END-OF-PAGE

In this case first three events are associated with selection screen. Rests of the events are
associated with your list.

INITIALIZATION

We have already seen how to fill default values for the selection criteria. But in
many cases you need to calculate the value and then put it in selection criteria. For
example, say, you are accepting date from user and you need to fill in the default
value for lower range as sy-datum – 30 days and sy-datum for higher range. In this
case you are calculating lower range and then filling the criteria. This can be done
in INITIALIZATION event. Piece of code to do the above task would look like the
following:

Tables: Sflight.
Select-options: fldate1 for sflight-fldate.
INITIALIZATION.
Data: date1 like SY-DATUM.
Date1 = sy-datum – 30.
Fldate1-low = date1.
Fldate1-high = sy-datum.
Append fldate1.
* Here appending is required because fldate1 is int’ table
This event is triggered when you execute your program for the first time i.e., before
selection screen is displayed.

AT SELECTION-SCREEN

When user enters the values in the fields of selection screen and clicks on execute
button, this event gets triggered. This event is basically for checking the values entered
by the user for the fields of the selection screen i.e., data validity checking. This event is
for entire selection screen. For example:
You are accepting carrid, connid, fldate from user and you don’t want to proceed if user
enters no value for carrid and fldate. Using AT SELECTION-SCREEN can do this.

Select-options: carrid1 for sflight-carrid,
Connid1 for sflight-connid,
F1date1 for sflight-f1date.

AT SELECTION-SCREEN.

If carrid1-low ne ‘ ’ and fldate1-low = ‘ ’.
Error message.
Endif.

In this case, if both the fields are entered blank, then the user gets error message.
Basically, this event is for many fields on selection screen. Usually, it is for the fields
which are logically related.

AT SELECTION-SCREEN ON

When you want to check for specific value of a field. For example, carrid should be in the
range of ‘LH’ and ‘SQ’. This can be done in this event. Basically, this event is for
checking individual fields. You can have many AT selection-screen events in your
program (i.e., for each field specified in the Select-Options).

Select-Options carrid1 for sflight-carrid.

AT SELECTION-SCREEN.
If carrid1-low ne ‘LH’ and carrid1-high ne ‘SQ’.
Error message.
Endif.
Here the system will not proceed on entering wrong values.

START-OF-SELECTION

This is the first event for your list. Once all the events are triggered for selection screen,
the data is retrieved from database. Data declaration, select statements are done in this
event. Consider the following example:

START-OF-SELECTION.
Data: mtype i.
Tables: sflight.
Select * from sflight where carrid = ‘LH’.
Write: / sflight-carrid,sflight-connid.
Endselect.

TOP-OF-PAGE

This event is triggered with first WRITE statement or whenever new page is triggered.
Advantage of using this event is that, whatever you write under this event, is applicable
to all the pages. If you don’t have any write statement before TOP-OF-PAGE or in
START-OF-SELECTION, this event is not triggered at all. For example, if you want the

name of company and column headers for all the pages, it can be written in this event.

TOP-OF-PAGE
Write: / ‘Bangalore’.
Write : / 10 ‘carrid’, 20 ‘connid’, 30 ‘fldate’.

END-OF-PAGE

This event is triggered at the end of page.
End-of-page.
Write : / ‘page number’, sy-pagno.
In this case page number will be written on every page.

Conditional triggering of EOP

Consider the following case.
REPORT ZDEMO1 line-count 15(3).
Top-of-page.
Write: ‘this line is written by top-of-page event’.
Start-of-selection.
Write: ‘this line is written by start-of-selection event’.
End-of-page.
Write : ‘this line is written by end-of-page event’.

In this case EOP will never be triggered, as end of page is never reached. The total Line-
count defined for page = 15 in which 3 lines are for footer area. The output of the above
code will be
This line is written by top of page event.
This line is written by start of selection event.

In output screen, only two lines are written and cursor remains still on 3rd line, the end-
of-page event is not triggered. To trigger end of page event, cursor should reach at the
last position, in this case on 11th line.

Such cases are quite common, and could be overcome by conditional triggering of end of
page.

Sy-linct is the system variable, which gives total line count of a list.
Sy-linno is the system variable, which gives the current line number where the cursor is
placed on the list.


Using Variants with selection criteria

In many cases you need report to execute report at regular interval for certain fixed
values of selection criteria. That means each times you execute the report you need to
enter its values again and again. ABAP/4 provides the facility by which you can define
the values for selection screen and store it. Using VARIANTS can do this. It can be
defined as group of values used for selection criteria while executing report. For a
particular report, you create a variant which means variant created for particular report
cannot be used for another report. The group of values for the selection criteria is saved
and assigned a variant name. So every time you call a report, you need not specify the
values for selection criteria but instead call the variant thus avoiding extra typing. User
can have many variants for a single report. Each of them can be used as different type of
information. For example, if a manager wants to see how an employee in personnel
department or admin department has performed. He need not enter the department,
one has to just execute the report with variant. In case he doesn’t know about the
variant, which is available, he can display list of variants attached to the report and
values assigned to each variant.

Creating variant
> Execute the report program. The selection screen is displayed.
> Enter the values for selection screen and click on saves.

> System displays the variant screen
> Enter the variant name and description for it.
> Save it.

Usually the variants are useful when you need to execute the report in background,
which will be discussed in background processing.

Example for Classical Report Events.

*&---------------------------------------------------------------------*
*& Report ZBASU_CLASSICAL_REPORT_EVENTS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZBASU_CLASSICAL_REPORT_EVENTS NO STANDARD PAGE HEADING
LINE-SIZE 90 LINE-COUNT 40(2).

Tables: mara.

data: begin of itab occurs 0,
matnr like mara-matnr,
ersda like mara-ersda,
ernam like mara-ernam,
end of itab.

DATA: M TYPE I.

selection-screen: begin of block b1 with frame title text-002.
select-options: material for mara-matnr.
selection-screen: end of block b1.

INITIALIZATION.
MATERIAL-LOW = '100'.
MATERIAL-HIGH = '200'.
MATERIAL-SIGN = 'I'.
MATERIAL-OPTION = 'BT'.

AT SELECTION-SCREEN.

IF MATERIAL-LOW = ' ' AND MATERIAL-HIGH = ' '.
MESSAGE 'ENTER PROPER DATA' TYPE 'E'.
ENDIF.

START-OF-SELECTION.

SELECT MATNR ERSDA ERNAM FROM MARA INTO CORRESPONDING FIELDS OF
TABLE ITAB WHERE MATNR IN MATERIAL.

TOP-OF-PAGE.

WRITE:/ 'GALAXE SOLUTIONS'.

END-OF-SELECTION.

LOOP AT ITAB.
WRITE:/ ITAB-MATNR,
ITAB-ERSDA,
ITAB-ERNAM.
ENDLOOP.

M = SY-LINCT - SY-LINNO - 2.
SKIP M.

END-OF-PAGE.

WRITE:/ 'BANGALORE', SY-DATUM
CLASSICAL REPORTS IN SAP ABAP-CLASSICAL REPORTS

REPORT ZCLASS_F34 NO STANDARD PAGE HEADING LINE-COUNT 30(3).
TABLES EKKO.
SELECT-OPTIONS S_EBELN FOR EKKO-EBELN.
PARAMETERS P_EBELN LIKE EKKO-EBELN DEFAULT ‘4500004823’.
DATA G_EBELN LIKE EKKO-EBELN.
DATA: BEGIN OF I_EKKO OCCURS 0,
EBELN TYPE EKKO-EBELN,
BUKRS TYPE EKKO-BUKRS,
ERNAM TYPE EKKO-ERNAM,
LIFNR TYPE EKKO-LIFNR,
END OF I_EKKO.
DATA: BEGIN OF I_EKPO OCCURS 0,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
WERKS TYPE EKPO-WERKS,
LGORT TYPE EKPO-LGORT,
MATNR TYPE EKPO-MATNR,
NETWR TYPE EKPO-NETWR,
END OF I_EKPO.
DATA: BEGIN OF I_T001 OCCURS 0,
BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
END OF I_T001.

DATA I_LFA1 TYPE LFA1 OCCURS 0 WITH HEADER LINE.
DATA G_CHK(1) TYPE C.
***********************************************************
*
INITIALIZATION
*
***********************************************************
INITIALIZATION.
S_EBELN-SIGN = ‘I ‘.
S_EBELN-OPTION = ‘BT ‘.
S_EBELN-LOW = ‘4500004823 ‘.
S_EBELN-HIGH = ‘4500005823 ‘.
APPEND S_EBELN.
CLEAR S_EBELN.
* S_EBELN-SIGN = ‘I ‘.
* S_EBELN-OPTION = ‘EQ ‘.
* S_EBELN-LOW = ‘4500004824 ‘.
*
* APPEND S_EBELN.
* CLEAR S_EBELN.
*
* S_EBELN-SIGN = ‘I ‘.
* S_EBELN-OPTION = ‘EQ ‘.
* S_EBELN-LOW = ‘4500004825 ‘.
*
* APPEND S_EBELN.
* CLEAR S_EBELN.
*************************************************************
*
AT SELECTION-SCREEN
*
*************************************************************
AT SELECTION-SCREEN.
SELECT SINGLE EBELN INTO G_EBELN FROM EKKO WHERE EBELN EQ
P_EBELN.
IF G_EBELN IS INITIAL.
SET CURSOR FIELD ‘P_EBELN ‘.
MESSAGE E000(ZCF) WITH P_EBELN.
ENDIF.
*************************************************************
*
START-OF-SELECTION
*
*************************************************************
START-OF-SELECTION.
SELECT EBELN
BUKRS
ERNAM
LIFNR INTO TABLE I_EKKO
FROM EKKO WHERE EBELN IN S_EBELN.
*************************************************************
*
END-OF-SELECTION
*
*************************************************************

END-OF-SELECTION.
SET TITLEBAR ‘ZCF34 ‘.
SET PF-STATUS ‘CF34 ‘.
LOOP AT I_EKKO.
WRITE:/ SY-VLINE, G_CHK AS CHECKBOX, (15) I_EKKO-EBELN, ”
HOTSPOT ON,
SY-VLINE, (10) I_EKKO-BUKRS, ” HOTSPOT ON,
SY-VLINE, (20) I_EKKO-ERNAM,
SY-VLINE, (15) I_EKKO-LIFNR.
* HIDE I_EKKO-EBELN.
ENDLOOP.
*************************************************************
*
TOP-OF-PAGE
*
*************************************************************
TOP-OF-PAGE.
ULINE.
WRITE:/ SY-VLINE, 30 ‘Purchase Order Details ‘.
ULINE.
WRITE:/ SY-VLINE, (15) ‘PO Doc ‘,
SY-VLINE, (10) ‘CoCode ‘,
SY-VLINE, (20) ‘U Name ‘,
SY-VLINE, (15) ‘Vendor ‘.
ULINE.
*************************************************************
*
END-OF-PAGE
*
*************************************************************
END-OF-PAGE.
ULINE.
WRITE:/30 ‘*** End of Report *** ‘, SY-PAGNO.
ULINE.
*************************************************************
*
AT LINE-SELECTION
*
*************************************************************
*AT LINE-SELECTION.
AT USER-COMMAND.
DATA: G_FIELD(20) TYPE C,
G_VALUE(10) TYPE C.
DATA: L_EBELN TYPE EKPO-EBELN,
G_BUKRS TYPE T001-BUKRS,
G_LIFNR(10) TYPE N.
GET CURSOR FIELD G_FIELD VALUE G_VALUE.
IF G_FIELD EQ ‘I_EKKO-EBELN ‘ AND SY-UCOMM EQ ‘EKPO ‘.
SET TITLEBAR ‘ZCF35 ‘.
L_EBELN = G_VALUE.
SELECT EBELN
EBELP
WERKS

LGORT
MATNR
NETWR INTO TABLE I_EKPO
FROM EKPO WHERE EBELN EQ L_EBELN.
LOOP AT I_EKPO.
WRITE:/ I_EKPO-EBELN,
I_EKPO-EBELP,
I_EKPO-WERKS,
I_EKPO-LGORT,
I_EKPO-MATNR,
I_EKPO-NETWR.
ENDLOOP.
CLEAR I_EKKO-EBELN.
ELSEIF G_FIELD EQ ‘I_EKKO-BUKRS ‘ AND SY-UCOMM EQ ‘T001 ‘.
G_BUKRS = G_VALUE.
SELECT BUKRS
BUTXT INTO TABLE I_T001
FROM T001 WHERE BUKRS EQ G_BUKRS.
*– Popup List
WINDOW STARTING AT 10 10
ENDING AT 50 50.
LOOP AT I_T001.
WRITE:/ I_T001-BUKRS,
I_T001-BUTXT.
ENDLOOP.
ELSEIF G_FIELD EQ ‘I_EKKO-LIFNR ‘ AND SY-UCOMM EQ ‘LFA1 ‘.
G_LIFNR = G_VALUE.
SELECT * FROM LFA1 INTO TABLE I_LFA1 WHERE LIFNR EQ G_LIFNR.
LOOP AT I_LFA1.
WRITE:/ I_LFA1-LIFNR, I_LFA1-NAME1.
ENDLOOP.
ENDIF.
*************************************************************
*
TOP-OF-PAGE DURING LINE-SELECTION
*
*************************************************************
TOP-OF-PAGE DURING LINE-SELECTION.
ULINE.
IF G_FIELD EQ ‘I_EKKO-EBELN ‘.
WRITE:/ SY-VLINE, 30 ‘Purchase Item Details ‘.
ELSEIF G_FIELD EQ ‘I_EKKO-BUKRS ‘.
WRITE:/ SY-VLINE, 30 ‘Company Code Details ‘.
ENDIF.
ULINE.

No comments:

Post a Comment