Uploaded by 12297997

BC 405 - Techniques of List Creation

advertisement
BC405 Techniques of List Creation
BC405
Techniques of List Creation
 SAP AG 2003
 SAP AG
System: R/3
System Requirements: SAP R/3, Basis Release 4.6C or higher
2002/Q2
Material No. 50054942
Copyright
Copyright 2003 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in
any form or for any purpose without
the express permission of SAP AG. The information contained
herein may be changed without prior notice.
All rights reserved.
 SAP AG 2003
Comments on trademarks:
Some software products marketed by SAP AG and its distributors contain proprietary software
components of other software vendors.
Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered
trademarks of Microsoft Corporation.
IBM®, DB2®, DB2 Universal Database, OS/2®, Parallel Sysplex®, MVS/ESA, AIX®, S/390®,
AS/400®, OS/390®, OS/400®, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner,
WebSphere®, Netfinity®, Tivoli®, Informix and Informix® Dynamic ServerTM are trademarks of IBM
Corporation in USA and/or other countries.
ORACLE® is a registered trademark of ORACLE Corporation.
UNIX®, X/Open®, OSF/1® and Motif® are registered trademarks of the Open Group.
Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®,
MultiWin® and other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.
HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web
Consortium, Massachusetts Institute of Technology.
JAVA® is a registered trademark of Sun Microsystems, Inc.
JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology
invented and implemented by Netscape.
MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.
SAP, R/, mySAP, mySAP.com, xApps, xApp, and other SAP products and services mentioned herein as
well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in
several other countries all over the world. All other product and service names mentioned are the
trademarks of their respective companies.
Course Prerequisites
SAPTEC - mySAP Technology Solution Fundamentals
BC400 - ABAP Workbench: Foundations and Concepts
Initial ABAP Programming Experience
 SAP AG 2003
Introduction
Course Goals
Course Objectives
Course Content
Course Overview Diagram
Main Business Scenario
Getting Started
 SAP AG 1999
(C) SAP AG
BC405
1-1
Course Goals
This course will prepare you to:
Use utilities to create lists.
Create print lists.
Create both simple and interactive lists.
 SAP AG 2002
(C) SAP AG
BC405
1-2
Course Objectives
At the conclusion of this course, you will be able to:
Create formatted lists.
Design a selection screen and evaluate user input.
Read data from the database and use logical databases.
Use internal tables and extract datasets to format data.
Create simple interactive lists.
Use the SAP Grid Control.
 SAP AG 2002
(C) SAP AG
BC405
1-3
Course Content 1
Preface
Unit 1
Introduction
Unit 2
Outputting Data in Lists
Unit 3
Selection Screen
Unit 4
Logical Database
Unit 5
Programming Data Retrieval
Unit 6
Data Formatting and Control Level Processing
 SAP AG 2002
(C) SAP AG
BC405
1-4
Course Content 2
Unit 7
Saving Lists and Background Processing
Unit 8
Basic Techniques in Interactive Lists
Unit 9
SAP Grid Control
The exercises and solutions are located at the end of each unit.
Appendix
 SAP AG 2002
(C) SAP AG
BC405
1-5
Course Overview Diagram
Connections of Airline LH
1
CAR Id
Departure
AA 0017
AA 0064
LH 0400
LH 0402
New York
San Francisco
San Francisco New York
Frankfurt
New York
Frankfurt
Berlin
Tools
Arrival
Simple Lists
AZ
AZ
AZ
DL
DL
LH
LH
LH
LH
ROME
TOKYO
TOKYO
ROME
AZ
0789
12/29/2001
12/09/2001
2,667,445 ITL
2,667,445 ITL
Interactive Lists
SAP Grid Control
 SAP AG 2002
(C) SAP AG
BC405
1-6
Business Scenario
You work for a tour operator.
The company wants to improve its service.
The company needs a list of the most current flight
data to allow for an increase in bookings.
You must write a program that displays the
required flight data to a list.
 SAP AG 2002
(C) SAP AG
BC405
1-7
Demonstrations, Copy Templates, and Solutions
Development class BC405 with the following naming conventions:
Demonstrations SAPBC405_xxxD_...
Copy templates SAPBC405_xxxT_...
Solutions
SAPBC405_xxxS_...
xxx
Individual unit code
 SAP AG 2002
Abbreviations for individual units:
•FOL Unit 2: Outputting Data in Lists
•SSC Unit 3: Selection Screen
•LDB Unit 4: Logical Database
•GDA Unit 5: Programming Data Retrieval
•DAP Unit 6: Data Formatting and Control Level Processing
•STL Unit 7: Saving Lists and Background Processing
•ILB Unit 8: Basic Techniques in Interactive Lists
•ALV Unit 9: ALV Grid Control
(C) SAP AG
BC405
1-8
Exercises and Units
Without LDB (with copy template)
With LDB (F1S)
Outputting Data in Lists
Logical Database
Selection Screen
Data Formatting and Control
Internal Data Collection
Level Processing Using
Data Formatting and Control Level
Extract Datasets
Processing using internal tables
Saving Lists and
Basic Techniques in Interactive
Background Processing
Lists
 SAP AG 2002
Several of the units contain exercises. The sample solution provided for each exercise can be used for the
subsequent exercise.
(C) SAP AG
BC405
1-9
Outputting Data in Lists
Contents
Simple Lists
List Formats
Page Layout
Output Design
Tools
 SAP AG 2002
(C) SAP AG
BC405
2-1
Outputting Data in Lists: Objectives
At the conclusion of this unit, you will be able to:
Structure a simple list
Design your own list:
Design the List Format
Layout the page
Design the output
 SAP AG 2002
(C) SAP AG
BC405
2-2
Generating a List
REPORT
sapbc405_fold_list_creation .
DATA: wa_spfli LIKE spfli.
START-OF-SELECTION.
SELECT carrid connid cityfrom cityto
FROM spfli
INTO (wa_spfli-carrid, …..
DEMO: Generating a list
1
WRITE: / wa_spfli-carrid, wa_spfli-connid,
wa_spfli-cityfrom, wa_spfli-cityto.
AA 0017 NEW YORK
SAN FRANCISCO
AA 0064 SAN FRANCISCO NEW YORK
ENDSELECT.
AZ 0555 ROME
FRANKFURT
IF sy-subrc <> 0. … ENDIF.
AZ 0788 ROME
TOKYO
:
:
 SAP AG 2002
The first WRITE statement in an ABAP program triggers list generation. Output is directed to a list
buffer and, when the buffer has been completely built, the system generates the screen image from the
list buffer.
As a standard function, the system generates two header lines (standard header). The first header line
contains the program title from the program attributes in the upper-left corner and the page number in
the upper-right corner. The second header line consists of an unbroken line. Both header lines remain in
the window when you scroll.
When you print a list, the first line of the header appears as follows:
Upper-left: System date
Center: Program title
Upper-right: Page number
Use transaction LIBS to display the SAP system list format suggestions. If you make your reports look
as much like SAP reports as possible, your users will have a consistent look and feel between your
custom reports and SAP reports.
(C) SAP AG
BC405
2-3
Setting the List Format
REPORT <name> LINE-SIZE <s> LINE-COUNT <m[(n)]>.
REPORT sapbc405_fold_list_layout
.LINELINE-SIZE 50
LINELINE-COUNT 12.
12
...
WRITE: ...
50
DEMO: List format design
AT LINE-SELECTION.
CHECK NOT….
NEW-PAGE LINE-SIZE 122
LINE-COUNT 65(3).
WRITE …...
:
1
DEMO: List format design
:
12
:
2
:
 SAP AG 2003
The default report line width is 83 columns. The default page length is 60,000 lines. To override these
defaults, use the additions LINE-SIZE <columns> and LINE-COUNT <lines_per_page> on the
REPORT statement. Note that the values for lines per page and column width must be numbers and not
data object names.
Within a list level, you can use NEW-PAGE LINE-COUNT <s> to change the number of lines on a
page – this value overrides the definition in the REPORT statement. The width of a list can only be
changed by creating a new list level. If you want to use the default values, then set <s> and/or <m> to
zero.
You cannot use variables for <s> or <m>.
The use of LINE-COUNT <lines_per_page>(<footer_lines>) indicates that the page has a fixed
number of lines part of which is reserved for use at the END-OF-PAGE event.
The number of lines per page includes headings, detail, and footer lines. The value of <lines_per_page>
must be higher than the sum of Header and Footer lines. Else, you get a program failure.
(C) SAP AG
BC405
2-4
Page and Column Headers
Standard headers
TOP-OF-PAGE
EDITOR
LIST
Goto
System
Text elements
Title/Headings
REPORT sapbc405_fold_top_of_page
NO
NO STANDARD
STANDARD PAGE
PAGE HEADING.
HEADING.
TOPTOP-OFOF-PAGE.
WRITE: / '************ ... '
List
List headers
START-OF-SELECTION.
...
******************************
List header
Column header
******************************
 SAP AG 2002
You can maintain the list header and up to four column headers for a list. These standard page headers
can be maintained either from the source code editor using the menu path Goto → Text Elements →
List Heading or from the primary list buffer display using the menu path System → List → List
Header. Maintaining the headers from the list display is helpful since the report output is visible. The
new headings will automatically appear the next time the report is started. If you have not maintained the
standard page headers, the system field SY-TITLE, which contains the program description from the
program's attributes, is shown.
The addition NO STANDARD PAGE HEADING in the REPORT/PROGRAM statement suppresses
the output of list and column headers. You can override this global setting with NEW-PAGE NOTITLE/WITH-TITLE and NO-HEADING/WITH-HEADING. As with all text elements, the headers
can be translated later.
The TOP-OF-PAGE event can be used to generate page headers. This is especially useful when you
want to output variables in the headers. The event is triggered automatically in the primary list buffer
when the first WRITE, ULINE, or SKIP keyword is encountered. If you do not suppress the standard list
headers, they will appear above the lines generated by TOP-OF-PAGE. Lines generated by TOP-OFPAGE remain in the window during vertical scrolling.
(C) SAP AG
BC405
2-5
Defining Line and Field Formats
REPORT sapbc405_fold_format ... .
...
TOP-OF-PAGE.
FORMAT COLOR
COLOR COL_HEADING
COL_HEADING INTENSIFIED
INTENSIFIED ON.
ON.
ON
FORMAT
ON
WRITE: ...
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: ...
START-OF-SELECTION.
SELECT carrid connid cityfrom cityto deptime arrtime
INTO wa_spfli FROM spfli.
WRITE: / wa_
wa_spflispfli-carrid COLOR COL_KEY INTENSIFIED ON,
ON
wa_
_
spfliconnid
COLOR
COL_KEY
INTENSIFIED
ON.
wa spfli
ON
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
WRITE:
wa_spfli-cityfrom HOTSPOT ON,
wa_spfli-cityto,
wa_spfli-deptime HOTSPOT ON,
wa_spfli-arrtime.
FORMATRESET.
RESET.
RESET
FORMAT
ENDSELECT.
 SAP AG 2002
You can use any of the following FORMAT options:
•COLOR <n> [ON|OFF] Colors the line background
•INTENSIFIED [ON|OFF] Intensify colors YES|NO
•INVERSE [ON|OFF] Inverse: Background/text color
•HOTSPOT [ON|OFF] Display mouse pointer as hand and single click
(see AT LINESELECTION)
•INPUT [ON|OFF] Input field
•RESET
Resets all formats to their default values
The formats set with FORMAT take effect with the next WRITE statement and remain in effect until
they are turned off either with FORMAT COLOR OFF or FORMAT RESET. Note that using RESET
turns off the standard setting of INTENSIFED ON. As a result, FORMAT COLOR OFF is typically a
better choice.
At each new event, the system resets all FORMAT options to their default values.
You can apply formatting options to individual fields as in WRITE WA_SPFLI COLOR COL_KEY.
This technique overrides the options set with the FORMAT keyword.
(C) SAP AG
BC405
2-6
WRITE Statement: General Syntax
WRITE [AT] [/<pos(len)>] <f> <option1> <option2> ...
.
REPORT sapbc405_fold_write ... .
* constants for positions of outputs
CONSTANTS: POS2 TYPE I VALUE 12,
LEN_FDT TYPE I VALUE 10,
"sflight-fldate
...
AT:
AT
WRITE AT:
AT / sy-vline,
pos2(
len
fdt)) wa_sflight-fldate COLOR COL_KEY,
pos2(len
len_
__fdt)
pos2(
fdt
...
(len_pri) wa_sflight-price CURRENCY wa_sflight-currency,
(len_cur) wa_sflight-currency.
...
 SAP AG 2003
NO-GAP
Suppresses output of spaces after the <f> field.
Fields output directly after each other appear without gaps.
NO-ZERO If the contents of field <f> are equal to zero, only spaces are
output. If the field is type C or N, spaces replace leading zeros.
DD/MM/YY Overrides the date formatting rule defined at the User profile
level.
CURRENCY <key>
Formats currency fields based on rules defined in table TCURX.
UNIT <key> Formats quantity fields based on rules defined in table T006.
USING EDIT MASK <mask> Outputs according to the formatting template<mask>.
UNDER <g>The output begins at the column in which field <g> was output.
LEFT-JUSTIFIED
Left-justified output (default for types C, N, D, T, X).
CENTERED
Centered output within the output length.
RIGHT-JUSTIFIED Right-justified output (standard for all number fields: I, P and F)
You can find a complete list of all WRITE options in the online documentation.
(C) SAP AG
BC405
2-7
Outputting Icons, Symbols, and Lines
REPORT sapbc405_fold_icon_symbol_line.
* INCLUDE <icon>
* INCLUDE <symbol>.
INCLUDE <list>.
...
* state of free seats
IF SEATSFREE < 1.
WRITE ICON_RED_LIGHT AS ICON.
ELSEIF SEATSFREE > 1.
WRITE ICON_GREEN_LIGHT AS ICON.
ENDIF.
* state of booked seats
IF WA_SFLIGHT-SEATSOCC < 10.
WRITE SYM_LEFT_HAND
SYM_LEFT_HAND AS
AS SYMBOL.
SYMBOL.
ENDIF.
 SAP AG 2002
You can use the AS SYMBOL option of the WRITE statement to show symbols in lists. This requires
the statement INCLUDE <SYMBOL>. You can also write icons in list using AS ICON on the WRITE
statement. The include named <LIST> can be used instead of the individual include statements. The
<LIST> include contains include statements for <SYMBOL>, <ICON>, <LINES>, and <COLOR>.
You can find an overview of available symbols and icons in the online documentation or in the statement
examples for WRITE.
To generate a horizontal line, use the ULINE statement, system field sy-uline in a WRITE statement, or
several minus signs in a WRITE statement. ULINE creates an underline the entire width of the report.
Other options for ULINE are ULINE /25 which underlines from column 25 to the right margin and
ULINE /25(30) which starts the underline in column 25 for 30 columns.
To generate a vertical line, use system field sy-vline in a WRITE statement
To generate special lines, like the upper-right corner, use line_top_right_corner AS LINE.
You can use these elements to frame a list, to separate titles from a list with horizontal lines, to separate
columns with vertical lines, and to create table and trees.
(C) SAP AG
BC405
2-8
Scrolling in Lists and Lead Columns
SCROLL LIST [TO PAGE <p>][TO COLUMN <c>][TO LAST PAGE]
[<option>]...
SET LEFT SCROLL-BOUNDARY [COLUMN <c>].
REPORT
sapbc405_fold_scroll_boundary ...
DATA: lsb_column
lsb_column TYPE i VALUE 10.
9
TOP-OF-PAGE.
SET
SCROLL
SET LEFT
LEFT SCROLLSCROLLBOUNDARY
SCROLL--BOUNDARY
COLUMN
lsb_column
lsb
COLUMN lsb_column
_column.
lsb_column.
START-OF-SELECTION.
...
SCROLL LIST
LIST TO
TO LAST
LAST PAGE.
PAGE.
PAGE
SCROLL
PAGE
 SAP AG 2003
You can use SET LEFT SCROLL-BOUNDARY to freeze a fixed number of columns from the left
margin. Without an additional parameter COLUMN <number_of_columns>, the system uses the
current write position (SY-COLNO) as the left margin to freeze.
You must code this keyword in the TOP-OF-PAGE and TOP-OF-PAGE DURING LINE-SELECTION
events since the system resets the value to zero at the end of each page.
You can use NEW-LINE NO-SCROLLING to prevent the next list line from scrolling. This is useful
to keep subheadings from scrolling while the detail lines scroll. This keyword can be combined with the
SET LEFT SCROLL-BOUNDARY to freeze left margin columns on the report, resulting in a line that
doesn't scroll while other lines scroll with frozen left margin columns.
You can use the SCROLL keyword to scroll to any column or page in the list. Use of the extension
INDEX <list_buffer_number> allows you to scroll in a specific list buffer. The following code will
scroll the list buffer indicated by the current value of SY-LSIND to a specific page and line number on
that page:
SCROLL LIST TO PAGE <page_number> INDEX sy-lsind LINE <line_number>
(C) SAP AG
BC405
2-9
Additional Statements for Page Layout
NEW-PAGE.
NEW-LINE.
SKIP [TO LINE] <n>.
RESERVE <n> LINES.
BACK.
POSITION <n>.
SET BLANK LINES ON|OFF}.
 SAP AG 2003
NEW-PAGE
NEW-LINE
Creates a page break.
Creates a line break and is the equivalent of "/" in a WRITE
statement.
RESERVE <n> LINES
If the current page does not have space for at least <n> more
lines in the list structure, a page feed is generated.
SKIP <n>
<n> blank lines are output.
SKIP TO LINE <n>
Positions the print cursor to line <n> on the current page.
BACK
Positions the print cursor to the first line after the headers on the
current page.
BACK (with RESERVE)
When used with RESERVE, returns the print cursor to the line
where the RESERVE keyword was issued.
POSITION <n>
Positions the print cursor to column <n> of the current line.
SET BLANK LINES ON
Blank lines created by SKIP and blank fields are output.
SET BLANK LINES OFF
No blank lines are output (default setting).
RESERVE, POSITION, and BACK are useful for printing mailing labels.
(C) SAP AG
BC405
2-10
Multilingual List Elements
Program
Source text
Text elements
REPORT
REPORT ...
...
Title/Headings
WRITE:/
WRITE:/ SY-VLINE,
SY-VLINE,
'Flight'(001),
'Flight'(001),
'Depature
'Depature city'(002),
city'(002),
'Dest.
'Dest. city'(003),
city'(003),
...
...
List header
DE Flugverbindungen
EN Flight Connections
FR ...
Text symbols
001
002
DE Flug
EN Flight
FR .....
:
DE Startort
Start the extended syntax check: Error if text elements are not maintained.
Reconciliation: Program
Text symbols possible.
Determine text lengths with character list for other languages.
 SAP AG 2003
Text elements include standard page headers, text symbols, and selection texts. The text elements are
saved separately from the source text and in the language of the developer who wrote the report. This
allows subsequent translation without touching the logic of the ABAP program. The user's logon
language determines the language in which the system displays text elements.
Define the output length of the text symbols as long as necessary, allowing sufficient space for
translation into other languages.
Text symbols can be addressed in programs in two ways:
•WRITE TEXT-xxx
(xxx is a three-character string)
•literal text (xxx)
An advantage to the second method of WRITE <literal text>(xxx) is that if there is no translation in the
user's sign on language, the literal text will appear on the report rather than spaces.
If a text symbol has been maintained, it is always output in the list. The extended syntax check
(transaction SLIN) returns an error if you forget to maintain the text symbols.
(C) SAP AG
BC405
2-11
SY-SROWS
1
SY-LINSZ
SY-LINCT
System Fields in List Creation
2
SY-SCOLS
SY-COLNO
SY-LINNO
SY-PAGNO
1
2
3
 SAP AG 1999
During generation of a list, the ABAP runtime system fills the following system fields:
SY-LINCT Number of lines from REPORT statement (LINE-COUNT)
SY-LINSZ Line width from REPORT statement (LINE-SIZE)
SY-SROWSNumber of lines in the display window
SY-SCOLS Number of columns in the display window
SY-PAGNOPage number of the current page
SY-LINNO Line number of the current line of the current page (SY-PAGNO)
SY-COLNO Column number of the current column
During generation of the list, the system fills the last three system fields continuously.
(C) SAP AG
BC405
2-12
Standard List Functions
Back/Exit/Cancel
Scroll
Print
Find
List
Save
Save/Send
 SAP AG 2002
A number of standard list functions are available in the standard list interface. This functionality is
provided automatically for report programs.
(C) SAP AG
BC405
2-13
Outputting Data in Lists: Unit Summary
You are now able to:
Structure a simple list
Design your own list:
Design the List Format
Layout the page
Design the output
 SAP AG 2002
(C) SAP AG
BC405
2-14
Outputting Data in Lists Exercises
Unit: Outputting Data in Lists
Topic: Formatting
When you have completed these exercises, you will be able to:
• Define list formatting
• Set headers
• Set hard lead columns
• Create multiple page lists
1-1
Copy program template SAPBC405_FOLT_1 to Z##FOL1_... Sample solution for
exercise: SAPBC405_FOLS_1.
The program template is structured as follows: The global data and selection screen are
defined in the TOP include. A selection list for the airline codes is displayed on the
selection screen. At START-OF-SELECTION, the system reads the data from the
database to internal table it_flights using a database view. At END-OF-SELECTION,
the system calls subroutine DATA_OUTPUT. Your task is to implement the data
output.
1-2
Generate a list (see sample list).
1-2-1 The list should contain the following fields:
Airline code
= wa_flights-carrid
Flight number
= wa_flights-connid
Flight date
= wa_flights-fldate
Departure city
= wa_flights-cityfrom
Arrival city
= wa_flights-cityto
Flight price
= wa_flights-price
Local currency of airline = wa_flights-currency
Display the data according to the template.
1-2-2 In the TOP include, define the list width as 100 columns and suppress the
standard list header.
1-2-3 Implement event TOP-OF-PAGE. Output the list and column headers here.
Refer to the template for details. Use text elements to allow your texts to be
(C) SAP AG
BC405
2-15
translated. To position the elements, use constants that you declare in the TOP
include.
1-3
Format the list.
1-3-1 Set a page break so that a new page is created for every new flight connection.
You can use the control structure ON CHANGE OF wa_flights-connid.
NEW-PAGE. ENDON.
1-3-2 Flag the international flights (wa_flights-countryto <> wa_flights-countryfr)
with an icon (ICON_BW_GIS) at the beginning of each line. You will need to
add the INCLUDE for <icon>.
1-3-3 Output the list header in color COL_HEADING with intensive display, and
the column headers in color COL_HEADING with a less intensive display.
Output the key information (CARRID, CONNID) in color COL_KEY with
intensive display and the list body in COL_NORMAL with intensive display.
Use horizontal lines to separate the headers from the list body. Output the price
as a currency amount.
Optional: Add a frame using sy-vline and ULINE as shown in the template.
1-3-4 Make sure that the airline code and connection number remain in view during
horizontal scrolling. Make sure that the statement SET LEFT
SCROLL-BOUNDARY is set for each page of the report.
(C) SAP AG
BC405
2-16
Template (Displaying Data in Lists)
Flight Data
Flight
Date
Departure
City
Arrival City
Price
@ JL
0407
06/24/2003
TOKIO
FRANKFURT
103,136 JPY
@ JL
0407
07/22/2003
TOKIO
FRANKFURT
103,136 JPY
@ JL
0407
08/19/2003
TOKIO
FRANKFURT
103,136 JPY
@ JL
0407
09/16/2003
TOKIO
FRANKFURT
103,136 JPY
@ JL
0407
10/14/2003
TOKIO
FRANKFURT
103,136 JPY
Flight Data
Flight
Date
Departure
City
Arrival City
Price
@ LH
0400
06/01/2003
FRANKFURT
NEW YORK
666.00 EUR
@ LH
0400
06/29/2003
FRANKFURT
NEW YORK
666.00 EUR
@ LH
0400
07/27/2003
FRANKFURT
NEW YORK
666.00 EUR
@ LH
0400
08/24/2003
FRANKFURT
NEW YORK
666.00 EUR
@ LH
0400
09/21/2003
FRANKFURT
NEW YORK
666.00 EUR
@
ICON_ BW_GIS
=
(C) SAP AG
BC405
2-17
Outputting Data in Lists Solutions
Unit: Outputting Data in Lists
Topic: Formatting
*&---------------------------------------------------------------------*
*& Report
SAPBC405_FOLS_1
*
*&
*
*&---------------------------------------------------------------------*
*& Exercise 1; Outputting Data in Lists
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_fols_1top.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE:
/ sy-vline,
'Flight data'(001),
AT line_size sy-vline.
ULINE.
* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
sy-vline, AT pos_c1 'Flight'(002).
* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE:
(C) SAP AG
'Date'(003) ,
BC405
2-18
'Departure location'(004),
'Arrival location'(005),
'Price'(006),
AT line_size sy-vline.
ULINE.
*&---------------------------------------------------------------------*
*&
Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Filling internal table with flight data using a DDIC view.
SELECT * FROM dv_flights INTO TABLE it_flights
WHERE carrid IN so_car.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
SORT it_flights BY carrid connid fldate.
* Data output
PERFORM data_output.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Get a new page if CONNID has changed.
ON CHANGE OF wa_flights-connid.
NEW-PAGE.
ENDON.
(C) SAP AG
BC405
2-19
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE:
wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:
wa_flights-fldate,
wa_flights-cityfrom,
wa_flights-cityto,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
AT line_size sy-vline.
ENDLOOP.
ENDFORM.
" DATA_OUTPUT
*&---------------------------------------------------------------------*
*& Include BC405_FOLS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT bc405_fols_1top LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
* Constants for writing position
CONSTANTS: pos_c1 TYPE i VALUE
6,
line_size TYPE i VALUE 100.
(C) SAP AG
BC405
2-20
* Internal table like DDIC view DV_FLIGHTS
DATA:
it_flights LIKE TABLE OF dv_flights,
wa_flights LIKE dv_flights.
* Selection screen
SELECT-OPTIONS so_car FOR wa_flights-carrid.
(C) SAP AG
BC405
2-21
Selection Screen
Contents:
Generate
Design
Input checks
Variants
 SAP AG 2002
(C) SAP AG
BC405
3-1
Selection Screen: Unit Objectives
At the conclusion of this unit, you will be able to:
Generate selection screens, supply them with
default values, and display them.
Execute input checks in the selection screen.
Create variants.
 SAP AG 2002
(C) SAP AG
BC405
3-2
Selection Screen: Overview
Logical
Logical Database
Database
NODES: ...
Default selection screen
Screen:
Variant 1
1000
Version 1
Program-internal
Program-internal
Default selection screen
PARAMETERS: ...
Screen:
1000
Variant 1
SELECT-OPTIONS: ...
SELECTION-SCREEN BEGIN
BEGIN OF
OF SCREEN
SCREEN 1100.
1100.
PARAMETERS:
... .
SELECT-OPTIONS: ... .
SELECTION-SCREEN END
ENDOFOFSCREEN
SCREEN1100.
1100.
. . .
Selection Screen
Screen:
1100
Variant 1
CALL
-SCREEN 1100.
CALL SELECTIONSELECTION-SCREEN
1100.
SELECTION
 SAP AG 2003
Selection screens serve as the interface between the program and the user and are used to limit the
amount of data to be read from the database.
Logical databases supply selection screens whose concrete appearance is dependent on the specified
node name (NODES<name>). Selection screen versions (if supplied by the logical database) offer a
subset of default selection screens.
You can use the declarative language elements PARAMETERS and SELECT-OPTIONS to generate a
default selection screen (screen 1000) with input-ready fields.
In addition to the default selection screen, you can create additional selection screens with
SELECTION-SCREEN BEGIN OF .... and call them with CALL SELECTION-SCREEN. Create
variants to save selection screen values that are used repeatedly. The variant can be recalled for use
whenever it is needed. If a report is to run in a background work process, a variant is required.
(C) SAP AG
BC405
3-3
Declaring Fields with PARAMETERS
PARAMETERS: <f>[TYPE <type>][DECIMALS <n>][LIKE <f1>][MEMORY ID <pid>]
[OBLIGATORY][DEFAULT <value>][LOWER CASE][VALUE CHECK]
[AS CHECKBOX]
[RADIOBUTTON GROUP <grp>]
REPORT sapbc405_sscd_checkbox_radiobutton.
... .
PARAMETERS: pa_carr LIKE sflight-carrid,
pa_name AS CHECKBOX DEFAULT 'X',
pa_curr AS CHECKBOX DEFAULT 'X',
pa_lim_1 RADIOBUTTON GROUP lim,
pa_lim_2 RADIOBUTTON GROUP lim,
pa_lim_3 RADIOBUTTON GROUP lim.
CONSTANTS mark VALUE 'X'.
* Check, if any checkbox has been selected
IF pa_name EQ mark. ... . ENDDIF.
IF pa_curr EQ mark. ... . ENDDIF.
Airline
AA
!
Output name
!
Output local currency
Price (local currency): up to 500
500 to 1000
1000 to 1500
* Check, which radiobutton has been selected
CASE mark.
WHEN pa_lim_1. ... .
WHEN pa_lim_2. ... .
WHEN pa_lim_3. ... .
ENDCASE.
 SAP AG 2003
The PARAMETERS keyword is a declarative language element. As in the case of the DATA
statement, you can declare parameters with TYPE or LIKE. The system generates input-ready fields in
the selection screen. The names of PARAMETERS fields can be up to eight characters long. You can
maintain selection texts using the menu path GOTO → TEXT ELEMENTS → SELECTION TEXTS.
You can set a default value for a PARAMETERS keyword with the DEFAULT <value> addition. If
you assign a MEMORY ID <pid>, the system retrieves the current value from SAP memory and
supplies it on the screen automatically. If you declare mandatory fields with the OBLIGATORY
addition, users cannot leave the selection screen until values have been entered in these fields.
The automatic checking done by the ABAP Dictionary is turned off by default for report selection
screens. However, if you make reference to a dictionary object that has a foreign key established, using
VALUE CHECK will cause the dictionary to verify that the input is valid.
You can also define parameters as checkboxes (AS CHECKBOX). Doing so creates a one-character
field that can contain a " "(SPACE) or an X. You can evaluate the contents of checkboxes using
IF/ENDIF control structures.
You can also define a series of radio buttons for the selection screen with the addition RADIOBUTTON
GROUP <grp>. The maximum length name for a RADIOBUTTON GROUP <grp> is four characters.
Only one radio button in a group can be active and can be evaluated during program processing. You
can evaluate the contents of radio buttons using CASE/ENDCASE control structures.
(C) SAP AG
BC405
3-4
Selections with SELECT-OPTIONS
SELECT-OPTIONS: <seltab> FOR <f>.
REPORT sapbc405_sscd_select_options .
TABLES: sflight.
SELECT-OPTIONS: so_carr FOR sflight-carrid DEFAULT 'AA',
so_fldt FOR sflight-fldate.
Internal Table
so_carr
Airline
Sign
Option
Low
I
EQ
AA
High
Flight date
AA
to
to
 SAP AG 2002
The SELECT-OPTIONS keyword is a declarative language element with the same eight character
naming restriction as PARAMETERS. In contrast to the PARAMETERS keyword,
SELECT-OPTIONS allows a range of values as well as complex selections instead of just a single inputready field.
The SELECT-OPTIONS keyword generates an internal table <seltab> with a standard structure and a
header line. This table has four columns: sign, option, low, and high. Just as with PAREMETERS, you
can maintain the selection text using the menu path Goto → Text elements → Selection texts.
Use the addition FOR to specify the field against which the system should check the selection entries.
This field must be declared in a DATA or TABLES statement. Both the high and low fields inherit the
attributes of the referenced field.
Each line of the selection table <seltab> formulates a condition using one of the following relational
operators. The following values are possible:
SIGN: I (Include), E (Exclude)
OPTION: EQ, NE, LE, LT, GE, GT, BT(Between), NB (Not Between),
CP (Contains Pattern), NP (Contains Pattern not)
The selection set is the union of all includes (I1,..., In) minus the union of all excludes (E1, ..., Em). If no
values are entered in the SELECT-OPTIONS object, all rows are returned from the database
(C) SAP AG
BC405
3-5
SELECT-OPTIONS with Multiple Selection Criteria
Airline
AA
=
to
Single value
Greater than or equal
Less than or equal
Multiple selections
Select
1 E...
1 I...
E...
I...
AA
Sign
Option
Low
High
I
I
EQ
BT
AA
DL
LH
 SAP AG 2003
When the user makes entries in a SELECT-OPTIONS object, the system populates the internal table
automatically.
To change the default entries for the table fields SIGN and OPTION, choose menu Edit Selection
options. The system offers all the alternatives that are appropriate for the selection. If the traffic signal
icon is green during Select, there is an (I)nclusive in the sign column while a red light indicates
(E)xclude.
To delete a table entry, use menu Edit Delete selection criterion.
Every selection criterion can be used to make multiple selections unless otherwise defined. If multiple
selections are present, the color of the arrow changes from white to green.
(C) SAP AG
BC405
3-6
Syntax of the SELECT-OPTIONS Statement
SELECT-OPTIONS <seltab> FOR <f>
DEFAULT <value>
DEFAULT <value1> TO <value2>
OPTION <xx> SIGN <x>
MEMORY ID <pid>
LOWER CASE
OBLIGATORY
NO-EXTENSION
NO INTERVALS
 SAP AG 2003
Additions to the SELECT-OPTIONS statements are:
DEFAULT enables you to set default values for low or low and high parameters. You can use
OPTION and SIGN to set default values for option and sign that differ from the normal defaults.
Value> addition. You can set a default value for a SELECT-OPTIONS keyword with the DEFAULT
<value> addition. If you assign a MEMORY ID <pid>, the system retrieves the current value from
SAP system memory and supplies it on the screen automatically. LOWER CASE suppresses
conversion of the entry into upper-case. This addition is not permitted for Dictionary fields, since the
attribute set in the Dictionary takes precedence.
OBLIGATORY generates a mandatory field. A question mark appears in the entry field in the
selection screen, and the user must enter a value.
NO-EXTENSION suppresses multiple single or multiple range selections.
NO INTERVALS suppresses the seltab-high (upper interval limit) entry on the selection screen. You
can use the additional screen, Multiple selection, to enter ranges.
(C) SAP AG
BC405
3-7
Designing the Selection Screen I
SELECTION-SCREEN BEGIN OF BLOCK <block>
WITH FRAME
TITLE <text>
SELECTION-SCREEN END OF BLOCK <block>
Price ...
REPORT sapbc405_sscd_sel_screen_i.
...
SELECTION-SCREEN BEGIN OF BLOCK carr WITH FRAME.
SELECT-OPTIONS: so_carr FOR wa_sflight-carrid.
SELECTION-SCREEN END OF BLOCK carr.
BEGIN OF
OF BLOCK
SELECTION-SCREEN BEGIN
BLOCK limit WITH FRAME TITLE text-001.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim,
pa_lim_2 RADIOBUTTON GROUP lim,
pa_lim_3 RADIOBUTTON GROUP lim.
END OF
OF BLOCK
SELECTION-SCREEN END
BLOCK limit.
...
 SAP AG 2003
You can use the SELECTION-SCREEN keyword to design the layout of the selection screen.
You can group screen elements that logically belong together with the extension BEGIN OF BLOCK
<block> and place a frame around them using WITH FRAME. Frames can be nested to a maximum
depth of five.
You can also assign a title to the block but only if you use a frame. The title can be declared as either
text-xxx or as a field name of up to eight characters. In the second case, you would set the text at runtime
in the INITIALIZATION event. Before designing a selection screen, you should become familiar with
the screen design guidelines shown in transaction BIBS.
(C) SAP AG
BC405
3-8
Designing the Selection Screen II
SELECTION-SCREEN:
BEGIN OF LINE
COMMENT pos(len) <text> [FOR FIELD <f>]
Output ...
POSITION pos
Seats ...
END OF LINE
REPORT sapbc405_sscd_sel_screen_ii.
...
* Parameters displayed in one line
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(20) text-s03.
SELECTION-SCREEN COMMENT pos_low(8) text-s04 FOR FIELD
pa_col.
PARAMETERS pa_col AS CHECKBOX.
SELECTION-SCREEN COMMENT pos_high(8) text-s05.
PARAMETERS pa_ico AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
 SAP AG 2002
You can display multiple parameters and comments on the same screen line. To do so, you must enclose
them between the SELECTION-SCREEN BEGIN OF LINE and SELECTION-SCREEN END OF
LINE statements. The COMMENT parameter enables you to include text in the line.
Comment texts must always have a format (position and output length). The position can be set using a
data field or pos_low or pos_high. These last two are the positions for SELECT-OPTIONS field low and
high on the selection screen.
Adding COMMENT ... FOR FIELD <f> ensures that the F1 Help for field <f> is displayed for the
comment text and for the parameter itself. If you hide the parameter (selection variant: attribute
invisible) the comment text is also hidden.
You can use POSITION <pos> to set the cursor for the next output position (only within ... BEGIN OF
LINE ... END OF LINE).
(C) SAP AG
BC405
3-9
Initializing the Selection Screen
INITIALIZATION.
REPORT
...
sapbc405_sscd_initialization.
INITIALIZATION.
INITIALIZATION.
MOVE:
mark TO
pa_all.
Airline
MOVE: 'I' TO so_carr-sign,
'BT' TO so_carr-option,
'AA' TO so_carr-low,
'LH' TO so_carr-high.
APPEND so_carr.
CLEAR so_carr.
MOVE: 'E' TO so_carr-sign,
'EQ' TO so_carr-option,
'DL' TO so_carr-low.
APPEND so_carr.
...
AA
Flight date
to
LH
to
Output ...
Seats ...
Occupied
Available
All
Selection
Colors
Icons
 SAP AG 2003
The INITIALIZATION and LOAD-OF-PROGRAM events are processed only once in an executable
program. You can supply default values for the selection screen fields of a report, as well as those for a
logical database, during this event. You can use F1 Help (Technical help) to determine the names of the
selection fields if a logical database is attached to the program.
The selection screen can also be supplied with values in the AT SELECTION-SCREEN OUTPUT
event. This event happens just before the selection screen is displayed.
(C) SAP AG
BC405
3-10
Input Checks: AT SELECTION-SCREEN
AT SELECTION-SCREEN
ON <f>
ON <seltab>
ON RADIOBUTTON GROUP <grp>
ON BLOCK <block>
REPORT sapbc405_sscd_at_sel_screen.
...
* Check of selection criterion SO_DEPT
AT SELECTION-SCREEN ON so_dept.
IF ( so_dept-low LT '060000' AND so_dept-high LT '060000' )
OR ( so_dept-low GE '220000' AND so_dept-high GE '220000' )
AND city_fr EQ 'FRANKFURT'.
MESSAGE e046(bc405).
ENDIF.
...
 SAP AG 2002
Validation of screen input can be done at the AT SELECTION-SCREEN event. If an error or warning
message is displayed during this event, all screen fields are made ready for input.
You can refer to individual selections with the parameters ON <f> or ON <seltab>. In case of errors,
only these selections are made input-ready again.
To check the entry combinations of a logical group, you can use the event AT SELECTION-SCREEN
ON BLOCK <block>. Fields in this block are made ready for input when an error message is issued.
The event AT SELECTION-SCREEN ON END OF <field> belongs to the PAI processing of the
selection screen for multiple selections.
You can perform entry checks for selection criteria of the logical database and for your own programspecific selections.
(C) SAP AG
BC405
3-11
General Help and Possible Entries Help (F1 and F4)
AT SELECTION-SCREEN
ON HELP-REQUEST FOR <seltab>
ON VALUE-REQUEST FOR <seltab>
REPORT
...
sapbc405_sscd_f1.
SELECT-OPTIONS: so_dept FOR spfli-deptime DEFAULT '080000' TO '220000'
NO-EXTENSION.
ON HELPHELP-REQUEST
...
* Help request for SO_DEPT (F1 help).
AT SELECTION-SCREEN ON HELP-REQUEST FOR so_dept.
CALL SCREEN 100 STARTING AT 30 03
ENDING
AT 70 10.
Abflugzeit
Enter the departure time
in this field.
 SAP AG 2003
You can program your own F1 (general help) and F4 (possible entries) at the events AT SELECTIONSCREEN ON HELP-REQUEST and AT SELECTION-SCREEN ON VALUE-REQUEST. Help
can refer to individual parameters or a selection table (seltab). When you enter the name of a SELECTOPTIONS table, you receive help for both seltab-low and seltab-high.
After positioning the cursor and using the F1 or F4 key, the system triggers the appropriate event.
The addition of ON VALUE-REQUEST displays the pushbutton for F4 help for the corresponding
field. The value selection is controlled by interactive events.
(C) SAP AG
BC405
3-12
CALL SELECTION-SCREEN
REPORT
sapbc405_sscd_call_sel_screen.
...
SELECTION-SCREEN:
BEGIN OF SCREEN 1100.
PARAMETERS: pa_cus AS CHECKBOX,
pa_agy AS CHECKBOX.
SELECTION-SCREEN:
END OF SCREEN 1100.
...
Selection screen: Screen 1000
AT SELECTION-SCREEN ON pa_add.
IF pa_add = mark.
CALL SELECTION-SCREEN 1100
START-OF-SELECTION.
STARTING AT 5 5 ENDING AT 50 10.
IF sy-subrc <> 0.
LEAVE TO SCREEN 1000.
ENDIF.
ENDIF.
Selection screen: Screen 1100
 SAP AG 2003
You can work with several selection screens in one program. The default selection screen always has the
screen number 1000. You can also define alternate selection screens with SELECTION-SCREEN
BEGIN OF SCREEN <nnnn> ... END OF SCREEN <nnnn>. Between the BEGIN ... END ...
statements, you declare the required selections with SELECT-OPTIONS and PARAMETERS. The
selection screen is called with CALL SELECTION-SCREEN <nnnn>.
The system takes care of the return from the selection screen, which means you do not have to program
it yourself with LEAVE SCREEN (as is the case with CALL SCREEN). The program continues with
the next statement following the call. The system field SY-SUBRC will equal zero if the user pressed
Execute or F8. If the User presses cancel or exit, SY-SUBRC contains a value of four.
You can supply the selection screen with default values at INITIALIZATION.
Use the system field SY-DYNNR in the selection screen events to determine which screen is being
processed.
(C) SAP AG
BC405
3-13
Selection Screen: Variants I
ABAP Editor
Program
...SSCD_VARIANTS
Subobjects
Variants
Display
change
For all selection
screens
Selection Screen
Save as
variant
For single
selection screens
DEMO ...SSCD_VARIANTS
 SAP AG 2002
Users can create any number of variants for a program. The variants are uniquely allocated to the
program and cannot be shared with other programs.
Creating variants makes sense when you frequently start a program with the same selection default
values.
If you select Start With Variant in the program attributes, the system forces the user to select a variant
when running the program.
If the program uses several selection screens, you can create a variant for all the selection screens or
individually for each selection screen.
Naming conventions and transporting variants
● SAP&xxx are supplied by SAP system
● CUS&xxx are created by customers (in client 000)
Variants that follow these naming conventions are client-independent and will automatically be
transported along with the report. If these naming conventions are not followed, an entry for a
request (task) must be added to the object list.
(C) SAP AG
BC405
3-14
Selection Screen: Variants II
Attributes
• Variant
•Only for background processing
•Protect variants
•Display only in catalog
•System variant (automatic transport)
• Field attributes
•Required field
•Deactivate SPA/GPA
•Save field without values
•Selection variable
•Hide TO field
•Hide field
•Protect field
 SAP AG 2002
You are required to assign a name and a description to each variant. By default, variants are available for
both online and background processing. You can also define a variant exclusively for use with
background processing.
You can protect the variant itself and the individual selection criteria and parameters against
unauthorized changes. If you select Display only in catalog, this variant will not be displayed in the
general value help (F4).
The type of a selection is determined in its declaration (type s for SELECT-OPTIONS and, type p for
PARAMETERS). If you select Selections protected, then the field(s) will not be ready for input. You
can use the hide attribute to suppress selection criteria and parameters on the screen, if required,
resulting in a less cluttered selection screen.
When you use selection variables, there are three basic ways of supplying your selections with values at
runtime:
●
From table TVARV (type T)
●
Date fields using dynamic date calculation (type D), such as today's date
●
User-specific variables (type B). (the selection must be declared with the MEMORY ID <pid>
addition).
(C) SAP AG
BC405
3-15
Selection Screen: Unit Summary
You are now able to:
Generate selection screens, supply them with default
values, and display them.
Execute input checks in the selection screen.
Create variants.
 SAP AG 2002
(C) SAP AG
BC405
3-16
Selection Screen Exercises
Unit: Selection Screen
Topic: Designing, initializing (optional) and
checking (optional) a selection screen
When you have completed these exercises, you will be able to:
1-1
•
Use the SELECT-OPTIONS statement
•
Use the PARAMETERS statement
•
Design a selection screen
•
Initialize and check (optional)
Copy or enhance your program Z##FOL1_..., or copy the sample solution,
SAPBC405_FOLS_1, to program Z##SSC1_... . Sample solution for exercise:
SAPBC405_SSCS_1.
Extend the selection screen with SELECT-OPTIONS for the connection number and
the flight date, as well as parameters for output control.
1-1-1 Extend the selection screen with a select options for the connection number and
the flight date.
1-1-2 Suppress the multiple selection option for the flight date.
1-1-3 Enclose the selections for the airline carrier ID and the connection number
within a frame that has a title.
Enclose the Group the flight date into a block. Create a frame with a title
around the block.
1-1-4 Maintain the selection texts for all selection screen fields.
1-2
Implement a group of parameters for output control
1-2-1 Create group of three radio buttons with the following functionality
•
all flights are read
•
domestic flights only are read
•
international flights only are read
The default setting should be for international flights.
1-2-2 Create an additional parameter for country code referencing
wa_flights_countryfr and require the user to enter a value if domestic flights is
selected.
(C) SAP AG
BC405
3-17
1-2-3 Create a frame without a title around the radio button set. Create a frame around
the complete display parameters and assign a title and selection texts. Arrange
the frames and texts as shown in the template.
1-3
Make sure that only the data records requested are read from the database.
1-3-1 To do this, supplement the WHERE clause of the SELECT statement with the
conditions that result from the selections.
1-3-2 Implement the logic for the radio button group.
Note: You need three separate SELECT statements with different WHERE
conditions. You can map the national/international condition directly on the
database:countryto = dv_flights~countryfr or countryto <>
dv_flights~countryfr. You use the tilde (~) to address the database field.
1-4
OPTIONAL
1-4-1 Initialize the selection table for the airline name such that the flights of airlines
AA through QF will be displayed, but not AZ.
1-4-2 Display error message 003 in message class BC405 if the user has selected
domestic flights and the input parameter for the country is initial. In case of
error, only the radio button group and the country parameter should be ready
for input.
(C) SAP AG
BC405
3-18
Selection Screen Solutions
Unit: Selection Screen
Topic: Designing, initializing (optional) and
checking (optional) a selection screen
*&---------------------------------------------------------------------*
*& Report
SAPBC405_SSCS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
Solution: Exercise 1; Selection Screen
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_sscs_1top.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE: / sy-vline,
'Flight data'(001),
AT line_size sy-vline.
ULINE.
* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
sy-vline, AT pos_c1 'Flight'(002).
* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE: 'Date'(003) ,
(C) SAP AG
BC405
3-19
'Departure location'(004),
'Arrival location'(005),
'Price'(006),
AT line_size sy-vline.
ULINE.
*********************************************************************
Optional parts: Initializing and checking a selection screen
*********************************************************************
*&---------------------------------------------------------------------*
*&
Event
INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
" OPTIONAL
* Initialize select-options for CARRID
MOVE:
'AA' TO so_car-low,
'QF' TO so_car-high,
'BT' TO so_car-option,
'I' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
MOVE:
'AZ' TO so_car-low
'EQ' TO so_car-option,
'E' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
*&---------------------------------------------------------------------*
*&
Event AT SELECTION-SCREEN ON BLOCK PARAM
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK param.
" OPTIONAL
* check country for national flights is not empty
CHECK national = 'X' AND country = space.
MESSAGE e003(bc405).
*&---------------------------------------------------------------------*
*&
Event START-OF-SELECTION
(C) SAP AG
BC405
3-20
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Checking the output parameters
CASE mark.
WHEN all.
* Radiobutton ALL is marked
SELECT * FROM dv_flights INTO TABLE it_flights
WHERE carrid IN so_car
AND connid IN so_con
AND fldate IN so_fdt.
WHEN national.
* Radiobutton NATIONAL is marked
SELECT * FROM dv_flights INTO TABLE it_flights
WHERE carrid IN so_car
AND connid IN so_con
AND fldate IN so_fdt
AND countryto = dv_flights~countryfr
AND countryto = country.
WHEN internat.
* Radiobutton INTERNAT is marked
SELECT * FROM dv_flights INTO TABLE it_flights
WHERE carrid IN so_car
AND connid IN so_con
AND fldate IN so_fdt
AND countryto <> dv_flights~countryfr.
ENDCASE.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
SORT it_flights BY carrid connid fldate.
* Data output
(C) SAP AG
BC405
3-21
PERFORM data_output.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Get a new page if CONNID has changed.
ON CHANGE OF wa_flights-connid.
NEW-PAGE.
ENDON.
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-cityfrom,
wa_flights-cityto,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
AT line_size sy-vline.
ENDLOOP.
ENDFORM.
(C) SAP AG
" DATA_OUTPUT
BC405
3-22
*&---------------------------------------------------------------------*
*& Include BC405_SSCS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT bc405_sscs_1top LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
* Constants for writing position
CONSTANTS
: pos_c1 TYPE i VALUE
6,
line_size TYPE i VALUE 100.
* Constant for CASE statement
CONSTANTS mark VALUE 'X'.
* Internal table like DDIC view DV_FLIGHTS
DATA:
it_flights LIKE TABLE OF dv_flights,
wa_flights LIKE dv_flights.
* Selections for connections
SELECTION-SCREEN BEGIN OF BLOCK conn
WITH FRAME TITLE text-tl1.
SELECT-OPTIONS:
so_car FOR wa_flights-carrid,
so_con FOR wa_flights-connid.
SELECTION-SCREEN END OF BLOCK conn.
* Selections for flights
SELECTION-SCREEN BEGIN OF BLOCK flight
WITH FRAME TITLE text-tl2.
SELECT-OPTIONS
so_fdt FOR wa_flights-fldate NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK flight.
* Output parameter
SELECTION-SCREEN BEGIN OF BLOCK param
(C) SAP AG
BC405
3-23
WITH FRAME TITLE text-tl3.
SELECTION-SCREEN BEGIN OF BLOCK radio WITH FRAME.
PARAMETERS:
all RADIOBUTTON GROUP rbg1,
national RADIOBUTTON GROUP rbg1,
internat RADIOBUTTON GROUP rbg1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK radio.
PARAMETERS country LIKE wa_flights-countryfr.
SELECTION-SCREEN END OF BLOCK param.
(C) SAP AG
BC405
3-24
Logical Database
Contents:
Advantages of using a logical database
Sub-objects of the logical database
Data retrieval with logical databases
 SAP AG 2002
(C) SAP AG
BC405
4-1
Logical Database: Objectives
At the conclusion of this unit, you will be able to:
Understand the advantages of using logical
databases.
Use logical databases.
Identify program-specific characteristics in a
logical database.
Read data with a logical database.
 SAP AG 2002
(C) SAP AG
BC405
4-2
Generating Lists
ABAP program
OPEN SQL
ABAP Program
GET <node>
Logical
database
ABAP program
NATIVE SQL
Database
 SAP AG 2002
In general, the system reads data that will appear in a list from the database.
You can use either OPEN SQL or NATIVE SQL statements to read data from the database. Native SQL
should be avoided in order to maintain portability from one RDBMS to another. In addition, Native SQL
would need to be recoded to take advantage of upgrades in the RDBMS. OPEN SQL has no such
limitations or requirements.
The use of a logical database program provides you with an excellent alternative to programming the
data retrieval yourself. Logical databases retrieve data records in primary key sequence and make them
available to ABAP programs.They also offer a security advantage since the authority checks are done in
the logical database program rather than in the report program.
(C) SAP AG
BC405
4-3
Advantages of a Logical Database
Program 1
Program 2
Query 1
Query 2
Query 3
Logical database
Program 4
Program 5
Program 3
- Provides a selection screen
- Provides input and authorization
checks
- Reads data records
QuickView 1
Query 4
QuickView 2
Program 6
 SAP AG 2003
The same logical database can be the data source for several QuickViews, queries, and reports. In the
QuickView, the logical database program (LDB) can be specified directly as a data source. A query
works with the logical database when the InfoSet that generated the query is defined with a logical
database. In the case of executable programs, the LDB is entered in the attributes or called using
function module LDB_PROCESS. See appendix for information on how to use the function module.
Logical databases offer several advantages over other methods of data retrieval:
The system generates a selection screen. The use of selection screen versions or variants provides the
required flexibility.
The programmer does not need to know the exact structure or relationship of the tables involved; the
data is made available to the application program in primary key sequence. Performance
improvements within logical databases directly affect all programs linked to the logical database
without having to change the programs themselves.
Maintenance and enhancements can be performed at a central location.
Authorization checks are done in the logical database program rather than in the application program.
(C) SAP AG
BC405
4-4
Logical Database: Overview
ABAP
ABAP Dictionary
Dictionary
Hierarchical view
SPFLI
SPFLI
F1S
F1S
SFLIGHT
SFLIGHT
SBOOK
SBOOK
 SAP AG 2002
A logical database is an ABAP program that reads data from the database and makes the data available
to other report programs.
A hierarchical structure determines the order in which the data is supplied to the programs. A logical
database also provides a selection screen that checks user entries and conducts error dialogs. You can
add your own parameters and select options.
The SAP system provides approximately 190 logical databases in Release 4.6. The names of logical
databases have been extended from three characters to 20 characters in Release 4.0 (namespace prefix
max. 10 characters).
If the logical database is three characters long, then the first two characters name the logical database
and the third character identifies the application area. A list of the values for the third character can be
displayed by looking at a program's attributes and then pressing F4 on the Application field. For
example, DDF is named for Debtor Data and the letter F represents financial data.
(C) SAP AG
BC405
4-5
Logical Database: F1S Nodes
SPFLI
SFLIGHT
SBOOK
Flight schedule
Flights
Flight booking
MANDT
MANDT
MANDT
CARRID
CARRID
CARRID
CONNID
CONNID
CONNID
FLDATE
FLDATE
PRICE
CURRENCY
PLANETYPE
SEATSMAX
SEATSOCC
PAYMENTSUM
BOOKID
COUNTRYFR
CITYFROM
AIRPFROM
COUNTRYTO
CITYTO
AIRPTO
FLTIME
DEPTIME
ARRTIME
DISTANCE
DISTID
FLTYPE
PERIOD
 SAP AG 2002
CUSTOMID
CUSTTYPE
SMOKER
LUGGWEIGHT
WUNIT
INVOICE
CLASS
FORCURAM
FORCURKEY
LOCCURAM
LOCCURKEY
ORDER_DATE
COUNTER
AGENCYNUM
CANCELLED
The demo programs and exercises for ABAP courses and ABAP documentation refer to the SAP
system's BC_TRAVEL flight data model, which is found in development class BC_DATAMODEL.
The following tables form the nodes of logical database F1S:
•SPFLI: Flight connections
•SFLIGHT: Flights
•SBOOK: Bookings
(C) SAP AG
BC405
4-6
Sample Program for a Logical Database
ABAP: Program Attributes
Logical database
F1S
Selection screen version
REPORT sapbc405_ldbd_simple_example.
NODES: spfli, sflight.
* Processing of SPFLI records
GET spfli FIELDS ... .
* Processing of SFLIGHT records
GET sflight FIELDS ... .
 SAP AG 2003
You must enter the logical database name in the program's attributes for an executable (type 1) program.
Use the keyword NODES <node> to specify the nodes of the logical database that you want to use in
the program. NODES allocates the appropriate storage space for the node (a work area or a table area
depending on the node type). Note that the keyword TABLES can still be used in release 4.6.
When the logical database reads the data records, it issues the statement PUT <node> which triggers the
GET event in the report program.
(C) SAP AG
BC405
4-7
LDB Sub-Objects: Structure
Name of node
SPFLI
SFLIGHT
SBOOK
Node type
Short text
Table
Timetable
Table
Flight table
Table
Bookings
Establishes a data hierarchy (read sequence)
Possible node types:
Database table
DDIC type
Data type
Dynamic type
Table or structure from the DDIC Name must be
identical to the node name.
DDIC type: Table or structure. Name can
differ from node name; deep structures
are possible.
Type that was defined in a type group.
Type is specified in program.
 SAP AG 2002
Logical databases are made up of several subobjects. The structure determines the hierarchy, and thus
the read sequence of the data records.
Node names can contain up to 14 characters. There are four different node types:
Table (type T): The node name is the name of a transparent table (this type corresponds to the concept
prior to Release 4.0A). The table name must be identical to the node name. Deep types (complex) are
not allowed.
DDIC type (type S): Any node name is possible. The node is assigned a structure or a table type from
the Dictionary. The node name can differ from the type name. Deep structures are possible.
Type groups (type C): The node type is defined in a type group. The name of the type group must be
maintained in the Type group field. You should generally prefer DDIC types since the other
applications that use the logical database (such as SAP Query) can access them (short texts, and so
on).
Dynamic nodes (type A): These nodes do not have a fixed type; they are not classified until the
program runtime. The types that are allowed are determined when the structure is created.
(C) SAP AG
BC405
4-8
Events in Logical Databases
REPORT
...
sapbc405_ldbd_events.
START-OF-SELECTION
1
START-OF-SELECTION
1
1
SPFLI
SPFLI
5
2
SFLIGHT
4
SBOOK SBOOK SBOOK
3
3
3
2 SFLIGHT
4
SBOOK SBOOK
3
3
END-OF-SELECTION
GET SPFLI
DL 1699
2
GET SFLIGHT
3
GET SBOOK
00002568
3
GET SBOOK
00002569
3
GET SBOOK
00002570
4
GET SFLIGHT LATE
2
GET SFLIGHT
3
GET SBOOK
00002590
3
GET SBOOK
00002591
4
GET SFLIGHT LATE
5
GET SPFLI LATE
1
GET SPFLI
25.02.2000
27.03.2000
DL 1984
END-OF-SELECTION
 SAP AG 2002
The START-OF-SELECTION event triggers before control is given to the read routine of the logical
database. The END-OF-SELECTION event triggers after all GET events have been processed (all data
records have been read and processed).
The GET <node> event triggers whenever the logical database supplies data for this node. This means
that GET events are processed several times, and that data has already been read from the database for
these events. The sequence in which the GET events are processed is determined by the structure of the
logical database.
The GET <node> LATE event triggers when all subordinate nodes of node <node> have been
processed, before the data is read for the next <node> (whenever a hierarchy level has been completed).
At the start of the event, the system automatically adds a line feed and sets the font and intensity to the
system defaults. If colors were set on in other events, they are reset as well.
(C) SAP AG
BC405
4-9
Program Flow and Termination Alternatives
Program Flow
START-OF-SELECTION
START-OF-SELECTION
Event Block Termination
CHECK
CHECK
STOP
STOP
Ends
event block.
Ends
event block.
END-OF
-SELECTION
is performed
EXIT
EXIT
GET
GET <node>
<node>
END-OF-SELECTION
END-OF-SELECTION
List
Display
Display list
 SAP AG 2002
The CHECK keyword ends the current processing block if the condition is false.
The STOP keyword ends program processing. However, in contrast to the EXIT statement, the
processing block END-OF-SELECTION processes first (if it exists).
If there is a STOP statement within the END-OF-SELECTION processing block, program processing
ends and the list buffer is displayed.
The EXIT statement exits the program but does not do the END-OF-SELECTION event. Any list buffer
created before the EXIT keyword is encountered will be displayed.
You can also use the REJECT statement. The data record does not process further. Processing continues
on the same hierarchy level when the next data record is read. REJECT can also be used within a
subroutine.
(C) SAP AG
BC405
4-10
LDB Sub-Objects: Selections
Selection include db<ldbname>sel:
Definition of selection screen
Default selection screen
Screen: 1000
SELECT-OPTIONS: ... .
PARAMETERS: ... FOR NODE <node>.
Enable field selection
Define a selection screen version
Allow dynamic selection
Fields are defined in dynamic selections using the
selection view:
Possible view origins are CUS and SAP.
 SAP AG 2003
Logical database programs have an include named db<name>sel in which the logical database selection
screen(s) are defined. The addition FOR NODE assigns selections to individual logical nodes. The
appearance of a selection screen directly depends on the NODES statement contained within your
program.
A field selection can be defined in the logical database program for the individual nodes. This is done
with the keyword FIELD SELECTION FOR NODE in the SELECTION-SCREEN statement. This
code in the logical database program allows the application program to use the GET <node> FIELD
<field list> to restrict the amount of data retrieved.
Some logical databases also designate dynamic selections for individual nodes. This is done by dynamic
selection using the addition DYNAMIC SELECTIONS FOR NODE. Dynamic selection button then
appears on your report's selection screen. You can determine which selection fields can be set by
choosing a particular selection view yourself (type: CUS) or by using the selection view delivered by the
SAP system (type: SAP)
Some large, logical databases have several selection screen versions. Each selection screen version
contains a subset of the selection criteria (language element: EXCLUDE). You can specify which
selection screen to display by entering the selection screen version number in the program attributes.
(C) SAP AG
BC405
4-11
Selection Screen for the Logical Database
Structure of F1S
REPORT sapbc405_ldbd_simple_example.
SPFLI
NODES: spfli,
spfli, sflight.
sflight.
NODES:
...
SFLIGHT
SBOOK
Selections for node SPFLI
Selections for node SFLIGHT
 SAP AG 2002
When you enter a logical database in the attributes of your type 1 program, the system processes the
selection screen of the logical database. The concrete characteristics of the selection screen depend upon
the node specified in the NODES statement. If you specify a node of type T (table), you can also declare
the table work area with the TABLES statement.
If you address only subordinate nodes (in the hierarchy) of the logical database in the program (for
example, SFLIGHT), the selection screen criteria for the superior node in the hierarchy (SPFLI) also
appears. You can thus restrict the dataset to be read so that it meets your specific requirements.
Note: A logical database always reads in accordance with its structure. This means that if you only
need data from a node deep in the hierarchy, you should either find a different logical database where the
desired node is higher in the structure or program the data retrieval yourself.
(C) SAP AG
BC405
4-12
Logical Database: Dynamic Selections
Dynamic Selections
Airline carrier
to
Dynamic Selections
Special information
Connection number
 SAP AG 2003
If the logical database supports dynamic selections, Dynamic selections appears on the selection screen.
When the user selects Dynamic selections, a second selection screen is displayed. This screen allows the
user to select additional database fields. The system transfers the selections directly to the logical
database program and to the database (dynamic selections).
The selection view determines which fields are displayed on the selection screen. Create your own view
with type CUS, and have it override the view with type SAP.
(C) SAP AG
BC405
4-13
LDB Sub-Objects: Database Programs
Naming convention sapdb<
sapdb<ldbname>
ldbname>
Database accesses, input checks, and authorization checks
sapdb<ldbname>
FORM
FORM init.
...
ENDFORM init.
ENDFORM
FORM
FORM put_spfli.
...
ENDFORM put_spfli.
ENDFORM
FORM
FORM put_sflight.
...
ENDFORM put_sflight.
ENDFORM
 SAP AG 2002
The logical database programs are named SAPDB<ldbname> for logical database <ldbname> .The
programs are a collection of subroutines, each of which is performed for specific events. For example,
subroutine <init> is processed once at the start of the database program. This program can define default
values for the selection screen of the LDB.
Other subroutines also exist that are processed during events PBO (Process Before Output) and PAI
(Process After Input) of the selection screen. Checks, such as authorization checks (AUTHORITYCHECK), are usually performed during event PAI.
The database accesses (SELECT statements) are programmed in the put_<node> subroutines. These
subroutines may be processed several times, depending on which selection criteria the user specifies.
The sequence in which these subroutines are processed is determined by the structure of the logical
database.
(C) SAP AG
BC405
4-14
Interaction: LDB and Program
Structure
Structure of
of F1S
F1S
PROGRAM SAPDBF1S
DEFINING DATABASE F1S.
...
FORM PUT_SPFLI.
SELECT * FROM SPFLI ...
PUT
PUT SPFLI.
SPFLI.
ENDSELECT.
ENDFORM.
SPFLI
SFLIGHT
SBOOK
FORM PUT_SFLIGHT.
SELECT * FROM SFLIGHT .
PUT SFLIGHT.
SFLIGHT.
PUT
ENDSELECT.
ENDFORM.
FORM PUT_SBOOK.
SELECT * FROM SBOOK ...
PUT SBOOK.
SBOOK.
PUT
ENDSELECT.
ENDFORM.
REPORT sapbc405_ldbd_ldb.
NODES: spfli, sflight, sbook.
* Processing of SPFLI records
GET SPFLI FIELDS ...
Data
Data processing
processing
* Processing of SFLIGHT records
GET SFLIGHT FIELDS ...
Data
Data processing
processing
* Processing of SBOOK records
GET SBOOK FIELDS ...
Data
Data processing
processing
 SAP AG 2002
When a report program that uses a logical database is started, control is initially passed to the database
program of the logical database. Each event has a corresponding subroutine in the database program (for
example, subroutine init for event INITIALIZATION). During the interaction between the LDB and
the associated report, the subroutine is always processed first, followed by the event (if there is one in
the report).
Logical database programs read data from a database according to the structure declared for the logical
database. They begin with the root node and then process the individual branches consecutively from top
to bottom.
The logical database reads the data in the PUT_<NODE> subroutines. During event PUT, control passes
from the database program to the GET event of the associated report. The data is made available in the
corresponding work areas in the report. The processing block defined for the GET event is performed.
Control then returns to the logical database. PUT activates the next form subroutine found in the
structure. This flow continues until the report collects all the available data.
The depth of data read in the structure depends upon a program's GET events. A logical database reads
to the lowest GET event contained within the structure attributes. Only those GET events for which
processing is supposed to take place are written into the report program. Logical databases read all data
records found on the direct access path.
(C) SAP AG
BC405
4-15
Checking Internal Program Selections
Are dynamic selections
allowed in this table?
LDB selections
Dep. time
Price
REPORT
08:00:00
23:00:00
SPFLI
YES
500.00
1000.00
SFLIGHT
NO
sapbc405_ldbd_check_sel.
NODES: spfli, sflight, sbook.
SELECT-OPTIONS:
SELECT-OPTIONS: sdepart FOR spfli-deptime
SELECT
DEFAULT '08000' TO '230000',
sprice FOR sflight-price
DEFAULT '500' TO '1000'.
GET spfli FIELDS ...
GET sflight FIELDS fldate price currency.
* check of selection criteria sprice
CHECK sprice.
sprice.
CHECK
.
sprice
...
GET sbook FIELDS ...
CHECK <seltab>.
SFLIGHT
SBOOK
 SAP AG 2002
SFLIGHT
SBOOK
Negative
CHECK
Positive
CHECK
If you specify a logical database and declare additional selections in the program attributes that refer to
the fields of a node not designated for dynamic selection, you must use the CHECK <seltab> statement
to see if the current data record fulfills the selection criteria.
If the data record does not fulfill these selection criteria, current event block processing ends.
(C) SAP AG
BC405
4-16
Logical Database: Unit Summary
You are now able to:
Understand the advantages of using logical
databases.
Use logical databases.
Identify program-specific characteristics in a
logical database.
Read data with a logical database.
 SAP AG 2002
(C) SAP AG
BC405
4-17
Logical Database Exercises
Unit: Logical Databases
Topic: GET Events
When you have completed these exercises, you will be able to:
• Create a list with data read from a logical database.
1-1
Create program Z##LDB1_... with TOP include (Z##LDB1_...TOP) and enter logical
database F1S in the program attributes. Make sure you specify Executable program as
the program type. To do this, you must change the program type. Sample solution for
exercise: SAPBC405_LDBS_1.
1-1-1 The logical database should supply the program with data for nodes SPFLI,
SFLIGHT, and SBOOK.
1-1-2 Create a list that displays the following data:
Table SPFLI: CARRID, CONNID, CITYFROM, AIRPFROM, CITYTO,
AIRPTO.
Table SFLIGHT: FLDATE, PRICE, CURRENCY, PLANETYPE,
SEATSMAX, SEATSOCC,FREE_SEATS.
Table SBOOK: BOOKID, CUSTOMID, SMOKER, LUGGWEIGHT,
WUNIT.
Field FREE_SEATS is not a table field – it has to be calculated in the
program. The price and luggage weight should be output with the appropriate
units.
1-1-3 Create a list in which each line outputs the information for one node (see
above).
1-1-4 The list should have 83 columns. Maintain the column headers (standard list
header).
1-1-5 Format the list (optional)
Output the first line in color COL_HEADING not intensified, the second line
in COL_NORMAL intensified, and the third line in COL_NORMAL not
intensified. Buffer the list.
Note:
(C) SAP AG
To output the fields, use the pattern functions available in the ABAP Editor.
BC405
4-18
Exercises
Unit: Logical Databases
Topic: GET LATE Events and Checks from Internal
Program Selections
When you have completed these exercises, you will be able to:
• Create a list with data read from a logical database.
• Check internal selections for their validity
2-1
Extend program Z##LDB1_... or copy the sample program SAPBC405_LDBS_1 to
program Z##LDB2_... . Sample solution for exercise: SAPBC405_LDBS_2.
2-1-1 Add a SELECT-OPTIONS statement for the posting date (SBOOKCUSTOMID) to the selection screen. Frame the selection and maintain the
selection text.
2-1-2 Make sure that only bookings that meet the specified selection criteria are
output in the list. Include the booking date in the list output.
2-1-3 Maintain the column header (standard list header). In the list, output a solid line
when all the bookings for a date have been output and when a flight has been
completely output. Display each flight on a new page.
(C) SAP AG
BC405
4-19
Logical Database Solutions
Unit: Logical Databases
Topic: GET Events
*&---------------------------------------------------------------------*
*& Report
SAPBC405_LDBS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_ldbs_1top.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI
*&---------------------------------------------------------------------*
GET spfli.
* Data output SPFLI
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
/ sy-vline, spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-airpfrom,
spfli-cityto,
spfli-airpto,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT
*&---------------------------------------------------------------------*
GET sflight.
* Calculate free seats
free_seats = sflight-seatsmax - sflight-seatsocc.
(C) SAP AG
BC405
4-20
* Data output SFLIGHT
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
WRITE: / sy-vline, sflight-fldate,
sflight-price CURRENCY sflight-currency,
sflight-currency,
sflight-planetype,
sflight-seatsmax,
sflight-seatsocc,
free_seats,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SBOOK
*&---------------------------------------------------------------------*
GET sbook.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: / sy-vline, sbook-bookid,
sbook-customid,
sbook-smoker,
sbook-luggweight UNIT sbook-wunit,
sbook-wunit, AT line_size sy-vline.
*&---------------------------------------------------------------------*
*& Include BC405_LDBS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
sapbc405_ldbs_1 LINE-SIZE 83.
* Used nodes of the structure of the logical database F1S
NODES: spfli, sflight, sbook.
* Variables
DATA: free_seats LIKE sflight-seatsocc.
* Constants
CONSTANTS: line_size LIKE sy-linsz VALUE 83.
(C) SAP AG
BC405
4-21
Logical Database Solutions
Unit: Logical Databases
Topic: GET LATE Events and Checks from Internal
Program Selections
*&---------------------------------------------------------------------*
*& Report
SAPBC405_LDBS_2
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_ldbs_2top.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI
*&---------------------------------------------------------------------*
GET spfli.
* Data output SPFLI
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
/ sy-vline, spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-airpfrom,
spfli-cityto,
spfli-airpto,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT
*&---------------------------------------------------------------------*
GET sflight.
* Calculate free seats
(C) SAP AG
BC405
4-22
free_seats = sflight-seatsmax - sflight-seatsocc.
* Data output SFLIGHT
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
WRITE: / sy-vline, sflight-fldate,
sflight-price CURRENCY sflight-currency,
sflight-currency,
sflight-planetype,
sflight-seatsmax,
sflight-seatsocc,
free_seats,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SBOOK
*&---------------------------------------------------------------------*
GET sbook.
* Check select-option
CHECK so_cust.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: / sy-vline, sbook-bookid,
sbook-customid,
sbook-smoker,
sbook-luggweight UNIT sbook-wunit,
sbook-wunit,
sbook-order_date,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI LATE
*&---------------------------------------------------------------------*
GET spfli LATE.
ULINE.
NEW-PAGE.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT LATE
(C) SAP AG
BC405
4-23
*&---------------------------------------------------------------------*
GET sflight LATE.
ULINE.
*&---------------------------------------------------------------------*
*& Include BC405_LDBS_2TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
sapbc405_ldbs_2 LINE-SIZE 83.
* Used nodes of the structure of the logical database F1S
NODES: spfli, sflight, sbook.
* Additional selections
SELECTION-SCREEN BEGIN OF BLOCK order WITH FRAME.
SELECT-OPTIONS: so_cust FOR sbook-customid.
SELECTION-SCREEN END OF BLOCK order.
* Variables
DATA: free_seats LIKE sflight-seatsocc.
* Constants
CONSTANTS: line_size LIKE sy-linsz VALUE 83.
(C) SAP AG
BC405
4-24
Programming Data Retrieval
Contents:
Read data from multiple transparent tables.
Evaluate the best technique for optimal performance.
 SAP AG 2002
(C) SAP AG
BC405
5-1
Data Retrieval: Objectives
At the conclusion of this unit, you will be able to:
Implement database read accesses across multiple
tables.
Rate the different techniques with regard to optimized
performance.
 SAP AG 2002
(C) SAP AG
BC405
5-2
Data Retrieval: Overview
ABAP program
GET
PUT
Open SQL
Native SQL
Logical Database
Database
 SAP AG 2003
Programming database access directly into the program itself can be done using either Open SQL or
Native SQL statements.
Open SQL is preferable to Native SQL since it is not database specific and guarantees that your program
is independent of the database engine. Use of Open SQL allows for portability between different
RDMBS systems or should your company change to a different database system. ABAP Open SQL is
completely integrated in to the Workbench which provides syntax checking of SQL statements. ABAP
Open SQL also allows the R/3 System to make use of data buffers where appropriate.
Native SQL statements are bound into a program using:
EXEC SQL [PERFORMING <form>].
<Native SQL statements>.
ENDEXEC
Do NOT use Native SQL to change the R/3 System database. The referential integrity of the R/3 System
data is maintained by the R/3 System programs. Using Native SQL can quite easily corrupt your data. If
you must use Native SQL, consider putting the code in an include so that it can be modified more easily
if your RDBMS changes. Restrict your Native SQL to Standard SQL (ISO9075:1992)
(C) SAP AG
BC405
5-3
Reading Multiple Database Tables
Database
Database View
View in the ABAP Dictionary
INNER
INNER JOIN,
JOIN, OUTER
OUTER JOIN
JOIN
FOR
FOR ALL
ALL ENTRIES
ENTRIES
Nested
Nested SELECT
SELECT Statements
Statements
 SAP AG 2003
To ensure optimal database performance, follow these general rules:
• Keep the amount of selected data as small as possible (use WHERE conditions, for example).
• Keep data transfer between the application server and the database to a minimum (use field lists, for
example).
• Reduce the number of database inquiries (use table joins instead of nested SELECT statements, for
example).
• Reduce search size (this optimizes access to the database).
Minimize database server load (use SAP buffers, for example).
(C) SAP AG
BC405
5-4
Reading Multiple Database Tables I
Database
Database View
View in
in the
the ABAP
ABAP Dictionary
Dictionary
REPORT sapbc405_gdad_db_view.
...
SELECT carrid carrname connid
cityfrom cityto fldate
seatsmax seatsocc
INTO TABLE itab_flights
sv_flights
FROM sv_flights
sv_flights
WHERE cityfrom IN so_cityf
AND cityto IN so_cityt
AND seatsocc < sv_flights~seatsmax
ORDER BY carrid connid fldate.
...
Dictionary: Database view sv_flights
Table
Join conditions
View fields
 SAP AG 2002
You can create database views in the ABAP Dictionary. Views are typically application specific and
allow you to work with multiple database tables. Database views are realized on the database as an
INNER JOIN.
From Release 4.0, forward, you can buffer database views. You can then read from views using the SAP
System buffer on the relevant application server. The same rules apply when buffering views as when
buffering tables.
Database view advantages:
Central maintenance
Accessible to all users
Only one SELECT statement is required in the program
One disadvantage of the view is its low flexibility.
(C) SAP AG
BC405
5-5
Reading Multiple Database Tables IIA
INNER
INNER JOIN
JOIN
REPORT sapbc405_gdad_inner_join_2tab.
...
SELECT spfli~carrid spfli~connid
spfli~cityfrom spfli~cityto
sflight~fldate sflight~seatsmax
sflight~seatsocc
INTO TABLE itab_flights
FROM spfli INNER JOIN
JOIN sflight
ON
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
WHERE spfli~carrid IN so_carr
AND spfli~connid IN so_conn.
...
INNER JOIN
A
B
C
A
B
D
a1
b1
c1
a1
b1
d1
a2
b2
c2
a3
b2
d2
a3
b3
c3
a3
b3
d3
A
B
C
D
a1
b1
c1
d1
a3
b3
c3
d3
 SAP AG 2003
To map the resulting set of a join, the database transparent tables are combined to form one results table.
The join conditions are applied to this results table. The resulting composite for inner join logic contains
only those records for which matching records exist in each transparent table.
Join conditions are not limited to key fields. They can be declared using any fields that have a foreign
key relationship defined or, in certain cases, between fields that share a common domain.
If columns from two tables have the same name, you have to ensure that the field labels are unique by
prefixing the table name or alias name.
A table join is generally an efficient way to read from the database. The database is responsible for
deciding which table is read first and which index is used.
(C) SAP AG
BC405
5-6
Reading Multiple Database Tables IIB
OUTER
OUTER JOIN
JOIN
REPORT sapbc405_gdad_outer_join.
...
SELECT scarr~carrid scarr~carrname
spfli~connid spfli~cityfrom
spfli~cityto
INTO TABLE itab_flights
FROM scarr LEFT outer
OUTER JOIN spfli
ON
ON scarr~carrid = spfli~carrid
ORDER BY scarr~carrid spfli~connid.
...
LEFT OUTER JOIN
A
B
C
A
D
E
a1
b1
c1
a1
d1
e1
a2
b2
c2
a3
d2
e2
a3
b3
c3
a3
d3
e3
A
B
C
D
E
a1
b1
c1
d1
e1
a2
b2
c2
a3
b3
c3
d2
e2
a3
b3
c3
d3
e3
 SAP AG 2002
At LEFT OUTER JOIN, results tables can also contain entries from the designated left-hand table
without the presence of corresponding data records (join conditions) from the table on the right. These
table fields are filled by the database with null values. However, the null values are initialized according
to ABAP type before being presented to your program.
It makes sense to use a LEFT OUTER JOIN when data from the table on the left is needed and there
are no corresponding entries in the table on the right. For example: sapbc405_gdad_outer_join: not all
airlines (table scarr) have flights listed (table spfli), but all airline names are supposed to be displayed in
the list.
The following limitations apply for the Left Outer Join:
You can only have a table or a view to the right of the JOIN operator, you cannot have another join
statement.
Only AND can be used as a logical operator in an ON condition.
Every comparison in the ON condition must contain a field from the table on the right.
If the FROM clause contains an Outer Join, then all ON conditions must contain at least one true
JOIN condition (a condition that contains a field from tab1 and a field from tab2).
(C) SAP AG
BC405
5-7
Reading Multiple Database Tables III
FOR
FOR ALL
ALL ENTRIES
ENTRIES
REPORT sapbc405_gdad_for_all_entries.
... .
SELECT carrid connid ...
INTO TABLE itab_spfli FROM spfli
WHERE .... .
itab_spli
LH
0400
...
LH
0402
...
* Check, if at least one dataset is found
EXIT.ENDIF.
ENDIF.
IFIFsy-subrc nene0.0.EXIT.
sysy-subrc
Conversion
where (
carrid = 'LH'
and connid = '0400')
* Delete Duplicates
SORT itab_
itab_spfli.
spfli.
DELETE ADJACENT DUPLICATES FROM itab_
itab_spfli
or
or
(
carrid = 'LH'
and connid = '0402')
(...
SELECT carrid connid fldate ...
INTO TABLE itab_sflight FROM sflight
FOR ALL
ALL ENTRIES
ENTRIES IN
IN itab_spfli
FOR
WHERE carrid = itab_spfli-carrid
AND
connid = itab_spfli-connid.
.... .
 SAP AG 2002
FOR ALL ENTRIES works with the database in a quantity-oriented manner. Initially, all data is
collected in an internal table. You must evaluate the value of SY-SUBRC after each SELECT statement.
If the result of the first array fetch returns no data, the following SELECT statements will retrieve all
entries from the database.
SELECT...FOR ALL ENTRIES IN <itab> is treated like a SELECT statement with an external OR
condition (depending on the optimizer and profile parameters). The system only selects those table
entries that meet the logical condition (WHERE carrid = itab_sflight-carrid), replacing the
placeholders (itab_spfli-carrid) with values from each entry in the internal table itab_spfli. Note that
itab_spfli-carrid is a placeholder, and not a component of the internal table. Duplicates are not allowed.
The internal table can, in principle, be as large as you want it to be.
Using FOR ALL ENTRIES is one way to approximate an SQL join or a database view. The join and
the view will typically yield significantly better performance than FOR ALL ENTRIES.
(C) SAP AG
BC405
5-8
Reading Multiple Database Tables IV
Nested
Nested SELECT
SELECT Statements
Statements
REPORT sapbc405_gdad_nested_selects.
... .
SELECT
SELECT carrid connid cityfrom ...
INTO wa_spfli FROM spfli
WHERE cityfrom IN so_cityf
AND
cityto
IN so_cityt.
APPEND wa_spfli TO itab_spfli.
SELECT
SELECT carrid connid fldate ...
INTO wa_sflight FROM sflight
WHERE carrid = wa_spfli-carrid
AND
connid = wa_spfli-connid.
APPEND wa_sflight TO itab_sflight.
SELECT carrid connid fldate bookid ...
SELECT
INTO wa_sbook FROM sbook
WHERE carrid = wa_sflight-carrid
AND
connid = wa_sflight-connid
AND
fldate = wa_sflight-fldate.
APPEND wa_sbook TO itab_sbook.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
... .
 SAP AG 2003
Another method for reading related tables is to use nested SELECT statements. This technique should be
avoided and used only as a last resort when no other data retrieval method is possible. The biggest
disadvantage of the nested SELECT is that the inner SELECT is executed for each record retrieved by
the outer SELECT. This leads to very poor performance in client/server environments.
From Release 4.0, forward, you can also work with subqueries. Refer to the online documentationfor
more information.
(C) SAP AG
BC405
5-9
Programming Data Retrieval: Summary
You are now able to:
Implement database read accesses across multiple
tables.
Rate the different techniques with regard to optimized
performance.
 SAP AG 2002
(C) SAP AG
BC405
5-10
Programming Data Retrieval Exercises
Unit: Programming Data Retrieval
Topic: Inner Join
When you have completed these exercises, you will be able to:
• Use an ABAP join to read data from several different DB
tables.
1-1
Copy or enhance your program Z##SSC1_..., or copy the sample solution,
SAPBC405_SSCS_1, to program Z##GDA1_... . Sample solution for exercise:
SAPBC405_GDAS_1.
1-1-1 Replace the data collected through database view dv_flights with an internal
INNER JOIN performed on the database.
1-2
Deactivate (mark with an asterix (*)) the three SELECT statements at START-OFSELECTION. Program INNER JOINs that fill internal table it_flights with data from
tables SPFLI and SFLIGHT in the database.
Note:
The structure of the internal table it_flights does not correspond exactly to the
combination of tables SPFLI and SFLIGHT. You must ensure that the fields are
copied to the fields of the same name in the target table.
(C) SAP AG
BC405
5-11
Programming Data Retrieval Solutions
Unit: Programming Data Retrieval
Topic: Inner Join
*&---------------------------------------------------------------------*
*& Report
SAPBC405_GDAS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
Solution: Exercise 1, Internal Data Collection
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_gdas_1top.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE: / sy-vline,
'Flight data'(001),
AT line_size sy-vline.
ULINE.
* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
sy-vline, AT pos_c1 'Flight'(002).
* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE: 'Date'(003) ,
(C) SAP AG
BC405
5-12
'Departure location'(004),
'Arrival location'(005),
'Price'(006),
AT line_size sy-vline.
ULINE.
*&---------------------------------------------------------------------*
*&
Event
INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
" OPTIONAL
* Initialize select-options for CARRID
MOVE: 'AA' TO so_car-low,
'QF' TO so_car-high,
'BT' TO so_car-option,
'I' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
MOVE: 'AZ' TO so_car-low,
'EQ' TO so_car-option,
'E' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
*&---------------------------------------------------------------------*
*&
Event AT SELECTION-SCREEN ON BLOCK PARAM
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK param.
" OPTIONAL
* check country for national flights is not empty
CHECK national = 'X' AND country = space.
MESSAGE e003(bc405).
*&---------------------------------------------------------------------*
*&
Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
(C) SAP AG
BC405
5-13
* Checking the output parameters
CASE mark.
WHEN all.
* Radiobutton ALL is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt.
SORT it_flights BY carrid connid fldate.
WHEN national.
* Radiobutton NATIONAL is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr = spfli~countryto
AND spfli~countryfr = country.
SORT it_flights BY carrid connid fldate.
WHEN internat.
* Radiobutton INTERNAT is marked
SELECT * FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr NE spfli~countryto.
(C) SAP AG
BC405
5-14
SORT it_flights BY carrid connid fldate.
ENDCASE.
* Additional solution: dynamical WHERE condition
* PERFORM get_data.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
* Data output
PERFORM data_output.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Get a new page if CONNID has changed.
ON CHANGE OF wa_flights-connid.
NEW-PAGE.
ENDON.
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
(C) SAP AG
BC405
5-15
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-cityfrom,
wa_flights-cityto,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
AT line_size sy-vline.
ENDLOOP.
ENDFORM.
" DATA_OUTPUT
*
<--------------
ADDITIONAL -------------->
*
*&---------------------------------------------------------------------*
*&
Form
GET_DATA
*&---------------------------------------------------------------------*
* Instead of programming three different SELECT statements, these
* SELECTs can be combined in one dynamical WHERE condition.
**---------------------------------------------------------------------*
*FORM GET_DATA.
"#EC CALLED
*
*
DATA: WHERE_LINE(40),
*
WHERE_TAB LIKE TABLE OF WHERE_LINE.
*
** only national flights requested
*
IF NATIONAL NE SPACE.
*
WHERE_LINE = 'p~countryfr = p~countryto'.
*
APPEND WHERE_LINE TO WHERE_TAB.
*
CONCATENATE 'AND p~countryfr ='
*
'''' INTO WHERE_LINE
*
SEPARATED BY SPACE.
"#EC NOTEXT
"#EC NOTEXT
*
CONCATENATE WHERE_LINE COUNTRY '''' INTO WHERE_LINE.
*
APPEND WHERE_LINE TO WHERE_TAB.
*
ENDIF.
*
(C) SAP AG
BC405
5-16
** only international flights requested
*
IF INTERNAT NE SPACE.
*
WHERE_LINE = 'p~countryfr NE p~countryto'.
*
APPEND WHERE_LINE TO WHERE_TAB.
*
"#EC NOTEXT
ENDIF.
*
** Close WHERE-clause by dot
*
*
WHERE_LINE = '.'.
APPEND WHERE_LINE TO WHERE_TAB.
*
** Inner join with dynamical where clause
*
SELECT P~CARRID P~CONNID
*
P~COUNTRYFR P~CITYFROM P~AIRPFROM
*
P~COUNTRYTO P~CITYTO P~AIRPTO
*
F~FLDATE F~PRICE F~CURRENCY
*
FROM SPFLI AS P JOIN SFLIGHT AS F
*
ON P~CARRID = F~CARRID AND P~CONNID = F~CONNID
*
INTO CORRESPONDING FIELDS OF TABLE IT_FLIGHTS
*
WHERE P~CARRID IN SO_CAR
*
AND P~CONNID IN SO_CON
*
AND F~FLDATE IN SO_FDT
*
AND (WHERE_TAB).
*
*ENDFORM.
" GET_DATA
*&---------------------------------------------------------------------*
*& Include BC405_GDAS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
sapbc405_gdas_1 LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
* Constants for writing position
CONSTANTS:
pos_c1 TYPE i VALUE
6,
line_size TYPE i VALUE 100.
* Constant for CASE statement
(C) SAP AG
BC405
5-17
CONSTANTS mark VALUE 'X'.
* Internal table like DDIC view DV_FLIGHTS
DATA: it_flights LIKE TABLE OF dv_flights,
wa_flights LIKE dv_flights.
* Selections for connections
SELECTION-SCREEN BEGIN OF BLOCK conn WITH FRAME TITLE text-tl1.
SELECT-OPTIONS: so_car FOR wa_flights-carrid,
so_con FOR wa_flights-connid.
SELECTION-SCREEN END OF BLOCK conn.
* Selections for flights
SELECTION-SCREEN BEGIN OF BLOCK flight WITH FRAME TITLE text-tl2.
SELECT-OPTIONS so_fdt FOR wa_flights-fldate NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK flight.
* Output parameter
SELECTION-SCREEN BEGIN OF BLOCK param WITH FRAME TITLE text-tl3.
SELECTION-SCREEN BEGIN OF BLOCK radio WITH FRAME.
PARAMETERS: all RADIOBUTTON GROUP rbg1,
national RADIOBUTTON GROUP rbg1,
internat RADIOBUTTON GROUP rbg1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK radio.
PARAMETERS country LIKE wa_flights-countryfr.
SELECTION-SCREEN END OF BLOCK param.
(C) SAP AG
BC405
5-18
Data Formatting and Control Level Processing
Contents:
Control Level Processing
With Internal Tables
With Extract Datasets
 SAP AG 2002
(C) SAP AG
BC405
6-1
Data Formatting and Control Level Processing:
Unit Objectives
At the conclusion of this unit, you will be able to:
Format data with internal tables.
Use control level processing with internal tables
and extract datasets.
 SAP AG 2002
(C) SAP AG
BC405
6-2
Control Level Processing
Data sets in an internal table
From:
To:
Flight no.
Frankfurt
Berlin
2402
2436
Frankfurt
Berlin
2402
Frankfurt
Berlin
2436
Frankfurt
New York
0026
0026
Frankfurt
New York
0400
Frankfurt
New York
0402
0400
0402
Frankfurt
San Francisco 0454
HongKong
Singapore
0863
New York
San Francisco
0454
Hong Kong
Singapore
 SAP AG 2003
You can use control level processing to create structured lists. The data can then be group indicated to
create a better list layout.
The data to be displayed must be stored in an internal table and sorted in ascending sequence. You can
also use an extract dataset for the same purpose. Both the internal table and the extract dataset offer
distinct advantages.
(C) SAP AG
BC405
6-3
Creating an Internal Table
TYPES: BEGIN OF <linetype>,
...
END OF <linetype>.
DATA
<itab> TYPE STANDARD TABLE OF <linetype>.
REPORT
sapbc405dapd_a_internal_tables.
TYPES:
struct_
struct_conn,
conn,
BEGIN OF struct_conn,
cityfrom LIKE spfli-cityfrom,
cityto
LIKE spfli-cityto,
carrid
LIKE spfli-carrid,
deptime LIKE spfli-deptime,
arrtime LIKE spfli-arrtime,
END OF struct_conn.
struct_
struct_conn.
conn.
DATA:
TYPE STANDARD
STANDARD TABLE
TABLE OF
OF struct_conn,
itab_conn TYPE
wa_conn TYPE struct_conn.
 SAP AG 2002
From Release 4.0 forward, the R/3 System has included three types of tables: Standard tables
(STANDARD TABLE), sorted tables (SORTED TABLE), and hashed tables (HASHED TABLE).
See the online documentation for information on the complete syntax of internal tables.
(C) SAP AG
BC405
6-4
Filling an Internal Table
SELECT f1 f2 f3… FROM <dbtab> INTO TABLE <itab>.
DL
DL
LH
LH
1699
1984
0400
0402
2,367
1,933
4,437
3,093
APPEND <wa> TO <itab>.
COLLECT <wa> INTO <itab>.
CARR CONN SEATSOCC
CARR CONN SEATSOCC
LH
0400
3,000
DL
DL
LH
LH
1699
1984
0400
0402
2,367
1,933
4,437
3,093
<wa>
LH
0400
3,000
<itab>
DL
DL
LH
LH
1699
1984
0400
0402
2,367
1,933
4,437
3,093
7,437
 SAP AG 2003
You can use an array fetch in a SELECT statement to fill an internal table using the syntax SELECT
carrid connid price currency INTO TABLE itab_sflight.
You can use the APPEND statement to insert table entries at the end of an internal table. The variant of
the APPEND statement on the graphic is permitted only for standard or sorted tables. After an
APPEND statement, the system field SY-TABIX contains the index value of the newly inserted table
entry.
You can use the COLLECT statement to create a unique or compressed set of data. The system searches
the table for an existing row that matches the character field(s) in the work area. If a match is found, the
numeric values in the work area are added to the existing row's values. If no matching row is found, the
work area is added as a new row in the table. When the COLLECT statement is used, all the fields that
are not part of the key must be numeric.
The internal table must have at lease one character field and at least one numeric field.
(C) SAP AG
BC405
6-5
Sorting and Processing an Internal Table
LOOP AT <itab> [INTO <wa>].
...
ENDLOOP.
SORT <itab> [BY <f1> <f2> ...]
[ASCENDING | DESCENDING].
REPORT sapbc405dapd_a_internal_tables.
...
DATA: itab_conn TYPE STANDARD TABLE OFstruct_conn,
wa_conn TYPE struct_conn.
GET spfli FIELDS cityfrom cityto deptime arrtime.
MOVE-CORRESPONDING spfli TO wa_conn.
APPEND wa_conn TO itab_conn.
END-OF-SELECTION.
SORT itab_conn BY cityfrom cityto carrid deptime.
LOOP AT itab_conn INTO wa_conn.
WRITE: / wa_conn-cityfrom, wa_conn-cityto, wa_conn-carrid,
51 wa_conn-deptime, 65 wa_conn-arrtime.
ENDLOOP.
 SAP AG 2003
The SORT statement sorts the table entries in ascending order. If the table type is STANDARD or
HASHED and the addition BY<f1> is missing, the keys defined for table would be used for the sort
sequence. Note that table type SORTED cannot be sorted into a different sequence.
If addition BY <f1> <f2> ... is used, then fields <f1>, <f2> ... are used as sort keys. The fields can be of
any data type.
You can use the additions ASCENDING and DESCENDING with the SORT statement to control
which fields are to sort in in ascending or descending order. Ascending order is the default. For control
level processing, the sort sequence must be in ascending order.
You use the LOOP AT <itab> ... ENDLOOP keywords to process an internal table row by row.
The EXIT keyword can be used to break out of the loop processing.
After ENDLOOP, the system field SY-SUBRC indicates whether the loop was processed or not:
SY-SUBRC = 0: The loop was passed at least once.
SY-SUBRC = 4: The loop was not passed because no entry was available.
(C) SAP AG
BC405
6-6
Control Level Processing for Internal Tables
AT FIRST.
AT NEW <f>.
AT END OF <f>.
AT LAST.
REPORT
TYPES:
[SUM.] ...
[SUM.] ...
[SUM.] ...
[SUM.] ...
ENDAT.
ENDAT.
ENDAT.
ENDAT.
sapbc405dapd_citab_gr_level.
BEGIN OF struct_conn,
cityfrom
cityfrom LIKE spfli-cityfrom,
cityto
LIKE spfli-cityto,
...
cityto
END OF struct_conn.
itab_conn TYPE STANDARD TABLE OFstruct_conn,
DATA:
...
END-OF-SELECTION.
SORT itab_conn BY cityfrom cityto carrid connid fldate
LOOP AT itab_conn INTO wa_conn.
AT NEW cityfrom [SUM.] ENDAT.
AT NEW cityto
[SUM.] ENDAT.
AT END OF cityto. [SUM.] ENDAT.
ENDLOOP.
 SAP AG 2003
The AT control structures are used within a LOOP at an internal table to implement control break
processing. The AT FIRST and AT LAST behave like first time and last time switches and execute
only once.
The statements between AT NEW <f> ... ENDAT are executed when the value of field <f> changes
within the loop process and indicate the start of a control level. The statements between AT END OF
<f> ... ENDAT are executed when the value of field <f> changes during the end of a control level.
When the AT events occur, all character fields to the right of the break field are initialized with asterisks
while all numeric fields are cleared. If the SUM keyword is coded, the system automatically totals all
numeric fields for the current break level. After the ENDAT, all fields are repopulated with the values
for the current loop pass.
(C) SAP AG
BC405
6-7
Control Level Processing Schema
for Internal Tables
REPORT ...
TYPES: BEGIN OF struct,
f1 ...,
f2 ...,
f3 ...,
END OF struct.
DATA: itab TYPE STANDARD TABLE OF struct, wa TYPE struct.
...
SORT itab BY f1 f2.
LOOP AT itab INTO wa.
AT FIRST. <Statements> ENDAT.
AT NEW f1. <Statements> ENDAT.
AT NEW f2. <Statements> ENDAT.
<Single Record Processing>
AT END OF f2. <Statements> ENDAT.
AT END OF f1. <Statements> ENDAT.
AT LAST. <Statements> ENDAT.
ENDLOOP.
 SAP AG 2002
To implement control level processing using an internal table, the break fields must be declared in the
desired break sequence. The first break field must be the first table column and the second break field
must be defined next, and so on.
The internal table data must be sorted in ascending sequence.
The processing block between AT FIRST and ENDAT is executed before processing of the single lines
begins. The processing block AT LAST and ENDAT is executed after all single lines have been
processed.
Look closely at the control levels listed above. The AT events must be coded in the sequence shown in
the graphic. Also notice that the single record processing must follow the last of the AT NEW events but
before the first of the AT END OF events.
(C) SAP AG
BC405
6-8
Data Formatting and Control Level Processing
Overview
Overview
InternalTables
Tables
Internal
ExtractDatasets
Datasets
Extract
Comparisonof
ofBoth
BothTechniques
Techniques
Comparison
 SAP AG 2002
(C) SAP AG
BC405
6-9
Creating an Extract Dataset
Name field groups
FIELD-GROUPS:
header,
connections,
Statement: FIELD-GROUPS
header
Field group HEADER must
always be present
Specify field groups
Statement: INSERT ... INTO
connections
flights.
flights
INSERT:spfli-carrid spfli-connid
sflight-fldate INTO header,
spfli-cityfrom spfli-airpfrom ...
INTO connections.
carrid connid fldate cityfrom airpfrom ...
header
Fill extract
connections
flights
EXTRACT connections.
Statement: EXTRACT
LH
400
Frankfurt FRA
 SAP AG 2003
Field groups are used to process large amounts of data. The INSERT keyword is used to put data objects
and field symbols into each of the field groups. The data objects for the field-groups must be defined as
global data objects.
If you use field symbols, you can dynamically insert data objects referred to by field symbols at runtime.
Any field symbols that have not been assigned are ignored, which means no new field is inserted into the
field group.
The EXTRACT keyword places the field group and writes the field group as one record to a sequential
dataset. The field group HEADER is required and is placed at the beginning of each field group to be
used as sort fields. Once all the data has been processed, sort the dataset using the SORT keyword and
process the extract dataset with LOOP ...ENDLOOP.
Note that you do not code an EXTRACT for the HEADER field group. The system takes care of putting
the HEADER field group at the beginning all other field groups.
(C) SAP AG
BC405
6-10
Example: Generating an Extract
REPORT
sapbc405dapd_d_extracts.
* Naming field groups
FIELD-GROUPS:
FIELD-GROUPS: header, connections, flights, bookings.
FIELD
* Specifying field groups
INSERT: spfli-carrid spfli-connid
INSERT:
INTO header,
header,
sflight-fldate
INTO
spfli-cityfrom spfli-airpfrom
spfli-cityto spfli-airpto INTO
INTO connections,
connections,
sflight-price sflight-paymentsum
sflight-currency seatsfree INTO
INTO flights,
flights,
sbook-bookid
INTO
bookings.
INTO bookings.
* Data retrieval
GET spfli FIELDS carrid connid.
EXTRACT
EXTRACT connections.
LH
GET sflight FIELDS fldate price ...
seatsfree = ...
EXTRACT
EXTRACT flights.
LH
GET sbook FIELDS bookid.
EXTRACT bookings.
EXTRACT
LH
...
400
'X00'
Frankfurt FRA
400
12/29/02
1,332.00 USD
400
12/29/02 00000048
...
...
 SAP AG 2003
The INSERT statement is not a declarative statement such as DATA or TYPES. As a result, the fields
groups can be expanded in the START-OF-SELECTION event.
As soon as the first dataset of a field group has been extracted with EXTRACT, that field group can no
longer be expanded with INSERT.
When the system puts the HEADER field group at the beginning of each secondary field group, the
fields for which there are no values are filled with hexadecimal zeros. Since the HEADER contains the
sort fields for all field groups, these hexadecimal zeros in the HEADER serve as a type of hierarchy key.
The more zeros there are, the further up in the control level hierarchy you go.
(C) SAP AG
BC405
6-11
Sorting and Processing an Extract
SORT [BY <f1> <f2> ...]
[ASCENDING |DESCENDING].
LOOP.
...
ENDLOOP.
AT FIRST.
...
AT NEW <f>.
...
AT <fg>.
...
AT <fg_1> WITH <fg_2>.
AT END OF <f>. CNT(<hf>)
AT LAST.
CNT(<hf>)
ENDAT.
ENDAT.
ENDAT.
ENDAT.
SUM(<nf>)
SUM(<nf>)
ENDAT.
ENDAT.
 SAP AG 2002
The SORT statement sorts the extract dataset in accordance with the defined field sequence in field
group HEADER. The addition BY <f1> <f2> lets you control the sequence. Each field used to sort the
extract dataset must be contained in the special field group HEADER.
Processing of an extract dataset always takes places within a LOOP. ENDLOOP. As the loop is
processed, the data from the field groups are placed in the program fields with the same name.
Control break processing is only possible on fields in the HEADER field group. Single record processing
for extract datasets is performed using AT <field_group>.
The extract dataset does not allow the use of SUM used with internal table processing. It does, however
offer two options that are unique to extract datasets.
In the AT END OF event, you can have the system count the number of entries for that control level.
You can also selectively sum individual fields as well. This is the only time that a form of mathematics
is done within the WRITE keyword.
The data object you select for the CNT keyword must be an alphanumeric field in the HEADER field
group. The data object you select for the SUM keyword can be a field in any of the field groups. The
syntax is:
WRITE: / CNT(<header_field_group_field>),
SUM(<any_numeric_field_group_field>).
SUM and CNT are only available at AT END OF or AT LAST. If you try to use the SUM keyword on
its own, the program will terminate abnormally.
(C) SAP AG
BC405
6-12
Example: Control Level Processing
REPORT sapbc405dapd_d_extracts.
...
END-OF-SELECTION.
* Sorting extract data in the order of the header fields
SORT.
*
Control Level Processing
LOOP.
LOOP.
ENDAT.
AT NEW spfli-connid. WRITE ... ENDAT.
ENDAT.
AT
AT NEW
NEW sflight-fldate. WRITE ... ENDAT.
* Single record processing
ENDAT.
AT connections. WRITE ... ENDAT.
AT flights WITH bookings. WRITE ... ENDAT.
ENDAT.
AT END OF spfli-connid. ... ENDAT.
ENDLOOP.
ENDLOOP.
 SAP AG 2002
Single record processing for extract datasets AT <field_group_1> WITH <field_group_2fg_2> allows
you to process <field_group1> only if it is immediately followed by only <field_group_2>. This is very
useful for header and detail processing where you do not want the header information to print unless
there is supporting detail.
Loops over an extract dataset cannot be nested. However, several consecutive loops are possible.
(C) SAP AG
BC405
6-13
Using Field Symbols in Extract Datasets
FIELD-SYMBOLS: <fs1> TYPE any, <fs2> TYPE any, <fs3> TYPE any.
FIELD-GROUPS: header, detail.
Select sort by field
LOOP.
AT NEW <fs1>.
PERFORM new_fs1.
ENDAT.
Carrier
Connection
Flight Date
Plane type
CASE ‘X’.
WHEN p_date.
ASSIGN sflight-fldate
TO <fs1>.
ASSIGN sflight-planetype TO <fs2>.
ASSIGN sflight-carrid
TO <fs3>.
WHEN p_carrid.
…..
endcase
SORT ASCENDING AS TEXT BY <fs1> <fs2> <fs3>.
AT NEW <fs2>.
PERFORM new_fs2.
ENDAT.
AT detail.
PERFORM write_detail.
ENDAT.
AT END OF <fs1>.
ULINE.
ENDAT.
ENDLOOP.
 SAP AG 2003
You can insert field symbols into your field groups instead of using data object names. This allows a
single program to produce multiple different output formats.
The steps required are quite simple:
Define as many field symbols as necessary for the processing.
Define the required field group HEADER and as many subordinate field groups as necessary.
Create a set of radio buttons on the selection screen to allow the user to determine the report output
sequence.
Evaluate the user’s selection, typically in a CASE construct, and assign data object names to the field
symbols. Note the syntax for the ASSIGN keyword.
Insert the field symbols into the appropriate field groups.
(C) SAP AG
BC405
6-14
Schema of Control Level Processing for Extracts
FIELD-GROUPS: header, record1, record2.
INSERT: f2 f1 INTO header,
f3 f4 INTO record1,
f5
INTO record2.
...
END-OF-SELECTION
SORT BY f1 f2.
LOOP.
AT FIRST. <statements> ENDAT.
AT NEW f1. <statements> ENDAT.
AT NEW f2. <statements> ENDAT.
Control header
processing
ENDAT.
ENDAT.
Single record
processing
AT END OF f2. <statements> ENDAT.
AT END OF f1. <statements> ENDAT.
AT LAST. <statements> ENDAT.
ENDLOOP.
Control footer
processing
AT record1. <statements>
AT record2. <statements>
 SAP AG 2002
The sequence of the control level changes within the LOOP must correspond to the sort sequence.
Totals can only be calculated within control footer processing.
(C) SAP AG
BC405
6-15
Data Formatting and Control Level Processing
Overview
Overview
InternalTables
Tables
Internal
ExtractDatasets
Datasets
Extract
Comparisonof
ofBoth
BothTechniques
Techniques
Comparison
 SAP AG 2002
(C) SAP AG
BC405
6-16
Comparing Internal Tables and Extract Datasets
Internal table
Extract
Several internal tables
A single EXTRACT dataset
Control level totals also in the
control header (AT FIRST, AT
NEW f)
Control level totals only in the
control footer (AT END OF f, AT
LAST)
Internal table keywords insert,
modify, delete, and append are
permitted
Few operations (only append, sort
and sequential processing)
Changing internal tables always
possible
Expansion of the dataset with
EXTRACT after SORT or LOOP no
longer possible
All table rows have the same
structure
Multiple different row structures
are supported.
Static line type
Dynamic record types (INSERT is
not a declarative statement!)
Control level processing only
according to the field sequence of
the line type
Control level processing according
to the sort sequence (independent
of header sequence)
Totaling (SUM) bound to high
costs
Totaling (SUM(f)) optimized
 SAP AG 2002
Extracts allow only EXTRACT, SORT, and sequential processing using LOOP. Once a SORT or
LOOP has occurred, the intermediate dataset structure is frozen and cannot be expanded with
EXTRACT. Operations that insert into or delete from EXTRACT datasets are not supported.
Extracts allow for several different row structures with fields that can be set dynamically. Internal tables
have a single, statically defined line type.
Internal tables use the sequence of table fields according to the declaration for the hierarchy of the
control level. The control level structure for internal tables is therefore static, and is independent of
which criteria were used to sort the internal table. Extracts do not depend on the field sequence for
control level processing: A re-sort or a completely different control level process can take place. The
control level structure for extract datasets is dynamic. It corresponds to the sort key of the extract
dataset. The sort key is the sequence of fields from the field group HEADER, and is used to sort the
extract dataset.
Extracts rely on the compiler to determine which combinations of group levels and cumulating field the
control level totals desire. The desired control level totals are determined by the processing of LOOP ...
ENDLOOP blocks. Internal tables build the control level total with the SUM statement. This procedure
leads to high resource depletion for totaling control levels in internal tables.
(C) SAP AG
BC405
6-17
Data Formatting and Control Level Processing:
Unit Summary
You are now able to:
Format data with internal tables.
Use control level processing with internal tables and
extract datasets.
 SAP AG 2002
(C) SAP AG
BC405
6-18
Data Formatting and Control Level Processing Exercises
Unit: Data Formatting and Control Level Processing
Topic: Internal Tables
When you have completed these exercises, you will be able to:
• Implement control level processing with internal tables
1-1
Copy or enhance your program Z##GDA1_..., or copy the sample solution,
SAPBC405_GDAS_1, to program Z##DAP1_... . Sample solution for exercise:
SAPBC405_DAPS_1.
Carry out control level processing for CITYFROM, CITYTO, CARRID, and
CONNID. Create a list like the one in the template.
1-1-1 Create a line type in the TOP include (TYPES statement). Declare the internal
table and the work area in accordance with the line type. You should include
the following fields:
CARRID, CONNID, FLDATE, PRICE, CURRENCY, CITYFROM,
COUNTRYFR, CITYTO, COUNTRYTO, SEATSMAX, SEATSOCC.
Note: The control level hierarchy for an internal table is established by your
line structure.
1-1-2 Sort the internal table in accordance with the requested control level processing
(event: END-OF-SELECTION).
1-2
Implement the control level processing in your output routine.
1-2-1 Display each new departure city on a separate page and with intensive display
in color COL_GROUP in the list.
1-2-2 Display the city and airport for each new arrival city with a less intensive
display in color COL_GROUP.
1-2-3 Ensure that the icon ICON_BW_GIS (for international flights), the airline, and
the flight number are displayed as required during single-record processing.
Display the key fields in color COL_KEY; they should remain as hard lead
columns. Display the flight date, the price, the currency, the maximum number
of seats, and the number occupied in color COL_NORMAL in the list with a
less intensive display.
(C) SAP AG
BC405
6-19
1-2-4 At the end of each flight connection, the totals for the maximum number of
seats and the number occupied should be displayed in color COL_TOTAL
without intensive display.
1-2-5 A solid line should appear on the list before the departure location changes.
1-2-6 Draw a frame around the list (sy-vline).
1-2-7 Modify the column headers to fit the new list output (see the template). Use text
elements to allow your texts to be translated.
Template:
Flight data
Departure city
Arrival city
Flight
Date
Price
Max.
Occ.
@ LH 0400
06/01/2003
666.00
@ LH 0400
06/29/2003
666.00
EUR
385
250
EUR
385
@ LH 0400
07/27/2003
190
666.00
EUR
385
105
@ LH 0400
@ LH 0400
08/24/2003
666.00
EUR
385
122
09/21/2003
666.00
EUR
385
37
1,925
704
@ LH 0402
06/01/2003
666.00
EUR
385
179
@ LH 0402
06/29/2003
666.00
EUR
385
124
@ LH 0402
07/27/2003
666.00
EUR
385
75
@ LH 0402
08/24/2003
666.00
EUR
385
5
@ LH 0402
09/21/2003
666.00
EUR
FRANKFURT
NEW YORK
Total
Total
385
2
1,925
385
@ = ICON_BW_GIS
(C) SAP AG
BC405
6-20
Exercises
Unit: Data Formatting and Control Level Processing
Topic: Extracts
When you have completed these exercises, you will be able to:
• Name field groups.
• Define field groups.
• Create extracts.
• Perform control level processing with extracts.
2-1
Copy or enhance your program Z##LDB2_..., or copy the sample solution,
SAPBC405_LDBS_2, to program Z##DAP2_... Sample solution for exercise:
SAPBC405_DAPS_2.
2-1-1 Deactivate the events GET … LATE.
2-1-2 Define the following field groups in the TOP to include:
HEADER
CONNECTIONS
FLIGHTS
BOOKINGS
2-1-3 Assign the following fields to the field groups:
HEADER:
spfli-carrid, spfli-connid, sflight-fldate, sbook-bookid,
sbook-customid
CONNECTIONS: spfli-cityfrom, spfli-airpfrom, spfli-cityto, spfli-airpto
FLIGHTS:
sflight-price, sflight-currency, sflight-planetype, sflightseatsmax, sflight-seatsocc, free_seats
BOOKINGS:
sbook-bookid, sbook-customid, sbook-smoker, sbookluggweight, sbook-wunit.
2-1-4 Fill the extract dataset for the GET events.
2-1-5 Sort the extract according to the sequence of field group HEADER.
2-1-6 Start control level processing and create a list with the following structure:
Line 1:
(C) SAP AG
SPFLI-CARRID, SPFLI-CONNID
BC405
6-21
Line 2:
SFLIGHT-FLDATE
Line 3:
SPFLI-CITYFROM, SPFLI-AIRPFROM, SPFLI-CITYTO,
SPFLI-AIRPTO
Line 4:
SFLIGHT-PRICE, SFLIGHT-CURRENCY,
SFLIGHT- PLANETYPE, SFLIGHT-SEATSMAX, SFLIGHTSEATSOCC, FREE_SEATS
Line 5:
SBOOK-BOOKID, SBOOK-CUSTOMID,
SBOOK-SMOKER, BOOK-LUGGWEIGHT,
SBOOK-WUNIT.
Only output line 3 if line 4 is also output.
Only output line 4 if line 5 is also output.
2-1-7 The list should also include the number of total bookings and the total weight of
the luggage for each flight date in one line.
2-2
Formatting the list
2-2-1 The price and luggage weight should be output with correct format for the
respective units.
2-2-2 Display each flight on a new page.
2-2-3 Display a solid line before and after the number of bookings and the total
weight.
2-2-4 Use the following control structures and colors:
AT NEW spfli-connid, COL_GROUP INTENSIFIED ON
AT NEW sflight-fldate, COL_HEADING INTENSIFIED ON
AT flights WITH bookings, COL_NORMAL INTENSIFIED ON
AT bookings, COL_NORMAL INTENSIFIED OFF
AT END OF sflight-fldate, COL_TOTAL INTENSIFIED ON
2-2-5 Position the control levels in the list in such a way that the hierarchy is
apparent. For example, line 1 begins further to the left than line 2, and so on.
Draw a frame around the list. Maintain the column headers (standard list
header).
(C) SAP AG
BC405
6-22
Data Formatting and Control Level Processing Solutions
Unit: Data Formatting and Control Level Processing
Topic: Internal Tables
*&---------------------------------------------------------------------*
*& Report
SAPBC405_DAPS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
Solution; Exercise 1; Control level processing
With internal table
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_daps_1top.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE: / sy-vline,
'Flight data'(001),
AT line_size sy-vline.
ULINE.
* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: sy-vline, 'Departure location'(004),
WRITE: sy-vline, 'Arrival location'(004),
AT line_size sy-vline.
AT line_size sy-vline.
WRITE: sy-vline, AT pos_c1 'Flight'(002).
(C) SAP AG
BC405
6-23
* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE: 'Date'(003),
AT pos_c3 'Price'(006),
AT pos_c4 'Max.'(008),
AT pos_c5 'Occ.'(009),
AT line_size sy-vline.
ULINE.
*&---------------------------------------------------------------------*
*&
Event
INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
" OPTIONAL
* Initialize select-options for CARRID
MOVE: 'AA' TO so_car-low,
'QF' TO so_car-high,
'BT' TO so_car-option,
'I' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
MOVE: 'AZ' TO so_car-low,
'EQ' TO so_car-option,
'E' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
*&---------------------------------------------------------------------*
*&
Event AT SELECTION-SCREEN ON BLOCK PARAM
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK param.
" OPTIONAL
* check country for national flights is not empty
CHECK national = 'X' AND country = space.
MESSAGE e003(bc405).
*&---------------------------------------------------------------------*
(C) SAP AG
BC405
6-24
*&
Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Checking the output parameters
CASE mark.
WHEN all.
* Radiobutton ALL is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt.
WHEN national.
* Radiobutton NATIONAL is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr = spfli~countryto
AND spfli~countryfr = country.
WHEN internat.
* Radiobutton INTERNAT is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
(C) SAP AG
BC405
6-25
AND spfli~countryfr NE spfli~countryto.
ENDCASE.
* Additional solution: dynamical WHERE condition
* PERFORM get_data.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*SORT it_flights BY carrid connid fldate.
* Control Level Processing: the internal table has to be sorted
SORT it_flights BY cityfrom cityto carrid connid.
* Data output
PERFORM data_output.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Group Level:
CITYFROM
AT NEW cityfrom.
NEW-PAGE.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline, wa_flights-cityfrom,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
(C) SAP AG
BC405
6-26
* Group Level:
CITYTO
AT NEW cityto.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, wa_flights-cityto,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Single Record Processing
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
wa_flights-seatsmax,
wa_flights-seatsocc,
AT line_size sy-vline.
FORMAT RESET.
* Group Level:
CONNID
AT END OF connid.
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / sy-vline,
'Total'(007),
wa_flights-seatsmax UNDER wa_flights-seatsmax,
wa_flights-seatsocc UNDER wa_flights-seatsocc,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
(C) SAP AG
BC405
6-27
* Group Level:
CITYFROM
AT END OF cityfrom.
ULINE.
ENDAT.
ENDLOOP.
ENDFORM.
" DATA_OUTPUT
*&---------------------------------------------------------------------*
*& Include BC405_DAPS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
bc405_daps_1top LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
* Linetype of internal table
TYPES: BEGIN OF linetype,
cityfrom LIKE spfli-cityfrom,
cityto
LIKE spfli-cityto,
carrid
LIKE spfli-carrid,
connid LIKE spfli-connid,
countryfr like spfli-countryfr,
countryto like spfli-countryto,
fldate
price
LIKE sflight-fldate,
LIKE sflight-price,
currency LIKE sflight-currency,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
end of linetype.
* Constants for writing position
CONSTANTS:
pos_c1 TYPE i VALUE
6,
pos_c3 TYPE i VALUE 30,
pos_c4 TYPE i VALUE 58,
(C) SAP AG
BC405
6-28
pos_c5 TYPE i VALUE 68,
line_size TYPE i VALUE 100.
* Constant for CASE statement
CONSTANTS mark VALUE 'X'.
* Internal table like DDIC view DV_FLIGHTS
*
DATA: it_flights LIKE TABLE OF dv_flights,
*
wa_flights LIKE dv_flights.
* Internal table type linetype
DATA: it_flights TYPE STANDARD TABLE OF linetype,
wa_flights TYPE linetype.
* Selections for connections
SELECTION-SCREEN BEGIN OF BLOCK conn WITH FRAME TITLE text-tl1.
SELECT-OPTIONS: so_car FOR wa_flights-carrid,
so_con FOR wa_flights-connid.
SELECTION-SCREEN END OF BLOCK conn.
* Selections for flights
SELECTION-SCREEN BEGIN OF BLOCK flight WITH FRAME TITLE text-tl2.
SELECT-OPTIONS so_fdt FOR wa_flights-fldate NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK flight.
* Output parameter
SELECTION-SCREEN BEGIN OF BLOCK param
WITH FRAME TITLE text-tl3.
SELECTION-SCREEN BEGIN OF BLOCK radio WITH FRAME.
PARAMETERS: all RADIOBUTTON GROUP rbg1,
national RADIOBUTTON GROUP rbg1,
internat RADIOBUTTON GROUP rbg1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK radio.
PARAMETERS country LIKE wa_flights-countryfr.
SELECTION-SCREEN END OF BLOCK param.
(C) SAP AG
BC405
6-29
Solutions
Unit: Data Formatting and Control Level Processing
Topic: Extracts
*&--------------------------------------------------------- -----------*
*& Report
SAPBC405_DAPS_2
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_daps_2top.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI
*&---------------------------------------------------------------------*
GET spfli.
* Save field group:
connections
EXTRACT connections.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT
*&---------------------------------------------------------------------*
GET sflight.
* Calculate free seats
free_seats = sflight-seatsmax - sflight-seatsocc.
* Save field group:
flights
EXTRACT flights.
(C) SAP AG
BC405
6-30
*&---------------------------------------------------------------------*
*&
Event GET SBOOK
*&---------------------------------------------------------------------*
GET sbook.
* Check select-option
CHECK so_odat.
* Save field group:
bookings
EXTRACT bookings.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI LATE
*&---------------------------------------------------------------------*
*GET spfli LATE.
*
ULINE.
*
NEW-PAGE.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT LATE
*&---------------------------------------------------------------------*
*GET sflight LATE.
*
ULINE.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
* Sorting extract data according to the header fields
SORT.
* Control level processing
LOOP.
AT NEW spfli-connid.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline,
spfli-carrid,
spfli-connid,
AT line_size sy-vline.
(C) SAP AG
BC405
6-31
ENDAT.
AT NEW sflight-fldate.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: / sy-vline,
AT pos_lev2 sflight-fldate,
AT line_size sy-vline.
ENDAT.
* Single record processing
AT connections WITH flights.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: / sy-vline,
spfli-cityfrom,
spfli-airpfrom,
spfli-cityto,
spfli-airpto, AT line_size sy-vline.
ENDAT.
AT flights WITH bookings.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
WRITE:
/ sy-vline,
sflight-price CURRENCY sflight-currency,
sflight-currency,
sflight-planetype,
sflight-seatsmax,
sflight-seatsocc,
free_seats, AT line_size sy-vline.
ENDAT.
AT bookings.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: / sy-vline,
AT pos_lev3 sbook-bookid,
sbook-customid,
sbook-smoker,
sbook-luggweight UNIT sbook-wunit,
sbook-wunit, AT line_size sy-vline.
ENDAT.
(C) SAP AG
BC405
6-32
* Control level processing with CNT and SUM
AT END OF sflight-fldate.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
ULINE.
WRITE: sy-vline,
'Totals:'(001),
cnt(sbook-bookid) UNDER sbook-bookid,
sum(sbook-luggweight) UNIT sbook-wunit
UNDER sbook-luggweight,
sbook-wunit,
AT line_size sy-vline.
ULINE.
ENDAT.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Include BC405_DAPS_2TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
bc405_daps_2top LINE-SIZE 83.
* Used nodes of the structure of the logical database F1S
NODES: spfli, sflight, sbook.
* Additional selections
SELECTION-SCREEN BEGIN OF BLOCK order WITH FRAME.
SELECT-OPTIONS: so_odat FOR sbook-order_date.
SELECTION-SCREEN END OF BLOCK order.
* Variables
DATA: free_seats LIKE sflight-seatsocc.
* Constants
CONSTANTS: line_size LIKE sy-linsz VALUE 83,
pos_lev2 TYPE i VALUE 10,
(C) SAP AG
BC405
6-33
pos_lev3 TYPE i VALUE 20.
* Field groups
FIELD-GROUPS: header,
" Group Level and sorting fields
connections,
" Fields of SPFLI
flights,
" Fields of SFLIGHT
bookings.
" Fields of SBOOK
* Fixing of field groups
INSERT:
spfli-carrid
spfli-connid
sflight-fldate
sbook-bookid
sbook-customid
INTO header,
spfli-cityfrom
spfli-airpfrom
spfli-cityto
spfli-airpto
INTO connections,
sflight-price
sflight-currency
sflight-planetype
sflight-seatsmax
sflight-seatsocc
free_seats
INTO flights,
sbook-bookid
sbook-customid
sbook-smoker
sbook-luggweight
sbook-wunit
(C) SAP AG
INTO bookings.
BC405
6-34
Saving Lists and Background Processing
Contents:
Saving Lists
Print
Background Processing
 SAP AG 2002
(C) SAP AG
BC405
7-1
Saving Lists and Background Processing:
Unit Objectives
At the conclusion of this unit, you will be able to:
Choose among options to save a list.
Save a list in an area menu.
Choose among options for generating a printing list.
Execute a report in a background work process using a
variant.
 SAP AG 2002
(C) SAP AG
BC405
7-2
Saving Lists and Background Processing
SavingLists
Lists
Saving
Printing
Printing
BackgroundProcessing
Processing
Background
 SAP AG 1999
(C) SAP AG
BC405
7-3
Options for Saving Lists
List
Save/Send
+
System
List
Save
Flight data
Folders
 SAP AG 2003
There are several ways to save a list that you have generated:
In SAP office
As a local file on your PC
In an area menu
In a User‘s Favorites on the main R/3 menu.
You can use the System->List->Save menu, or the List->Save menu in the standard list status.
(C) SAP AG
BC405
7-4
Saving Lists in SAPoffice
Flights from Frankfurt
LH Lufthansa
400 04/06/2003
400 05/04/2003
400 06/01/2003
402 06/29/2003
New York
New York
New York
New York
1
380
380
380
189
My flight data
Save
Personal
folders
Flight data
Send
Folders
 SAP AG 2003
You can also create folders in SAP office. You can use these folders to store the lists. When a list is
placed in the outbox of the personal folders, it can also be sent to other users.
(C) SAP AG
BC405
7-5
Saving Lists as PC Files
Flights from Frankfurt
LH Lufthansa
400 04/06/2003
400 05/04/2003
400 06/01/2003
402 06/29/2003
Unconverted
1
New York
New York
New York
New York
Spreadsheet
380
380
380
189
Rich Text
Format
HTML format
 SAP AG 2003
You can save a list to a PC as a local file in four different formats:
Unconverted (ASCII)
Spreadsheet format (→ Microsoft Excel)
RTF (Rich Text Format → Microsoft Word)
HTML (Web Browser)
You can use the program RSSOPCDR to specify the default file that the system proposes when the user
chooses to save a file to the local PC.
(C) SAP AG
BC405
7-6
Saved Lists in an Area Menu
Goto
Report
Area menu
Preview
Saved lists
Programs for flight data model
Flights from Frankfurt
Display flight data
1
Programs
LH Lufthansa
400 04/06/2003
400 05/04/2003
400 06/01/2003
402 06/29/2003
New York
New York
New York
New York
DEMO: Read ...
380
380
380
189
DEMO: Variant ...
Queries
One-line basic list ...
+
Change flight data
 SAP AG 2003
Area menus have been converted to tree navigation in Release 4.6A. Type 1 programs and SAP queries
can now be added to the area menus, which may already contain transactions. Any programs that do not
have a transaction code are automatically allocated one.
The report trees have been integrated in the area menus in Release 4.6. The report trees are now
maintained using the maintenance tools for area menus. You can maintain area menus in the Workbench
menu path Tools->ABAP Workbench->Development->Other Tools->Area Menus. If you have report
trees that you want to convert to area menus, use transaction RTTREE_MIGRATION.
Saved lists are saved with the program itself. If the program has been integrated in an area menu or in a
User’s Favorites on the main R/3 menu, then the saved lists will also appear there. You can also use
standard program RSRSSLIS to display saved lists.
A user can access an area menu whenever that area menu has been allocated to an activity group to
which the user belongs. You can use the profile generator to allocate an area menu to an activity group.
(C) SAP AG
BC405
7-7
Saving Lists and Background Processing
SavingLists
Lists
Saving
Printing
Printing
BackgroundProcessing
Processing
Background
 SAP AG 1999
(C) SAP AG
BC405
7-8
List Printing Options
REPORT ...
Spool process
WRITE: ...
Background WP
4
1
2
3
REPORT ...
WRITE: ...
Dialog process
 SAP AG 2003
There are four options for printing a list:
From the selection screen
- The list is output to print only when it is generated (adjusted to print format) and does not appear on
the screen.
- The list is generated in a dialog work process
From within the program
- All the choices available when printing from the selection screen
- This procedure is suitable for interactive lists: (printing details lists).
After the list has been generated
- The list has already been generated (visible on the screen) and can be formatted within limits. For
example, the number of columns in the list cannot be changed after the list is generated.
- The list is generated in a dialog work process
In the background
- The list can be printed after it has been generated (as described in one above)
- The list is generated in a background work process. This procedure is particularly suitable for long
running programs.
(C) SAP AG
BC405
7-9
Print Parameters
Spool request
Output device
Number of copies
Cover sheets
SAP System cover sheet
Selection cover sheet
Recipient
Department
Name
Title
Authorization
Spool
process
Spool control
Immediate output
Delete after output
New spool request
Spool retention period
Archiving mode
Output format
Lines
Columns
Format
 SAP AG 2002
To print a list, you must enter print parameters. The print parameters which control list output are
divided into the following areas:
Output device and number of copies
Spool request
Spool control
Cover sheets
Output format
You can enter print parameters on the screen or set them directly in the program. Setting print
parameters in the program is covered below (NEW-PAGE PRINT ON).
You can use the function module SET_PRINT_PARAMETERS to set default values for printing an
online list. You can execute print from the selection screen or after generation of the list.
(C) SAP AG
BC405
7-10
Program-Controlled Printing
NEW-PAGE PRINT ON [PARAMETERS <pri_set> |
<p1> <p2> ... ]
[NO DIALOG].
NEW-PAGE PRINT OFF.
REPORT sapbc405_stld_new_page_prt_on.
NEWNEW-PAGE
NEW-PAGE PRINT
PRINT ON
ON
IMMEDIATELY
KEEP IN SPOOL
RECEIVER
COVER TEXT
' '
'X'
sy-uname
'Flight data'(001).
WRITE: ...
NEW-PAGE PRINT OFF.
NEW
NEW
 SAP AG 2002
NEW-PAGE PRINT ON triggers a page break, and all the subsequent output is redirected to the spool.
The print parameters can either be passed on to the system as a field list with the PARAMETERS
attribute or, as shown in the above example, specified individually.
Individual entry of print parameters is not recommended. Consider the case where the user arrives at the
print parameter screen and decides not to print; the only option in this case would be to terminate the
entire program.
If you enter parameter NO DIALOG, the list is placed directly in the spool without giving the user any
opportunity to change the print parameters at runtime. If you do not enter NO DIALOG, the user is
presented with a print parameters screen containing default values at runtime.
NEW-PAGE PRINT OFF triggers a page break, ends the spool request (sy-spono is assigned), and all
subsequent output is once again output on the screen.
(C) SAP AG
BC405
7-11
Printing with GET_PRINT_PARAMETERS
REPORT
sapbc405_stld_get_print_param ...
DATA: print_parameter_set
print_
pri_
print_parameter_
parameter_set TYPE
TYPE pri_params,
pri_params,
params,
valid,
valid,
valid, list_text LIKE print_parameter_set-prtxt.
...
START-OF-SELECTION.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination
= 'LP01'
immediately
= ' '
release
= 'X'
receiver
= sy-uname
list_text
= list_text
IMPORTING
out_parameters = print_parameter_set
valid
= valid.
IF valid = 'X'.
PRINT
ON PARAMETERS
print_params
NO DIALOG.
NEWPAGE PRINT
ON PARAMETERS
print_
_parameter_
NO DIALOG.
NEW-NEW-PAGE
print
parameter_set
... . ENDIF.
...
END-OF-SELECTION.
-PAGE PRINT OFF.
IF valid = 'X'. NEWNEW-PAGE
NEW
ENDIF.
 SAP AG 2003
The structure for the PARAMETERS attribute of the NEW-PAGE PRINT ON statement must be
filled using function module GET_PRINT_PARAMETERS. The structure contains an internal
checksum that is calculated by NEW-PAGE PRINT ON. If the checksum is incorrect, the program
terminates. Function module GET_PRINT_PARAMETERS calculates the checksum and returns it with
out_parameters.
Function module GET_PRINT_PARAMETERS provides users with a print parameters screen that can
be used to modify the print parameters and then determine a complete new set of print parameters. The
set is returned using output parameter out_parameters. In successful cases, output parameter valid
contains the value X. If the system cannot create a complete set record of print parameters, the structure
transferred with out_parameters is empty and valid contains the value space.
You can transfer print parameters to the function module GET_PRINT_PARAMETERS. The print
parameters appear as default values in the print parameters screen.
The print parameters screen of function module GET_PRINT_PARAMETERS offers the option of
canceling the filling of print parameters. In this case, the structure transferred with out_parameters is
empty and valid contains the value space.
(C) SAP AG
BC405
7-12
GET_PRINT_PARAMETERS: Applications
REPORT sapbc405_stld_diff_receiver ...
LOOP ...
receiver
= ...
department = ...
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
department
= department
new_list_id
= 'X'
no_dialog
= 'X'
receiver
= receiver
...
IMPORTING
out_parameters
= print_parameters_set
valid
= valid
EXCEPTIONS ...
IF valid <> space.
NEW-PAGE
PRINT ON
ON PARAMETERS
PARAMETERS print_
print_parameters_set
NO DIALOG.
DIALOG.
NEW-PAGE PRINT
_parameters_
NEW
print
parameters_set NO
PERFORM list_generator.
NEW-PAGE
PRINT OFF.
OFF.
NEW-PAGE PRINT
NEW
-spono
WRITE: / 'Spool ID'(001), sysy-spono.
sy
....
ENDLOOP.
 SAP AG 2002
One application is to send a list to several recipients.
Sending a list to several recipients is implemented in the above example. To send a list to several
recipients, you to distribute the list among several spool requests. To do this, use parameter
NEW_LIST_ID and then NEW-PAGE PRINT OFF to end the spool request.
(C) SAP AG
BC405
7-13
Saving Lists and Background Processing
SavingLists
Lists
Saving
Print
Print
BackgroundProcessing
Processing
Background
 SAP AG 1999
(C) SAP AG
BC405
7-14
The Phases of Background Processing
Steps
Print
Define job
Start date
Save job
Status
Planned
Job overview
Released
Ready
Active
Canceled
 SAP AG 2002
When a program converts large datasets and requires a long runtime, it makes sense to execute it in a
background work process.
Background runs take place without user dialogs, and can take place in parallel to online operations. The
dialog work processes are available for online processing. Background job runs are performed by special
work processes (background processes), which enable distributed processing.
To start a program in the background, you must first add it to a job.
Use the job definition to determine which programs (steps) will run during this job. You can specify
print parameters and set the start time for the job.
The job overview tells you the current status of the job.
From release 4.6C, a job wizard is available to make the creation of background jobs easier.
(C) SAP AG
BC405
7-15
Defining Steps
Start condition
Steps
General information
Job name
MY_JOB
Job class
C
ABAP program
Status
Planned
ABAP program
Destination
External command
Name
SAPBC405_SSCD_VARIANTS
Variant
DEMO: BC405
Language EN
Printing information
Save
Spool
 SAP AG 2003
Define job is located under menu path System->Services->Jobs->Define job. First assign a job name (of
your choice) and define the priority (job class) and the destination (F4 help).
Determine the individual steps of the job. If you want the program to run with a selection screen, you
also have to specify a variant. The list can be stored in the spool or printed immediately. This depends on
the specified print parameters. When you have defined all the steps, save them and return to the initial
screen of the job definition.
(C) SAP AG
BC405
7-16
Determining the Start Date and Releasing the Job
Start condition
Steps
General information
Now
Date/Time
Job name
MY_JOB
Job class
C
Status
Planned
Date/Time
Destination
Planned start
01/01/2001
00:00:00
Do not start after
Save
Save job
 SAP AG 2002
Once you have defined the steps, you can determine the start date for the job. For example, you can start
the job on a certain day at a certain time.
Once you have defined the start date, save your entries and return to the initial screen of the job
definition. Now save the job, which releases it to run at the specified time.
You can also use the automated job scheduling with the function modules in function groups BTCH and
BTC2. An example is available in program SAPBC405STLD_E_JOB.
(C) SAP AG
BC405
7-17
Saving Lists and Background Processing:
Unit Summary
You are now able to:
Choose among options to save a list.
Save a list in an area menu.
Choose among options for generating a printing list.
Start a report with a variant in the background.
 SAP AG 2002
(C) SAP AG
BC405
7-18
Savings Lists and Background Processing Exercises
Unit: Saving Lists and Background Processing
Topic: Program-Controlled Printing
When you have completed these exercises, you will be able to:
• Print using function module GET_PRINT_PARAMTERS
1-1
Copy or enhance your program Z##LDB2_..., or copy the sample solution,
SAPBC405_LDBS_2, to program Z##STL1_... Sample solution for exercise:
SAPBC405_STLS_1.
1-1-1 Enhance the program to include the function for storing the generated list in the
spool. To do this, use function module GET_PRINT_PARAMETERS. Use
the pattern functions available in the ABAP Editor to program the function call.
Pass the following values on in the interface:
EXPORTING: copies = 2, destination = LP01, expiration = 3, immediately =
space, line_size = 83, list_text = text-xxx (text element), no_dialog = space,
release = X, report = EXAMPLE
IMPORTING: out_parameters = print_parameter, valid = valid
1-1-2 In the TOP include, create variable print_parameter as a character field with
length 1, in accordance with DDIC structure PRI_PARAMS and variable
valid.
1-1-3 Evaluate the return value of valid after the function call. If valid is not
equal to space, store the list in the spool and suppress the print dialog. In
addition, display information message 104 from message class BCTRAIN. If
valid is equal to space, output information message 105 from message class
BC405.
(C) SAP AG
BC405
7-19
Saving Lists and Background Processing Solutions - Optional
Unit: Saving Lists and Background Processing
Topic: Program-Controlled Printing
*&---------------------------------------------------------------------*
*& Report
SAPBC405_STLS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE BC405_STLS_1TOP.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI
*&---------------------------------------------------------------------*
GET spfli.
* Data output SPFLI
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:
/ sy-vline, spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-airpfrom,
spfli-cityto,
spfli-airpto,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SFLIGHT
*&---------------------------------------------------------------------*
GET sflight.
(C) SAP AG
BC405
7-20
* Calculate free seats
free_seats = sflight-seatsmax - sflight-seatsocc.
* Data output SFLIGHT
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
WRITE: / sy-vline, sflight-fldate,
sflight-price CURRENCY sflight-currency,
sflight-currency,
sflight-planetype,
sflight-seatsmax,
sflight-seatsocc,
free_seats,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SBOOK
*&---------------------------------------------------------------------*
GET sbook.
* Check select-option
CHECK so_odat.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: / sy-vline, sbook-bookid,
sbook-customid,
sbook-smoker,
sbook-luggweight UNIT sbook-wunit,
sbook-wunit,
sbook-order_date,
AT line_size sy-vline.
*&---------------------------------------------------------------------*
*&
Event GET SPFLI LATE
*&---------------------------------------------------------------------*
GET spfli LATE.
ULINE.
NEW-PAGE.
*&---------------------------------------------------------------------*
(C) SAP AG
BC405
7-21
*&
Event GET SFLIGHT LATE
*&---------------------------------------------------------------------*
GET sflight LATE.
ULINE.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
* Define print parameters via function module
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
COPIES
=
2
" Number of copies
DESTINATION
=
'LP01'
" Printer
EXPIRATION
=
3
" Duration /d in spool
IMMEDIATELY
=
SPACE
" print immediately
LINE_SIZE
=
100
" Width of list
LIST_TEXT
=
TEXT-SP1
" Title
NO_DIALOG
RELEASE
=
=
REPORT
'X'
=
SPACE
" dialog is allowed
" delete task after print
'EXAMPLE'
" Name
IMPORTING
OUT_PARAMETERS
= PRINT_PARAMETER
VALID
= VALID.
* Sending list to the SAP spool or on the screen
IF VALID NE SPACE.
" List to spool
NEW-PAGE PRINT ON PARAMETERS PRINT_PARAMETER NO DIALOG.
MESSAGE I104(BC405).
ELSE.
" List on screen
MESSAGE I105(BC405).
ENDIF.
*&---------------------------------------------------------------------*
*& Include BC405_STLS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
(C) SAP AG
sapbc405_stls_1 LINE-SIZE 83.
BC405
7-22
* Used nodes of the structure of the logical database F1S
NODES: spfli, sflight, sbook.
* Additional selections
SELECTION-SCREEN BEGIN OF BLOCK order WITH FRAME.
SELECT-OPTIONS: so_odat FOR sbook-order_date.
SELECTION-SCREEN END OF BLOCK order.
* Variables
DATA: free_seats LIKE sflight-seatsocc.
DATA: print_parameter LIKE pri_params, " NEW-PAGE PRINT ON .....
valid VALUE 'X'.
* Constants
CONSTANTS: line_size LIKE sy-linsz VALUE 83,
pos_lev2 TYPE i VALUE 10,
pos_lev3 TYPE i VALUE 20.
(C) SAP AG
BC405
7-23
Basic Techniques in Interactive Lists
Contents:
Detail lists
Interactive events
Data transport between list and program
Hide technique
Valid line selection
Querying cursor position
Page headings for detail lists
List in modal dialog boxes
 SAP AG 2002
(C) SAP AG
BC405
8-1
Basic Techniques in Interactive Lists: Objectives
At the conclusion of this unit, you will be able to:
Describe what detail lists are and how to generate
them.
Identify which interactive events exist.
Transport data between lists and programs.
Recognize an invaild line selection.
Create page headers in detail lists.
Create lists in modal dialog boxes.
 SAP AG 2002
(C) SAP AG
BC405
8-2
Basic Techniques in Interactive Lists
Detaillists
lists
Detail
Datatransport
transport
Data
Othertechniques
techniques
Other
 SAP AG 2002
(C) SAP AG
BC405
8-3
Navigating Between Lists
DL 20
DL 2
DL 1
Basic list
double-click on line
 SAP AG 2002
Up to 20 parallel detail lists can exist for each basic list. Each list has in its own individual memory area
called a list buffer.
The same functions are available in detail lists as are available in basic lists.
Choose Back (the green arrow) or Cancel (the red X) to leave the current list. This releases the
corresponding list buffer and returns to the preceding list.
Use the Exit function (yellow arrow) to return to the selection screen.
(C) SAP AG
BC405
8-4
Events: Overview
*
Basic list
START-OF-SELECTION.
GET ... .
END-OF-SELECTION.
TOP-OF-PAGE.
*
Detail lists
AT LINE-SELECTION.
AT USER-COMMAND.
TOP-OF-PAGE DURING LINE-SELECTION.
 SAP AG 2003
The events START-OF-SELECTION, GET, END-OF-SELECTION, TOP-OF-PAGE and ENDOF-PAGE can be used only to create basic lists. Once you leave a basic list, these events are no longer
processed.
Detail lists are created using two basic events: AT LINE-SELECTION and AT USER-COMMAND.
The event TOP-OF-PAGE DURING LINE-SELECTION is used to create headers for all detail lists.
If the application displays multiple detail lists, use the CASE keyword with system field sy-lsind
detemine which secondary headings to display.
(C) SAP AG
BC405
8-5
Program Flow in Detail Lists
List
Edit
Goto
System
SY-UCOMM
Help
%EX
PRI
DEMO: List ...
P+
P...
System programs
F2
SY-UCOMM
PICK
REPORT SAPBC405_...
AT
AT LINE-SELECTION.
LINELINE-SELECTION.
 SAP AG 2003
If the user selects a menu option, pushes a pushbutton or an icon, or uses a function key, the event AT
USER-COMMAND is triggered. The function code assigned to the action can be evaluated using a
CASE construct to determine which option was selected.
If the user double-clicks on a list, the AT LINE-SELECTION event is triggered. The event can also be
triggered by single clicking on a report line and either pressing the Detail icon with the function code
PICK in the application tool bar, or using the function key F2.
(C) SAP AG
BC405
8-6
Creating Detail Lists I
REPORT sapbc405_ilbd_interact_list_1.
Basic list
...
AT
AT LINE-SELECTION.
LINELINE-SELECTION.
WRITE:
'This is a detail list'(001)
COLOR COL_TOTAL,
/ 'List level: '(002), sy-lsind, ...
User action sy-ucomm = PICK
This is a detail list
List level: 1
 SAP AG 2003
When the PICK function is triggered, the program is given control, and the interactive event AT LINESELECTION is processed. All the subsequent output (WRITE, ULINE, or SKIP) is output in a details
list.
The system field SY-LSIND indicates the current list level and is increased by one whenever event AT
LINE-SELECTION or the AT USER-COMMAND event is processed.
(C) SAP AG
BC405
8-7
Creating Detail Lists II
Basic list
sy-lsind: 0
REPORT sapbc405_ilbd_interact_lists_2.
PICK
AT
AT LINE-SELECTION.
LINELINE-SELECTION.
sysy-lsind.
lsind.
CASE sy-lsind.
WHEN 1.
'1'
WRITE: 'Detail list: 1'(001),
/'SY-LSIND: '(000), sy-lsind.
WHEN 2.
'2'
WRITE: 'Detail list: 2'(002),
/'SY-LSIND: '(000), sy-lsind.
Detail list: 1
sy-lsind: 1
PICK
Detail list: 2
sy-lsind: 2
ENDCASE.
PICK
 SAP AG 2003
The system field SY-LSIND is incremented by one each time the AT USER-COMMAND or AT LINESELECTION events are triggered. You can determine the number of the new list buffer by using a
CASE construct with the system field SY-LSIND.
You control the maximum number of detail lists that will be displayed. In the above example, no third
list is generated. If the AT LINE-SELECTION event is triggered while viewing list 2, the value of sylsind increments to three but since no WRITE, ULINE, or SKIP is executed, the system sets SY-LISIND
back to two and detail list two remains visible.
(C) SAP AG
BC405
8-8
Basic Techniques in Interactive Lists
Detaillists
lists
Detail
Datatransport
transport
Data
Othertechniques
techniques
Other
 SAP AG 2002
(C) SAP AG
BC405
8-9
HIDE Area
HIDE: <f1>, <f2>, ...
.
REPORT sapbc405_ilbd_hide .
GET spfli FIELDS carrid connid
cityfrom cityto.
DEMO: Data Transport: Hide Technique
-------------------------------------------------------AA
NEW YORK
SAN FRANCISCO
AZ
ROME
FRANKFURT
AZ
TOKYO
ROME
LH
FRANKFURT NEW YORK
WRITE: / spfli-carrid,
10 spfli-cityfrom,
(24) spfli-cityto.
HIDE area of list level 0
HIDE: spfli-carrid,
spfli-connid.
AT LINE-SELECTION.
...
Line
Field name
Value
3
3
:
6
6
:
spfli-carrid
spfli-connid
:
spfli-carrid
spfli-connid
:
AA
0017
:
LH
0400
:
 SAP AG 2003
The HIDE statement is used to store global field names and their values so they can be made available
when the User selects a report line. The runtime system automatically records the name and contents of
the data object in relation to its line position in the list currently being created. When a line is selected,
the values hidden for that line are brought back into the corresponding fields in the program.
You typically use the HIDE statement to save the key fields or other information that you’ll need next.
The HIDE keyword must be coded immediately after the last write sentence on the output line.
(C) SAP AG
BC405
8-10
Line Selection: The Hide Technique
DEMO: Data Transport: Hide Technique
-------------------------------------------------------AA
NEW YORK
SAN FRANCI
AZ
ROME
FRANKFURT
AZ
TOKYO
ROME
LH
FRANKFURT
NEW YORK
DEMO: Data Transport: Hide Technique
-------------------------------------------------------LH
400
02.01.2002
1,332.00 DEM
03.28.2002
1,332.00 DEM
04.17.2002
1,332.00 DEM
1
SY-LILLI
6
2
5
4
REPORT SAPBC405_ILBD_HIDE .
HIDE area of list level 0
Line
Field name
Value
AT
AT LINE-SELECTION.
LINELINE-SELECTION.
3
3
:
6
6
:
spfli-carrid
spfli-connid
:
spfli-carrid
spfli-connid
:
AA
0017
:
LH
0400
:
SELECT ...
WHERE carrid = spfli-carrid
LH
AND
connid = spfli-connid.
0400
3
 SAP AG 2002
The individual steps of the above example are described below:
The user selects a line for which data has been stored in the HIDE area. This can be done either by
double clicking on a line or, if the field or line was written with HOTSPOT ON, a single click will
react like a double click.The runtime system evaluates field SY-LILLI to determine the selected line:
in this case line six.
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 in the HIDE area into their
corresponding fields.
The runtime system processes the event AT LINE-SELECTION and its corresponding program
processing block.
A detail list is created.
(C) SAP AG
BC405
8-11
Detail List Buffering
HIDE area
Basic List
HIDE area 1
Detail List 1
HIDE area 2
Detail List 2
Basic List
DL 1
DL 2
...
Display
Display
Display
List buffer
Basic List
List buffer
Detail List 1
List buffer
Detail List 2
 SAP AG 2003
All the output for a list is saved in a list buffer. As a result, each list remains saved in the system until the
list buffer is deleted. All the details lists whose list level is greater than the current list level are deleted
automatically by the runtime system (that is, their list buffer is deleted). For example, when you branch
from details list five to detail list three, the list buffers of detail lists four and five are deleted.
Each list level is allocated its own HIDE area.
(C) SAP AG
BC405
8-12
Valid line selection
REPORT sapbc405_ilbd_valid_line_sel.
...
GET spfli FIELDS ...
WRITE ...
HIDE: spfli-carrid, spfli-connid.
DEMO: Data Transport: Hide Technique
-------------------------------------------------------LH
400
01/02/2002 666.00 EUR
03/28/2002 666.00 EUR
04/17/2002 666.00 EUR
END-OF-SELECTION.
CLEAR
CLEAR spfli-carrid.
spflispfli-carrid.
carrid.
HIDE area
AT LINE-SELECTION.
CHECK
CHECK NOT
NOT spfli-carrid
spfliIS INITIAL.
INITIAL.
spfli-carrid IS
...
CLEAR spfli-carrid.
spfliCLEAR
spfli-carrid.
carrid.
 SAP AG 2003
You must ensure that when you choose a line for which no data has been stored in the HIDE area, this is
interpreted as an invalid line selection. Invalid lines include headers and footers.
When necessary, you can ensure that no detail lists are created for invalid line selections.
The field spfli-carrid, whose contents have been stored in the HIDE area, is initialized in the
programming example above. If a user chooses an invalid line, the runtime system will not find a value
in the HIDE area. The field retains its initial value. The CHECK statement then reads this initial value
and the program exits the current processing block (AT LINE-SELECTION). No detail list is
generated and the current list buffer remains in view.
(C) SAP AG
BC405
8-13
Basic Techniques in Interactive Lists
Detaillists
lists
Detail
Datatransport
transport
Data
Othertechniques
techniques
Other
 SAP AG 2002
(C) SAP AG
BC405
8-14
Setting GUI Titles
SET TITLEBAR
'T01'
Double-click
[WITH <f1> <f2> ..<f9>]
Maintain title
Create Title
Program
SAPBC405_ILBD_GUI_TITLE
Title code
T01
SY-TITLE
SY-TITLE
Title
Flight data for airline &1
OK
All titles
 SAP AG 2002
Title names can be up to 20 characters in length and must be entered all in capital letters. A title that is
set stays active until a new one is set.
You can display up to 9 variables within the GUI title using SET TITLEBAR <TITLE> WITH <f1>.
The total length of title including all variables cannot exceed 70 characters in length.
(C) SAP AG
BC405
8-15
Page Headings for Detail Lists
TOP-OF-PAGE DURING LINE-SELECTION.
REPORT sapbc405_ilbd_heading_i_lists
NO STANDARD PAGE HEADING.
Basic list
TOP-OF-PAGE.
TOPDURING LINE-SELECTION
LINETOP-OFOF-PAGE DURING
LINE-SELECTION..
TOP-OF-PAGE
Detail list
 SAP AG 2003
The TOP-OF-PAGE event is only processed when you create a basic list.
The TOP-OF-PAGE DURING LINE-SELECTION event is used to create headers for each of the
detail lists. Evaluate the system field SY-LSIND to determine which headings to display.
TOP-OF-PAGE DURING LINE-SELECTION is triggered by the first output (such as WRITE) in
each new list page.
(C) SAP AG
BC405
8-16
Creating Lists in Modal Dialog Boxes
WINDOW STARTING AT <c1> <r1>
[ENDING
AT <c2> <r2>].
REPORT
sapbc405_ilbd_g_window.
DATA: ... line1 TYPE i, line2 TYPE i.
...
AT
AT LINE-SELECTION.
LINELINE-SELECTION.
...
line1 = sy-curow + 1.
line2 = line1 + 12.
WINDOW STARTING
STARTING AT
AT 10
10 line1
line1
WINDOW
ENDING
AT
65
line2.
ENDING
AT 65 line2.
´
WRITE
...
...
DEMO: Modal Dialog Box
------------------------------------------------------------AA
NEW YORK
SAN FRANCISCO
AZ
ROME
FRANKFURT
AZ
TOKYO
Demo: Modal
Box
DEMO:
ModalDialog
DialogROM
Box
LH
FRANKFURT
NEW YORK
LH
AZ 0555
LH
09/19/2003
185.00 EUR
QF
10/17/2003
185.00 EUR
QF
SQ SINGAPORE
SAN FRANCISCO
<c1> <r1>
<c2> <r2>
 SAP AG 2003
You can display the current detail list in a modal dialog box with statement WINDOW STARTING
AT.
The upper-left corner of a modal dialog box is positioned at column <c1> row <r1>. The count begins at
zero/zero in the upper-left corner of the main window. If <r1> is less than or equal to zero, the list
displays in full screen format instead of a modal dialog box.
You can use the optional parameter ENDING to set the length and width of a modal dialog box: The
lower-right corner is positioned at column <c2> row <r2>.
You can create a title for the modal dialog box with SET TITLEBAR '<title>’, as well as a modal dialog
box GUI.
(C) SAP AG
BC405
8-17
Field Selection
GET CURSOR FIELD <feld1>
[VALUE <feld2>].
REPORT sapbc405_ilbd_field_selection.
DATA: ... ,
field_name(30),field_value(50).
field_value(50).
field_name(30),
...
AT LINE-SELECTION.
GET
GET CURSOR
CURSOR FIELD
FIELD field_name
field_name
VALUE
VALUE field_value.
field_value.
field_name.
CASE field_name.
WHEN 'SPFLI-CARRID'.
'SPFLI'SPFLI-CARRID'.
...
WHEN 'SPFLI-CONNID'.
'SPFLI'SPFLI-CONNID'.
...
DEMO: Field Selection
-------------------------------------------------------CARRID CONNID CITYFROM
AA
0017
NEW YORK
AZ
0555
ROME
AZ
0789
TOKYO
LH
0400
FRANKFURT
DEMO: Field Selection
DEMO: Field Selection
LH: Lufthansa
LH
0400
19.05.2002
21.08.2002
ENDCASE.
 SAP AG 2002
You can use the GET CURSOR statement to create detail lists according to the cursor position. If a user
clicks on one of the CARRID fields in the example above, the name of the corresponding airline is
displayed. If a user clicks on one of the CONNID fields, all flight dates for that particular flight number
are displayed instead.
The parameter FIELD provides the name of an output field. The parameter VALUE provides the output
value.
The return value SY-SUBRC is set to:
● Value 0: The cursor is positioned on a field
● Value 4: The cursor is not positioned on a field
Note: Do not use the value of parameter VALUE in the WHERE condition of a SELECT statement,
because this can lead to type conversions for non-character fields that produce undesirable results. It is
better to use the HIDE technique in this case.
(C) SAP AG
BC405
8-18
System Fields for Interactive Lists
SY-LILLI
SY-LILLI
11
22
33
44
1
SY-PAGNO
SY-PAGNO
2
SY-CPAGE
SY-CPAGE
SY-LINNO
SY-LINNO
55
66
77
88
11
22
33
44
SY-CUROW
SY-CUROW
SY-CUCOL
SY-CUCOL
99
10
10
3
Basic list
SY-LSIND
SY-LSIND == 00
SY-LISTI
SY-LISTI == 00
DL 1
SY-LSIND
SY-LSIND == 11
SY-LISTI
SY-LISTI == 00
DL 2
SY-LSIND
SY-LSIND == 22
SY-LISTI
SY-LISTI == 11
...
 SAP AG 2002
The following system fields are automatically supplied with values at each interactive event:
SY-LSIND Index for the current list
SY-LISTI Index of the last list displayed
SY-LILLI Absolute number of a selected line in the list displayed
SY-CPAGE
Number of the upper-most displayed line in the list displayed
SY-CUCOL
Number of the column in the window where the cursor was last positioned in
the list displayed
SY-CUROW Number of the line in the window where the cursor was last positioned in the list
displayed
SY-STACONumber of the first column displayed in the list displayed
SY-STARONumber of the first visible line in the top displayed page (SY-PAGE) in the list
displayed (not including header lines)
SY-UCOMM Function code that triggered the interactive event in the list displayed
SY-PFKEY Status of the list displayed
(C) SAP AG
BC405
8-19
Basic Techniques in Interactive Lists: Summary
You are now able to:
Describe what detail lists are and generate them.
Identify which interactive events exist.
Transport data between lists and programs.
Recognize an invalid line selection.
Create page headers in detail lists.
Create lists in modal dialog boxes.
 SAP AG 2002
(C) SAP AG
BC405
8-20
Interactive Lists Exercises
Unit: Interactive Lists
Topic: Printing Detail Lists
When you have completed these exercises, you will be able to:
• Use interactive event AT LINE-SELECTION.
• Use the hide technique.
• Use valid line selection.
• Set GUI titles.
1-1
Copy or enhance your program Z##DAP1_..., or copy the sample solution,
SAPBC405_DAPS_1, to program Z##ILB1_... . Sample solution for exercise:
SAPBC405_ILBS_1.
The user needs to be able to display bookings for a flight in a detail list.
1-1-1 Enable the user to display the bookings for a flight in a detail list by selecting
(Format HOTSPOT) a line with the flight dates. The detail list should contain
the following fields:
bookid
(table sbook)
customid (table sbook)
form
(table scustom)
name
(table scustom)
order_date (table sbook)
class
(table sbook)
1-1-2 To do this, create an appropriate internal table in the TOP include (type:
standard) and a working area.
1-1-3 Make sure that only flights for which seats are already occupied are output in
HOTSPOT format (sflight-seatsocc > 0).
1-1-4 Output the booking number and the customer number in color COL_KEY, and
the other fields in color COL_NORMAL.
1-1-5 No other details option should be possible within the booking list.
1-2
Prevent invalid line selections.
1-3
Collect the required data for the detail list at event AT LINE-SELECTION.
1-3-1 Encapsulate the data collection and the data output in one subroutine each.
Read the data from table SBOOK and the corresponding data from table
(C) SAP AG
BC405
8-21
SCUSTOM. The key relationship between SBOOK and SCUSTOM is
SBOOK-BOOKID=SCUSTOM-ID.
There are two ways of reading the data:
You can read the data from table SBOOK in a SELECT loop and then read
the appropriate data record from SCUSTOM (SELECT SINGLE).
You can program an INNER JOIN for both tables.
1-3-2 If the user selects a flight for which no seats have yet been booked, then display
information message 004 from message class BC405.
1-4
Set a GUI title for the basic list and the detail list.
1-4-1 The title of the basic list should contain the dates specified in the selection
screen (flight connections from … to …).
(C) SAP AG
BC405
8-22
Exercises
Unit: Interactive Lists
Topic: Printing Detail Lists
When you have completed these exercises, you will be able to:
• Utilize the cursor position.
• Display lists in a modal dialog window.
• Set headers in detail lists.
2-1
Copy or enhance your program Z##ILB1_..., or copy the sample solution,
SAPBC405_ILBS_1, to program Z##ILB2_... Sample solution for exercise:
SAPBC405_ILBS_2.
Give the user an option to display additional information for airlines in a modal dialog
window.
2-1-1 Allow the user to display additional information for the airline by selecting the
airline code. To do this, output the name, short description, and the local
currency of the airline in a modal dialog window.
Position the modal dialog box in such a way that it is opened in the line that the
user has selected, but three columns further right. Use the system variables SYCUCOL and SY-CUROW.
2-1-2 To control the output of the detail list for event AT LINE-SELECTION, use
the name of the field where the cursor was positioned when the event was
triggered (GET CURSOR ... ).
2-1-3 Encapsulate the collection of the appropriate data (table SCARR) and its output
in a subroutine.
2-1-4 Display a page header in both the dialog window and in the booking list. The
booking list should contain the short name of the airline, the flight number, and
the flight date. Display column headers in the booking list.
2-1-5 Ensure that the modal dialog box has a GUI title.
(C) SAP AG
BC405
8-23
Interactive Lists Solutions
Unit: Interactive Lists
Topic: Printing Detail Lists
*&---------------------------------------------------------------------*
*& Report
SAPBC405_ILBS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
Solution; Exercise 1; Basic Techniques ...
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_ilbs_1top.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
* Title
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
WRITE: / sy-vline,
'Flight data'(001),
AT line_size sy-vline.
ULINE.
* Column header
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE: sy-vline, 'Departure location'(004),
WRITE: sy-vline, 'Arrival location'(004),
AT line_size sy-vline.
AT line_size sy-vline.
WRITE: sy-vline, AT pos_c1 'Flight'(002).
(C) SAP AG
BC405
8-24
* Fix left scroll boundary
SET LEFT SCROLL-BOUNDARY.
WRITE: 'Date'(003),
AT pos_c3 'Price'(006),
AT pos_c4 'Max.'(008),
AT pos_c5 'Occ.'(009),
AT line_size sy-vline.
ULINE.
*&---------------------------------------------------------------------*
*&
Event
INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
" OPTIONAL
* Initialize select-options for CARRID
MOVE: 'AA' TO so_car-low,
'QF' TO so_car-high,
'BT' TO so_car-option,
'I' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
MOVE: 'AZ' TO so_car-low,
'EQ' TO so_car-option,
'E' TO so_car-sign.
APPEND so_car.
CLEAR so_car.
*&---------------------------------------------------------------------*
*&
Event AT SELECTION-SCREEN ON BLOCK PARAM
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON BLOCK param.
" OPTIONAL
* check country for national flights is not empty
CHECK national = 'X' AND country = space.
MESSAGE e003(bc405).
*&---------------------------------------------------------------------*
*&
Event START-OF-SELECTION
(C) SAP AG
BC405
8-25
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Checking the output parameters
CASE mark.
WHEN all.
* Radiobutton ALL is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt.
WHEN national.
* Radiobutton NATIONAL is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr = spfli~countryto
AND spfli~countryfr = country.
WHEN internat.
* Radiobutton INTERNAT is marked
SELECT * FROM spfli INNER JOIN sflight
ON
spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INTO CORRESPONDING FIELDS OF TABLE it_flights
WHERE spfli~carrid
IN so_car
AND spfli~connid
IN so_con
AND sflight~fldate IN so_fdt
AND spfli~countryfr NE spfli~countryto.
(C) SAP AG
BC405
8-26
ENDCASE.
*&---------------------------------------------------------------------*
*&
Event END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*SORT it_flights BY carrid connid fldate.
* Control Level Processing: the internal table has to be sorted
SORT it_flights BY cityfrom cityto carrid connid.
* Data output
PERFORM data_output.
* clear hidden field for valid line selection
CLEAR: wa_flights-fldate.
* Set GUI title for base list
SET TITLEBAR 'T_BASE' WITH so_fdt-low so_fdt-high.
*&---------------------------------------------------------------------*
*&
Event AT LINE-SELECTION
*&---------------------------------------------------------------------*
AT LINE-SELECTION.
* no higher display lists allowed
CHECK sy-lsind < 2.
* only valid line selections
CHECK NOT wa_flights-fldate IS INITIAL.
IF wa_flights-seatsocc < 1.
* info message for flights without bookings
MESSAGE i004(bc405).
ELSE.
* get booking data
PERFORM booking_select.
* output for flights with bookings
(C) SAP AG
BC405
8-27
PERFORM booking_output.
* clear hidden field for valid line selection
CLEAR wa_flights-fldate.
* Set GUI title for secondary list
SET TITLEBAR 'T_LIST1'.
ENDIF.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Group Level:
CITYFROM
AT NEW cityfrom.
NEW-PAGE.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline, wa_flights-cityfrom,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Group Level:
CITYTO
AT NEW cityto.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, wa_flights-cityto,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Single Record Processing
* Hotspot off, if no bookings exist
(C) SAP AG
BC405
8-28
IF wa_flights-seatsocc < 1.
FORMAT HOTSPOT OFF.
ELSE.
FORMAT HOTSPOT ON.
ENDIF.
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
wa_flights-seatsmax,
wa_flights-seatsocc,
AT line_size sy-vline.
* Hide Fields
HIDE: wa_flights-carrid, wa_flights-connid, wa_flights-fldate,
wa_flights-seatsocc.
FORMAT RESET.
* Group Level:
CONNID
AT END OF connid.
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / sy-vline,
'Total'(007),
wa_flights-seatsmax UNDER wa_flights-seatsmax,
wa_flights-seatsocc UNDER wa_flights-seatsocc,
(C) SAP AG
BC405
8-29
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Group Level:
CITYFROM
AT END OF cityfrom.
ULINE.
ENDAT.
ENDLOOP.
ENDFORM.
" DATA_OUTPUT
*&---------------------------------------------------------------------*
*&
Form
BOOKING_OUTPUT
*&---------------------------------------------------------------------*
*
output of bookings
*----------------------------------------------------------------------*
FORM booking_output.
FORMAT COLOR COL_NORMAL.
LOOP AT it_book INTO wa_book.
WRITE: / wa_book-bookid COLOR COL_KEY,
wa_book-customid COLOR COL_KEY,
wa_book-form,
wa_book-name,
wa_book-order_date,
wa_book-class,
AT sy-linsz space.
ENDLOOP.
ENDFORM.
" BOOKING_OUTPUT
*&---------------------------------------------------------------------*
*&
Form
BOOKING_SELECT
*&---------------------------------------------------------------------*
(C) SAP AG
BC405
8-30
*
selection of booking data
*----------------------------------------------------------------------*
FORM booking_select.
REFRESH it_book.
* Selection via SELECT SINGLE
*
SELECT bookid customid class order_date FROM sbook
*
INTO CORRESPONDING FIELDS OF wa_book
*
WHERE carrid = wa_flights-carrid
*
AND connid = wa_flights-connid
*
AND fldate = wa_flights-fldate.
*
SELECT SINGLE name form telephone FROM scustom
*
INTO CORRESPONDING FIELDS OF wa_book
*
WHERE id = wa_book-customid.
*
APPEND wa_book TO it_book.
*
ENDSELECT.
* Selection via INNER JOIN
SELECT bookid customid class order_date
FROM sbook INNER JOIN scustom
ON sbook~customid = scustom~id
INTO CORRESPONDING FIELDS OF TABLE it_book
WHERE carrid = wa_flights-carrid
AND connid = wa_flights-connid
AND fldate
= wa_flights-fldate.
ENDFORM.
" BOOKING_SELECT
*&---------------------------------------------------------------------*
*& Include BC405_ILBS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
sapbc405_ilbs_1 LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
(C) SAP AG
BC405
8-31
* Linetype of internal table
TYPES: BEGIN OF linetype,
cityfrom LIKE spfli-cityfrom,
cityto
LIKE spfli-cityto,
carrid
LIKE spfli-carrid,
connid LIKE spfli-connid,
countryfr LIKE spfli-countryfr,
countryto LIKE spfli-countryto,
fldate
price
LIKE sflight-fldate,
LIKE sflight-price,
currency LIKE sflight-currency,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF linetype.
* Constants for writing position
CONSTANTS:
pos_c1 TYPE i VALUE
6,
pos_c3 TYPE i VALUE 30,
pos_c4 TYPE i VALUE 58,
pos_c5 TYPE i VALUE 68,
line_size TYPE i VALUE 100.
* Constant for CASE statement
CONSTANTS mark VALUE 'X'.
* Internal table like DDIC view DV_FLIGHTS
*
DATA: it_flights LIKE TABLE OF dv_flights,
*
wa_flights LIKE dv_flights.
* Internal table type linetype
DATA: it_flights TYPE STANDARD TABLE OF linetype,
wa_flights TYPE linetype.
* Work area and itab for bookings
DATA: BEGIN OF wa_book,
bookid LIKE sbook-bookid,
customid
(C) SAP AG
LIKE sbook-customid,
BC405
8-32
class LIKE sbook-class,
order_date LIKE sbook-order_date,
name
LIKE scustom-name,
form LIKE scustom-form,
END OF wa_book,
it_book LIKE TABLE OF wa_book.
* Selections for connections
SELECTION-SCREEN BEGIN OF BLOCK conn WITH FRAME TITLE text-tl1.
SELECT-OPTIONS: so_car FOR wa_flights-carrid,
so_con FOR wa_flights-connid.
SELECTION-SCREEN END OF BLOCK conn.
* Selections for flights
SELECTION-SCREEN BEGIN OF BLOCK flight WITH FRAME TITLE text-tl2.
SELECT-OPTIONS so_fdt FOR wa_flights-fldate NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK flight.
* Output parameter
SELECTION-SCREEN BEGIN OF BLOCK param
WITH FRAME TITLE text-tl3.
SELECTION-SCREEN BEGIN OF BLOCK radio WITH FRAME.
PARAMETERS: all RADIOBUTTON GROUP rbg1,
national RADIOBUTTON GROUP rbg1,
internat RADIOBUTTON GROUP rbg1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK radio.
PARAMETERS country LIKE wa_flights-countryfr.
SELECTION-SCREEN END OF BLOCK param.
(C) SAP AG
BC405
8-33
Solutions
Unit: Interactive Lists
Topic: Printing Detail Lists
*&---------------------------------------------------------------------*
*& Report
SAPBC405_ILBS_2
*
*&
*
*&---------------------------------------------------------------------*
*&
Solution; Exercise 2; Basic Techniques ...
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_ilbs_2top.
<<<<<<<< *************** >>>>>>>
Not all events shown here. See above for missing events
<<<<<<<< *************** >>>>>>>
*&---------------------------------------------------------------------*
*&
Event AT LINE-SELECTION
*&---------------------------------------------------------------------*
AT LINE-SELECTION.
* no higher display lists allowed
CHECK sy-lsind < 2.
* get cursor position
GET CURSOR FIELD field_name.
CASE field_name.
WHEN 'WA_FLIGHTS-CARRID'.
* Set GUI-title for the dialog box
(C) SAP AG
BC405
8-34
SET TITLEBAR 'T_LIST_MODAL'.
* output of carrier details
PERFORM carrier_output.
WHEN OTHERS.
* only valid line selections
CHECK NOT wa_flights-fldate IS INITIAL.
IF wa_flights-seatsocc < 1.
* info message for flights without bookings
MESSAGE i004(bc405).
ELSE.
* get booking data
PERFORM booking_select.
* output for flights with bookings
PERFORM booking_output.
* Set GUI title for secondary list
SET TITLEBAR 'T_LIST1'.
ENDIF.
ENDCASE.
* clear hidden fields for valid line selection
CLEAR: wa_flights-fldate, wa_flights-carrid.
*&---------------------------------------------------------------------*
*&
Event TOP-OF-PAGE DURING LINE-SELECTION
*&---------------------------------------------------------------------*
TOP-OF-PAGE DURING LINE-SELECTION.
CASE field_name.
WHEN 'WA_FLIGHTS-CARRID'.
FORMAT COLOR COL_HEADING.
WRITE: / 'Detail display'(d10).
ULINE.
WHEN OTHERS.
(C) SAP AG
BC405
8-35
* format for page headings on the detail list
FORMAT COLOR COL_HEADING.
* title of the detail list
WRITE: / 'Bookings for'(d00),
wa_flights-carrid NO-GAP,
wa_flights-connid,
wa_flights-fldate,
AT sy-linsz space.
ULINE.
* headings of the detail list
WRITE: / 'Booking'(d01),
'Customer no.'(d02),
'Title'(d03),
'Name'(d04),
'Book.date'(d05),
'Class'(d06),
AT sy-linsz space.
ENDCASE.
*&---------------------------------------------------------------------*
*&
Form
DATA_OUTPUT
*&---------------------------------------------------------------------*
*
List output of flight data
*----------------------------------------------------------------------*
FORM data_output.
* Loop at the internal table for writing data
LOOP AT it_flights INTO wa_flights.
* Group Level:
CITYFROM
AT NEW cityfrom.
NEW-PAGE.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE: / sy-vline, wa_flights-cityfrom,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
(C) SAP AG
BC405
8-36
* Group Level:
CITYTO
AT NEW cityto.
FORMAT COLOR COL_GROUP INTENSIFIED OFF.
WRITE: / sy-vline, wa_flights-cityto,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Single Record Processing
* Hotspot off, if no bookings exist
IF wa_flights-seatsocc < 1.
FORMAT HOTSPOT OFF.
ELSE.
FORMAT HOTSPOT ON.
ENDIF.
* Mark international flights
FORMAT COLOR COL_KEY INTENSIFIED ON.
IF wa_flights-countryfr EQ wa_flights-countryto.
WRITE: / sy-vline, icon_space AS ICON CENTERED.
ELSE.
WRITE: / sy-vline, icon_bw_gis AS ICON CENTERED.
ENDIF.
* Data output
WRITE: wa_flights-carrid,
wa_flights-connid.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: wa_flights-fldate,
wa_flights-price CURRENCY wa_flights-currency,
wa_flights-currency,
wa_flights-seatsmax,
wa_flights-seatsocc,
AT line_size sy-vline.
* Hide Fields
HIDE: wa_flights-carrid, wa_flights-connid, wa_flights-fldate,
wa_flights-seatsocc.
FORMAT RESET.
(C) SAP AG
BC405
8-37
* Group Level:
CONNID
AT END OF connid.
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / sy-vline,
'Total'(007),
wa_flights-seatsmax UNDER wa_flights-seatsmax,
wa_flights-seatsocc UNDER wa_flights-seatsocc,
AT line_size sy-vline.
FORMAT RESET.
ENDAT.
* Group Level:
CITYFROM
AT END OF cityfrom.
ULINE.
ENDAT.
ENDLOOP.
ENDFORM.
" DATA_OUTPUT
*&---------------------------------------------------------------------*
*&
Form
BOOKING_OUTPUT
*&---------------------------------------------------------------------*
*
output of bookings
*----------------------------------------------------------------------*
FORM booking_output.
FORMAT COLOR COL_NORMAL.
LOOP AT it_book INTO wa_book.
WRITE: / wa_book-bookid COLOR COL_KEY,
wa_book-customid COLOR COL_KEY,
wa_book-form,
wa_book-name,
wa_book-order_date,
wa_book-class,
(C) SAP AG
BC405
8-38
AT sy-linsz space.
ENDLOOP.
ENDFORM.
" BOOKING_OUTPUT
*&---------------------------------------------------------------------*
*&
Form
BOOKING_SELECT
*&---------------------------------------------------------------------*
*
selection of booking data
*----------------------------------------------------------------------*
FORM booking_select.
REFRESH it_book.
* Selection via SELECT SINGLE
*
SELECT bookid customid class order_date FROM sbook
*
INTO CORRESPONDING FIELDS OF wa_book
*
WHERE carrid = wa_flights-carrid
*
AND connid = wa_flights-connid
*
AND fldate = wa_flights-fldate.
*
SELECT SINGLE name form telephone FROM scustom
*
INTO CORRESPONDING FIELDS OF wa_book
*
WHERE id = wa_book-customid.
*
APPEND wa_book TO it_book.
*
ENDSELECT.
* Selection via INNER JOIN
SELECT bookid customid class order_date
FROM sbook INNER JOIN scustom
ON sbook~customid = scustom~id
INTO CORRESPONDING FIELDS OF TABLE it_book
WHERE carrid = wa_flights-carrid
AND connid = wa_flights-connid
AND fldate
= wa_flights-fldate.
ENDFORM.
" BOOKING_SELECT
*&---------------------------------------------------------------------*
*&
Form
(C) SAP AG
CARRIER_OUTPUT
BC405
8-39
*&---------------------------------------------------------------------*
*
selection and output of carrier data
*----------------------------------------------------------------------*
FORM carrier_output.
* Local Variables
DATA: pos_col LIKE sy-cucol.
* get scarr data
SELECT SINGLE carrname currcode INTO (carrname, currcode)
FROM scarr WHERE carrid = wa_flights-carrid.
WRITE: / 'Airline:'(d11), carrname,
/ 'Airline code:'(d12), wa_flights-carrid,
/ 'Local currency:'(d13), currcode.
* Calculate the column position
pos_col = sy-cucol + 3.
* set window
WINDOW STARTING AT pos_col sy-curow.
*&---------------------------------------------------------------------*
*& Include BC405_ILBS_2TOP
*
*&
*
*&---------------------------------------------------------------------*
REPORT
sapbc405_ilbs_2 LINE-SIZE 100 NO STANDARD PAGE HEADING.
* Include for using icons
INCLUDE <icon>.
* Linetype of internal table
TYPES: BEGIN OF linetype,
cityfrom LIKE spfli-cityfrom,
cityto
LIKE spfli-cityto,
carrid
LIKE spfli-carrid,
connid LIKE spfli-connid,
countryfr LIKE spfli-countryfr,
countryto LIKE spfli-countryto,
(C) SAP AG
BC405
8-40
fldate
price
LIKE sflight-fldate,
LIKE sflight-price,
currency LIKE sflight-currency,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF linetype.
* Constants for writing position
CONSTANTS:
pos_c1 TYPE i VALUE
6,
pos_c3 TYPE i VALUE 30,
pos_c4 TYPE i VALUE 58,
pos_c5 TYPE i VALUE 68,
line_size TYPE i VALUE 100.
* Constant for CASE statement
CONSTANTS mark VALUE 'X'.
* Internal table like DDIC view DV_FLIGHTS
*
DATA: it_flights LIKE TABLE OF dv_flights,
*
wa_flights LIKE dv_flights.
* Internal table type linetype
DATA: it_flights TYPE STANDARD TABLE OF linetype,
wa_flights TYPE linetype.
* Work area and itab for bookings
DATA: BEGIN OF wa_book,
bookid LIKE sbook-bookid,
customid
LIKE sbook-customid,
class LIKE sbook-class,
order_date LIKE sbook-order_date,
name
LIKE scustom-name,
form LIKE scustom-form,
END OF wa_book,
it_book LIKE TABLE OF wa_book.
* Variables for cursor position and output
DATA:
field_name(30),
(C) SAP AG
BC405
8-41
carrname LIKE scarr-carrname,
currcode LIKE scarr-currcode.
* Selections for connections
SELECTION-SCREEN BEGIN OF BLOCK conn WITH FRAME TITLE text-tl1.
SELECT-OPTIONS: so_car FOR wa_flights-carrid,
so_con FOR wa_flights-connid.
SELECTION-SCREEN END OF BLOCK conn.
* Selections for flights
SELECTION-SCREEN BEGIN OF BLOCK flight WITH FRAME TITLE text-tl2.
SELECT-OPTIONS so_fdt FOR wa_flights-fldate NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK flight.
* Output parameter
SELECTION-SCREEN BEGIN OF BLOCK param
WITH FRAME TITLE text-tl3.
SELECTION-SCREEN BEGIN OF BLOCK radio WITH FRAME.
PARAMETERS: all RADIOBUTTON GROUP rbg1,
national RADIOBUTTON GROUP rbg1,
internat RADIOBUTTON GROUP rbg1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK radio.
PARAMETERS country LIKE wa_flights-countryfr.
SELECTION-SCREEN END OF BLOCK param.
(C) SAP AG
BC405
8-42
SAP Grid Control
Contents:
SAP Grid Control - Standard Application
Preview of Other Techniques
 SAP AG 2002
(C) SAP AG
BC405
9-1
SAP Grid Control: Unit Objectives
At the conclusion of this unit, you will be able to:
Explain how the SAP Grid Control collects and
formats data
Name the standard functions
Explain how the control can be used for basic
interactive reporting
 SAP AG 2002
(C) SAP AG
BC405
9-2
SAP Grid Control
SAPGrid
GridControl:
Control: Simple
Simple Application
Application
SAP
MoreComplex
ComplexTechniques
Techniques
More
Outlook
Outlook
 SAP AG 2002
(C) SAP AG
BC405
9-3
Controls:
Technical Background I
SAP Grid Control: What are controls?
Independent binary software components
Installed locally on the frontend using SAPGUI
Move functions from the application server to the frontend
Have a wrapper class in ABAP Objects
Intended for reuse
 SAP AG 2002
This task is performed by the SAP Control Framework.
The R/3 System allows you to create custom controls using ABAP Objects. The application server is the
Automation Client, which drives the custom controls (automation server) at the frontend.
If custom controls are to be included on the frontend, then the SAPGUI acts as a container for them.
Custom controls can be ActiveX Controls or JavaBeans.
The system uses a Remote Function Call (RFC) to transfer methods for creating and using a control to
the front end.
ABAP objects are used to implement the controls in programs.
(C) SAP AG
BC405
9-4
Controls:
Technical Background II
Area
Custom container
control
Every control that you want to
display on the screen must be
allocated to a container control. The
diagram to the left shows how a
custom container control is used to
integrate an SAP grid control. A
container defined in the Screen
Painter must be used to define an
area that the custom container
control is supposed to fill.
SAP Grid Control
 SAP AG 2003
An SAP Container can contain other controls (for example, SAP Grid Control, Tree Control, SAP
Picture Control, SAP Splitter Control, and so on). The SAP Container administers these controls
logically in one collection and provides a physical area for the display.
Every control exists in a container. Since containers are themselves controls, they can be nested within
one another. The container becomes the parent of its control. SAP containers are divided into five
groups:
SAP custom container: Displays within an area defined in Screen Painter on screens or subscreens.
Class: CL_GUI_CUSTOM_CONTAINER
SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
CL_GUI_DIALOGBOX_CONTAINER
SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as a
modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
SAP splitter container: Displays and groups several controls in one area - that is, splits the area into cells
Class: CL_GUI_SPLITTER_CONTAINER
SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar.
Class: CL_GUI_EASY_SPLITTER_CONTAINER.
(C) SAP AG
BC405
9-5
SAP Grid Example and Standard Functions
Details
Find
Sort
Total
Filter
Download
Print
Display variant
Toolbar
AA
AA
AA
AA
LH
LH
LH
LH
LH
17
17
17
64
400
400
400
402
402
08/24/2003
09/21/2003
10/19/2003
10/15/2003
08/24/2003
09/21/2003
10/19/2003
09/21/2003
10/19/2003
422.94
422.94
422.94
422.94
666.00
666.00
666.00
666.00
666.00
USD
USD
USD
USD
EUR
EUR
EUR
EUR
EUR
A321
A321
747-400
747-400
A310-300
A310-300
A310-300
A319
A319
 SAP AG 2003
Within the control, you can manually make the columns wider and narrower or use the AutoFit function.
You can also rearrange the columns by dragging a selected column to the new position.
Standard functions are available in the control toolbar. The detailed display appears as a modal dialog
box containing all the fields in the row (including hidden ones) at the current cursor position.
The ALV control supports the Sort function for any number of columns. You can define complex sort
criteria and sort the columns in ascending or descending order.
You can use the Find function to search for a string in rows or columns within a selected area (wildcard
search does not require *).
You can calculate totals for one or more numerical columns. You can then use the Subtotals function to
set up control level lists. Select the columns (non-numeric fields only) to calculate and the system
displays the appropriate control level totals.
When you print or download, the system always processes the complete list, not just the displayed screen
sections.
You can define display variants to meet your own specific requirements. Saving variants: See Other
Techniques
(C) SAP AG
BC405
9-6
SAP Grid Control: Principle
Data source
SELECT ...
GET ...
Query
Interface
SAP GRID CONTROL
Collect data in
an internal table
Field description
• Field catalog
• DIC Structure
List
Display data from
internal table
according to field
description and
standard functions
like sorting and totals
QuickView
 SAP AG 2002
The SAP grid control is a generic tool for displaying lists in screens. The control offers standard
functions such as sorting by any column, adding numeric columns, and fixed lead columns
Data collection is performed in the program using SELECT statements or GET eventsse. The data
records are saved in an internal table and passed on to the SAP control along with a field description.
The field description contains information about the characteristics of each column, such as the column
header and output length. This information can defined either globally in the Dictionary (structure in the
Dictionary) or in the field catalog in the program itself. You can also merge both techniques.
The SAP link is a standard function of Query and QuickViewer. If multiline queries or QuickView lists
have been defined, they will automatically compress into a single line and output in the SAP control as a
long, single line list.
(C) SAP AG
BC405
9-7
Implementing the Control: Screen
Create in Screen Painter:
Screen 100
Create in Menu Painter:
Status
MY_CONTROL_AREA
C
Create layout in Screen
Painter
100
In the flow logic of screen 100
PBO
PAI
Define status
OK_CODE processing for BACK, EXIT, and CANCEL
 SAP AG 2002
Use Screen Painter to create a container for the SAP grid control. The control requires an area where it
can be displayed in the screen. You have to create a container control that determines this area.
Use the corresponding icon in the Screen Painter layout to create the container control. The size of area
MY_CONTROL_AREA determines the subsequent size of the SAP control.
A dialog status with the standard BACK, EXIT, and CANCEL functionality must be set during the PBO
event. You must also add the necessary coding for these function codes in the PAI event.
(C) SAP AG
BC405
9-8
Implementation in the Program
Container control
* CONTROLS
DATA: g_custom_container
TYPE REF TO cl_gui_custom_container,
sap_grid
TYPE REF TO cl_gui_alv_grid.
SAP Grid Control
SAP grid control can be displayed using class
CL_GUI_ALV_GRID.
 SAP AG 2002
The reference variables for the custom container and the ALV grid control must be declared.
To create reference variables, use ABAP statement TYPE REF TO <class name>.
The global classes you need to do this are called cl_gui_custom_container (for the custom container
control) and cl_gui_alv_grid (for the SAP grid control).
The global classes are defined in the Class Builder. You can use the Class Builder to display information
for the methods, their parameters, exceptions, and so on.
(C) SAP AG
BC405
9-9
Generating and Linking Objects
MODULE create_objects OUTPUT.
IF g_custom_container IS INITIAL.
CREATE
CREATE OBJECT
OBJECT g_custom_container
EXPORTING container_name = 'MY_CONTROL_AREA'.
CREATE
CREATE OBJECT
OBJECT sap_grid
EXPORTING i_parent = g_custom_container.
C
ENDIF.
ENDMODULE.
" CREATE_OBJECTS
OUTPUT
 SAP AG 2002
Use ABAP statement CREATE OBJECT <name> to create the objects for the container and the ALV
control. Objects are instances of a class.
When an object is created (CREATE), method CONSTRUCTOR of the corresponding class is
executed. The parameters of method CONSTRUCTOR determine which parameters have to be supplied
with data when the object is created. In the above example, object sap_grid is given the name of the
container control (g_custom_container) in exporting parameter i_parent, which links the two controls.
For information on which parameters method CONSTRUCTOR possesses and which of these
parameters are required, see the Class Builder.
Objects should only be created once during the program. To ensure that this is the case, enclose the
CREATE OBJECT statement(s) in an IF <object_name> IS INITIAL. ... ENDIF clause. The objects
must be generated before the control is displayed for the first time - that is, during the PBO event of the
ALV subscreen container.
(C) SAP AG
BC405
9-10
Program Flow
START-OF-SELECTION
Internal table with data
Description of columns
Field catalog
itab_sflight
A
B
DIC
sflight
C
SELECT * FROM
A
B
sflight ...
A
B
C
C
CALL SCREEN 100.
Process Before Output
Process After Input
MODULE status_0100.
MODULE exit AT EXIT-COMMAND.
MODULE create_objects.
MODULE user_command_0100.
MODULE transfer_data.
 SAP AG 2002
To display the requested dataset in the SAP Grid Control, the data must be passed on to the control as an
internal table, and a field description must exist indicating the order in which the columns will be output.
In the simplest case, the field description can use a structure from the Dictionary. The Dictionary also
determines the technical field attributes like type and length, as well as the semantic attributes like short
and long texts. The SAP Grid Control uses this information to determine the column widths and headers.
The column sequence is determined by the field sequence in the structure.
If no suitable structure is active in the Dictionary, or you want to output internal program fields in the
control, then you will have to define information like the output length and column header in the field
catalog.
In a typical report application, the data is read first using SELECT...INTO TABLE or using a logical
database and then APPEND/INSERT the data into an internal table. When the data retrieval is
complete, the ABAP statement CALL SCREEN <number> is used to call the screen containing the
SAP Grid Control.
(C) SAP AG
BC405
9-11
Displaying the Data in the Control
Process Before Output
MODULE status_0100.
MODULE create_objects.
MODULE transfer_data.
MODULE transfer_data OUTPUT.
CALL METHOD sap_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab
= itab_sflight.
ENDMODULE.
" TRANSFER_DATA OUTPUT
SET_TABLE_FOR_FIRST_DISPLAY is a method of class
CL_GUI_ALV_GRID.
 SAP AG 2002
The data transfer to the ALV control takes place during the call of method set_table_for_first_display
from class cl_gui_alv_grid. The method call must be programmed at the PBO event of the screen with
the SAP Grid Control container.
The name of the Dictionary structure that supplies the field description is specified in exporting
parameter i_structure_name. The name of the internal table that contains the data records to display is
specified in changing parameter it_outtab.
(C) SAP AG
BC405
9-12
SAP Grid Control
SAPGrid
GridControl:
Control: Simple
Simple Application
Application
SAP
MoreComplex
ComplexTechniques
Techniques
More
Outlook
Outlook
 SAP AG 2002
(C) SAP AG
BC405
9-13
Field Catalog
You want to output internal fields, such as
available seats, in the SAP grid control
TYPES: BEGIN OF t_con,
carrid like sflight-carrid,
...
free_seat
LIKE sflight-seatsmax,
free_seats
icon_name (30),
Additional fields
Available seats
END OF t_con.
DATA: gt_outtab type STANDARD TABLE OF t_con,
...
gt_fieldcat
TYPE
lvc_t_fcat,
,
lvc_t_fcat
gt_fieldcat
TYPE
lvc_t_fcat,
lvc_t_fcat
wa_fieldcat LIKE line of gt_fieldcat.
Output table
Field catalog
 SAP AG 2002
The field description for the SAP Grid Control can be taken from an active Dictionary structure (fully
automatic), by passing a field catalog (manual), or through a mixture of the two options (merge).
The field catalog is in internal table with type lvc_t_fcat. This type is defined globally in the Dictionary.
Each line in the field catalog table corresponds to a column in the SAP control.
(C) SAP AG
BC405
9-14
Selected Fields in the Field Catalog
Table type lvc_t_fcat has a global DIC definition.
• fieldname
Field name in output table
• ref_table
Name of DIC reference structure
• ref_field
Name of DIC reference field
• inttype
Data type (c, f, i, ...)
•outputlen
Column width
• coltext
Column header
• seltext
Field name in detail view
• col_pos
Column position
• no_out
Column hidden
• icon
Output columns as icon
 SAP AG 2002
The field characteristics (= column characteristics) are defined in the field catalog. The field catalog is in
internal table with type lvc_t_fcat. Each line that is explicitly described in the ALV control corresponds
to a column in the field catalog table.
The link to the data records to output that are saved in internal table <outtab> is established through field
name <outtab-field>. This name must be specified in column fieldname in the field catalog.
This field can be classified through a Dictionary reference (ref_table and ref_field) or by specifying an
ABAP data type (inttype).
Column headers and field names in the detail view of an SAP control line can be determined in the field
catalog in coltext and seltext, respectively.
The position of a field during output can be determined with col_pos in the field catalog.
If you want to hide a column, fill field no_out with an X in the field catalog. Hidden fields can be
displayed again in a user display variant.
Icons can be displayed in the SAP control. If you want a column to be interpreted as an icon, then the
icon name must be known to the program (include <icon>.) and icon = X must be specified for this
column in the field catalog.
(C) SAP AG
BC405
9-15
Filling and Passing On the Field Catalog
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'FREE_SEATS'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-ref_field = 'SEATSMAX'.
wa_fieldcat-coltext
= text-001.
wa_fieldcat-seltext
= text-001.
wa_fieldcat-col_pos
= pos_free.
APPEND wa_fieldcat TO gt_fieldcat.
Fill field catalog
for additional fields
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ICON_NAME'.
wa_fieldcat-icon = 'X'.
" Displayed as Icon
wa_fieldcat-coltext
= text-001.
wa_fieldcat-seltext
= text-001.
wa_fieldcat-col_pos
= pos_icon.
APPEND wa_fieldcat TO gt_fieldcat.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab
= gt_outtab
it_fieldcatalog
=
gt_fieldcat.
gt_fieldcat
it_fieldcatalog = gt_fieldcat.
gt_fieldcat
 SAP AG 2002
The above example shows a semi-automatic field description: Part of the field description comes from
the Dictionary structure (sflight), while another part is explicitly defined in the field catalog
(gt_fieldcat).
The field catalog (internal table) which fills in the program, passes on together with the name of the
Dictionary structure during the method call. The information merges accordingly in method
set_table_for_first_display.
(C) SAP AG
BC405
9-16
Grid Layout Options
Which parameters of the SET_TABLE_FOR_FIRST_DISPLAY method must be filled, and
in which situations?
Structure types in the
ABAP Dictionary
A1 A2 A3
F1
F1
Data table in the
calling program
Display in the
SAP Grid Control
F1
F2 F3 F4
B1 B2 B3 B4
F2 F3 F4 Z
F2 F3 F4
F1
A2 B2 B4 Z
Z
F2 F3 F4
A2
B2 B4 Z
Parameter
I_STRUCTURE_NAME
Parameter
IT_FIELDCATALOG
 SAP AG 2002
Field catalogs are created in one of the following three ways depending on the line type used by the data
table:
Case 1:
All the fields of the global structure type have an identically-named column in the data table. You want
to display precisely these columns. In this case, you can have the proxy instance generate the field
catalog. You need only pass the name of the global structure type. Data table columns are not displayed
on the screen unless they are defined in the global structure type.
Case 2:
All fields of the global structure type have an identically-named column in the data table, but you want
to adapt the attributes derived from the ABAP Dictionary or you want to add columns or both.
In this case, you need to add lines in the field catalog matching the columns you want to add or change.
Case 3:
Either there are no Dictionary references in the line type of the data table or there are references only for
some of the global structure fields. In this case, the calling program must generate the field catalog from
scratch.
(C) SAP AG
BC405
9-17
Saving Display Variants
* Save variants
data: gs_variant type disvariant,
x_save.
* Filling variant structure
* At least the report name has to be filled
gs_
gs
variant
sy
repid
gs_
variantreport == sysycprog.
gs__variantvariant--report
sy--repid.
cprog
*Determine saving options.
x_save = 'A'.
"The user may save ALL types of variants
CALL METHOD sap_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_
= gs_
is_variant
gs_variant
i_save
= x_save
is_layout
= gs_layout
CHANGING
it_outtab
it_fieldcatalog
=
=
gt_outtab
gt_fieldcat.
 SAP AG 2002
For a user to save display variants, parameters is_variant and i_save must be passed on during method
call set_table_for_first_screen. To assign display variants uniquely to a program, at least the program
name must be supplied in the transferred structure (gs_variant). Program names can be up to 30
characters long.
If you only pass on the current parameters for is_variant, then existing variants can be loaded, but no
new ones can be saved. If you use parameter i_save, you must pass on a variant structure with
is_variant.
I_SAVE = SPACE No variants can be saved.
I_SAVE = 'U'
The user can only save user-specific variants.
I_SAVE = 'X'
The user can only save general (shared) variants.
I_SAVE = 'A'
The user can save both user-specific and general (shared) variants.
(C) SAP AG
BC405
9-18
Filling and Passing On the Layout Structure
* Layout
DATA: gs_layout TYPE lvc_s_layo.
* Filling laoyout structure
gs_layout-grid_title = 'SAP Grid Title'(002).
gs_layout-detailtitl = 'Detail Title'(003).
gs_layout-zebra = 'X'.
CALL METHOD sap_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_variant
= gs_variant
i_save
= x_save
is_layout = gs_layout
= gs_layout
is_layout
CHANGING
it_outtab
it_fieldcatalog
=
=
gt_outtab
gt_fieldcat.
 SAP AG 2002
You can use parameter is_layout of method set_table_for_first_display, for example, to define the
header in the ALV control and the detail display.
To do this, define a query area <gs_layout> in the program in accordance with Dictionary structure
lvc_s_layo, and pass on the text to display in field <gs_layout>-grid_title or <gs_layout>-detailtitl.
If you want to create print lists with zebra stripes, set field <gs_layout>-zebra to X. You can display a
print preview for print lists by requesting standard function Print.
(C) SAP AG
BC405
9-19
Interface to Display Method
CALL METHOD sap_grid->set_table_for_first_display
EXPORTING i_structure_name =
Name of structure, table, or view
is_variant =
Display variants
i_save =
Save display variant
i_default =
Select initial layout
is_layout =
Change technical configuration
is_print =
Parameters for printing on backend
it_special_groups =
Groupings
it_toolbar_excluding = Hide standard functions
CHANGING
it_outtab =
Output table
it_fieldcatalog =
Field catalog
it_sort =
Sort criteria for first list output
it_filter =
Filter criteria for first list output
 SAP AG 2002
All parameters of method SET_TABLE_FOR_FIRST_DISPLAY from global class
CL_GUI_ALV_GRID are defined in the Class Builder.
(C) SAP AG
BC405
9-20
SAP Grid Control
SAPGrid
GridControl:
Control: Simple
Simple Application
Application
SAP
MoreComplex
ComplexTechniques
Techniques
More
Outlook
Outlook
 SAP AG 2002
(C) SAP AG
BC405
9-21
Mouse Operations
DOUBLE_CLICK (double-clicking a cell or row)
Export parameters:
( E_ROW (line ID, type LVC_S_ROW)
< INDEX (line number in data table)
( E_COLUMN (column ID, type LVC_S_COL)
< FIELDNAME (column name in data table)
Air... Flug... Datum
Preis Währ...
17 2000-01-17 513,69 USD
AA
17 2000-02-20 513,69 USD
AA
17 2000-03-11 513,69 USD
AA
64 2000-05-19 369,00 USD
AA
400 2000-01-13 1234,56 DEM
LH
400 2000-02-16 1234,56 DEM
LH
400 2000-03-21 1234,56 DEM
LH
400 2000-03-04HOTSPOT_CLICK
LH
1234,56 DEM (clicking a hot spot)
Export parameters:
402 2000-05-28 1234,56 DEM
LH
( E_ROW_ID (line ID, type LVC_S_ROW)
< INDEX (line number in data table)
( E_COLUMN (column ID, type LVC_S_COL)
< FIELDNAME (column name in data table)
 SAP AG 2002
If the user double-clicks a data area, the DOUBLE_CLICK event is triggered in the calling program.
The export parameters contain information about the data table. Note that both parameters are structures.
E_ROW:
The INDEX field contains the line number in the internal table that belongs to the double-clicked row
in the data area.
E_COLUMN:
The FIELDNAME field contains the name of the column in the internal table that belongs to the
double-clicked cell in the data area.
If a column is characterized as a hot spot, the HOTSPOT_CLICK event is triggered when the user
clicks this column in the data area. The export parameters are filled in a similar way to those of the
DOUBLE_CLICK event.
For further information about other mouse operation events, refer to the online documentation.
(C) SAP AG
BC405
9-22
Outlook: Handling Events I
Events are defined in class CL_GUI_ALV_GRID, such as DOUBLE_CLICK
DOUBLE_CLICK.
 SAP AG 2002
Events are defined in global class cl_gui_alv_grid; you can use these events to implement user
interaction within the program. To respond to a double-click on a table line, you must respond to event
DOUBLE_CLICK.
You receive control in the program, allowing you to implement interactive reporting - such as a fullscreen details list. The events for cl_gui_alv_grid are located in the Class Builder.
(C) SAP AG
BC405
9-23
Outlook: Handling Events II
Definition of a local class
CLASS lcl_ils DEFINITION.
PUBLIC SECTION.
METHODS on_dblclick FOR EVENT double_click
OF cl_gui_alv_grid IMPORTING e_row.
ENDCLASS.
CLASS class lcl_ils IMPLEMENTATION.
METHOD on_dblclick .
Implementing a local
class with handler
method
[ own functionality ].
ENDMETHOD.
ENDCLASS.
DATA sap_dblclick TYPE REF TO lcl_ils.
Generating the object
Registration of
handler method
for event double_click
CREATE OBJECT sap_dblclick.
SET HANDLER sap_dblclick->on_dblclick
FOR alv_grid.
 SAP AG 2003
To define and implement a local class in the program, you use a handler method. In this handler method,
you program the functionality to trigger by a double-click in the output table.
To activate a handler method at runtime, a class or an object from that class registers itself with an event
using command SET HANDLER. The names of the IMPORTING parameters in the handler method
correspond to the names of the EXPORTING parameters of the related event.
In the above example, the local class is LCL_ILS and the handler method is ON_DBLCLICK. An
object - SAP_DBLCLICK - is created and registers itself for event DOUBLE_CLICK.
You can query parameter e_row-index to determine which output line was requested by the double-click.
This parameter corresponds to the line number of the output table (internal table with the data records to
output). If you need information for the selected line, you have to read it with READ TABLE itab
INDEX e_row-index.
This subsequent read in the output table generally corresponds to the HIDE area in conventional
reporting. You first have to make sure that the user has double-clicked a line in the output table (similar
to the valid line selection with the HIDE technique).
(C) SAP AG
BC405
9-24
Demo Programs Delivered for the SAP Grid Control
Package
Programs
Demonstrates
SLIS
BCALV_GRID_01
Print list events
BCALV_GRID_02
Basic and detail lists with an instance
BCALV_GRID_03
Detail list in a modal dialog box
BCALV_GRID_04
Threshold value handling (exceptions/traffic light icons)
BCALV_GRID_05
Adding your own functions to the application toolbar
BCALV_GRID_06
Context menus
BCALV_GRID_07
Adding your own menus to the application toolbar
BCALV_GRID_08
Menu with standard pushbutton
BCALV_GRID_09
Options for managing display variants
BCALV_GRID_10
Initial use of display variants
 SAP AG 2003
As well as these demonstration and test programs, you will also find other Repository objects for the
SAP Grid Control in the SLIS package.
This package is part of the standard SAP R/3 System - that is, it is always delivered with the ABAP
Workbench.
You can also analyze and execute these and other demonstration and test programs in a comfortable test
environment. In the ABAP Workbench, choose Environment Examples Control examples.
(C) SAP AG
BC405
9-25
ALV Grid Control: Unit Summary
You are now able to:
Explain how the SAP Grid Control collects and
formats data
Name the standard functions
Explain how the control can be used for basic
interactive reporting
 SAP AG 2002
(C) SAP AG
BC405
9-26
ALV Grid Control Exercises
Unit: ALV Grid Control
Topic: Using the ALV Grid Control to Output a List
When you have completed these exercises, you will be able to:
• Use the applications of the ALV grid control
1-1
Copy template SAPBC405_ALVT_1 to program Z##ALV1_... . Copy all the program
objects (including screens, GUI status, and so on). Sample solution for exercise:
SAPBC405_ALVS_1.
The OK code processing for screen 100 is included in the template (BACK, EXIT,
CANCEL). Do not work in the Screen Painter.
All the necessary program objects are contained in the TOP include.
1-1-1 Familiarize yourself with the program.
2-1
Read data from table SFLIGHT and display the data on screen 100 in an ALV grid
control.
2-1-1 Calculate the number of free seats.
2-1-2 Include the following fields in the ALV control:
carrid, connid, fldate, price, planetype, seatsmax, seatsocc, paymentsum,
free_seats.
Use the method SET_TABLE_FOR_FIRST_DISPLAY of class
CL_GUI_ALV_GRID.
2-1-3 Place the field free_seats in position 10 and make sure that the column is
colored (for example, colour 3, intensified display).
3-1
Change the layout.
3-1-1 Enter a title in the control and the detail view. Use text elements so that the text
can be translated.
3-1-2 Create a striped pattern (zebra).
(C) SAP AG
BC405
9-27
ALV Grid Control Solutions
Unit: ALV Grid Control
Topic: Using the ALV Grid Control to Output a List
*&---------------------------------------------------------------------*
*&
SAPBC405_ALVS_1
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
INCLUDE bc405_alvs_1top.
*&---------------------------------------------------------------------*
*&
Event START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF wa_outtab
WHERE carrid IN so_car.
wa_outtab-free_seats = wa_outtab-seatsmax - wa_outtab-seatsocc.
APPEND wa_outtab TO gt_outtab.
ENDSELECT.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&
Module
STATUS_0100
OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'S100'.
(C) SAP AG
BC405
9-28
SET TITLEBAR 'T100'.
ENDMODULE.
" STATUS_0100
OUTPUT
*&---------------------------------------------------------------------*
*&
Module
EXIT
INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE exit INPUT.
LEAVE PROGRAM.
ENDMODULE.
" EXIT
INPUT
*&---------------------------------------------------------------------*
*&
Module
USER_COMMAND_0100
INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
MOVE ok_code TO save_ok_code.
CLEAR ok_code.
CASE save_ok_code.
WHEN 'BACK'.
CALL METHOD g_custom_container->free.
LEAVE TO
SCREEN 0.
WHEN 'EXIT'.
CALL METHOD g_custom_container->free.
LEAVE TO
SCREEN 0.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0100
INPUT
*&---------------------------------------------------------------------*
*&
Module
CREATE_OBJECTS
OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE create_objects OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
(C) SAP AG
BC405
9-29
EXPORTING container_name = 'MY_CONTROL_AREA'.
CREATE OBJECT alv_grid
EXPORTING i_parent = g_custom_container.
ENDIF.
ENDMODULE.
" CREATE_OBJECTS
OUTPUT
*&---------------------------------------------------------------------*
*&
Module
TRANSFER_DATA
OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE transfer_data OUTPUT.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
is_layout
=
gs_layout
it_outtab
=
gt_outtab
it_fieldcatalog
=
gt_fieldcat.
CHANGING
ENDMODULE.
" TRANSFER_DATA OUTPUT
*&---------------------------------------------------------------------*
*&
Module
FIELD_CATALOG
OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE field_catalog OUTPUT.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'FREE_SEATS'.
wa_fieldcat-ref_table = 'SFLIGHT'.
wa_fieldcat-coltext
= 'Free seats'(001).
wa_fieldcat-seltext
= 'Free seats'(001).
wa_fieldcat-col_pos
=
wa_fieldcat-emphasize =
(C) SAP AG
pos_free.
'C310'.
BC405
9-30
APPEND wa_fieldcat TO gt_fieldcat.
ENDMODULE.
" FIELD_CATALOG
OUTPUT
*&---------------------------------------------------------------------*
*&
Module
LAYOUT
OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE layout OUTPUT.
gs_layout-grid_title = 'ALV Grid Title'(002).
gs_layout-detailtitl = 'Detail Title'(003).
gs_layout-zebra = 'X'.
ENDMODULE.
" LAYOUT
OUTPUT
*&---------------------------------------------------------------------*
*& Include BC405_ALVS_1TOP
*
*&
*
*&---------------------------------------------------------------------*
PROGRAM
sapbc405_alvs_1 .
TYPES: BEGIN OF t_con,
carrid
LIKE sflight-carrid,
connid
LIKE sflight-connid,
fldate
LIKE sflight-fldate,
price
LIKE sflight-price,
currency LIKE sflight-currency,
planetype
LIKE sflight-planetype,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
paymentsum LIKE sflight-paymentsum,
free_seats LIKE sflight-seatsmax,
END OF t_con.
(C) SAP AG
BC405
9-31
* OK code handling
DATA: ok_code LIKE sy-ucomm,
save_ok_code LIKE sy-ucomm.
* Data, which will be displayed in the ALV Control
DATA: gt_outtab TYPE STANDARD TABLE OF t_con,
wa_outtab TYPE t_con.
* Field position
DATA: pos_free TYPE i VALUE 10.
* Fieldcatalog
DATA:
gt_fieldcat TYPE lvc_t_fcat,
wa_fieldcat LIKE LINE OF gt_fieldcat.
* Layout
DATA: gs_layout TYPE lvc_s_layo.
* CONTROLS
DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
alv_grid TYPE REF TO cl_gui_alv_grid.
* Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK connection WITH FRAME.
SELECT-OPTIONS: so_car FOR wa_outtab-carrid.
SELECTION-SCREEN END OF BLOCK connection.
(C) SAP AG
BC405
9-32
Appendix
Contents:
Additional slides
 SAP AG 2002
(C) SAP AG
BC405
10-1
Calling an LDB with a Function Module
Function module LDB_PROCESS
* Start of Logical Database
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname
= 'F1S'
*
VARIANT
=
*
EXPRESSIONS
=
*
FIELD_SELECTION
=
TABLES
callback
= call_back_tab
selections
= sel_tab.
LDB does not have to be entered
in the program attributes
Several LDBs can be used in a
single program
LDBs are also available in
interactive reporting
The same LDB can be called
several times in a program
 SAP AG 2002
Previously, logical databases (LDB) could only be used in executable programs. To do this, the name of
the logical database had to be entered in the program attributes for the GET events to be available to the
program. In particular, this means that logical databases could not be used for interactive reporting or
module pools. Starting in Release 4.5, a logical database can be processed using function module
LDB_PROCESS.
Function module LDB_PROCESS can be used to call each logical database exactly one time. If you
need to process the same logical database several times over the course of the program, you have to
modify the database program for this functionality.
A multiple call is not involved when the logical database is entered in the program attributes. The LDB
can then be called again with function module LDB_PROCESS.
(C) SAP AG
BC405
10-2
Using Callback Form Routines
Structure
Structure of
of F1S
F1S
SPFLI
SFLIGHT
SBOOK
PROGRAM SAPDBF1S
DEFINING DATABASE F1S.
...
FORM PUT_SPFLI.
SELECT * FROM SPFLI ...
PUT
PUT SPFLI.
SPFLI.
ENDSELECT.
ENDFORM.
FORM PUT_SFLIGHT.
SELECT * FROM SFLIGHT .
PUT SFLIGHT.
SFLIGHT.
PUT
ENDSELECT.
ENDFORM.
FORM PUT_SBOOK.
SELECT * FROM SBOOK ...
PUT SBOOK.
SBOOK.
PUT
ENDSELECT.
ENDFORM.
REPORT
sapbc405_ldbd_ldb_process.
CALL FUNCTION 'LDB_PROCESS' ...
FORM call_back_spfli
call_back_spfli
USING name LIKE ldbn-ldbnode
workarea TYPE spfli
mode
TYPE c
selected TYPE c.
FORM call_back_sflight
call_back_sflight
USING name LIKE ldbn-ldbnode
workarea TYPE sflight
mode
TYPE c
selected TYPE c.
FORM call_back_sbook
call_back_sbook
USING name LIKE ldbn-ldbnode
workarea TYPE sbook
mode
TYPE c
selected TYPE c.
FORM LDB_PROCESS_INIT.
LDB_SUBRC = 0.
ENDFORM.
Multiple call
 SAP AG 2002
In principle, the interaction between the logical database and function module LDB_PROCESS is
analogous to the interaction during GET events. You pass on the name of the LDB to call when you call
the function module.
An internal table and a table work area have to be created in accordance with Data Dictionary structure
ldbcb. This table collects the nodes to process and the names of the callback subroutines, which are
passed on during the function module call. The individual table fields have the following meanings:
LDBNODE
GET X
Name of the node to process
Process the GET event of the above node
GET_LATE X Process the GET LATE event of the above node
CB_PROG
Name of the program containing the callback subroutine
CB_FORM
Name of the callback subroutine
When you call the logical database, you have to make sure that the selection screen is supplied with
valid values. An internal table and a table work area have to be created in accordance with Data
Dictionary structure ldbcb. This table is used to pass the selection criteria on to the logical database.
To enable a logical database for multiple processing, you have to add subroutine LDB_PROCESS_INIT
to the database program.
(C) SAP AG
BC405
10-3
Checking Internal Program Selections
Are dynamic selections
allowed in this table?
Selections
Dep. time
Price
REPORT
08:00:00
23:00:00
SPFLI
YES
500.00
1000.00
SFLIGHT
NO
sapbc405_ldbd_ldb_process_sel.
SELECT-OPTIONS:
SELECTSELECT-OPTIONS: sdepart FOR spfli-deptime
DEFAULT '08000' TO '230000',
sprice FOR sflight-price
DEFAULT '500' TO '1000'.
...
FORM call_back_sflight
USING name LIKE ldbn-ldbnode
workarea TYPE sflight
mode
TYPE c
selected TYPE c.
* check of selection criteria sprice
IF NOT
NOT workareaworkarea-price
IN sprice.
sprice.
IF
-price IN
.
workarea
sprice
selected = space.
EXIT.
ENDIF.
 SAP AG 2002
selected = space
SFLIGHT
SBOOK
SFLIGHT
SBOOK
Negative
CHECK
Positive
CHECK
If you specify a logical database in your program with function module LDB_PROCESS and declare
additional selections in the program attributes that refer to the fields of a node not designated for
dynamic selection, the program must contain a check as to whether the current data record fulfills the
selection criteria.
If the check fails, you have to set parameter selected in the subroutine to space to ensure that deeper
hierarchy nodes are not processed.
(C) SAP AG
BC405
10-4
Download