You are on page 1of 25

BY MR.

BABU (OASIS TECHNOLOGIES)

Events
The ABAP is an event driven programming language with events are triggered in the particular
order by driver program.

An event is a process block set of line statements or collection of statements.

An event start with the event name and ends with the next event beginning.

Syntax: *Begin of an event*

INITIALIZATION

*Process block

*Begin of an event by ending previous events

AT SELECTION - SCREEN…….

*Process block

*Main program Beginning

START – OF – SELECTION “Default event”.

*Process block

NOTE: The Default event for each executable program is START -OF- SELECTION.

Classical Reports
Classical reports are the simple repots to extract the data from the data
and display the process the database table or data base view, process the extracted
data and display the processed final data using the WRITE statements within the loop
statements.

Events Associated with classical Reports:

Following are the different types of events of classical reports which are triggered in the
same order.

1. LOAD-OF-PROGRAM

2. INITIALIZATION

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
3. AT SELECTION SCREEN: A) AT-SELECTION-SCREEN OUTPUT

B) AT-SELECTION-SCREEN ON VALUE

C) AT-SELECTION-SCREEN ON REQUEST FOR

D) AT SELECTION SCREEEN ON

E) AT-SELECTION-SCREEN

4. START-OF-SELECTION

5. END-OF-SELECTION

6. TOP-OF-PAGE

7. END-OF-PAGE

NOTE: The events LOAD-OF-PROGRAM, INITIALIZATION, AT-SELECTION-SCREEN events,


END-OF-SELECTION are common events for any type of reports.

1. LOAD-OF-PROGRAM:

This event is triggered before INITIALIZATION event while loading a program.

Syntax: *trigger before INITIALIZATION

LOAD-OF-PROGRAM

2. INITIALIZATION:

This event is triggered before the selection screen or input screen is displayed.

1, it is used to clear and refresh the data variables.

2, it can also be used to pass the default values to the selection fields or input fields and data
variables.

NOTE: This event is not used in the real time.

SYNTAX: *Trigger before selection-screen

INITIALIZATION

*Clear, Refresh the data variables

PERFORM < f-clear-refresh >

*Default values

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
PERFORM < f-default-value >

FORM < f-clear-refresh >

CLEAR: < GV_VAR >,

< GT_ DBTAB>

REFRESH: < GT_DBTAB>,

ENDFORM

3. AT-SELECTION-SCREEN Event:

They are triggered while performing any action in the selection screen.

They can also be triggered after input value or data is provided in the selection screen.

Then perform any action.

The AT -SELECTION- SCREEN events are used to format the selection-screen dynamically
and validate or check the input data.

Following are some of the useful AT-SELECTION-SCREEN events.

a) AT SELECTION-SCREEN OUTPUT
b) AT SELECTION-SCREEN ON HELP-REQUEST FOR
c) AT SELECTION-SCREEN ON VALUE HELP-REQUEST FOR
d) AT SELECTION-SCREEN ON

AT SELECTION-SCREEN OUTPUT Event:

This event is triggered after INITIALIZATION event.

It can also be triggered while performing any action in the selection screen.

This event is used to format the selection screen

SYNTAX:

*Triggers after INITIALIZATION

AT SELECTION-SCREEN OUTPUT

*Format selection screen dynamically

PERFORM < F-format-screen-din >

FORM <F- format –din >

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
LOOP AT SCREEN

IF SCREEN- NAME = ‘< S_FIELD_HIGH/P_FIELD>’

SCREEN-ACTIVE =’< 1/0>’

MODIFY SCREEN.

ENDIF

ENDLOOP

ENDFORM

STANDARD STRUCTURE SCREEN:

This structure is field with all the attributes or the properties of all selection field or the input
field in the selection screen.

It behaves like an internal table since it holds each selection field properties at run-time.

Following are some of useful fields in the standard structure screen.

FIELD DESCRIPTION

1) NAME Name of the selection field or input field


2) GROUP Modification group names which are specified using
an addition ‘ MODIF ID’.
3) REQUIRED Makes the input field mandatory.

1->Mandatory

0-> Optional

4) INPUT makes the selection fields (or) input fields as input

(or) output fields

1-> Input for editable mode

2->display mode (non-modifiable mode).

5) OUTPUT makes the selection fields (or) input fields as output

(or) input fields

1->output

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
0->input

6) ACTIVE To make the selection screen fields appear (or) hide.

1->appear

2-> hide.

NOTE:

1) The ‘SELECTION-SCREEN-OUTPUT’ event is also called as process before output event


(PBO) event in reports.
2) ‘AT-SELECTION-SCREEN ON VALUE-REQUEST FOR’ event is triggered when the function
key F4 (OR) the ‘search help’ icon is pressed.
3) ‘AT-SELECTION-SCREEN ON VALUE-REQUEST FOR’ event is used to display the
populated data (possible entries) in a search help window.

AT-SELECTION-SCREEN ON VALUE-REQUEST FOR:

It is also called as PROCESS-ON-VALUE-REQUEST (POV) event in report.

The standard function module “F4IF_INT_TABLE_VALUE_REQUEST” is used to display the


search help with the populated possible entries.

SYNTAX: :

*Triggers with F4 function key (or) search help icon is pressed*

AT-SELECTION-SCREEN-ONVALUE-REQUEST FOR<S_FIELD-LOW/S_FIELD-HIGH/P_FIELD>.

*Populate possible entries and display search help*

PERFORM <F_SEARCH_HELP>.

FORM <F_SEARCH_HELP>.

EXPORTING

: RETURN

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
*get the data*

SELECT <F1>,

<F2>,

INTO TABLE <lt_shelp>

*display search help*

CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’

EXPORTING

: ret_field = <s_field-low/…………..>.

: value_org = ‘s’.

TABLES

Value_tab = <lt_shelp> “possible entries”

Return_tab = <lt_return> “selected entries”

*pass selected entry to input field*

READ TABLE <lt_return> into <ls_return> INDEX 1.

<s_field-low/s_field-high/p_field> = <LS_RETURN>-field value.

ENDFORM.

AT-SELECTION-SCREEN ON HELP REQUEST FOR:

This event is triggered when the function key F1 (or) help icon is pressed. It is used to provide

The help documentation on the screen fields.

The transaction code ‘SE61’ (or) ‘SO72’ is used to maintain the help documentation as per

The specification.

The standard function module “HELP_OBJECT_SHOW’ (WITH TECHNICAL


INFORMATION) and ‘DSYS_SHOW_FOR_F1HELP’ (WITH TECHNICAL INFORMATION) is used
to the maintained documentation.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
NOTE:

This event is also called as ‘PROCESS-ON-HELP REQUEST’ event.

SYNTAX: :

*Triggers when F1 (or) help icon is pressed*

AT-SELECTION-SCREEN ON-HELP REQUEST FOR <S_FIELD-LOW/S_FIELD-HIGH/P_FIELD>.

*Display help documentation*

PERFORM <F_HELP_DOCU>…..

FORM <F_HELP_DOC>.

*Help documentation with technical information*

CALL FUNCTION ‘HELP_OBJECT_SHOW’.

(OR)

*Help documentation without technical information*

CALL FUNCTION ‘DSYS-SHOW_FOR_F1HELP’.

ENDFORM.

AT-SELECTION-SCREEN-ON:

This event is triggered after the input values provided in the selection screen .

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
It is used to validate (or) check the input data of the selection screen.

It can be used on the particular selection field (or) input field.

SYNTAX: :

*Triggers after input data is provided on the specified input field*

AT-SELECTION-SCREEN ON <S_FIELD/P_FIELD>.

*Validate (or) check input field data*

PERFORM <F_VALIDATE_FIELD>;

FORM <F_VALIDATE_FIELD>.

*Get the data based on the input data*

SELECT……………

Into ………………..

Where <f1> in S_field.

(or)

<f2> = p_field.

IF SY-SUBRC NE 0.

*Give message*

MESSAGE ‘<message text>’ type ‘<E/S/I>’.

ENDIF.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
ENDFORM.

START-OF-SELECTION:

It is the default event and mandatory event to execute any executable program (or) report.

The main program begins with this event.

This event is triggered after all the selection screen events are processed.

It is used to specify the data extraction statements.

SYNTAX : :

*After selection screen id processed*

START-OF-SELECTION.

*Extract the data*

PERFORM <F_GET_DATA>.

FORM<F_GET_DATA>.

SELECT <f1>

<f2>

From <dbtab>

Into table <gt_dbtab>

Where <condition1> and

<condition2>……..

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
ENDFORM.

NOTE: If no one event is used in the executable program, the entire program will be triggered

(or) processed under START-OF-SELECTION since it is the default event.

END-OF-SELECTION:

It is continuous event to START-OF-SELECTION EVENT.

It is triggered after START-OF-SELECTION event is processed.

It is used to specify the data process statements.

SYNTAX: :

*Triggers after START-OF-SELECTION*

END-OF-SELECTION.

*Process extracted data populate final data*

PERFORM<F_PROCESS_DATA>.

FORM<F_PROCESS_DATA>.

LOOP AT <gt_base> INTO <gs_base>.

*read table*

READ TABLE <gt_dbtab> INTO <gs_dbtab>.

IF SY-SUBRC = 0.

*Move data to final internal table*

MOVE <gs_dbtab-f1> TO <gs_final-f1>.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
ENDIF.

*Append final internal table*

APPEND <gs_final> TO <gt_final>.

ENDLOOP.

TOP-OF-PAGE:

This event is triggered with the first ULINE (or) WRITE statement in the program.

It is used to specify the column headings for the classical reports.

SYNTAX: :

*First ULINE (or) WRITE Statement*

ULINE/WRITE………..

*Triggers with the First ULINE (or) WRITE Statement.*

TOP-OF-PAGE.

*Populate column headings(or) header*

PERFORM<F_POP_HEADER>.

FORM<F_POP_HEADER>.

WRITE’<column heading or header>’.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
:

ENDFORM.

END-OF-PAGE:

This event is triggered after the current page is ended before the new page is
displayed.

The report addition LINE COUNT must be specified to trigger this event.

It is used to display the footer details of a page such as totals……etc.

NOTE:

This event can also be triggered with an ABAP statement ‘NEW PAGE’.

The output list should have more than 67 records (or) lines to trigger this event.

SYNTAX: :

* triggers after the current page is ended before the new page is displayed*

END-OF-PAGE.

*Populate footer data*

PERFORM<F_FOOTER_DATA>.

FORM<F_FOOTER_DATA>.

WRITE’<footer data>’.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
ENDFORM.

SKELETON OF CLASSICAL REPORTS:

REPORT <ZREP-NAME> LINE-COUNT<N> MESSAGE-ID<ZMSG_CLASS>.

*Top includes for global data declarations*

INCLUDE<ZREP-NAME>-TOP.

*SEL include for selection screen*

INCLUDE<ZREP-NAME>-SEL.

*FORM include for defining sub routines*

INCLUDE<ZREP-NAME>-FORMS.

*Triggers before selection screen*

INITIALIZATION.

PERFORM<F_CLASS_REFRESH>.

*Triggers while performing any action in the selection screen*

AT SELECTION-SCREEN OUTPUT.

PERFORM<F_FORMAL_SCREEN>.

*Validate input data*

AT SELECTION-SCREEN ON <S_FIELD/P_FIELD>.

PERFORM<F_VALIDATE_INPUT>.

*Main program begins*

START-OF-SELECTION.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
PERFORM<F_GET_DATA>.

*Process extracted data*

END-OF-SELECTION.

PERFORM<F_PROCESS_DATA>.

NOTE:

1. Up to END-OF-SELECTION events are common for any type of report (or) migration.

2. Display data in the first basic list and TOP-OF-PAGE and END-OF-PAGE events are

specific to classical Reports.

*Trigger with first WRITE (OR) ULINE STATEMENT.

TOP-OF-PAGE.

PERFORM<F_DISPLAY_DATA>.

*Display footer details*

*Trigger before new page is display*

END-OF-PAGE.

PERFORM<F_DISPLAY_FOOTER>.

INNER JOINS:

It is used to extract the data from the multiple tables by joining them.

NOTE:

1. Cluster & pooled tables cannot be used with joins.

2. Up to 2 tables can only be joined.

SYNTAX: SELECT <a~f1>

<a~f2>

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
:

<b~g1>

<b~g>

Into table <gt_dbtab1_dbtab2>

From <dbtab1>as <a>

Inner join <dbtab2> as <b>

On <a~f1> = <b~f1> AND

Where <a~f2> in <s_f2> AND

<b~g1> in <s-g2>

Here ‘<a>’ is an alias name for the first database table <dbtab1>.

‘<b>’ is an alias name for the first database table <dbtab2>.

NOTE: The database name can also be used instead of alias name.

SYNTAX: SELECT <dbtab1~f1>

<dbtab1~f2>

<dbtab2~g1>

<dbtab2~g2>

FOR ALL ENTRIES Statement:

This statement is used to extract the data from the database table based on the entries of the
base internal table. It is advisable instead of joining more than two tables.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
NOTE: 1.The base internal table must be checked whether it has data or not before is used with

‘FOR ALL ENTRIES’.

2. The SELECT statement extracts all the data without considering ‘FOR ALL ENTRIES’.

In case of a base internal table is empty and not checked.

SYNTAX: :

*Check base internal table*

IF NOT <gt_dntab1_dbtab2>[] is initial.

SELECT <h1>

<h2>

From <dbtab3>

Into table <gt_dbtab3>

For all entries in<gt_dbtab1_dbtab2>

Where <f1> = <gt_dbtab1_dbtab2-f1> and

<f2> IN <s-f2>………..

ENDIF.

NOTE: The ‘FOR ALL ENTRIES’ statements can also be used by inner join.

SYNTAX:

IF NOT <GT_DBTAB3> [] IS INITIAL.

SELECT <a~f1>

<a~f2>

<b~g1>

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
<b~g2>

INTO TABLE <gt_dbtab4_dbtab5>

FROM <dbtab4>AS <a>

INNER JOIN <dbtab5> AS <b>

On <a~f1> = <b~f1> AND

FOR ALL ENTRIES IN <gt_dbtab3>

WHERE <a~f2> IN <s_f2> AND

<b~g1> IN <s_g2>

ENDIF.

NOTE:

Use ‘READ TABLE’ statement within the base internal table loop.

SYNTAX:

LOOP AT <gt_dbtab1_dbtab2> INTO < gs_dbtab1_dbtab2>.

*Move data into final internal table*

MOVE : <gs_dbtab-f1> TO <gs_final-f1>,

*Read another internal table*

READ TABLE <gt_dbtab3> INTO<GS_DBTAB3> WITH KEY <a> = <gs_dbtab1_dbtab2-f1>

(OR)

READ TABLE <gt_dbtab>……………………..INDEX SY-TABIX.

IF SY-SUBRC = 0.

MOVE : <gs_dbtab-f1> TO <gs_final-f1>,

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
ENDIF.

*Read another internal table*

READ TABLE <ggt_dbtab4>………….

*Fill final internal table*

APPEND <gs_final> to <gt_final>……………

ENDLOOP.

*Display data - - - - -- *

LOOP AT <gt_final> into <gs_final>.

WRITE: / <gs_final-f1>,

CLEAR : <gs_final>.

ENDLOOP.

DESCRIBE TABLE:

This statement is used to get total number of records in an internal table.

SYNTAX:

DESCRIBE TABLE <gt_final> LINES <gv_total>.

NOTE:

The statement field sy-dbcnt holds the total no of extracted records from the
database tables (or) database views.

INTERACTIVE REPORTS
They are used to provide the detailed drill down list based on the current output list.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
An interactive between the multiple list can be provided using this concept.

Up to 20 Secondary (or) drill down lists can only be provided including basic list, the total
no. of lists are 21.

Note:-

The program goes to runtime error (or) short dump in case of more than 20 Secondary
lists are provided.

The system field SY-LSIND holds the index of next drill down list.

Events associated with interactive (or) drill down classical report :-

1. AT LINE-SELECTION.

2. TOP-OF-PAGE-DURING LINE-SELECTION.

3. AT USER-COMMAND.

4. AT PF.

AT LINE-SELECTION :-

This event is triggered when the record (or) list line is selected (click (or) double click)
in the current list.

The system field SY-LSIND holds the index of the next drill down list of the current list.

It is used to provide the detailed list based on the current list.

SYNTAX: - :

* Display Basic list.

LOOP AT <gt_basic> into <gs_basic>.

WRITE: _ _ _ _ _ _ _ _ .

* Hides selected field value.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)

CASE SY-LSIND.

* 1st drill down.

WHEN '1'.

LOOP AT <gt_first> INTO <gs_first> WHERE <f> = <gs_basic-f1> / <gv_f1>.

WRITE: _ _ _ _ _ _ _ _ _ _ .

HIDE <gs_first-g1> / <gv_g1> _ _ _ _ _.

ENDLOOP.

HIDE STATEMENT :-

The statement is used to hide the selected field / row value which can be passed to the
corresponding drill down list to filter the unwanted records.

SYNTAX :- :

:
BY MR. BABU (OASIS TECHNOLOGIES)
BY MR. BABU (OASIS TECHNOLOGIES)
AT LINE-SELECTION.

CASE SY-LSIND.

WHEN '1'.

* Get selected field value of cursor position / selection.

GET CURSOR FIELD <gs_basic-f1> VALUE <gv_value>.

PERFORM <f_display_first>.

FORM <f_display_first>.

LOOP AT <gt_first> INTO <gs_first> WHERE <f1> EQ <gv_value>.

ENDLOOP.

TOP-OF-PAGE DURING LINE-SELECTION :-

This event is triggered with First "WRITE" (or) "Value" statement of the detailed
lists (or) drill down list.

It is used to provide the column headings for the drill down list (or) secondary
list.

SYNTAX :-

WRITE / ULINE.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)

* Triggers when the record (or) field is selected in the current list.

AT LINE-SELECTION.

CASE SY-LSIND.

WHEN '1'.

WHEN '1'.

* Column headings of 1st drill down list.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
WRITE <column>.

ENDFORM.

AT PF :-

This event is triggered when the menu item (function key) is pressed.

This event is used to provide the additional functionality based of the selected menu
item.

The system field SY-PFKEY holds the selected function key of the menu.

SYNTAX :-

AT PF.

* Call the menu status.

SET PF-STATUS '<zmenu_status>'.

CASE SY-PFKEY

* Additional functionality

WHEN '<CRT>'.

* Call create T-code

WHEN '<DEL>'.

* Delete the data

ENDCASE.

SET PF-STATEMENT :-

This statement is used to call the menu status.

SYNTAX :-

SET PF-STATUS '<zmenu_status>' [EXCLUDING <gv_exclude_tab>]

Here <zmenu_status> is the custom menu status name '(Should be mentioned in uppet case)'.

- - - - EXCLUDING addition :-

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)
This addition is used to exclude(Hide) the unwanted push buttons or generic
functions (or) menu items.

NOTE :-

The T-code 'SE41' is used to work with menu painter.

AT USER COMMAND :-

This event is triggered when the push button is selected.

This event is used to provide the additional functionality based on the selected push
button.

The system field SY-UCOMM holds the function code of (FCT code) the selected push
button.

SYNTAX :-

AT USER COMMAND.

* Provide the additional interactive functionality.*

CASE SY-UCOMM.

WHEN '<DELT>'.

* Delete functionality

ENDCASE.

NOTE :-

The additional functionality can be provide using only the system fields SY-PFKEY or SY-
UCOMM without using Events 'AT PF and AT USER COMMAND.

BY MR. BABU (OASIS TECHNOLOGIES)


BY MR. BABU (OASIS TECHNOLOGIES)

REPORTS-ABAP Queries and


Fundamentals

Contents ......................................................................................................................................................
REPORTS-ABAP Queries .......................................................................................................................
Programming in ABAP Editor .........................................................................................................................
Different types of ABAP Programs ..............................................................................................................
REPORT Statement ......................................................................................................................................
Some useful additions to REPORT Statement .............................................................................................
Comments ...................................................................................................................................................
WRITE Statement ........................................................................................................................................
Some useful additions to WRITE Statement ..............................................................................................
Data Types...................................................................................................................................................
Pretty Printer...............................................................................................................................................
Elementary Data Types ...............................................................................................................................
Mathematical Operations ...........................................................................................................................
DATA Statement..........................................................................................................................................
TYPE and LIKE Statements...........................................................................................................................
MOVE Statement ........................................................................................................................................
CLEAR Statement ........................................................................................................................................
ULINE Statement .........................................................................................................................................
ABAPDOCU Transaction Code .....................................................................................................................
PARAMETERS Statement.............................................................................................................................
Some useful additions to PARAMETERS Statement ...................................................................................
Mathematical Functions .............................................................................................................................
String Operators ..........................................................................................................................................
Condition or Control Statements ................................................................................................................
Numeric Comparison Operators .................................................................................................................
String Comparison Operators .....................................................................................................................
Loop Statements .........................................................................................................................................

You might also like