ABAP Programming Part2
1
Classical Reports
▪ Reports are programs that read data from the database, processes the data and displays
the data in the required format.
▪ It consists of 2 screens - selection screen and output screen.
▪ The selection screen is optional.
▪ SAP ABAP classical reports are the most basic ABAP reports in which we displayed the
output using WRITE statement.
2
Open SQL
▪ SQL stands for structured query language.
▪ It is of 2 types.
1. Open SQL - Open SQL is database independent.
2. Native SQL - Native SQL is database dependent.
3
Open SQL Queries
▪ The figure shows an example of open SQL query.
▪ This query fetches data from database table ztordh_88, based upon the select-options
s_ono.
▪ Whenever, there is a select-options, we need to use IN operator.
Example of Open SQL Query
4
Open SQL Queries(Contd.)
▪ The figure shows an example of open SQL query.
▪ This query fetches data from database table ztordh_88, based upon the parameter
p_ono.
▪ Whenever, there is a parameter, we need to use = operator.
Example of Open SQL Query
5
Open SQL Queries - For All Entries In
▪ When we fetch the data from multiple tables, ‘For All Entries In’ is the best alternative.
▪ It reduces the database load.
▪ The parent internal table(lt_data1) must not be empty.
Use of For All Entries In
6
Open SQL Queries - Join
▪ With the help of join, we can read from more than one table in a single select
statement.
▪ Join is of 2 types.
1. Inner Join
2. Outer Join
7
Inner Join
▪ An inner join finds and returns matching data from tables based upon specified
conditions.
▪ If one or more criteria are not met, no data records are created in the result set.
Use of Inner Join to Fetch Data From Multiple Tables
8
Outer Join
▪ Outer join finds and returns matching data and non-matching data from tables.
▪ Outer join is of 2 types.
1. Left Outer Join( Left Join)
2. Right Outer Join(Right Join)
9
Left Outer Join
▪ The left outer join takes all the values from the left table and combines them with the
values from the right table that meet the criteria.
Use of Left Outer Join to Fetch Data From Multiple Tables
1
0
Right Outer Join
▪ The right outer join takes all the values from the right table and combines them with the
values from the left table that meet the criteria.
1
1
Best Performance Practices/Guidelines
▪ Never use * in the query. Fetch the data of only those columns which are required.
▪ Columns fetching sequence needs to be same as that of data dictionary column
sequence.
▪ Where condition column sequence needs to be same as that of data dictionary column
sequence.
▪ Never use corresponding in the query.
▪ Never write the queries inside the loop.
1
2
Best Performance Practices/Guidelines(Contd.)
▪ For traditional databases avoid using JOIN, use FOR ALL ENTRIES IN.
▪ For fetching data from foreign key tables/dependent tables - check for sy-subrc or
internal table not initial condition.
▪ Use binary search in read table.
▪ Use parallel cursor in nested loops.
▪ For multiple conditions, use CASE conditional statement rather than IF conditional
statement.
1
3
Best Performance Practices/Guidelines(Contd.)
▪ Use existing indexes or create secondary indexes to improve the performance.
1
4
Message Class
▪ Messages always plays an important role for end user.
▪ The various types of messages are - A(abort), E(error), I(information),
S(success/status),W(warning), X(exit).
▪ The transaction code for message class is SE91.
Transaction Code : SE91
1
5
Message Class(Contd.)
▪ A message number length is 3(000-999).
▪ One can pass values to a message number using &.
▪ In a message number, we can pass up to 4 &.
▪ Syntax to use a message in a program: MESSAGE E000(<msg class >).
▪ In the above syntax - MESSAGE = keyword , E = error message type , 000 is message
number , <msg class> = name of the message class.
1
6
Transaction Code
▪ One can create own shortcut/transactions to access the applications.
▪ The transaction code to create a transaction code is SE93.
Transaction Code : SE93
1
7
Classical Report Events
▪ Classical reports are the most basic ABAP reports in which we display the output using
WRITE statement.
▪ Event is always triggered by a specific action or a specific occurrence(when a particular
time has been reached).
▪ The example of specific actions are mouse click, pressing a key etc. The example of
specific occurrence is running out of memory etc.
1
8
Classical Report Events(Contd.)
▪ The same concept of events is applicable to classical reports. Some events trigger by
specific user action and some events trigger at specific occurrence in classical reports.
▪ The various classical report event are as follows:
Initialization
At selection-screen
Start-of-selection
End-of-selection
1
9
Classical Report Events(Contd.)
Top-of-page
End-of-page
At selection-screen output
At selection-screen on value request for <field>
At selection-screen on help request for <field>
At selection-screen on <field>
2
0
Initialization
▪ This event calls before displaying the selection screen/Input screen.
▪ The purpose of this event is to assign the default values to parameters and select-
options.
2
1
AT Selection-Screen
▪ This event calls when user performs some action (enter, click etc.) on to the selection
screen.
▪ The purpose of this event is to validate the Input.
2
2
Start-of-Selection
▪ This event calls when user clicks execute button on the selection screen.
▪ The selection logic is the part of this event.
2
3
End-of-Selection
▪ This event calls when selection process ends or after the last statement in the START-OF-
SELECTON event is executed.
▪ This event helps to identify the end of data/records.
2
4
Top-of-Page
▪ This event calls when the first write statement occurs in a program for
a page.
▪ The purpose of this event is to provide title/header at the beginning of a new page.
2
5
End-of-Page
▪ This 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 end 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 2 are reserved for end-of-page.
2
6
AT Selection-Screen Output
▪ This event calls before displaying the selection screen/Input screen.
▪ The purpose of this event is to modify the selection screen before it is displayed.
2
7
Initialization and AT Selection-Screen Output Comparison
▪ Initialization event calls only first time before displaying the selection screen whereas at
selection-screen output event calls every time before displaying a selection screen.
▪ Initialization event is to assign the default values to parameters and select-options
whereas at selection-screen output event is used to modify the selection screen.
2
8
AT Selection-Screen and AT Selection-Screen Output Comparison
▪ AT selection-screen event calls when user performs some action (enter, click etc.) on to
the selection screen whereas at selection-screen output event calls before displaying
the selection-screen.
▪ At selection-screen event is to validate the input whereas at selection screen output is
to used to modify the selection screen.
▪ AT selection-screen event is equal to PAI( Process After Input) of module pool whereas
at selection-screen output is equal to PBO(Process Before Output) of module pool.
2
9
AT Selection-Screen On Value Request For <Field>
▪ This event calls when user clicks F4 on a field of selection screen.
▪ The purpose of this event is to provide value help for an input field.
3
0
AT Selection-Screen On Help Request For <Field>
▪ This event calls when user clicks F1 on a field of selection screen.
▪ The purpose of this event is to provide technical information for a field.
3
1
AT Selection-Screen On <Field>
▪ This event calls when user performs some action (enter, click etc.) on to the selection
screen.
▪ This event is used to validate a particular input field present on the selection screen.
3
2
AT Selection-Screen and AT Selection-Screen On <Field> Comparison
▪ AT selection-screen event is used to validate multiple input fields whereas at selection-
screen on <field> event is to validate a particular input field present on the selection
screen.
▪ In case of at selection-screen event to highlight a wrong input field the explicit logic is
required, whereas in at selection screen on <field> the wrong input field highlighted
automatically.
3
3
AT Selection-Screen and AT Selection-Screen On <Field> Comparison
▪ In case of at selection-screen event all input fields remain enable after the wrong input
whereas in case of at selection-screen on <field> event the wrong input field remain
enable and other input fields become disable.
3
4
Interactive Classical Report Events
▪ In classical report we only display the output on basic list . There is no interaction with
the output.
▪ In Interactive classical report is one we interact with the output on basic list and it take
us to secondary list.
▪ Basic list is the list which is generated at first by our ABAP program.
▪ The secondary lists are generated by further navigation or user selection from the basic
list.
3
5
Interactive Classical Report Events(Contd.)
▪ The number of basic list in classical report is 1.
▪ The number of secondary lists in classical report is 20.
▪ The various interactive classical report events are as follows:
At line-selection
At user-command
Top-of-page during line-selection
3
6
AT Line-Selection
▪ When user double clicks on the line or select a line and press F2 or select a line and click
choose at that time at line-selection event triggers.
3
7
AT User-Command
▪ When user clicks on the functions created using pf-status, at that time at user-command
event triggers.
▪ The system variable sy-ucomm is used to capture the value of function code.
3
8
Top-of-Page During Line-Selection
▪ This event calls when the first WRITE statement occurs in a program
for a page on secondary list.
▪ The purpose of this event is to provide title/header at the beginning of a new page on
secondary list.
3
9
Interactive Classical Reports Statements - HIDE
▪ The HIDE statement is one of the fundamental statements for
interactive reporting.
▪ We can use HIDE statement to store the line-specific information while
creating a basic list.
▪ This stored information will be used while creating secondary list.
▪ Syntax : HIDE <f>.
▪ The above statement places the contents of the variable <f> into the
4
0
Interactive Classical Reports Statements - HIDE(Contd.)
▪ We can consider hide area as a table which stores the field name, field
value and line number(system variable SY-LINNO).
▪ The various pre requisites for HIDE statement are as follows:
1. HIDE statement must be written after the WRITE statement.
2. HIDE statement must be called inside the loop.
4
1
Interactive Classical Reports Statements - Working of HIDE
▪ The user selects a line for which data has been stored in the HIDE
area.
▪ The system variable SY-LILLI determines the selected line.
▪ The runtime system jumps to the point in the HIDE area where data for
this
line is stored.
▪ The runtime system then inserts all values stored for the selected line
4
2
Interactive Classical Reports Statements - GET CURSOR
▪ In interactive classical reports, GET CURSOR statement is used to create secondary lists
according to the cursor position.
▪ The parameter FIELD provides the name of an output field. The parameter VALUE
provide the output value
▪ Syntax : GET CURSOR FIELD <lv_field> VALUE <lv_value>.
▪ In the above syntax - the field name and field value will be returned in to variables
lv_field and lv_value respectively.
4
3
Comparison of HIDE and GET CURSOR Statements
▪ HIDE statement responds for a particular line whereas GET CURSOR statement responds
for a particular field.
▪ HIDE statement is used to store the line with line number in the hide area whereas GET
CURSOR is used to store the value of the selected field name.
▪ With HIDE statement, we can not display secondary lists based upon Individual field
name and field value whereas with GET CURSOR statement we can display secondary
lists based upon the Individual field name and field value.
4
4
System Variables in Interactive Classical Report Events
▪ The various system variables used in interactive classical report events are as follows:
SY-LISEL - It is a system variable which returns the contents of the selected line.
SY-LILLI - Absolute number of a selected line in the list displayed.
SY-LSIND - It is a system variable which returns the index of the displayed list. For the
basic list SY-LSIND = 0 and for the secondary lists SY-LSIND > 0.
4
5
Control Break Statements
▪ Control break statements are also called as control break events.
▪ Control break statements are used to control loop or we can say they are used to control
the data flow in loop.
▪ Control break statements starts with at and ends with endat.
▪ The various pre-requisites to apply control break statements are as follows:
Control break statements should be applied inside a loop.
Internal table should be in the sorted order.
4
6
Types of Control Break Statements
▪ The various control break statements are as follows:
AT FIRST
AT LAST
AT NEW <fieldname>
AT END OF <fieldname>
4
7
Types of Control Break Statements
AT FIRST - It triggers for the first row/first record/first iteration of the internal table in
loop.
AT LAST - It triggers for the last row/last record/last iteration of the internal table in
loop.
AT NEW <fieldname> - It triggers for the new/first record of a group having the same
value for the specified fieldname in loop.
4
8
Types of Control Break Statements(Contd.)
AT END OF <fieldname> - It triggers for the end/last record of a group having the same
value for the specified fieldname in loop.
4
9
Control Break Statements With SUM Statement
▪ SUM statement can only be used in loop- endloop statement and needs to be applied in
control break statements(at and endat).
▪ SUM calculates the sum of all numeric fields to the right of the current group key.
▪ The sum is for all rows of the current group and assign it to the corresponding fields of
the workarea.
5
0
Control Break Statements - Important Points
▪ Always sort the internal table based upon the fieldname used in AT NEW<fieldname> or
AT END OF <fieldname>.
▪ The event AT NEW <fieldname> and AT END OF <fieldname> also triggers if the value of
other fields change which are present on the left hand side of specified fieldname. If we
want AT NEW <fieldname> and AT END OF <fieldname> to trigger based on specified
fieldname only , then we need to take specified fieldname at the first position in the
internal table.
5
1
Control Break Statements - Important Points
▪ Whenever AT FIRST and AT LAST control break events triggers all character field values
converted to **** and all numeric field values converted to 0.
▪ Whenever AT NEW <fieldname> and AT END OF <fieldname> triggers the value of
character fields on the right hand side of specified fieldname converted to **** and
numeric field values converted to 0.
Solution : Store the values in a temporary work area before any of the control break
event triggers.
5
2
Database Operations
▪ Database operations deals with database tables. The various database operations are as
follows:
Select - Select is used to fetch data from database tables.
Insert - Insert is used to insert the records to database tables.
Update - Update is used to update the existing records in the database tables.
Delete - Delete is used to delete the existing records from database tables.
5
3
Database Operations(Contd.)
Modify - It works for both - insert + update. For existing records - It acts as update, for
non-existing records - it acts as Insert.
5
4
Report Variant
▪ When we run the same program with the same set of input or selections, so instead of
passing the input every time, we can save the input values in a selection set which is
called a variant.
5
5
Field Symbols
▪ Field symbols are placeholders for the data objects.
▪ Field symbols do not reserve any physical memory space, but point to the content of the
data objects.
▪ After declaring a field symbol, we can assign the data object to the field symbol.
▪ After successful assignment, Whenever we address a field symbol, ultimately we are
addressing the data object that is assigned to that field symbol.
5
6
Field Symbols(Contd.)
▪ Syntax : FIELD-SYMBOLS <fs>.
▪ In the above syntax, FIELD-SYMBOLS = keyword , where fs is the name of the field
symbol. The name of the field symbol is always enclosed between <>.
5
7
Types of Field Symbols
Field symbols are of 2 types.
1. Typed field symbol.
2. Generic field symbol.
5
8
Typed Field Symbol
▪ When we provide the data type like elementary, complex etc. to the field symbol, then it
is called as typed field symbol.
▪ If we specify a type to the field symbol , the system checks the
compatibility of the field symbol and the data object assigned to that
field symbol.
▪ Example - FIELD-SYMBOLS : <fs> TYPE I.
▪ In the above syntax, the field symbol is of elementary data type Integer(I).
5
9
Generic Field Symbol
▪ When we provide the generic data types like ANY and ANY TABLE to the field symbol,
then it is called as generic field symbol.
▪ Generic field symbols are used for dynamic programming.
▪ Example - FIELD-SYMBOLS : <fs_str> TYPE ANY.
FIELD-SYMBOLS : <ft_tab> TYPE ANY TABLE.
6
0
Field Symbol as a Replacement of Work Area
▪ We can replace work area by field symbol while performing internal table operations.
▪ This is because work area stores a copy of the internal table row, whereas field symbol
directly references the internal table row.
▪ Hence processing of internal table with field symbol is faster than the
processing of internal table with work area.
6
1
Modify the Internal Table Contents Using Field Symbols
▪ We can declare a field symbol of type any structure, which we can use
while looping through an internal table.
▪ If we change any field of structure in field symbol, the corresponding field in internal will
get updated.
▪ So , there is no need to write the MODIFY statement when we use field symbols to
modify the contents of the internal table.
6
2
Thank You
6
3