ABAP Report programming: –

SAP-ABAP programs are either written as “Reports” or as “Dialogs”. ABAP Report programming is done when a large amount of data is to be presented. This includes selecting data from the tables in the ABAP Dictionary, processing the data and formatting it. ABAP Reports can also be downloaded from SAP into an Excel sheet and distributed within and outside an organization, or sent by e-mail to a person several thousand miles away.

Events in Report Programming

ABAP Report programs are also known as Event Driven Programs. The various events in report programming are:

Load-of-program

This is the first event in report programming which loads a program of type 1, M, F, or S and triggers the associated event in an internal session after the loading. It then runs a processing block that is associated with the program only once for each program and internal session.

Initialization

Initialization is executed just before the display of the selection screen. Here are the values are initialized and one may assign different values other than the values that are shown by default on the selection screen. One may also feed the selection screen with more values at runtime.

At Selection-Screen.

This event occurs when the selection screen is processed, at the end of then event PAI (or Process After Event). Any validations and checks of the values are done here after input.

Start-of-Selection.

In this event, the report program begins and values are selected  from  the tables.

End-of-selection.

This event writes the data to the screen after all the data have been selected.

 Interactive Events

These are events used for interactive reporting, to create a detailed list from a basic list.

A simple Report program looks like this:

[codesyntax lang=”abap” title=”Report program ” bookmarkname=”Report program “]

REPORT  ZWORKAREAS_ITABS LINE-SIZE 15 LINE-COUNT 25(3)  MESSAGE-ID ZMSG


**delaration of itab

DATA : BEGIN OF IT_ITAB OCCURS 0,
       EMPNO TYPE I,
       EMPNAME TYPE STRING,
       EMPSAL TYPE P,
       END   OF IT_ITAB,
*** EXTERNAL ITAB2 AND WORKAREA 2

       IT_ITAB2 LIKE IT_ITAB OCCURS 0,
       WA_ITAB2 LIKE IT_ITAB.






***POPULATING THE ITAB

IT_ITAB-EMPNO = 100.
IT_ITAB-EMPNAME = 'KUMAR'.
IT_ITAB-EMPSAL = 1000.

APPEND IT_ITAB.


IT_ITAB-EMPNO = 200.
IT_ITAB-EMPNAME = 'PRAVEEN'.
IT_ITAB-EMPSAL = 2000.

APPEND IT_ITAB.


IT_ITAB-EMPNO = 300.
IT_ITAB-EMPNAME = 'PRASANTH'.
IT_ITAB-EMPSAL = 3000.

APPEND IT_ITAB.



***RETRIVING THE RECS FROM ITAB

WRITE :/10 'RECS FROM ITAB'.
ULINE.
SKIP.

  IT_ITAB2[] = IT_ITAB[].


WRITE :/10 'RECS FROM ITAB2'.
ULINE.
SKIP.

LOOP AT IT_ITAB2 INTO WA_ITAB2.

  WRITE :/10 WA_ITAB2-EMPNO,
          WA_ITAB2-EMPNAME,
          WA_ITAB2-EMPSAL.

  SKIP 2.

ENDLOOP.

[/codesyntax]

Few points to consider from the above program:

# A report program is an executable program with the Program Type 1

# A report program is also known as an Event Driven program.

#You must specify the Application Type of the report program – whether it related to Sales and Distribution, FICO, or is a Cross Application Program.

#A report program ALWAYS begins with Report <report-name>.

#The line size for a report program is specified by using line-size <size>. This is not compulsory.

#The line count for a report program is specified by using line-count n(n1). This is not compulsory. n is how many lines for the page and n1 is how many lines are for the page footer.

#Message-id <message class name> is used to convey a certain message about the program or an error information. All Message classes are maintained in SE91.

 Interactive Reports

 Interactive Reports are special report programs that are user driver, allowing the user to interactively control how data is displayed, using many display lists in addition to the primary or basic list. The secondary lists, which are displayed on clicking on a data item in the basic list open in a new screen. Interactive report programming introduces several new concepts such as Hotspot and Hide and interactive events such as At Line Selection and Top-Of-Page during Line Selection. We will be giving an example of an interactive program, it may seem to be complicated at first, but as you take time over it, and learn some of the related concepts it becomes easier.

[codesyntax lang=”abap” lines_start=”0″ title=”Example of an Interactive Report:” bookmarkname=”Example of an Interactive Report:”]
REPORT  ZITAB_NEW MESSAGE-ID ZMSGCLSS LINE-SIZE 133
 LINE-COUNT 50(3).
 INCLUDE ZDECLARATION. "DECLARATION OF VARIBLES AND SELECT-OPTIONS
 TOP-OF-PAGE.
 PERFORM ZTOP_OF_PAGE. "perform is declaration and invocation
 START-OF-SELECTION.
 PERFORM ZSELECT_DATA. "perform is declaration and invocation
 
END-OF-SELECTION.
PERFORM ZDISPLAY_DATA. "perform is declaration and invocation
***COPY THE LSIND VALUE OT T_LSIND FOR INTERCTIVE REPORTING
T_LSIND = SY-LSIND.

CASE T_LSIND.
  WHEN 1.
  PERFORM ZIACTIVE_REPORT. "perform is declaration and invocation
  WHEN OTHERS.
ENDCASE.

TOP-OF-PAGE  DURING LINE-SELECTION.
CASE T_LSIND.
  WHEN 1.
WRITE :/10 'Employee Address Details'.
uline.
skip.

ENDCASE.

END-OF-PAGE.
**PRINTING FOOTER
CASE T_LSIND.
 WHEN 0.
 WRITE :/10 'PAGE NO=',T_PAGNO.
 WHEN 1.
WRITE :/10 'PAGE NO=',T_PAGNO.
ENDCASE.

INCLUDE ZSUB_ROUT_DEF.

TABLES : ZEMPDET,  ZEMPADDR.

DATA :  IT_ITAB1 LIKE ZEMPDET OCCURS 0 WITH HEADER LINE,
       IT_ITAB2 LIKE ZEMPADDR OCCURS 0 WITH HEADER LINE,

       JUMP1 TYPE I,
       JUMP2 TYPE I,
       JUMP3 TYPE I,

       T_LSIND LIKE SY-LSIND, "TEMP VARIBLE TO CAPTURE THE LIST INDEX
       T_PAGNO LIKE SY-PAGNO VALUE 1. "TEMP PAGE NO LIKE SY-PAGENO FOR IREPRT
SELECT-OPTIONS : S_EMPNO FOR ZEMPDET-ZEMPNO.
INITIALIZATION.

S_EMPNO-SIGN = 'I'.
S_EMPNO-OPTION = 'BT'.
S_EMPNO-LOW = '100'.
S_EMPNO-HIGH = '105'.
APPEND S_EMPNO.

FORM  ZTOP_OF_PAGE .

WRITE :/10 'Employee Details'.
ULINE.
SKIP.

ENDFORM.               
" ZTOP_OF_PAGE FORM ZSELECT_DATA .

SELECT * FROM ZEMPDET INTO TABLE IT_ITAB1  WHERE ZEMPNO IN S_EMPNO.



ENDFORM.          
    " ZSELECT_DATA FORM ZDISPLAY_DATA .

  LOOP AT IT_ITAB1.

  WRITE :/10 it_itab1-zempno HOTSPOT,it_itab1-zempname,it_itab1-zempsal,SY-LSIND.

  HIDE it_itab1-ZEMPNO.

  ENDLOOP.

**LOGIC FOR END OF PAGE EVENT
JUMP1 = SY-LINCT - 3.
JUMP2 = SY-LINNO.
JUMP3 = JUMP1 - JUMP2.
SKIP JUMP3.

 CLEAR : JUMP1,JUMP2,JUMP3.


ENDFORM.                
" ZDISPLAY_DATA FORM ZIACTIVE_REPORT .

      SELECT * FROM ZEMPADDR INTO TABLE IT_ITAB2 WHERE
                ZEMPNO EQ IT_ITAB1-ZEMPNO.

      LOOP AT IT_ITAB2.
        WRITE :/10 it_itab2-zempno,it_itab2-zcity,it_itab2-zpin,SY-LSIND.
        ENDLOOP.

T_PAGNO = T_PAGNO + 1.

JUMP1 = SY-LINCT - 3.
JUMP2 = SY-LINNO.
JUMP3 = JUMP1 - JUMP2.
SKIP JUMP3.

***INCREMENT THE PAGE NO
 CLEAR : JUMP1,JUMP2,JUMP3.

ENDFORM.                    " ZIACTIVE_REPORT
[/codesyntax]

Read more for SAP ABAP interview questions and answers with scenarios.