abap report
DESCRIPTION
ABAP Report programming overiew has described with examples, Classification has reports are enlightenTRANSCRIPT
Report ProgrammingSrinivas Vuppala
Report Programming
SAP- ABAP supports two types of Programs
Report Programs Dialog Programs
Report Programs Report Programs are always Executable Programs. Program Type is always 1
Every Report program corresponds to a particular Application Type are of Sales & Distribution, Material Management, FI CO etc.
Report Programming is an Event-driven programming
Report Programs
The first line of a report program is always Report <report-name>.
In order to suppress the list heading or the name of the program the addition No Standard Page Heading is used.
The line size for a particular report can be set by using the addition line-size <size>.
The line count for a particular page can be set by using the addition line-count n(n1). N is the number of lines for the page and N1 is the number of lines reserved for the
page footer.
To display any information or error message, we add a message class to the program using the addition: Message-id <message class name>.
Message classes are maintained in SE91
Uses of Report Program
To display the large amount of data and also data from a number of tables that
have to be selected and processed before presenting
when reports demand a special format
when the report has to be downloaded from SAP to an Excel sheet to be
distributed across.
when the report has to be mailed to a particular person.
Report Program
▪ Ideal report program should start with:
Report <report name> no standard page heading line-size <size> line-count <n(n1)>
message-id <message class>.
SELECTION SCREEN
Selection screen is the screen where one specifies the input values for Field.
Functions of selection screen
Abap program use selection screens to obtain input from users
The rules for calling and defining selection screens in ABAP programs depend on the program type
The selection screen is normally generated from the
Parameters
Select-Options
Select-screen
Syntax
Selection-screen begin of screen <screen #>selection-screen begin of block <#> with frame title <text>………………….selection-screen end of block <#>selection-screen end of screen <screen #>
Parameters Parameters helps one to do dynamic selection.
They can accommodate only one value for one cycle of execution of the program.
Syntax
Defining parameters as a data type
Parameters p_id(30) type c.
Defining parameters like a table field.
Parameter p_id like <table name>-<field name>.
Parameters can be Checkboxes as well as Radiobuttons.
Parameters p_id as checkbox. Parameters p_id1 radiobutton group <group name>. Parameters p_id2 radiobutton group <group name>.
Parameters can be listbox.
Parameter p_id like <table name>-<field name> as listbox
Select Options
A Select-Option is used to input a range of values or a set of values to a program
Syntax
select-options s_vbeln for vbak-vbeln.
You can also define a select option like a variable
select-options s_vbeln for vbak-vbeln no intervals no-extension
Selection Tables
To declare a selection table in the program that is linked to the <f> column of a database or to at internal <f> field in the program
Their main purpose is to directly translate the selection criteria into database selections using WHERE addition in open SQL statements
Structure of Selection Tables:
▪ The row type of a selection table is a structure that consists of four components
SIGN
OPTION
LOW
HIGH
SIGN ▪ The data type of SIGN is C with length 1. ▪ The contents of SIGN determine for each row condition is to be
included or excluded from the resulting set of all rows.
Possible values are I and E▪ I stands for ‘inclusive’ (inclusion criteria – operators are not
inverted)▪ E stands for ‘exclusive’ (exclusive criteria – operators are
inverted)
OPTION▪ The data type of OPTION is C with length 2.
▪ OPTION contains the selection operator., it contains following operator
▪ If HIGH is empty, You can use EQ,NE, GT,LE,LT,CP(contains pattern) AND NP(No pattern)
▪ If HIGH is filled, You can use BT(Between) and NB (Not between)
Low
The data type of LOW is same as column type of the database table to which selection criteria linked.
It represents the lower limit of selection criteria.
High
The data type of HIGH is same as column type of database table to which selection criteria linked.
It represents the higher limit of selection criteria.
Syntax
SELECT-OPTIONS <seltab> for <f>.
Valid data types of <f> include all elementary ABAP types expect data type F.
EVENTS IN AN ABAP REPORT PROGRAM
▪ ABAP report programs are event driven programs
Events in a report Program
Load-of-program.
▪ Triggers the associated event in an internal session after loading a program of program type Executable program (type 1), Module Pools( Type M), Function Modules (Type F), or Subroutine Pools (Type S).
▪ Also runs the associated processing block once and once only for each program and internal session.
▪ The processing block LOAD-OF-PROGRAM has the same function for an ABAP program of type 1, M, F or S as a constructor has for classes in ABAP Objects
INITIALIZATION
▪ This event occurs before the standard selection screen is called
▪ To initialize the input fields of the standard selection screen
AT SELECTION-SCREEN
▪ This event is processed before leaving the screen.
▪ To validate the input provided through the selection screen.
AT SELECTION-SCREEN ON <Field Name> This event is processed before leaving the selection screen element. To validate the individual input provided through selection screen
START-OF-SELECTION This event occurs after the selection screen has been processed and before data
is read using the logical database. The Report statement always executes a START-OF-SELECTION implicitly
consequently all processing logic
TOP-OF-PAGE
This is a list processing event executed before the first data is output on a new page.
This is processed only when generating basic list. This is only executed before outputting the first line using any output statement
such as write, uline, skip on a new page This allows you to define output which supplements the standard page header at
the beginning of the page.
END-OF-PAGE
This will be triggered when it reaches the END-OF-PAGE. This is used to print the same footer details for all pages.
END-OF-SELECTION
This is called by the runtime environment to occur. It is triggered after all of the data has been read from the logical database and
before the list processor is started.
TOP-OF-PAGE DURING LINE-SELECTION
This event is used to create page header for detail list
The system triggers this event for each detail list.
You must program the processing block accordingly
GET
This event is triggered each time a logical database program reads a row from a database table using GET statement
GET LATE
This event is triggered when all of the data records for a node of the logical database have been read
AT LINE-SELECTION
When you choose a list line, the system triggers at AT LINE-SELECTION event.
GUI status permits the function(f2) by choosing choose, the user can create 20 lists
AT USER COMMAND
This event triggers at the function codes that are intercepted by the runtime environment which must be defined in GUI status.
AT PF <nn> (obsolete)
When ever the user hits the function code this event will trigger
All the function keys of the keyboard F<nn> that are not for predefined functions, are set to function codes PF<nn>, where <nn> is a number between 01 and 24.
During the list processing, function codes PF<nn> are linked to the event blocks for PF<nn>.
Classical Reports
▪ Displaying the whole data as one list
▪ One Basic List
Events in Classical Report
▪ INITIALIZATION
▪ AT SELECTION-SCREEN
▪ AT SELECTION-SCREEN ON <Field Name>
▪ START-OF-SELECTION
▪ TOP-OF-PAGE
▪ END-OF-PAGE
▪ END-OF-SELECTION
Example: Classical Reports
Report ZDEMO_CLASSICAL_REPORTS_EVENTS NO STANDARD PAGE DEADING LINE-SIZE(72) LINE-COUNT 20(3) MESSAGE-ID ZCRE.
DATA: BEGIN OF ITAB, EBELN TYPE EBELN, LIFNR TYPE LIFNR, BUKRS TYPE BUKRS, EKORG TYPE EKORG, EBELP TYPE EBELP, MATNR TYPE MATNR, MENGE TYPE MENGE, NETPR TYPE NETPR, END OF ITAB.
DATA : JTAB LIKE TABLE OF ITAB.
DATA: V_BUKRS TYPE BUKRS, V_EKORG TYPE EKORG.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_BUKRS FOR V_BUKRS, "COMPANY CODE S_EKORG FOR V_EKORG. "PURCHASING ORGANSIATION
SELECTION-SCREEN END OF BLOCK B1.
******************************************TOP-OF-PAGE*****************************************TOP-OF-PAGE.WRITE: / 5 'COMPANY CODE', 17 'VENDOR', 28 'PUR ORG', 40 'Doc No'.uline.
******************************************
*INITIALIZATION
******************************************
S_BUKRS-LOW = '1000'.
S_BUKRS-HIGH = '5000'.
S_BUKRS-SIGN = 'I'.
S_BUKRS-OPTION = 'BT'.
APPEND S_BUKRS.
******************************************
*AT SELECTION-SCREEN
******************************************
AT SELECTION-SCREEN ON S_BUKRS.
SELECT BUKRS INTO V_BUKRS FROM T001 WHERE BUKRS IN S_BUKRS.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: /'INVALID COMPANY CODE'.
ENDIF.
AT SELECTION-SCREEN ON S_EKORG.
SELECT EKORG INTO V_EKORG FROM EKKO WHERE EKORG IN S_EKORG.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: /'INVALID PURCHASING ORGANISATION'.
ENDIF.
******************************************
*START-OF-SELECTION
******************************************
START-OF-SELECTION.
SELECT EKKO~EBELN
EKKO~LIFNR
EKKO~BUKRS
EKKO~EKORG
INTO TABLE JTAB
FROM EKKO INNER JOIN EKPO
ON EKKO~EBELN = EKPO~EBELN
WHERE EKKO~BUKRS IN S_BUKRS AND EKKO~EKORG IN
S_EKORG.
******************************************
*END-OF-SELECTION
******************************************
END-OF-SELECTION.
IF SY-SUBRC = 0.
LOOP AT JTAB INTO ITAB.
WRITE: /5 ITAB-BUKRS,
17 ITAB-LIFNR,
28 ITAB-EKORG,
40 ITAB-EBELN.
CLEAR ITAB.
ENDLOOP.
ELSE.
WRITE:/'NO RECORDS WERE FOUND'.
ENDIF.
**********************************************************
*END-OF-PAGE
**********************************************************
END-OF-PAGE.
ULINE.
WRITE: / ‘PAGE NO’, SY-PAGENO.
ULINE.
Interactive Reports
▪ All lists created during an interactive list event are detail lists.
▪ Each interactive event creates a new detail list.
▪ You can maintain one basic list and Upto 20 detail list.
▪ The Basic list has a standard list status and a standard page header.
▪ The TOP-OF-PAGE and END-OF-PAGE event occur while the basic list is being created.
▪ The basic list is automatically sent to the list processor and displayed at the end of END-OF-SELECTION event.
▪ AT LINE-SELECTION event, the first details list overlays the basic list and thereafter user can create upto 20 detail list
Events in Interactive Reports
▪ INITIALIZATION
▪ AT SELECTION-SCREEN
▪ START-OF-SELECTION
▪ END-OF-SELECTION
▪ TOP-OF-PAGE
▪ END-OF-PAGE
▪ TOP-OF-PAGE DURING LINE SELECTION
▪ AT LINE-SELECTION
▪ AT USER-COMMAND
▪ AT PF <nn> (obsolete)
Example Program
Report Zdemo Interactive_Report_Events No standard page Heading line-size 100
line-count 37(4)
Message-id ZDemo.
TABLES: LFA1,"VENDOR MASTER
EKKO,"PURCHASING DOCUMENT HEADER
EKPO."PURCHASING DOCUMENT ITEM
DATA: BEGIN OF WA_LFA1,
LIFNR TYPE LIFNR,"ACCOUNT NUMBER OF VENDOR
NAME1 TYPE NAME1,"NAME
LAND1 TYPE LAND1,"COUNTRY KEY
ORT01 TYPE ORT01,"CITY
ANRED TYPE ANRED,"TITLE
END OF WA_LFA1.
DATA: IT_LFA1 LIKE STANDARD TABLE OF WA_LFA1.
DATA: BEGIN OF WA_EKKO,
LIFNR TYPE LIFNR,"ACCOUNT NUMBER OF VENDOR
EBELN TYPE EBELN,"PURCHASING DOCUMENT NUMEBR
BSTYP TYPE BSTYP,"PURCHASING DOCUMENT CATEGORY
EKORG TYPE EKORG,"PURCHASING ORGANISATION
END OF WA_EKKO.
DATA: IT_EKKO LIKE STANDARD TABLE OF WA_EKKO.
DATA: BEGIN OF WA_EKPO,
EBELN TYPE EBELN,"PURCHASING DOCUMENT NUMBER
EBELP TYPE EBELP,"ITEM NUMBER OF PURCHASING DOCUMENT
MATNR TYPE MATNR,"MATERIAL NUMBER
BSTYP TYPE BSTYP,"PURCHASING DOCUMENT CATEGORY
EKORG TYPE EKORG,"PURCHASING ORGANISATION
NETPR TYPE NETPR,"NET PRICE
END OF WA_EKPO.
DATA: IT_EKPO LIKE STANDARD TABLE OF WA_EKPO.
DATA: BEGIN OF WA_MAKT,
MATNR TYPE MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKTX,"MATERIAL DESCRIPTION
END OF WA_MAKT.
DATA: IT_MAKT LIKE STANDARD TABLE OF WA_MAKT.
***************************************************************** SELECTION-SCREEN****************************************************************SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.DATA V_LIFNR TYPE LIFNR.SELECT-OPTIONS: S_LIFNR FOR V_LIFNR.SELECTION-SCREEN END OF BLOCK B1.
*********************************************** TOP-OF-PAGE*********************************************TOP-OF-PAGE.WRITE: /40 'BASIC LIST: VENDOR DETAILS' COLOR 5, SY-LSIND.ULINE.FORMAT COLOR 4.WRITE: / 'VENDOR NUMBER', 27 'NAME', 53 'COUNTRY', 65 'CITY', 80 'TITLE'.ULINE.
*************************************************AT SELECTION-SCREEN************************************************AT SELECTION-SCREEN.SELECT SINGLE LIFNR INTO S_LIFNR FROM LFA1 WHERE LIFNR IN S_LIFNR.
IF SY-SUBRC NE 0. MESSAGE E000.ENDIF.
************************************************
*START-OF-SELECTION
************************************************
START-OF-SELECTION.
SELECT LIFNR
NAME1
ORT01
ANRED INTO TABLE IT_LFA1 FROM LFA1 WHERE LIFNR IN S_LIFNR.
***********************************************
* END-OF-SELECTION
***********************************************
END-OF-SELECTION.
LOOP AT IT_LFA1 INTO WA_LFA1.
FORMAT COLOR 3.
WRITE: /5 WA_LFA1-LIFNR, 15 WA_LFA1-NAME1, 55 WA_LFA1-LAND1, 64 WA_LFA1-ORT01, 75 WA_LFA1-ANRED.
*HIDE THE REQUIRED QUERY
HIDE WA_LFA1-LIFNR.
ENDLOOP.
**********************************************
* END-OF-PAGE
**********************************************
END-OF-PAGE.
ULINE.
FORMAT COLOR 4.
WRITE: /75 'PAGE NO', SY-PAGNO.
ULINE.
***********************************************
* AT LINE-SCREEN
***********************************************
AT LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
*DISPLAY PUR.DOC NO IN Ist SECONDARY LIST
SELECT LIFNR
EBELN
BSTYP
EKORG FROM EKKO INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
IF NOT IT_EKKO IS INITIAL.
LOOP AT IT_EKKO INTO WA_EKKO.
AT FIRST.
WRITE: /30 'FIRST SECONDRY LIST: PURCHASING DOCUMENT NUMBER
DETAILS' COLOR 5, SY-LSIND.
ULINE.
FORMAT COLOR 4.
WRITE: / 'ACCOUNT NO', 15 'PUR DOC NO', 30 'DOC CATEGORY', 45 'PUR ORG'.
ULINE.
ENDAT.
FORMAT COLOR 3.
WRITE: / WA_EKKO-LIFNR, 15 WA_EKKO-EBELN, 35 WA_EKKO-BSTYP, 45
WA_EKKO-EKORG.
*HIDE EBELN INTO QUERY
HIDE: WA_EKKO-EBELN.
ENDLOOP.
ELSE.
WRITE: /5 'NO RECORDS FOUND FOR THE SELECTED VENDOR'.
ENDIF.
WHEN 2.
*DISPLAY LINE ITEM IN 2ND SECONDARY LIST
SELECT EBELN
EBELP
MATNR
NETPR FROM EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO.
WHEN 2.
*DISPLAY LINE ITEM IN 2ND SECONDARY LIST
SELECT EBELN
EBELP
MATNR
NETPR FROM EKPO INTO CORRESPONDING FIELDS OF TABLE IT_EKPO.
*WHICH WAS ALREADY HIDDEN AT PREVIOUS LIST
IF NOT IT_EKPO IS INITIAL.
LOOP AT IT_EKPO INTO WA_EKPO.
AT FIRST.
WRITE: /5 'SECOND SECONDARY LIST: ITEM NO OF PURCHASING DOCUMENT'
COLOR 4, SY-LSIND.
ULINE.
FORMAT COLOR 5.
WRITE: / 'PUC DOC NO', 15 'ITEM NO', 25 'MATERIAL NO', 45 'NET PRICE'.
ULINE.
ENDAT.
FORMAT COLOR 3.
WRITE: / WA_EKPO-EBELN, 15 WA_EKPO-EBELP, 25 WA_EKPO-MATNR, 35
WA_EKPO-NETPR.
*HIDE THE MATERIAL NUMBER TO QUERY
HIDE: WA_EKPO-EBELN.
ENDLOOP.
ELSE.
WRITE: /5 'NO RECORDS'.
ENDIF.
WHEN 3.
*DISPLAY MATERIALS DETAILS IN 3RD SECONDARY LIST
SELECT MATNR
MAKTX
INTO TABLE IT_MAKT FROM MAKT WHERE MATNR = WA_EKPO-MATNR.
IF NOT IT_MAKT IS INITIAL.
LOOP AT IT_MAKT INTO WA_MAKT.
AT FIRST.
WRITE: /5 'MATERIAL NO' COLOR 5, SY-LSIND.
ULINE.
FORMAT COLOR 4.
WRITE: /5 'MATERIAL NO', 25 'MATERIAL DESC'.
ULINE.
ENDAT.
FORMAT COLOR 3.
WRITE: /5 WA_MAKT-MATNR, 25 WA_MAKT-MAKTX.
ENDLOOP.
ELSE.
WRITE: /5 'NO RECORDS FOUND'.
ENDIF.
ENDCASE.