0% found this document useful (0 votes)
449 views115 pages

1.list Generation Techniques

This document provides an agenda and overview of list generation techniques in ABAP. It discusses selection screens, logical databases, classical reports, interactive lists, menu painter, ALV reporting, and includes exercises. Key points covered include using selection screens to define user input, logical databases for centralizing data retrieval, different types of reports like classical and interactive, and how events drive the processing of reports from initialization to selection to retrieval and output.

Uploaded by

Swati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
449 views115 pages

1.list Generation Techniques

This document provides an agenda and overview of list generation techniques in ABAP. It discusses selection screens, logical databases, classical reports, interactive lists, menu painter, ALV reporting, and includes exercises. Key points covered include using selection screens to define user input, logical databases for centralizing data retrieval, different types of reports like classical and interactive, and how events drive the processing of reports from initialization to selection to retrieval and output.

Uploaded by

Swati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 115

List Generation

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

 By end of this course, participants will

– Learn to generate a list using simple reports


– Use the Logical Database
– Know the different events in a report
– Know about Interactive reports
– Learn to create simple ALV Reports
Reports

 There are different types of Reports

– 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

 The standard selection screen of executable programs is predefined and


has the screen number 1000.

 The input fields of a standard selection screen can be defined only in


executable programs.
User-defined selection screens

 The two statements:


SELECTION-SCREEN BEGIN OF SCREEN numb [TITLE tit] [AS WINDOW].
...
SELECTION-SCREEN END OF SCREEN numb.

 Define a user-defined selection screen with screen number numb.

 Screen number numb can be any four-digit number apart from 1000, which
is the number of the standard selection screen.

 AS WINDOW addition is used to call a user-defined selection screen as a


modal dialog box.
Formatting Selection Screen

 The selection screen that is define d using the PARAMETERS or SELECT-


OPTIONS statements has a standard layout in which all parameters appear
line by line

 When the standard layout is not sufficient,The SELECTION-SCREEN


statement has its own formatting options that can be used to define the
layout for selection screens.
Blank Lines, Underlines, and Comments

 Blank Lines
– To place blank lines on the selection screen

SELECTION-SCREEN SKIP [n].

 Underlines
– To place underlines on the selection screen

SELECTION-SCREEN ULINE [[/]pos(len)] [MODIF ID key].

 Comments
– To place comments on the selection screen use:

SELECTION-SCREEN COMMENT [/]pos(len) comm [FOR FIELD f]


[MODIF ID key].
Example

PARAMETERS: r1 RADIOBUTTON GROUP rad1,


r2 RADIOBUTTON GROUP rad1.
SELECTION-SCREEN ULINE /1(50).
SELECTION-SCREEN COMMENT /10(30) comm1.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN ULINE.
INITIALIZATION.
comm1 ='Comment in Selection screen'.
Several Elements in a Single Line

SELECTION-SCREEN BEGIN OF LINE.


...
SELECTION-SCREEN END OF LINE.

– 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

SELECTION-SCREEN BEGIN OF BLOCK block


[WITH FRAME [TITLE title]]
[NO INTERVALS].
...
SELECTION-SCREEN END OF BLOCK block.
– Example
SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-002.
PARAMETERS r1 RADIOBUTTON GROUP gr1.
PARAMETERS r2 RADIOBUTTON GROUP gr1.
PARAMETERS r3 RADIOBUTTON GROUP gr1.
SELECTION-SCREEN END OF BLOCK rad1.
Calling User-Defined Selection Screens

CALL SELECTION-SCREEN numb [STARTING AT x1 y1] [ENDING AT x2 y2].

• 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

 The ABAP runtime environment fully controls the processing flow of


selection screens.

 The ABAP runtime environment generates a number of special selection


screen events before the selection screen is displayed and after the user
has executed actions on the selection screen.

 Programmers can define event blocks in the program to react to these


events.
Processing Selection Screen (Contd.).

 The basic form of the selection screen events is the AT SELECTION-


SCREEN event

 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

 Selection Screen Processing starts after the INITIALIZATION event with


AT SELECTION SCREEN OUTPUT.

 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.

 Only if the AT SELECTION-SCREEN event is exited properly, the other


events of the executable program triggered, starting with START-OF-
SELECTION.
Selection Screen - Basic Form

 The AT SELECTION-SCREEN event is triggered in the PAI of the selection


screen once the ABAP runtime environment has passed all of the input
data from the selection screen to the ABAP program

 In the PBO of the selection screen, the AT SELECTION-SCREEN


OUTPUT event is triggered.

– This event block allows o modify the selection screen and its fields directly
before it is displayed.
Exercise

1. Create a selection screen with the following elements

– Vendor no as input parameter

– Radio buttons for vendor and master

– 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

 LDB can be called using the function module LDB_PROCESS

 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.

 The structure of a LDB is hierarchical


Tasks of a LDB

 Reading the same data for several programs.

 Defining the same user interface for several programs.

 Central authorization checks

 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

 Two ways to use a LDB.

– Link to an Executable Program

– Use Function Module LDB_PROCESS in ABAP Program


Example Program without LDB

DATA: wa_spfli TYPE spfli, wa_sflight TYPE sflight.


SELECT-OPTIONS: sel_carr FOR wa_spfli-carrid.
SELECT carrid connid cityfrom cityto FROM spfli
INTO CORRESPONDING FIELDS OF wa_spfli WHERE carrid IN sel_carr.

WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom, wa_spfli-cityto.

SELECT fldate FROM sflight INTO CORRESPONDING FIELDS OF wa_sflight


WHERE carrid = wa_spfli-carrid AND connid = wa_spfli-connid.

WRITE: / wa_sflight-fldate.

ENDSELECT.

ENDSELECT.
Example Program with LDB

NODES: spfli, sflight.

GET spfli FIELDS carrid connid cityfrom cityto.

WRITE: / spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-cityto.

GET sflight FIELDS fldate.

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>….

…..

GET <tname2> LATE

GET <tname1> LATE


…..
END-OF-SELECTION
Events - INITIALIZATION

 Occurs before the standard selection screen is called

 In this event the input fields of the standard selection screen can only be
initialized once after the program has been started

 If an executable program declares a standard selection screen the same


program will be automatically called again by the system once the selection
screen has been executed. This triggers the INITIALIZATION event again.
Events - Examples

PARAMETERS datum TYPE sy-datum DEFAULT sy-datum.


NODES spfli.
INITIALIZATION.
airp_fr-sign = 'I'.
airp_fr-option = 'EQ'.
airp_fr-low = 'JFK'.
APPEND airp_fr.
airp_to-sign = 'I'.
airp_to-option = 'EQ'.
airp_to-low = 'FRA'.
APPEND airp_to.
carrid-sign = 'I'.
carrid-option = 'BT'.
carrid-low = 'AA'.
carrid-high = 'LH'.
APPEND carrid.
datum+6(2) = '01'.
Events - Example

 Upon execution, the following screen appears


Events - AT SELECTION-SCREEN

 The event AT SELECTION-SCREEN is the basic form of a whole series of


events that occur while the selection screen is being processed.

 This event is used to validate the information entered in the selection


screen

 The standard selection screen, either in an executable program or in the


logical database linked to it, is automatically called between the
INITIALIZATION and START-OF-SELECTION events
Events - START-OF-SELECTION

 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

 In an executable program, any non-declarative statements that occur


between the REPORT or PROGRAM statement and the first processing
block are also processed in the START-OF-SELECTION block
Events - Example

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

 ABAP contains a series of statements that allows to leave an event block.

 They return control to the runtime environment.

 The subsequent sequence of events in the runtime environment depends


on which statement is used and the event block in which it is used.
Exiting Event Blocks (Contd.).

 Exiting Event Blocks Using STOP

– If the STOP statement is used within an event block, the system stops
processing the block immediately.

 Exiting Event Blocks Using EXIT

– If the EXIT statement is used within an event block but not in a loop, the
system stops processing the block immediately.

 Leaving Event Blocks Using CHECK

– 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

NODES: spfli, sflight, sbook.

START-OF-SELECTION.
WRITE 'Test program for STOP'.

GET sbook.
WRITE: 'Bookid', sbook-bookid.
STOP.

END-OF-SELECTION.
WRITE: / 'End of Selection'.
Events - Example

NODES: spfli, sflight, sbook.


DATA flag(1) TYPE c.
AT SELECTION-SCREEN.
IF carrid-low IS INITIAL.
flag = 'X'.
EXIT.
ENDIF.
START-OF-SELECTION.
IF flag = 'X'.
WRITE / 'Keine Eingabe für CARRID gemacht'(001).
EXIT.
ENDIF.
GET spfli.
GET sflight.
GET sbook.
END-OF-SELECTION.
WRITE / 'End of Selection'(002).
Events - Examples

NODES: spfli, sflight, sbook.

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.

GET sflight LATE.


ULINE.
Exercise
Day 1
Exercise

1. Write an report program to display the material details with the


following specification:

– The page should not display the standard heading


– The length of a page is 20
– 2 lines should be reserved for the footer
– Display page number in the footer
– Specify the heading as the ‘MATERIAL DETAILS’.
– Use a selection screen to accept the vendor and the price as input
– Initialize the price to be between 1000 and 10000.
Interactive Lists
Day 2
Interactive Lists

 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.

 The basic list is the standard screen of an executable program (report).

 In list processing, the event is intercepted by the list processor and


processed.

 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.

 For the basic list SY-LSIND is zero.

 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.

 If there is, SY-LSIND is automatically increased by one, and the relevant


event block is executed

 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.).

 Each interactive list event creates a new detail list.

 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

 There is no standard page header for detail lists


Consequences of Event Control

 Processing blocks cannot be nested

 TOP-OF-PAGE event cannot be used in secondary lists but TOP-OF-


PAGE DURING LINE-SELECTION can be used

 The system does process the event END-OF-PAGE in secondary lists.

 The GET and GET LATE cannot be used to retrieve data for secondary
lists
System Field for Detail List

System Field Information


SY-LSIND Index of the list created during the current event (basic list = 0)

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.).

System Field Information


SY-CPAGE Page number of the first displayed page of the list from which the
event was triggered
SY-STARO Number of the first line of the first page displayed of the list from
which the event was triggered (counting starts with 1). This line
may contain the page header.

SY-STACO Number of the first column displayed in the list from which the
event was triggered (counting starts with 1)

SY-UCOMM Function code that triggered the event


SY-PFKEY Status of the List Currently Being Displayed
Using Detail Lists

 A classic report is a program that generates a single list

 Example

START-OF-SELECTION.
WRITE: 'Basic List, SY-LSIND =', sy-lsind.
AT LINE-SELECTION.
WRITE: 'Secondary List, SY-LSIND =', sy-lsind.
Interactive Lists - Example

WRITE 'Basic List'.


AT LINE-SELECTION.
WRITE 'Secondary List'.
TOP-OF-PAGE DURING LINE-SELECTION.
CASE sy-lsind.
WHEN 1.
WRITE 'First Secondary List'.
WHEN 2.
WRITE 'Second Secondary List'.
WHEN OTHERS.
WRITE: 'Secondary List, Level:', sy-lsind.
ENDCASE.
ULINE.
Dialog Status For Lists

 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 system assigns function codes to list-specific user actions.


Standard List Status

 The GUI status for lists can be defined and attached to list level using
SET PF-STATUS

 If an event block is define d in the program using the event keyword AT


SELECTION SCREEN, the system automatically assigns extra function to
other function keys

 For AT LINE-SELECTION event, the F2 key(double click) is assigned to


function code PICK

 All other function codes are either intercepted by the runtime


environment or trigger the event AT USER-COMMAND.

 Function codes that trigger AT USER-COMMAND must be defined in the


own GUI status.
Setting a Dialog Status

SET PF-STATUS <stat> [EXCLUDING <f>|<itab>]


[OF PROGRAM <prog>]
[IMMEDIATELY].

– This statement sets the status <stat> for the current output list

– SET PF-STATUS SPACE is used to set the standard list status


Setting a Title for a List

SET TITLEBAR <ttl> [WITH <g1> ... <g9>]


[OF PROGRAM <prog>].

– 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

 After a user interaction on a list, the ABAP runtime environment checks


whether it should process the function code itself (for example, %EX or
%PC), or whether it should trigger the relevant event.

 Unlike normal screens, in which the PAI event is triggered, the runtime
environment triggers three special events when list events occur

 The corresponding event blocks in ABAP program can be used to react to


the user action. From within the program, the SY-UCOMM system field
can be used to access the function code.
Interactive Lists – Event Block

 Event Block for Function Code PICK

– When the user triggers the function code PICK, AT LINE-SELECTION is


always triggered if the cursor is positioned on a list line

 Event Block for User-Defined Function Codes

– 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.

 Triggering a List Event from the Program

SET USER-COMMAND <fc>.


Example

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

WINDOW STARTING AT <left> <upper> [ENDING AT <right> <lower>].

 The WINDOW statement takes effect only within the processing block of
an interactive event, that is, only for detail lists

 Dialog boxes have no menu bar and no standard toolbar

 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

 Automatic Data Transfer

– Using System Fields

– System Fields provide the information about


• the list index
• Position of List in the Output Window
• The cursor Position

– The system field SY-LIESEL contains the contents of the selected line .
Example

REPORT DEMO_LIST NO STANDARD PAGE HEADING.


DATA num TYPE i.
WRITE : / 'List of Square Numbers between One and Hundred'.
WRITE : / 'List of Cubic Numbers between One and Hundred'.
TOP-OF-PAGE.
WRITE 'Choose a line!'.
ULINE.
AT LINE-SELECTION.
CASE sy-lilli.
WHEN 3.
DO 100 TIMES.
num = sy-index ** 2.
WRITE: / sy-index, num.
ENDDO.
WHEN 4.
DO 100 TIMES.
num = sy-index ** 3.
WRITE: / sy-index, num.
ENDDO.
ENDCASE.
Program-Controlled Data Transfer

 Using ABAP Statements


– HIDE
• Fundamental Statement for interactive reporting
• Defines the information that can be passed to subsequent lists

– 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.).

 A line can be selected

– By an interactive event.

– By the READ LINE statement.

 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

TABLES: SPFLI, SBOOK.


SELECT-OPTIONS CARRID FOR SPFLI-CARRID.
START-OF-SELECTION.
SET PF-STATUS 'FLIGHT'.
SELECT * FROM SPFLI WHERE CARRID IN CARRID.
WRITE: / SPFLI-CARRID, SPFLI-CONNID,SPFLI-CITYFROM, SPFLI-CITYTO.
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SELE'.
SET PF-STATUS 'BOOKING'.
SELECT * FROM SBOOK WHERE CARRID = SPFLI-CARRID AND CONNID = SPFLI-CONNID.
WRITE / SBOOK-FLDATE. POSITION 16. WRITE SBOOK-BOOKID.
HIDE: SBOOK-BOOKID, SBOOK-FLDATE, SBOOK-CUSTTYPE,SBOOK-SMOKER, SBOOK-
LUGGWEIGHT, SBOOK-CLASS.
ENDSELECT.
IF SY-SUBRC NE 0.
WRITE / 'No bookings for this flight'.
ENDIF.
CLEAR SBOOK-BOOKID.
WHEN 'INFO'.
IF NOT SBOOK-BOOKID IS INITIAL.
WRITE: 'Customer type :', SBOOK-CUSTTYPE, / 'Smoker :', SBOOK-SMOKER,
/ 'Luggage weight :', SBOOK-LUGGWEIGHT UNIT 'KG', / 'Class :', SBOOK-CLASS.
ENDIF.
ENDCASE.
Reading Lines from the Lists

 Used to To read a line from a list after an interactive list event

READ LINE <lin> [INDEX <idx>]


[FIELD VALUE <f1> [INTO <g 1>] ... <f n> [INTO <g n>]]
[OF CURRENT PAGE|OF PAGE <p>].

– 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>] ...].

– This statement reads a line read before by an interactive event or by READ


LINE
Example

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

 Reading Lists at the Cursor Position

GET CURSOR FIELD <f> [OFFSET <off>] [LINE <lin>]


[VALUE <val>] [LENGTH <len>].

 Determining the Attributes of Lists


– To retrieve the number of lines or pages of a list:
DESCRIBE LIST NUMBER OF LINES|PAGES <n> [INDEX <idx>].

– To retrieve the page number for a certain line number:


DESCRIBE LIST LINE <lin> PAGE <pag> [INDEX <idx>].

– To retrieve the attributes of a certain page:


DESCRIBE LIST PAGE <pag> [INDEX <idx>] [<options>]
Retrieving Attributes of a Page

 The <options> of the statement can be


– LINE-SIZE <col>
• writes the page width into the variable <col>.
– LINE-COUNT <len>
• writes the page length into the variable <len>.
– TOP-LINES <top>
• writes the number of page header lines into the variable <top>.
– TITLE-LINES <ttl>
• writes the number of list header lines of the standard page header into the variable
<ttl>.
– HEAD-LINES <head>
• writes the number of column header lines of the standard page header into the
variable <head>.
– END-LINES <end>
• writes the number of page footer lines into the variable <end>.

– Etc.,
Example

REPORT DEMO_LIST NO STANDARD PAGE HEADING LINE-SIZE 40 LINE-COUNT 5(1).


DATA: lin TYPE i, pag TYPE i,col TYPE i, len TYPE i, lin1 TYPE i,top TYPE i, tit TYPE i, head TYPE i, end
TYPE i.
DO 4 TIMES.
WRITE / sy-index.
ENDDO.
TOP-OF-PAGE.
WRITE 'Demonstration of DESCRIBE LIST statement'.
ULINE.
END-OF-PAGE.
ULINE.
AT LINE-SELECTION.
NEW-PAGE LINE-COUNT 0.
WINDOW STARTING AT 1 13 ENDING AT 40 25.
DESCRIBE LIST: NUMBER OF LINES lin INDEX 0, NUMBER OF PAGES pag INDEX 0.
WRITE: 'Results of DESCRIBE LIST: '.
ULINE AT /(25). WRITE: / 'Lines: ', lin, / 'Pages: ', pag. SKIP.
DESCRIBE LIST LINE sy-lilli PAGE pag INDEX 0.
WRITE: / 'Line', (1) sy-lilli, 'is on page', (1) pag. SKIP.
DESCRIBE LIST PAGE pag INDEX 0 LINE-SIZE col LINE-COUNT len LINES lin FIRST-LINE lin1
TOP-LINES top TITLE-LINES tit HEAD-LINES head END-LINES end.
WRITE: 'Properties of Page', (1) pag, ':', / 'Width: ', col, / 'Length: ', len, / 'Lines: ', lin,
/ 'First Line: ', lin1, / 'Page Header: ', top, / 'Title Lines: ', tit, / 'Header Lines:', head,
/ 'Footer Lines:', end.
Example - output
Exercise

1. Write an interactive report to display the following details from the


SALES HEADER (VBAK) 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


Exercise

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

VBELN Sales Document

POSNR Sales Document Item

MATNR Material number

MATKL Material Group

POSAR Item Type

STLNR Bill of Material

NETPR Net Price


Exercise

3. Modify the interactive list in exercise 1 where multiple line items can be
chosen in the basic list.

4. Write an interactive report to display the following details from the


SALES HEADER (VBAK) 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


Menu Painter
Menu Painter

 A tool that is used to design the user interfaces for ABAP Program.

 GUI status is the instance of the interface consisting of menu bar, a


standard toolbar, an application toolbar, and a function key setting.

 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

 It consists of a reference to a menu bar, a standard toolbar, and a function


key setting.
Menu Painter (Contd.).

 The initial screen of the menu painter (SE41)


Menu Bars

 A menu bar may contain up to six menus.


 The system then adds the two standard menu bars
– System and
– Help.
 These two menu are always displayed at the right-hand end of every menu
bar in the R/3 System.
Menu Painter
Defining An Application Toolbar

 A function to a function key must be assigned before it can be included


in the application toolbar.

 A maximum of 35 pushbuttons in the application toolbar can be included.

 Application toolbar functions can contain an icon, a text, or both together.


Menu Painter
ALV Reporting
Day 3
ALV Reporting

 ABAP List Viewer

 An SAP Tool for Reporting

 The tool provides common list operations as generic functions and can be
enhanced by self-defined options.

 Reduces the development time of reports by providing the standard


interfaces ( Function Modules)
Traditional ABAP Reporting

 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.

 Interactive list events (AT LINE-SELECTION)

 20% of the time spent on making the report output ‘look pretty’

 Column headings

 Vertical lines and frames


Programming with the ALV

 50% of the time spent on finding the right tables and table relationships
(selection process)

 1% of the time spent on preparing field catalog and sort sequence


information for the list viewer

 9% of the time spent on ‘fancy features’ for interactive list events

 No time spent on ‘looks’ and ‘feel’ (column headings, sorting, etc.)

 Time savings >= 40% easily possible


Steps involved in creating ALV reports.

 Declare data areas for list viewer


 Declare internal table to store selected data
 Select data into internal table
 Populate display variants
 Build field catalog
 Build sort catalog
 Build event catalog
 Build Layout
 Build GUI status
 Build Event Exit Table
 Build Field groups
 Start list viewer
 Process call back events
Implementation Details

 Declare data areas for list viewer


TYPE-POOLS: SLIS.
** For field catalog
DATA: i_fieldcat TYPE SLIS_t_fieldcat_ALV.
** For events
DATA: i_events TYPE SLIS_t_EVENT.
** For sorting
DATA: i_sort TYPE slis_t_sortinfo_alv.
** For fieldgroups
DATA: i_fieldgroups_tab TYPE SLIS_t_sp_group_ALV.
** For variant
DATA: ws_x_variant LIKE disvariant,
ws_variant LIKE DISVARIANT,
ws_save TYPE C,
ws_exit TYPE C,
ws_repid LIKE sy-repid.
** For layout
DATA: ws_layout TYPE SLIS_layout_alv.
ALV Reporting (Contd.).

 Declare internal table to store selected data


– Internal table definition, that will store the data to be displayed on the screen

 Select data into Internal Table


– To get the dat ainto the Internal Table

 Populate Display Variant


– To store onscreen display as Variants

 Build Field Catalog

– 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 sort catalog


– Sort catalog contains fields on which the sorting of the list will be done.

 Build event catalog


– ALV supports normal ABAP reporting events and handles it internally as well
as externally.
– The internal table I_EVENTS is populated with the name of the form
corresponding to the event to be handled.

 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.).

 Build Field Groups

– For easy onscreen display selection, fields can be grouped.


– Populate internal table i_fieldgroups_TAB with the groups and description.
– Assign the groups to the fields in the field catalog.

 Start list viewer

– 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

 The commonly used ALV functions are:

– 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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM = 'SY-REPID'
I_STRUCTURE_NAME = 'SFLIGHT'
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = IT_SFLIGHT.
ALV Reporting – Example (Contd.).

TABLES : SPFLI, SBOOK.


TYPE-POOLS : SLIS.
DATA: SYSREPID TYPE SY-REPID.
DATA: I_TAB_NAME.
SYSREPID = SY-REPID.
DATA: BEGIN OF WA_FINAL ,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
AIRPFROM TYPE SPFLI-AIRPFROM,
AIRPTO TYPE SPFLI-AIRPTO,
FLDATE TYPE SBOOK-FLDATE,
CUSTTYPE TYPE SBOOK-CUSTTYPE,
BOOKID TYPE SBOOK-BOOKID,
END OF WA_FINAL.
DATA : IT_FINAL LIKE TABLE OF WA_FINAL.
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER L
INE,
FIELDLAYOUT TYPE SLIS_LAYOUT_ALV.
ALV Reporting – Example (Contd.).

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 POPULATE_LAYOUT USING FIELDLAYOUT TYPE SLIS_LAYOUT_ALV.


FIELDLAYOUT-WINDOW_TITLEBAR = 'MY LIST VIEWER'.
ENDFORM.

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 Field header

VBELN Sales Document

POSNR Sales Document Item

MATNR Material number

MATKL Material Group

POSAR Item Type

STLNR Bill of Material

NETPR Net Price


Assignment
Day 3
Assignment

1. Write an interactive report to display the following details from the


SALES HEADER (VBAK) 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

VBELN Sales Document

POSNR Sales Document Item

MATNR Material number

MATKL Material Group

POSAR Item Type

STLNR Bill of Material

NETPR Net Price


Assignment

 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

KUNNR Customer number

NAME1 NAME

ADRNR ADDRESS

ORT01 CITY

LAND1 COUNTRY

TELF1 TELEPHONE NUMBER

TELFX FAX NUMBER


Assignment

 On clicking on the MATNR from the INTERACTIVE list, the


corresponding details from the MARA( material master) should be
displayed in the next interactive lists

Fields Description

MATNR Material number

MTART Material Type

MBRSH Industry Sector

MATKL Material Group

MEINS Unit of measure


Assignment

2. Write an ALV Report to display the following fields from EKKO (Purchase
Document Header) and EKPO (Purchase Document Item) table.

Field Field Heading Description


EBELN PO Number Purchase Document Number
LIFNR Vendor Vendor Account number
MATNR Material Material Number
BUKRS Company Code Company Code
MENGE Quantity PO Quantity
MEINS UOM Unit Of Measure
NETPR Price Price Unit
List Generation Techniques

QUESTIONS?
Summary

 By end of this course, the participants have learnt

– The different input methods ( PARAMETERS and SELECT-OPTIONS)


– To use Selection Screen
– The complete usage of WRITE statement
– To generate a list using simple reports
– The Structure of Logical Database and use it in reports
– To use different events in a report
– To apply the Interactive reports
– To write simple ALV Reports
– To use Debugger
Thank You

You might also like