abap workbench - mod
TRANSCRIPT
-
7/30/2019 ABAP Workbench - Mod
1/178
INTRODUCTION TO ABAP
-
7/30/2019 ABAP Workbench - Mod
2/178
Who ? Why ?
Introductions
Your objectives
-
7/30/2019 ABAP Workbench - Mod
3/178
-
7/30/2019 ABAP Workbench - Mod
4/178
What is SAP?
SystemApplicationProducts in Data Processing
1972 Founded by 4 IBM employees in a small German Town
(Walldrof). SAP AG R/2 (Real Time / Two Tier)
1992 R/3 was introduced.
1995 SAP ranked fifth independent software vendors.
-
7/30/2019 ABAP Workbench - Mod
5/178
SAP Modules
FI
MM
PP
QA
PM
HR
SD
CO
AM
PS
OC
IS
R/3Client/Server
ABAP
Sales and
Distribution
Materials
Management
Production
Planning
Quality
Assurance
Financial
Accounting
Controlling
Fixed Assets
Accounting
Project
System
Office &
Communi-
cation
HumanResources
Plant
Maintenance
Industry
Solutions
-
7/30/2019 ABAP Workbench - Mod
6/178
Course Outline
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
-
7/30/2019 ABAP Workbench - Mod
7/178
System Architecture
Hardware
Database Engine
Interface
Application
MM, SD, FI,
CO, PA, PS etc.
Informix,Oracle,
SQL/Server etc.
IBM, HP,
SUN, HP etc.
-
7/30/2019 ABAP Workbench - Mod
8/178
System Architecture
DATABASE
SERVER
APPLICATIONSERVERS
PRESENTATION
SERVERS
DATA
BASE
DATA FLOW
-
7/30/2019 ABAP Workbench - Mod
9/178
Architecture of ABAP applications
Client/Server architecture
First level
Presentation level (SAP Gui). Contains the user interface whereby an end user can access anapplication, enter new data and receive the results of a work process.
Second level
Application level. ABAP program runs in this level, consists of both the applications provided bySAP and the ones you develop yourself. ABAP programs work with data called up from thedatabase level and store new data there as well.
Third level
Database level. Data in here is managed with the help of a relational database managementsystem (RDBMS). In addition to master data and transaction data, programs that describes the
R/3 System are stored and managed here.
-
7/30/2019 ABAP Workbench - Mod
10/178
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
-
7/30/2019 ABAP Workbench - Mod
11/178
A Powerful Tool
Advanced Business Application Programming
NB Before version 4.0 (1998), the official name was ABAP/4
The system is written in it
SAP can be shaped to the Clients particular needs
Adds value to the implementation ?
-
7/30/2019 ABAP Workbench - Mod
12/178
A Dangerous Weapon
Avoid changing the source code
SAP will not support a system that has been improperly changed.
Poor design = poor performance
Many projects get a reputation based on the performance of a smallnumber of ABAPs
Is your ABAP really necessary?
-
7/30/2019 ABAP Workbench - Mod
13/178
Reporting Alternatives
Performance - time to develop compared to time to run.
Standard SAP
Existing Reports
SAP (ABAP) Query
Report Writer
LIS
Extended SAP
Business Information Warehouse
Third Party - though ABAP code often needed for data
extraction
-
7/30/2019 ABAP Workbench - Mod
14/178
Data Loading Alternatives
Standard SAP
Data Transfer Workbench
Data reformatting and conversion ABAPs still need to be written
Extended SAP
Legacy System Migration Workbench (LSMW)
Data reformatting and conversion ABAPs are generated by the tools
provided
-
7/30/2019 ABAP Workbench - Mod
15/178
(AB)uses of ABAP
Paper Reporting
Interactive Reporting
Data Export
Data Import
Batch Input
Transaction Development
-
7/30/2019 ABAP Workbench - Mod
16/178
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
-
7/30/2019 ABAP Workbench - Mod
17/178
The Development Environment
Navigation
Eg on setting up a newserver
-
7/30/2019 ABAP Workbench - Mod
18/178
Logging on
The logon screen
To change password:
1. The system will prompt thechange password box atinitial logon screen (firsttime logging into thesystem)
2. Click on New passwordat the logon screen if youwish to change again
-
7/30/2019 ABAP Workbench - Mod
19/178
The Development Environment
SAP Easy Access Menu
-
7/30/2019 ABAP Workbench - Mod
20/178
The Development Environment
Favorite list and user menu
-
7/30/2019 ABAP Workbench - Mod
21/178
The Development Environment
Command field
SAP Easy Access &Favorite lists
-
7/30/2019 ABAP Workbench - Mod
22/178
The Development Environment
List of useful commands:
1. /n To cancel the current transaction
2. /nxxxx To call transaction (where xxxx is your t-code name)
directly from another transaction.
3. /o To open a new session.
4. /oxxxx To open a transaction in a new session (where xxxx is your
t-code name) directly from another transaction.
5. /nend To end the logon session with a confirmation dialog box.
6. /nex To end the logon session without a confirmation dialog box.
7. /i To delete the session.
-
7/30/2019 ABAP Workbench - Mod
23/178
The Development Environment
Display F1 help
-
7/30/2019 ABAP Workbench - Mod
24/178
The Development Environment
Display F4 help
-
7/30/2019 ABAP Workbench - Mod
25/178
The Development Environment
Where-use list
-
7/30/2019 ABAP Workbench - Mod
26/178
Exercise 01
Task 1:
Logon to the system. Try to change the password. Once in the
system, try to familiarize with the screen. Navigate to a transaction
code (e.g. SE11) and return to the SAP easy access menu.
Task 2:
What is the maximum number of parallel sessions that you can open
using System -> Create session?
Task 3:
What is the name of the function you reach if you choose Tools ->
Administration -> Monitor -> System Monitoring -> User Overview?
-
7/30/2019 ABAP Workbench - Mod
27/178
Exercise 01
Task 4:
Familiarize with F1 and F4 help uses and do a where-used list on a
table via SE11. Sample of tables that can be used (e.g. MARA,
MARC)
Task 5:
Add a new transaction to the SAP easy access menu into the
favorites. Any transaction codes like (SM04, SE11, SE80) could be
added. Delete it once this is added.
-
7/30/2019 ABAP Workbench - Mod
28/178
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
-
7/30/2019 ABAP Workbench - Mod
29/178
Packages and transports
ABAPs are examples ofDevelopment Objects. Otherexamples are:
Table Definitions
Screens
Development Objects are organized into Development
Classes.
This enables objects to be assigned to Transportsfor
transport to other systems.
Lo cal Objectsare not transportable, but can be reassigned to
development classes
-
7/30/2019 ABAP Workbench - Mod
30/178
Packages and transports
Ver 4.6 Tools > ABAP Workbench > Overview > Object Navigator -
this is transaction SE80
Note that in earlier releases the menu path was different, but the
transaction was the same.You are then faced with a choice of view options, the most useful
are:
Development Class
Local Objects - defaults to objects local to your ID
Program
Press display to see the list of components
-
7/30/2019 ABAP Workbench - Mod
31/178
Creating package
A package can be created via SE80. When creating, it will prompt to enter
description (meaningful names) and assigning a transport number to it.
-
7/30/2019 ABAP Workbench - Mod
32/178
Creating transport
A transport can be created via transaction SE10 / SE01.
-
7/30/2019 ABAP Workbench - Mod
33/178
Transport Request types
Workbench Request
Request that involves changes to cross-client Customizing and
Repository Objects. The objects are independent of the client. Therefore
the requests are used for transferring and transporting changed
Repository objects and changed system settings from cross-client
tables.
Customizing Request
Request that involves changes recorded to client-specific Customizing
objects .These client specific requests are used for copying and
transporting changed system settings from client-specific tables.
-
7/30/2019 ABAP Workbench - Mod
34/178
Releasing transport
To release a transport, click on the truck button.
Note: Do NOT click on this unless instructed to doso
Note: If accidentally created a TR, click on the
trash button to delete the transport.
CO S O
-
7/30/2019 ABAP Workbench - Mod
35/178
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
P O tli
-
7/30/2019 ABAP Workbench - Mod
36/178
Program Outline
A program does something - divided up as follows:
INPUT (from the screen, the system etc)
PROCESS (calculate, manipulate)
OUTPUT (to the screen, to the system etc)
PROCESSINPUT OUTPUT
Program Str ct re I
-
7/30/2019 ABAP Workbench - Mod
37/178
Program Structure I
Typical Report :
REPORT ......
* DECLARATION SECTION
TYPES: ......
DATA: ......
* STATEMENT SECTION
SELECT BUKRS BUTXT FROM T001
........
-
7/30/2019 ABAP Workbench - Mod
38/178
Lets write an ABAP
From the Object Browser (SE80)
Choose the Development Class or develop as a Loc al Object .
If this is the first program in this category, then double click on
Development class object type, then the Programtab.
If programs already exist in this category, choose the Programfolderand Right Mouse Click - Create
Disable the option With Top Includ e- otherwise you will be creating
the wrong kind of ABAP.
Names - an ABAP name can be up to 30 characters long
To keep SAP and client-written ABAPs separate, all client-written
ABAPs should begin with Y or Z
C ti
-
7/30/2019 ABAP Workbench - Mod
39/178
Creating new program
To create a new ABAP program,we can do it via transaction
SE38 (ABAP editor)
SE80 (Object Navigator)
Enter program name
C ti k
-
7/30/2019 ABAP Workbench - Mod
40/178
Creating new program access key
To be able to create ABAP programs, you will need to be givenan access key. Normally, you request this from the Basis team.
The developer access key is
20 characters in length.
You only need to enter this
key ONCE.
C ti
-
7/30/2019 ABAP Workbench - Mod
41/178
Creating new program
Description
Type
Executable program
Include program
Module pool
Function group
etc.
Th D l t E i t
-
7/30/2019 ABAP Workbench - Mod
42/178
The Development Environment
Right Mouse Click on a folder or object within a folder.
This activates a Context Menu - different options
depending on what the context is - folder or type of
object.
In SE80
C ti t ti d
-
7/30/2019 ABAP Workbench - Mod
43/178
Creating transaction code
Going into the editor
-
7/30/2019 ABAP Workbench - Mod
44/178
Going into the editor
Save/activate(Ctrl-F3)
Save (Ctrl-S)
Syntax check(Ctrl-F2)
Display/Changemode(Ctrl-F1)
Execute (F8) Display objectlist
Exercise 02
-
7/30/2019 ABAP Workbench - Mod
45/178
Exercise 02
Task 1:
Create an ABAP program via SE38 or SE80 which will be called
Zuu_exNN_
uu is your ABAPER number
NN refers to the exercise number
Please stick to these rules
FOR THIS COURSE ONLY - ALL ABAPS SHOULD BE LOCAL PRIVATE
OBJECTS - NO TRANSPORT
Task 2:
Write a simple program (eg. Write: / Hello World. ). Perform syntax check,
save, activation and execute the program. Get yourself familiar with the
shortcut keys and the screen.
Exercise 02
-
7/30/2019 ABAP Workbench - Mod
46/178
Exercise 02
Task 3:
Copy program Z00_TEST_TCODE, create a transaction code for the
program. Name your transaction Zuu_NN_tcode
uu is your ABAPER number
NN refers to the exercise number
Task 4:
Add the newly created transaction code to the favourites in the SAPeasy access menu.
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
47/178
COURSE OUTLINE
Client/Server Architecture
Uses of ABAP
The Development Environment
Packages and Transport request
ABAP program structure
Debugging
PROGRAM DEBUGGING
-
7/30/2019 ABAP Workbench - Mod
48/178
PROGRAM DEBUGGING
A powerful tool to show what a program is doing
Enables us to walk through code step-by-step
Enables us to check values of certain fields at each step
Debugging of standard SAP is also possible The downside is the impact it has on response
Starting
-
7/30/2019 ABAP Workbench - Mod
49/178
Starting
You have no idea where the error is:
Switch on Debugger in the Editor initial screen via Program =>
Execute => Debuggin g
Executethe program
You may find yourself debugging SAP standard code eg
selection-screen processing.
You have an idea where the program is starting to go wrong
Set a Break Point -the program will process up to that point then
stop in the debugger.
Break Points
-
7/30/2019 ABAP Workbench - Mod
50/178
Break Points
BREAK POINTS are points at which we want to stop the
program to start debugging. There are 2 types:
DYNAMIC
These are session specific - you loose them when you sign
off
Set on Active programs via the icon
Can be cleared via the menu or within the debugger
STATIC.
Set directly into code via the Editor
User-independent - visible in program code
MUST BE REMOVED FOLLOWING TESTING
Screen Display I
-
7/30/2019 ABAP Workbench - Mod
51/178
Screen Display I
7 Different Views - same basic structure
Fields(default) - Displays a fields contents and technical
characteristics
Table- Displays the contents of an internal table
Breakpoints- Gives a scrollable display of up to 30 breakpoints
defined in the program
Watchpoints- Displays up to 5 watchpoints
Call Stack- Displays an active event chain up to the currentbreakpoint
Overview- Displays the structure of the program being debugged
Sett ings-
Screen Display II
-
7/30/2019 ABAP Workbench - Mod
52/178
Screen Display II
There are a number of ways of stepping through theprogram code using the debugger:
SINGLE STEP- executes a program statement by
statement
EXECUTE(subroutines treated as a single step)
CONTINUE- up to the next BREAK or WATCH POINT
RETURN- to the calling program. Used from within a
subroutine call
Field contents
-
7/30/2019 ABAP Workbench - Mod
53/178
Field contents
To display the contents of critical fields used in the program
Use Fieldsview
Double Click on the field name to bring it into the display
Click on to display Hexadecimal value
Click on to replace the value - this can be used to force the program
through pathways that it is difficult to find data for.
Watchpoints
-
7/30/2019 ABAP Workbench - Mod
54/178
Watchpoints
Set a WATCH POINT to check when a field contents changes
Conditional WATCH POINT - e.g. stop execution when the document
number is 4900012345
Execute by choosing CONTINUE - program will stop when the
chosen field contents change or hit a certain value
Debugging 1
-
7/30/2019 ABAP Workbench - Mod
55/178
Debugging 1
An important tool for ABAP programmers. This can be done in various
ways.
1. Click on Stop icon.
Debugging 2
-
7/30/2019 ABAP Workbench - Mod
56/178
Debugging 2
2. Using keyword break-point or break
Debugging 3
-
7/30/2019 ABAP Workbench - Mod
57/178
Debugging 3
3. Enter /h in the command field in the standard toolbar and press enter.
Help
-
7/30/2019 ABAP Workbench - Mod
58/178
Help
SAP provide 2 forms of help:
CD ROM / Library Help
HELP
then type in the keyword F1 on the key word
On the web:
https://www.sdn.sap.com/irj/sdn
https://websmp206.sap-ag.de/
COURSE OUTLINE
https://www.sdn.sap.com/irj/sdnhttps://websmp206.sap-ag.de/https://websmp206.sap-ag.de/https://websmp206.sap-ag.de/https://websmp206.sap-ag.de/https://www.sdn.sap.com/irj/sdn -
7/30/2019 ABAP Workbench - Mod
59/178
COURSE OUTLINE
ABAP syntax
Report specific selection
Data: Data Types / Message Types
Data: Tables
Data Access: The SELECT statement
Internal tables
ABAP Syntax I
-
7/30/2019 ABAP Workbench - Mod
60/178
ABAP Syntax I
Not unlike other major programming languages (e.g. COBOL)
Similar commands
WRITE
PERFORM
MOVE
Similar structures
IF/ELSE
DO/WHILE
CASE etc.
ABAP Syntax II
-
7/30/2019 ABAP Workbench - Mod
61/178
ABAP Syntax II
A program is made up of statements which must end with a .
DATA MY_FIELD(1) TYPE C.
MOVE MY_FIELD TO YOUR_FIELD.
YOUR_FIELD = MY_FIELD.
The words in a statement must be separated by at least 1 space
Statements can be indented for easy reading
Make use of the Pretty Printer push-button to auto-indent your codes.
Statements can spread over several lines The first word in a statement is often a key word
ABAP Syntax III- Chaining
-
7/30/2019 ABAP Workbench - Mod
62/178
ABAP Syntax III Chaining
Where several statements use the same key word, they can bechained (via a colon :) - the statements being separated by
commas.
WRITE My name is.
WRITE first_name.
WRITE family_name.
Equivalent to:
WRITE: My name is,
first_name,
family_name.
System Fields I
-
7/30/2019 ABAP Workbench - Mod
63/178
System Fields I
Automatically available to you
SY-DATUM - Date
SY-UZEIT - Time
SY-UNAME - Your Logon ID
SY-REPID - The ABAP being run
SY-SUBRC - Return Code (0 = Success)
Format color
-
7/30/2019 ABAP Workbench - Mod
64/178
Format color
In a list, we can design the screen by adding colors. Below are the
attributes that we can add.
Exercise 03
-
7/30/2019 ABAP Workbench - Mod
65/178
Exercise 03
Task 1:
Create an ABAP program which will be called Zuu_exNN_
Task 2:
Display your Logon ID, Date and Time
Write Statement II
-
7/30/2019 ABAP Workbench - Mod
66/178
Write Statement II
WRITE:/p(w) Text.
Text - Better to use numbered texts (see later)
/ - New Line (or use syntax NEW-LINE)
p - Position on the Screen (w) - Field Width
Example:
WRITE:/2(3) HELLO. => HEL
Other examples in HELP WRITE
Exercise 03
-
7/30/2019 ABAP Workbench - Mod
67/178
Exercise 03
COPY Exercise 2
Line up the columns of data
Control Statements
-
7/30/2019 ABAP Workbench - Mod
68/178
Control Statements
LOGIC FLOW
IF ... ENDIF.
ON CHANGE OF ... END ON.
CASE ... ENDCASE.
LOOPS
DO ENDDO.
WHILE ENDWHILE.
OTHERS
CHECK
CONTINUE
EXIT
The IF Statement
-
7/30/2019 ABAP Workbench - Mod
69/178
The basic syntax is:
IF .
.... Processing done when true
ELSE. Optional
.... Processing done when false
ENDIF.
Conditionals - the IF statement
-
7/30/2019 ABAP Workbench - Mod
70/178
Conditionals the IF statement
IF NE .
IF AND .
IF OR .
IF NOT ( ).
IF .
...
ELSEIF .
...
IF Operations
-
7/30/2019 ABAP Workbench - Mod
71/178
IF Operations
These operations can be used within IF clauses to comparecertain values:
Relational Operators (Letters or Symbols)
EQ = NE > GE >= =>
LT < LE
-
7/30/2019 ABAP Workbench - Mod
72/178
String Comparisons
As well as comparing values, we can also use the IFstatement to check character strings against certain
criteria using the following:
CO CONTAINS ONLY
CA CONTAINS ANY
CS CONTAINS STRING
CP CONTAINS PATTERN
THECASESTATEMENT
-
7/30/2019 ABAP Workbench - Mod
73/178
CASE .
WHEN
...
WHEN
...
WHEN OTHERS - CATCH ALL
...
ENDCASE.
Do, While
-
7/30/2019 ABAP Workbench - Mod
74/178
,
DO TIMES . can be a constant or
.... field.
ENDDO.
DO. Must have an EXIT inside.
....
ENDDO.
WHILE .
....
ENDWHILE.
The EXIT statement
-
7/30/2019 ABAP Workbench - Mod
75/178
TERMINATES PROCESSING OF CURRENT LOOP OUTSIDE A LOOP - TERMINATES THE ABAP
Used to prevent program behaving unpredictably or crashing
under certain conditions
Example:
IF .
- processing, e.g. error message
EXIT.
ENDIF.
The CHECKStatement
-
7/30/2019 ABAP Workbench - Mod
76/178
Check a condition is satisfied before continuing processing
Syntax:
CHECK .
CHECK: ,
. AND implied
CHECK: OR .
IF THE CHECK SUCCEEDS:
CONTINUE PROCESSING
IF THE CHECK FA ILS:
SUBSEQUENT STATEMENTS IN PROCESSING BLOCK NOT
EXECUTED
The CHECKStatement
-
7/30/2019 ABAP Workbench - Mod
77/178
WHILE COUNTER LT 100.
statements
CHECK Entry NE SPACE.
statements
ENDWHILE.
CHECK within loop
FALSE
TRUE
TRUE
TOP-OF-PAGE.
CHECK SY-PAGNO GT 1.
statements
CHECK outside loop
FALSE
CONTINUE
-
7/30/2019 ABAP Workbench - Mod
78/178
This is a version of CHECK that has no logical expression
It is used to move on to the next iteration within the loop without
having to process the rest of the code in the loop
In older ABAPs the same function was achieved by:
CHECK 0 = 1. Always false
Comments
-
7/30/2019 ABAP Workbench - Mod
79/178
* - Marks a complete line as a comment
- Marks the remainder of a line as a comment (USE THEM!)
You can comment / uncomment blocks of code:
Select > Block/Buffer > Insert or Delete Comment
PATTERN - useful for code template generation
Pattern XANSA is a sample template for the start of the ABAP
Write Statement I
-
7/30/2019 ABAP Workbench - Mod
80/178
Displays data on the screen which can be printed out.
Basic Syntax:
WRITE .
Fields are automatically separated by 1 space
An output list will be wrapped around automatically
Check and Save
-
7/30/2019 ABAP Workbench - Mod
81/178
Do this as you go.
The syntax checker stops at the first error.
Remember the Scales of Justice.
Activation
-
7/30/2019 ABAP Workbench - Mod
82/178
For ABAPs this is new in version 4.6
When code is changed in an ABAP it is set Inactive
To Activate an ABAP press
Note: You can activate an ABAP with syntax errors, but it is not
advised. You can only release and transport an active ABAP
Other users in the system can only access the active version of your
ABAP -ABAPs are client independent.
Activate Deactivate
-
7/30/2019 ABAP Workbench - Mod
83/178
Copy an ABAP - The Active source goes to an Inactive target
Rename - does not change the status
Save - makes the program Inactive
Activate - also saves
Breakpoints - can only be set on an Active program
You can toggle between Active and Inactive versions
In Active mode, you can delete the Inactive Version. Utilities >
Versions > Return to Active Version
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
84/178
ABAP syntax
Report specific selection
Data: Data Types / Message
Types
Data: Tables
Data Access: The SELECT
statement
Internal tables
Parameters
-
7/30/2019 ABAP Workbench - Mod
85/178
Defines fields to be filled on the Selection Screen
Names must have a maximum of 8 characters
Example:
PARAMETERS: pa_name(8) TYPE C.
DEFAULT - Value preset
OBLIGATORY - Must be entered
Parameters
-
7/30/2019 ABAP Workbench - Mod
86/178
PARAMETERS are one way of supplying values to a program at run
time
PARAMETERS: pa_plant TYPE mard-werks
DEFAULT READ OBLIGATORY.
SELECT werks lgort labst
INTO stockstr
FROM MARD
WHERE werks = pa_plant....
ENDSELECT.
REPORT SPECIFIC SELECTION
-
7/30/2019 ABAP Workbench - Mod
87/178
To cause a selection range to appear on the SelectionScreen:
SELECT-OPTIONS: FOR .
This is a special kind of internal table containing 4 fields:-SIGN I(nclusive) E(xclusive)-OPTION Value (EQ, BT etc)-LOW Start of the range
-HIGH End of the range
SELECT-OPTIONS
-
7/30/2019 ABAP Workbench - Mod
88/178
SELECT-OPTIONS FOR .
DATA: WA_COUNTRY TYPE Z9A01-COUNTRY.
SELECT OPTIONS:
SO_CNTRY FOR WA_COUNTRY
DEFAULT GB TO US.
Sign Option Low High
I BT GB USScreen:
S_CNTRY GB US
Internal table
VALUE SETS
-
7/30/2019 ABAP Workbench - Mod
89/178
Screen:
C_CNTRY
(Press on )
Extended selections for COUNTRY:
Single Value Selections:
BE
FR
Ranges:
GB US
Sign Option Low High
I EQ BE
I EQ FR
I BT GB US
Internal table SO_CNTRY
VALUE SETS ALLOW FOR MULTIPLE SELECTIONS
ORIMPLIED
...
REPORT SPECIFIC SELECTION
-
7/30/2019 ABAP Workbench - Mod
90/178
Using these to select data:
SELECT
INTO (, , )
FROM WHERE IN .
If a SELECT-OPTIONS is left empty on the selection screen, the ABAPwill select all data.
Select-options
-
7/30/2019 ABAP Workbench - Mod
91/178
In select options, there are a few options that is available
The POWER and the GLORY
-
7/30/2019 ABAP Workbench - Mod
92/178
POWER
Small amount of ABAP coding necessary Define SELECT-OPTIONS
Code the IN
Add in Select ion Texts
GLORY
You have provided a very flexible selection tool to the user
PARAMETERS vs SELECT-OPTIONS
-
7/30/2019 ABAP Workbench - Mod
93/178
PARAMETERS
PO_PARM TYPE
Support only a single value
SELECT-OPTIONS
SO_OPT FOR
Allow for flexible data selection /exclusion
Both follow the rules:
Maximum of 8 characters as a name Screen Description via Selectio n Texts
Initial value set by DEFAULT option
Exercise 04
-
7/30/2019 ABAP Workbench - Mod
94/178
Task 1: An ABAP Calculator
Define 3 PARAMETERS
2 input integer numbers
1 input operand ( + , - , * , / )
Output the result to 2 decimal places
Allow for invalid operators and division by zero
This can be achieved using ifelse..endif, caseendcase. Tryusing both methods
Exercise 05
-
7/30/2019 ABAP Workbench - Mod
95/178
Task 1:
Write an ABAP program to display contents of SFLIGHT table using a
parameter selection. The program will prompt the user to enter (CARRID)
carriage ID as the parameter selection criteria. Display all flights with the
following information: SFLIGHT-CARRID
SFLIGHT-CONNID
SFLIGHT-FLDATE
SFLIGHT-PLANETYPE
SFLIGHT-SEATSMAX
SFLIGHT-SEATSOCC
Exercise 06
-
7/30/2019 ABAP Workbench - Mod
96/178
Task 1:
Write an ABAP making use of the select-options selection. Distinguishthe difference between no intervals and no-extensions usage.
Task 2: Write an ABAP program to display contents of SFLIGHT table using a
select-options selection. The program will prompt the user to enter a
range of (CARRID) carriage ID as the selection criteria. Display all flightswith the following information: SFLIGHT-CARRID
SFLIGHT-CONNID
SFLIGHT-FLDATE
SFLIGHT-PLANETYPE
SFLIGHT-SEATSMAX SFLIGHT-SEATSOCC
Notice the difference using select-options
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
97/178
ABAP syntax
Report specific selection
Data: Data Types / Message
Types
Data: Tables
Data Access: The SELECT
statement
Internal tables
Declarations - Data
-
7/30/2019 ABAP Workbench - Mod
98/178
Definition of variables (fields) used in the program
You can either:
Define it based on an SAP Dictionary Type. This makes it have
the same characteristics as an existing SAP field.
Define it based on a Standard Data Type
Based on an SAP Dictionary Type -Syntax
DATA: TYPE .
Declarations- Data
-
7/30/2019 ABAP Workbench - Mod
99/178
Based on a Standard Data Type
DATA: (l) TYPE t.
l = length in bytes
t = data type. Possibilities are:
C - Character
D - Date (YYYYMMDD)
P - Packed (2l - 1 digits, decimals)
I - Integer
N - Numeric text (1 byte/digit)
Declarations - Data and numbers
-
7/30/2019 ABAP Workbench - Mod
100/178
Use Type P for accuracy (decimal places)
Use Type I for speed (counters)
Use Type N for Input/Output only
Declarations - Data field names
-
7/30/2019 ABAP Workbench - Mod
101/178
Local to the program
Try to select meaningful field names
Avoid:
dashes spaces
Declarations - Data values
-
7/30/2019 ABAP Workbench - Mod
102/178
VALUE x - preassigns value x to a field
Example (fixed point):
DATA: TEMP_FIELD(3) TYPE P
DECIMALS 2 VALUE 123.45.
Declarations - Constants
-
7/30/2019 ABAP Workbench - Mod
103/178
DATA fields may be changed by operations within the ABAP
CONSTANT fields cannot be changed within the ABAP
Example:
CONSTANTS: PI(3) TYPE P DECIMALS 4 VALUE 3.1428.
PI = 3.9999. - syntax error
Partial Fields
-
7/30/2019 ABAP Workbench - Mod
104/178
For types C,N,D it is possible to refer to part of a field:
+O(L)
O is the offset (zero is the first position)
L is the length
Example:
TEMP_NAME = JOHN ARMYTAGE
TEMP_NAME+5(4) contains ARMY
Under certain conditions O and L can be variables
Numbered Texts
-
7/30/2019 ABAP Workbench - Mod
105/178
WRITE: TEXT-nnn will display the contents of numbered text nnn
(nnn is a 3 character identifier)
Maintained through Text Elements or Double Click on the TEXT in
the ABAP
TEXTS are language dependent
Message types
-
7/30/2019 ABAP Workbench - Mod
106/178
Type Description Behavior Appearance
I Information Program continues after
interruption
Model dialog box
S Success Program continues w/o
interruption
Status bar
W Warning Context dependent Status bar or dialog
box
E Error Context dependent Status bar or dialogbox
A Termination Program cancels Model dialog box
x Short dump Runtime error triggered Short dump
Message tnnn(message class) with v1 v2.
Exercise 07
-
7/30/2019 ABAP Workbench - Mod
107/178
Task 1:
Copy program from exercise 5. Add additional logic to check when
the user enters invalid data. If the input is invalid, prompt an error
message. Else, the program should have a success message
displayed.
Test the other message types namely ( W, S, E, A, and I) to see
how the program handles it.
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
108/178
ABAP syntax
Report specific selection
Data: Data Types / Message
Types
Data: Tables
Data Access: The SELECT
statement
Internal tables
Data Access I - Tables
-
7/30/2019 ABAP Workbench - Mod
109/178
Data is stored in SAP as tables
What do they look like?
Help then Table/Structure/View
We may need to reference table fields from within our ABAP e.g. MARD-MATNR = Material Number
Note the dash !
TABLE SFLIGHT
-
7/30/2019 ABAP Workbench - Mod
110/178
Marked fields form the table key
Fields have a name, data type, length and description (these are all
set up in Data Dictionary)
Will be used to introduce the next set of concepts
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
111/178
ABAP syntax
Report specific selection
Data: Data Types / Message
Types
Data: Tables
Data Access: The SELECT
statement
Internal tables
Accessing Data
-
7/30/2019 ABAP Workbench - Mod
112/178
DATABASE
(where the data sits)
APPLICATION
SERVER
(where the ABAP
runs)
SELECTED DATA
The Select Statement
-
7/30/2019 ABAP Workbench - Mod
113/178
Basic Syntax
SELECT something - a list of table fields
INTO somewhere - a target area in the program
FROM a table
WHERE selection conditions
The SELECT statement does allow you to retrieve data from more
than 1 table, but this is beyond the scope of this course.
Optimising SELECT
-
7/30/2019 ABAP Workbench - Mod
114/178
Optimising the design of this process is vital to ABAP Design
This section will focus on 2 areas:
SELECTing from a single table
Multiple SELECTs
In practice, Basis monitoring is needed to determine if the table
needs:
Buffering - most suitable for small, config type tables not often updated.
Indexing- most suitable for large data tables frequently accessed via
non key fields.
SELECT from a single table
-
7/30/2019 ABAP Workbench - Mod
115/178
Small Buffered Tables
Consider reading the table once into an internal table (possibly sorting
it)
Large Tables
Indexes to improve selection on non key fields (e.g. Material Number in
table MSEG)
New database techniques to extract summarised data from the table on
the database
Any Table
Only SELECT the fields you need
Select Endselect
-
7/30/2019 ABAP Workbench - Mod
116/178
SELECT
INTO
FROM
WHERE .
.....
ENDSELECT.
Each selected record will be made available in turn within the
SELECT ... ENDSELECT
SY-SUBRC will not be zero if no data is selected
SY-DBCNT will show the number of successful SELECTs
SELECT SINGLE
-
7/30/2019 ABAP Workbench - Mod
117/178
Retrieve a single record from an external table
Full Key must be specified (apart from the client)
SY-SUBRC must be checked to determine if the access is
successful (0 -> success)
No ENDSELECT needed - the read is either a success or it is not.
SELECT INTO TABLE
-
7/30/2019 ABAP Workbench - Mod
118/178
One Step Build of an Internal Table
No ENDSELECT needed
Avoid the use of INTO CORRESPONDING FIELDS OF - this
causes each entry in the database table to be checked in turn
MULTIPLE SELECTs
-
7/30/2019 ABAP Workbench - Mod
119/178
Many ABAPs need to SELECT data from several tables - there are
several ways of doing this.
Nested SELECTs
SELECT INTO & SELECT ... FOR ALL ENTRIES IN
Views
Logical Databases
In this situation a poorly designed method can cause severe
performance problems
NESTED SELECTs
-
7/30/2019 ABAP Workbench - Mod
120/178
SELECT FROM KNA1.....
ENDSELECT.
SELECT FROM KNB1
WHERE KUNNR = KNA1-KUNNR.....
ENDSELECT.
SELECT FROM BSIDWHERE KUNNR = KNA1-KUNNR
AND BUKRS = KNB1-BUKRS.
....
ENDSELECT.
SELECT INTO TABLE I
-
7/30/2019 ABAP Workbench - Mod
121/178
SELECT ... FROM KNA1 INTO TABLE CUSTABA.
SELECT ... FROM KNB1 INTO TABLE CUSTABB
FOR ALL ENTRIES IN CUSTABA
WHERE KUNNR = CUSTABA-CUSTNO.
SELECT ... FROM BSID INTO TABLE DOCTAB
FOR ALL ENTRIES IN CUSTABB
WHERE BUKRS = CUSTABB-COCODE
AND KUNNR = CUSTABB-CUSTNO.
Selecting into a table will NOT require ENDSELECTs
SELECT INTO TABLE II
-
7/30/2019 ABAP Workbench - Mod
122/178
Use nested LOOPs to report by
LOOP AT CUSTABA.
....
ENDLOOP.
LOOP AT CUSTABB
WHERE CUSTNO = CUSTABA-CUSTNO.
....
ENDLOOP.
LOOP AT DOCTAB
WHERE COCODE = CUSTABB-COCODE.
.....
ENDLOOP.
Defining a Target Area I
-
7/30/2019 ABAP Workbench - Mod
123/178
DATA: plant TYPE mard-werks,
store TYPE mard-lgort,
stock TYPE mard-labst.
* Note where the commas, spaces and brackets are
SELECT werks lgort labst
INTO (plant, store, stock)
FROM mard WHERE ...
...
ENDSELECT.
Defining a Target Area II - Structures
-
7/30/2019 ABAP Workbench - Mod
124/178
DATA: BEGIN OF custstr,
name TYPE z9a01-name,
city TYPE z9a01-city,
country TYPE z9a01-country,END OF custstr.
NAME CITY COUNTRY
Filling the Structure
-
7/30/2019 ABAP Workbench - Mod
125/178
FIELD BY FIELD:
CUSTSTR-NAME = Z9A01-NAME.
... (etc)
CODING SHORTCUT:
MOVE-CORRESPONDING Z9A01 TO CUSTSTR .
Using SELECT
Select Intro (Structure)
-
7/30/2019 ABAP Workbench - Mod
126/178
DATA: BEGIN OF stockstr,
plant TYPE mard-werks,
store TYPE mard-lgort,
stock TYPE mard-labst,END OF stockstr.
SELECT werks lgort labst
INTO stockstr FROM MARD WHERE ....
...ENDSELECT.
Authorization check
-
7/30/2019 ABAP Workbench - Mod
127/178
Fields: CARRID
ACTVT
CARRID =
ACTVT = 02
CARRID =
ACTVT = 03
Authorization object S_CARRID
Change Display
E.g. To display all CARRID, you can include *
To create authorization object: SU21/SE80
Exercise 08
-
7/30/2019 ABAP Workbench - Mod
128/178
Task 1:
Create a program to show how a select.endselect works. Retrieve
the following fields (CARRID, CONNID, FLDATE, PLANETYPE,
SEATSMAX, SEATSOCC) using the following conditions:
CARRID = P_CARRID
Where P_CARRID is the parameter from the selection screen.
Display the records in a list format. If there are no records found,
inform the user that No records have been selected.
Exercise 09
-
7/30/2019 ABAP Workbench - Mod
129/178
Task 1:
Create a program to show how a select single works. Retrieve the following
fields (CARRID, CONNID, FLDATE, PLANETYPE, SEATSMAX,
SEATSOCC) using the following conditions:
CARRID = AA
CONNID = 0017
FLDATE = 20070930
Display the records in a list format. If there are no records found, inform the
user that No records have been selected.
Try to store them in both variable and structure format.
Exercise 10
-
7/30/2019 ABAP Workbench - Mod
130/178
Task 1:
Create a program to show how a selectinto table works. Retrieve
the following fields (CARRID, CONNID, FLDATE, PLANETYPE,
SEATSMAX, SEATSOCC) using the following conditions:
CARRID = P_CARRID
Where P_CARRID is the parameter from the selection screen.
Display the records in a list format. If there are no records found,
inform the user that No records found.
Exercise 11
-
7/30/2019 ABAP Workbench - Mod
131/178
Task 1:
Create a program with parameter CARRID.
Check whether the user has authorization for the airline AA. Use
authorization object S_CARRID.
If the user is authorized, display a list of all the airline records.
Else if the user is not authorized, inform the user that he/she is not
authorized.
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
132/178
ABAP syntax
Report specific selection
Data: Data Types / Message
Types
Data: Tables
Data Access: The SELECT
statement
Internal tables
INTERNAL TABLES
-
7/30/2019 ABAP Workbench - Mod
133/178
These are tables internal to an ABAP and are used to store and
process data.
There are 3 parts to their use that we shall consider:
DEFINITION - in the DATA statement
FILLING THE TABLE - APPEND, COLLECT or APPEND SORTED BY
PROCESSING THE TABLE - LOOP AT . Only process a table when it
has been completely built.
INTERNAL TABLES
-
7/30/2019 ABAP Workbench - Mod
134/178
Table type Standardtable
Sorted table Hashed table
Index Access
Key Access
Uniqueness of
key
Non-unique Unique/Non-
unique
Unique
Access Primarily index
access
Primarily key
access
Exclusively
key access
Exercise 12
-
7/30/2019 ABAP Workbench - Mod
135/178
Task 1:
Create a program to show how the 3 different table type works.
Standard table
Sorted table using non-unique keys of PLANETYPE and SEATSOCC
Hashed table using unique keys of CARRID CONNID FLDATE
INTERNAL TABLE DEFINITION
-
7/30/2019 ABAP Workbench - Mod
136/178
There are several (over 10) different ways to define these.
Many date from earlier releases and still supported for compatibility
reasons
We will focus on the Standard type with Work Area - this is the
default format for ver 4.6
Internal table w/o Header Line
-
7/30/2019 ABAP Workbench - Mod
137/178
TYPES: BEGIN OF custstr ,
country TYPE z9a01-country,
name TYPE z9a01-name,
city TYPE z9a01-city,
turnover TYPE z9a01-turnover,END OF custstr.
*
DATA: wa_cust TYPE custstr, Work Area
it_cust TYPE STANDARD TABLE OF custstr INITIAL SIZE 100.
Internal table with Header Line
-
7/30/2019 ABAP Workbench - Mod
138/178
TYPES: BEGIN OF custstr ,
country TYPE z9a01-country,
name TYPE z9a01-name,
city TYPE z9a01-city,
turnover TYPE z9a01-turnover,
END OF custstr.
*
DATA: wa_cust TYPE custstr, Work Area
it_cust TYPE STANDARD TABLE OF custstr WITH HEADER LINE.
TABLE STRUCTURE
-
7/30/2019 ABAP Workbench - Mod
139/178
WORK AREA:
JP Sartre Paris 1234
INTERNAL TABLE :
Tintin Bruxelles 1111
Louis XIV VersaillesFR 2222
JPSartre ParisFR 1234
CUSTTAB-COUNTRY CUSTTAB-CITY
CUSTTAB-TURNOVER
.
.
.
.
.
.
.
.(100 rows)
FR
CUSTTAB-NAME
BE
FILLING THE TABLE
-
7/30/2019 ABAP Workbench - Mod
140/178
SELECT customer city country turnover
INTO wa_cust
FROM z9a01
WHERE .
APPEND wa_cust to it_cust.
ENDSELECT.
FILLING THE TABLE
-
7/30/2019 ABAP Workbench - Mod
141/178
Fill the fields of the work area then: APPEND TO - New records added into the table
body at the end.
APPEND TO SORTED BY - Sort on
Descending Order. The number of entries stored is the value of the INITIAL
SIZE. COLLECT INTO - Accumulates numeric (type P or I)
data.
Where the source of data is an SAP table - the fastest way is an array
fetch
SELECT INTO TABLE
FROM
WHERE
Append
-
7/30/2019 ABAP Workbench - Mod
142/178
1.APPEND .
2.APPEND SORTED BY SALES.
DE 400
AU 700
US 200
DE 400
AU 700
US 200
Country Sales
Country Sales
Collect
-
7/30/2019 ABAP Workbench - Mod
143/178
COLLECT .
DE 600
DE 400
AU 100
US 200
DE 200
Country Sales
INTERNAL TABLES and the DEBUGGER
-
7/30/2019 ABAP Workbench - Mod
144/178
The debugger can be used to see how an internal table is being
filled.
Can also adjust entries
MODIFY
DELETE
INSERT
APPEND
This is for the run of the program only
APPEND v COLLECT
-
7/30/2019 ABAP Workbench - Mod
145/178
APPEND - entries added at the end of the table. No summarising,
fast table build.
COLLECT - searches the table for an entry for an entry where the
table line matches the header for all but P,I type fields.
If it does not find one, a new entry is added at the end of the table.
If it does find one, then it adds the contents of the P,I fields in the
header to the body.
Numeric data is summarised; table build is slower
PROCESSING THE TABLE - SORTING
-
7/30/2019 ABAP Workbench - Mod
146/178
Sort the table only after it has been built
SORT . - Sorts by all non-numeric fields in the order specified
SORT BY COUNTRY.
SORT BY COUNTRY CITY DESCENDING.
Note that the field names are not qualified.
Try to define table fields in correct order (primary sort field first, etc)
to exploit powerful features
PROCESSING THE TABLE - LOOP AT
-
7/30/2019 ABAP Workbench - Mod
147/178
LOOP AT INTO .
......
ENDLOOP.
SY-SUBRC NE 0 if the table is empty
CHECK within the LOOP goes on to the next entry
LOOP AT WHERE - Restrict the range of data selected
AT COMMANDS
-
7/30/2019 ABAP Workbench - Mod
148/178
AT FIRST - First entry in the Table
AT LAST - Last entry in the Table
AT NEW ) Fields below this in the
AT END OF ) table are not available
SUM - Provides control break totals - note these are stored in the
header numeric fields
ENDAT to end the block
The order in which these are coded is the order in which they will
take place.
AT FIRST / AT LAST
-
7/30/2019 ABAP Workbench - Mod
149/178
LOOP AT INTO .
... (processing)
AT FIRST.
... (processing to be performed during first loop
pass through the table)
ENDAT.
...
AT LAST.
... (processing to be performed during final loop pass
through the table)
ENDAT.
ENDLOOP.
AT NEW / AT END OF
-
7/30/2019 ABAP Workbench - Mod
150/178
These are used as follows within LOOP ENDLOOP:
LOOP AT it_cust INTO wa_cust.
AT NEW country.
SKIP.
WRITE:/ Country:,
wa_cust-country.
ENDAT.
WRITE:/ wa_cust-city,
wa_cust-name,
wa_cust-turnover.
ENDLOOP.
SUM
-
7/30/2019 ABAP Workbench - Mod
151/178
SUM is used within an AT ENDAT block as follows:
AT FIRST/LAST/NEW /END OF .
... (processing)
SUM.
... (processing relevant to sum)
ENDAT.
BRINGING IN THE DATA
-
7/30/2019 ABAP Workbench - Mod
152/178
WORK AREA:
TAB LE :
Tintin Bruxelles BE 1111
LouisXIV Versailles FR 2222
JPSartre Paris FR 1234
CUSTTAB-NAME CUSTTAB-CITY
CUSTTAB-
COUNTRY
CUSTTAB-
TURNOVER
1
2
3
Delete table contents
-
7/30/2019 ABAP Workbench - Mod
153/178
To delete the table contents: Refresh
Deletes entire content of the table
Clear
Use with internal tables without header lines (have the same effect as
refresh). For internal table with header line, it only clears the header.
Free
Deletes entire content of the table and releases the memory used
Exercise 13
T k 1
-
7/30/2019 ABAP Workbench - Mod
154/178
Task 1:
Copy program from exercise 11.
Using APPEND, insert a new record into the internal table by adding the
following values:
CARRID = XX
CONNID = 123
FLDATE = SY-DATUM
PLANETYPE = 747-400
Task 2:
Using DELETE, delete the record which was appended in task 1.
Exercise 13
-
7/30/2019 ABAP Workbench - Mod
155/178
Task 3:
Using INSERT, insert a new record into the internal table by adding the
following values to position 2 of the internal table content:
CARRID = XX
CONNID = 123 FLDATE = SY-DATUM
PLANETYPE = 747-400
Task 4:
Using MODIFY, modify value for PLANETYPE 747-400 to 123-456.
Exercise 13
-
7/30/2019 ABAP Workbench - Mod
156/178
Task 5:
Sort the internal table by SEATSMAX (ascending/descending)
Display the list at the end of the program execution.
Exercise 14
-
7/30/2019 ABAP Workbench - Mod
157/178
Task 1:
Create a new program. Retrieve CARRID, CONNID, FLDATE,PLANETYPE, SEATSMAX, SEATSOCC from SFLIGHT using conditions:
CARRID = P_CARRID
Using the records returned from SFLIGHT, retrieve CARRID, CONNID,
BOOKID, CUSTTYPE, SMOKER, LUGGWEIGHT from SBOOK into a
separate internal table. (Note: use for all entries addition in this select
statement) This will base on:
CARRID = I_SFLIGHT-CARRID
CONNID = I_SFLIGHT-CONNID FLDATE = I_SFLIGHT-FLDATE
Exercise 14
-
7/30/2019 ABAP Workbench - Mod
158/178
Task 2:
The final report should show information of CARRID, CONNID, FLDATEPLANETYPE, SEATSMAX, SEATSOCC from SFLIGHT and CUSTTYPE,
SMOKER, LUGGWEIGHT from SBOOK.
Hints:
Sort the tables
Loop through the main table and read the next table with matching fields
Task 3:
The header should contain (Carriage ID, Connection ID, Flight Date, Plane
type, Seats max, Seats occ, Cust type, Smoker and Weight). Use color
format on to distinguish the header and the record items. (Hint: use format
color on)
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
159/178
Events & Sub programs
Function Modules & BAPIs
EVENTS
-
7/30/2019 ABAP Workbench - Mod
160/178
INITIALIZATION.
AT SELECTION-SCREEN
START-OF-SELECTION. ABAP HAS PASSED
THE SELECTION SCREEN
GET
END-OF-SELECTION.
TOP-OF-PAGE.
END-OF-PAGE.
AT LINE-SELECTION.
AT USER-COMMAND.
EVENTS
-
7/30/2019 ABAP Workbench - Mod
161/178
START-OF-SELECTION - the ABAP has passed the SelectionScreen but has not yet tried to GET any data
END-OF-SELECTION - there is no more data for the ABAP to GET
These statements should be used in all ABAPs particularly those
using Logical Databases
-
7/30/2019 ABAP Workbench - Mod
162/178
PROGRAM MODULARITY
-
7/30/2019 ABAP Workbench - Mod
163/178
A general programming concept
A MODULE is a discrete, self-contained chunk of code that performs
a specific task
A well-designed program will have a high degree of MODULARITY
Advantages:
Code is easier to understand
Programs are easier to test
Programs are easier to maintain
FORMS I
I t l S b ti
-
7/30/2019 ABAP Workbench - Mod
164/178
Internal Subroutines
Local DATA declarations are allowed in FORMs
Basic syntax:
PERFORM .
.....FORM
.......
ENDFORM.
Create the skeleton FORM block by double-clicking on the name in
the PERFORM block.
FORMS II - USING
-
7/30/2019 ABAP Workbench - Mod
165/178
Global data (eg Table fields) is known throughout the program,
including in all FORMs
We may want to pass different arguments to the FORM under
different circumstances.
Syntax:
PERFORM ... USING - passing the ACTUALparameters
FORM ... USING - using the FORMALparameters
Passing BY REFERENCE
-
7/30/2019 ABAP Workbench - Mod
166/178
PERFORM USING ARG1 ARG2 RES1.
..........
FORM USING A1 A2 R1.
R1 = A1 + A2.
ENDFORM.
If A1 or A2 are changed in the Form, then ARG1 or ARG2 will
change in the main program
RES1 will be filled with the result
Passing BY VALUE
-
7/30/2019 ABAP Workbench - Mod
167/178
PERFORM USING ARG1.
........
FORM USING VALUE(A1).
...
ENDFORM.
A1 is in a separate storage location to ARG1 - ARG1 will not be
changed
This method does not allow for any changes in the form to be
passed back to the main program.
Passing BY VALUE & RESULT
-
7/30/2019 ABAP Workbench - Mod
168/178
PERFORM USING ARG1 CHANGING ARG2...........
FORM USING VALUE(A1)
CHANGING VALUE(A2).
...
ENDFORM.
Only ARG2 will be changed
Exercise 15
-
7/30/2019 ABAP Workbench - Mod
169/178
Task 1:
Write a program displaying date field to hold SY-DATUM + 7 in the
initial selection screen.
Display the value on the list.
Hints: Make use of the events (initialization)
Exercise 16
-
7/30/2019 ABAP Workbench - Mod
170/178
Task 1:
Create a program utilizing the subroutine. Set up constant data and
use this to simulate pass by value, reference and value-result.
COURSE OUTLINE
-
7/30/2019 ABAP Workbench - Mod
171/178
Events & Sub programs Function Modules & BAPIs
FUNCTION MODULES
-
7/30/2019 ABAP Workbench - Mod
172/178
What they are
How to find them
How to use them
How to write them will not be discussed here
FUNCTION MODULES
-
7/30/2019 ABAP Workbench - Mod
173/178
Standard routines contained in the Function Builder They are used for a wide variety of tasks:
Currency Conversion
Interfaces - File uploads/downloads
Batch Input Control
Address formatting
Calendar Functions
Any ABAP can call them
FUNCTION GROUPS
-
7/30/2019 ABAP Workbench - Mod
174/178
Function Modules are arranged in Function Groups
Groupings determined by whether the modules are logically related
and/or use the same global data variables
Function Group ID - up to 26 character code (+ description)
Function Module names - up to 18 characters
Example: Function Group ABCD contains:
Master ABAP: SAPLABCD
Global data stored in LABCDTOP
Function Module code stored in LABCDxxx
Function module
What is FM?
-
7/30/2019 ABAP Workbench - Mod
175/178
What is FM?
Function modules are applied across applications and are available
throughout the SAP system. Function modules must be assigned to
a function group.
A function group is a placeholder which holds specific function
modules that are defined in it. Function group can be created via
SE37 or SE80
SE37 SE80
A Black Box
ABAP EXPORTSFUNCTION
-
7/30/2019 ABAP Workbench - Mod
176/178
ABAP EXPORTS
TABLES
EXCEPTIONS
(errors)
ABAP IMPORTS
IMPORTS
EXPORTS
FUNCTION
MODULE
Use in ABAP I
Syntax (use the PATTERN button to generate this):
-
7/30/2019 ABAP Workbench - Mod
177/178
CALL FUNCTION FUNCTION_NAME
EXPORTING
PARM1 =
.......
IMPORTING
PARM10 =
.........
EXCEPTIONS
NOT_FOUND = 1 .
Use in ABAP II
T t th FM i t th ABAP th P tt h b tt
-
7/30/2019 ABAP Workbench - Mod
178/178
To enter the FM into the ABAP program, use the Pattern push-button.
Alternatively, the codes can be typed in as well.
CALL FUNCTION 'CONVERSION EXIT ALPHA INPUT'EXPORTING
The syntax will be copied
into the program. ABAPer
needs to fill in the input
and/or output variables.