Taw10 Part1 6 (1) .10-Col32 PDF
Taw10 Part1 6 (1) .10-Col32 PDF
Taw10 Part1 6 (1) .10-Col32 PDF
TAW10 1/2
ABAP Workbench
Fundamentals
SAP AG 2003
SAP AG
R/3 System
Release 4.6D or above
2003/Q2
Material number 5006 0990
SAP AG
TAW10
0-1
Copyright
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.
SAP AG
TAW10
0-2
TAW10
10 days
TAW12
15 days
mySAP Technology
- ABAP Workbench
Concepts
Development
consultant
certification
mySAP Technology
ABAP Workbench
SAP AG 2003
SAP AG
TAW10
0-3
Course Prerequisites
Required
SAP AG 2003
SAP AG
TAW10
0-4
Target group
Target group
Development consultants and developers who are
responsible for adapting and developing ABAP/ABAP
Objects programs
Duration
10 days
SAP AG 2003
SAP AG
TAW10
0-5
Course Goals
SAP AG 2003
SAP AG
TAW10
0-6
Preface
Complex
mySAP.com Technologies
Complex
Complex
ABAP Objects
Case Study
SAP AG 2003
This SAP Consultant Education training course contains different individual courses (sections), each of
which deals with a separate topic
Each individual course (section) is divided into different units.
SAP AG
TAW10
0-7
Preface
Complex
ABAP Dictionary
Complex
Programming Database
Updates
Complex
Techniques of List
Processing
Complex
Solution Manager
Complex
Enhancements and
Modifications
Complex
Programming User
Dialogs
Case Study
SAP AG 2003
This SAP Consultant Education training course contains different individual courses (sections), each of
which deals with a separate topic
Each individual course (section) is divided into different units.
SAP AG
TAW10
0-8
SAP AG 2003
SAP AG
TAW10
1-1
Unit
mySAP.com
Unit
Navigation
Unit
Unit
Cross-System Concepts
SAP AG 2003
SAP AG
TAW10
1-2
mySAP.com
Contents:
System Overview
Internet Technologies
Interfaces
SAP Service Marketplace
SAP AG 2003
SAP AG
TAW10
2-1
mySAP.com (1)
System
System Overview
Overview
Internet
Internet Technologies
Technologies
Interfaces
Interfaces
SAP
SAP Service
Service Marketplace
Marketplace
SAP AG 2003
SAP AG
TAW10
2-2
R/3
Marketplace
Laptop or
PDA (handheld)
Field staff
Only
browser
required
R/3:
HR
CRM
Customer
TM
R/3:
SD
R/3
Legacy
software
APO
Your company
Other
software
Business partner
SAP AG 2003
mySAP.com provides the option of mapping internal business processes with employees and external
business processes for partners, customers or suppliers using the Internet.
SAP AG
TAW10
2-3
browser
browser
Classic users
SAP
SAP GUI
GUI
ESS
Middleware
components
browser
browser
SAP R/3 Enterprise provides a wide range of core business functions (as did its precursor, SAP R/3),
including Financial Accounting and Human Resources Management.
SAP R/3 Enterprise, which excellently complements all SAP solutions, can be used as an ERP backend
system.
SAP AG
TAW10
2-4
mySAP CRM
e.g. Internet selling
browser
browser
Mobile Services
Middleware
components
CRM System
ERP Backend
Laptop
Laptop
Call Center
SAP
SAP GUI
GUI
SAP AG 2003
Many companies now attach growing importance to generating and maintaining customer loyalty. This
is why it is necessary to manage customer information efficiently.
mySAP Customer Relationship Management (mySAP CRM) not only enables you to do this, it also
enables you to optimize your customer relationships as a whole and throughout the life cycle from
customer acquisition through sales processes and order fulfillment to customer service.
SAP AG
TAW10
2-5
mySAP E-Procurement
Catalog
Employees
within your
company
...
Middleware
ERP Backend
EBP System
SAP
SAP GUI
GUI
...
Internet Marketplace
Not necessarily
required
SAP AG 2003
SAP AG
TAW10
2-6
mySAP BI
BW System
ERP Backend
Manager
...
GUI
GUI
SEM System
ERP Backend
Not necessarily
required
SAP AG 2003
The mySAP Business Intelligence solution provides you with a variety of options for extracting,
evaluating, storing and disseminating the data in your systems so you can make business or strategic
decisions.
mySAP BI components:
- SAP Business Information Warehouse (SAP BW)
- SAP Strategic Enterprise Management (SAP SEM)
SAP AG
TAW10
2-7
mySAP SCM
Manager
(person responsible)
BW System
ERP Backend
APO System
Other
ERP Backend
GUI
GUI
(Excel-based
(Excel-based
for
for example)
example)
Manager
(planner)
SAP
SAP GUI
GUI
SAP AG 2003
mySAP Supply Chain Management (mySAP SCM) gives you the tools you need to manage your entire
logistics chain, so you can control all intracompany and intercompany processes, from mapping the
logistics chain to sourcing, and from requirements planning to sales.
The Internet-enabled functions in mySAP Supply Chain Management allow you to control the logistics
chain even beyond your company boundaries. This enables you to collaborate with your partners and
customers, exchanging important information and reacting swiftly as the need arises.
One of the central modules of mySAP SCM is the Advanced Planner & Optimizer (APO). APO includes
the following components: Supply Chain Cockpit, Demand Planning, Supply Network Planning and
Deployment, Production Planning and Detailed Scheduling and Global Available-to-Promise.
By combining APO with the Business Information Warehouse, SAP customers can optimize
performance and costs along the entire logistics chain.
SAP AG
TAW10
2-8
ERP Backend
Employee
Portal
browser
browser
browser
browser
browser
browser
Other
ERP Backend
Browser
Browser
Other sources of
information or systems
(such as the Internet)
SAP AG 2003
SAP AG
TAW10
2-9
mySAP.com (2)
System
System Overview
Overview
Internet
Internet Technologies
Technologies
Interfaces
Interfaces
SAP
SAP Service
Service Marketplace
Marketplace
SAP AG 2003
SAP AG
TAW10
2-10
Web server
HTTP
SAP ITS
RFC/
DIAG
SAP Application
Server
previously
"SAP Basis")
SAP Web
Application Server
optional
RFC
Various
SAP systems
SAP AG 2003
There are basically two ways of accessing an SAP component in dialog mode from the Internet:
- Using the SAP Internet Transaction Server (SAP ITS)
- Using the Internet Communication Manager (ICM) of the SAP Web Application Server (SAP Web
AS)
SAP AG
TAW10
2-11
Service
files
Common host
Web
browser
HTTP
Web
server
CGI*
WGate
TCP/IP AGate
DIAG
RFC
SAP
System
HTML page
HTMLBusiness
Templates
Flow files
CSS
files
SAP AG
TAW10
2-12
Dispatcher
WP
WP
DB
Dispatcher
WP
WP
WP
WP
Memory
pipes
ICM
DB
SAP AG 2003
The SAP Web AS is a further development of the classic SAP Basis technology. A new process has been
added to the SAP kernel, the Internet Communication Manager (ICM).
The ICM enables you to process directly queries that were placed from the Internet/Intranet via a
browser.
The Web browser and ICM communicate using Business Server Pages; these are HTML pages that also
contain ABAP coding, for example, so that the HTML page can be filled with data at runtime.
The SAP GUI for HTML cannot currently be used with the ICM (-> SAP ITS)
SAP AG
TAW10
2-13
mySAP.com (3)
System
System Overview
Overview
Internet
Internet Technologies
Technologies
Interfaces
Interfaces
SAP
SAP Service
Service Marketplace
Marketplace
SAP AG 2003
SAP AG
TAW10
2-14
P
H
HTTTT
SMTP
SMTP
DI
EED
A
ALE
E
BAPI
BAPI
OLE
OLE
RFC
RFC
CPI-C
CPI-C
Open Interfaces
TCP/IP
TCP/IP
LU6.2
LU6.2
Open Interfaces
SAP AG 2003
SAP AG
TAW10
2-15
Distributed
business processes
Plant maintenance
Inventory
management
Internal sales,
shipping and billing
Local purchasing
PP
Accounting
Central Controlling
Information systems:
Inventory
Purchasing
Sales
Central purchasing
Reference system for
master data and tax
data
SAP AG 2003
SAP AG
TAW10
2-16
External system
ABAP program
External program
RFC interface
RFC interface
SAP system
RFC interface
ABAP program
SAP AG 2003
Remote Function Call (RFC) is a communications interface that is based on CPI-C, but which has more
functions and is easer for application programmers to use. You can use R/3 and R/2 Systems as well as
external applications as RFC communication partners. See also SAP Notes 13903 and 116051.
RFC is the protocol for calling special subroutines over the network. These subroutines are labeled
function modules. Function modules are comparable with C functions or PASCAL procedures. They
have a defined interface via which data, tables and return codes can be exchanged. Function modules are
managed in the R/3 System in their own function library, called the Function Builder.
SAP AG
TAW10
2-17
System called
RFC DESTINATION
R/2
R/3
DEST
...
...
CALL FUNCTION XY
DESTINATION DEST
EXPORTING...
IMPORTING...
...
FUNCTION XY.
.
.
.
ENDFUNCTION.
RFC interface
RFC interface
interface
RFC
SAP AG 2003
Function modules remote calls across system borders are only different to local remote calls in that a
special parameter (Destination) specifies the destination host on which the program is to be executed.
There are three types of RFC call:
- Synchronous RFC call: the calling program stops until the function module has been
processed in the destination system and any results have been returned to the caller. Only
then does the calling program continue processing.
- Asynchronous RFC call: the calling program runs parallel to and independently
of function module processing in the destination system. Programmers are
responsible for handling result processing. In addition, the destination system must also be
available at the time of the RFC call.
- Transactional RFC call: several function modules can be grouped into one
transaction. They are processed in the destination system within an LUW once only,
and in the sequence in which they were called. In the case of an error, the calling system receives
a confirmation that you can access using Transaction SM58. In the case of transactional RFC, the
destination system does not have to be available at the time of the RFC call. In addition, you can
configure the frequency and intervals of individual queries.
SAP AG
TAW10
2-18
mySAP.com (4)
System
System Overview
Overview
Internet
Internet Technologies
Technologies
Interfaces
Interfaces
SAP
SAP Service
Service Marketplace
Marketplace
SAP AG 2003
SAP AG
TAW10
2-19
?? ?
Problem
messages
Current
Output /
messages?
Notes
database
Training
course
information
Corrections
SAP Software
Change
Registration
Service
requirements
SAP AG 2003
The SAP Service Marketplace under http://service.sap.com is aimed at SAP customers and partners
(unlike http://www.sap.com, which provides information on all SAP solutions and on SAP as a company
for everyone).
At the SAP Service Marketplace you can access various services, special information and additional
offers.
You must be registered as a user to use the SAP Service Marketplace. There is normally a contact person
in each company who creates users for employees as required and sets authorizations.
Access to the SAP Service Marketplace is free of charge (apart from the necessary Internet access).
SAP AG
TAW10
2-20
SAP AG 2003
SAP AG
TAW10
2-21
Navigation
Contents:
Logon and Screen Design
User Guide
Getting Help
User Settings
SAP AG 2003
SAP AG
TAW10
3-1
Navigation (1)
Logon
Logon and
and Screen
Screen Design
Design
User
User Guide
Guide
Getting
Getting Help
Help
User
User Settings
Settings
SAP AG 2003
SAP AG
TAW10
3-2
SID
Group/Server
Sys.No. Messageserver
DEV
SPACE
00
Logon
twdf0670
Properties
Groups...
Server...
New...
Delete
SAP AG 2003
The SAP GUI program connects the front-end computer with a specific SAP System. Theoretically you
can specify the SAP system required at command-line level when calling the SAP GUI program. In
practice, you never need to do this. SAP provides another program for starting the SAP GUI: SAP
Logon.
When you call up the SAP Logon, it displays a list of SAP systems whose logon process can be started.
This list is derived from a file on the front-end computer: saplogon.ini. This file is normally
preconfigured centrally and made available to end users.
SAP AG
TAW10
3-3
Users
System
Help
SAP R/3
New password
client
100
User
Password
Language
DE
TWDF0670
OVR
SAP AG 2003
SAP systems are client systems. You can use the client concept to control several separate enterprises in
one system at the same time. The BW and KW components are exceptions since each uses one client
only. Each user session only accesses data on the client that you selected when you logged on.
A client is a self-contained organizational unit in the system. Each client has its own data environment
and, therefore, its own user master and transaction data, assigned user master records and chart of
accounts and specific Customizing parameters.
So that you can log onto the system, you must have a user master record created for you for the
corresponding client. For reasons of access protection, you must enter a password when you log onto the
system. The system does not display the password that you enter (stars are displayed in place of the
password).
SAP systems are multilingual. You can use the Language field to select the logon language for the
current session.
Multiple logons are recorded as of Release 4.6. This is for reasons of both security and licensing. If the
same user logs on more than once, then the system displays a warning message for each subsequent
logon.
You can add your own texts to the logon screen in different ways. For more information, see SAP Note
205487.
SAP AG
TAW10
3-4
Menu
Edit
Favorites
Extras
System
Help
Create role
Assign users
Documentation
Favorites
SAP menu
Office
Information Systems
tools
TWDF0670
OVR
SAP AG 2003
The SAP Easy Access screen is the standard way to access the system. You navigate within the system
using a clearly arranged tree structure.
You can attach an image such as your company logo to the right side of the screen. This image can be
assigned throughout the system and is valid for all clients. Given that you have authorization to do so,
you can find a detailed description of the settings that are required to do this by choosing Extras -->
Administration information. Please note that the graphic is stored in the system and transported to the
front-end every time SAP Easy Access is called. Although it is transported in compressed form, the
graphic should not exceed 20 KB. You can also prevent the graphic from being called by choosing the
setting Low Speed Connection in the SAP Logon program (see SAP Note 161053), or by choosing
Extras --> Settings in the SAP Easy Access screen. See also "User Settings".
SAP AG
TAW10
3-5
Screen Elements
Users
Edit
Goto
System
Menu bar
Standard toolbar
Title bar
Application toolbar
Help
Command
field ESCH
User
ESCH
Last changed by
Address
Defaults
05.07.2001 15 : 46 : 37
Parameter
s
Saved
Tab page
StartMenu
Logon language
Output Controller
OutputDevice
Status
Decimal notation
Input fields
Checkboxes
Radio buttons
1.234.567,89
1,234,567.89
1 234 567,89
Output immediately
Delete after output
Date format
DD.MM.YYYY
MM/DD/YYYY
MM-DD-YYYY
YYYY.MM.DD
CATT
Test status
YYYY/MM/DD
YYYY-MM-DD
Status bar
DEV (1) (100)
TWDF0670
OVR
SAP AG 2003
Command field: you can start applications directly by entering their transaction code in the command
field (this is hidden by default). You can find the transaction code for an application either in the SAP
Easy Access menu tree (see "User Settings") or in the application itself under System -> Status.
Menu bar: the menus shown here depend on which application you are in. These menus may also
contain cascading menus.
Standard toolbar: the icons in the standard toolbar are shown on every R/3 screen. If they are not
available in an application, the pushbuttons that you cannot use on that screen are deactivated. If you
position the cursor over an icon for a short time, the system displays quick info text with the name or
function of the icon. If appropriate, you also see the corresponding function key setting. The application
toolbar shows the icons available in the application you are currently in.
Title bar: the title bar names the function that is available in the application you are currently in.
Checkboxes: checkboxes enable you to select several options from a group of fields at the same time.
Radio buttons: radio buttons enable you to choose exactly one item from a selection.
Tab: arranges several information screens to improve clarity.
Status bar: the status bar displays information such as warnings and errors about the current system
status.
SAP AG
TAW10
3-6
Navigation (2)
Logon
Logon and
and Screen
Screen Design
Design
User
User Guide
Guide
Getting
Getting Help
Help
User
User Settings
Settings
SAP AG 2003
SAP AG
TAW10
3-7
Menu
Edit
Favorites
Extras
System
Help
Create role
Assign users
Documentation
Favorites
URL - SAP Service Marketplace
SM50 - Process Overview
SM04 - User List
Favorites list
Role SAP_BC_BASIS_ADMIN
System: Running Operation
System Configuration
Performance Analysis
Problem Analysis
Overview
RZ20 - CCMS Monitoring
Details
Role-based menu
TWDF0670
OVR
SAP AG 2003
Role: a role describes a number of activities in the system that it makes sense to define. These represent
the scope of functions that users typically require at their work station.
Roles (formerly "activity groups") must be set up using the Profile Generator so that SAP system users
can work with user-specific or work station-related menus.
Roles are also used to assign users with authorization for the activities defined in menus. Predefined user
roles from all application areas are included in the standard system as of Release 4.6.
When users are assigned roles, they can choose between the standard SAP menu and their user menus.
In addition to their roles, end users can also use Favorites to personalize their access to the system. You
can create your own Favorites list of the transactions, reports, files and Web addresses that you
frequently use.
You can create edits using the Favorites menu or simply using the mouse to "drag & drop" URLs or
links to files to your personal favorites list.
SAP AG
TAW10
3-8
Navigation Options
Menu
Edit
Favorites
Extras
System
Create session
End session
User profile
Services
Utilities
List
Favorites
URL - SAP Service Marketplace
SM50 - Process Overview
SM04 - User List
Role SAP_BC_BASIS_ADMIN
System: Running Operation
System Configuration
Performance Analysis
Problem Analysis
Overview
RZ20 - CCMS Monitoring
Details
Menu
SAP AG
TAW10
3-9
Menu
Edit
Favorites
Extras
Help
System
Create session
Application help
End session
SAP Library
User profile
Glossary
Create role Release Notes
Assign users
Services
Utilities
Favorites
SAP menu
Office
Information Systems
tools
Documentation
List
Feedback
Settings...
Object history
Own spool requests
Own jobs
Short message
Status...
Log off
TWDF0670
OVR
SAP AG 2003
You can find the following options amongst others in the System menu option:
Create/end session: creates and ends a session. System administrators can use parameter
rdisp/max_alt_modes to set the maximum number of sessions to a number between 2 and 6.
User profile: contains user-specific settings. Choose Own data to use parameters IDs that fill specific
fields in the system (such as the company code field) with default values.
List: important list functions, such as searching by character string, saving to PC files, printing and so
on.
- Status: displays the most important user and system data
- Logoff: ends the SAP R/3 session (with a request for confirmation)
The menu option Help contains the following options, amongst others:
- A context-sensitive Application Help
- SAP Library call (see next page)
- A Glossary
SAP AG
TAW10
3-10
Navigation (3)
Logon
Logon and
and Screen
Screen Design
Design
User
User Guide
Guide
Getting
Getting Help
Help
User
User Settings
Settings
SAP AG 2003
SAP AG
TAW10
3-11
F1 Help
Output Controller
OutputDevice
Output immediately
Delete after output
Personal time zone
CET
Technical information
CATT
Test status
F1 help
Performance Assistant
Print parameter 2
Indicates whether spool requests are printed immediately.
Select this field to print your spool requests immediately.
lassen.
Leave the field blank to retain spool requests in the spool
system until they are released. To release these spool
requests for printing, you can use System -> Services -> Output controller.
SAP AG 2003
You can choose the F1 key to display an explanation of fields, menus, functions and messages.
The F1 help also displays technical information on the relevant field. This information includes, for
example, the parameter ID that you need to set user-specific default values for input fields that are also
linked to the parameter ID.
SAP AG
TAW10
3-12
F4 Help
Address
Defaults
StartMenu
Restrictions
Logon language
Output Controller
OutputDevice
F4 help
Langu... Language
AF
Afrikaans
AR
Arabic
BG
Bulgarian
CS
Czech
DA
Danish
DE
German
EL
Greek
EN
ES
English
Spanish
ET
Estonian
FI
Finnish
FR
French
HE
Hebrew
HR
Croatian
HU
Hungarian
ID
Indonesian
SAP AG 2003
You can use F4 to display possible input values. You can also call up the F4 help for a field using the
button immediately to the right of the selected field.
SAP AG
TAW10
3-13
SAP Library
Getting Started
Hide Tree
Open All
Previous
Release
Notes
IMG
Glossary
Search
Help on Help
Area
SAP Library
Close All
Next
Synchronize
SAP Library
Getting Started
SAP Web Application Server
SAP Knowledge Management
Help on Help
Help on the Web
Copyright
Local intranet
SAP AG 2003
SAP Systems provide extensive online help. You can call this help from every screen in the system. You
can call up help by choosing the Help menu, or by choosing the appropriate icon (yellow question mark).
You can also access the SAP Library easily and quickly from the SAP Service Marketplace. You can
find the SAP Help Portal under Knowledge and Training. You can display the help in HTML format and
also perform a very efficient full text search in the library. If the SAP Library has been installed, you can
also call this option within your company.
You can also access the Help Portal directly at http://help.sap.com.
SAP AG
TAW10
3-14
Navigation (4)
Logon
Logon and
and Screen
Screen Design
Design
User
User Guide
Guide
Getting
Getting Help
Help
User
User Settings
Settings
SAP AG 2003
SAP AG
TAW10
3-15
Favorites Extras
System
Help
Display documentation
Technical details
Settings
Set start transaction
Shift+F6
Ctrl+Shift+F10
Shift+F9
Create roleShift+F7
Options ...
New Visual Design ...
Assign users
Documentation
Clipboard
Generate graphic
Favorites
SAP menu
Office
Information Systems
tools
Default size
Hardcopy
Quick Cut and Paste
Spelling Check
Sapgui Help
Settings
About ...
TWDF0670 OVR
SAP AG 2003
Choose Extras ->Settings to change the appearance of the initial screen, for example, by turning off the
graphics display on the right side of the screen, or by displaying technical names (transaction codes) on
the SAP Easy Access screen.
When you choose Options, you have the option of activating Quick Cut and Paste. Under Options... you
have the option of setting the reaction speed of the quick info text that is displayed when you position
the cursor over an icon or pushbutton.
You can set personal standard values by choosing System -> User Profile -> Own Data. You can do this
on the tab pages Address, Defaults, and Parameters.
SAP AG
TAW10
3-16
SAP AG 2003
SAP AG
TAW10
3-17
Navigation - Exercises
Unit:
Navigation
Topic:
Basic Functions
As a new SAP system user, start to navigate in the system using menu
paths and transaction codes, and use the various types of online help.
All menu paths in the exercises refer to the SAP standard menu.
1-1
1-2
What is the maximum number of parallel sessions (windows of the SAP system) can
you open by choosing System Create session?
Number: __
1-3
What are the functions called that you access using the following SAP standard menu
paths and what are the corresponding transaction codes?
1-3-1 Tools Administration Monitor System Monitoring User Overview
Function name: ___________________________________________
Transaction: _________________________________________________
SAP AG
TAW10
3-18
Help
1-4-1 On the SAP Easy Access initial screen, if you choose Application Help ("Help"
menu), you branch to which area of the SAP Library?
_________________________________________________________
1-4-3 Use the F1 help for the Company code field. To which business area of the SAP
Library does the system branch when you choose the Application Help icon at
the top edge of the F1 help window?
______________________________________________________
1-4-4 Which icon at the upper edge of the F1 help window can you use to find the
parameter ID for the Company code field?
______________________________________________________
SAP AG
TAW10
3-19
1-4-5 Use the F4 help for the Customer field to find the number of customer "Becker
##". To do this, call the F4 help and use the search term "Becker*".
Hint: ## is your group number.
___________________________________________________
SAP AG
TAW10
3-20
Unit:
Navigation
Topic:
User-Specific Settings
2-2
Define user-specific settings by choosing System --> User Profile --> Own Data.
2-2-1 Set your Logon Language to the language that you are using in the training
course.
2-2-2 Define the Decimal Notation and the Date Format you require.
SAP AG
TAW10
3-21
2-3
Maintain favorites
2-3-1 Create at least one new folder below the favorites folder.
2-3-2 Add two of your favorite transactions to this folder.
2-3-3 Add the Internet address http://www.sap.com below the title SAP
Homepage.
2-4*
SAP AG
TAW10
3-22
Solutions
Unit:
Navigation
Topic:
Basic Functions
1-1
Log on to the system indicated by the instructor and change your password.
1-2
To create and end sessions, choose System Create session (or choose the
corresponding icon) and System End session.
Depending on the system setting, up to six sessions can be opened simultaneously
during one user terminal session.
1-3
You can find the transaction code under System Status. These screens and
transaction codes correspond to the menu paths:
1-3-1 SM04 for User List
1-3-2 FD03 for Customer Display: General Data
1-4
Help
1-4-1 The Getting Started unit is displayed with
information about using SAP Easy Access.
1-4-2 Suggestion: The Customer field is used within an SAP
system to identify a customer uniquely.
1-4-3 FI Accounts Receivable and Accounts Payable
1-4-4 Using the Technical Info icon you can find: Parameter ID: BUK
1-4-5 Customer##
If you use the F4 help for the Customer field, a dialog box appears in which you can
enter various search criteria.
The different tabs on the dialog box contain different search criteria. Use the Search
term search criteria and enter the following data:
Criterion Name
Value
Search term
Becker*
If you perform the search using the Enter key, a list of possible hits is displayed, from
which you can select the corresponding value.
SAP AG
TAW10
3-23
Unit: Navigation
Topic: User-Specific Settings
2-1
2-2
2-3
Maintain favorites
2-3-1 To place favorites in a folder, you must first create a folder (functional areas):
Favorites Insert folder with a name of your choice. You can create as many
folders as you like. You can move folders using the mouse to drag & drop
them.
2-3-2 To create favorites, select specific applications (transactions) in the menu tree
of the SAP standard menu that you require as favorites (those applications that
you use daily). You can add entries to your favorites list by selecting the
application and choosing Favorites Add. You can subsequently move
favorites into folders by choosing Favorites Move favorites. You can also
move favorites using the mouse to drag & drop them.
SAP AG
TAW10
3-24
2-3-3 You create Internet addresses by choosing Favorites Add Web address or
file.
2-4
SAP AG
TAW10
3-25
Contents:
Data Structure
System Kernel
SAP AG 2003
SAP AG
TAW10
4-1
Data
Data Structure
Structure
System
System Kernel
Kernel
SAP AG 2003
SAP AG
TAW10
4-2
Application
Data
(Orders,
Invoices,...)
Client-Specific
Customizing
(Company Codes, Plants,
Stores, ...)
(Orders,
Invoices,...)
Client-Specific
Customizing
User
Application
Data
(Authorizations,
Master Record...)
Client 200
User
Client 100
(Authorizations,
Master Records...)
...
Cross-Client Customizing
Repository Objects
(For example: Table Definitions, Programs, Transactions, Function
Modules)
Customer
Developments
Basis
FI
CO
HR
PP
MM
SD
...
Development Classes
SAP AG 2001
SAP AG
TAW10
4-3
Customizing
ASAP Roadmap
View:
View: Change Company Code
New entries
CoCd.
Customizing
Company name
. . .
Customizing
.
Customizing
SAP AG 1999
In addition to the various data types in the SAP R/3 System, there are also different types of changes and
adaptations in the SAP R/3 System, and in other mySAP.com component systems.
As the SAP R/3 System is standard software, it must be adapted to the individual needs of each company
that uses it. This tailoring process is called Customizing, which includes the client-specific and crossclient data shown in the slide. A small amount of Customizing may also be required after an SAP R/3
System upgrade.
Customizing is not developed and tested in the same client in which it will be in production. This means
that several clients are required during an SAP R/3 implementation. Customizing is executed and tested
in one client. In a large installation, it may make sense to combine and test Customizing subprojects in
another client. Production occurs in its own client.
SAP AG
TAW10
4-4
SAP Namespace
Customer Namespace
QAS
Repository
PRD
Modifications
Extension
Customer Development
SAP AG 1999
In contrast to Customizing, the Repository does not necessarily need to be changed or enhanced for a
mySAP.com System implementation:
Customers can add their own developments to the Repository.
In addition, customers can add what are called customer enhancements, which are customer objects
added to existing objects in the SAP standard system. Customers add their enhancements using
Customer Exits.
Modifications change SAP objects, such as reports and table definitions. The Repository delivered
from SAP is not only enhanced, but changed as well. This is why the modifications may need to be
adjusted to a new Repository installed during the next SAP R/3 upgrade. This adjustment may take
some time.
As Repository objects are cross-client, it is not possible to use a development system as a production
environment. The danger of creating data inconsistencies would be too great.
Therefore, if changes are to be made to the Repository, we recommend two, even better, three systems.
The third SAP R/3 System can be used for testing and quality assurance.
All customer developments take place in the customer namespace. This means that all objects created by
customers have names within a certain namespace, for example beginning with Y or Z for ABAP
programs.
SAP AG
TAW10
4-5
Data
Data Structure
Structure
System
System Kernel
Kernel
SAP AG 2003
SAP AG
TAW10
4-6
Applications
ABAP
Interpreter
Screen
Processor
User Interface
ABAP
Dictionary
Runtime Environment
Communication Interface
Programming Interfaces
This unit introduces the central processes of mySAP.com Basis Technology. This includes an
explanation of how a user request is sent to and processed by the application layer, and which process
types are involved in processing the request. Data entered by the user is sent through the user interface
(the SAP GUI) to the dispatcher, which coordinates further processing. The work processes use the same
source code as the dispatcher and whose substructures such as the Screen Interpreter and the ABAP
Interpreter are presented here. Another topic is data exchange with the database.
SAP AG
TAW10
4-7
Presentation
SAP GUI
SAP GUI
SAP GUI
SAP GUI
Communication
Application
Dispatcher
Buffer
Work
Process
Database
Work
Process
Work
Process
Database Processes
DB
SAP AG 1999
The dispatcher is the central process of the application server. The dispatcher manages, in association
with the operating system, the resources for the applications written in ABAP. The main tasks of the
dispatcher include distributing transaction load to the work processes, connecting to the presentation
level, and organizing communication.
User input is received by the SAP presentation program SAPGUI, converted into its own format and
then sent to the dispatcher. The processing requests are then saved by the dispatcher in request queues
and processed according to a first in-first-out principle.
The dispatcher distributes the requests one after the other to available work processes. Data is actually
processed in the work process, although the user, who creates the request using the SAP GUI, is not
always assigned the same work process. There is no fixed assignment of work processes to users.
Once the data has been processed, the processing result from the work process is sent via the dispatcher
back to the SAP GUI. The SAP GUI interprets the received data and generates the output screen for the
user with the help of the operating system on the front end computer.
During initialization of the mySAP.com component system, the dispatcher executes the following
actions among others: It reads the system profile parameters, starts work processes, and logs on to the
message server (this service will be explained later).
SAP AG
TAW10
4-8
Windows 32 Bit
Java Application
Browser-Based
SAP AG 1999
The presentation interface SAPGUI (GUI = Graphical User Interface) implements the platformspecific input and output functions of an SAP business application. The SAP GUI is primarily based on
the Windows Style Guide and is available for several platforms providing the same functions for each. If
you have learned to use the SAP GUI on one platform, with the exception of a few small platformspecific GUI attributes, you can use the system on another platform exactly the same as before.
The presentation software implements the graphical user interface using the functions provided by the
relevant presentation environment.
As of SAP R/3 Release 4.6B you have a choice between the classic SAP GUI and a number of
alternative access possibilities:
SAP GUI for HTML
SAP GUI for Java
SAP AG
TAW10
4-9
Presentation Layer
Presentation
Workstation/PC
Terminal Client
Windows PC
SAP GUI
Process
Terminal
Server
SAP GUI
Process
Windows PC and
Browser for
SAP GUI for HTML
Java
Environment
SAP GUI
LAN / WAN
Network
Application
Dispatcher
SAP AG 1999
The data flow between the presentation level and the application level when using the SAP GUI for
Windows consists not of prepared images, but of compact, logical information about control elements
and user entries (DIAG Protocol). The amount of data that must be transferred for each screen change
when using the SAP GUI for Windows is typically several kB. You can also connect application servers
over Wide Area Networks (WANs). For more information, see SAP Note 161053.
An Internet Transaction Server is used for the SAP GUI for HTML to turn the SAP GUI data flow from
the dispatcher into HTML, and conversely. In this case, an HTML data flow is exchanged between the
WGate of the ITS (see the Communications and Integrations Technology unit) and the Frontend. The
primary advantage of the SAP GUI for HTML is the low installation cost for the Frontend; all you need
is a browser.
SAP GUI for Java receives the Standard DIAG Protocol (from the dispatcher) and places this on the
Frontend in HTML or, if in use by Java Plug-Ins, in a graphical format, which can, for example, be
displayed in a browser. In this case the installation costs for the Frontend are equally minimal. For more
information, see SAP Note 146505.
For information about implementation of the SAP GUI on a Windows Terminal Client, see SAP Note
138869.
SAP AG
TAW10
4-10
Database Server
ABAP
Interpreter
SELECT *
FROM ...
DB
Interface
Local
Buffer
Data
OPEN SQL
Native SQL
Data
EXEC SQL.
SELECT ...
END EXEC.
Database
DB Data
Native Native
SQL SQL
DB Data
SAP AG 1999
Relational Database Management Systems (RDBMS) are generally used to manage large sets of data.
An RDBMS saves data and relationships between data in the form of two-dimensional tables. These are
known for their logical simplicity. The data, tables, and table relationships are defined in the database
catalog (the data dictionary) of the database system.
Within the ABAP programming language, you can use SAP OPEN SQL to access data in the database
regardless of your database management system. The mySAP.com database interface converts Open
SQL statements from ABAP statements into corresponding database statements. This means that the
application programs that are written in ABAP do not depend on the database used. Furthermore, Native
SQL commands can be used directly in ABAP.
When interpreting Open SQL statements, the SAP database interface checks the syntax of these
statements and ensures the optimal utilization of the local SAP buffers in the shared memory of the
application server. Data that is frequently required by the applications is stored in these buffers so that
the system does not have to access the database to read this data. In particular, all technical data, such as
ABAP programs, screens, and ABAP Dictionary information, as well as a number of business
administration parameters, usually remain unchanged in a running system and are therefore ideally
suited to buffering. The same is true of business application data, which is almost exclusively accessed
as read-only and can therefore be buffered.
SAP AG
TAW10
4-11
mySAP.com Processes
Message Server
V2
Dialog
D
Update
Disp.
V1
Disp.
Disp.
MS
Disp.
Background
11
10
12
SAP Dispatcher
Lock Administration
1
2
4
7 6 5
Spool
Gateway Server
R/2
GW
R/3
SAP AG 1999
The operating system views the SAP runtime system as a group of parallel, cooperating processes. On
each application server these processes include the dispatcher as well as work processes; the number of
work processes depends on the available resources. Special work processes may be installed for dialog
processing, update, background processing and spooling.
In addition to these work process types (dialog processing (D), update (V: for the German
"Verbuchung"), lock management (E), background processing (B), spool (S), the runtime system
provides two additional services for internal and external communication (below are the restrictions on
the number of work processes):
The message server (MS or M) communicates between the distributed dispatchers within a
mySAP.com System and is therefore the prerequisite for scalability using several parallel-processing
application servers.
The gateway server (GW or G) allows communication between mySAP.com components such as SAP
R/3 and SAP R/2 and external application systems. There is only one gateway process for each
dispatcher process.
Dialog: Every dispatcher requires at least two dialog work processes
Spool: At least one for each mySAP.com System (more than one allowed for each dispatcher)
Update: At least one for each mySAP.com System (more than one allowed for each dispatcher)
Background processing: At least two for each mySAP.com System (more than one allowed for each
dispatcher)
Enqueue: Only one enqueue work process is needed for each system
SAP AG
TAW10
4-12
Instance (a)
Instance (b)
Dispatcher
...
D-WP
Dispatcher
B-WP
...
D-WP
D-WP
Dispatcher
MS
...
D-WP
V-WP
E-WP
B-WP
S-WP
SAP AG 1999
An instance is an administrative unit that combines mySAP.com system components providing one or
more services. The services offered by an instance are started or stopped together. You use a common
instance profile to set parameters for all of the components of an instance.
A central mySAP.com System consists of a single instance that provides all of the necessary services.
Each instance has its own SAP buffer areas.
The example illustrates how a background processing server (a) and dialog server (b) are set up. These
instances, which provide specific services, generally run on separate servers, but can also run on the
same server, if needed.
The message server provides the application servers with a central message service for internal
communication (for example: trigger update, request and remove locks, or trigger background requests).
The dispatchers for the individual application servers communicate through the message server that is
installed once in each mySAP.com System (it is configured in the system profile files).
Presentation servers can also log on to an application server through the message server. This means that
you can use the message server performance database for automatic load distribution (logon load
balancing).
SAP AG
TAW10
4-13
Dispatcher
Work
Process 1
Internal Memory
Request
Queues
Work Process n
Screen
Processor
ABAP
Processor
Task
Handler
...
Database
Interface
Buffer Access
Shared Memory
LAN / WAN
Network
Rollout
Application Buffer
Factory Calendar
Screens
ABAP Programs
Tables
Dictionary Objects...
Roll In
Roll Area
User Context
Roll File
SAP AG 1999
The following components on the application level are involved in processing a dialog request:
The dispatcher as central control process
Work process queues (administered by the dispatcher) for incoming requests.
One of the diaog work processes
Buffers in shared memory and also possibly the roll file
The task handler coordinates activity within a dialog work process. It activates the screen processor or
the the ABAP processor (which control the screen flow logic and process ABAP statements,
respectively) and executes the roll-in and roll-out of the user context.
The memory management system differentiates between main memory areas that are available
exclusively to a work process, and memory areas that can be used by all work processes. The memory
space used exclusively by a work process stores session-specific data that must be kept longer than the
duration of a work step. This data is automatically made available to the process at the start of a dialog
step (rolled-in) and saved at the end of the dialog step (rolled-out). This data characterizes users (user
context), such as their authorizations, administration information and additional data for the ABAP and
dialog processor. It also contains data collected by the system in the preceding dialog steps in the
running transaction (see slide Work Process Multiplexing and SAP Transactions).
There are also additional memory areas for all processes in the shared memory for the factory calendar,
screen, table, program, and other buffers.
SAP AG
TAW10
4-14
Dispatcher
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
D-WP
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
11 12 1
10
2
9
3
8
4
7 6 5
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
D-WP
D-WP
11 12 1
10
2
9
3
8
4
7 6 5
Dialog work processes should not be loaded down with long-running dialog steps, as these work
processes would then not be available to other users. The remaining dialog work processes would have
to handle many more users, thus considerably increasing response times.
This is the reason for the parameter rdisp/max_wprun_time (default setting: 300 seconds), which sets
the maximum time a dialog step is allowed to remain in a dialog work process. If this time is exceeded
by more than double, the dialog step is terminated and the started transaction terminates with an error.
This allows the administrator to ensure that users execute long-running actions only in the background
work processes, which are designed for these types of long-running actions.
SAP AG
TAW10
4-15
Background Processing
Dialog Server
Dispatcher
...
Dispatcher
D-WP
D-WP
1
11
10
12
B-WP
B-WP
B-WP
1
2
Background Scheduler
(every 60 s)
4
7 6
...
Job
Job1
...
...
DB
XXX xxxx
xxx
xx
uuu
uu
UU uuuu
uuu u
Scheduling Table
SAP AG 1999
Background work processes are used for dialog-free execution of programs. They are used, for example,
for periodic tasks such as reorganization or the automatic transfer of data from an external system to a
mySAP.com component system.
Background processing is scheduled in the form of jobs. Each job consists of one or more steps (ABAP
reports, external programs or other operating system calls) that are processed sequentially. You can also
set priorities (from "C" to "A") so that certain jobs are prioritized.
Job processing is not generally triggered immediately (immediate start). Instead you specify a start date
and time when you schedule the job. It may also be necessary to start jobs periodically, for example,
system control jobs repeated on a fixed cycle. You can trigger a job start at the operating system level
using the SAPEVT program.
The background scheduler is responsible for automatically triggering the job at the specified time. The
background scheduler is an ABAP program that regularly looks in the scheduling table for jobs to be
executed and then ensures that they are executed (RDISP/BTCTIME, default 60 s).
SAP AG
TAW10
4-16
ABC
XYZ
Spool Server
Operating System
Spool
Dispatcher
D-WP
...
ABC
Spool
Request
XYZ
1B ...
41 42
43 ....
0D 0A
S-WP
Output
Request
LAN/WAN
Printer server
Database/File System
1B ...
41 42
43 ....
0D 0A
TemSe
Operating
System
Spool
SAP AG 1999
Spooling refers to the buffered transfer of data to output devices such as printers, fax devices and so on.
In distributed systems, networked administration is necessary for this output.
The spool mechanism in mySAP.com Systems can supply output requests to printers and external
spoolers both within a local network as well as over WANs. The spool mechanism works with the local
spool system on each server.
Spool requests are generated in dialog mode or during background processing and are then set in the
spool database with details about the output device and the print format. The data itself is stored in the
TEMporary Sequential(TemSe) object database.
When data is to be printed, an output request is generated for a spool request. This output request is
processed by a spool work process.
Once the spool work process has formatted the data for output, it returns the output request to the
operating system spool system.
The operating system spooler takes over the queue management and ensures that the required data is
passed on to the output device.
SAP AG
TAW10
4-17
D-WP
E-WP
B-WP
Change Access
DB
D-WP
xxx
xx
uuu
uu
UU uuuu
uuu u
SAP AG 1999
The lock mechanisms present in the current relational database systems are not generally sufficient to
handle business data objects (such as sales orders) that may affect several tables in the database. To
coordinate several applications simultaneously accessing the same business object, the mySAP.com
System provides its own lock management, controlled by the enqueue work process.
In order for the system to execute lock requests, you must first define a lock object in the ABAP
Dictionary. The lock object contains tables whose entries are to be locked. You can also have additional
secondary tables using foreign key relationships (the name of a user-defined lock object must begin with
"EY" or "EZ").
You can specify the lock mode ("S": shared lock or "E": exclusive lock) for a lock object. An exclusive
lock (mode "E") can only be set if no other user has set a lock ("E" or "S") on the data record. The same
user can request additional "E" or "S" locks within a transaction.
If a lock object is activated, the system generates an ENQUEUE and a DEQUEUE function module.
These function modules have the names ENQUEUE_<object_name> and DEQUEUE_<object_name>,
and are used in ABAP coding to lock and unlock data.
SAP AG
TAW10
4-18
Enqueue Server
Dialog Server
Dispatcher
Dispatcher
...
...
D-WP
Call function
'ENQUEUE_E...'
E-WP
...
Lock table in
main memory
MS
SAP AG 1999
When a lock is requested, the system checks to determine whether the requested lock conflicts with any
entries in the lock table. If there are conflicts, the lock request is rejected. The application program can
then inform the user that the requested operation cannot currently be executed.
The locks (enqueues) are administered by the enqueue work process using the lock table. The lock table
is stored in the main memory of the server where the enqueue work process is running. In the example
shown above, the dialog work process and the enqueue work processes are not located on the same
application server, they communicate through the message server.
Locks set by an application program are either reset by the application program itself, or using a special
update program (second part of the SAP Logical Unit of Work). Locks, which are inherited in this way
by an update work process, are also written to a file at operating system level. In transaction SM12, the
locks held by the update program are colored blue, while the locks held in the dialog work process are
colored black.
SAP AG
TAW10
4-19
Dialog
WP 0
PBO
100
PAI
PBO
Screen
100
PAI
Screen
PAI PBO
100 105
Dialog
WP 1
User Chooses:
Save / Cancel
Screen
105
Dialog
WP 2
PBO
PAI
Screen
110
PAI
105
PBO
PBO
110
PAI
110
SAP AG 1999
Business transactions are processing units with related functions; these transactions execute consistent
database changes meaningful for the business. Typical examples are credit and debit postings, which
only make sense together, or creating an order and reserving the material concerned.
Accordingly, an SAP transaction is implemented as a series of consistent, connected dialog steps. A user
dialog step is represented by a screen (or a dynpro, which is a dynamic program = mask and flow logic).
SAP transactions are not necessarily executed within one single dialog work process. In fact, the
individual dialog steps of a transaction can be processed by various dialog work processes (work process
multiplexing, which only exists for dialog work processes). Using asynchronous update, the dialog part
of the transaction and the associated database update can also be run in different work process types or
even on different servers.
From the systems point of view, a dialog step begins with the processing of a piece of data entered by
the user (Process after Input (PAI) and the preparation and sending of the next screen template (Process
before Output (PBO); after this, the screen that has been filled out by the user is once again accepted,
and in turn the input data contained in the received screen is analyzed and processed. System and user
dialog steps are processed alternately. The two parts of the dialog step from the systems point of view
are called PBO and PAI.
SAP AG
TAW10
4-20
SAP AG 2003
SAP AG
TAW10
4-21
Cross-System Concepts
Contents:
Organizational units and master data
Transactions and documents
Workflow
SAP AG 2003
SAP AG
TAW10
5-1
Company
Client
Company
Code
Subsidiary
Plant
Factory
Sales
Organization
Department
Division
Business
Area
Sales
Organization
Division
Storage
Locations
Warehouses
SAP AG 2003
SAP AG
TAW10
5-2
Ides Holding
Germany
Company
Code
U.S.A.
Plant
Hamburg 1000
0001
Berlin 1100
Dresden 1200
0002
0003
Storage
Location
SAP AG 2003
The client is the superior element of all organizational units. A client corresponds to a group with
several subsidiaries. All company data in an R/3 installation are differentiated at least by client, but
usually also by deeper organizational structures.
Flexible organizational elements in the R/3 System mean you also have the option of mapping complex
enterprise structures. Many organizational units are used to represent the legal and organizational
structure of an enterprise from different points of view.
The various enterprise areas are joined by linking the organizational units together and the structure of
the total enterprise is represented in the R/3 System.
SAP AG
TAW10
5-3
Client
Financial Accounting
Data
Payment Parameters
G/L Account
Dunning.
Company
Code
Sales Data
Sales/Shipping
Billing Parameter
Partner
Sales Area
Storage
Location
SAP AG 2003
Master data are data records that remain in the database for a long period of time. Master data include
customers, suppliers, materials, accounts and so on.
Master data are created centrally (for all applications) .
Master data have an organizational aspect. They are assigned to organizational units. A customer master
record can be assigned to the following organizational units: company code, sales organization,
distribution channel and division.
Master data can be used for all modules. For example, customer master data have common data for
accounting and sales.
SAP AG
TAW10
5-4
Valuation
Forecast
Planning Parameters
Purchasing Parameters
...
Requirements Planning
Parameters
Inventory Management
Physical Inventory
...
Client
Sales
Organization
Distribution
Channel
Plant
Storage
Location
SAP AG 2003
The material master is the central source for a company to display material-specific data. It is used by all
components of the SAP logistics system.
The data in the material master can be used by all areas such as purchasing, inventory management,
materials planning, invoice verification and so on.
SAP AG
TAW10
5-5
MARA
MAKT
MARC
MARM
MVKE
MLAN
MEAN
MBEW
MLGN
MLGT
MARD
MVER
MAPR
SAP AG 2003
SAP AG
TAW10
5-6
Company
Code
Sales Document
Customer
Master Record
Customer: 1000
Item
Material
Master Record
Material Quantity
10
HD-1300
20
P-103
Sales
Organization
Distribution
Channel
Division
SAP AG 2003
When a customer order is created, the transport agreements, terms of delivery and payment and so on
agreed with the business partner must be considered. So that you don't have to enter this information for
each activity connected with the business partner, the data that are relevant for the activity are copied
from the business partner's material master.
The information stored in the material master record (price per unit of measure, stock per storage
location and so on) are processed in the order entry. This principle applies to processing the data from
any master record involved in the activity.
The relevant organization units must be assigned when a transaction is executed. This ensures that the
assignments to the company structure are retained in the document that is created, in addition to the
information stored for the customer and the material.
A document is created for each transaction that is executed in the R/3 System.
The document that is created from a transaction implicitly contains all of the default features for the
master data and organizational units.
SAP AG
TAW10
5-7
Message Type
Invoice
Immediately
(creating orders)
Invoice
Invoice
On request
(printing activity)
Messages
Message type
Online
(screen output)
Printer
Telefax
EDI
SAP AG 2003
Whenever you save a query, an order, an outline agreement, a inquiry confirmation, a delivery note and
so on, an output format is created from the document concerned. This output format is a message
(message type). The message is then placed in the message queue, from where it can be released for
printing, output via EDI and so on as required. The message is released either manually or automatically
using a message control program.
You can use the various send media to output individual messages during processing, provided that the
corresponding message types and send media were assigned in Customizing. For each document type,
you can define when and how the messages are sent.
The message control can be stored as a default value in the business partner's master record.
SAP AG
TAW10
5-8
Decision
Employee
Employee
Leave form
processed
Dates not
approved
Decision
Form
changed
Form
rejected
Decision
Supervisor
Supervisor
Dates approved
Dates approved
Workflow completed
SAP AG 2003
The SAP Business Workflow is a tool that you can use to optimize the flow of business transactions. It
can execute consecutive work steps automatically, or coordinate the flow of information.
Workflows control processes according to a predefined model and are particularly suitable for
organizations that are structured and based on the principle of division of labor.
Workflow brings the "right" work in the "right" sequence to the "right" persons at the "right" time. This
can be done using an automated mail or a workflow item.
SAP AG
TAW10
5-9
SAP AG 2003
SAP AG
TAW10
5-10
SAP AG 2003
SAP AG
TAW10
6-1
Unit
Unit
Data Retrieval
Unit
Unit
Program-internal
Modularization with
Subroutines
Unit
Unit
Unit
Unit
SAP AG 2003
SAP AG
TAW10
6-2
Unit
Unit
Unit
Global Modularization
Unit
Appendix
SAP AG 2003
SAP AG
TAW10
6-3
Departure airport
Destination airport
In this course, you will develop several
programs designed to assist travel agencies.
Some of their typical needs include:
Departure city
Destination city
SAP AG 2001
SAP AG
TAW10
6-4
CARRID:
CARRNAME:
CURRCODE:
Airline ID
Airline name
Local currency of airline
SPFLI
CARRID:
CONNID:
COUNTRYFR:
CITYFROM:
AIRPFROM:
COUNTRYTO:
CITYTO:
AIRPTO:
Airline ID
Flight connection ID
Country key for departure city
Departure city
Departure airport
Country key for arrival city
Destination city
Destination airport
SFLIGHT
CARRID:
CONNID:
FLDATE:
PRICE:
CURRENCY:
SEATSMAX:
SEATSOCC:
Airline ID
Flight connection ID
Flight date
Price
Currency
Maximum number of seats on flight
Current number of occupied seats on flight
SAP AG 2001
You will refer to this information as you do the exercises throughout this course.
SAP AG
TAW10
6-5
Contents:
System Architecture and ABAP Program
Example Program with Selection Screen and List
SAP AG 2003
SAP AG
TAW10
7-1
SAP AG 2001
SAP AG
TAW10
7-2
System
System Architecture
Architecture and
and ABAP
ABAP Program
Program
Example
Example Program
Program with
with Selection
Selection Screen
Screen and
and List
List
SAP AG 2003
SAP AG
TAW10
7-3
Client/Server Architecture
Presentation
Server
Layer
SAPGUI
SAPGUI
SAPGUI
Dispatcher
Application
Server
Layer
Database
SAPGUI
SAPGUI
SAPGUI
Dispatcher
Work
Process
Work
Process
Work
Process
Work
Process
Work
Process
Work
Process
Work
Process
Work
Process
SAP AG 2001
The R/3 System has a modular software architecture that follows software-oriented client/server
principles.
The R/3 System allocates the presentation, application logic, and data storage to different computers.
This serves as the basis for the scalability of the R/3 System.
The lowest level is the database level. Here data is managed with a relational database management
system (RDBMS). In addition to application data, the database contains the programs and the metadata
that the R/3 System requires for self-management.
ABAP programs (both the applications provided by SAP and the ones you develop yourself) run at the
application server level. The ABAP programs read data from the database level, process the data, and
possibly store data there.
The presentation server level contains the user interface through which each user can access the
program, enter new data, and display the results of a work process.
The technical distribution of software is independent of its physical location on the hardware. All levels
can be installed vertically (on top of each other on one computer) or each level can be installed on a
separate computer. The presentation and application servers can be divided horizontally among any
number of computers. The horizontal distribution of database components, however, depends on the type
of database installed.
SAP AG
TAW10
7-4
Presentation
Server
Layer
Work Process
Application
Server
Layer
ABAP Program
Database
SAP AG 2001
This graphic can be simplified for most topics discussed during this course. The interaction between a
single user and a single ABAP program will be of primary interest to us during this course.
The exact processes involved in user dispatching on an application server are secondary to understanding
how to write an ABAP program. Therefore, we will work with a simplified graphic that does not
explicitly show the dispatcher and the work process. Certain slides will, however, include these details
whenever they are relevant to ABAP programming.
ABAP programs are processed on the application server. The design of user dialogs and database
dialogs is, therefore, of particular importance when writing application programs.
SAP AG
TAW10
7-5
Presentation
Server
Layer
Application
Server
Layer
Screen
Selection Screen
List
Black Box
Database
SAP AG 2001
Most users are only interested in how a business transaction flows and how to enter data into and display
data from a transaction. The technical aspects of programming are less interesting. The user does not
need to know the precise flow of the ABAP program on the application server. To the average user, the
SAP system is like a "black box."
Technically speaking, there are three different types of screens: dynamic screens or dynpros, selection
screens, and lists. Each type of screen provides different services. The developers task is to select for
each user dialog exactly those types that are most suitable for the accomplishment of the tasks
concerned. For this reason, developers should have precise knowledge of the technical aspects.
SAP AG
TAW10
7-6
ABAP Program
Program
Start
ABAP
Processing
Block
Database
Table
ABAP
Processing
Block
Time
Once the user performs a user action (selecting Enter, a function key, a menu function or a pushbutton,
for example), control is passed from the presentation server to the application server.
If a further user dialog is triggered from within the ABAP program, the system transmits the screen and
passes control once again to the presentation server.
SAP AG
TAW10
7-7
System
System Architecture
Architecture and
and ABAP
ABAP Program
Program
Example
Example Program
Program with
with Selection
Selection Screen
Screen and
and List
List
SAP AG 2003
SAP AG
TAW10
7-8
Program Start
Program
Start
Repository
Database
Table
SAP AG 2001
Time
Whenever a user logs on to the system, a screen is displayed. From this screen, the user can start an
ABAP program via a menu path or by entering a transaction code.
SAP AG
TAW10
7-9
Program
Start
ABAP Program
Repository
Selection Screen
Data Objects
Database
Table
ABAP
Processing
Block
Time
The system first loads the program context onto the application server. The program context contains
memory areas for variables and complex data objects, information on the screens for user dialogs, and
ABAP processing blocks. The runtime system gets the program information from the Repository, which
is a special part of the database.
The sample program has a selection screen as the user dialog, a variable and a structure as data objects,
and one ABAP processing block. The list that is used to display the data is created dynamically at run
time.
SAP AG
TAW10
7-10
Program
Start
ABAP Program
Repository
Data Objects
Database
Table
ABAP
Processing
Block
Time
Because the program contains a selection screen, the ABAP runtime system sends it to the presentation
server. The presentation server controls the program flow for as long as the user enters data in the input
fields.
Selection screens allow users to enter selection criteria required by the program.
SAP AG
TAW10
7-11
Program
Start
ABAP Program
Repository
Data Objects
Database
Table
ABAP
Processing
Block
Time
As soon as the user has finished entering data on the selection screen, he or she can trigger further
processing of the program by selecting Execute.
The entered data is automatically placed in its corresponding data objects in the program and the ABAP
runtime system resumes control of processing.
In our simple program example, there is only one ABAP processing block. The ABAP runtime system
triggers sequential processing of this ABAP processing block.
If the entries made by the user do not have the correct type, an error message is triggered automatically.
The user must correct the entries.
SAP AG
TAW10
7-12
Program
Start
ABAP Program
Repository
Data Objects
Database
Table
ABAP
Processing
Block
Time
Within the ABAP processing block, a read access to the database is programmed. The program passes to
the database information about which database table to access and which line in the table to read.
SAP AG
TAW10
7-13
Program
Start
ABAP Program
Repository
Data Objects
Database
Table
ABAP
Processing
Block
Time
The database returns the requested data record to the program and the runtime system ensures that this
data is stored in the appropriate data objects.
If a single record is accessed, this data object is usually a structure that contains components for all the
required database fields.
SAP AG
TAW10
7-14
Program
Start
ABAP Program
Repository
Data Objects
Database
Table
ABAP
Processing
Block
Time
The layout of the subsequent list display was also programmed into the processing block. After
completion, the runtime program sends this list as a screen to the presentation server.
SAP AG
TAW10
7-15
SAP AG 2001
SAP AG
TAW10
7-16
Contents:
Introduction to the R/3 Repository
Working with the Object Navigator
Organizing Developments
Developing an ABAP Program
SAP AG 2001
SAP AG
TAW10
8-1
SAP AG 2001
SAP AG
TAW10
8-2
Introduction
Introduction to
to the
the R/3
R/3 Repository
Repository
Working
Working with
with the
the Object
Object Navigator
Navigator
Organizing
Organizing Developments
Developments
Developing
Developing ABAP
ABAP Programs
Programs
SAP AG 2001
SAP AG
TAW10
8-3
Presentation
Server
Layer
Application
Server
Layer
ABAP Program
Cross-client
Database
Client-specific
Repository
Customizing tables
Application tables
SAP AG 2001
The database contains application and Customizing tables that are usually client-specific.
The database also contains the R/3 Repository. The ABAP Dictionary is part of the R/3 Repository.
The R/3 Repository contains all the development objects, for example, programs, definitions of
database tables, or central data type definitions. Development objects are therefore also known as
Repository objects.
Repository objects are never client-specific; therefore, they can be viewed and used in all clients.
SAP AG
TAW10
8-4
Repository Objects
FI
HR
MM
SD
WM
MM
MM
MM
Cust.
Development Classes
Function Modules
Programs
Tables
...
SAP AG 2001
SAP AG
TAW10
8-5
+
+
+
CA
AC
FI
Cross-Application Components
Accounting - General
Financial Accounting
...
FBAS Financial Accounting Basis
...
+ FI-GL General Ledger Acctg
+ FI-LC Consolidation
...
Treasury
TR
CO Controlling
...
Application component
Information System
Development class
Selected subtree
SAP AG 2001
The structure of the application components is shown in the application hierarchy. From the SAP Easy
Access menu, you access the application hierarchy by choosing
Tools ABAP Workbench Overview Application Hierarchy.
The application components are displayed in a tree structure in the application hierarchy. Expanding a
component displays all the development classes that are assigned to that component.
You can select a subtree or branch and navigate from the application hierarchy to the R/3 Repository
Information System. The system then collects all development classes for the branch selected and passes
them to the Repository Information System.
SAP AG
TAW10
8-6
You can use the Repository Information System to search for specific Repository objects. Suitable
search criteria are available for the various Repository objects.
Which objects are to be found using the Repository Information System depends on how you get there:
From within the application hierachy, select the Information system (double-click the selected
application component or development class). This filters the the respective Repository objects.
From the SAP Easy Access menu, choose Tools ABAP Workbench Overview Information
system. The system lists all the Repository Objects available for searching.
SAP AG
TAW10
8-7
Introduction
Introduction to
to the
the R/3
R/3 Repository
Repository
Working
Working with
with the
the Object
Object Navigator
Navigator
Organizing
Organizing Developments
Developments
Developing
Developing ABAP
ABAP Programs
Programs
SAP AG 2001
SAP AG
TAW10
8-8
Debugger
Screen Painter
Menu Painter
FI
HR
MM
SD
WM
Object
Navigator
MM
Cust.
ABAP Editor
ABAP Dictionary
Function Builder
Class Builder
SAP AG 2001
The ABAP Workbench contains different tools for editing Repository objects. These tools can be used
throughout the entire software development cycle. The most important tools for creating and editing
Repository objects are as follows:
The ABAP Editor for editing source text
The ABAP Dictionary for processing database table definitions, central data types, and more
The Screen Painter for configuring screens (screens with functions for user dialogs)
Menu Painter for designing the user interface (menu bar, standard toolbar, application toolbar)
(see Interfaces)
The Function Builder for processing function modules
The Class Builder for processing central classes
You can start these tools in three ways:
Directly from the Easy Access menu.
Using the Object Navigator. This has a tree diagram of all objects within a development class or
program. Double-click on an object to start the respective tool.
By double-clicking from one tool to the next, and back again.
SAP AG
TAW10
8-9
Tool area
Navigation area
Right-click
Right-click
Context menu
Context menu
SAP AG 2001
SAP AG
TAW10
8-10
Development Class
BC400
Display higher-level
object list
Use of navigation
history
BC400
Favorites
Dictionary objects
Programs
SAPBC400WBD_GETTING_STA
SAPBC400WBT_GETTING_STA
Function groups
BC400
Classes
CL_BC400
Double-click on a
Repository object with
subobjects: List of
subobjects
SAP AG 2001
SAP AG
TAW10
8-11
Functions of the
current tool
Show navigation
window
Use of navigation
history
Navigation stack
Hide navigation
window
SAP AG 2001
In the tool area, you can display a window showing your navigation history, that is, a list of the objects
you have displayed since you started the Object Navigator in the tool area.
The object currently displayed in the tool area is highlighted in a different color.
SAP AG
TAW10
8-12
Double-click on a
Repository object
without subobjects or
choose context menu:
Display/change in tool
area
Display
Change
...
SAP AG 2001
Navigation in the navigation area is logically independent from navigation in the tool area. This allows
for screens to be used in a flexible manner.
If you wish, you can synchronize the two areas:
You can display an object in the tool area by double-clicking it, or by selecting the context menu
from within the navigation area. The system automatically selects the appropriate tool for processing
the object you selected.
To display the object list that belongs to an object you are currently processing in the tool area,
choose Display object list.
To create objects from an object list, you can use the context menu for that object type. If there is no
entry in the object list for the required object type, you can create any number of objects using Edit
object or Other object.
SAP AG
TAW10
8-13
Organizing Developments
Introduction
Introduction to
to the
the R/3
R/3 Repository
Repository
Working
Working with
with the
the Object
Object Navigator
Navigator
Organizing
Organizing Developments
Developments
Developing
Developing ABAP
ABAP Programs
Programs
SAP AG 2001
SAP AG
TAW10
8-14
Change
Request
FI
HR
MM
FI
SD
HR
MM
WM
MM
SD
Cust.
WM
MM
Cust.
Development System
Production System
SAP AG 2001
Development projects are always implemented in a development system and then transported to the next
system.
Repository objects are automatically assigned to a transport route based on their belonging to a particular
development class and on their actual function.
A decisive criterion for combining the development projects is, therefore, which Repository objects need
to be transported together because of their dependencies.
You schedule the group transport of the Repository objects using a change request.
SAP AG
TAW10
8-15
Monday
...
Friday
Request is released
SAP AG 2001
Scheduling a development project using a change request covers the following aspects:
All employees in the project start their work on a defined date.
Employees have the chance to follow up and check their activities separately.
The respective Repository objects can be processed by all employees involved in the project. For those
developers who do not belong to the team, the Repository objects remain locked until the project is
completed.
The group triggers the transport of all the respective Repository objects.
SAP AG
TAW10
8-16
Project Manager:
FRY
Team:
FRY
Request number
Transportable
BC400-00
BC400-01
BC400-02
BC400-03
Project
Manager
Changeable
User
IT3K900051 CARSON
Task number
IT3K900052 CARSON
IT3K900053 BC400-00
Repository objects
created or corrected
by employee
Report source
ZBC400_00_FLIGHTLIST
ABAP program
IT3K900054 BC400-01
...
IT3K900055 BC400-02
IT3K900056 BC400-03
IT3K900057
...
SAP AG 2001
At the beginning of a development project, the project manager creates a change request in the
Workbench Organizer. The project manager assigns all project team members to the change request.
The Workbench Organizer then creates a task for each project developer.
From now on, whenever an employee assigns a Repository object to this change request, the Repository
object is automatically entered in the employee's task. Thus all Repository objects that an employee
works on during a development project are collected within his or her task folder. The Repository
objects are therefore locked for all developers who do not belong to this particular project.
Unlike the logical functional divisions that separate Repository objects through the respective
development class, change requests are project-related and, therefore, are limited to the time schedule
involved. Thus, although a program always belongs to only one development class, it can belong to
different change requests at different times.
SAP AG
TAW10
8-17
ZBC400_00
Short Text
Exercises group 00
Where should the development objects be transported to?
Transport Layer
ZDEV
Person Responsible
BC400-00
Software Component
Application Component
HOME
CA
To which application
component does the
development class belong?
SAP AG 2001
SAP AG
TAW10
8-18
ZBC400_00
Request
IT3K90051
Workbench request
My requests
Double-click
request number
Changeable
Transportable
IT3K900051 FRY
IT3K900052 FRY
IT3K900053 BC400-00
IT3K900054 BC400-01
SAP AG 2001
All Repository objects that are created or changed must be assigned to the change request of the
respective project. For this course, the trainer has created a change request for the project called
"Exercises for Participants of BC400". Each group has a task within this change request.
To display all change requests in which you have a task, select Own requests.
When you assign all Repository objects (development classes, programs, and so on) to this change
request, the system takes care of the exact assignment for your task.
SAP AG
TAW10
8-19
Introduction
Introduction to
to the
the R/3
R/3 Repository
Repository
Working
Working with
with the
the Object
Object Navigator
Navigator
Organizing
Organizing Developments
Developments
Developing
Developing ABAP
ABAP Programs
Programs
SAP AG 2001
SAP AG
TAW10
8-20
SAP AG 2001
To support data processing by types, ABAP contains a systematic type hierarchy. Type conversions and
type casting are supported.
Using translatable text elements, you can develop multi-language applications.
The OPEN SQL standard embedded in ABAP allows direct database accesses.
ABAP Objects is the object-oriented enhancement of the ABAP programming language.
The ABAP runtime system is one of the R/3 Basis components and is platform-independent.
ABAP continues to evolve from release to release. If an old syntax statement is replaced by a better one,
you can still run the old statement.
SAP AG
TAW10
8-21
ABAP
keyword
DATA
DATA wa_scarr TYPE scarr..
START-OF-SELECTION.
STARTSTART-OFOF-SELECTION.
SELECT * FROM scarr
INTO CORRESPONDING FIELDS OF wa_scarr..
NEW-LINE.
NEW-LINE.
NEW
WRITE wa_scarr-carrid..
WRITE wa_scarr-carrname..
WRITE wa_scarr-url..
ENDSELECT.
ENDSELECT.
SAP AG 2001
For indentations and for converting uppercase and lowercase letters, use the Pretty Painter function.
Choose Utilities Settings ABAP Editor Pretty Printer
SAP AG
TAW10
8-22
** comments ...
** comments ...
** comments ...
Comments
Chained
Statement
ENDSELECT.
SAP AG 2001
Use an asterisk (*) to introduce comment lines. The ABAP runtime system ignores the comment line.
If you want to enter a comment in the middle of a started line, enter double quotes.You can combine
consecutive statements with an identical beginning into a single chained statement:
Close the identical beginning part with a colon.
Separate individual elements that come after the colon by commas.
Use blank spaces and line breaks before and after the separators (colons, commas, and periods).
The ABAP runtime system considers the individual parts of a chained statement to be single
statements.
SAP AG
TAW10
8-23
SAP AG 2001
With several ABAP statements, the ABAP runtime system writes a return code into the system field sysubrc to indicate how successfully the statement was executed
The return code zero (0) means that the statement was successful..
Read the documentation for the respective statements to find out whether and how this return code is set
in individual cases.
SAP AG
TAW10
8-24
ZBC400_00_GS
Title
Attributes
Type
Executable program
Status
Application
Test program
Fixed point arithmetic
SAP AG 2001
From the Object Navigator, you can create a program using one of the following options:
In the navigation area, choose Program as the object type and enter a program name. Be sure to
comply with the customer namespace conventions. If the program does not exist, the system displays
the dialog sequence that lets you create a program. (This procedure is possible only as of Release
4.6C.)
Display the development class for which you want to create the program. Start the dialog sequence for
creating a program using the development class context menu or the Program node.
Select Other object... or Edit object. Select the Program objects tab and enter the name. Select Create.
In this course, deselect With Top Include (by removing the check mark from the checkbox). (If you dont
do this, your source text would be distributed to several programs.)
Change the title to a meaningful short text.
Choose Test program as the program status for all ABAP courses.
SAP AG
TAW10
8-25
i
Help
START-OF-SELECTION.
SELECT SINGLE * FROM scarr
Editor Help
INTO wa_scarr
ABAP Overview
WHERE carrid = pa_car.
WRITE
ABAP Term
IF sy-subrc = 0.
ABAP News
MOVE-CORRESPONDING wa_scarr
ABAP Docu and Examples
TO sbc400_carrier.
Keyword
CALL SCREEN 100.
Documentation
MOVE-CORRESPONDING sbc400_carrier
WRITE
WRITE:
F1 TO wa_scarr.
wa_scarr-carrid,
wa_scarr-carrname,
wa_scarr-currcode.
ENDIF.
SAP AG 2001
SAP AG
TAW10
8-26
Actively integrated,
for system-wide
usage
Program 1,
active version
Program 2,
active version
Program 3,
inactive version
Program 3,
active version
SAP AG 2001
Whenever you create a development object, or change and then save it, the system stores an inactive
version only in the R/3 Repository.
Before a Repository object is available on a system-wide basis, it must first be available as an active
version. This active version of your program will be used whenever a user wants to execute your
program.
If your program is available in both versions, you can switch from one version to the other in display
mode.
Whenever you activate a program, the system first displays a list of all inactive objects that you have
processed. This is called the worklist. If you continue to activate the program, the following happens:
The system saves the program, that is, it stores or overwrites the inactive version.
The system performs a syntax check.
The system stores the active version or overwrites it.
SAP AG
TAW10
8-27
saved,
actively integrated,
for development/testing
Program 3,
inactive version
Program 3,
active version
Generate
(automatically)
Generate
(automatically)
Program 3,
generated version
SAP AG 2001
When you generate a development object, the system creates (compiles) a separate runtime object
(LOAD) and stores it in the R/3 Repository.
SAP AG
TAW10
8-28
Help
Transaction code
Development class
Z00GS
ZBC400_00
Transaction text
...
Program
ZBC400_00_GS
...
Classification
Professional User Transaction
Easy Web transaction
...
...
SAP AG 2001
If you want to include a program in role menus or in the Favorites in your SAP Easy Access menu, you
must assign a transaction code to it.
In the Object Navigator, display the object list for your program. Right-click the program name and
choose Create Transaction. Comply with the customer namespace conventions.
Choose Program and Selection Screen (Report Transaction) if the program is an executable program.
On the next screen, enter the name of the program. Choose Professional User Transaction.
Save the transaction code.
Since each transaction code is a Repository object, you must assign it to a development class and to a
change request on the following screens.
SAP AG
TAW10
8-29
Help
Z00GS
SAP AG 2001
SAP AG
TAW10
8-30
SAP AG 2001
SAP AG
TAW10
8-31
As a developer for an airline group, you are given the task of developing
evaluation programs for several airline companies.
To group the Repository objects together logically and transport them,
you must create a development class.
User name:
Development class:
Change request:
ZBC400_##
Log on to the operating system and then to the specified SAP R/3 training system using the
user name the instructor has given you. Enter a new personal password.
1-2
Create the development class ZBC400_##. Assign it to the change request the instructor
has given you.
1-3
From now on, assign all your Repository objects in the following exercises to this
development class and this change request.
SAP AG
TAW10
8-32
Exercises
Unit: Introduction to the ABAP Workbench
Topic: Developing ABAP Programs
At the conclusion of these exercises, you will be able to:
Create, edit, save, and process ABAP programs
Check ABAP programs for correct syntax
Test and activate ABAP programs
Create an ABAP program that lists additional information on all existing
flight departure times.
Get the data from the database table SFLIGHT.
Program: ZBC400_##_GS_LIST
Model solution:
SAPBC400WBS_GS_LIST
2-2
Define a work area for the data retrieval and data display (name suggestion: wa_flight):
DATA wa_flight TYPE sflight.
2-3
Program a loop access to all the data records in the database table SFLIGHT:
SELECT * FROM sflight
INTO wa_flight.
...
ENDSELECT.
2-4
For each data record, display the contents of the fields carrid, connid, fldate,
seatsocc, and seatsmax in the list:
NEW-LINE. WRITE wa_flight-carrid. WRITE ...
2-5
Check your program for syntax errors, test it, and activate it
SAP AG
TAW10
8-33
Exercises
Unit: Introduction to the ABAP Workbench
Topic: Transaction Codes
At the conclusion of these exercises, you will be able to:
Assign transaction codes to ABAP programs
Add transaction codes to your Favorites list in the SAP Easy Access
menu
Give your first ABAP program a transaction code, in addition to its
technical name, which you use to execute it.
ZBC400_##_GS_LIST
Model solution:
SAPBC400WBS_GS LIST
3-2
SAP AG
TAW10
8-34
Follow the instructions as given in the notes and figures on page 3-18 and 3-19, Creating
Development Classes and Assignment to a Change Request.
Model solution:
REPORT sapbc400wbs_gs_list.
DATA wa_flight TYPE sflight.
SELECT * FROM sflight
INTO wa_flight.
NEW-LINE.
WRITE:
wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-seatsocc,
wa_flight-seatsmax.
ENDSELECT.
SAP AG
TAW10
8-35
3-1
Follow the instructions as given in the notes and figure on page 3-29, Creating Transaction
Codes.
3-2
Follow the instructions as given in the notes to the figure, Adding a Transaction Code to
the SAP Easy Access Menu.
SAP AG
TAW10
8-36
Contents:
SAP Flight Data Model
Transparent Tables
Structures
Using Transparent Tables and Structures in an ABAP
Program
SAP AG 2001
SAP AG
TAW10
9-1
SAP AG 2001
SAP AG
TAW10
9-2
Data Modeling
Real world
Data model
ABAP Dictionary
Relational
database
SAP AG 2001
In the development of business application software, the real world must be partly mapped in the form of
data. An entity represents a business unit.
Entities all relate to each other. The entities and relationships are contained in the data model or entity
relationship model (ERM).
The conversion of the table definitions and their relationships in the ABAP Dictionary are based on this
data model.
The actual application data is physically stored in the database itself.
SAP AG
TAW10
9-3
Departure city
Departure airport
Destination airport
Destination city
SAP AG 2001
ABAP training courses, online documentation, and ABAP keyword documentation all use the same
flight data model. All Repository objects in the flight data model are located in the development class
BC_DATAMODEL.
This training course demonstrates one simple excerpt from this data model, which the instructor can
refine if necessary. If a person wants to travel from one place to another, she asks the travel agency the
following questions:
What connection offers me the best and most direct flight?
At what times are flights offered on the date when I want to travel?
How can I optimize the travel conditions to find the best solution? What is the cheapest flight, the
fastest connection, the connection that gets me there closest to the time when I want to arrive?
The passengers view differs from that of a travel agency. In the data model, which is tailored to suit
management of the necessary data, all data is stored, organized by technical criteria, in tables on a
central database. The amount of data stored far exceeds the demands of the passenger.
As a programmer, you must be able to compile the data in programs to suit the requirements of the travel
agent.
SAP AG
TAW10
9-4
BC_AIRPORT
Airline
Airport
City
H
BC_PLANFLI
BC_GEOCITY T
A
T
R R
BC_CITAIRP
City-airport
assignment
Timetable
H
BC_SFLIGHT
Flight
BC_CUSTOM T
BC_COUNTER T
BC_TRAVLAG T
Customer
Sales office
Travel agency
H
BC_BOOKING T
CR
CR
Flight booking
SAP AG 2001
The flight data model contains entities for all business information that is logically connected, such as:
Cities
Airports
Airlines
Flights
These entities all relate to each other in certain ways:
Each flight schedule contains exactly one airline, one departure airport, and one destination airport.
Bookable flights always belong to exactly one existing flight schedule each.
You can assign cities to nearby airports.
You can manage all necessary data without redundancies, using these relationships. At the same time,
the travel agency is able to obtain all data requested by the customer.
SAP AG
TAW10
9-5
Airline
SCARR
MANDT
CARRID
CARRNAME
CURRCODE
URL
H
BC_PLANFLI
Timetable
SPFLI
MANDT
AIRPTO DEPTIME
...
H
BC_SFLIGHT
Flight
SFLIGHT
MANDT
SEATSMAX
SEATSOCC
...
H
BC_BOOKING T
Flight booking
SBOOK
MANDT
COUNTER
...
SAP AG 2001
A transparent table contains different columns, to allow you to manage data records in a structured way.
You define transparent tables in the ABAP Dictionary. In this context, the table key is especially
significant.
The table key of a table combines key fields, which are also called primary key fields.
The values in the key fields allow the system to identify all data records uniquely.
Fields that link to other tables are called foreign key fields. With these foreign key relationships you can
manage the data hierarchically and consistently.
SAP AG
TAW10
9-6
SAP AG
TAW10
9-7
Table
Edit
Goto
Utilities
Extras
Environment
System
Help
SPFLI
Short text
Flight schedule
Fields
Attributes
Fields
MANDT
CARRID
CONNID
COUNTRYFR
CITYFROM
AIRPFROM
COUNTRYTO
CITYTO
...
Key
!
!
!
Field type
S_MANDT
S_CARR_ID
S_CONN_ID
LAND_1
S_FROM_CIT
S_FROMAIRP
LAND_1
S_TO_CITY
...
Active
Currency/Quantity Fields
Data type
CLNT
CHAR
NUMC
CHAR
CHAR
CHAR
CHAR
CHAR
...
Length
3
3
4
3
20
3
3
20
...
Dec. places
0
0
0
0
0
0
0
0
...
Short text
Client for training
Airline Carrier
Flight connection
Country key
City of departure
Airport of departure
Country key
Arrival city
...
SAP AG 2001
The fields make up the columns of the transparent table. A check mark in the Key column indicates that
the corresponding field is a key field.
You normally assign a type to a field using a data element (under Field type). The Short text stored with
the data element is listed here. The technical attributes of the field are listed again under Data type,
Length, and Dec. places. (A data element normally uses a domain.)
This is a logical view of the table. It is a purely technical description. When it is physically converted,
the table is in the database, where you also find the table content or the actual application data.
SAP AG
TAW10
9-8
Structure
SBC400FOCC
Short text
Attributes
Component
CARRID
CONNID
FLDATE
SEATSMAX
SEATSOCC
PERCENTAGE
Components
Active
Entry help/check
Component type
S_CARR_ID
S_CONN_ID
S_DATE
S_SEATSMAX
S_SEATSMAX
S_FLGHTOCC
DTyp
CHAR
NUMC
DATS
INT4
INT4
DEC
Length
3
4
8
10
10
5
Currency/quantity fields
Dec. places
0
0
0
0
0
2
Short text
Airline
Flight connection
Flight date
Maximum capacity
Occupied seats
Flight Occupancy
SAP AG 2001
A flat structure is defined in almost the same way as a transparent table, except that you cannot convert
fields to key fields. This would be pointless for structures. Structures do not represent a database table in
the ABAP Dictionary, but are a pure type definition instead.
When defining a flat structure, however, we refer to component and component type as opposed to
field and field type, because, in contrast to transparent tables, you can define complex structures. This
means that, it is possible to store a structure or substructure under a component name.
SAP AG
TAW10
9-9
400 20011231
seatsmax
450
64 US
seatsocc
New York
percentage
180
40
US
...
pa_carr L H
SAP AG 2001
A structure is used to centrally provide a data type in which fields from different tables are compiled.
In the ABAP program, you can define data objects using the (Dictionary) structure.
A transparent table merely represents a technical description in the ABAP Dictionary. Therefore you can
use it as a central data type definition, as with a structure. This means that, similarly to the data object
definitions listed above, the following variants are also possible:
DATA wa_spfli TYPE spfli provides a data object, typed like the line in the transparent table
SPFLI.
TABLES sbc400focc provides a data object, typed like the structure SBC400FOCC.
PARAMETERS pa_carr TYPE sbc400focc-carrid provides an input field, typed like the
CARRID component of the structure SBC400FOCC.
SAP AG
TAW10
9-10
Dict/Program fields
Airline
Performance Assistant
F1
Short description ...
ID
AA
AB
AC
AF
Documentation
Airline
American Airlines
Air Berlin
Air Canada
Air France
Input help
SAP AG 2001
If you use an elementary structure to define an input field on a selection screen, you can use semantic
attributes or technical attributes. On request, the system automatically generates a documentation
dialog and an input help dialog for the user. The necessary information for this is taken from the ABAP
Dictionary.
The same applies to fields of transparent tables.
If you use an elementary structure component to assign a type to an input/output field on a screen, you
can use the same attributes as with selection screens.
If you have defined a foreign key relationship, the resulting value combinations appear in the input help
on the screen. If an error occurs, the system processes an automatic error dialog.
The same applies to fields of transparent tables.
Use the TABLES statement to define the data object for the data transport between screen and program.
SAP AG
TAW10
9-11
SAP AG 2001
SAP AG
TAW10
9-12
Program: SAPBC400WBT_GETTING_STARTED
1-1
Open the object list for development class BC400. Find the program
SAPBC400WBT_GETTING_STARTED, and open its object list. Throughout the exercise,
make sure that you remain in display mode.
1-2
1-3
1-3-2
1-3-3
1-3-4
SAP AG
TAW10
9-13
1-4
1-5
Use the object list to analyze the source code of the program.
1-5-1 What data objects are there? Where are they defined in the program?
1-5-2 Where in the program are they used?
(Use the where-used list in the ABAP Editor.)
1-5-3 What data object corresponds to the input field on the selection screen?
(Search the object list for a data object with the same name as the field that you
found in step 1-3-4.)
SAP AG
TAW10
9-14
1-4
1-5
SAP AG
TAW10
9-15
Contents:
Data Types and Data Objects
Basic ABAP Statements
Using the ABAP Debugger
Working with Structures
Working with Internal Tables
SAP AG 2001
SAP AG
TAW10
10-1
SAP AG 2001
SAP AG
TAW10
10-2
Data
Data Types
Types and
and Data
Data Objects
Objects
Basic
Basic ABAP
ABAP Statements
Statements
Using
Using the
the ABAP
ABAP Debugger
Debugger
Working
Working with
with Structures
Structures
Working
Working with
with Internal
Internal Tables
Tables
SAP AG 2001
SAP AG
TAW10
10-3
ABAP program
Data objects
Object
F
Interface
Subroutine
e
le
fac odu
er
Int on m
cti
un
Interface
Method
SAP AG
TAW10
10-4
ABAP program
Object
F
Interface
Subroutine
e
le
fac odu
er
Int on m
cti
un
Interface
Method
SAP AG 2001
You can define data types in an ABAP program (local, keyword TYPES) or in the ABAP Dictionary
(global). Using global data types has several advantages:
Global types are managed centrally and you can use them in all repository objects. This increases the
consistency of the system and significantly reduces the amount of maintenance.
In the ABAP Dictionary, you can perform an environment analysis (where-used list).
Global data types can be linked to business variables by content, and therefore contain semantic and
technical information.
You can use global datat types to design screens.
When searching for global data types, make sure you take both the technical and semantic attributes into
account. Only then will you be able to make full use of the maintenance and robustness advantages of
your program.
SAP AG
TAW10
10-5
Local types
TYPES type_name TYPE ...
Predefined
ABAP types
d
t
i
f
string
n
c
xstring x
You can use a predefined ABAP type, a local, or a global type to type a data object.
The following predefined ABAP types are complete:
d
Date (format: YYYYMMDD)
t
Time (format: HHMMSS)
i
Integer
f
Floating point number
string String (of variable length)
xstring Byte sequence (heXadecimal string, of variable length)
You must define the length for these predefined types:
c
Character
n
Numeric character
x
Byte (heXadecimal)
p
Packed number (= binary coded decimals). You must enter the number of decimal
places.
For more information on predefined ABAP types, refer to the keyword documentation on TYPES or
DATA.
You can use LIKE to refer to the type of a predefined data object.
SAP AG
TAW10
10-6
TYPE
TYPE
TYPE
TYPE
i VALUE 17,
t_percentage,
s_carr_id,
sbc400focc-connid.
S_CARR_ID
Data
element
Structure
SBC400FOCC
17
number
percentage
carrid
connid
SAP AG 2001
The predefined ABAP types (d, t, i, f, string, and xstring) are complete. This means they can
define an elementary data object of these types as follows:
DATA do_name TYPE predefined_ABAP_type.
For the predefined ABAP types c, n, p, and x, you must define the length. This means you should first
define an elementary type:
TYPES type_name(length) TYPE predefined_ABAP_type.
You use it to define the data object:
DATA do_name TYPE type_name.
For type p, you can also define the number of decimal places using the DECIMALS addition.
You can use the VALUE addition to pre-assign the value of an elementary data object.
For compatibility reasons, you can still construct data objects in the DATA statement without first
having to define the type locally in the program with a TYPES statement.
In the case of incompletely predefined ABAP types, the system adds standard values to make up the
missing type information.
If there is no type specification at all, the system defines a type c data object with a length of one.For the
standard lengths and for more information, refer to the keyword documentation for TYPES and DATA.
The same syntax applies to global types as to user-defined types:
DATA do_name TYPE global_type_name
SAP AG
TAW10
10-7
Text literal:
literal Type c
Character string: 'aBcdE'
Decimal numbers: '123.45'
Floating point numbers: '123.45E01'
Constant:
SAP AG 2001
You assign a value to each fixed data object in the source code. Therefore, it cannot be changed at run
time.
You can use literals to transfer fixed values to ABAP statements. There are numeric literals and text
literals. The latter are always enclosed in inverted commas:
You can display integers as numeric literals (in the case of negative numbers, with a preceding
sign). The system then maps them onto the data type i, if they are within the value range of 4-byte
integers. Higher numeric literals are mapped onto data type p.
You must display all other literals (such as character sets, numbers with decimal places, floating
point numbers) as text literals. They are mapped onto data type c and converted later, if necessary.
If you want to include an inverted comma in a text literal, you must enter it twice.
You define constants using the CONSTANTS statement. Their type is defined similarly to the type of an
elementary data object with the DATA statement. The VALUE addition is required for constants
Recommendation: Avoid literals when using statements. Create constants instead. This significantly
improves program maintenance.
SAP AG
TAW10
10-8
Data
Data Types
Types and
and Data
Data Objects
Objects
Basic
Basic ABAP
ABAP Statements
Statements
Using
Using the
the ABAP
ABAP Debugger
Debugger
Working
Working with
with Structures
Structures
Working
Working with
with Internal
Internal Tables
Tables
SAP AG 2001
SAP AG
TAW10
10-9
Value Assignments
Data declarations
CONSTANTS c_qf TYPE s_carr_id VALUE 'QF'.
DATA: carrid1 TYPE s_carr_id,
carrid2 TYPE s_carr_id VALUE 'LH',
counter TYPE i.
Program start
c_qf QF
carrid1
carrid2
counter
LH
QF
LH
carrid2 = carrid1.
QF
QF
ADD 1 TO counter.
QF
QF
CLEAR
CLEAR: carrid1,
carrid2,
counter.
ABAP program
ABAP runtime system
Time
SAP AG 2001
When a program is started, the program context is loaded into a storage area of the application server
and made available for all the data objects.
Every elementary data object is preassigned the type-related initial value, except if you preassigned a
different value using the VALUE addition.
You can use the MOVE statement to copy the contents of data objects. Two statements are available for
this purpose:
MOVE source TO target.
target = source.
If the two data objects have different types, the type is automatically converted if there is a conversion
rule.
For detailed information about copying and the conversion rules, refer to the keyword documentation for
the MOVE statement.
The CLEAR statement resets the contents of a data object to the type-related initial value. For detailed
information about the initial values for a particular type, refer to the keyword documentation for the
CLEAR statement.
SAP AG
TAW10
10-10
Calculations
Data declarations
DATA: max
TYPE sbc400focc-seatsmax,
occ
TYPE sbc400focc-seatsocc,
percentage TYPE sbc400focc-percentage.
COMPUTE
COMPUTE
ABAP program
SAP AG 2001
In ABAP you can program arithmetic expressions nested to any depth. Note that parentheses and
operators are keywords and must be separated by at least one blank character.
The following are valid operators:
+
Addition
Subtraction
*
Multiplication
/
Division
** Power
DIV Integer division without remainder
MOD Integer division with remainder
There are several functions for different data types in the ABAP runtime environment.
For example, the following statement returns the current length of the contents of a character set:
length = STRLEN( cityfrom ).
With functions the opening parenthesis is part of the ID. The rest must again be separated by at least one
space.
In general, the usual algebraic rules apply for the processing sequence: expressions in parentheses come
first, then powers, then multiplication/division, and finally addition/subtraction.
For detailed information about the available operations and functions, refer to the keyword
documentation for COMPUTE..
SAP AG
TAW10
10-11
Conditional Branching
CASE data_object_1.
WHEN data_object_2.
Statements
WHEN data_object_3 OR
OR data_object_4.
Statements
OTHERS
WHEN OTHERS.
IF
IF <logical_expression>.
Statements
ENDCASE
ENDCASE.
Statements
ELSEIF
ELSEIF <logical_expression>.
Statements
ELSE
ELSE.
Statements
ENDIF
ENDIF.
SAP AG 2001
In ABAP you have two ways to execute different sequences of statements, depending on certain
conditions.
With the CASE-ENDCASE construction the criterion for the execution of a statement block is the
similarity of the data objects. If no comparison is successful, then the system executes the OTHERS
branch, if it is available.
Except for the first WHEN branch, all further additions are optional.
With the IF-ENDIF construction, you can use any logical expressions. If the condition is met, the system
executes the relevant statement sequence. If no comparison is successful, then the system executes the
OTHERS branch, if it is available. Except for the first query, all further branches are optional.
For both constructions, the system executes only one statement sequence and always for the first valid
case.
Recommendation:
If, in every condition, you check that a variable is equal to a given value, use the CASE-ENDCASE
construction. It is clearer and less runtime intensive.
Outside of loops you can also use CHECK instead of IF. This query sets the execution of all statements
up to the end of the current processing block under one condition. If this is unsuccessful, the system
continues with the first statement in the next processing block.
SAP AG
TAW10
10-12
Loops
DO [ n TIMES ] [...].
Statements
ENDDO.
Loop
Loop counter:
counter:
sy-index
sy-index
WHILE <logical_expression>.
Statements
ENDWHILE.
LOOP AT ...
Statements
ENDLOOP.
DO.
Statements
SELECT ...
Statements
ENDSELECT.
IF <abort_condition>.
EXIT.
ENDIF.
ENDDO.
SAP AG 2001
In ABAP there are four loop constructions, whereby LOOP-ENDLOOP and SELECT-ENDSELECT
represent special cases. In the DO and WHILE loops, the system stores the number of the current loop
pass in the sy-index field. If these loops are nested, sy-index contains the number of the current
(that is, inner) loop.
Unconditional/index controlled loops
The statements between DO and ENDDO are executed until the loop is left over other statements. You
also have the option of specifying the maximum number of loop passes; otherwise, you may get an
endless loop.
Header controlled loops
The statements between WHILE and ENDWHILE are executed only if the condition
<logical_expression> has been met.
You can use the statements CHECK and EXIT for different effects on the way the loop is processed. For
example, you can construct a footer-controlled loop.
SAP AG
TAW10
10-13
Dialog Messages
Meaning
Type
Behavior
Message appears in
t
s
Status message
Information
Warning
Context dependent
Status bar
Error
Context dependent
Status bar
Termination
Program aborted
Short dump
Short dump
SAP AG 2001
You can use the MESSAGE statement to send dialog messages. You must specify the three-digit
message number and the message class.
Furthermore, you can use the WITH addition to include up to four values. The system, depending on the
message text, inserts these values into the message text.
You control the dialog behavior using the type abbreviation t. There are six different types of message:
a Abort The program is ended after a dialog box.
x Exit
The program ends in a short dump.
e Error Runtime behavior is context dependent.
w Warning Runtime behavior is context dependent.
i Information The program continues after a dialog box.
s Success The message appears in the status bar on the subsequent screen.
For further information about the syntactic alternatives of the MESSAGE statement, refer to the keyword
documentation.
SAP AG
TAW10
10-14
Editor Help
ABAP Overview
ABAP Term
ABAP News
ABAP Docu and Examples
Depending on the context in which they appear, some message types show different dialog behavior.
You can find a program for testing the resulting options in the ABAP documentation. To access these
example programs, choose Utilities Help onABAP doc. and examples (in the following dialog box)
SAP AG
TAW10
10-15
Data
Data Types
Types and
and Data
Data Objects
Objects
Basic
Basic ABAP
ABAP Statements
Statements
Using
Using the
the ABAP
ABAP Debugger
Debugger
Working
Working with
with Structures
Structures
Working
Working with
with Internal
Internal Tables
Tables
SAP AG 2001
SAP AG
TAW10
10-16
Or:
Set a breakpoint and
execute the program
Use the context menu
Program
ZBC400_00_GS
ZBC400_00_GS Execute
REPORT sapbc400wbt_getting_started.
TABLES
sbc400_carrier.
DATA
wa_scarr TYPE scarr.
PARAMETERS pa_car TYPE scarr-carrid.
START-OF-SELECTION.
SELECT SINGLE * FROM scarr
Debugging
INTO CORRESPONDING
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_scarr TO sbc4
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier T
WRITE:/
wa_scarr-carrid,
wa_scarr-carrname,
SAP AG 2001
You can start a program in Debugging mode from the Object Navigator, without having to change the
program in two ways:
In the navigation area, choose Execute Debugging for the selected program.
In the editing area, select the desired program line and choose Set/delete breakpoint. Then start the
program by choosing Execute Direct processing (F8)
SAP AG
TAW10
10-17
System
Or:
Choose menu System
/h
Help
Utilities
Debug screen
Debug ABAP
SAP AG 2001
If you want to debug only certain parts of a program, start the program first and then switch to
debugging mode before a screen change. You can do this in two ways:
Choose System Utilities Debug ABAP or Debug screen.
Enter /h in the command field and select Enter.
SAP AG
TAW10
10-18
SAP
ABAP Debugger
chws
Watchpoint
r
SingleZJJ_FORMS
step
1 - 4
Field Name
pa_carr
SY-SUBRC
SY-TABIX
Field Value
SY-DBCNT
SAP AG 2001
In debugging mode, you can choose Single step to execute the program statement by statement.
You can display the contents of up to eight data objects. Enter the names in the left input field or doubleclick the name in the displayed source code.
SAP AG
TAW10
10-19
SAP
ABAP Debugger
chws
Watchpoint
Continue
Variant
SY-SUBRC
SY-TABIX
Variant
SY-DBCNT
SAP AG 2001
SAP AG
TAW10
10-20
LH
Watchpoints
No. Local Program
Field name
pa_carr
1
2
3
...
10
Logical operator between watchpoints
OR
AND
SAP AG 2001
Watchpoints are breakpoints that depend on the field content. You can create the following types of
watchpoints:
Field name:
The program is executed until the content of the field has changed.
Field name, relational operator, comparison value:
The program is executed until the content of the field has changed so that the defined logical
condition, relative to a value, is met.
Field name, relational operator, comparison value:
The program is executed until the content of the field has changed so that the defined logical
condition, relative to the content of a field, is met.
You can set up to 10 watchpoints and link them using the logical operators AND or OR.
SAP AG
TAW10
10-21
Data
Data Types
Types and
and Data
Data Objects
Objects
Basic
Basic ABAP
ABAP Statements
Statements
Using
Using the
the ABAP
ABAP Debugger
Debugger
Working
Working with
with Structures
Structures
Working
Working with
with Internal
Internal Tables
Tables
SAP AG 2001
SAP AG
TAW10
10-22
Structure
SBC400FOCC
SPFLI
seatsmax
seatsocc
Transparent
table
percentage
wa_focc
mandt carrid connid countryfr cityfrom
spfli
SAP AG 2001
In ABAP, you can define structured data objects (simply called structures). This allows you to combine
values that belong together logically into one object.
Structures can be nested. This means that components can consist of more structures or even tables.
There are two ways to define structures:
For DATA struc_name TYPE struc_type, you can use local or global types
struc_type.
SAP AG
TAW10
10-23
BEGIN OF
OF st_flightinfo,
TYPES: BEGIN
carrid
TYPE s_carr_id,
connid
TYPE s_conn_id,
fldate
TYPE s_date,
seatsmax
TYPE sflight-seatsmax,
seatsocc
TYPE sflight-seatsocc,
percentage(3) TYPE p DECIMALS 2,
END OF
OF st_flightinfo .
END
DATA wa_flightinfo TYPE st_flightinfo.
seatsmax
seatsocc
percentage
wa_flightinfo
SAP AG 2001
You can also define structure types locally using the TYPES statement. The components are enclosed by
the following statements as shown in the graphic:
BEGIN OF structure_type_name.
...
END OF structure_type_name.
Each individual component can in turn be assigned any type you wish.
For more information, refer to the keyword documentation for TYPES.
You define the data object itself in the usual way.
For compatibility reasons, you can also directly define a structured data object:
DATA: BEGIN OF structure_name
...
END OF structure_type_name
SAP AG
TAW10
10-24
SAP AG 2001
SAP AG
TAW10
10-25
...
wa_sflight
wa_focc
carrid connid fldate
SAP AG 2001
SAP AG
TAW10
10-26
SAP
ABAP Debugger
chws
Watchpoint
Fields
Main program
Source code of
wa_sbc400
Structured field
SELECT SINGLE * FROM scarr
INTO CORRESPONDING
Length
(in bytes)
58 FIELDS OF wa_scarr
WHERE carrid = pa_carr.
0.Component name
Type Length Contents
4 IF sy-subrc =No.
MOVE-CORRESPONDING wa_scarr TO sbc400_carrier.
1100.
MANDT
100
C
3
Double-click
the
CALL SCREEN
2
CARRID
AA
C
3
data
object
MOVE-CORRESPONDING sbc400_carrier TO wa_scarr.
3 CARRNAME
American Airlines
C
20
Variant
4 CURRCODE
USD
C
5
wa_sbc400
5 MARK
C
1
6 UNAME
C
12
7 UZEIT
000000
T
6
8 DATE
00000000
D
8
SY-SUBRC
SAP AG 2001
You can trace the field contents of a structure by entering the name of the structure in the left column.
Double-click this entry to see the component display.
SAP AG
TAW10
10-27
Data
Data Types
Types and
and Data
Data Objects
Objects
Basic
Basic ABAP
ABAP Statements
Statements
Using
Using the
the ABAP
ABAP Debugger
Debugger
Working
Working with
with Structures
Structures
Working
Working with
with Internal
Internal Tables
Tables
SAP AG 2001
SAP AG
TAW10
10-28
Internal Tables
Table can be
extended dynamically
SAP AG 2001
Internal tables are data objects that allow you to retain several data records with the same structure in
memory. In principle, the number of data records is unlimited. It is restricted only by the capacity limits
of specific system installations.
The ABAP runtime system dynamically manages the length of internal tables. This eliminates any work
concerning working memory management.
The individual data records in an internal table are known as table lines or table entries. For this reason,
the individual components in a line are referred to as columns of the internal table.
The line type of an internal table can be any ABAP data type, elementary or structured, or it can be
another internal table.
Internal tables are a simple way of processing large data records in a structured form within a program.
Typical uses include:
Temporarily storing data from database tables for future processing
SAP AG
TAW10
10-29
Line type
AA 0017
LH 0400
LH 0400
QF 0005
Key definition
Components
Sequence
Unique / nonnon-unique key
2,572
6,162
7,273
10,000
Index access
SQ
0866
1,625
UA
0007
2,572
UA 0007
Key access
SAP AG 2001
The data type of an internal table is completely specified by the following attributes:
Line type
This is the source of the attributes of the individual columns. You normally specify a structure type but
any data types are possible.
Key definition
The key columns and their order define the criteria by which the tables are identified. Depending on the
access type, the key can be defined as unique or non-unique. With unique keys there are no multiple
entries with identical values in the key.
Data access type
With a key access as with database tables you access using the field contents.
Example: A read access using the search term 'UA 0007' to an internal table with the unique key
CARRID CONNID and the data pictured above returns exactly one data record.
Index access: Unlike database tables, with internal tables the system may number the lines and give
the line an index. You can use this idex to access a specific table line.
Example: A read access to a data record with index 5 returns the fifth data record of the internal table
SAP AG
TAW10
10-30
Index tables
Table type
STANDARD TABLE
Hashed table
SORTED TABLE
HASHED TABLE
Index access
n
Key access
Unique /
NON- UNIQUE
Non-Unique Key
UNIQUE | NON-UNIQUE
UNIQUE
Mainly keys
Keys only
n
Access Using
Mainly index
SAP AG 2001
Another internal table attribute is the table type. Internal tables can be divided into three table types
according to the respective access types:
With standard tables the line numbering is maintained internally. Both index and key accesses are
possible.
With sorted tables the data records are always sorted according to key and saved. Here too, the
index is maintained internally. Both index and key accesses are possible.
With hashed tables the data records are managed optimized at run time. A unique key is a
requirement. With hashed tables only key accesses are possible.
Which table type you use in each case, depends on how that table's entries are generally going to be
accessed:
For index accesses you should normally use standard tables.
Sorted tables are best for unique keys and fixed sorting.
With hashed tables the runtime optimization is noticeable only if the accesses are of the read type
with a unique key.
This course deals with standard tables only. Apart from a few special cases, the syntax is identical for
all three table types.
SAP AG
TAW10
10-31
SBC400_T_SBC400FOCC
Key definition
Key category
Key components
SBC400FOCC
Standard table
Key components
Non-unique
CARRID
CONNID
FLDATE
seatsmax
seatsocc
percentage
itab_flightinfo
SAP AG 2001
Table types can be defined locally in a program or globally in the ABAP Dictionary.
For DATA itab_name TYPE itab_type you can use local or global types itab_type.
For detailed information on the definition of global table types in the ABAP Dictionary, refer to the SAP
Library under Basis ABAP Workbench BC-ABAP Dictionary Types Table types.
SAP AG
TAW10
10-32
TYPES: tt_flightinfo
TYPE STANDARD TABLE OF sbc400focc
WITH NON-UNIQUE
NONKEY carrid connid fldate.
WITH
NON-UNIQUE KEY
DATA itab_flightinfo TYPE tt_flightinfo.
seatsmax
seatsocc
percentage
itab_flightinfo
SAP AG 2001
You can also define internal table types locally using the TYPE statement.
The table type is specified between TYPE and TABLE OF.
The line type comes after TABLE OF.
The key fields are listed after the WITH addition. Note that the order of the key fields plays a part here.
For detailed information about defining local table types, refer to the keyword documentation on
TYPES.
You define the data object itself in the usual way.
For compatibility reasons, you can also directly define an internal table as follows:
DATA itab_name TYPE table_kind TABLE OF struc_type WITH key_def.
SAP AG
TAW10
10-33
ABAP Dictionary
Transparent table
TABLES sbc400focc.
Structure
SPFLI
(Description)
Database
AA
AA
...
LH
LH
17
64
...
400
402
...
...
...
...
...
SPFLI
SBC400FOCC
DATA wa TYPE
sbc400focc.
Structure
SBC400FOCC
DATA it TYPE
sbc400_t_sbc400focc.
Table type
SBC400_T_SBC400FOCC
AA
AA
...
LH
LH
17
64
...
400
402
...
...
...
...
...
SAP AG 2001
SAP AG
TAW10
10-34
APPEND wa TO itab.
APPEND
Insert
INSERT
INSERT
Read
READ TABLE
TABLE itab INTO wa <condition>.
READ
Change
Delete
SAP AG 2001
The following single record operations are available for internal tables: In each case wa represents a
structure that must have the same type as the line type of the internal table itab.
APPEND Appends the contents of a structure to an internal table. This operation should be used
with standard tables only.
INSERT Inserts the contents of a structure into an internal table. In a standard table it is
appended, in a sorted table it is inserted in the right place, and in a hashed table it is inserted
according to the hash algorithm.
MODIFY
DELETE
COLLECT Accumulates the contents of a structure into an internal table. This statement may be
used only for tables whose non-key fields are all numeric. The
numeric values are
summarized for identical keys
For detailed information about the ABAP statements described here, refer to the relevant keyword
documentation.
SAP AG
TAW10
10-35
ENDLOOP
ENDLOOP..
Delete
Inserting several
lines from another
internal table
Appending several
lines from another
internal table
SAP AG 2001
The following set operations are available for internal tables: In each case wa represents a structure that
must have the same type as the line type of the internal table itab.
DELETE
Deletes the lines of the internal table that satisfy the condition <condition>.
INSERT
Copies the contents of several lines of an internal table to another internal table.
APPEND
Appends the contents of several lines of an internal table to another standard table.
For detailed information about the ABAP statements described here, refer to the relevant keyword
documentation.
SAP AG
TAW10
10-36
itab_flightinfo
wa_flightinfo
* fill structure with values:
wa_flightinfo-carrid
= ...
wa_flightinfo-connid
= ...
wa_flightinfo-fldate
= ...
wa_flightinfo-seatsmax
= ...
wa_flightinfo-seatsocc
= ...
wa_flightinfo-percentage = ...
.
.
.
.
.
.
You can insert lines into an internal table by first filling a structure with the required values and then
inserting it into the internal table using the INSERT statement.
For standard tables, this means that the line is appended to the table. For sorted tables and hash tables,
the system inserts the line after referring to the key.
SAP AG
TAW10
10-37
itab_flightinfo
wa_flightinfo
LOOP AT itab_flightinfo INTO wa_flightinfo.
WRITE: / wa_flightinfo-carrid,
wa_flightinfo-connid,
wa_flightinfo-fldate,
wa_flightinfo-seatsmax,
wa_flightinfo-seatsocc,
wa_flightinfo-percentage,
'%'.
ENDLOOP.
SAP AG 2001
You can read and process the contents of an internal table using a LOOP by accessing the structure
component within the loop.
In this example, the WRITE statement is used to create a list from the field contents.
If you want to change the contents of the internal table, first change the value of the components within
the loop and then overwrite the line of the internal table using the MODIFY statement.
SAP AG
TAW10
10-38
Sort
SORT
SORT
REFRESH
REFRESH
itab <conditions>.
itab.
SAP AG 2001
SAP AG
TAW10
10-39
itab_flightinfo
wa_flightinfo
SORT itab_flightinfo BY
DESCENDING.
BY percentage DESCENDING
Ascending
or
descending?
Name of column(s)
by which to sort
SAP AG 2001
You can sort standard tables by any column, simply by entering the column name after the BY addition
to the SORT statement.
SORT itab [ ASCENDING | DESCENDING ]
[ BY f1 [ ASCENDING | DESCENDING ]
...
fn [ ASCENDING | DESCENDING ] ]
[ AS TEXT ]
[ STABLE ].
Sorting the internal table by the table key or specified field order: Without an addition the system sorts in
ascending order.
If you use the AS TEXT addition, the system will, while sorting by character-type fields, take the
culture-specific sort rule into account.
Only if you use the STABLE addition will the relative order of data records, which are identical in the
sort key, remain intact during sorting.
In this example, the data records of the internal table are sorted in descending order by the percentage
occupancy of flights.
For more details, refer to the keyword documentation for SORT.
SAP AG
TAW10
10-40
SAP
ABAP Debugger
chws
Watchpoint
Table
Table
it_flightinfo
SY-SUBRC
1
2
3
4
5
6
7
8
Type STANDARD
CARRID
CONNID
FLDATE
...
PERCENTAGE
AA
AA
AA
AA
LH
LH
LH
LH
0017
0017
0017
0017
0400
0400
0400
0400
20000512
20000724
20000828
20001224
20000626
20000715
20001113
20001212
...
...
...
...
...
...
...
...
66
120
560
470
240
123
273
280
SAP AG 2001
You can trace the line contents of an internal table by entering the name in the left column. To see the
table display, double-click this entry.
SAP AG
TAW10
10-41
SAP AG 2001
SAP AG
TAW10
10-42
SAPBC400TSS_COMPUTE
1-2
Define the input parameters for two integers (name suggestion: pa_int1, pa_int2)
and an arithmetic operator (name suggestion: pa_op). Additionally, define an
elementary data object for the result type: packed number with two decimal places
(name suggestion: result).
1-3
1-4
1-5
If the user has specified an invalid arithmetic operator on the selection screen, write an
appropriate statement on the list screen..
SAP AG
TAW10
10-43
1-6
If the user tries to divide by zero, display an appropriate statement on the list screen.
In a later unit you will learn how you can implement the error
handling with a more elegant user dialog.
SAP AG
TAW10
10-44
Exercises
Unit: Basic ABAP Language Elements
Topic:
Program: SAPBC400WBS_GETTING_STARTED
2-1
2-2
Make sure that all of the data objects are initial. Transfer all of the data objects defined
in the program to the field view. Find out about the structure and type of the individual
components.
2-3
Step through the program, one statement at a time, by choosing Single step (F5). Which
fields of the structure wa_scarr does the SELECT statement fill? What is the value
of system field sy-subrc after the statement?
2-4
Now observe how fields are copied from the structure wa_scarr to the structure
sbc400_carrier. Which field values are copied?
2-5
The statement CALL SCREEN 100 processes screen 100. On the screen, enter
appropriate values for the user name, date, and time, and continue with the program.
Now observe how fields are copied from the structure sbc400_carrier to the
structure wa_scarr.
SAP AG
TAW10
10-45
2-6
2-7
Restart the program in Debugging mode. Set a breakpoint at the MOVECORRESPONDING statement. Before the screen is processed, assign a name to the
structure component sbc400_carrier-uname in the Debugger.
The button used to change the field values at runtime is next to the
input/output field.
2-8
SAP AG
Repeat step 2-1. Now set a breakpoint at the CALL SCREEN statement. Additionally,
set a field content-dependent watchpoint for the condition that a field value of the
structure wa_scarr changes. Choose Continue (F8) to continue the program and
check why the debugging of the program is stopped in each case.
TAW10
10-46
Exercises
Unit: Basic ABAP Language Elements
Topic:
SAPBC400TSS_ITAB_LOOP
3-2
Buffer the data from the database table SPFLI in an internal table. Define an internal
table with a line type that is compatible with the line structure of SPFLI.
In the ABAP Dictionary, search for all internal table kinds that match this condition.
(Use the Where-used list in the ABAP Editor.)
3-3
Define an internal table (name suggestion: it_spfli) based on one of the global
table types you have found.
3-4
Define a work area that corresponds to the internal table (name suggestion:
wa_spfli).
SAP AG
TAW10
10-47
3-5
SAP AG
Program an array fetch access to all the data records in the database table SPFLI:
SELECT * FROM spfli
INTO TABLE it_spfli.
TAW10
10-48
3-6
SAP AG
TAW10
10-49
Model solution:
REPORT sapbc400tss_compute.
PARAMETERS:
pa_int1 TYPE i,
pa_op(1) TYPE c,
pa_int2 TYPE i.
DATA result TYPE p DECIMALS 2.
pa_int2.
pa_int2.
pa_int2.
pa_int2.
result.
ENDIF.
SAP AG
TAW10
10-50
Solutions
Unit: Basic ABAP Language Elements
Topic:
2-3
2-4
SAP AG
TAW10
10-51
Solutions
Unit: Basic ABAP Language Elements
Topic:
Model solution:
REPORT sapbc400tss_itab_loop.
DATA: it_spfli TYPE sbc400_t_spfli.
DATA: wa_spfli TYPE spfli.
SAP AG
TAW10
10-52
Data Retrieval
Contents:
Data Retrieval for Database Tables
Querying the Database
Reading Database Tables
Authorization Checks
Preview
SAP AG 2001
SAP AG
TAW10
11-1
SAP AG 2001
SAP AG
TAW10
11-2
ABAP program
pa_car
Data objects
Database
table
SCARR
wa_scarr
ABAP
Processing
block
SELECT
SELECT ...
FROM scarr
DatabaseDatabasespecific
conversion
Open SQL
Database SQL
Database
interface
ABAP runtime system
SAP AG 2001
Open SQL statements are a subset of Standard SQL that is fully integrated in the ABAP language.
(SQL stands for standard query language.)
Open SQL statements allow you to access the database in a uniform way from your programs,
regardless of the database system installed. The database interface converts Open SQL statements to
database-specific SQL statements.
SAP AG
TAW10
11-3
SAP AG 2001
You can search for database tables via the Application Hierarchy or the Repository Information
System.
If you have the name of a program that accesses the database table you are searching for:
Debugger:
Start this program in debugging mode and set a breakpoint at the SELECT statement.
ABAP Editor:
Search for the SELECT statement in the source text.
If you know a program that contains a screen with input fields connected to the table you are
looking for, choose F1 Technical info. Double-click the technical name of the screen field to go
to the ABAP Dictionary. This is often a structure field. Double-click the data element and then use
the where-used list to search for transparent tables with the field type
SAP AG
TAW10
11-4
Reading
Reading Database
Database Tables
Tables
Authorization
Authorization Checks
Checks
Preview
Preview
SAP AG 2001
SAP AG
TAW10
11-5
Which table(s)?
Whereto?
Whereto?
WHERE <condition>
Which lines?
Single line
Multiple lines
Particular
column
SAP AG 2001
To program database read access, use the Open SQL statement SELECT.
The SELECT statement contains a series of clauses, each of which has a different task:
The SELECT clause describes, among other things, whether the result of the selection will be
several lines or a single data record and which fields of the table are to be read.
The FROM clause names the source (database table or view) from which the data is to be selected.
The INTO clause determines the internal data objects into which the selected data is to be placed.
The WHERE clause specifies the conditions that the selection results must fulfill. It thus determines
the lines to be selected from the table.
For information about other clauses, refer to the keyword documentation for SELECT.
SAP AG
TAW10
11-6
pa_car
Database
table
SCARR
wa_scarr
SELECT SINGLE *
FROM scarr
INTO
INTO wa_scarr
WHERE
WHERE carrid = pa_car.
IF sy-subrc = 0.
...
Database
interface
SAP AG 2001
The SELECT SINGLE* statement allows you to read a single record from the database table. To
ensure that you read a unique entry, all of the key fields must be filled by the WHERE clause. The asterisk
* after SINGLE tells the database interface to read all columns in that line of the database table. If you
want only a specific selection of columns, you can list the required fields instead.
In the INTO clause, enter the destination where the database interface is to copy the data. The target
area should be structured left justified just like the required columns of the database table.
If you use the CORRESPONDING FIELDS OF addition in the INTO clause, you can fill the target area
component by component. The system fills only those components that have identical names to columns
in the database table. Note: If you do not use this addition, the system fills the target area left justified,
irrespective of its structure.
If the system finds a table entry matching your conditions, SY-SUBRC has the value zero (0).
The SINGLE addition tells the database that only one line needs to be read. The database can then
terminate the search as soon as it has found that line. Therefore, SELECT SINGLE produces better
performance for single-record access than a SELECT loop if you supply values for all key fields
SAP AG
TAW10
11-7
Database
table
SFLIGHT
pa_car
wa_sbc400focc
SELECT
SELECT carrid connid fldate
seatsocc seatsmax
FROM sflight
INTO wa_sbc400focc
WHERE carrid = pa_car.
Statements for every record read
ENDSELECT
ENDSELECT.
IF sy-subrc = 0.
...
Database
interface
SAP AG 2001
If you do not use the addition SINGLE with the SELECT statement, the system reads multiple records
from the database. The field list determines the columns whose data is to be read from the database.
The number of requested lines to be read can be restricted using the WHERE clause.
In the WHERE clause you may enter only the field names of the database table. The name of the database
table you want to access is found in the FROM clause.
Multiple logical conditions can be added to the WHERE clause using AND, NOT or OR statements.
The database delivers data to the database interface in packages. The ABAP runtime system copies the
data records to the target area line by line using a loop. It also enables sequential processing of all the
statements between SELECT and ENDSELECT.
After the ENDSELECT statement, you can check the return code for the SELECT loop. sy-subrc will
have the value zero (0) if the database interface has found at least one record.
After the ENDSELECT statement, sy-dbcnt contains the total number of lines read.
SAP AG
TAW10
11-8
Database
table
SFLIGHT
pa_car
itab_focc
IF sy-subrc = 0.
...
Database
interface
SAP AG 2001
The addition INTO TABLE itab causes the ABAP runtime system to copy the contents of the
database interface directly to the internal table itab. This is called an array fetch.
Since the array fetch is not executed as a loop, do not program any ENDSELECT statement.
If you want to add lines to the end of an internal table that is already filled, instead of overwriting it, use
the APPENDING TABLE itab addition.
sy-subrc has the value 0 if the system was able to read at least one record.
SAP AG
TAW10
11-9
SAP AG 2001
The program must contain a data object with a suitable type for each column that is required from a
database table. For program maintenance reasons, you must use the corresponding Dictionary objects to
assign types to the data objects. The INTO clause specifies the data object into which you want to place
the data from the database table. You can use the INTO clause in two different ways:
Using a flat structure You define a structure in your program that has the same fields in the
same sequence as the field list in the SELECT clause. You can enter the name of the structure in the
INTO clause. The contents are copied left justified. The field names of the structure are disregarded
here.
Using individual data objects You can enter a set of data objects in the INTO clause. For
example:
DATA:
gd_carrid TYPE sflight-carrid,
gd_connid TYPE sflight-connid,
gd_fldate TYPE sflight-fldate,
gd_seatsmax TYPE sflight-seatsmax,
gd_seatsocc TYPE sflight-seatsocc.
START-OF-SELECTION.
SELECT carrid connid fldate seatsmax seatsocc
FROM sflight
INTO (gd_carrid, gd_connid, gd_fldate, gd_seatsmax, gd_seatsocc)
WHERE ...
SAP AG
TAW10
11-10
...
deptime
...
DEPTIME
SAP AG 2001
If you use the INTO CORRESPONDING FIELDS clause, the data is placed in the fields with the same
name in the target structure.
Advantages of this construction:
The target structure does not have to be structured left justified in the identical way as the field list.
This construction is easy to maintain, because extending the field list does not require other changes
to the program, as long as there is a field in the target structure that has the same name and type.
To place data in internal table columns of the same name using an array fetch, use the INTO
CORRESPONDING FIELDS OF TABLE itab statement.
SAP AG
TAW10
11-11
CARRID
AA
AA
...
...
AA
AA
...
...
AA
AA
CONNID
CITYFROM
0017
0064
...
...
0017
0064
...
...
0017
0064
NEW YORK
FRANKFURT
...
...
NEW YORK
FRANKFURT
...
...
NEW YORK
FRANKFURT
SAP AG 2001
With client-specific database tables, the first keyword must always be MANDT or client (data type
CLNT).
If you select data from client-specific tables, the system always reads the data records of the logon
client, unless otherwise specified. (The ABAP runtime system automatically converts the SELECT
statement.)
If you wish to explicitly include the client field in the WHERE clause, you must set the CLIENT
SPECIFIED addition after the FROM clause.
Since this special case is not relevant for this course, the client field is generally omitted from the
graphics.
SAP AG
TAW10
11-12
Secondary index
CITYFROM
BERLIN
BERLIN
...
FRANKFURT
FRANKFURT
FRANKFURT
FRANKFURT
...
NEW YORK
NEW YORK
...
CONNID
0017
0064
...
...
0400
0402
...
...
0941
3504
...
CITYFROM
CITYTO
NEW YORK
FRANKFURT
...
...
FRANKFURT
FRANKFURT
...
...
FRANKFURT
SAN FRANCISCO
...
SAN FRANCISCO
NEW YORK
...
...
NEW YORK
NEW YORK
...
...
SAN FRANCISCO
FRANKFURT
SAP AG 2001
When you go to the definition of a database table in the ABAP Dictionary, you will see information on
all the technical attributes of the database table.
The following information is useful for improving the performance of database accesses:
Key fields If the lines requested from the database are retrieved according to key fields, the
Database Optimizer can perform access using a primary index.
Secondary index If the lines requested from the database are retrieved according to fields, the
Database Optimizer can perform access using a secondary index. Secondary indexes are displayed
in a dialog box whenever you select Indexes. You choose an index from the dialog box by doubleclicking it. The system then displays a screen with additional information about that index.
SAP AG
TAW10
11-13
Authorization Checks
Reading
Reading Database
Database Tables
Tables
Authorization
Authorization Checks
Checks
Preview
Preview
SAP AG 2001
SAP AG
TAW10
11-14
User master
records
Selection
screen
BC400-00
AUTHORITY
CHECK
Profile 1
Profile 2
Note
No
Profile S_CARRID
Authorization for
authorization
object S_CARRID
Authorization for
authorization
object S_CARRID
SY-SUBRC
= 0
?
Yes
SELECT
Profile 4
Authorization for
authorization
object S_TCODE
SAP AG 2001
You should program an authorization check before accessing the database. The AUTHORITY-CHECK
statement first checks whether the user has the authorization containing all the required values. After the
authorization check is completed, check the return code. If it is 0, the user has the required authorization
and the program can be continued. If the value is not 0, the user does not have the required authorization
and you should issue an appropriate message.
Later in this course, you will learn how to make fields on the selection screen ready for input again if
you perform the authorization check right after the selection screen and how to send a message if the
user does not have the required authorization
SAP AG
TAW10
11-15
"Display" authorization
for object S_CARRID
*
03
Object S_CARRID
CARRID (Airline)
ACTVT (Activity)
Activities:
Create
Change
Display
"Change" authorization
for object S_CARRID
LH
=
=
=
01
02
03
02
SAP AG 2001
All data in the SAP system must be protected from unauthorized access by users who do not explicitly
have permission to access it.
The system administrator assigns user authorizations when maintaining user master data. During this
process, you should determine exactly which data users are allowed to access and what kind of access
should be allowed. For example, you might want to allow users to display data for all airlines, but allow
them to change data for only certain ones. In this case, the system must look for a combination of the
activity (ACTVT) and airline carrier (CARRID) fields each time it performs an authorization check.
Both fields must be filled with values during authorization creation as well (in this example, activity
Change and airline carrier LH or activity Display and airline carrier *). You can ensure this by creating
an authorization object composed of the ACTVT and CARRID fields that must be accessed both
during the authorization assignment process and whenever your program performs an authorization
check.
Authorization objects simply define the combination of fields that need to be addressed simultaneously
and serve as templates for both authorizations and authorization checks. They are organized into object
classes to make it easier to find and manage them. One or more object classes may be assigned to each
application.
SAP AG
TAW10
11-16
Authorizations
for object S_CARRID
AUTHORITY_CHECK
OBJECT 'S_CARRID'
Check
ID 'CARRID' FIELD 'LH'
ID 'ACTVT' FIELD '02'.
IF sysy-subrc NE 0.
Report
results
ACTVT
03
02
01
ENDIF.
AA AZ DL LH UA
CARRID
SAP AG 2001
When you check authorizations in programs, you specify the object and values the user needs in a
particular authorization to be able to access the object in question.
In the above example, there is a check to determine whether the user has authorization for the object
S_CARRID, which has the value 'LH' in the CARRID field and the value '02' (change) in the ACTVT
field. The abbreviations for the possible activities are documented in the table TACT and also in the
appropriate authorization objects.
The AUTHORITY-CHECK statement executes the authorization check for the user master record and
also issues the return code. When evaluating the return code, you can specify the consequences of
lacking authorization (for example, program terminates or skips some input lines).
SAP AG
TAW10
11-17
Insert
values
ENDIF.
SAP AG 2001
You must specify all fields of the object in an AUTHORITY-CHECK statement; otherwise you receive a
return code not equal to zero. If you do not want to carry out a check for a particular field, enter
DUMMY after the authorization field.
Example: When a change transaction is called, it is a good idea to check whether the user may change
the entries for a particular airline:
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' DUMMY
ID 'ACTVT' FIELD '02'.
The most important return codes for AUTHORITY-CHECK are:
- 0: The user has authorization containing the required values.
- 4: The user does not have the required authorization.
- 8: The check was not successful because not all fields of the authorization object were specified.
The keyword documentation for AUTHORITY-CHECK contains a complete list of The check was not
successful because not all fields of the authorization object were specifiedreturn codes.
SAP AG
TAW10
11-18
Preview
Reading
Reading Database
Database Tables
Tables
Authorization
Authorization Checks
Checks
Preview
Preview
SAP AG 2001
SAP AG
TAW10
11-19
spfli-mandt = scarr-mandt
spfli-carrid = scarr-carrid
SPFLI
MANDT CARRID CONNID
...
SCARR
CITYFROM
...
...
...
...
...
...
...
...
...
...
...
spfli-connid
spfli-cityfrom
scarr-carrname
SAP AG 2001
You can access several database tables using one database query, if the databse tables are logically
related. To do so, you must specify the following information:
Which database tables should be accessed?
What should the link condition look like? In the graphic, columns from both database tables are
linked. If all the field values of the linked columns match, a record is placed in a common line in the
results table.
Which columns are to be read? If a column appears in more than one database table, you must specify
the table from which this column is to be read.
SAP AG
TAW10
11-20
SELECT
SELECT
...
FROM
spfli INNER JOIN scarr
spfli~carrid = scarr~carrid
ON
WHERE ...
SAP AG 2001
SAP AG
TAW10
11-21
Object
Global
class
methods
BAPIs
Business
Object
ce
fa n
r
te
io
In n c t le
u
F odu
m
Function
group
Logical
Database
SAP AG 2001
If reusable components that encapsulate complex data retrieval statements are available, you should use
them. There are four techniques for reusing data retrieval components:.
Calling methods of global classes
Calling methods of business objects
Calling function modules
Including logical databases Logical databases are data retrieval programs that return logicallyconnected data in a hierarchical sequence.
You can find information on these techniques in the appropriate units.
For detailed information on how to include logical databases, refer to the SAP Library under:
Basis Components ABAP Programming and Runtime Environment ABAP Database Accesses
Logical Databases.
SAP AG
TAW10
11-22
INSERT
UPDATE
SELECT
DELETE
MODIFY
SAP AG 2001
In addition to the SELECT statement, Open SQL contains the UPDATE, INSERT, DELETE, and
MODIFY statements.
Do not use these data base accesses, which initiate changes in the database, unless you understand the
SAP transaction concept.
All Open SQL statements support the return code sy-subrc. If a database access was successful, the
return code in the system field sy-subrc is 0; if it was not successful, the return code is not 0.
For more information about Open SQL statements, refer to the respective keyword documentation.
SAP AG
TAW10
11-23
SAP AG 2001
SAP AG
TAW10
11-24
SAPBC400DDS_SELECT_SFLIGHT
1-1
1-2
Change the work area type name (name suggestion: wa_flight). Now use the global
structure SBC400FOCC.
Find out information on the components (fields) of this structure.
1-3
1-4
Now select only the flights from the database table SFLIGHT that belong to the
selected airline.
Select only those fields that have a target field in the work area.
1-5
Within the loop statement, calculate the percentage occupancy for each flight. Assign
the result to the PERCENTAGE field in your work area.
SAP AG
TAW10
11-25
1-6
1-7
SAP AG
TAW10
11-26
Exercises
Unit: Data Retrieval
Topic:
SAPBC400DDS_SELECT_SFLIGHT_TAB
2-2
Define an internal table (name proposal: it_flight) using a global table type as a
basis that has the global structure SBC400FOCC as line type.
Use the Where-used list in the ABAP Dictionary to find a suitable
table type.
2-3
Fill this internal table line by line by using an INSERT statement in the SELECT loop.
(Remove the statements for list output. You can use the source text again later.)
2-4
Sort the internal table by percentage occupancy and display the contents of the internal
table in a loop on a list.
SAP AG
TAW10
11-27
Exercises
Unit: Data Retrieval
Topic:
Authorization Check
3-2
Program an authorization check for the authorization object S_CARRID. Check the
combination of selected airline and activity Display.
Use the respective Pattern statement in the ABAP Editor.
Search for the correct abbreviation of the activity to be checked.
SAP AG
TAW10
11-28
3-3
Define a constant for the abbreviation of the activity Display (name proposal
actvt_display). Use ACTIV_AUTH for typing the data element and use this
constant during the authorization check.
3-4
Execute the database access only if the user has display authorization for the selected
airline. If this is not the case, display an appropriate error message on the list.
3-5
Execute your programs; select the airline abbreviations ."AA" and "UA".
SAP AG
TAW10
11-29
1-2
1-7
The MANDT field in SFLIGHT is marked as a key field. The WHERE condition does
not need this field. Despite this fact, the database interface can use the primary index in
this case for selecting the data records.
Reason:
When the ABAP runtime system accesses a client-specific table, it assumes that data
should be taken into account only if it belongs to the client under which the user is
logged on. Thus, by default, the database interface enhances the WHERE condition with
a WHERE mandt = sy-mandt condition.
SAP AG
TAW10
11-30
REPORT
Model solution:
sapbc400dds_select_sflight
SAP AG
TAW10
11-31
Solutions
Unit: Data Retrieval
Topic:
Model solution:
REPORT sapbc400dds_select_sflight_tab.
DATA: wa_flight TYPE sbc400focc,
it_flight TYPE sbc400_t_sbc400focc.
PARAMETERS: pa_car TYPE s_carr_id.
* select all datasets from database table SFLIGHT
* corresponding to carrier
SELECT carrid connid fldate seatsmax seatsocc
FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car.
* calculate occupation of each flight
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
* append single line into internal table
INSERT wa_flight INTO TABLE it_flight.
* alternatively, you could use the APPEND statement,
* if you are using standard tables:
*
*
APPEND wa_flight TO it_flight.
ENDSELECT.
* sort internal table
SORT it_flight BY percentage.
* create list from sorted internal table
LOOP AT it_flight INTO wa_flight.
WRITE: / wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-seatsocc,
wa_flight-seatsmax,
wa_flight-percentage,'%'.
ENDLOOP.
SAP AG
TAW10
11-32
Solutions
Unit: Data Retrieval
Topic:
Authorization Checks
Model solution:
REPORT sapbc400dds_authority_check.
CONSTANTS actvt_display TYPE activ_auth VALUE '03'.
DATA wa_flight TYPE sbc400focc.
PARAMETERS pa_car TYPE s_carr_id.
* authority-check:
* Is user authorized to display data for carrier PA_CAR?
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD pa_car
ID 'ACTVT' FIELD actvt_display.
CASE sy-subrc.
* user is authorized
WHEN 0.
SELECT carrid connid fldate seatsmax seatsocc
FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car.
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
WRITE: / wa_flight-carrid COLOR COL_KEY,
wa_flight-connid COLOR COL_KEY,
wa_flight-fldate COLOR COL_KEY,
wa_flight-seatsocc,
wa_flight-seatsmax,
wa_flight-percentage,'%'.
ENDSELECT.
* user is not authorized or
* other error of authority-check
WHEN OTHERS.
WRITE: / 'Authority-Check Error'(001).
ENDCASE.
(REPORT sapbc400dds_authority_check_2 analog).
SAP AG
TAW10
11-33
Contents:
Defining Subroutines
Interface Parameters
Visibility
Calling Subroutines
Subroutines in Debugging Mode
SAP AG 2001
SAP AG
TAW10
12-1
SAP AG 2001
SAP AG
TAW10
12-2
PERFORM ...
Total seats
200
PERFORM ...
Inquiries
1000
FORM ...
Occupied seats
60
Bookings
555
Percentage
occupied
30.00
Sales ratio
55.50
Interface
Formal parameters
Subroutine
SAP AG 2001
A subroutine is an internal module within a program. In a subroutine, you lift parts of a program out
of the main programming block and put them somewhere else. This makes your program easier to read
and allows you to use these code segments more than once.
You can pass data to the subroutine and back through its interface. This allows you to call the same
function for different data objects. The example in the graphic shows a subroutine that calculates a
percentage. This subroutine is called several times, even though different data objects are passed to the
interface in each case.
Using subroutines makes your program more function oriented: it splits the program's task into
subfunctions so that each subroutine is responsible for one subfunction.
This generally makes programs easier to maintain. In the Debugger, you can execute the subroutines in
background so that you see only the result. This usually makes it easier to find the source of the error.
The statements that the subroutine executes come between FORM and ENDFORM.
SAP AG
TAW10
12-3
Call-by-value
Call-by-reference
Call-by-value-and-result
SAP AG 2001
You specify how the data is passed from the main program (actual parameters) to the subroutine
(formal parameters) in the interface of the subroutine. You can do this in three ways:
Call-by-value A local copy of the actual parameter is passed to the subroutine. This means that
value assignments to the formal parameter have absolutely no effect on the actual parameter.
Call-by-reference A dereferenced address of the actual parameter is passed to the subroutine.
This means that value assignments to the formal parameter directly affect the actual parameter.
The value of the actual parameter is physically changed by the subroutine through the address.
Call-by-value-and-result A local copy of the actual parameter is passed to the subroutine and a
value is passed back to the main program only if the ENDFORM statement is executed. This
means that value assignments to the formal parameter affect the actual parameter only after they
have left the subroutine. Choose this option if you want to make sure that the actual parameter is
not changed if the subroutine is terminated prematurely.
SAP AG
TAW10
12-4
a2
a3
f1
f2
f3
SAP AG 2001
In the interface definition, you list the formal parameters of the different sorts and assign a type to
each one. The sequence of parameters is fixed: first you name all the USING parameters, then you
name all the CHANGING parameters. Within the subroutine, you address the data that has been passed
using the formal parameters.
The actual parameters are grouped by USING and CHANGING when the subroutine is called.
You specify the way in which the parameters are to be passed in the interface definition:
Call-by-value (f1) You list these parameters after the USING keyword and complete them with
the value(f1) addition.
Call-by-reference (f2) You list these parameters after the CHANGING keyword. (For
documentation purposes, you can also list a pass-by-reference parameter after USING. Technically,
USING and CHANGING have exactly the same effect. (However, if you change a parameter listed
after USING in the subroutine, you receive a warning in the Extended Program Check.)
Call-by-value-and-result (f3) You list these parameters after the CHANGING keyword and
complete them with the value(f3) addition
SAP AG
TAW10
12-5
Specified type
FORM calc_perc
USING
value(f_part) TYPE i
value(f_all) TYPE
TYPE ii
CHANGING
value(f_pc)
TYPE
TYPE t_perc.
t_perc
t_perc
Inherited type
FORM calc_perc
USING
value(f_part) TYPE ANY
value(f_all) TYPE ANY
CHANGING
value(f_pc)
TYPE ANY.
a1
a2
CHANGING a3.
a1
a2
CHANGING a3.
ENDFORM.
ENDFORM.
SAP AG 2001
The data objects passed to a subroutine (that is, the actual parameters) can be of any type. If you use
elementary types, you can decide whether or not you want to specify the type of the formal
parameters.
By specifying the type of the formal parameters, you ensure that only actual parameters of that type
can be passed to the subroutine. This makes your program more stable because the syntax check will
find any type conflicts.
If you use the TYPE ANY addition, you leave the type unspecified. (For compatibility reasons, you
can also omit this addition.) In this case, the formal parameter inherits the type from the actual
parameter at run time. If the statements in the subroutine are not suited to the inherited type, a runtime
error may occur.
If you assign the types p, n, c or x, the missing type attributes are similarly "inherited" at run time. If
you want to specify a type completely, you must use a user-defined type. If you use string or
xstring, the type is not fully specified until run time.
SAP AG
TAW10
12-6
DATA it_flightinfo
TYPE sbc400_t_sbc400focc.
...
...
PERFORM fill_wa
CHANGING wa_flightinfo.
PERFORM fill_itab
CHANGING it_flightinfo.
Table type
FORM fill_itab
CHANGING
sbc400_t_sbc400focc
f_itab TYPE sbc400_t_sbc400focc.
f_wa-carrid = ... .
f_wa-connid = ... .
Address the structure
components
ENDFORM.
SAP AG 2001
If you use structures or internal tables as formal parameters, you must type them fully. This allows
you to access these formal parameters within the subroutine.
The components of structures are known in the subroutine, as a result of the assigned type, so that you
can address these components with the usual syntax.
If you use internal tables, the assigned type allows you to address the formal parameter as an internal
table with the usual syntax.
Note on performance:
If you use internal tables as parameters, you should generally pass them using pass-by-reference.
Otherwise, the system can use considerable resources simply copying them to the subroutine.
SAP AG
TAW10
12-7
Visible globally
...
PERFORM fill_itab CHANGING it_flightinfo.
FORM fill_itab
CHANGING
f_itab TYPE sbc400_t_sbc400focc.
Visible locally
DATA
DATA l_wa LIKE LINE OF f_itab.
Both the formal parameters and the local data objects are active only at the run time of the subroutine.
This means that memory is allocated only when the subroutine is called and is released as soon as the
subroutine has been executed. Thus these parameters and data objects can be addressed only from
within the subroutine.
The global data objects from the main program can also be addressed from the subroutine. However,
you should avoid doing this wherever possible. Otherwise, you bypass the interface, which makes the
program more prone to errors.
If a local data object or formal parameter has the same name as a global data object, the ABAP
runtime system addresses the local data object in the subroutine and the global one outside it. These
objects are then known as locally obscured objects.
SAP AG
TAW10
12-8
it_flightinfo
'LH'
CHANGING lines.
f_itab
TYPE sbc400_t_sbc400focc
f_carr
TYPE sbc400focc-carrid
CHANGING value(f_lines) TYPE i.
The example in the graphic shows a main program calling a subroutine, which specifies the number of
lines of an internal table needed to fulfill a specific criterion.
The internal table, f_itab, and the comparison value, f_carr, are passed by reference to improve
performance. The number of lines, f_lines, is passed by value-and-result.
To loop through the internal table, you need a work area with a compatible line type, which you define
locally in the subroutine, by making a reference to the formal parameter.
SAP AG
TAW10
12-9
Calling Subroutines
System
Help
Subroutines
COUNT_LINES
1:
"drag-and-drop"
PERFORM count_lines
USING
f_itab
+ f_carr
CHANGING
f_lines.
2:
Adapt the actual
parameters
FORM count_lines
USING
f_itab
TYPE ...
f_carr
TYPE ...
CHANGING value(f_lines) TYPE ... .
...
ENDFORM.
SAP AG 2001
For this reason, you should define the subroutine first and then call it. The Object Navigator supports
you in this respect: You can generate the PERFORM statement by dragging the subroutine from the
navigation area to the editor area.
Alternatively, you can generate the call using the Pattern function in the ABAP Editor.
This prevents you from mixing up or forgetting any parameters. However, you must remember to
replace the formal parameters with actual parameters.
SAP AG
TAW10
12-10
SAP
ABAP Debugger
chws
Watchpoint
ZJJ_KURS_000
ZJJ_FORMS
Return
Execute
f_itab
TYPE ...
f_carr
TYPE ...
CHANGING value(f_lines) TYPE ... .
6
LH
1 - 4
Variant
f_carr
SY-SUBRC
SY-TABIX
Variant
SY-DBCNT
SAP AG 2001
In debugging mode, you can make a subroutine run without stopping. The execution of the main
program does not stop until after the subroutine has been executed.
Alternatively, you can execute the subroutine statement by statement using Single Step.
If the current statement is located in a subroutine, you can run the rest of the subroutine without it
stopping by selecting Return (F7). Execution of the main program does not stop until after the
subroutine is executed.
SAP AG
TAW10
12-11
SAP AG 2001
SAP AG
TAW10
12-12
Modularization Exercises
Unit: Internal Program Modularization
Topic: Subroutines
Template:
ZBC400_##_AUTHORITY_CHECK_2 or
SAPBC400DDS_AUTHORITY_CHECK_2
Program:
ZBC400_##_SUBROUTINE
1-1
1-2
Encapsulate the display of data in a list in a subroutine. Call the subroutine (suggested
name: WRITE_LIST) after the SELECT loop. Pass the internal table containing the
data that has been read using the interface.
1-3
Define the subroutine and specify types for the interface parameters.
1-4
Display the data from the subroutine using a LOOP ENDLOOP structure. To do this,
create the required table work area as a local data object in the subroutine. To specify
the type of the local structure, use the ABAP statement DATA <wa> LIKE LINE
OF <itab>.
SAP AG
TAW10
12-13
Modularization Solutions
Unit: Internal Program Modularization
Topic: Subroutines
*&--------------------------------------------------------------*
*& Report
SAPBC400PBS_SUBROUTINE
*&
*
*
*&--------------------------------------------------------------*
REPORT
sapbc400pbs_subroutine.
START-OF-SELECTION.
* Authority-Check:
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD pa_car
ID 'ACTVT'
FIELD actvt_display.
CASE sy-subrc.
* User is authorized
WHEN 0.
SELECT carrid connid fldate seatsmax seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car.
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
APPEND wa_flight TO it_flight.
SAP AG
TAW10
12-14
ENDSELECT.
PERFORM write_list USING it_flight.
Form
WRITE_LIST
*&--------------------------------------------------------------*
*
text
*---------------------------------------------------------------*
*
-->P_IT_FLIGHT
text
*---------------------------------------------------------------*
FORM write_list USING p_it_flight TYPE sbc400_t_sbc400focc.
DATA: wa LIKE LINE OF p_it_flight.
LOOP AT p_it_flight INTO wa.
WRITE: / wa-carrid COLOR COL_KEY,
wa-connid COLOR COL_KEY,
wa-fldate COLOR COL_KEY,
wa-seatsocc,
wa-seatsmax,
wa-percentage,'%'.
ENDLOOP.
ENDFORM.
SAP AG
" WRITE_LIST
TAW10
12-15
Contents:
Execution of Event Blocks by the ABAP Runtime
System
Event Block LOAD-OF-PROGRAM (INITIALIZATION)
Event Block START-OF-SELECTION
SAP AG 2001
SAP AG
TAW10
13-1
SAP AG 2001
SAP AG
TAW10
13-2
Event
block
Event
block
Selection screen
Event
block
Module
Interface
Event
block
Module
Subroutine
program
Process
Before
Output
Process
After
Input
Screen
SAP AG 2001
An ABAP program is a collection of processing blocks. A processing block consists of passive source
code sections that are processed sequentially when called.
Processing blocks are the smallest units in ABAP. They cannot be split, which also means that they
cannot be nested.
There are various kinds of ABAP processing blocks:
Event blocks are processing blocks that are called by the ABAP runtime system whenever the
respective event is initiated. Such events can be initiated by the ABAP runtime system itself or by the
user.
Subroutines are processing blocks that are called by ABAP statements. The developer controls
subroutines.
Modules are special ABAP processing blocks that are called by screen statements. These are required
for screen processing.
Whenever a program is started, all the global data objects of the program are created in the working
memory first. Declarative ABAP statements are not components of ABAP processing blocks; instead,
they are collected by the ABAP runtime system when the overall source code is generated. For the sake
of clarity, however, you should place all declarative statements together at the beginning of the source
code. Exceptions to this are local declarations within subroutines.
SAP AG
TAW10
13-3
Selection screen
(generated by the
runtime system)
LOAD-OF-PROGRAM.
Event block
Default settings for
selection screen
pa_date = sy-datum - 7.
START-OF-SELECTION.
Event block
WRITE pa_date.
SAP AG 2001
In all of the programs we have seen so far in this course, only one processing block has been
programmed in addition to declarative statements. In this case, there is no need to declare the processing
block explicitly. In more complex programs, however, several different processing blocks are required.
The example in the graphic contains a selection screen with an input field for a date. The date of the
same weekday in the previous week should appear as a default value.
The PARAMETERS statement is a declarative language element. The system requires a calculation to
preset the date dynamically. The DEFAULT addition to the PARAMETERS statement ensures that the
data object is filled with a default value. The ABAP runtime system fills the sy-datum field with the
current date at the start of the program.
To change variables at run time, therefore, you must program a processing block. Because this should
be processed before the standard selection screen is transmitted, use the respective event block called
LOAD-OF-PROGRAM.
Use the standard event block, START-OF-SELECTION, to create the list
SAP AG
TAW10
13-4
ABAP program
pa_date
Program
start
LOAD-OF-PROGRAM.
pa_date = sy-datum - 7. 19991225
???
START-OF-SELECTION.
WRITE pa_date.
List
buffer
for
basic list
In the flow diagram in the graphic, you can easily follow the sequence of processing steps by the ABAP
runtime system. Event blocks are called in a fixed sequence designed for list processing:
The first event block to be called is LOAD-OF-PROGRAM. In the example, the date "A week ago" is
calculated and placed into the pa_date input field. Next the system sends the selection screen with
this new value to the presentation server. The user can change the value.
Next the selection screen is sent to the presentation server.
After the user leaves the selection screen, START-OF-SELECTION is called.
If the START-OF-SELECTION event block contains the ABAP statements WRITE, SKIP or
ULINE, a list buffer is filled.
As soon as START-OF-SELECTION is processed completely, the list buffer is sent to the
presentation server as a list.
Both events presented here are initiated by the ABAP runtime system exactly once each time a program
is executed.
SAP AG
TAW10
13-5
Introduced by an
event keyword
ABAP program
LOAD-OF-PROGRAM.
LOADLOAD-OFOF-PROGRAM.
pa_date = sy-datum - 7.
START-OF-SELECTION.
STARTSTART-OFOF-SELECTION.
WRITE pa_date.
SAP AG 2001
An event block is introduced with an event keyword. It ends implicitly when the next processing block
starts.
Event blocks are called by the ABAP runtime system. Therefore, the sequence in which the event blocks
are written in the program is unimportant.
LOAD-OF-PROGRAM is the first event block called in all ABAP program types. This event block allows
you to set default values that can only be determined at runtime.
For compatibility reasons, the event block INITIALIZATION is available as an alternative. However,
it is available for executable programs only.
START-OF-SELECTION is the first event block for creating a list. It is called by the ABAP runtime
system as soon as you leave the standard selection screen. It is available for executable programs only.
In executable programs, additional event blocks are available for different tasks and are designed for
creating lists. You can obtain a complete list of event blocks from the ABAP documentation: choose
ABAP Overview ABAP - Overview Diagrams Classification of Keywords by Type Event
keywords.
SAP AG
TAW10
13-6
SAP AG 2001
SAP AG
TAW10
13-7
Contents:
List attributes and strengths
Basic list
List events
Interactive lists
Example with syntax: Detail list
SAP AG 2001
SAP AG
TAW10
14-1
SAP AG 2001
SAP AG
TAW10
14-2
List Attributes
Screen
CA ID
PRICE
AA 2602 2400
AA 2602 2500
Total
7800
08/21/2001
According to fixed
user settings
Print
Formatted output:
Amounts according
to their currency
Lengths according
to their unit
SAP AG 2001
The main purpose of a list is to display data while involving a minimum amount of programming.
Special business data requirements are taken into account:
Lists are language-independent. Texts and headers appear in the logon language whenever a
translation is available.
Lists can display monetary values in numerous currencies.
SAP AG
TAW10
14-3
Save
:
List
:
SAP AG 2001
The standard list interface offers the user several navigation features:
Back
Exit
Cancel
Print
Find (in list)
Save as a file, in the menu, or to a buffer
Send the list in e-mail form
You can use the Menu Painter to adjust the standard list interface to fit your individual needs.
SAP AG
TAW10
14-4
List header
Save
Column header
SAP AG 2001
Each list can have a list header and up to four lines of column headers. You can use these tools in two
ways:
From the ABAP Editor: Use the text element maintenance functions. A ruler is available.
From the list: If you save your program, activate it, and then execute it to create the list, you can
access the maintenance screen by choosing System List List header. The main advantage of
using this method is that the list is still displayed on the screen. This makes it easier to position
column headers.
The next time you start the program, the new headers will appear in the list automatically.
If no header text is entered, the program title is inserted in the header.
SAP AG
TAW10
14-5
ABAP program
Text elements
Titles/headers
List header
WRITE: /15
35
/15
35
text-001,
texttext-001
sy-datum,
text-002,
texttext-002
sy-uname.
DE creation date
EN creation date
FR ...
Text symbols
001
002
DE Anlegen Datum
EN Creation date
FR ...
:
EN Created by
SAP AG 2001
Titles and headers are part of the program's text elements. You can translate all text elements into other
languages. The logon language setting on the logon screen determines in which language text elements
will be displayed.
Text symbols are another kind of text element. Text symbols are text literals that can be translated and
are assigned to the program. They are frequently used to create lists independent of language.
You can write text symbols into your program in either of the following ways:
TEXT-ccc (ccc is a three-byte character string)
'...'(ccc) (... is any text, ccc is a three-digit character string)
From the Editor, you can access the maintenance screen for the text symbols by choosing Goto Text
elements Text symbols or by double-clicking the number of a text symbol.
SAP AG
TAW10
14-6
Program
start
ABAP program
Database
tables
Data objects
START-OF-SELECTION.
SELECT ...
List
buffer
WRITE ...
Time
In executable programs, lists are automatically displayed after their corresponding event blocks have
been processed. These processing blocks must, however, contain a statement that writes to the list buffer.
These are WRITE, SKIP, and ULINE.
Event blocks are called in a sequence designed for list processing:
Before the selection screen: LOAD-OF-PROGRAM.
After the user leaves the selection screen: START-OF-SELECTION.
All output from the event blocks that create the lists (here only START-OF-SELECTION) and from the
modularization units called there, which is processed before a list is sent, is temporarily stored in the list
buffer.
Once all list creation event blocks (here only START-OF-SELECTION) have been processed, all data
from the list buffer is displayed in the form of a list.
SAP AG
TAW10
14-7
START-OF-SELECTION.
Database
tables
Basic
list
buffer
AT LINE-SELECTION.
Detail
list
buffer
SAP AG 2001
Time
In executable programs, you can use the event block AT LINE-SELECTION to create detail lists.
The ABAP runtime system ensures that:
The basic list is sent after the event blocks responsible for creating the basic list have been processed
(for example, after START-OF-SELECTION). In this case, the system field sy-lsind contains the
value 0.
The event block AT LINE-SELECTION is processed using the function code PICK each time you
double-click an entry or choose an action for the system to perform. If you are not using a userdefined status, this happens automatically every time you choose Detail list (icon looks like a
magnifying glass), the menu function Choose, or the function key F2.
The detail list is sent after the AT LINE-SELECTION event block is processed and the value
contained in sy-lsind is increased by one.
After every user action with the function code BACK, the system displays the list at the previous
detail level (that is, it goes from level n to n-1).
SAP AG
TAW10
14-8
Basic list
sy-lsind
Detail list
sy-lsind
Detail list
sy-lsind
2
Second detail list
SAP AG 2001
SAP AG
TAW10
14-9
...
START-OF-SELECTION.
WRITE: / text-001 COLOR col_heading,
/ 'sy-lsind',
sy-lsind color 2.
Text symbols:
001
Basic list
002
Detail list
AT
-SELECTION.
LINE
AT LINELINE-SELECTION.
WRITE: / text-002 COLOR col_heading.
ULINE.
WRITE: / 'sy-lsind',
sy-lsind color 4.
SAP AG 2001
SAP AG
TAW10
14-10
Timetable
Airl.
LH
LH
...
SQ
Flight
From
0400 FRA Frankfurt
0400 FRA Frankfurt
0002 SIN
JFK
JFK
To
New York
New York
Departing at
10:10:00
13:30:00
Detail: Flights
You have chosen LH
Flight date
19.12.2001
20.12.2001
24.12.2001
0402
Max.
Occ.
380
380
380
240
270
380
SAP AG 2001
You will now write a program using both basic lists and detail lists.
The basic list in your program should contain flight data such as carrier ID and flight numbers, departure
city and airport, destination city and airport, and departure and arrival times. This data can be found in
the database table SPFLI.
The user should be able to access information about any particular flight by double-clicking its carrier ID
and flight number. Flight date and occupancy should be displayed. This data can be found in the
database table SFLIGHT. You must use the SPFLI key fields in this detail list in order to read the
appropriate data in SFLIGHT. The following graphics demonstrate how this is done.
The example program is SAPBC400UDD_DETAIL_LIST and it is part of development class BC400.
SAP AG
TAW10
14-11
WRITE: /
HIDE :
1
2
3
4
55
CAR
AA
LH
LH
ID
From
0017 JFK
0400 FRA
0402 FRA
:
To
Departing at
SFO
JFK
JFK
13:30:00
10:10:00
13:30:00
Hide area
wa_spfli-carrid,
wa_spfli-connid,
wa_spfli-airpfrom,
wa_spfli-airpto,
wa_spfli-deptime.
wa_spfli-carrid,
wa_spfli-connid.
ENDSELECT.
Line
Field name
Value
3
3
4
4
5
5
:
wa_spfli-carrid
wa_spfli-connid
wa_spfli-carrid
wa_spfli-connid
wa_spfli-carrid
wa_spfli-connid
:
AA
0017
LH
0400
LH
0402
:
AT LINE-SELECTION.
SAP AG 2001
When the event AT LINE-SELECTION is processed, a program's data objects contain the same values
as before basic list display. A detail list, however, often needs data selected within the basic list itself.
You can use the HIDE area to store certain data from the line that you have selected and then
automatically insert it where you need it in the corresponding data object for a detail list.
To predetermine which information is classified by its line position when you create a basic list, use the
ABAP keyword HIDE followed by a list of the data objects you require. 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.
The HIDE global_field statement buffers the content of the global data field global_field with reference
to the current display line. You do not have to display the field beforehand using the WRITE statement.
You merely have to program the HIDE statements after the last WRITE statement in the current line.
The data field can also be a flat structure.
SAP AG
TAW10
14-12
Line Selection
Hide area
CAR
ID From
From
CAR ID
To
To
AA 0017 JFK
LH 0400 FRA
LH 0402 FRA
...
SQ 0002 SIN
SFO
JFK
JFK
13:30:00
10:10:00
13:30:00
SFO
09:30:00
Line
Field name
Value
3
3
4
4
5
5
:
14
14
wa_spfli-carrid
wa_spfli-connid
wa_spfli-carrid
wa_spfli-connid
wa_spfli-carrid
wa_spfli-connid
:
wa_spfli-carrid
wa_spfli-connid
AA
0017
LH
0400
LH
0402
:
SQ
0002
Departingatat
Departing
?? LH 0400 ??
??
??
wa_spfli
...
AT LINELINE-SELECTION.
LINE-SELECTION.
WRITE: text-001,
wa_spfli-carrid,
wa_spfli-connid.
Text symbols:
001
SAP AG 2001
When you select a line (by pointing to it followed by PICK or double-click), this triggers the event AT
LINE-SELECTION.
First the values for this line buffered in the HIDE area are inserted back into the corresponding global
data objects.
Then the system processes the relevant event block in the ABAP program.
SAP AG
TAW10
14-13
...
Text symbols:
AT LINE-SELECTION.
LINE
LINE-SELECTION.
IF sy-lsind = 1.
WRITE: text-001,
wa_spfli-carrid,
wa_spfli-connid.
001
You create a detail list by filling the detail list buffer at the AT LINE-SELECTION event block using
either WRITE, SKIP, or ULINE.
In the example program, the key fields of the airline will be displayed. The flights available for this
airline in the database table SFLIGHT are read using a SELECT loop.
Note that the line-specific information on the airline is only available by double-clicking in the data
objects if the relevant data objects have been placed in the HIDE area when the basic list was created.
SAP AG
TAW10
14-14
SAP AG 2001
SAP AG
TAW10
14-15
ZBC400_##_SELECT_SFLIGHT or
SAPBC400DDS_AUTHORITY_CHECK
Program:
ZBC400_##_DETAIL_LIST
1-1
1-2
Make sure that the key fields of the database table SFLIGHT are available to you for
creating the detail list when the user selects a flight from the basic list (double-click or
F2 on the corresponding list line).
1-3
1-4
In the first line of the detail list, display key information from the selected flight. Under
this line, display a horizontal line and a blank line.
1-5
Read all of the bookings from database table SBOOK for the selected flight. Make sure
that you read only those fields from the database table that you want to display in the
list. Display the following fields from the database table SBOOK on the detail list:
SAP AG
TAW10
14-16
BOOKID,
CUSTOMID,
CUSTTYPE
CLASS,
ORDER_DATE,
SMOKER,
CANCELLED.
1-6
Optional: Display the fields LOCCURAM and LOCCURKEY on the detail list: Ensure
that the currency amount LOCCURAM is displayed with the appropriate formatting for
the currency LOCCURKEY. Use the addition CURRENCY <currency_key> in the
WRITE statement.
Example:
WRITE: wa_sflight-price CURRENCY wa_sflight-currency,
wa_sflight-currency.
1-7
SAP AG
TAW10
14-17
*&--------------------------------------------------------------*
*& Report
SAPBC400UDS_DETAIL_LIST
*&
*
*
*&--------------------------------------------------------------*
REPORT
sapbc400uds_detail_list.
TYPE sbook.
START-OF-SELECTION.
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD pa_car
ID 'ACTVT'
FIELD actvt_display.
CASE sy-subrc.
WHEN 0.
SELECT carrid connid fldate seatsmax seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car.
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
WRITE: / wa_flight-carrid,
SAP AG
TAW10
14-18
wa_flight-connid,
wa_flight-fldate,
wa_flight-seatsocc,
wa_flight-seatsmax,
wa_flight-percentage,'%'.
* Hide key field values corresponding to the actual line
HIDE: wa_flight-carrid, wa_flight-connid,
wa_flight-fldate.
ENDSELECT.
WHEN OTHERS.
WRITE: / 'Authority-Check Error'(001).
ENDCASE.
CLEAR wa_flight.
* Program continues here, if a line is selected on basic list
AT LINE-SELECTION.
IF sy-lsind = 1.
* Key fields transported back from hide area to ABAP data objects
WRITE: / wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate.
ULINE.
SKIP.
* Selection of bookings, which depend on selected flight
SELECT bookid customid custtype class order_date
smoker cancelled loccuram loccurkey
FROM sbook INTO CORRESPONDING FIELDS OF wa_sbook
WHERE carrid = wa_flight-carrid
AND
connid = wa_flight-connid
AND
fldate = wa_flight-fldate.
TAW10
14-19
wa_sbook-smoker,
wa_sbook-cancelled.
ENDSELECT.
ENDIF.
CLEAR wa_flight.
SAPBC400UDS_DETAIL_LIST1
*&
*
*
*&--------------------------------------------------------------*
REPORT
sapbc400uds_detail_list1.
TYPE sbook.
START-OF-SELECTION.
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD pa_car
ID 'ACTVT'
FIELD actvt_display.
CASE sy-subrc.
WHEN 0.
SELECT carrid connid fldate seatsmax seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car.
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
WRITE: / wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-seatsocc,
wa_flight-seatsmax,
SAP AG
TAW10
14-20
wa_flight-percentage,'%'.
* Hide key field values corresponding to the actual line
HIDE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate.
ENDSELECT.
WHEN OTHERS.
WRITE: / 'Authority-Check Error'(001).
ENDCASE.
CLEAR wa_flight.
connid = wa_flight-connid
AND
fldate = wa_flight-fldate.
SAP AG
TAW10
14-21
Contents:
Selection screen attributes and strengths
Defining selection screens
Evaluating user input to restrict database selection
Selection screen events
Syntax examples: Additional input checks with error
dialog
SAP AG 2001
SAP AG
TAW10
15-1
SAP AG 2001
SAP AG
TAW10
15-2
ABAP program
Selection criteria
Database
table
ABAP
processing
block
Selection screens allow users to enter selection criteria required by the program for it to continue.
For example, if you create a list containing data from a very large database table, you can use a selection
screen to restrict the amount of data that is selected. At runtime, the user can select intervals for one of
the key fields, and only data that corresponds to this selection is read from the database and displayed in
the list. This considerably reduces the load on the database and network.
SAP AG
TAW10
15-3
Selection
Selection Screen
Screen Attributes
Attributes
Single
Single Fields
Fields (PARAMETERS)
(PARAMETERS)
Value
Value Sets
Sets (SELECT-OPTIONS)
(SELECT-OPTIONS)
Selection
Selection Screen
Screen Events
Events
SAP AG 2001
SAP AG
TAW10
15-4
Type checks
Multilingual Capacity
Value entry
Variants
Input help
Possible
entries
help
SAP AG 2001
Selection screens are input masks for value sets that restrict the amount of data read from the database.
The following possibilities are available to the user:
Entries in single fields
Complex entries: Intervals, operations, patterns
Saving filled selection fields as variants
Input help and search helps are available by choosing the F4 function key or the possible entries
pushbutton
You can translate selection texts into other languages so that they are then displayed in the language in
which the user is logged on.
The system checks the type: If you enter a value with an incorrect type, the system displays an error
message and makes the field ready for new input.
SAP AG
TAW10
15-5
SELECT-OPTIONS ...
Airline
PARAMETERS ...
Departure city
LH
to
SAP AG 2001
Selection screens allow you to define selection options for complex entries as well as simple input fields.
Setting selection options
Entering multiple values or intervals
Defining a value set that is not to be selected and is to be subtracted from the value set to be selected
at the end.
Every selection screen contains an information icon. Choose this icon to display additional information.
SAP AG
TAW10
15-6
Structure
Airline
Global types
Data element
Formatting
rules
Selection screen
Semantic
information
[Search help]
Field label
Input help
Search help
Technical
information:
Technical type
ABAP program
PARAMETERS pa_carr TYPE spfli-carrid.
SAP AG 2001
If an input field is typed with a data element, the following additional semantic information is available:
You can use a field name as a selection text
Input help (F1 help) from the data element is available automatically
Possible entries help (F4 help) is available automatically, provided the data element has been linked
with a search help. A search help is a standalone object defined in the Dictionary, which controls the
dialog with the user and data retrieval for the possible entries help.
If an input field is typed with a structure field that uses a data element, the following semantic
information is available:
Field names and input help (F1 help) are copied from the data element that has been used to type the
Dictionary structure field.
If a structure field is coupled with a search help, then this is the search help that is used for the
possible entries help (F4 help) - that is, it obscures the data element search help. If there is no search
help coupled with the structure field, the system uses the data element search help.
Bear in mind that the global type you choose to provide a type for an input field affects the semantic
information available to the user.
For more information, refer to the online documentation for the ABAP Dictionary.
SAP AG
TAW10
15-7
Selection Texts
Multilingual capacity
ABAP program
Text elements
Source code
...
Titles/headers
Text symbols
Airline
LH
Selection texts
SO_CARR
DE
EN Airline
PA_CITY
DE
EN Departure city
to
Departure city
Dictionary reference
SAP AG 2001
On the selection screen, the field names appear as text next to the input fields. However, you can replace
these with selection texts, which you can then translate into any further languages you require. Selection
texts are displayed in the user's logon language.
If the input field is typed directly or indirectly with a data element, you can copy the field name from
one of the texts stored in the Dictionary.
SAP AG
TAW10
15-8
Variants
Airline
LH
to
Departure city
Createaavariant:
variant:
Create
Fill out the selection screen
Save as a variant
Enter a variant name
Meaning: Enter a descriptive short text
You can also choose other attributes
Use the
variant:
Create
a variant:
Start the program
Choose the
If you want to save the values (or some of the values) on a selection screen that you have filled out, you
can do so by creating a variant. When you start the program again later, you can get these values from
the variant and display them in the selection screen.
You can define and save variants for any program that contains a selection screen. You do this by
starting the program and then creating a variant by choosing Goto Variants Save as variant.
Variants allow you to tailor selection screens to suit your needs. You can:
Preassign values for input fields
Hide input fields
A single variant can refer to more than one selection screen in the same program.
Variants are client-specific.
Every selection screen contains an information icon. Choose this icon to display additional information.
SAP AG
TAW10
15-9
Selection
Selection Screen
Screen Attributes
Attributes
Single
Single Fields
Fields (PARAMETERS)
(PARAMETERS)
Value
Value Sets
Sets (SELECT-OPTIONS)
(SELECT-OPTIONS)
Selection
Selection Screen
Screen Events
Events
SAP AG 2001
SAP AG
TAW10
15-10
ABAP program
pa_car
Declarative statements
PARAMETERS
PARAMETERS pa_car
TYPE s_carr_id.
Reference to
ABAP Dictionary
S_CARR_ID
Selection
screen
SAP AG 2001
The PARAMETERS <name> TYPE <typename> statement and the PARAMETERS <name> LIKE
<data_object> statement both generate an elementary input field on the selection screen, and a data
object with the same type.
If the user enters a value and chooses Execute, that value is placed in the internal data object <name> in
the program. The system permits only entries with the correct type.
SAP AG
TAW10
15-11
ABAP program
Description of
selection screen
pa_car
Selection
screen
ABAP
processing
block
Time
Once the LOAD-OF-PROGRAM event block has been processed, the selection screen is sent to the
presentation server. The runtime system transports the data object values that are defined using
PARAMETERS to the selection screen input fields of the same name.
The user can then change the values in the input fields. If the user then clicks on the Execute function,
the input field values are transported to the program data objects with the same name and can be
evaluated in the ABAP processing blocks.
SAP AG
TAW10
15-12
REPORT ...
DATA wa_spfli TYPE spfli.
PARAMETERS pa_car TYPE s_carr_id.
...
SELECT
SELECT carrid connid cityfrom cityto ...
FROM spfli
INTO CORRESPONDING FIELDS OF wa_spfli
pa_
WHERE carrid
carrid == pa_car
pa_car .
WHERE
WRITE: / wa_spfli-carrid, wa_spfli-connid,
wa_spfli-fldate, ... .
ENDSELECT
ENDSELECT .
SAP AG 2001
If you have used the PARAMETERS statement to program an input field as a key field for a database
table, you can use a WHERE clause at the SELECT statement to limit data selection to this value.
In the example above only those data records are read from database table SPFLI whose key field
CARRID has the same value as is contained in data object pa_car at runtime.
SAP AG
TAW10
15-13
Selection
Selection Screen
Screen Attributes
Attributes
Single
Single Fields
Fields (PARAMETERS)
(PARAMETERS)
Value
Value Sets
Sets (SELECT-OPTIONS)
(SELECT-OPTIONS)
Selection
Selection Screen
Screen Events
Events
SAP AG 2001
SAP AG
TAW10
15-14
Option
sign
low high
ABAP program
Reference to
ABAP Dictionary
so_carr
gd_carrid
Selection
screen
Declarative statements
DATA gd_carrid TYPE s_carr_id.
SELECT-OPTIONS
SELECTSELECT-OPTIONS so_carr
FOR gd
gd_carrid.
S_CARR_ID
SAP AG 2001
You use the SELECT-OPTIONS name FOR data_object statement to define selection options: Two
input fields with the same type as the data object appear on the selection screen, allowing you to enter
interval limits. Additionally, a button appears that allows you to realize complex set limits.
The statement also declares an internal table name within the program, with the following four columns:
sign: This field designates whether the value or interval should be included (I) in or excluded (E)
from the selection.
option for the operator (BT, ...): For a list of possible operators, refer to the keyword
documentation for the SELECT-OPTIONS statement.
low: This field contains the lower limit of an interval or single value.
high: This field contains the upper limit of an interval.
This selection table name always refers to a data object that has already been defined. The data object is
used as a target field during database selection, while the selection table is a set of possible values. For
this reason a special version of the WHERE clause exists for database selection. It determines whether or
not the database contains the corresponding field within the value set.
Note:
Similarly, an inclusion test is also defined for the IF statement.
SAP AG
TAW10
15-15
ABAP program
Description of
selection screen
gd_carrid
so_carr
Selection
screen
ABAP
processing
block
Time
If the user enters several values or intervals for a selection option and chooses Execute, the system places
them in the internal table.
SAP AG
TAW10
15-16
REPORT ...
DATA wa_spfli TYPE spfli.
SELECT-OPTIONS so_carr FOR wa_spfli-carrid.
...
SELECT carrid connid cityfrom cityto ...
FROM spfli
INTO CORRESPONDING FIELDS OF wa_spfli
WHERE carrid IN so_carr
so_carr.
so_carr
WRITE: / wa_spfli-carrid, wa_spfli-connid,
wa_spfli-cityfrom, wa_spfli-cityto, ...
ENDSELECT
ENDSELECT.
SAP AG 2001
The above example shows how you can restrict database selection to a certain range using a selection
table.
Conditions in an internal table declared using SELECT-OPTIONS are interpreted as follows:
If the internal table is empty, the condition field IN selname is always true.
If the internal table only contains inclusive elementary conditions, such as i_1, or i_n, the result is
the composite condition (i_1 OR ... OR i_n ).
If the internal table only contains exclusive elementary conditions such as e1 or em, the result is the
composite condition ( NOT e_1) AND ... AND (NOT e_m)
If the internal table contains inclusive elementary conditions, such as i_1 or i_n, and exclusive
elementary conditions, such as e_1 or e_m, the result is the composite condition ( i_1 OR ...
OR i_n ) AND ( NOT e_1 ) AND ... AND ( NOT e_m ).
SAP AG
TAW10
15-17
Selection
Selection Screen
Screen Attributes
Attributes
Single
Single Fields
Fields (PARAMETERS)
(PARAMETERS)
Value
Value Sets
Sets (SELECT-OPTIONS)
(SELECT-OPTIONS)
Selection
Selection Screen
Screen Events
Events
SAP AG 2001
SAP AG
TAW10
15-18
LOAD-OF-PROGRAM.
AT SELECTION-SCREEN.
No
Yes
SAP AG 2001
START-OF-SELECTION.
Time
In an executable program, the ABAP runtime system generates a standard selection screen as long as
you have written at least one PARAMETERS or SELECT-OPTIONS statement. The event block AT
SELECTION-SCREEN belongs to the selection screen.
The selection screen is sent after the event block LOAD-OF-PROGRAM.
Each time the user presses <Enter>, a pushbutton, a function key, or chooses a menu function, the
system initially carries out a type check. If the entries do not have the correct type, the system displays
an error message, and makes the fields ready for input again. When the entries have the correct type, the
system processes the event block AT SELECTION-SCREEN.
Subsequent program flow depends on the user action:
If the user chooses <F8> or Execute the next event block is called: in this case START-OFSELECTION.
If the user chose any other function, the selection screen is displayed again.
SAP AG
TAW10
15-19
LOAD-OF-PROGRAM.
No authorization...
AT SELECTION-SCREEN.
IF ... Error check
Message text
Error message
START-OF-SELECTION.
SAP AG 2001
Time
Use the event block AT SELECTION-SCREEN if you want to program additional input checks for a
standard selection screen.
The event block AT SELECTION-SCREEN is triggered by each user action. If an error dialog is
triggered by the MESSAGE statement, the system resends the selection screen and automatically resets all
input fields to ready for input.
For more detailed information on the MESSAGE statement, refer to the keyword documentation.
Additional information can be found in the keyword documentation for AT SELECTION-SCREEN.
SAP AG
TAW10
15-20
SAP AG 2001
As an example of an additional input check with error dialog, an input field for the airline ID needs to be
added to the program.
An authorization check is to be carried out on the selection screen.
If the user has authorization to display the specified airline, the program continues.
If the user does not have display authorization, then the selection screen is displayed again and an
error message appears in the status bar.
SAP AG
TAW10
15-21
SAP AG 2001
SAP AG
TAW10
15-22
ZBC400_##_SEL_SCREEN
SAPBC400UDS_DETAIL_LIST
1-1
1-2
Extend your selection screen to allow the user to enter a complex value range for the
flight number CONNID.
When you are typing the airline and flight number, make sure
you refer to the same structure so that the search helps are
context-dependent.
1-3
1-4
SAP AG
Use the complex value set to restrict the amount of data selected from the database
table SFLIGHT.
Change your program so that the user cannot progress from the selection screen if the
authorization check against the authorization object S_CARRID fails. If the
TAW10
15-23
authorization check fails, display a suitable error message from message class BC400,
and allow the user to enter a different value on the selection screen.
*&--------------------------------------------------------------*
*& Report
SAPBC400UDS_SEL_SCREEN
*&
*
*
*&--------------------------------------------------------------*
REPORT
sapbc400uds_sel_screen.
TYPE sbook.
FIELD actvt_display.
IF sy-subrc <> 0.
* Return to selection screen again and display message in status * bar
SAP AG
TAW10
15-24
START-OF-SELECTION.
SELECT carrid connid fldate seatsmax seatsocc FROM sflight
INTO CORRESPONDING FIELDS OF wa_flight
WHERE carrid = pa_car
AND
connid IN so_con.
wa_flight-percentage =
100 * wa_flight-seatsocc / wa_flight-seatsmax.
WRITE: / wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-seatsocc,
wa_flight-seatsmax,
wa_flight-percentage,'%'.
HIDE: wa_flight-carrid, wa_flight-connid, wa_flight-fldate.
ENDSELECT.
AT LINE-SELECTION.
IF sy-lsind = 1.
WRITE: / wa_flight-carrid, wa_flight-connid, wa_flight-fldate.
ULINE.
SKIP.
SELECT bookid customid custtype class order_date
smoker cancelled loccuram loccurkey
FROM sbook INTO CORRESPONDING FIELDS OF wa_sbook
WHERE carrid = wa_flight-carrid
AND
connid = wa_flight-connid
AND
fldate = wa_flight-fldate.
WRITE: / wa_sbook-bookid,
wa_sbook-customid,
wa_sbook-custtype,
wa_sbook-class,
wa_sbook-order_date,
SAP AG
TAW10
15-25
wa_sbook-smoker,
wa_sbook-cancelled,
wa_sbook-loccuram CURRENCY wa_sbook-loccurkey,
wa_sbook-loccurkey.
ENDSELECT.
ENDIF.
SAP AG
TAW10
15-26
Contents:
Screen Attributes and Strengths
Creating Screens
Layout
Field Attributes
Flow Logic
Data Transport
Using Pushbuttons and Evaluating User Actions
SAP AG 2001
SAP AG
TAW10
16-1
SAP AG 2001
SAP AG
TAW10
16-2
Screen Attributes
Editing
options
Input help
Possible entries
help
Flexible
program flow
100
120
200
140
Consistency check
during data entry
300
Type checks
SAP AG 2001
Screens are made up of more than just a screen layout with input and output fields. They also have their
own processing logic.
The fact that the ABAP Dictionary is integrated in the system means that automatic consistency checks
for screen input fields are provided. These checks include type checks, foreign key checks, and fixed
value checks. All of these checks are automatically supplied with information from the ABAP
Dictionary.
Checks like the ones above can be complemented by other program-specific checks. With the techniques
available for screens , you can control the order in which checks are performed and, if errors occur,
make the fields input ready again, where appropriate.
You can also set up screen layout in a very flexible way. Input fields, output fields, radio buttons,
checkboxes, and even pushbuttons can be placed on screens. These features allow users to determine the
direction in which the program will proceed.
The same editing options are available for the screen as for list display and the selection screen: the fixed
point numbers and the date are set according to the user default values, the time in format hh:mm:ss,
amounts according to the setting in a currency field, and lengths and weights according to the content of
a unit-of-measure field.
SAP AG
TAW10
16-3
Transaction code
100
200
120
140
SAP AG 2001
SAP AG
TAW10
16-4
Timetable
Flgt
LH
LH
...
SQ
Conn.
Conn.
0400 FRA
0400 FRA
Dept
Frankfurt
Frankfurt
0002 SIN
JFK
JFK
Dest.
Dest.
New York
New York
Airline
Flight number
Screen
LH
0400
Flight duration
Departure time
Save
8:24
10:10:00
Back
SAP AG 2001
In the following units, you will develop a program, in several steps, that enables the user to change the
master data of the flight timetable.
Double-clicking on an entry in the basic list containing the flight timetable calls a screen, which
displays data from the line you selected, and additional information about the flight connection. You
can change the flight duration and the departure time.
Choosing Back takes the user back to the basic list without changing any data.
Choosing Save changes the data in the database.
There is a function module for database changes that is implemented later on (see the unit about CrossProgram Modularization).
SAP AG
TAW10
16-5
Screen
Painter
Attributes
Screen number
Short text
Screen type
Next screen
...
Layout
Departure City
Element list
Attributes:
CHAR20
Required entry
field
...
Flow control
PROCESS BEFORE OUTPUT.
MODULE clear_ok_code.
PROCESS AFTER INPUT.
MODULE user_command.
SAP AG 2001
Flow control:
Contains the processing logic that is to be processed before the screen is sent to the presentation server
(PBO) and the processing logic that is to be processed after a user action has taken place.
SAP AG
TAW10
16-6
Toolbar
Layout area
Element list
SAP AG 2001
From the Graphical Layout Editor, you can start other functions:
Element attributes:
All the attributes of a screen element are displayed in this dialog box. You can change some of the
attributes in the box. Example: you can specify whether or not an input/output field is to be input
ready.
Get from ABAP Dictionary / Get from program:
This dialog box allows you to generate fields that have either a global type or the same type as a data
object in the program.
Element list:
Shows all the elements displayed on the screen with their attributes. You can also change attributes
here..
SAP AG
TAW10
16-7
Timetable
Flgt
LH
LH
...
SQ
Conn.
Conn.
0400 FRA
0400 FRA
Dept
Frankfurt
Frankfurt
0002 SIN
JFK
JFK
Dest.
Dest.
New York
New York
Screen
Airline
Flight number
Departure airport
Destination airport
Flight duration
Departure time
SAP AG 2001
Your first step is to create a screen, specify its layout, and define its field attributes.
The fields Airline, Flight number, Departure airport, and Destination airport are to appear as output
fields. The fields Flight duration and Departure time are available as input-ready fields.
The user should be able to call the screen by double-clicking a line within the basic list and return to the
basic list by choosing the appropriate function on the screen.
SAP AG
TAW10
16-8
ABAP
Create object
:
AT LINE-SELECTION.
:
CALL SCREEN 100
100. Double-click
:
Screen
Painter
No
Cancel
Screen Attributes
Short text
Screen type
Normal
Subscreen
Modal dialog box
Next screen
SAP AG 2001
When you create a screen, the system will ask you to enter screen attributes. Enter a short description
of the screen, select screen type Normal, and enter the number of the subsequent screen.
If you enter 0 for the subsequent screen, the system first processes your screen completely and then
returns to processing at the point where the screen call is set. (Note that "0" in the entry field for the
subsequent dynpro is not displayed because this is actually the inital value.)
In the example in the graphic, the screen the user creates is called from within the basic list. Therefore,
CALL SCREEN 100 must belong to the AT LINE-SELECTION event block.
SAP AG
TAW10
16-9
SDYN_CONN
Airline
Flight number
Departure airport
Destination airport
Flight duration
Departure time
SAP AG 2001
There are two ways of assigning field attributes to the required screen fields:
Copying data from the Dictionary: You can copy types and field attributes from existing ABAP
Dictionary structures. This makes all information about the object available to you, including
semantic information about its data elements and foreign key dependencies. The name of the
Dictionary field is automatically adopted as a field name.
Copying data from the program: You can copy field attributes from data objects already defined
within your program to the screen. In order to do this, however, an activated copy of the program
must already exist. The name of the data object is automatically taken as the field name.
The Graphical Screen Painter allows you to define different screen elements (for example, input and
output fields, keyword texts, borders, and so on) with relative ease. Choose the desired screen element
and then place it on the screen using the mouse.
You can delete screen elements simply by pointing to them and choosing Delete.
You can move screen elements by selecting them and dragging them to a new position.
SAP AG
TAW10
16-10
Attributes
T
Name
Text
Line
Airline
Flight number
X
Departure airport
Destination airport
SDYN_CONN-CARRID
Colu
mn
FCode
FTyp
e
Dict Prog Disp
Flight duration
Departure time
Input field
Output field
Required field
...
SAP AG 2001
To maintain the attributes of a screen field, select the field and choose Attributes.
You can assign the attribute mandatory (Required field) to a screen field. At run time, the field will be
marked accordingly if it is set to initial value.
If not all required fields have been filled at run time and a user action is performed, an error dialog is
triggered by the ABAP run time system and all input fields are once again displayed ready for input.
SAP AG
TAW10
16-11
Timetable
Flgt
LH
LH
...
SQ
Conn.
Conn.
0400 FRA
0400 FRA
Dept
Frankfurt
Frankfurt
0002 SIN
JFK
JFK
Dest.
Dest.
New York
New York
Airline
Flight number
Screen
LH
0400
8:24
10:10:00
SAP AG 2001
In step two you learn how to display data on a screen by programming data transport from the basic list
to the screen.
With this in mind, this part of the unit will deal with:
Setting up prerequisites for automatic data transport between the program and screen fields
Defining the screen interface and programming data transport to the data objects of the interface
SAP AG
TAW10
16-12
Screen Interface
ABAP program
Data objects
wa_spfli
sdyn_conn
Declarative statements
DATA wa_spfli TYPE spfli.
TABLES sdyn_conn.
TABLES
SDYN_CONN
Process
Before
Output
ABAP
processing
block
Process
After
Input
Screen
SAP AG 2001
The TABLES statement defines an internal data object that serves as an interface for the screen. The
TABLES statement always refers to an ABAP Dictionary object (for example, transparent table or
structure).
If the screen fields and the TABLES statement refer to the same ABAP Dictionary object, this data
object's data is automatically transported to the screen fields every time the screen is transmitted. Any
new entries or changes that the user makes on the screen are then transferred back into this data object.
As a rule, structures that contain fields of the same type for the different tables are created in the ABAP
Dictionary. The flight data programs being created in this course use one structure for master data
maintenance (sdyn_conn) and another for bookings data (sdyn_book). Using your own structures as
interfaces usually helps make a program easier to understand and helps to avoid errors as well.
SAP AG
TAW10
16-13
ABAP program
wa_spfli
sdyn_conn
Process
Before
Output
Process
After
Input
Screen 100
ABAP runtime system
SAP AG 2001
Time
Data transport between program data objects and screen fields with the same name takes place
automatically:
Immediately before the screen is sent to the presentation server, that is, after the PBO event has been
fully processed, the contents from fields with the same names are copied from the ABAP work area into
the screen fields.
ABAP statements facilitate data transport between ABAP program data objects and the work area
designated as the screen interface.
SAP AG
TAW10
16-14
wa_spfli
sdyn_conn
Process
Before
Output
Process
After
Input
Screen 100
SAP AG 2001
Time
Data transport between screen fields and program data objects with the same name takes place
automatically:
Immediately after a user performs an action on the screen, that is, before the PAI event is fully
processed, the contents of the fields with the same name are copied from the screen fields into the ABAP
work area.
ABAP statements facilitate data transport between jects the work area designated as the screen interface
and program data objects..
SAP AG
TAW10
16-15
Automatic
data transport
HIDE area
in data objects
AT LINE-SELECTION.
Fill the
TABLES structure
with current data
for selected line
TABLES structure
in screen fields
Screen fields in
TABLES structure
ABAP runtime system
SAP AG 2001
Time
The sample program should display screen data that matches the line selected in the basic list.
If data objects and their values were stored in the HIDE area when the basic list was created, the data
belonging to the selected line will be placed in the corresponding data objects.
You must copy the data to be displayed on the screen to a TABLES structure. You can do this in any
ABAP processing block that is processed before the screen is sent to the presentation server. There are
various ways of doing this:
You start by reading all the data to be displayed on the screen before retrieving the basic list from the
database. You then place all the necessary data in the HIDE area. Then, at the AT LINESELECTION event, you have to copy the data into the TABLES structure only.
Disadvantage: You have to read data from the database that the user may not even look at. If detailed
data has changed between creating the basic list and displaying the screen, the system will display the
wrong data.
Before the screen is called using the SELECT SINGLE statement, you read the additional data for the
selected key (HIDE area) from the database.
Advantage: You reduce the volume of data you need to read from the database when you create the
basic list. The detailed list is up-to-date.
Disadvantage: The system sends a query to the database every time the user double-clicks the list.
SAP AG
TAW10
16-16
wa_spfli
Basic
HIDE Area
List
MANDT
CARRID
CONNID
COUNTRYFR
CITYFROM
AIRPFROM
COUNTRYTO
CITYTO
AIRPTO
FLTIME
DEPTIME
ARRTIME
DISTANCE
DISTID
FLTYPE
!
!
!
!
sdyn_conn
Screen:
Output Field
Input Field
!
!
!
!
!
!
!
On the last development level, the program should allow the user to change data in the database. The
user should be able to change the fields FLTIME and DEPTIME. To enable the user to change data for
several airlines, a basic list of the airlines for which the user is allowed to change data should be
displayed. The user reaches the change screen by double-clicking in the basic list. Once the changes are
made successfully, the user returns to the basic list. However, a new basic list is not created. Therefore,
the data that can be changed should not appear on the basic list.
To ensure that the database data displayed on the screen is up-to-date, the record is read again from the
database at the beginning of AT LINE-SELECTION.
SAP AG
TAW10
16-17
wa_
wa_spfli-carrid
wa_spflispfli-carrid
wa_
_
spfliwa_spfli-connid.
wa spfli-connid.
connid.
sdyn_
_
conn.
.
sdyn conn
SAP AG 2001
To display data on the screen, the TABLES structure must be filled with current data before the screen is
sent to the presentation server. The example in the graphic shows one way of doing this.
The HIDE statement is used to place key fields of database tables with reference to the list line in the
HIDE area. Then the current data for the line selected is available in fields wa_spfli-carrid and
wa_spfli-connid at event AT LINE-SELECTION.
The data record is read from the database using SELECT SINGLE. This ensures that the data is up-todate.
The corresponding fields of the wa_spfli work area are copied to the TABLES structure sdyn_conn
using MOVE-CORRESPONDING. The system transports the structure data to the screen fields
automatically.
Alternatively, you can place the data into the TABLES structure directly when the database is accessed,
using the INTO CORRESPONDING FIELDS addition.
SAP AG
TAW10
16-18
Timetable
Flgt
LH
LH
...
SQ
Dept
Frankfurt
Frankfurt
0002 SIN
JFK
JFK
Dest.
Dest.
New York
New York
Message 1
in status line
Conn.
Conn.
0400 FRA
0400 FRA
Airline
Flight number
Screen
LH
0400
8:24
10:10:00
Back
SAP AG 2001
In step three you learn how to assign pushbutton functions. These functions allow different kinds of
program logic to be processed according to user choice.
For the user, the program works in the following manner:
By double-clicking on a line, the user branches to a screen where the most important items of
information for the connection the user chose are displayed. The flight duration and departure time can
be changed.
By choosing the Back pushbutton, the user returns to the basic list without writing any changes to the
database. The message "Screen was left without any changes being made" is displayed in the status
bar of the basic list.
Choose Save to write all of your changes to the database. The changes take effect in the program only
at a later time. The pushbutton is already prepared in the following section. The user returns to the
basic list after choosing the pushbutton and a message is displayed in the status bar. .
After each other user activity, the screen is displayed once again.
With this in mind, this part of the unit deals with:
Flow logic in PBO and PAI event blocks
Using PBO and PAI modules as ABAP processing blocks for screen programming
Evaluating information on which pushbutton was selected at the time of PAI
SAP AG
TAW10
16-19
ABAP program
Global data object
Back
BACK
ok_code
ENDCASE.
Time
If the user chooses a pushbutton, the run time system copies the associated function code to a special
screen field. This screen field is usually called the ok_code.
The content of this screen field is then automatically transported if there is an ABAP data object of the
same name.
The content of this ok_code field can then be evaluated in an ABAP processing block.
This mechanism allows you to create a program flow that depends on the user's actions. The following
slides deal with how you declare the ok_code field, how you create pushbuttons and assign function
codes to them, and how you can change the screen sequence.
SAP AG
TAW10
16-20
Attributes
T
Name
Text
Line
Airline
Flight number
X
Departure airport
Destination airport
BUTTON2
Back
Colum
n
Flight time
Departure time
Save
Back
Input field
Output field
...
SAP AG 2001
To be able to transport information as to which pushbutton was chosen, you must assign a function code
to each pushbutton. You can do this either in the Graphical Layout Editor using the maintenance
function for field attributes or from the element list.
SAP AG
TAW10
16-21
ABAP
Editor
2
TABLES sdyn_conn.
DATA:
ok_code
like sysy-ucomm.
DATA ok_
_code LIKE
-ucomm.
ok
sy
ucomm.
Screen
Painter
Screen Painter:
Painter: List of Elements
General attributes
OK
Field name
Field text
BUTTON1
BUTTON2
OK_CODE
Save
Back
...
Function code
...
SAVE
BACK
1
SAP AG 2001
The command field serves as a special field into which corresponding function codes are placed after
every user action.
This field must be given a name in the last line of the list of elements on each screen. Generally, you use
the name OK_CODE.
In the declaration part of the program, define a corresponding data object with the same name. At run
time, whenever a user action is triggered, the function code of the pushbutton chosen is placed into the
data object. You can use the system field sy-ucomm as a reference field for the type.
SAP AG
TAW10
16-22
Calling Modules
100
CALL SCREEN 100.
PBO
MODULE
name.
MODULE name
OUTPUT.
ENDMODULE.
PAI
MODULE
name.
MODULE name
INPUT.
ENDMODULE.
The ABAP statement CALL SCREEN <nnnn> interrupts the processing of the processing block and
calls a screen.
Each screen has two event blocks:
PROCESS BEFORE OUTPUT (PBO) is processed immediately before a screen is displayed. At
this time, modules are called that take care of tasks such as presetting values in screen fields.
PROCESS AFTER INPUT (PAI) is processed immediately after a user action. All program logic
that is influenced by user action must be processed at PAI.
Note: The code for the events PBO and PAI is written using the Screen Painter, not with the ABAP
Editor. These two event blocks make up the flow logic of a screen. A special small set of commands
(not ABAP statements) is available for programming flow logic. The most important statement here is
called: MODULE module_name. This calls the module_name ABAP processing block. Within this block
you can code in ABAP as usual.
Modules are ABAP processing blocks with no interface that can be called only from within the flow
logic. Modules are enclosed within the ABAP statements MODULE and ENDMODULE.
SAP AG
TAW10
16-23
Screen
Painter
ABAP
Editor
Save
Back
user_
MODULE user_command_0100
user_command_0100
command_0100 INPUT.
CASE
CASE ok_code.
WHEN 'BACK'. ...
WHEN 'SAVE'. ...
ENDCASE.
ENDMODULE.
SAP AG 2001
You can evaluate user actions in a PAI module. Usually, this PAI module is called
user_command_nnnn, where nnnn stands for the screen number. In this module, evaluate the
function code in the ok_code field.
Note: For historical reasons, modules have no interface and no local variables. You can access all the
ABAP program's global data in modules.
SAP AG
TAW10
16-24
Create object
PAI module USER_COMMAND_100 does not exist.
Do you want to create the object?
Yes
No
Cancel
USER_COMMAND_0100
Include selection
ZBC400_00_DYNPRO
New include
Main program
ABAP
Editor
ENDMODULE.
SAP AG 2001
As a rule, you implement MODULE calls within a screen's flow control (PBO and PAI events). The
modules themselves are created using ABAP.
There are two ways to create a module:
Forward navigation: To create a module, double-click on the module name in the flow logic from
within the Screen Painter.
Navigation area: If you want to create a module from within the object list of the program, choose a
new program object PBO module or PAI module.
A module can be called from more than one screen (reusability).
Make sure that modules called at PBO events are defined using the statement MODULE ... OUTPUT,
whereas modules defined using the statement MODULE ... INPUT can be called only at PAI events.
SAP AG
TAW10
16-25
100
CALL SCREEN 100.
PBO
PAI
Screen attributes
Next screen
Next screen 0
If you enter 0 for the next screen, the system first processes your screen completely and then continues
processing the program from the point where the screen was called.
SAP AG
TAW10
16-26
100
CALL SCREEN 100.
...
PBO
PAI
Screen attributes
Next screen
100
If you set the next screen for screen 100 to 100, the system processes the screen again after it has
finished processing the PAI module.
SAP AG
TAW10
16-27
100
CALL SCREEN 100.
...
PBO
PAI
SET
SCREEN 0.
SET SCREEN
0.
Screen attributes
Next screen
100
0
Next screen 0
Using the ABAP statement SET SCREEN nnnn from within a PAI module, you can have the next
screen set dynamically. The static entry is then suppressed.
The number of the current screen is entered by the system as the standard entry for the next screen. This
ensures that the Enter key or the green checkmark lead to a field check only; afterwards the screen is
transmitted once again, possibly with a respective error message. To leave the screen, an appropriate
pushbutton must be defined that triggers a screen change within the PAI module.
Note: If the system processes the same screen again, it also runs through all the PBO modules again. If
you decide to fill the TABLES structure in a PBO module, make sure that data changes made by the user
are not overwritten on the screen if the module gets called twice
SAP AG
TAW10
16-28
.
.
MODULE user_command_0100 INPUT.
CASE ok_
ok_code.
code.
ok_code.
WHEN
WHEN 'BACK'.
'BACK'.
SET SCREEN 0.
MESSAGE s057(BC400).
WHEN
WHEN 'SAVE'.
'SAVE'.
* calling a function module to save changes
* is left out for didactical reasons
SET SCREEN 0.
MESSAGE s057(BC400).
ENDCASE.
ENDMODULE.
SAP AG 2001
For the example for evaluating function codes, two pushbuttons are discussed:
Choosing BACK dynamically sets this value to 0. This sends the user back to the callpoint. In our
case, this means the user returns to the basic list. Message 057 appears in the status bar of the next
screen.
With SAVE, the program behaves in the same way as BACK. The user returns to the basic list;
however, there is a new message in the status bar. In the unit about Cross-Program Modularization,
the program is enhanced with a data record change.
SAP AG
TAW10
16-29
Basic list
Screen field
Data object
OK_CODE
ok_code
Double-click
Transmit
screen 100
BACK
BACK
Double-click
BACK
Back to
basic list
Transmit
screen 100
BACK
BACK
SAP AG 2001
BACK
Back to
basic list?
Time
This section walks through a particular scenario to point out the necessity of an additional program step.
The user starts the program and double-clicks to display detailed information on the screen. After
determining that all the data is correct the user returns to the basic list by choosing the green arrow. In
this way, the function code BACK, which is assigned to this standard pushbutton, is placed in the
command field and then it is transported automatically to the global data object ok_code of the ABAP
program. This function code is then evaluated in a PAI module. The next screen is set to 0.
Then AT LINE-SELECTION is processed further. If there is no WRITE statement there, the system
displays the basic list again.
The user then displays details for another record by double-clicking it. Through automatic field
transport, the content of the global data object ok_code is transported into the screen field with the
same name and the screen is displayed.
If the user now chooses Enter, the screen is displayed once again, provided no function code has been
assigned to the Enter key. (Standard case!) Therefore, the command field is not overwritten. The
function code BACK remains in the command field and is copied to the global data object ok_code at
the beginning of the PAI event.
This function code is then evaluated in a PAI module. Consequently, as described above, the system
goes back to the basic list, instead of displaying the screen again.
SAP AG
TAW10
16-30
Solution Option:
Deleting the Command Field for PBO
Screen
Painter
ABAP
Editor
Save
clear_
MODULE clear_ok_code
clear_ok_
ok_code OUTPUT.
CLEAR ok_code.
ok_
ok_code.
code.
ENDMODULE.
ENDMODULE.
Back
SAP AG 2001
If the command field is not initialized, errors can occur since not every pushbutton must have a function
code assigned to it. There are two ways to initialize a command field:
Initialize the ok_code field in a PBO module. Then it is set to the initial value at PAI, unless the user
has carried out a user action to which a function code is assigned. In this case, the ok_code field
contains the current function code.
Use an auxiliary field and copy the content of the ok_code field into the auxiliary field in a PAI
module, then initialize the ok_code field. In this case, the auxiliary field must be queried in the PAI
module for the function code evaluation.
SAP AG
TAW10
16-31
SAP AG 2001
SAP AG
TAW10
16-32
Screen
Exercises
Unit: Screen
Topic: Creating Screens
At the conclusion of these exercises, you will be able to:
Create screens
Call existing screens from the program
The program SAPBC400UDT_DYNPRO_A enables you to display all
bookings made by one travel agency as a list.
As a first step, change the program as follows:
A screen is to be called whenever the user double-clicks a line in the
basic list. This screen should contain input fields for specific booking
data that is not displayed on the list. This screen should also contain
output fields for booking information that is already displayed on the list.
Any user action should result in the basic list being displayed again
Program:
ZBC400_##_DYNPRO
SAPBC400UDT_DYNPRO_A
1-1
1-2
Become familiar with the program. Test the program using the travel agency number
1## (## is your group number).
1-3
Selecting a line on the basic list (by double-clicking or using F2) should call a screen.
Create this screen (screen number 100) using forward navigation.
1-4
For the attributes, assign screen number 0 as the number of the next screen, so that
after any user action on screen 100, the user returns to the basic list.
1-5
Create input/output fields on the screen. When you are assigning field types, refer to
ABAP ABAP Dictionary structure SDYN_BOOK.
SAP AG
TAW10
16-33
1-6
SAP AG
Copy booking table key fields CARRID, CONNID, FLDATE, and BOOKID with
their field labels.
The customer name NAME should be copied without a field label and should be
displayed next to the customer number.
The customer name NAME should be displayed next to the customer number
without text (Output only attribute).
TAW10
16-34
Exercises
Unit: Screen
Topic: Data Transport
At the conclusion of these exercises, you will be able to:
Fill the screen fields with data from the program
ZBC400_##_DYNPRO
2-1
2-2
2-3
2-4
2-5
SAP AG
TAW10
16-35
Exercises
Unit: Screen
Topic: Field Transports and Subsequent Screen Processing
At the conclusion of these exercises, you will be able to:
Create pushbuttons on screens
Process the system code triggered when the user clicks on a
pushbutton and thus control the program flow
Set the next screen dynamically
Change your program ZBC400_##_DYNPRO:
On the screen, the user should be able to control program flow through
two pushbuttons.
Program:
ZBC400_##_DYNPRO
3-1
3-2
Define two pushbuttons on the screen that allow the user to either return to the basic
list (PUSH_BACK) or to save the changed data (PUSH_SAVE):
Name of
pushbutton
Text
Function code
PUSH_BACK
Back
BACK
PUSH_SAVE
Save
SAVE
or icon
ICON_SYSTEM_SAVE
3-3
SAP AG
Name the OK_CODE field on the screen and define a data object of the same name (and
corresponding type) in the program.
TAW10
16-36
3-4
Navigate in the flow logic. Create a module for function code processing (using
forward navigation) at PROCESS AFTER INPUT:
Function code
Next screen
Action
BACK
None
List
SAVE
First:
List
3-5
SAP AG
None
Screen 100
Ensure that pressing Enter always displays screen 100, regardless of the navigation
history. Initialize the OK_CODE field in a PBO module.
TAW10
16-37
Screens
Solutions
Unit: Screens
Topic: Creating Screens
*&--------------------------------------------------------------*
*& Report
SAPBC400UDS_DYNPRO_A
*&
*&
*&--------------------------------------------------------------*
REPORT
sapbc400uds_dynpro_a.
START-OF-SELECTION.
* selecting data using an ABAP dictionary view to get the data from
* sbook and the customer name from scustom
SELECT carrid connid fldate bookid customid name
FROM sbc400_booking
INTO CORRESPONDING FIELDS OF wa_booking
WHERE agencynum = pa_anum.
TAW10
16-38
FIELD actvt_display.
IF sy-subrc = 0.
* Output
WRITE: / wa_booking-carrid COLOR col_key,
wa_booking-connid COLOR col_key,
wa_booking-fldate COLOR col_key,
wa_booking-bookid COLOR col_key,
wa_booking-name.
ENDIF.
ENDSELECT.
AT LINE-SELECTION.
CALL SCREEN 100.
1-3
1-4
1-5
Layout
- Navigate to the Graphical Layout Editor
- Choose the Dict/Program fields icon
- Enter SDYN_BOOK
- Choose the Get from Dictionary icon
- Select the fields you want
choose Enter to confirm, and drag these fields to the screen
- 1st Block:
Copy key fields: CARRID, CONNID, FLDATE, and BOOKID
with field names
- 2nd Block:
Copy customer name NAME
without a field name (choose the Without text radio button)
SAP AG
TAW10
16-39
- 3rd Block:
Copy the fields: CUSTOMID, CUSTTYPE, SMOKER, CLASS,
LOCCURAM, and LOCCURKEY
with field names
1-6
Change the field attributes for example, by double-clicking the input field
- Change the attributes:
- The fields CARRID, CONNID, FLDATE, BOOKID, and CUSTOMID
should be displayed as output fields (Output field attribute).
- The customer name NAME should be displayed next to the customer number
without text
(Output only attribute).
- The fields CUSTTYPE, SMOKER, CLASS, LOCCURAM, and
SAP AG
TAW10
16-40
Solutions
Unit: Screens
Topic: Data Transport
SAPBC400UDS_DYNPRO_B
*&
*&
*&--------------------------------------------------------------*
REPORT
sapbc400uds_dynpro_b.
START-OF-SELECTION.
TAW10
16-41
FIELD actvt_display.
IF sy-subrc = 0.
* Output
WRITE: / wa_booking-carrid COLOR col_key,
wa_booking-connid COLOR col_key,
wa_booking-fldate COLOR col_key,
wa_booking-bookid COLOR col_key,
wa_booking-name.
HIDE:
wa_booking-carrid,
wa_booking-connid,
wa_booking-fldate,
wa_booking-bookid,
wa_booking-name.
ENDIF.
ENDSELECT.
AT LINE-SELECTION.
FIELD actvt_change.
IF sy-subrc = 0.
SELECT SINGLE *
FROM sbook
INTO wa_sbook
WHERE carrid = wa_booking-carrid
AND connid = wa_booking-connid
AND fldate = wa_booking-fldate
AND bookid
= wa_booking-bookid.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_sbook TO sdyn_book.
MOVE wa_booking-name TO sdyn_book-name.
SAP AG
TAW10
16-42
SAP AG
TAW10
16-43
Unit: Screens
Topic: Field Transports and Subsequent Screen Processing
*&--------------------------------------------------------------*
*& Report
SAPBC400UDS_DYNPRO_C
*&
*&
*&--------------------------------------------------------------*
REPORT
sapbc400uds_dynpro_c.
START-OF-SELECTION.
TAW10
16-44
FIELD actvt_display.
IF sy-subrc = 0.
* Output
WRITE: / wa_booking-carrid COLOR col_key,
wa_booking-connid COLOR col_key,
wa_booking-fldate COLOR col_key,
wa_booking-bookid COLOR col_key,
wa_booking-name.
HIDE:
wa_booking-carrid,
wa_booking-connid,
wa_booking-fldate,
wa_booking-bookid,
wa_booking-name.
ENDIF.
ENDSELECT.
CLEAR wa_booking.
AT LINE-SELECTION.
FIELD actvt_change.
IF sy-subrc = 0.
SELECT SINGLE *
FROM sbook
INTO wa_sbook
SAP AG
TAW10
16-45
= wa_booking-bookid.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_sbook TO sdyn_book.
MOVE wa_booking-name TO sdyn_book-name.
CALL SCREEN 100.
ENDIF.
ELSE .
MESSAGE ID 'BC400' TYPE 'S' NUMBER '047'
WITH wa_booking-carrid.
ENDIF.
*&--------------------------------------------------------------*
*&
Module
CLEAR_OK_CODE
OUTPUT
*&--------------------------------------------------------------*
*&
text
*&--------------------------------------------------------------*
MODULE clear_ok_code OUTPUT.
CLEAR ok_code.
ENDMODULE.
" CLEAR_OK_CODE
OUTPUT
*&--------------------------------------------------------------*
*&
Module
USER_COMMAND_0100
INPUT
*&--------------------------------------------------------------*
*&
text
*&--------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'SAVE'.
SAP AG
TAW10
16-46
ENDCASE.
ENDMODULE.
SAP AG
" USER_COMMAND_0100
TAW10
INPUT
16-47
Global Modularization
Contents:
Function Groups and Function Modules
Working with Methods
Working with BAPIs
SAP AG 2003
SAP AG
TAW10
17-1
SAP AG 2003
SAP AG
TAW10
17-2
Function
Function Groups
Groups and
and Function
Function Modules
Modules
Working
Working with
with Methods
Methods
Working
Working with
with BAPIs
BAPIs
SAP AG 2003
SAP AG
TAW10
17-3
Function Module
Function Module
Attributes
Local data objects
Source code
Interface
Import
Import parameters
parameters
Export parameters
Changing parameters
Exceptions
sy-subrc
SAP AG 2001
Function modules can, therefore, be called specifically from within programs or function modules.
Exceptions provide information about error situations. If a function module initiates an exception,
processing of the function module is interrupted. It is possible to set a return code, if necessary, in the
calling program.
As is the case with subroutines, a function module can contain local type and data object definitions.
SAP AG
TAW10
17-4
Function Group
e le
fac odu
r
e
Int ion M 1
t
Fun
Subroutine
Screen
le
F
face
Inter
u
Mod
ction 5
M
Interface
nter
fa ce
FM
Fun
ction
M
FM3 odule
I
nc
Fu
Fu Int
nc er
tio fac
n
FM Mo e
Global
2 du
le
data objects
Function Module
FM4
Interface
SAP AG 2001
A function group represents the main program for function modules. Several function modules that
operate on the same data content are combined to form a function group.
The function group remains active for as long as the calling program is active. For example, if an
executable program calls a function module, its entire function group is loaded as well. It remains active
until the executable program is completed.
A function group can contain the same components as an executable program. These include:
Data Objects
These are then global in relation to the function group, that is, they are visible to and changeable by all
function modules within the group. The validity period is the same as for the function group.
Subroutines
These can be called from all function modules in the group.
Screens
These can be called from all function modules in the group.
SAP AG
TAW10
17-5
e le
fac odu
r
e
Int ion M 1
t
FM
F
face
Inter
ule
Mod
ction 5
M
Inte
r fac
e
Fun
Fun
ction
M
FM3 odule
nc
Fu
Fu Int
nc er
tio fac
n
FM Mo e
2 du
le
Function Module
FM4
Interface
SAP AG 2001
The global data of a function module is retained until the program that contained the first call of a
function module in the function group is finished.
Thus, if a function module that writes values to the global data is called, other function modules in the
same function group can access this data when the program calls them.
Seen from the outside, the global data is encapsulated, that is, it is not possible to access it directly.
Therefore, you must have function modules that allow orderly access from the outside.
The same applies to all the other components of the function group (screens, subroutines).
SAP AG
TAW10
17-6
Attributes
Function module
Edit
Goto
Utilities
Environment
System
Help
active
BC402_FMDD_GET_FREE_SEATS
Attributes
Import
Export
Changing
Tables
Exceptions
Source code
Classification
Function group
BC402_FMDD_FLIGHT
Short text
Processing type
General data
Development class
BC402
Update module
SAP AG 2002
In the Attributes of a function module, you specify its general administrative data and the processing type:
Remote-enabled function modules can be called asynchronously in the same system and can be called
from other systems (not just R/3 Systems). To call a function module in another system, there must be a
valid system connection. For further information, refer to the course BC415 - Communications Interfaces in
ABAP or the online documentation.
Update function modules contain additional functions for bundling database changes. For
further information, refer to the course BC414 - Programming Database Updates or the online
documentation.
The online documentation also details the interface restrictions that apply to remote-enabled and
update function modules.
SAP AG
TAW10
17-7
Interface
Function module
Edit
Goto
Utilities
Environment
System
Help
active
BC402_FMDD_GET_FREE_SEATS
Attributes
Import
Export
Changing
Tables
Attributes
Parameter name
EP_SEATSFREE
Import
Type
TYPE
Export
Changing
Tables
Exceptions
Source code
Short text
Seats free
SAP AG 2002
Three kinds of parameters can be used to exchange data with function modules:
Importing parameters, which are received by the function module
Exporting parameters, which are returned by the function module
Changing parameters, which are both received and returned
By default, all parameters are passed by reference. You can change exporting and changing parameters
only in the function module. This rule ensures that you avoid unwanted side effects. If you want to pass
parameters by value, you must select the relevant option when you define the interface.
You can also declare importing and changing parameters as optional. You do not have to pass values to
these parameters when you call the function module. Where possible, use this option when you add new
parameters to function modules that are already in use. You can assign a default value to an optional
parameter. If you do not pass a value of your own when you call the function module, the system then
uses the default value instead. Exporting parameters are always optional.
You may specify the type of an elementary parameter. You must specify the type of a structured or table
parameter. You can use either ABAP Dictionary types, ABAP Dictionary objects, predefined ABAP
type (i,f,p,n,c,string,x,xstring,d,t) or user-defined types. Any type conflicts show up in
the extended program check. You can also assign a reference type.
Table parameters are obsolete for normal function modules but have been retained to ensure
compatibility for function modules with other execution modes.
SAP AG
TAW10
17-8
Processing Logic
Function module
Edit
Goto
Utilities
Environment
System
Help
Attributes
active
BC402_FMDD_GET_FREE_SEATS
Import
Export
Changing
Tables
Exceptions
Source code
FUNCTION bc402_fmdd_get_free_seats.
*"--------------------------------*"*"Local Interface:
*" IMPORTING
*" EXPORTING
*" EXCEPTIONS
*"--------------------------------...
ENDFUNCTION.
SAP AG 2002
When you save the interface, the system generates the statement framework together with the
comment block that lists the interface parameters:
FUNCTION name.
*"-------------*" ...
*"-------------...
ENDFUNCTION.
The comment block is updated automatically if you make changes to the function module later on.
This means that you can always see the interface definition when you are coding the function
module. You program the statements exactly as you would in any other ABAP program in the
ABAP Editor.
In the function module, you can create your own local types and data objects and call subroutines
or other function modules.
SAP AG
TAW10
17-9
Exceptions
Function module
Edit
Goto
Utilities
Environment
System
Help
Attributes
active
BC402_FMDD_GET_FREE_SEATS
Import
Exception
NO_SEATS
OVERLOAD
DB_FAILURE
Export
Changing
Tables
Exceptions
Source code
Short text
Cargo plane
Overbooked
No data
RAISE <exception>.
*** with default message:
MESSAGE <kind><num>(<id>)
RAISING <exception>.
SAP AG 2002
exception under the required condition. At runtime, the function module is terminated when an
exception is triggered. The changes to exporting and changing parameters are the same as in
subroutines. You can use two statements to raise an exception. In the forms given below,
exception stands for the name of an exception that you declared in the interface. The system
reacts differently according to whether or not the exception was listed in the function module call:
RAISE exception.
If the exception is listed in the calling program, the system returns control to it directly. If
the exception is not listed, a runtime error occurs.
MESSAGE <kind><num>(<id>) RAISING <exception>.
NOTE: If the exception is listed in the calling program, the statement has the same effect as RAISE
<exception>. If it is not listed, the system sends message <num> from message class <id>
with type <kind>, and no runtime error occurs.
SAP AG
TAW10
17-10
Parameters
Exceptions
Worklist
Revised version
Inactive version
Active version
Exceptions
Messages
SAP AG 2002
Function modules differ from subroutines in that you must assume that other programmers will use
them. For this reason, you should ensure that you complete the steps listed here:
You should document all your parameters and exceptions, along with your entire function module,
with short text (and long text if necessary). The system provides a text editor for you to do this,
containing predefined sections for Functions, Example Call, Hints, and Further
Information.
Work list
When you change an active function module, it acquires the status active (revised). When
you save it, another version is created with the status inactive. When you are working on a
function module, you can switch between the inactive version and the last version that you
activated. When you activate the inactive version, the previous active version is overwritten.
Function test
Note: Once you have activated your function module, you can test it using the built-in test
environment in the Function Builder. If an exception is triggered, the test environment
displays it, along with any message that you may have specified for it. You can also switch
into the Debugger and the Runtime Analysis. You can save test data and compare sets of
results.
SAP AG
TAW10
17-11
Call
DATA: result TYPE s_seatsmax.
PARAMETERS: pa_type TYPE s_planetye, pa_occ
TYPE s_seatsmax.
CALL
CALL FUNCTION
FUNCTION ''BC402_FMDD_GET_FREE_SEATS''
EXPORTING
ip_planetype = pa_type
ip_seatsocc = pa_occ
" default: 0
IMPORTING
IMPORTING
Insert pattern
ep_seatsfree = result
CALL FUNCTION
BC402_FMDD_GET_FREE_SEATS
EXCEPTIONS
...
no_seats
= 1
...
overload
= 2
...
OTHERS
= 3.
...
...
syCASE sy-subrc.
sy-subrc.
WHEN 0.
WRITE: / result COLOR 5.
WHEN 1.
WRITE: / 'You''ll have to stand, it''s a freighter!'(frt).
WHEN 2.
WRITE: / 'The plane has already been overloaded!'(nos).
WHEN 3.
WRITE: / 'Please contact your system administrator!'(adm).
ENDCASE.
SAP AG 2002
When you insert a function module call in your program, you should use the Pattern function.
Then, you only need to enter the name of the function module (input help is available). The system
then inserts the call and the exception handling (MESSAGE statement) into your program.
You assign parameters by name. The formal parameters are always on the left side of the
expressions:
Exporting parameters are passed by the program. If a parameter is optional, you do not
need to pass it. Default values are displayed if they exist.
Importing parameters are received by the function module. Importing parameters are always
optional.
Changing parameters are both passed and received. You do not have to list optional
parameters. Default values are displayed if they exist.
The system assigns a value to each exception, beginning at one and continuing to number them
sequentially in the order they are declared in the function module definition. You can assign a
value to all other exceptions that you have not specifically listed using the special exception
OTHERS.
If you list the exceptions and one is triggered in the function module, the corresponding value is
placed in the return code field sy-subrc. If you did not list the exception in the function call, a
runtime error or a message occurs, depending on the statement you used in the function module
to trigger the exception.
SAP AG
TAW10
17-12
Edit
Goto
Utilities
Environment
System Help
Object Navigator
Workbench Edit
Goto
Extras
Environment
System Help
Object Navigator
Object list
Development class
program
Function group
Class
Local objects
Object name
BC402_FMDD_WAITLIST
Display
PBO modules
Global declarations
Function modules
>
BC402_FMDD_WAITLIST
<
<
<
<
<
>
Function modules
Fields
PBO modules
Screens
GUI titles
Includes
LBC402_FMDD_WAITLISTO01
LBC402_FMDD_WAITLISTTOP
LBC402_FMDD_WAITLISTU01
LBC402_FMDD_WAITLISTU02
LBC402_FMDD_WAITLISTU03
LBC402_FMDD_WAITLISTU04
LBC402_FMDD_WAITLISTU05
LBC402_FMDD_WAITLISTU06
LBC402_FMDD_WAITLISTUXX
SAP AG 2002
As described in the ABAP Runtime Environment unit, the ABAP Workbench helps you to
structure your source code when you work with function groups and function modules.
Forward navigation ensures that you always enter the correct object. Include programs are named
automatically, and the relevant call statements are inserted automatically in the correct positions.
You only have to observe the naming convention for function groups: Y|Z<rem_name>.
The system then creates a type F program called SAPLY|Z<rem_name>, which contains automatically
generated INCLUDE statements. The include programs are also named automatically:
LY|Z<rem_name><abbrev><num>.
The system also inserts the include program, LY|Z<rem_name>UXX, which contains an include
statement in the form LY|Z<rem_name>U<num> for each function module.
SAP AG
TAW10
17-13
Function
Function Groups
Groups and
and Function
Function Modules
Modules
Working
Working with
with Methods
Methods
Working
Working with
with BAPIs
BAPIs
SAP AG 2003
SAP AG
TAW10
17-14
Name
meth1
8
attr1
attr2 ...
meth2
attr1
attr2
...
Methods (functions):
meth1
meth1
meth2
...
123
attr1
attr2 ...
meth2
meth1
Class:
technical
description
of objects
4711
attr1
attr2 ...
meth2
Objects:
Runtime instances
in a class
SAP AG 2001
At first glance, a class is very much like a function group since it contains data objects (attributes) and
functions (methods). These components can be protected from access by components of other programs.
Then they can be accessed only by methods belonging to the class.
In contrast to function groups, classes can have multiple instances, that is, more than one runtime object
can be created for each program in a class. In other words, a class contains the technical description of
objects (instances). All these objects, therefore, have the same attributes and provide the same methods.
However, they can be distinguished physically. Their attributes can have different features.
Classes can be defined either locally within an executable program or globally in the Class Builder.
The ABAP runtime system provides support for standard object-oriented syntax elements as of Release
4.6A. For more details, refer to the SAP online library.
SAP AG
TAW10
17-15
ref2
meth1
ABAP program
SAP AG 2001
To create instances of classes and to be able to access them, you need reference variables, which are
pointers to these instances. You define these reference variables using DATA reference_name
TYPE REF TO class_name.
At program start, the data objects are created in memory. However, since no instances have been created
yet, the reference variables are still empty.
At runtime, you can create as many instances of classes as you wish using
CREATE OBJECT reference_name.
If necessary, the import parameters of the special method CONSTRUCTOR must be filled with values.
This special method is executed immediately after the instance is created. As a rule, basic settings for the
actual instance are thus created.
SAP AG
TAW10
17-16
Picture Control
http://www.sap.com
Airlines
AA
0017
0064
LH
0400
0402
Tree Control
SAP AG 2001
As of Release 4.6A, the ABAP Workbench offers several new EnjoySAP controls in order to move
dialog functions from the application server to the presentation server. These controls are called on an
object-oriented basis using classes, that is, the SAP Control Framework.
For each method call, you select the controls from your ABAP program. The Control Framework sends
your requests to the presentation server where they are converted on a platform-specific basis.
You can give the user the option of triggering events on the presentation server. The Control Framework
then converts these events and you can react to them in your ABAP program.
For more details on the EnjoySAP controls and the Control Framework, refer to the SAP online library.
SAP AG
TAW10
17-17
Function
Function Groups
Groups and
and Function
Function Modules
Modules
Working
Working with
with Methods
Methods
Working
Working with
with BAPIs
BAPIs
SAP AG 2003
SAP AG
TAW10
17-18
BAPI
SAP AG 2001
A BAPI can be viewed as the door to the SAP system; this interface provides access to business data and
processes in the SAP system from the outside.
Each object in the BOR can have several methods, one or more of which can be implemented as BAPIs.
BAPIs usually exist for basic functions of a business object, such as:
Creating objects
Querying the attributes of an object
Changing the attributes of an object
SAP AG
TAW10
17-19
BAPI Usage
JAVA, C, ...
Internet /
Intranet
Business
Component
R/3 Component
Creation
Business
B
Component
Business
Component
Business
Workflow
SAP AG 2001
SAP AG
TAW10
17-20
Standardized BAPIs
GetList
Supplies a list of object key fields that satisfy selected
criteria (search function)
GetDetail
Supplies detailed information (attributes) on an object
(the full key must be specified)
Create, Change, Delete, Cancel
Creating, changing, and deleting objects
AddItem, RemoveItem
Creating and removing subobjects (for example,
item in an order)
SAP AG 2001
SAP AG
TAW10
17-21
Hierarchy
Alphabetical
Detail
Documentation
Tools
Project
Method (BAPI)
FlightBooking
FlightCustomer
FlightConnection
AirlineCarrier
ConnectionNumber
DateOfFlight
GetDetail
Return
FlightData
Method
GetDetail
Business object
FlightBooking
Short text
Flight details
New as of release
40C
Function module
BAPI_SFLIGHT_GETDETAIL
GetList
Double-click:
Navigation in
Function Builder
SAP AG 2001
From the SAP Easy Access menu, you call the BAPI Explorer by choosing Tools Business
Framework BAPI Browser.
Using the BAPI Explorer, you can navigate to the function module display for the selected BAPI in the
Function Builder.
Select the BAPI in the hierarchy section.
In the detailed display window, choose the Detail tab.
By double-clicking on the name of the function module, you can display it in the Function Builder.
SAP AG
TAW10
17-22
Error messages
through EXPORT
parameter RETURN
(structure or
internal table)
No CHANGING
parameters
No
exceptions
Interface
Structure of
BAPI_name
Remote
capability
Source code
No user
dialogs
SAP System
Function group
SAP AG 2001
SAP AG
TAW10
17-23
BACV
BOR
SAP AG 2001
If you would like to use a BAPI in the SAP R/3 System, you can call the function module containing it.
Pay attention to the limitations already mentioned.
BAPI interfaces are created according to the needs for the "external" call, that is, from a non-R/3
System. Quantities are expected in an external format with 4 or 9 decimal places. The quantities must be
transferred to the interface in converted format, even if the corresponding currency has no decimal
places.
For this conversion you can use function modules from the BACV function group (development class
SBF_BAPI).
SAP AG
TAW10
17-24
Global Modularization:
Unit Summary
SAP AG 2003
SAP AG
TAW10
17-25
1. All plane types that are available for each airline should be stored in a function group in an
internal table. For simplicity, these should have a flat line structure and not a nested structure.
## is your two-digit group number
Model solution:
TAW10_BASICS_FLIGHT
1-1
1-2
1-3
SAP AG
TAW10
17-26
2. A function module should fill internal tables for plane types. Only the available replacement
types for the airline with sufficient seats should be written to the table.
From the total prices that are transferred, the average price for each seat should also be
calculated. The plane list should then be sorted in descending order before it is returned.
## is your two-digit group number
Model solutions:
TAW10_BASICS_FLIGHT
TAW10_BASICS_CREATE_PLANELIST
2-1
2-2
Declare the line type t_carr_plane as your function groups global data type. It
should be structured as follows:
Component
Type
carrid
planetype
seatsmax
scarplan-carrid
scarplan-planetype
saplane-seatsmax
Declare the internal table it_carr_planes with line type t_carr_plane as the
global data object of your function group. It should be in the form of a sorted table with
the unique key carrid and planetype.
2-4
Fill the internal table it_carr_planes for each array fetch using view
TAW10_CARPLAN.
Choose an appropriate time for the event to occur. Remember that a
function group cannot be executed directly.
Implement the corresponding event block in a suitable include
program that you have added to the main program at a suitable
location. Adhere to the naming conventions for function group
include programs.
2-5
Now declare the import parameter with pass by value for your function module:
ip_seatsocc as an optional parameter with the default value 0,
ip_carrid, ip_paymentsum, ip_currency.
2-6
Declare the export parameter ep_planelist with pass by value. Assign a type
using the global table type TAW10_TYPS_PLANETAB.
SAP AG
TAW10
17-27
2-7
2-8
2-9
From the global internal table, read those plane types that are available to the airline
and which have sufficient seats for the booking that was transferred.
In this loop calculate the average price for each seat for each plane type. Also declare
work area l_wa_plane as a local data object within the function module. Assign a
type using the global structure TAW10_TYPS_PLANE.
Attach the completely filled work area to the internal table to be exported.
2-10
Before exporting, sort the internal table by the average price per seat.
2-11
Trigger the exception if no suitable plane types could be found. Implement the trigger
using error message 040, specifying the airline.
2-12
2-13
SAP AG
TAW10
17-28
3. If a plane breaks down that is already scheduled for a flight and already has bookings, a
replacement plane must be used. Write a program that outputs all the available replacement
plane types for each airline in a list. You can obtain the data for the list using the function
module you created in Task 2.
Model solution:
TAW10_BASICS_CALL_FUNCTION
3-1
3-2
In the program, define an internal table it_planelist that stores the replacement
plane types. The type of this internal table results from the function module interface.
3-3
The user should query the IMPORTING parameters of the function module using a
selection screen, where the field for the airline must be a mandatory field.
3-4
3-5
Display the table it_planelist filled by the function module in a list. Use a field
symbol for this.
SAP AG
TAW10
17-29
1-1, 2-4
**************************************************************
*
System-defined Include-files.
**************************************************************
INCLUDE ltaw10_basics_flighttop.
" Global Data
INCLUDE ltaw10_basics_flightuxx.
" Function Modules
**************************************************************
*
User-defined Include-files (if necessary).
**************************************************************
INCLUDE ltaw10_basics_flighttop.
" Subprograms
* INCLUDE LTAW10_BASICS_FLIGHTO...
" PBO-Modules
* INCLUDE LTAW10_BASICS_FLIGHTI...
" PAI-Modules
INCLUDE ltaw10_basics_flighte01.
" Events
TYPES:
BEGIN OF t_carr_plane,
carrid
TYPE scarplan-carrid,
planetype TYPE scarplan-planetype,
seatsmax TYPE saplane-seatsmax,
END OF t_carr_plane.
DATA:
it_carr_planes TYPE SORTED TABLE OF t_carr_plane
WITH UNIQUE KEY carrid planetype.
SAP AG
TAW10
17-30
2-4
*------------------------------------------------------------*
*
INCLUDE LTAW10_BASICS_FLIGHTE01
*
*------------------------------------------------------------*
LOAD-OF-PROGRAM.
SELECT carrid planetype seatsmax
FROM taw10_carplan
INTO CORRESPONDING FIELDS OF TABLE it_carr_planes.
FUNCTION TAW10_BASICS_CREATE_PLANELIST.
*"-----------------------------------------------------------*"*"Local interface:
*" IMPORTING
*"
VALUE(IP_SEATSOCC) TYPE SFLIGHT-SEATSOCC DEFAULT 0
*"
VALUE(IP_CARRID) TYPE SPFLI-CARRID
*"
VALUE(IP_PAYMENTSUM) TYPE SFLIGHT-PAYMENTSUM
*"
VALUE(IP_CURRENCY) TYPE SFLIGHT-CURRENCY
*" EXPORTING
*"
VALUE(EP_PLANELIST) TYPE TAW10_TYPS_PLANETAB
*" EXCEPTIONS
*"
NO_PLANES
*"-----------------------------------------------------------DATA:
l_wa_carr_plane TYPE t_carr_plane,
l_wa_plane
TYPE taw10_typs_plane.
LOOP AT it_carr_planes INTO l_wa_carr_plane
WHERE carrid EQ ip_carrid
AND
seatsmax GE ip_seatsocc.
l_wa_plane-planetype = l_wa_carr_plane-planetype.
l_wa_plane-seatsmax = l_wa_carr_plane-seatsmax.
l_wa_plane-avg_price =
ip_paymentsum / l_wa_carr_plane-seatsmax.
l_wa_plane-currency = ip_currency.
APPEND l_wa_plane TO ep_planelist. ENDLOOP.
IF sy-subrc NE 0.
MESSAGE e040 RAISING no_planes WITH ip_carrid.
ELSE.
SORT ep_planelist BY avg_price DESCENDING.
ENDIF.
ENDFUNCTION.
SAP AG
TAW10
17-31
*&-----------------------------------------------------------*
*& Report TAW10_BASICS_CALL_FUNCTION
*
*&
*
*&-----------------------------------------------------------*
*& solution of exercise 3 function groups
*
*&
and function modules
*
*&-----------------------------------------------------------*
REPORT
taw10_basics_call_function.
DATA:
FIELD-SYMBOLS:
PARAMETERS: pa_carr
pa_occ
AT SELECTION-SCREEN.
= pa_occ
ip_carrid
= pa_carr
ip_paymentsum = pa_paysu
ip_currency
= pa_curr
IMPORTING
ep_planelist
= it_planelist
EXCEPTIONS
no_planes
= 1
OTHERS
= 2.
CASE sy-subrc.
WHEN 1.
MESSAGE e040(taw10) WITH pa_carr.
SAP AG
TAW10
17-32
WHEN 2.
MESSAGE e041(taw10).
ENDCASE.
START-OF-SELECTION.
WRITE: / <plane>-planetype,
<plane>-seatsmax,
<plane>-avg_price CURRENCY <plane>-currency,
<plane>-seatsmax,
ENDLOOP.
SAP AG
TAW10
17-33
Contents:
Techniques for calling programs
Memory model
Techniques for passing data
Use
SAP AG 2002
SAP AG
TAW10
18-1
SAP AG 2002
SAP AG
TAW10
18-2
Calling
Calling programs
programs
Memory
Memory management
management
Passing
Passing data
data
SAP AG 2002
SAP AG
TAW10
18-3
Calling Programs
Time
Main
memory
Main
memory
1
New program
Insert program
Insertion
2
Restart
End insert
Program 1
Program 2
SAP AG 2002
There are two ways of starting an ABAP program from another ABAP program that is already running:
The called program is inserted, that is the current program is interrupted to run the new one. The called
program is executed, and afterwards, processing returns to the program that called it.
The current program is terminated and the called program is started.
Complete ABAP programs within a single user session can only run sequentially. We refer to this
technique as sequential calling.
If you want to run functions in parallel, you must use function modules. For further information about this
technique, refer to the course BC415 (Communication Interfaces in ABAP) or the documentation for the
CALL FUNCTION ... STARTING NEW TASK ... statement.
SAP AG
TAW10
18-4
...
SUBMIT prog_name_2.
...
Program 2
Restart
prog_name_2
PROGRAM ...
...
List
F3
...
SUBMIT prog_name_2
AND RETURN.
...
Insertion
prog_name_2
PROGRAM ...
...
List
F3
Insertion
...
SUBMIT prog_name_2
VIA SELECTION-SCREEN
AND RETURN.
...
Selection Screen
prog_name_2
Liste
PROGRAM ...
...
F3
F3
SAP AG 2002
SAP AG
TAW10
18-5
Calling a Transaction
Program 1
Program 2: Transaction
TCODE
Restart
1. Screen
...
LEAVE TO TRANSACTION 'T_CODE'
[AND SKIP FIRST SCREEN].
...
2. Screen
F15
Insertion
...
CALL TRANSACTION 'T_CODE'
[AND SKIP FIRST SCREEN].
...
1. Screen
2. Screen
F15
SAPM t_name
...
LEAVE PROGRAM.
...
SAPM t_name
...
LEAVE PROGRAM.
...
SAP AG 2002
With the LEAVE TO TRANSACTION 'T_CODE' statement you terminate the current program and start
the transaction with transaction code T_CODE. The statement is the equivalent to entering /n<T_CODE>
in the command field.
CALL TRANSACTION 'T_CODE' allows you to insert ABAP programs that have a transaction code.
To terminate an ABAP program, use the LEAVE PROGRAM statement. If the statement is used in a
program that you called using CALL TRANSACTION 'T_CODE' or SUBMIT prog_name AND
RETURN, the system resumes processing at the next statement after the call in the calling program.
Otherwise, the user returns to the application menu from which he or she started the program.
If you use the ... AND SKIP FIRST SCREEN addition, the system does not display the screen
contents of the first screen. However, it does process the flow logic.
If the transaction T_CODE you called with CALL TRANSACTION uses update techniques, you can use the
UPDATE... addition to specify the update technique (asynchronous (default), synchronous, or local) that
the program should use. For further information, refer to course BC414 (Programming Database
Updates) and the online documentation.
SAP AG
TAW10
18-6
Calling
Calling programs
programs
Memory
Memory management
management
Passing
Passing data
data
SAP AG 2002
SAP AG
TAW10
18-7
ABAP memory 2
ABAP memory 1
Program 1.2
Program 1.1
Program 2.1
SAP memory
SAP AG 2002
The way in which the main memory is organized from the program's point of view can be represented in
the above logical model. There is a distinction between internal and external sessions:
Generally, an external session is connected to an R/3 window. You can create a new session by
choosing System New Session or by entering /o<T_CODE> in the command field. You can have up
to six external sessions open simultaneously in one terminal session.
External sessions are subdivided into internal sessions (placed on a stack). Each program that you run
occupies its own internal session. Each external session can contain up to nine internal sessions.
Data for a program is only visible within an internal session. The visibility of the data is generally
restricted to the relevant program.
The following slides illustrate how the stack inside an external session changes with various program calls.
SAP AG
TAW10
18-8
ABAP memory 1
ABAP memory 2
Program 1.1
Program 2.1
SAP memory
SAP AG 2002
SAP AG
TAW10
18-9
ABAP memory 2
ABAP memory 1
Program 1.2
Program 1.1
Program 2.1
SAP memory
SAP AG 2002
When you insert a program, the system creates a new internal session, which in turn creates a new program
context.
The new session is placed on the stack The program context of the calling program also remains intact.
SAP AG
TAW10
18-10
ABAP memory 1
ABAP memory 2
Program 1.1
Program 2.1
SAP memory
SAP AG 2002
When the called (inserted) program finishes, its internal session (the top one in the stack) is deleted.
Processing is resumed in the next-highest internal session in the stack.
SAP AG
TAW10
18-11
ABAP memory 2
ABAP memory 1
Program 1.1
SAP memory
SAP AG 2002
When you end a program and start a new one, there is a distinction between calling an executable program
and calling a transaction, with regard to memory areas.
SAP AG
TAW10
18-12
ABAP memory 2
ABAP memory 1
Program 1.1
SAP memory
SAP AG 2002
If you call an executable program using its program name (terminating the calling program), the system
deletes the internal session of the program that you are terminating (the top one from the stack).
The system creates a new internal session, which in turn creates the program context of the called program.
The new session is placed on the stack Existing program contexts remain intact. The topmost internal
session on the stack is replaced.
SAP AG
TAW10
18-13
ABAP memory 2
ABAP memory 1
Program 1.1
SAP memory
SAP AG 2002
SAP AG
TAW10
18-14
Restart
(complete
initialization)
ABAP memory 2
Program 1'.1
SAP memory
SAP AG 2002
If you start a program using its transaction code (that is, if one was defined), all of the internal sessions on
the stack are deleted.
The system creates a new internal session, which in turn creates the program context of the called program.
After the call, the ABAP memory is initialized.
SAP AG
TAW10
18-15
Calling
Calling programs
programs
Memory
Memory management
management
Passing
Passing data
data
SAP AG 2002
SAP AG
TAW10
18-16
SAP memory
(SET/GET parameters)
3
ABAP memory
2
Program A
Interface
1
Program B
DB
5
SAP AG 2002
There are various ways of passing data to programs running in separate internal sessions:
You can use:
The interface of the called program (usually a standard selection screen)
ABAP memory
SAP memory
Database tables
Local files on your presentation server
The following slides deal with the first three of these methods.
For further information regarding the passing of data using database tables or the shared buffer, refer to the
documentation for the EXPORT and IMPORT statements.
For further information on transferring data between an ABAP program and a presentation server, refer to
the documentation for the function modules GUI_UPLOAD and GUI_DOWNLOAD.
SAP AG
TAW10
18-17
Program A
Data
Program B
SAP AG 2002
When you call ABAP programs that have a standard selection screen, you can pass data for the input fields
in the call.
There are two ways to do this:
By specifying a variant for the selection screen when you call the program
By specifying values for the input fields when you call the program
SAP AG
TAW10
18-18
Insert pattern
...
...
...
Other pattern
SUBMIT
SAP AG 2002
The WITH addition to the SUBMIT statement allows you to preassign values for parameters and selection
options on a standard selection screen of the called executable program. The abbreviations "EQ, NE, ...; I,
E" have the same meanings as with selection options.
If you want to pass several selections for a selection option, you can use the RANGE statement instead of
individual WITH additions. The RANGES statement creates a selection table, which you can fill as though
it were a selection option. You then pass the whole table to the executable program.
If you want to display the standard selection screen when you call the program, use the VIA
SELECTION-SCREEN addition.
When you use the SUBMIT statement, use the Pattern function in the ABAP Editor to insert an appropriate
statement pattern for the program you want to call. It automatically supplies the names of the parameters
and selection options that are available on the standard selection screen.
For further information about working with variants and about other syntax variants of the WITH addition,
refer to the documentation for the SUBMIT statement.
SAP AG
TAW10
18-19
ABAP memory 2
ABAP memory 1
Program 1.2
Program 1.1
Program 2.2
Program 2.1
You can use SAP memory and ABAP memory to pass data between programs.
SAP memory is a user-specific memory area for storing field values. It is only of limited value for
passing data between internal sessions. Values in SAP memory are retained for the duration of the
user's terminal session. The memory can be used between sessions in the same terminal session. You
can use the contents of SAP memory as default values for screen fields. All external sessions can use
the SAP memory.
ABAP memory is also user-specific. There is a local ABAP memory for each external session. You
can use it to exchange any ABAP variables (fields, structures, internal tables, complex objects)
between the internal sessions in any one external session.
When the user exits an external session (/i in the command field), the corresponding ABAP memory
is automatically initialized or released.
SAP AG
TAW10
18-20
Internal session 1
ABAP memory
MY_ID
PROGRAM p1 ... .
DATA: p1_spfli TYPE spfli,
it_spfli TYPE STANDARD TABLE
OF spfli.
...
EXPORT
EXPORT
wa_fli FROM p1_spfli
it_spfli
TO MEMORY ID 'MY_ID'.
wa_fli
it_spfli
Internal session 2
MY_ID1
...
PROGRAM p2 ... .
DATA: p2_spfli TYPE spfli,
it_spfli TYPE STANDARD TABLE
OF spfli.
...
IMPORT
IMPORT
wa_fli TO p2_spfli
it_spfli
FROM MEMORY ID 'MY_ID'.
SAP AG 2002
The EXPORT ... TO MEMORY statement allows you to copy any number of ABAP data objects with
their current values to the ABAP memory (data cluster).
The ID ... addition enables you to identify different clusters (maximum of 60 characters).
If you use a new EXPORT TO MEMORY statement for an existing data cluster, the new one will overwrite
the old.
The IMPORT ... FROM MEMORY ID ... statement allows you to copy the data from the ABAP
memory into corresponding data objects of your ABAP program.
It is also possible to only import parts of data clusters using IMPORT.
The data objects that are to receive the data from the ABAP memory cluster must have the same types in
both the calling and the called programs.
To release a data cluster, use the FREE MEMORY ID ... statement.
Bear in mind that when you call programs using transaction codes, you can only use the ABAP memory to
pass data when inserting (CALL TRANSACTION).
SAP AG
TAW10
18-21
Program A
Airline
SET PARAMETER ID
'CON' FIELD sdyn_conn-connid.
LH
or
CALL TRANSACTION ... .
Connection 400
!
SET
SAP memory
CAR
CON
LH
400
Program B
Airline
LH
GET
Connection 400
or
GET PARAMETER ID
'CON' FIELD sdyn_conn-connid.
SAP AG 2002
You can define memory areas (parameters) in the SAP memory in various ways:
By creating input/output fields with reference to the ABAP Dictionary. These take the parameter name
of the data element to which they refer.
Alternatively, you can enter a name in the attributes of the input/output fields.
Here, you can also choose whether the entries from the field should be transferred to the parameter
(SET), or whether the input field should be filled with the value from the parameter (GET).
To find out about the names of the parameters assigned to input fields, display the field help for the
field (F1), then choose Technical info.
You can also fill the memory areas directly using the SET PARAMETER ID 'PAR_ID' FIELD
var. statement and read them using GET PARAMETER ID 'PAR_ID' FIELD var.
Finally, you can define parameters in the Object Navigator and let the user fill them with values.
SAP AG
TAW10
18-22
Program 2: Transaction
...
DATA:
bi_itab TYPE TABLE OF bdcdata,
bi_wa
TYPE bdcdata.
T_CODE
bi_itab
* fill bi_itab
...
* call other program
CALL TRANSACTION 'T_CODE'
USING bi_itab.
IF sy-subrc = 0.
...
ELSE.
...
1st screen
2nd screen
F15
SAPM t_name
...
LEAVE PROGRAM.
...
SAP AG 2002
The CALL TRANSACTION 'T_CODE' USING bi_itab statement allows you to insert the
transaction T_CODE, and the screens are processed according to the internal table bi_itab.
This internal table must be typed according to the structure bdcdata and filled appropriately.
The MODE addition allows you to specify whether the screen contents should all be displayed ('A' - the
default setting), only when an error occurs ('E'), or not at all ('N').
The MESSAGES INTO mess_itab addition is used to specify where the system messages sent during
the execution of the called transaction are written.
The internal table must be typed according to the structure bdcmsgcoll.
You can find out if the transaction was executed successfully from the system field sy-subrc.
This technique is useful if, for example:
You are processing in the foreground, but the input fields have not been filled using GET parameters
You want to process the transaction in the background. In this case, you normally have to pass function
codes as well.
This technique is also one of the possible ways of transferring data from non-SAP systems.
To do so the internal table in the bdcdata format must be filled completely.
SAP AG
TAW10
18-23
Field name
Length
Description
Note when
filling
program
dynpro
dynbegin
fnam
fval
40
132
132
Screen number
First record
Field name
Program name
Only in 1st
Only in 1st
record on screen record on screen
Field value
Casesensitive
SAP AG 2002
Each screen that is to be processed and filled automatically in the transaction must be identified by a
line, in which only the fields program, dynpro and dynbegin are filled.
After the record that identifies the screen, use a separate bdcdata record for each field you want to
fill. These records use the table fields fnam and fval. The following fields can be filled:
Input/output fields, with data
The command field (bdc_okcode), with function codes
The cursor position field (bdc_cursor), with field names.
You also use the CALL TRANSACTION technique to transfer data from external systems.
Further information on this topic is available in the course BC420 (Data Transfer) and in the online
documentation.
SAP AG
TAW10
18-24
dynpro
dynbegin
0100
SAPBC401_CALD_CREATE_CUSTOMER
fnam
fval
SCUSTOM-NAME <current_name>
SCUSTOM-CITY <current_city>
BDC_OKCODE
DATA:
bdcdata
wa_bdcdata TYPE bdcdata,
it_bdcdata LIKE TABLE OF wa_bdcdata.
* fill the bdcdata-table ...
CALL TRANSACTION 'BC401_CALD_CRE_CUST'
USING it_bdcdata
MODE 'N'.
IF sy-subrc <> 0.
MESSAGE ... WITH sy-subrc.
ENDIF.
SAVE
Save
ID for command
field
SAP AG 2002
This example refers to the transaction BC401_CALD_CTA_U. If you request the creation of a new
customer entry here, the transaction BC401_CALD_CRE_CUST is inserted. This transaction has not
implemented an import from the ABAP memory, and its input fields are not set as GET parameters. The
customer data is therefore passed using an internal table and the transaction processed in the background.
If the operation is successful, the new customer data record can be entered in the waiting list.
The relevant internal table in bdcdata format is shown above. current_name is the customer
name adopted from the input field at runtime, current_city is the city.
You address the command field using BDC_OKCODE. Here you enter the function code that is triggered by
the user choosing a function key, pushbutton, or menu entry during the dialog flow (or by entering a code
directly in the command field).
SAP AG
TAW10
18-25
SAP AG 2002
SAP AG
TAW10
18-26
Appendix
SAP AG 2001
SAP AG
TAW10
19-1
Program Types
Program
Program Types
Types
Data
Data Types,
Types, Data
Data Objects,
Objects, and
and Statements
Statements
Logical
Logical Databases
Databases
Preview
Preview
SAP AG 2001
SAP AG
TAW10
19-2
Include: <include_name>
( Program type: Include )
Program: <program_name>
REPORT <program_name>.
:
INCLUDE <include_name>.
ABAP statements
SAP AG 2001
SAP AG
TAW10
19-3
TOP Include
Create program
Repository Browser:
program
<name>
Create program
With TOP-Include
Program: <name>TOP
Program type: Include
Program: <name>
REPORT <name>.
TYPES:...
DATA: ...
INCLUDE <name>TOP.
SAP AG
TAW10
19-4
Goto
Utilities
Environment
System Help
Object Navigator
Workbench Edit
Goto
Extras
Environment
System Help
Object Navigator
Object name
BC402_FMDD_WAITLIST
Display
PBO modules
Global declarations
Function modules
>
BC402_FMDD_WAITLIST
<
<
<
<
<
>
Function modules
Fields
PBO modules
Screens
GUI title
Includes
LBC402_FMDD_WAITLISTO01
LBC402_FMDD_WAITLISTTOP
LBC402_FMDD_WAITLISTU01
LBC402_FMDD_WAITLISTU02
LBC402_FMDD_WAITLISTU03
LBC402_FMDD_WAITLISTU04
LBC402_FMDD_WAITLISTU05
LBC402_FMDD_WAITLISTU06
LBC402_FMDD_WAITLISTUXX
SAP AG 2001
When you work with function groups and modules, you can use the ABAP Workbench to arrange the
program source code in overview form and structure it with ease.
In the Navigation function, you always branch to the correct object, and Include programs are given
names and created. The respective call statements are automatically entered at the correct position.
The call statements must contain only the name convention for function groups: Y|Z<rem_name>.
The system then creates a program of F type, SAPLY|Z<rem_name>. This contains only INCLUDE
statements that were created automatically. The Include programs are automatically given the name
LY|Z<rem_name><abbrev><num>.
In addition, the system includes the Include program, LY|Z<rem_name>UXX. Here, there is a call for
an appropriate Include program, LY|Z<rem_name>U<num>, for each function module.
SAP AG
TAW10
19-5
Program
Program Types
Types
Data
Data Types,
Types, Data
Data Objects,
Objects, and
and Statements
Statements
Logical
Logical Databases
Databases
Preview
Preview
SAP AG 2001
SAP AG
TAW10
19-6
SAP AG 2001
SAP AG
TAW10
19-7
TYPE-POOL Z400.
TYPES: z400_name_type(25) TYPE C,
BEGIN OF z400_flightrec_type,
...
,
END OF z400_flightrec_type.
REPORT ... .
TYPE-POOLS z400.
DATA: name TYPE z400_name_type,
wa TYPE z400_flightrec_type.
... .
ABAP
SAP AG 2001
In addition to declaring a data type within an ABAP program, you can also declare data types in a type
group in the ABAP Dictionary.
The type group name in the ABAP Dictionary has a maximum of five characters. Type names within the
type group <typpool> must begin with <typpool> followed by an underscore.
The types in a type group must be declared in ABAP programs with the TYPE-POOLS command.
SAP AG
TAW10
19-8
Type Conversion
If two data types are not compatible, but a conversion rule exists, then the system
performs type conversions for value assignments, calculations, or comparisons.
The following graphics introduce the basic forms of conversion rules and give examples
of the most important cases. All the conversion rules can be found in the ABAP documentation
on the MOVE statement.
If no conversion rule is defined for a statement, the system's reaction depends upon
the particular program context:
In the case of statistical types, the system issues a syntax error.
Example:
DATA: date TYPE d VALUE '19991231', time TYPE t.
FIELD-SYMBOLS: <fs_date> TYPE d, <fs_time> TYPE t.
ASSIGN: date TO <fs_date>, time TO <fs_time>.
<fs_time> = <fs_date>.
In the case of dynamic types, the system issues a runtime error since the the field symbols are typed
only when the data objects are assigned at runtime.
Example (rest as above):
...
FIELD-SYMBOLS: <fs_date> TYPE ANY, <fs_time> TYPE ANY.
...
SAP AG
TAW10
19-9
Logical Expressions
* comparisons for all datatypes:
.. <dobj> {EQ|=} {<literal>|<dobj>}
.. <dobj> {NE|<>} {<literal>|<dobj>}
.. <dobj> {GT|>} {<literal>|<dobj>}
.. <dobj> {GE|>=} {<literal>|<dobj>}
.. <dobj> {LT|<} {<literal>|<dobj>}
.. <dobj> {LE|<=} {<literal>|<dobj>}
.. <dobj> BETWEEN {<lit>|<dobj>} AND
.. <dobj> IS INITIAL ..
.. "equal
.. "not equal
.. "greater than
.. "greater or equal
.. "less than
.. "less or equal
{<lit>|<dobj>} ..
SAP AG 2001
If you have a comparison of non-numeric data objects, these are interpreted differently, depending upon
type.
Date and time: interpreted as earlier or later; for example, 12/31/1999 < 01/01/2000
Other characters: lexographical interpretation according to character code; adapt length by filling in
blanks
References: comparison of address and data type, only identical can be interpreted suitably
For comparisons of strings and bits, more relational operators are available (see online documentation
for IF).
In the case of links and negations, the standard rules for logical expressions apply:
NOT is more powerful than AND, AND is more powerful than OR.
Example
NOT f1 = f2 OR f3 = f4 AND f5 = f6 therefore corresponds to
( NOT ( f1 = f2 ) ) OR ( f3 = f4 AND f5 = f6 ).
To have a better overview and for security reasons, place your partial expressions in brackets, even if it
is not absolutely necessary.
By setting up your expressions carefully, you can influence the runtime requirement in a positive way.
SAP AG
TAW10
19-10
CHECK
Loops:
DO WHILE
SELECT LOOP
Nextrun
EXIT
LEAVE
PROGRAM
LEAVE TO
TRANSACTION
Leaveloop
Display
list buffer;
Execute
event
blocks II
Events I:
LOAD-OF-PROGRAM.
START-OF-SELECTION.
GET <node> [LATE].
END-OF-SELECTION.
Display message
then
Program end
Events II:
INITIALIZATION.
AT SELECTION-SCREEN [OUTPUT].
TOP-OF-PAGE.
END-OF-PAGE.
AT LINE-SELECTION.
AT USER-COMMAND.
MESSAGE a..
End current
processing block
and proceed
with next
processing block
program end
and
delete all internal
modes
Modularization units
SAP AG 2001
ABAP event blocks or modularization units (subroutines, modules) are called processing blocks.
Using the LEAVE PROGRAM or LEAVE TO TRANSACTION tcode statements, you can terminate the
current program.
After a termination message, the system terminates not only the current program, but also the entire
program stack.
SAP AG
TAW10
19-11
Message class:
Attributes
Message
040
041
002
Messages
Message short text
The name of the airline &1 is &2
Airline &1 is not available
<message
number>
<message number>
SAP AG 2001
To trigger a message dialog in a program, enter the MESSAGE statement with the following additions:
ID '<message class>' for the message class
NUMBER '<number> for the message number
To display the message text for a MESSAGE statement in a program's source code, double-click the
message number to go to the associated message class texts.
Other syntax variants are available for the MESSAGE statement. For more information, refer to the
keyword documentation for the MESSAGE statement.
SAP AG
TAW10
19-12
Long text
Message
class:
Message
class
BC400
Number
Short text
000
<short text>
001
<short text>
: Message is self-explanatory
There is a long text
explaining the message
Self-explanatory
<short text>
Long text
Definition
SAP AG 2001
Diagnosis
<text>
System activities
<text>
Procedure
<text>
Procedure for system administrator
<text>
If a message short text contains all the information the user needs, the message is described as selfexplanatory.
Example: "The program has been saved."
Self-explanatory messages are flagged as such in the message class.
If you want to provide more detailed information for the user, you can do so by storing a long text with
the message. In the Message Maintenance screen, the Self-Explanatory flag indicates whether or not a
message is indeed self-explanatory. To display the long text, select the message line and choose Long
Text. The system then displays the maintenance formats. You can display the formatted text by choosing
Screen Output. You usually create the long text from a template, which contains the headings Diagnosis,
System Activities, Procedure, and Procedure for the System Administrator. The system does not display
the heading to the user if there is no text stored under it.
SAP AG
TAW10
19-13
Definition
&1
&2
&3
BC400
Message class:
Attributes
Message
039
040
041
&4
Messages
Message short text
The name of the airline &1 is &2
Airline &1 is not available
SAP AG 2001
You can include up to four placeholders in a message (&1, &2, &3 and &4). You can then assign current
parameters to them in the MESSAGE statement using the WITH addition. You can use literals, text
symbols, or variables. You must include a space between each one. The current parameters are assigned
to the placeholders &1, &2, &3, and &4 in order.
In the long text, the placeholders are given the names &V1&, &V2&, &V3&, and &V4& and replaced
at run time in order, according to the same logic. To insert a placeholder in the long text:
Place your cursor in the text where you want to insert the placeholder.
Choose Edit Command Insert command . The system displays a dialog box. In Symbols, enter
&V1& (or &Vi& i = 2, 3 or 4, as appropriate).
Choose Enter to confirm the dialog box.
SAP AG
TAW10
19-14
Double-click
No
Development class
In the Object Navigator:
ZBC400_12
Programs
...
Message classes
ZBC400_MC12
Create
ZBC400_12
...
Message class
...
Change
Display
SAP AG 2001
To create your own message class, give it a name in the customer namespace, that is, a name beginning
with Y, Z, or the namespace prefix.
You can create both the message class and the message itself using forward navigation from the
MESSAGE statement.
In the Object Navigator, you can create and edit a message class in any of the following ways:
From the context menu belonging to the root node in the object list of the respective development
class
From the context menu belonging to the Message class node in the object list of the appropriate
development class
From the Other object... icon
A dialog box containing a tab appears. In the Other tab, enter a message class, or a message with its
message class, and then display, create, or change it by choosing the appropriate icon.
SAP AG
TAW10
19-15
Colors/Icons/Symbols in Lists
Colors in Lists
Flight
from
to
AA 0017
LH 0400
LH 0402
NEW YORK
FRANKFURT
FRANKFURT
SAN FRANCISCO
NEW YORK
BERLIN
SAP AG 2001
You can set several list display attributes within a WRITE statement. One such attribute is color, which
can be adjusted using the formatting option COLOR <n>. You can choose from seven background
colors that are activated by either a numeric value or a symbolic name.
0 col_background Background
1 col_headingHeaders
2 col_normal List entries
3 col_total Totals
4 col_key Key columns
5 col_positivePositive threshold value
6 col_negative Negative threshold value
7 col_group Control levels
SAP provides guidelines for creating lists in color. Please consult transaction LIBS for examples.
With the help of one more parameter of the WRITE statement AS ICON , you can use icons in your
list. For this purpose, you must include the Include <LIST> statement in your program.
You can find an overview of all available icons in either the keyword documentation under WRITE, or
in the WRITE statement structure.
SAP AG
TAW10
19-16
Screen attributes
Screen number
Next screen
PBO
100
Screen attributes
100
100
PAI
Screen number
Next screen
200
PBO
200
200
200
PAI
0
SAP AG 2001
You can use this technique to program clusters of screens with complicated links without having to
continually return to the source code and call them using CALL SCREEN.
SAP AG
TAW10
19-17
Edit
Goto
Utilities
Environment
System Help
Attributes
Exception
NO_SEATS
OVERLOAD
DB_FAILURE
Active
BC402_FMDD_GET_FREE_SEATS
Import
Export
Changing
tables
Exceptions
Source code
Short text
Freight carrier
overbooked
no data
RAISE <exception>.
*** with default message:
MESSAGE <kind><num>(<id>)
RAISING <exception>.
SAP AG 2001
SAP AG
TAW10
19-18
Logical Databases
Program
Program Types
Types
Data
Data Types,
Types, Data
Data Objects,
Objects, and
and Statements
Statements
Logical
Logical Databases
Databases
Preview
Preview
SAP AG 2001
SAP AG
TAW10
19-19
SPFLI
SFLIGHT
SBOOK
SAP AG 2001
You can use easy-to-use read programs (logical databases) to read logically connected data. Each logical
database has a structure containing a hierarchy of those tables and views that are to be read.
You can attach exactly one logical database to each type 1 program. The logical database then supplies
your program with entries from tables and views. This means that you need to program the data
processing statements only.
SAP AG
TAW10
19-20
Logical Databases
You
You can attach
attach a logical
logical database
database to each type 1 program
program
using the
the program
program attributes.
attributes.
Special event
event blocks are also available for processing
processing
individual records.
SAP AG 2001
Each logical database is an encapsulated data collection program for frequent database access.
Database access has been optimized using Open SQL.
If you are working with a logical database, you do not need a selection screen for user entry, because it is
created automatically.
The system performs authorization checks according to the SAP authorization concept.
SAP AG
TAW10
19-21
Data from
the LDB
Program
NODES sflight.
SPFLI
GET sflight ...
SFLIGHT
SBOOK
SAP AG 2001
Logical databases read according to their structure, that is, from top to bottom. The depth of data read
depends on a program's GET statements. The deepest GET statement from the structural view of the
logical database determines the level.
SAP AG
TAW10
19-22
Program
NODES: SPFLI,
SFLIGHT.
Logical
database
START-OF-SELECTION.
GET spfli.
GET sflight.
SPFLI
SFLIGHT
ABAP
runtime
system
SBOOK
Basic list
END-OF-SELECTION.
SAP AG 2001
You can include a logical database in every executable program (type 1) using the program attributes.
Each node in the hierarchy of the logical database also provides you with a GET event block in addition
to the other event blocks (GET SPFLI, GET SFLIGHT, and GET SBOOK in the example in the
graphic).
You can program individual record processing using these GET event blocks.
At run time, the event blocks that create lists are processed in the following order:
START-OF-SELECTION.
GET SPFLI and GET SFLIGHT are called several times in nested SELECT logic according to the
structure of the logical database.
END-OF-SELECTION is called after all GET events, and immediately before the list is sent to the
presentation server
SAP AG
TAW10
19-23
REPORT bc400d_logical_database.
NODES: spfli, sflight.
START-OF-SELECTION.
WRITE: / 'START-OF-SELECTION'
color 3.
GET spfli
spfli FIELDS carrid connid.
GET
WRITE: / 'GET SPFLI' color 1,
spfli-carrid,
spfli-connid.
GET
GET sflight
sflight FIELDS fldate.
WRITE: / 'GET SFLIGHT' color 2,
sflight-fldate.
START-OF-SELECTION
GET SPFLI
DL 1699
GET SFLIGHT
25.08.1998
GET SFLIGHT
27.09.1998
DL 1984
GET SFLIGHT
25.08.1998
GET SFLIGHT
27.09.1998
GET SFLIGHT
29.09.1998
GET spfli
spfli
LATE.
GET
LATE.
WRITE :/ 'GET SPFLI LATE'.
END-OF-SELECTION
END-OF-SELECTION.
WRITE: 'END-OF-SELECTION'
color 3.
SAP AG 2001
At run time, the event blocks that create lists are processed in the following order:
START-OF-SELECTION.
GET spfli: The first data record from database table SPFLI that corresponds to the selection criteria is
placed in work area spfli and the event block is processed.
GET sflight: The first data record from SFLIGHT that corresponds to the selection criteria as well as
to the key of the current SPFLI record are placed in work area sflight and the event block is processed.
GET sflight: The next data record from database table SFLIGHT is placed into work area sflight and
the event block is processed again.
GET sflight: This is called again until no further corresponding data records are found.
GET spfli LATE is called before the next data record from SPFLI is placed into work area spfli.
GET spfli: The logical database places the next corresponding data record from SPFLI in work area
spfli.
END-OF-SELECTION is called immediately before the list is displayed.
SAP AG
TAW10
19-24
Summary
Attributes
Type
Application
Logical Database
F1S
SPFLI
SFLIGHT
SBOOK
SAP AG 2001
Logical databases are included in type 1 programs as program attributes. Only one logical database can
be used for each program.
You can supply a logical database with the information regarding which fields you need from the
database using the GET addition FIELDS. If the logical database supports this action, it will read from
the database only those fields you require.
If, for your list, you need database table data that is not supplied by your logical database, you can
program any additional database access needed using SELECT.
SAP AG
TAW10
19-25
Preview
Program
Program Types
Types
Data
Data Types,
Types, Data
Data Objects,
Objects, and
and Statements
Statements
Logical
Logical Databases
Databases
Preview
Preview
SAP AG 2001
SAP AG
TAW10
19-26
External
Server
Sequential
Files
SAP
Interfaces /
Checks
SAP AG 2001
When you transfer data from another SAP or external system to your own SAP system, it is important to
ensure data integrity.
Thus, it is necessary to subject this type of data transfer to the same checks as data transfer in dialog
mode.
Since dialog mode checks in transactions are comprehensive and, in part, done on a cross-application
basis, it is extremely difficult to program them yourself.
Therefore, it is much easier to use the online checks provided for SAP transactions because these SAP
transactions are used also for the data transfer.
The techniques used for external data transfer are called batch-input processes.
SAP offers standardized procedures for external data transfer for many areas within R/3. These
procedures use these programming techniques: batch input, call transaction, and direct input. The SAP
standard data transfer procedures are called using the Data Transfer Workbench (transaction SXDA).
If no SAP data transfer procedures are available, transfer can be programmed individually using batch
input or call transaction.
SAP AG
TAW10
19-27
CALL TRANSACTION:
Sequential
file
BDC
BDC table
table
DIRECT INPUT:
Sequential
file
BDC
BDC table
table
Queue file
SAP
transfer
program
CALL
TRANSACTION
Batch
Batch input
input function
function
Application
Application function
function
SAP
database
Application
Application function
function
SAP
database
SAP
database
SAP AG 2001
SAP AG
TAW10
19-28
Update
Dialog process
PAI
PBO
PAI
PBO
UPDATE
Request
PBO
INSERT
Request
PAI
DELETE
Request
Log
table
UPDATE req.
INSERT req.
DELETE req.
COMMIT WORK
Update process
UPDATE
INSERT
DELETE
Database process
SAP AG 2001
Another way of bundling database changes at the end of an SAP LUW is to use the update technique.
Here, you do not pass updates directly to the database, but enter them as update requests in a log table
instead.
Using the ABAP statement COMMIT WORK, you end SAP LUW in dialog mode. The SAP system then
triggers a special work process called an update work process that, based upon your log entries, executes
the actual changes to the database within a database transaction. The SAP LUW ends only when the
update process has finished.
The program part in the dialog and update process can run either synchronously or asynchronously.
The advantage of update in contrast to bundling using subroutines is that you can store the data for the
database change in the log table at any time and do not have to keep it in the program work area. Its
disadvantage lies in the effort required for additional logging.
Use asynchronous update when response times are important and the database updates are complicated
enough that they justify the extra work involved in using the log table.
Use synchronous update whenever you need the changed data immediately and when the database
updates are complicated enough to justify the extra work involved in using the log table.
SAP AG
TAW10
19-29