1.list Generation Techniques
1.list Generation Techniques
Techniques
ABAP L2
Agenda
1 Introduction
2 Selection Screen
3 Logical Database
4 Reports
5 Classical Reports
Agenda (Contd.)..
6 Exercise
7 Interactive Lists
8 Menu Painter
9 ALV Reporting
10 Assignment
Introduction
Day 1 – Session 1
Objectives
– Classical Reports
• Normal Reports
• Has only one list in the output
• Can be Event Driven
– Interactive Reports
• Known as Drill Down Reporting
• User can interact with Report
• Possible to have 21 lists
– ALV Reports
• ABAP List Viewer
Selection Screen
Day 1
Standard Selection Screens
Screen number numb can be any four-digit number apart from 1000, which
is the number of the standard selection screen.
Blank Lines
– To place blank lines on the selection screen
Underlines
– To place underlines on the selection screen
Comments
– To place comments on the selection screen use:
– Example
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-001.
PARAMETERS: p1(3) TYPE c, p2(5) TYPE c, p3(1) TYPE c.
SELECTION-SCREEN END OF LINE.
Blocks of Elements
• Example:
SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
PARAMETERS: airpfr TYPE spfli-airpfrom,
airpto TYPE spfli-airpto.
SELECTION-SCREEN END OF SCREEN 500.
CALL SELECTION-SCREEN 500 STARTING AT 10 1.
Selection Screen Processing
Selection screens are special screens that are defined with the help of
ABAP statements
This event occurs after the runtime environment has passed all input data
from the selection screen to the ABAP program.
Overview of Selection Screen Events
User actions on the selection screen result in other events that are either
used for field or possible entries help, or that trigger PAI processing of the
selection screen.
– This event block allows o modify the selection screen and its fields directly
before it is displayed.
Exercise
– If the vendor radio button is choosen, display the details of the vendor from
zvendor table
– If the material radio button is choosen, display the material details of that
vendor from the zmaterial table.
Logical Database
Day 1
Logical Database
Logical databases are special ABAP programs that retrieve data and make it
available to application programs.
Logical databases contain Open SQL statements that read data from the
database
The logical database reads the program, stores them in the program if
necessary, and then passes them line by line to the application program or
the function module LDB_PROCESS using an interface work area.
Improving performance
Structure of a Logical Databases
Has 3 components
Structure
Selections
Database Program
– The database program contains the ABAP statements used to read the data
and pass it to the user of the logical database
Structure
LFA1
LFBK
LFB1
LFC1
Using Logical Databases
WRITE: / wa_sflight-fldate.
ENDSELECT.
ENDSELECT.
Example Program with LDB
WRITE: / spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-cityto.
WRITE: / sflight-fldate.
Reports
Day 1
Classical Reports
Events in Reports
Events
INITIALIZATION
AT SELECTION-SCREEN
START-OF-SELECTION
Logical Database
GET <tname1>….
GET <tname2>….
…..
In this event the input fields of the standard selection screen can only be
initialized once after the program has been started
This event occurs after the selection screen has been processed and
before data is read using the logical database
It is used to prepare the data for reading and creating the list
NODES spfli.
START-OF-SELECTION.
WRITE: / 'List of Flights' COLOR COL_HEADING,
/ 'Created by', sy-uname, 'on', sy-datum.
ULINE.
GET spfli.
Events - END-OF-SELECTION
This is the last of the events 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.
The event block is used to process and format all data that the program
has stored in sequential datasets, such as internal tables or extracts.
Events - Example
NODES spfli.
DATA: spfli_tab TYPE SORTED TABLE OF spfli
WITH UNIQUE KEY cityfrom cityto carrid connid,
spfli_line TYPE spfli.
START-OF-SELECTION.
WRITE 'Demo program for END-OF-SELECTION'.
SKIP.
GET spfli FIELDS carrid connid cityfrom cityto.
MOVE-CORRESPONDING spfli TO spfli_line.
INSERT spfli_line INTO TABLE spfli_tab.
END-OF-SELECTION.
LOOP AT spfli_tab INTO spfli_line.
WRITE: / spfli_line-cityfrom,
spfli_line-cityto,
spfli_line-carrid,
spfli_line-connid.
ENDLOOP.
Exiting Event Blocks
– If the STOP statement is used within an event block, the system stops
processing the block immediately.
– If the EXIT statement is used within an event block but not in a loop, the
system stops processing the block immediately.
– If the CHECK expr statement is used within an event block but not within a
loop, and the condition expr is not fulfilled, the system exits the processing
block immediately.
Events - Example
START-OF-SELECTION.
WRITE 'Test program for STOP'.
GET sbook.
WRITE: 'Bookid', sbook-bookid.
STOP.
END-OF-SELECTION.
WRITE: / 'End of Selection'.
Events - Example
GET sflight.
CHECK sflight-carrid EQ 'LH'.
WRITE: / 'Connid:', sflight-connid,
'Carrid:', sflight-carrid,
'Fldate:', sflight-fldate.
GET sbook.
CHECK sbook-bookid LT 00000320.
WRITE: / 'Bookid:', sbook-bookid.
Lists are the output medium for structured, formatted data from ABAP
programs.
Each program can produce up to 21 lists, one basic list and 20 secondary
lists.
One of the following list events may be called, depending on the function
code triggered by the user.
– AT LINE-SELECTION
– AT USER-COMMAND
Interactive Lists (Contd.).
When the system processes event blocks that are not assigned to
interactive list events, and when processing dialog modules, the ABAP
program writes its list output to the basic list.
The ABAP system field SY-LSIND contains the index of the list currently
being created.
The basic list has a standard list status and a standard page header
The TOP-OF-PAGE and END-OF-PAGE events can occur while the basic
list is being created
Creating Detail Lists
All lists created during an interactive list event are detail lists.
Each time the user executes an action on a list, the runtime environment
checks whether there is an event block defined that corresponds to the
function code.
Any list output arising during this event block places its data into a new list
(list level) with the index SY-LSIND.
Creating Detail Lists (Contd.).
With one ABAP program, one basic list and up to 20 detail lists can be
maintained.
If the user creates a list on the next level , the system stores the previous
list and displays the new one. The user can interact with whichever list is
currently displayed.
By default, the new list overlays the previous list completely. However, list
can be displayed in a dialog box
The GET and GET LATE cannot be used to retrieve data for secondary
lists
System Field for Detail List
SY-LISTI Index of the list level from which the event was triggered
SY-LILLI Absolute number of the line from which the event was triggered
SY-LISEL Contents of the line from which the event was triggered
SY-CUROW Position of the line in the window from which the event was
triggered (counting starts with 1)
SY-CUCOL Position of the column in the window from which the event was
triggered (counting starts with 2)
System Fields (Contd.).
SY-STACO Number of the first column displayed in the list from which the
event was triggered (counting starts with 1)
Example
START-OF-SELECTION.
WRITE: 'Basic List, SY-LSIND =', sy-lsind.
AT LINE-SELECTION.
WRITE: 'Secondary List, SY-LSIND =', sy-lsind.
Interactive Lists - Example
To allow the user to communicate with the system when a list is displayed,
the lists must be able to direct user actions to the ABAP program.
Function codes which are used for this purpose is maintained in the GUI
status of the list screen
GUI status is maintained in the Menu Painter tool in the ABAP Workbench
The GUI status for lists can be defined and attached to list level using
SET PF-STATUS
– This statement sets the status <stat> for the current output list
– Sets the title of the user interface for the output list
– It remains active for all screens until another SET TITLEBAR is specified
Example
START-OF-SELECTION.
SET PF-STATUS 'TEST'.
WRITE: 'Basic list, SY-LSIND =', sy-lsind.
AT LINE-SELECTION.
WRITE: 'LINE-SELECTION, SY-LSIND =', sy-lsind.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'TEST'.
WRITE: 'TEST, SY-LSIND =', sy-lsind.
ENDCASE.
List Events in an ABAP Program
Unlike normal screens, in which the PAI event is triggered, the runtime
environment triggers three special events when list events occur
– If the user chooses a function code during list processing that is neither
processed by the system, or PICK or PF<nn>, the system triggers the event AT
USER-COMMAND. For this event, a GUI status for a list must be defined.
START-OF-SELECTION.
WRITE 'Basic List'.
AT LINE-SELECTION.
WRITE: 'Secondary List by Line-Selection',
/ 'SY-UCOMM =', sy-ucomm.
Example
START-OF-SELECTION.
WRITE: 'Basic List', / 'SY-LSIND:', sy-lsind.
TOP-OF-PAGE DURING LINE-SELECTION.
CASE sy-pfkey.
WHEN 'TEST'.
WRITE 'Self-defined GUI for Function Codes'. ULINE.
ENDCASE.
AT LINE-SELECTION.
SET PF-STATUS 'TEST' EXCLUDING 'PICK'.
PERFORM out. sy-lsind = sy-lsind - 1.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'FC1'.
PERFORM out.
WRITE / 'Button FUN 1 was pressed'.
WHEN 'FC2'.
PERFORM out.
WRITE / 'Button FUN 2 was pressed'.
ENDCASE.
sy-lsind = sy-lsind - 1.
FORM out.
WRITE: 'Secondary List', / 'SY-LSIND:', sy-lsind, / 'SY-PFKEY:', sy-pfkey.
ENDFORM.
Lists in Dialog Box
List can be displayed in a dialog box instead of on the full screen using the
WINDOW statement
The WINDOW statement takes effect only within the processing block of
an interactive event, that is, only for detail lists
The application toolbar appears at the bottom of the dialog box. This is a
feature common to all dialog boxes in the R/3 System
Passing Data From Lists to Programs
– The system field SY-LIESEL contains the contents of the selected line .
Example
– READ LINE
• To read data from the lines of existing list levels
• Closely connected to HIDE technique
– GET CURSOR
• GET CURSOR FIELD and GET CURSOR LINE is used to pass the output field or
output line on which the cursor was positioned during the interactive event to the
ABAP program.
– DESCRIBE LIST
• Used to read certain list attributes, such as the number of lines or pages, into
program variables
HIDE Technique
HIDE <f>.
Places the contents of the variable <f> for the current output line (system
field SY-LINNO) into the HIDE area.
Always place the HIDE statement directly after the output statement for
the variable <f>
As soon as the user selects a line for which HIDE fields, are stored, the
system fills the variables in the program with the values stored
Hide Technique (Contd.).
– By an interactive event.
HIDE area is like a table, in which the system stores the names and values
of all HIDE fields for each list and line number.
Examples
– The statement without any options stores the contents of line <lin> from the
list on which the event was triggered (index SY-LILLI) in the SY-LISEL system
field and fills all HIDE information stored for this line back into the
corresponding fields
READ CURRENT LINE [FIELD VALUE <f1> [INTO <g 1>] ...].
TABLES: SFLIGHT.
DATA: BOX(1) TYPE C, LINES TYPE I, FREE TYPE I.
SELECT-OPTIONS CARRID FOR SFLIGHT-CARRID.
START-OF-SELECTION.
SET PF-STATUS 'CHECK'.
SELECT * FROM SFLIGHT WHERE CARRID IN CARRID .
WRITE:/ BOX AS CHECKBOX, SFLIGHT-FLDATE.
HIDE: SFLIGHT-FLDATE, SFLIGHT-CARRID, SFLIGHT-CONNID,SFLIGHT-SEATSMAX, SFLIGHT-SEATSOCC.
ENDSELECT.
END-OF-SELECTION.
LINES = SY-LINNO - 1.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'READ'.
BOX = SPACE.
SET PF-STATUS 'CHECK' EXCLUDING 'READ'.
DO LINES TIMES.
READ LINE SY-INDEX FIELD VALUE BOX.
IF BOX = 'X'.
FREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC.
IF FREE > 0.
WRITE: /'Company:', SFLIGHT-CARRID, 'Connection: ',SFLIGHT-cONNID, / 'Number of free seats:', FREE.
ELSE.
ULINE.
WRITE : / 'No seats Available in Airline' , SFLIGHT-CARRID , 'Connection ',SFLIGHT-CONNID .
ENDIF.
ENDIF.
ENDDO.
ENDCASE.
Interactive Lists
– Etc.,
Example
Fields Description
SPART Division
2. On choosing one of the items, the following details from the VBAP( Sales
Document Item Data) should be displayed in the interactive lists
Fields Description
3. Modify the interactive list in exercise 1 where multiple line items can be
chosen in the basic list.
SPART Division
A tool that is used to design the user interfaces for ABAP Program.
The GUI status and GUI title defines how the user interface will look and
behave in an ABAP program
The principal object of a user interface is the GUI status which can be
assigned to any screen
The tool provides common list operations as generic functions and can be
enhanced by self-defined options.
50% of the time spent on finding the right tables and table relationships
30% of the time spent on providing ‘fancy’ features sorting subtotals and
overall totals.
20% of the time spent on making the report output ‘look pretty’
Column headings
50% of the time spent on finding the right tables and table relationships
(selection process)
– Field catalog defines the fields and it’s attributes for on screen display.
– Field catalog can be build using function modules provided by SAP as well as
manually populating internal table I_FIELDCAT.
ALV Reporting (Contd.).
Build Layout
– On screen display can be controlled by creating layout and passing this
parameter to ALV.
– Display layout is build by populating the structure WS_LAYOUT in the
template.
ALV Reporting (Contd.).
– Output list can be displayed in two format namely table control mode and list
mode.
– The in-house developed tool for creating ALV reports make use of the table
control format.
ALV Functions
– REUSE_ALV_LIST_DISPLAY
– REUSE_ALV_GRID_DISPLAY
– REUSE_ALV_VARIANT_DEFAULT_GET
– REUSE_ALV_VARIANT_F4
– REUSE_ALV_VARIANT_EXISTENCE
– REUSE_ALV_EVENTS_GET
– REUSE_ALV_COMMENTARY_WRITE
– REUSE_ALV_FIELDCATALOG_MERGE
– REUSE_ALV_POPUP_TO_SELECT
ALV Reporting - Example
TABLES : SFLIGHT.
DATA : IT_SFLIGHT TYPE TABLE OF SFLIGHT .
START-OF-SELECTION.
SELECT * INTO TABLE IT_SFLIGHT FROM SFLIGHT.
PERFORM POPULATE_FIELDCATALOG.
PERFORM SELECTDATA_AND_SORT.
PERFORM POPULATE_LAYOUT USING FIELDLAYOUT.
PERFORM MERGE_FIELDCATALOG.
PERFORM DISPLAY_ALV_LIST.
FORM POPULATE_FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'BOOKID'.
FIELDCATALOG-SELTEXT_M = 'BOOKING ID'.
FIELDCATALOG-COL_POS = 0.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'CARRID'.
FIELDCATALOG-SELTEXT_M = 'Airline Code'.
FIELDCATALOG-COL_POS = 1.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
ALV Reporting – Example (Contd.).
FIELDCATALOG-FIELDNAME = 'CONNID'.
FIELDCATALOG-SELTEXT_M = 'FLIGHT CONNECTION NO.'.
FIELDCATALOG-EMPHASIZE = 'C911'.
FIELDCATALOG-COL_POS = 2.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'AIRPFROM'.
FIELDCATALOG-SELTEXT_M = 'FROM AIRPORT'.
FIELDCATALOG-COL_POS = 3.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'AIRPTO'.
FIELDCATALOG-SELTEXT_M = 'TO AIRPORT'.
FIELDCATALOG-COL_POS = 4.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'FLDATE'.
FIELDCATALOG-SELTEXT_M = 'DATE '.
FIELDCATALOG-COL_POS = 5.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
ALV Reporting – Example (Contd.).
FIELDCATALOG-FIELDNAME = 'CUSTTYPE'.
FIELDCATALOG-SELTEXT_M = 'CUSTOMER TYPE'.
FIELDCATALOG-COL_POS = 6.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
ENDFORM. "POPULATE_FIELDCATALOG
FORM SELECTDATA_AND_SORT.
SELECT P~CARRID P~CONNID P~AIRPFROM P~AIRPTO B~FLDATE B~CUSTTYPE
B~BOOKID
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL FROM (
SPFLI AS P INNER JOIN SBOOK AS B ON P~CARRID = B~CARRID AND P~CO
NNID = B~CONNID ).
SORT IT_FINAL BY CARRID.
ENDFORM. "SELECTDATA_AND_SORT
ALV Reporting – Example (Contd.).
FORM MERGE_FIELDCATALOG.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SYSREPID
I_INTERNAL_TABNAME = 'IT_FINAL'
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = FIELDCATALOG[] .
ENDFORM. "MERGE_FIELDCATALOG
FORM DISPLAY_ALV_LIST.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'SYSREPID'
I_STRUCTURE_NAME = 'WA_FINAL'
IS_LAYOUT = FIELDLAYOUT
IT_FIELDCAT = FIELDCATALOG[]
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = IT_FINAL.
ENDFORM.
ALV Reporting – Example - Output
Exercise
1. Write an ALV Report which displays the following fields from the VBAP
Table.
Fields Description
VBELN Sales Document
AUDAT Document Date
AUART Sales Document Type
VKORG Sales Organization
VTWEG Distribution Channel
SPART Division
VKBUR Sales Office
BSTNK Customer PO number
KUNNR Sold to party
Assignment
On clicking on the VBELN from the basic list, the corresponding details
from the VBAP( Sales Document Item Data) should be displayed in the
interactive lists
Fields Description
On clicking on the KUNNR from the basic list, the corresponding details
from the KNA1( Customer Master) should be displayed in the interactive
lists
Fields Description
NAME1 NAME
ADRNR ADDRESS
ORT01 CITY
LAND1 COUNTRY
Fields Description
2. Write an ALV Report to display the following fields from EKKO (Purchase
Document Header) and EKPO (Purchase Document Item) table.
QUESTIONS?
Summary