Complete Abap Basic
Transcript of Complete Abap Basic
-
7/27/2019 Complete Abap Basic
1/728
Basic ABAP
-
7/27/2019 Complete Abap Basic
2/728
On Completing this course, participants will be able to
Understand the Structure of ABAP Program
Work with ABAP Editor
Declare Data Types and Data Objects
Understand the internal tables and its types Work with internal tables
Understand modularization Techniques
Use message class
Use Open SQL Statements for processing
Objectives
-
7/27/2019 Complete Abap Basic
3/728
Advanced Business Application Programming
The programming language for SAP
Platform independent
Designed for dialog based Business Applications
Enables multi-language Applications
SAP R/3 written in ABAP
ABAP Editor (Tcode - SE38) is used for creating simple ABAP Programs.
ABAP Basics
-
7/27/2019 Complete Abap Basic
4/728
Structure of an ABAP Program
ABAP Processing logic is responsible for processing data in R/3
application Programming
ABAP Basics - Introduction
Declaration Part for
Global Data
Dialog
Modules
SubroutinesEvent
Blocks
etc..
-
7/27/2019 Complete Abap Basic
5/728
ABAP Programs cannot be constructed as a single sequential unit, butdivided into sections that is assigned to individual dialog steps.
To do this, ABAP Programs have a modular structure called Processing
Block
Processing Block consists of Set of ABAP Statements
Every ABAP Program has the following 2 parts
Declaration Part for Global Data , Classes and Selection Screens Container for Processing Blocks
Structure of ABAP Program
-
7/27/2019 Complete Abap Basic
6/728
Declaration Part for Global Data , Classes and Selection Screens
Contains all declaration Statements for Global Data
Global Data is visible in all internal processing blocks
Defined using Declarative Statements Appears before the first Processing Block
Cannot declare Global Data in Dialog Modules or Event Blocks
All Selection Screen Definition
All Local Class Definition
Local Classes are part of ABAP Objects (OO ABAP)
Structure of ABAP Program
(Contd.).
-
7/27/2019 Complete Abap Basic
7/728
Container for Processing Blocks
Dialog Modules
Event Blocks
Procedures
Methods
Subroutines Function Modules
Structure of ABAP Program
(Contd.).
-
7/27/2019 Complete Abap Basic
8/728
Calling Processing Blocks Using ABAP Commands , which is a part of
processing block
E.g. : Procedures
Outside the ABAP Program
E.g. : Dialog Modules and Event Blocks
Event Block Triggered by an Event
Structure of ABAP Program
(Contd.).
-
7/27/2019 Complete Abap Basic
9/728
Go to Transaction Code : SE38 ( ABAP Editor)
Simple ABAP Program
-
7/27/2019 Complete Abap Basic
10/728
Simple ABAP Program
(Contd.).
-
7/27/2019 Complete Abap Basic
11/728
Type
Status
Application
Authorization Group
Development Class
ABAP Program - Attributes
-
7/27/2019 Complete Abap Basic
12/728
Specifies the Type of Program Created Executable Program
Controlled by Run-time Environment, which
calls the processing blocks in a fixed sequence
An Executable Program can be started in
another ABAP Program using the SUBMITStatement
Simple ABAP Program - Program Type
-
7/27/2019 Complete Abap Basic
13/728
Referred as Reports because the main task of
Executable program is to read data from the
Database, Process and Display the results.
Need not define Event Blocks
START-OF-SELECTION is a processing Block
which is available by Default
A Transaction Code can be assigned
Simple ABAP Program - Program Type
-
7/27/2019 Complete Abap Basic
14/728
Module Pool Program
Can Only Be controlled using Screen Flow Logic
Must Start them using a Transaction Code
Must Define Your own Screen
Contains Dialog module belonging to various Screens
Used when the program contains large number of screens
whose flow logic determines the Program Flow
ABAP Program Program Type
(Contd.).
-
7/27/2019 Complete Abap Basic
15/728
INCLUDE Programs To Divide Program code into Smaller , more
manageable Units
INCLUDE Statement is used to insert the coding of aninclude program
FUNCTION GROUPS
Special Procedures that can be called from ABAP
Programs
Cannot be started using a Transaction Code
ABAP Program Program Type
(Contd.).
-
7/27/2019 Complete Abap Basic
16/728
Subroutine Pool
Containers for Subroutine which can be called from
ABAP Programs
Cannot Run using transaction Code or by entering
Program name
Cannot contain Screens
ABAP Program Program Type
(Contd.).
-
7/27/2019 Complete Abap Basic
17/728
Interface Pool
Container for Global Interfaces in ABAP Objects
Creates in Class Builder
Cannot Run using transaction Code or by
entering Program name
ABAP Program Program Type
(Contd.).
-
7/27/2019 Complete Abap Basic
18/728
Class Pool
Containers for Global Classes in ABAP Objects
Cannot Run using transaction Code or by entering
Program name
Type-Pool
Contains global type definitions and constant
declarations
ABAP Program Program Type
(Contd.).
-
7/27/2019 Complete Abap Basic
19/728
Status Describes the status of Program Development
Application Contains the short form of application
Enables system to allocate the program to
correct Business area
ABAP Program - Attributes
-
7/27/2019 Complete Abap Basic
20/728
Authorization Group
Name of the program group
To group different programs together forauthorization checks
Logical Database Determines the Logical Database used by
Executable Program
ABAP Program - Attributes
-
7/27/2019 Complete Abap Basic
21/728
Selection Screen
To specify a selection-screen other than the
standard LDB selection screen.
Specify a screen number less than 1000 (
1000 reserved for standard selection screennumber)
ABAP Program - Attributes
-
7/27/2019 Complete Abap Basic
22/728
The following rules in general applies toABAP syntax
ABAP Programs comprises of individualsentences
The first word in the statement is the ABAPkeyword
Each statement ends with a period (.)
ABAP Syntax
-
7/27/2019 Complete Abap Basic
23/728
First ABAP Program
REPORT ZFIRSTPRG.
WRITE 'MY FIRST PROGRAM'.
In the above program REPORT and WRITEare keywords.
On Execution , this program displays a list on
screen which contains a line
ABAP Program
-
7/27/2019 Complete Abap Basic
24/728
Chained Statements Used to concatenate statements
The chain operator used is :
Example Statement sequence:
WRITE var1.
WRITE var2.
WRITE var3.
Chain Statement:
WRITE : var1, var2, var3.
ABAP Statements
-
7/27/2019 Complete Abap Basic
25/728
Chained Statements
Example
Statement Sequence
sum = sum + 1.
sum = sum + 2.
sum = sum + 3.
Chained Statement:
sum = sum + : 1, 2, 3.
ABAP Statements (Contd.).
-
7/27/2019 Complete Abap Basic
26/728
Define data types
Declare Data Objects
Examples
TYPES
DATA
TABLES
ABAP Statements - Declarative
Statements
-
7/27/2019 Complete Abap Basic
27/728
Define the processing blocks in ABAPProgram
Defining Keywords To define Subroutines, Function Modules, Dialog
Modules and Methods
Examples
METHOD...END METHOD
FUNCTION ......END FUNCTION
MODULE ..END MODULE
ABAP Statements - Modularization
Statements
-
7/27/2019 Complete Abap Basic
28/728
Control Statements Used to control the flow of program within the
processing block
Examples: IF, WHILE, CASE
Call Statements
Used to call the processing block
Examples:
CALL METHOD , CALL TRANSACTION,
SUBMIT, LEAVE TO
ABAP Statements
-
7/27/2019 Complete Abap Basic
29/728
Data Types
Elementary Types Smallest indivisible unit
Fixed Length
8 predefined types in ABAP
C Character
N Numeric Character
D Date
T Time
X Hexa Decimal Byte Field
I Integer
P Floating Point Number
F Packed Number
Variable Length
STRING
XSTRING
Data Types and Data Objects
St d d D t T
-
7/27/2019 Complete Abap Basic
30/728
Predefined Elementary Types
Standard Data Types
Data Type Initial Field
Length
Valid
Field Length
Initial Value
Numeric Types
I 4 4 0
P 8 8 0F 8 1-16 0.0000000E+0
0
Character Types
C 1 1 65535
N 1 1 65535 00
D 8 8 00000000
T 6 6 000000
Hexa Decimal
X 1 1-65535 X00
(C )
-
7/27/2019 Complete Abap Basic
31/728
Local Elementary Data Types are defined
with reference to predefined elementarytypes
Syntax:
TYPES [()] [TYPE |LIKE
] [DECIMALS ]
Where type is a predefined data type..
If TYPE or LIKE is not used , system takes the
default type C
Data Types (Contd.).
-
7/27/2019 Complete Abap Basic
32/728
Reference Types Describes Data Objects that contain
references to other objects
No predefined references
Complex Types
Allows to manage and process related data
under a single name
Data Types (Contd.).
-
7/27/2019 Complete Abap Basic
33/728
Structures
Sequence of any elementary types, reference types orcomplex data types
Used in ABAP Programs to group work areas that
logically belong together
Example:
TYPES : BEGIN OF address,
name(20) TYPE c,
street(30) TYPE c,
city(20) TYPE c,
END OF address.
Data Types - Complex Data Types
-
7/27/2019 Complete Abap Basic
34/728
Internal Tables
Consists of series of lines which has the same data
type
Characterized By
Line Type Elementary, Reference or Complex Type
The Key Unique or non-Unique.
Identifies Table Rows
Data Types - Complex Data Types
What are Data Objects?
-
7/27/2019 Complete Abap Basic
35/728
Physical units with which ABAP Statements work
Instance of an abstract Data type
Has a set of technical attributes
Length
Number of Decimal Places
Data Type
Always defined with the DATA keyword
Can refer to an existing data object
What are Data Objects?
-
7/27/2019 Complete Abap Basic
36/728
Defining Data Objects
ABAP PROGRAM
TYPES gty_type_name TYPE .
DATA gd_myvar1 TYPE type_name.
DATA gd_myvar2 LIKE gd_myvar1.
Predefined Data Types
C I
N P
D F
T X
Global
Types
ABAP
Dictionary
N d D t Obj t
-
7/27/2019 Complete Abap Basic
37/728
They are Data Objects which have a name
Various Types
Text Symbols
Pointers to texts in the text pool of the ABAP program
Variables Data Objects whose contents can be changed using ABAP
statements
Declared Using DATA, CLASS-DATA, STATICS, PARAMETERS,
SELECT-OPTIONS statements
Constants
Data Objects whose contents cannot be changed
Declared Using CONSTANTS Statement.
Example:
CONSTANTS pi TYPE p DECIMALS 3 VALUE 3.141.
Named Data Objects
-
7/27/2019 Complete Abap Basic
38/728
SPACE
Constant
Type C
Length - 1 byte
Contains Space Character
Pre-defined Data Objects
-
7/27/2019 Complete Abap Basic
39/728
SY-SUBRC
Return code for ABAP statements
0 - if a statement is executed successfully
SY-UNAME
logon name of the user
SY-REPID:
Current ABAP program
SY-TCODE
current transaction
SY-INDEX
Number of the current loop pass
System Fields from Structure SY
Determining the attributes of Data
-
7/27/2019 Complete Abap Basic
40/728
Syntax:DESCRIBE FIELD [LENGTH ]
[TYPE [COMPONENTS ]]
[OUTPUT-LENGTH ][DECIMALS ]
[EDIT MASK ] [HELP-ID
].
Determining the attributes of Data
Objects
Determining the attributes of Data
-
7/27/2019 Complete Abap Basic
41/728
Examples
DATA : text(8) TYPE c, len TYPE i, typ TYPE c.
DATA : fl TYPE f, out TYPE i, leng TYPE i.
DESCRIBE FIELD text LENGTH lenin CHARACTER MODE.
DESCRIBE FIELD text TYPE typ.
DESCRIBE FIELD fl LENGTH leng in BYTE MODE
OUTPUT-LENGTH out
Upon Execution, the value of len is 8 , typ is C, leng is 8 and
out is 24.
Determining the attributes of Data
Objects Cont.d..
-
7/27/2019 Complete Abap Basic
42/728
Assigning Values
MOVE
MOVE source TO destination
Examples
MOVE 5.7 TO number.
DATA : num1 TYPE i, num2 TYPE i.
num1 = 10.
MOVE num1 TO num2.
Data Objects - Operations
D t Obj t O ti (C td )
-
7/27/2019 Complete Abap Basic
43/728
Assigning Values
MOVE-CORRESPONDINGMOVE-CORRESPONDING sourcestruct TO destinationstruct
Examples
DATA : BEGIN OF address,
fname(15) TYPE c VALUE Robert,
lname(15) TYPE c VALUE David,
compname(30) TYPE c VALUE WIPRO TECHNOLOGIES,
number TYPE i VALUE 72,
street(30) TYPE c VALUE Keonics Electronic City,
city(10) TYPE c VALUE BANGALORE,
END OF address.
DATA : BEGIN OF name,
lname(15) TYPE c ,
fname(15) TYPE c ,
END OF name.
MOVE-CORRESPONDING address TO name.
Data Objects Operations (Contd.).
D t Obj t O ti
-
7/27/2019 Complete Abap Basic
44/728
Assigning Values WRITE TO
WRITE TO [].
This statement converts to TYPE C and
places the string in
Example
DATA : number TYPE f VALUE 4.38,
text(10).
WRITE number TO text .
WRITE text.
Data Objects Operations
(Contd.).
-
7/27/2019 Complete Abap Basic
45/728
CLEAR var. Resets var to appropriate initial value for its type
Cannot use CLEAR to reset a CONSTANT
Has different effect for different Data Types
Elementary ABAP Types Sets the value of the variable to initial value
References Resets reference variable to initial value, so that it doesnt point
to any object Structures
Resets individual components of a structure to their respective
initial values
Internal Tables Deletes the entire contents of Internal Table
Resetting Variables to Initial Values
R tti V i bl t I iti l
-
7/27/2019 Complete Abap Basic
46/728
CLEAR var.
Example
DATA number TYPE i VALUE '10'.
WRITE number.
CLEAR number.
WRITE number.
Output : 10 0
Resetting Variables to Initial
Values(Contd.).
T C i
-
7/27/2019 Complete Abap Basic
47/728
When a Data Object is assigned to a variable
the data types involved must be compatible or
The source fields data type must be convertible into target fields
data type.
Two non-compatible data types can be converted to each other if
a corresponding conversion rule exists
Assignment Rules for Reference Variable
The content of a reference variable can be assigned only to
another reference variable.
Data references can be assigned only to data reference
variables
Object references can be assigned only to object reference
variables.
No Conversion takes place during this assignments
Type Conversions
Type Conversions (Contd )
-
7/27/2019 Complete Abap Basic
48/728
Conversion Rule for Structures
No Conversion Rule for Structures that contain internal tables orstrings
Only assignment between structures that are compatible is
possible
The system first converts all the structures concerned to type c
fields and then performs the conversion between the two
resulting elementary fields
Conversion Rule For Internal Tables
Can only be converted into another internal table
Internal tables which have internal tables as their line type are
convertible if the internal tables which define the line types areconvertible.
Type Conversions (Contd.).
N i l O ti
-
7/27/2019 Complete Abap Basic
49/728
COMPUTE = .
COMPUTE is optional
The interpretations of mathematical expressions are in
the following order
Expressions in parentheses
Functions
** (powers)
*, / , MOD, DIV (multiplication, division)
+, - (addition, subtraction)
Numerical Operations
Arithmetic Operations
-
7/27/2019 Complete Abap Basic
50/728
The following arithmetic operators are used in mathematical
expressions:
Arithmetic Operations
Operator Meaning
+ Addition
_ Subtraction
* Multiplication
/ Division
DIV Integer division
MOD Reminder of Integer
Division
** Powers
-
7/27/2019 Complete Abap Basic
51/728
ADD-CORRESPONDING
SUBTRACT-CORRESPONDING MULTIPLY-CORRESPONDING
DIVIDE-CORRESPONDING
Example:DATA: BEGIN OF RATE,
USA TYPE F VALUE '0.6667',
FRG TYPE F VALUE '1.0',
END OF RATE.
DATA: BEGIN OF MONEY,USA TYPE I VALUE 100,
FRG TYPE I VALUE 200,
END OF MONEY.
MULTIPLY-CORRESPONDING MONEY BY RATE.
WRITE : MONEY-USA, MONEY-FRG.
Arithmetic Calculations Using Structures
Adding Sequences Of Fields
-
7/27/2019 Complete Abap Basic
52/728
ADD THEN UNTIL GIVING .
ADD THEN UNTIL TO .
Example:
DATA: BEGIN OF SERIES,
N1 TYPE I VALUE 10,
N2 TYPE I VALUE 20,
N3 TYPE I VALUE 30,
N4 TYPE I VALUE 40,
N5 TYPE I VALUE 50,
N6 TYPE I VALUE 60,
END OF SERIES.
DATA SUM TYPE I.
ADD SERIES-N1 THEN SERIES-N2 UNTIL SERIES-N5 GIVING SUM.
WRITE SUM.
ADD SERIES-N2 THEN SERIES-N3 UNTIL SERIES-N6 to SUM.
WRITE / SUM.
Adding Sequences Of Fields
-
7/27/2019 Complete Abap Basic
53/728
Date and Time fields are of Character types
But numeric operations can be performed
The system performs automatic type conversions
Example
DATA: ultimo TYPE D.
ultimo = SY-DATUM.
ultimo+6(2) = '01'. " first day of this month
ULTIMO = ULTIMO - 1. " last day of last month
WRITE ultimo.
Date and Time calculations
P i d t b t
-
7/27/2019 Complete Abap Basic
54/728
Data can be passed between programs using the
Internal Memory Areas
There are two cross-program memory areas to which
ABAP programs have access that can be used to pass
data between programs
SAP Memory
ABAP Memory
Passing data between programs
Passing Data between Programs - SAP
-
7/27/2019 Complete Abap Basic
55/728
SAP memory is a memory area to which all main sessions within aSAPgui have access.
SAP memory is used either to pass data from one program to
another within a session, or to pass data from one session to
another.
Application programs that use SAP memory must do so using
SPA/GPA parameters (also known as SET/GET parameters).
These parameters can be set either for a particular user or for aparticular program using the SET PARAMETER statement.
Other ABAP programs can then retrieve the set parameters using
the GET PARAMETER statement.
g gMemory
-
7/27/2019 Complete Abap Basic
56/728
Filling an Initial Screen using SPA/GPA Parameters
SPA/GPA parameters are values that the system stores in the
global, user-specific SAP memory.
SAP memory allows passing values between programs.
A user can access the values stored in the SAP memory during
one terminal session for all parallel sessions.
Each SPA/GPA parameter is identified by a 20-character code
which is maintained in the Repository Browser in the ABAP
Workbench.
The values in SPA/GPA parameters are user-specific.
SPA/GPA
-
7/27/2019 Complete Abap Basic
57/728
Filling an Initial Screen using SPA/GPA Parameters
ABAP programs can access the parameters using the SET
PARAMETER and GET PARAMETER statements.
To fill one, use: SET PARAMETER ID FIELD .
This statement saves the contents of field under the ID
in the SAP memory.
If the ID does not exist, double-click in the ABAP
Editor to create a new parameter object.
SPA/GPA (Contd.).
SPA/GPA (Contd )
-
7/27/2019 Complete Abap Basic
58/728
Filling an Initial Screen using SPA/GPA Parameters
To read an SPA/GPA parameter, use:
GET PARAMETER ID FIELD .
This statement fills the value stored under the ID into the
variable .
If the system does not find a value for in the SAP memory,
it sets SY-SUBRC to 4, otherwise to 0.
To fill the initial screen of a program using SPA/GPA parameters,
use the SET PARAMETER statement.
On a selection screen, link fields to parameters using the
MEMORY ID addition in the PARAMETERS or SELECT-
OPTIONS statement.
SPA/GPA (Contd.).
-
7/27/2019 Complete Abap Basic
59/728
ABAP memory is a memory area that all ABAP programs within the
same internal session can access using the EXPORT and IMPORT
statements.
Data within this area remains intact during a whole sequence of
program calls.
To pass data to a program which you are calling, the data needs to
be placed in ABAP memory before the call is made.
The internal session of the called program then replaces that of thecalling program. The program called can then read from the ABAP
memory.
If control is then returned to the program which made the initial call,
the same process operates in reverse.
ABAP Memory
S i D t Obj t i M
-
7/27/2019 Complete Abap Basic
60/728
Any number of internal data objects of any complexity from an
ABAP program can be stored temporarily in ABAP memory
ABAP memory is a memory area within the internal session (roll
area) of an ABAP program
ABAP memory is independent of the ABAP program or program
module from which it was generated.
An object saved in ABAP memory can be read from any other ABAPprogram in the same call chain.
Saving Data Objects in Memory
-
7/27/2019 Complete Abap Basic
61/728
Data can be passed
From an executable program (report) to
another executable program called usingSUBMIT.
From a transaction to an executable program
(report).
Between dialog modules.
Data Objects in Memory
Saving Data Objects in
-
7/27/2019 Complete Abap Basic
62/728
EXPORT [FROM ] [FROM ] ... TO MEMORY ID .
Example
EXPORT text1 TO MEMORY ID text'.
Saving Data Objects in
ABAP Memory
Reading Data Objects From
-
7/27/2019 Complete Abap Basic
63/728
IMPORT [TO ] [TO ] ...FROM MEMORY ID .
Example:
IMPORT text1 to text2 FROM MEMORY ID
'text'.
Reading Data Objects From
Memory
-
7/27/2019 Complete Abap Basic
64/728
Controlling the Program Flow
Logical Expressions
Operand1 operator operand2
Several Logical Expressions can be linked
together with a condition
Checking For Initial Values
... IS INITIAL ...
Control Structures
-
7/27/2019 Complete Abap Basic
65/728
Conditional Branching The IF Control Structure
The Case Control Structure
Loops
Unconditional loops using the DO..ENDDO.
Conditional Loops Using the WHILE
.ENDWHILE.
Control Structures (Contd.).
-
7/27/2019 Complete Abap Basic
66/728
Terminating Loops
Terminating Loop Pass Unconditionally
CONTINUE
EXIT
Terminate Loop Pass Conditionally
CHECK
Loops
-
7/27/2019 Complete Abap Basic
67/728
Processing Character Strings FIND
FIND [{FIRST OCCURRENCE}|{ALLOCCURRENCES} OF] pattern IN dobj.
REPLACE
REPLACE [{FIRST OCCURRENCE}|{ALL
OCCURRENCES} OF] pattern
IN dobj WITH new
Character Strings
Processing Character
-
7/27/2019 Complete Abap Basic
68/728
TRANSALATE
TRANSLATE text TO UPPER CASE.
TRANSLATE text TO LOWER CASE.
TRANSLATE text USING pattern
CONDENSE
Processing Character
Strings
-
7/27/2019 Complete Abap Basic
69/728
Placeholders or symbolic names for aData Object.
To Access Data Objects Dynamically in
ABAP Programs Do not Physically reserve space for a field
but points to its Contents
Can point to any Data Object Allows the access of Data Objects whose
name and attributes are not known till
runtime
Field Symbols
-
7/27/2019 Complete Abap Basic
70/728
Declaring Field Symbols
FIELD-SYMBOLS [typing].
Angle brackets are part of declaration
Typing specifies the type of field symbol
Assigning Data Objects to Field Symbols
Field Symbols (Contd.).
-
7/27/2019 Complete Abap Basic
71/728
TYPES: BEGIN OF LINE,
COL1,
COL2,
END OF LINE.
DATA: WA TYPE LINE,ITAB TYPE HASHED TABLE OF LINE
WITH UNIQUE KEY COL1,
KEY(4) VALUE 'COL1'.
FIELD-SYMBOLS TYPE ANY TABLE.ASSIGN ITAB TO .
READ TABLE WITH TABLE KEY (KEY)
= 'X' INTO WA.
Field Symbols - Example
Assigning Data Objects To
-
7/27/2019 Complete Abap Basic
72/728
To assign a data object to a field symbol,use the ASSIGN statement
ASSIGN TO .
When the data object is assigned, the
system checks whether the technical
attributes of the data object correspond to any type specifications for
the field symbol .
Assigning Data Objects To
Field Symbols
-
7/27/2019 Complete Abap Basic
73/728
-
7/27/2019 Complete Abap Basic
74/728
Simple output lists on the screen can becreated by using the ABAP statements
WRITE
ULINE
SKIP
When an executable program is
Creating Simple Reports
-
7/27/2019 Complete Abap Basic
75/728
Output Format of Predefined
-
7/27/2019 Complete Abap Basic
76/728
Output Format of Predefined
Data Types
Data
Type
Positioning
I Right-Justified
P Right-Justified
F Right-Justified
C Left-Justified
N Left-Justified
D Left-Justified
T Left-Justified
Positioning WRITE Output
-
7/27/2019 Complete Abap Basic
77/728
Syntax
WRITE AT [/][][()] .
the slash '/' denotes a new line,
is a number or variable up to threedigits long denoting the position on the screen
is a number or variable up to three
Positioning WRITE Output
on the List
Formatting Options for all
-
7/27/2019 Complete Abap Basic
78/728
WRITE .... .
Formatting Options for all
Data Types
Option Function
Left-Justified Output is left-justified.
Centered Output is centered.
Right-Justified Output is right-justified.
Under Output starts directly under field
.NO-GAP The blank after field is omitted.
Using Edit
Mask(m)
Specifies format template .
Using No Edit Deactivates a format template
Formatting Options for
-
7/27/2019 Complete Abap Basic
79/728
Formatting Options for
numeric fields
Option Function
NO-SIGN The leading sign is not
displayed on the screen.
DECIMALS
defines the number of digitsafter the decimal point.
EXPONEN
T
In type F fields, the exponent is
defined in .
ROUND
Type P fields are multiplied by10**(-r) and then rounded.
CURRENC
Y
Format according to currency
in table TCURX.
UNIT The number of decimal places is
< >
Displaying Symbols and
-
7/27/2019 Complete Abap Basic
80/728
WRITE AS SYMBOL.WRITE AS ICON.
Example
INCLUDE .
INCLUDE .
WRITE: / 'Telephone symbol:', sym_phone AS SY
MBOL.
WRITE: / 'Alarm icon: ', icon_alarm AS ICON.
Displaying Symbols and
Icons on the List
D i Li
-
7/27/2019 Complete Abap Basic
81/728
Horizontal lines
ULINE [AT [/][][()]].
WRITE [AT [/][][()]] SY-ULINE.
WRITE [AT [/][][()]] '-----...'.
Vertical Lines
-
Drawing Lines
Modifying the Structure of
-
7/27/2019 Complete Abap Basic
82/728
Individual Page Header
To layout a Page Header the event keyword
TOP-OF-PAGE must be defined.
The TOP-OF-PAGE event occurs as soon as
the system starts processing a new page of a
list
The system processes the statements
following TOP-OF-PAGE before outputting the
Modifying the Structure of
Lists
D t i i Th Li t Width
-
7/27/2019 Complete Abap Basic
83/728
LINE-SIZE option of the REPORTstatement is used to determine the width
of the output list.
REPORT LINE-SIZE
.
If the is set to zero, the system
uses the width of the standard list.
Determining The List Width
Determining the Page
-
7/27/2019 Complete Abap Basic
84/728
Page length of an output list, is determinedusing the LINE-COUNT option of the
REPORT statement.
REPORT LINE-COUNT
[()].
This statement determines the page length
of the output list of program as
lines.
Determining the Page
Length
D fi i P F t
-
7/27/2019 Complete Abap Basic
85/728
END-OF-PAGE event is used todetermine the footer
This event occurs if the system reachesthe lines reserved for the page footer, or if
the RESERVE statement triggers a page
break
The system only processes the processing
block following END-OF-PAGE if the lines
Defining a Page Footer
-
7/27/2019 Complete Abap Basic
86/728
P i P B k
-
7/27/2019 Complete Abap Basic
87/728
The NEW-PAGE statement is used toprogram unconditional page breaks.
NEW-PAGE [NO-TITLE|WITH-TITLE] [NO-HEADING|WITH-HEADING].
Ends the current page and does not triggerthe END-OF-PAGE event
System does not output a page footer even if
one is defined.
Programming Page Breaks
Si l R t E l
-
7/27/2019 Complete Abap Basic
88/728
REPORT DEMO_LIST LINE-SIZE 40 LINE-COUNT 5(1).
END-OF-PAGE.
ULINE.
START-OF-SELECTION.NEW-PAGE LINE-COUNT 5.
DO 4 TIMES.
WRITE / sy-index.
ENDDO.
WRITE: / 'Next Loop:'.
NEW-PAGE LINE-COUNT 6.
DO 6 TIMES.
WRITE / sy-index.
ENDDO.
Simple Reports - Example
M
-
7/27/2019 Complete Abap Basic
89/728
Single texts stored in table T100
Maintained in Transaction SE91
Provides a way to communicate with the
user
Mostly used for error handling
Messages
Messages (Contd )
-
7/27/2019 Complete Abap Basic
90/728
The message class and number are usedto identify the message in table T100.
The message types are one of thefollowing:
A : Termination Message
E : Error Message I : Information Message
S : Status
W : Warning
Messages (Contd.).
Messages Statement
-
7/27/2019 Complete Abap Basic
91/728
Using a Global Message Class
MESSAGE tnnn [WITH f1 ... f4] [RAISING exc].
Specifying the Message Statically
MESSAGE tnnn(id) [WITH f1 ... f4] [RAISINGexc].
Specifying the Message Dynamically
Messages Statement
Creating Message Class
-
7/27/2019 Complete Abap Basic
92/728
Creating Message Class
Messages Examples
-
7/27/2019 Complete Abap Basic
93/728
MESSAGE i001(zmsgs).
MESSAGE i003(ZMSGS) WITH 'This is th
'
Messages - Examples
Selection Screen
-
7/27/2019 Complete Abap Basic
94/728
Selection screens are a standardized userinterface.
It is used when the user has to give datainput.
Input parameters are primarily used tocontrol the program flow, while users can
enter selection criteria to restrict the
amount of data read from the database.
Selection Screen
Defining Selection Screens
-
7/27/2019 Complete Abap Basic
95/728
PARAMETERS for single fields
SELECT-OPTIONS for complex selections
SELECTION-SCREEN for formatting the
selection screen and defining user-specific
selection screens
Defining Selection Screens
Defining Input Fields for
-
7/27/2019 Complete Abap Basic
96/728
Enables the user to enter values for singlefields on the selection screen
Each parameter declared with thePARAMETERS statement appears as an
input field on the relevant selection screen.
PARAMETERS p[(length)] [TYPE
type|LIKE obj] [DECIMALS d].
g p
Single Values
Internal Tables Introduction
-
7/27/2019 Complete Abap Basic
97/728
Two ways to process large quantities ofdata
Internal Tables
Dynamic sequential dataset in which all records
have the same structure and a key
Individual records can be accessed by index or
keys
Internal Tables - Introduction
Internal Tables (Contd )
-
7/27/2019 Complete Abap Basic
98/728
Line Type
Can be any data type
The data type of an internal table is usually a
Structure
Each component of a structure is a column in
internal table
Internal Tables (Contd.).
Internal Tables Key
-
7/27/2019 Complete Abap Basic
99/728
Standard Key Tables with Structured and non -structured
row type : all Character Type columns
Tables with Elementary line-type : entire line
is the default key
If line type is an internal table : no default key
Tables with non-structured row type :
Internal Tables - Key
Internal Tables Table Type
-
7/27/2019 Complete Abap Basic
100/728
Determines how ABAP accesses theindividual entries
Three Types
Standard Tables
Sorted Tables
Hashed Tables
Internal Tables - Table Type
Internal Tables - Standard
-
7/27/2019 Complete Abap Basic
101/728
Have an internal linear index
Records are accessed by index or keys
The response time for key access is
proportional to number of entries
The key is always non-unique
Tables
Internal Tables - Sorted
-
7/27/2019 Complete Abap Basic
102/728
Always saved sorted by the key
Have an internal index
Records can be accessed by table index
or key
Uses Binary Search for access
Tables
Internal Tables - Hashed
-
7/27/2019 Complete Abap Basic
103/728
Has no linear index
Only accessed using its key
Key must be Unique
Uses Hash Algorithm for accessing
records
Tables
Creating Internal Tables
-
7/27/2019 Complete Abap Basic
104/728
Syntax:
TYPES type TYPE|LIKE tabkind OF linetype
[WITH key] [INITIAL SIZE n].
DATA itab TYPE type|LIKE obj.
Example:
DATA : BEGIN OF str_mat,
matno(18),
matname(30),
Creating Internal Tables
Internal table objects
-
7/27/2019 Complete Abap Basic
105/728
Internal tables are dynamic variable dataobjects.
Like all variables, declare them using theDATA statement.
Internal table objects
Reference to Declared
-
7/27/2019 Complete Abap Basic
106/728
Like all other data objects, declareinternal table objects using the LIKE or
TYPE addition of the DATA statement.
DATA TYPE |LIKE [WITH
HEADER LINE].
Here, the LIKE addition refers to an existing
table object in the same program.
Internal Table Types
Reference to Declared
-
7/27/2019 Complete Abap Basic
107/728
Use it as a work area when working withthe internal table.
When using internal tables with headerlines, the header line and the body of the
table have the same name.
If there is an internal table with header
line, to address the body of the table,
place brackets after the table name
Internal Table Types
Operations on Entire Internal
-
7/27/2019 Complete Abap Basic
108/728
The entire body of the table is addressedas a single Data Object
The following operations are done on theentire Internal Table
Assigning Internal Tables
Initializing Internal Tables
Table
Assigning Internal Tables
-
7/27/2019 Complete Abap Basic
109/728
Syntax:
MOVE itab1 TO itab2. or
itab2 = itab1. Example:
DATA : it_mat LIKE TABLE OF str_mat,it_mat1 LIKE TABLE OF str_mat.
str_mat-matno = 'm01'.
str mat-matname = 'Notepads'.
Assigning Internal Tables
Initializing Internal Tables
-
7/27/2019 Complete Abap Basic
110/728
CLEAR itab.
The memory space required for the table is
released, except for the initial memory
requirement.
REFRESH itab
This always applies to the body of the table.
With REFRESH, too, the initial memory
Initializing Internal Tables
Processing Internal Tables
-
7/27/2019 Complete Abap Basic
111/728
Sorting Internal Tables Syntax
SORT itab [ASCENDING|DESCENDING] [AStext] [STABLE].
Determining the Attributes of Internal
Tables
Processing Internal Tables
Access Methods to
-
7/27/2019 Complete Abap Basic
112/728
2 ways to access the individual tableentries
Access Using a Work Area
While accessing individual table entries, the data in
the table is not directly accessed but through
another Data Object like a Work Area
Work Area is an interface to the entries in the
Internal Table
Work Area must be compatible with the line type of
Individual Table Entries
Access Methods to
-
7/27/2019 Complete Abap Basic
113/728
Access using Field Symbols
A line of the Internal Table is assigned to the
Field Symbol i.e., the Field Symbol will have
the same line type as the Internal Table
Once an entry is assigned to the Field
Symbol, working with it is like accessing theline of the Internal Table directly.
Individual Table Entries
Filling Internal Tables Line
-
7/27/2019 Complete Abap Basic
114/728
To Insert Individual Row at a SpecificPosition
INSERT wa INTO TABLE itab.
To Append Rows to the Internal Table
APPEND wa TO itab.
By Line
Filling Internal Tables
-
7/27/2019 Complete Abap Basic
115/728
Standard Tables
Lines are always Appended to the end of the
Internal Table.
Sorted Tables
The lines are inserted into the table according
to the table key
Filling Internal Tables
Inserting Lines
-
7/27/2019 Complete Abap Basic
116/728
Inserting Several Lines
To insert several lines into the internal table
use
INSERT LINES OF itab1 [FROM n1] [TO n2] INTO TABLE
itab2.
Inserting Lines Using The Index
Inserting a Single Line
Inserting Lines
Appending Lines
-
7/27/2019 Complete Abap Basic
117/728
Appending a Single Line
APPEND line TO itab.
Appending Multiple Lines
APPEND LINES OF itab1 TO itab2.
Appending Lines
Reading Lines of Table
-
7/27/2019 Complete Abap Basic
118/728
To Read a Single Line
READ TABLE itab key result.
If the system finds an entry it sets the system
field SY-SUBRC to 0 and if not, it sets the
value to 4.
Specifying The Search Key
Reading Lines of Table
Processing Table Entries in
L
-
7/27/2019 Complete Abap Basic
119/728
Syntax:LOOP AT itab result condition.
statement block
ENDLOOP.
The sequence in which lines are processed
depends on the table type
Standard and Sorted Table
The lines are processed according to linear index
Loops
Processing Table Entries in
L (C td )
-
7/27/2019 Complete Abap Basic
120/728
Loop blocks can be nested
After the ENDLOOP, SY-SUBRC = 0 , if
at least one table entry is processed.
The loop may not contain any operations
which may change the contents of theentire table
Loops (Contd.).
Changing Lines
-
7/27/2019 Complete Abap Basic
121/728
Changing Lines of an Internal Table
MODIFY TABLE itab FROM wa [TRANSPORTING
f1 f2 ...].
Changing Table Lines Using a Condition
MODIFY itab FROM wa TRANSPORTING f1 f2 ...
WHERE cond.
Changing Lines
Deleting Lines
-
7/27/2019 Complete Abap Basic
122/728
DELETE TABLE itab FROM wa.
Deletion Using Table Key
DELETE TABLE itab WITH TABLE KEY k1 = f1 ... kn
= fn.
Deletion Using a Condition
DELETE itab WHERE cond.
Deleting Lines
Deleting Lines Contd..
-
7/27/2019 Complete Abap Basic
123/728
Deleting a line specifying the Index
DELETE itab [INDEX idx].
Deleting Several Lines
DELETE [FROM n1] [TO n2] [WHEREcondition].
Deleting Lines Contd..
Control Level Processing
-
7/27/2019 Complete Abap Basic
124/728
Its for internal tables accessed usingLoops
Internal tables are divided into groupsaccording to the sequence of the fields in
the line structure.
The first column defines the highest
control level and so on.
Control Level Processing
Control Level Processing
(C td )
-
7/27/2019 Complete Abap Basic
125/728
Within the processing block of the loop,the control level statement AT is used to
react to a control level change
The SUM statement to calculate totals
from subsets of all lines
The AT statement introduces a statement
block that is end with the ENDAT
statement
(Contd.).
Control Level Processing
(C td )
-
7/27/2019 Complete Abap Basic
126/728
Control Level Statements are used toreact to control breaks in internal tables
instead of programming them with logical
expressions
According to the hierarchy of the control
levels , the AT-ENDAT statements must be
placed within the Loop.
All character fields to the right of the
(Contd.).
Open SQL
-
7/27/2019 Complete Abap Basic
127/728
Subset of Standard SQL
Enable the ABAP programs to access data
irrespective of the database systeminstalled
Open SQL consists of the DataManipulation Language (DML)
O en SQL allows to read SELECT and
Ope SQ
Native SQL
-
7/27/2019 Complete Abap Basic
128/728
Loosely integrated into ABAP
Allows access to all of the functions
contained in the programming interface ofthe respective database system
Native SQL statements are not checkedand converted, but sent directly to the
database system
Q
Open SQL
-
7/27/2019 Complete Abap Basic
129/728
Open SQL consists of a set of ABAPstatements that perform operations on the
central database in the SAP Web AS
ABAP
Open SQL provides a uniform syntax and
semantics for all of the database systems
supported by SAP
ABAP programs that only use Open SQL
p Q
Keywords used in Open
SQL
-
7/27/2019 Complete Abap Basic
130/728
SQLKeyword Function
SELECT Reads data from database
tables
INSERT Adds lines to database tablesUPDATE Changes the contents of lines of
database tables
MODIFY Inserts lines into database tables
or changes the contents ofexisting lines
DELETE Deleting Lines from Database
Tables
OPEN Reads lines of database tables
Open SQL - Return Codes
-
7/27/2019 Complete Abap Basic
131/728
All Open SQL statements fill the followingtwo system fields with return codes:
sy-subrc
After every Open SQL statement, the system field
sy-subrc contains the value 0 if the operation was
successful, a value other than 0 if not.
sy-dbcnt
p
Open SQL - Client Handling
-
7/27/2019 Complete Abap Basic
132/728
Open SQL Statements use automaticClient-handling
The condition for the client field cannot bespecified in the WHERE clause of the
open SQL statement.
If the client has to be specified in an Open
SQL statement, use
CLIENT SPECIFIED Directly after
p g
Open SQL - Reading Data
-
7/27/2019 Complete Abap Basic
133/728
Select Statement Syntax:
SELECT result
INTO target
FROM source[WHERE condition]
[GROUP BY fields]
[HAVING cond]
[ORDER BY fields].
p g
Open SQL Select
Statement (Contd )
-
7/27/2019 Complete Abap Basic
134/728
Statement (Contd.).Clause
\Description
SELECT
result
The SELECT clause result defines the
structure of the data that is to be read. i.e.,
single or several lines, column to be read,
and for identical entriesINTO target Determines the target area into which the
selected data is to be written
FROM
source
Specifies the Database Table or View from
which the data is to be selected.
WHEREcond
Specifies the condition for Selection
GROUP BY
fields
Produces a single line of results from a
group of several lines.A group is a set oflines with identical values for each column
listed in fields
Open SQL - Defining a
Selection
-
7/27/2019 Complete Abap Basic
135/728
Defines the structure of a result set whichis to be read from the database
A single SELECT statement can performfunctions ranging from simply reading a
single line to executing a very complicated
database query
Aggregate functions can be applied to
individual columns.
Selection
Open SQL - Example
-
7/27/2019 Complete Abap Basic
136/728
Specifying a flat work area as the target.
SELECT ... INTO [CORRESPONDING
FIELDS OF] wa ...
DATA wa TYPE spfli.
SELECT * INTO CORRESPONDING FIELDS O
F wa FROM spfli WHERE carrid EQ 'LH'.
WRITE: / wa-carrid, wa-connid, wa-
cityfrom, wa-cityto.
p p
Open SQL - Example
-
7/27/2019 Complete Abap Basic
137/728
Specifying an internal table as the target.
SELECT ... INTO|APPENDING [CORRESPONDING
FIELDS OF] TABLE itab [PACKAGE SIZE n] ...
DATA wa TYPE spfli.
DATA it_spfli LIKE TABLE OF wa.
SELECT * INTO TABLE it_spfli FROM spfli WH
ERE carrid EQ 'LH'.
LOOP AT it_spfli INTO wa.
p p
Open SQL - ReadingAggregate Data for Columns
-
7/27/2019 Complete Abap Basic
138/728
SELECT lines agg( [DISTINCT] s1) [AS a1]
agg( [DISTINCT] s2) [AS a2] ...
The expression agg represents one of the
following aggregate functions:
MAX: supplies the maximum value of the column
MIN: supplies the minimum value of the column
AVG: supplies the average value of the column
Aggregate Data for Columns
Open SQL Aggregate
Functions
-
7/27/2019 Complete Abap Basic
139/728
Example
DATA: average TYPE p DECIMALS 2,
sum TYPE p DECIMALS 2.
SELECT AVG( luggweight ) SUM( luggweight ) INTO
(average, sum) FROM sbook.
WRITE: / 'Average:', average, / 'Sum :', sum.
Functions
Open SQL - Specifying
Columns Dynamically
-
7/27/2019 Complete Abap Basic
140/728
Examples
DATA: itab TYPE STANDARD TABLE OF spfli,
wa LIKE LINE OF itab.
DATA: line(72) TYPE c, list LIKE TABLE OF
line(72).
line = ' CITYFROM CITYTO '.
APPEND line TO list.
SELECT DISTINCT (list) INTO CORRESPONDING
FIELDS OF TABLE itab FROM spfli.
Columns Dynamically
Open SQL ReadingIndividual Line
-
7/27/2019 Complete Abap Basic
141/728
Example
DATA wa TYPE spfli.
SELECT SINGLE carrid connid cityfrom cityto INTO
CORRESPONDING FIELDS OF
wa FROM spfli WHERE carrid EQ 'LH' AND connid EQ
'0400'.
IF sy-subrc EQ 0.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-
cityto.
ENDIF
Individual Line
Open SQL - Disable
Automatic Client Handling
-
7/27/2019 Complete Abap Basic
142/728
Example:
DATA wa TYPE spfli.
DATA name(10) TYPE c VALUE 'SPFLI.
SELECT * INTO wa
FROM (name) CLIENT SPECIFIED
WHERE mandt = '000'.
WRITE: / wa-carrid, wa-connid.
ENDSELECT.
Automatic Client Handling
Open SQL - Inner Join
-
7/27/2019 Complete Abap Basic
143/728
Data From more than 1 table is read in asingle select statement, such that the data
in all tables has to meet the same
condition.
SELECT ... ... FROM tab [INNER] JOIN
dbtab [AS alias] ON cond options
Open SQL - Inner Join
-
7/27/2019 Complete Abap Basic
144/728
Example
SELECT p~carrid p~connid f~fldate b~bookid INTO
CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS pINNER JOIN sflight AS f ON p~carrid =
f~carrid AND
p~connid = f~connid )
INNER JOIN sbook AS b ON b~carrid =f~carrid AND
b~connid = f~connid AND
b~fldate = f~fldate )
' '
Open SQL Left Outer Join
-
7/27/2019 Complete Abap Basic
145/728
Specifying Two or More Database Tablesas a Left Outer Join
In an inner join, a line from the left-hand
database table or join is only included in the
selection if there is one or more lines in the
right-hand database table that meet the ON
condition cond.
The left outer join, on the other hand, reads
lines from the left-hand database table or join
Open SQL - Left Outer Join
-
7/27/2019 Complete Abap Basic
146/728
Example
SELECT s~carrid s~carrname p~connid INTO
CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS sLEFT OUTER JOIN spfli AS p ON
s~carrid = p~carrid
AND p~cityfrom =
'FRANKFURT'.
Open SQL
-
7/27/2019 Complete Abap Basic
147/728
Values in Intervals
SELECT... WHERE s NOT BETWEEN f1 AND
f2...
Checking List of Values
SELECT... WHERE s NOT IN (f1,......,
fn)...
Open SQL (Contd.).
-
7/27/2019 Complete Abap Basic
148/728
Checking for Null Values
SELECT... WHERE s IS NOT NULL...
Negating Conditions
SELECT... WHERE NOT cond...
Linking Conditions
Open SQL - DynamicConditions
-
7/27/2019 Complete Abap Basic
149/728
SELECT... WHERE (itab)...
SELECT... WHERE cond AND (itab)...
Conditions
Open SQL DynamicConditions
-
7/27/2019 Complete Abap Basic
150/728
Example
DATA: cond(72) TYPE c, itab LIKE TABLE
OF cond.
PARAMETERS: city1(10) TYPE c, city2(10)
TYPE c.
DATA wa TYPE spfli-cityfrom.
CONCATENATE 'CITYFROM = ''' city1 ''''INTO cond.
APPEND cond TO itab.
CONCATENATE 'OR CITYFROM = ''' city2
Conditions
Open SQL - Grouping Lines
-
7/27/2019 Complete Abap Basic
151/728
The GROUP-BY clause summarizes
several lines from the database table into
a single line of the selection
To use the GROUP-BY clause, all of the
relevant columns in the SELECT clause
must be specified.
Example
Open SQL - SelectingGroups of Lines
-
7/27/2019 Complete Abap Basic
152/728
The HAVING clause uses conditions to
restrict the number of groups selected.
The HAVING clause can be used only inconjunction with the GROUP-BY clause.
SELECT lines s1 [AS a1] s2 [AS a2]... agg sm[AS am] agg sn [AS an]...
GROUP BY s1 s2.... HAVING cond.
Groups of Lines
Open SQL - Sorting
-
7/27/2019 Complete Abap Basic
153/728
Specifying a Sort Order
The ORDER BY clause sorts the lines in the
selection according to the contents of their
columns
Sorting by the Primary Key
SELECT lines * ...ORDER BY PRIMARY KEY.
Sorting by any Columns
Open SQL - SubQueries
-
7/27/2019 Complete Abap Basic
154/728
A sub query is a special SELECT
statement containing a sub query within
particular conditions of the WHERE or
HAVING clauses
It cannot be used in the ON condition of
the FROM clause
SELECT carrname INTO TABLE name_tab FROM
scarr WHERE EXISTS
( select * FROM spfli WHERE carrid =
Open SQL - Insert
-
7/27/2019 Complete Abap Basic
155/728
Inserting Lines into Table
INSERT INTO .
One or more lines can be inserted into the
database table .
Inserting a Single Line
INSERT INTO VALUES
Open SQL Insert
-
7/27/2019 Complete Abap Basic
156/728
Inserting Several Lines
INSERT FROM TABLE
[ACCEPTING DUPLICATE KEYS].
Open SQL - Update
-
7/27/2019 Complete Abap Basic
157/728
To Change data in the Database Table
UPDATE .
UPDATE SET ...
[WHERE ].
UPDATE FROM .
UPDATE FROM TABLE .
Open SQL - Delete
-
7/27/2019 Complete Abap Basic
158/728
To delete Lines from the Database Table
DELETE [FROM] .
DELETE FROM WHERE .
DELETE FROM .
DELETE FROM TABLE itab .
Open SQL - Modify
-
7/27/2019 Complete Abap Basic
159/728
Inserting or Changing Lines
To insert lines into a database table
regardless of whether there is already a line in
the table with the same primary key
MODIFY .
MODIFY FROM
MODIFY FROM TABLE .
Open SQL CommitRollback
-
7/27/2019 Complete Abap Basic
160/728
Committing Database Changes
For confirming or undoing database updates
COMMIT WORK always concludes a
database LUW and starts a new one
ROLLBACK WORK always undoes all
changes back to the start of the database
LUW.
Rollback
Native SQL
-
7/27/2019 Complete Abap Basic
161/728
Native SQL statement begins with the
EXEC SQL statement, and ends with the
ENDEXEC statement.
There is no period (.) after Native SQL
statements.
Using inverted commas () or an asterisk
(*) at the beginning of a line does not
introduce a comment as it would in normal
Native SQL - Example
-
7/27/2019 Complete Abap Basic
162/728
DATA: BEGIN OF wa,
connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF wa.DATA c1 TYPE spfli-carrid VALUE 'LH'.
EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto INTO :wa
FROM spfli WHERE carrid = :c1
ENDEXEC.
Modularization Techniques
-
7/27/2019 Complete Abap Basic
163/728
ABAP programs are modular in structure
and made up of processing blocks
Two kinds of processing blocks
Called from outside a program by ABAP
runtime system
Event Blocks
Dialog Modules
Modularization Techniques(Contd.).
-
7/27/2019 Complete Abap Basic
164/728
The modularization of ABAP programs in
event blocks and dialog modules serves
for general execution of ABAP programs
Modularization in procedures and source
code modules serves for
Improving the readability
Maintainability of ABAP programs,
(Contd.).
Defining Processing Blocks
-
7/27/2019 Complete Abap Basic
165/728
Event Blocks
Introduced by an Event Keyword
Ends when the next processing block begins
Event keywords have the same name as the
events to which they react
Dialog Modules
Procedures
-
7/27/2019 Complete Abap Basic
166/728
Contains a set of statements, and are
called from other ABAP programs
Procedures are defined in ABAP Programs
When the program is generated, they
remain as standalone modules.
Procedures have an interface for passing
data and can also contain local data
Subroutines
-
7/27/2019 Complete Abap Basic
167/728
Used for local modularization
Generally called from the program from
which it is defined
Use subroutines to write functions that are
used repeatedly within a program
Defining Subroutines
Subroutines - Example
-
7/27/2019 Complete Abap Basic
168/728
FORM header.
WRITE: / 'Program started by',
sy-uname,
/ 'on host', sy-host,
'date:', sy-datum, 'time:',
sy-uzeit.
ULINE.
ENDFORM.
Subroutines - ParameterInterface
-
7/27/2019 Complete Abap Basic
169/728
The USING and CHANGING additions in
the FORM statement define the formal
parameters of a subroutine
When a subroutine is called, all formal
parameters must be filled with the values
from the actual parameters
At the end of the subroutine, the formal
parameters are passed back to the
e ace
Subroutines (Contd.).
-
7/27/2019 Complete Abap Basic
170/728
Subroutines has the following formal
parameters
Parameters Passed by Reference
Parameters passed by Value
Parameters Passed By Reference
Parameters are listed after USING or
CHANGING without VALUE addition
Subroutine - Example
-
7/27/2019 Complete Abap Basic
171/728
DATA: num1 TYPE i, num2 TYPE i, sum TYPE i.
num1 = 2. num2 = 4.PERFORM addit USING num1 num2 CHANGING
sum.
num1 = 7. num2 = 11.
PERFORM addit USING num1 num2 CHANGINGsum.
FORM addit USING add_num1TYPE any add_num2
TYPE any CHANGING add_sum TYPE any.
add_sum = add_num1 + add_num2.
PERFORM out USING add_num1 add_num2
add_sum.
Subroutines - Pass by Value
-
7/27/2019 Complete Abap Basic
172/728
The formal parameter occupies its own memory
space
The value of the actual parameter is passed to the
formal parameter
If the value of the formal parameter changes, this
has no effect on the actual parameter
Pass By Value - Example
-
7/27/2019 Complete Abap Basic
173/728
DATA: num TYPE i VALUE 5, fac TYPE i VALUE 0.
PERFORM fact USING num CHANGING fac.
WRITE: / 'Factorial of', num, 'is', fac.
FORM fact USING value(f_num) TYPE I
CHANGING f_fact TYPE i.
f_fact = 1.
WHILE f_num GE 1.
f_fact = f_fact * f_num.f_num = f_num - 1.
ENDWHILE.
ENDFORM.
Function Modules
-
7/27/2019 Complete Abap Basic
174/728
Function modules are procedures that are
defined in special ABAP programs called
function groups
Function groups act as containers for
function modules that logically belong
together.
Function groups and function modules are
created in the ABAP Workbench using the
Types of Function Modules
-
7/27/2019 Complete Abap Basic
175/728
Normal Function Module
Remote Function Module
Update Function Module
Function Groups
-
7/27/2019 Complete Abap Basic
176/728
Function groups are containers for
function modules
Function Groups cannot be executed
When a function module, is called the
system loads the whole of its functiongroup into the internal session of the
calling program
Function Modules
-
7/27/2019 Complete Abap Basic
177/728
INCLUDE LTOP.
INCLUDE LUXX.
INCLUDE LF.
INCLUDE.
FUNCTION-POOL
TABLES : ..TYPES:.....
DATA:.
INCLUDE LU01.
INCLUDE LU02.
INCLUDE LU03.
FORM ..
..
ENDFORM.
FUNCTION
.
ENDFUNCTION
Main Program
SAPL
Include Programs
S f
Function Modules (Contd.).
-
7/27/2019 Complete Abap Basic
178/728
The main program SAPLfgrp contains
nothing but the INCLUDE statements for
the following include programs:
LfgrpTOP : This contains the FUNCTION-
POOL statement (equivalent for a function
group of the REPORT or PROGRAM
statement) and global data declarations forthe entire function group.
LfgrpUXX : This contains further INCLUDE
E ti h dli i th i t l t f
Exception Handling
-
7/27/2019 Complete Abap Basic
179/728
Exception handling is the integral part of
the designing the application.
By raising the exception, we are providing
the opportunity to the Caller program to
handle the exception in its own way.
When creating a reusable component like
the Function Module,
Create the exception,
I th F ti d l th
Exception Handling (Contd.).
-
7/27/2019 Complete Abap Basic
180/728
In the Function module, there are
situations when it is not advisable to
process further because of, for example,
missing data, conversion, etc.
At that point of time, raise the excepetion.
For this, we need to define the Exception
under the tab "Exception" in the Function
Builder.
RFC I t f
Remote Function Module
-
7/27/2019 Complete Abap Basic
181/728
RFC Interface
A remote function call is a call to a function
module running in a system different from the
caller's.
The remote function can also be called from
within the same system (as a remote call), butusually caller and callee will be in different
systems
RFC i t f th f ll i i t f
RFC Function Module -Interfaces
-
7/27/2019 Complete Abap Basic
182/728
RFC consists of the following interfaces:
A calling interface for ABAP programs
Any ABAP program can call a remote function
using the CALL FUNCTION.. DESTINATION
statement.
The DESTINATION parameter tells the SAP
System that the called function runs in a system
other than the caller's.
RFC communication with the remote system
happens as part of the CALL FUNCTION
C lli i t f f SAP
RFC Function Module -Interfaces
-
7/27/2019 Complete Abap Basic
183/728
Calling interfaces for non-SAP programs
When either the caller or the called partner is
a non-ABAP program, it must be programmed
to play the other partner in an RFCcommunication.
To help implement RFC partner programs innon-SAP Systems, SAP provides External
Interfaces
It i f E ti i U d t T k
Update Function Module
-
7/27/2019 Complete Abap Basic
184/728
It is for Execution in Update Task
The update Function is not Remotely
Callable
All database updates are processed at the
end of the SAP LUW in contrast to normalFM call where the database updates are
done and commited at the time of call
(Database LUW).
Wh th F ti M d l i t d th
Update Function Module(Contd.).
-
7/27/2019 Complete Abap Basic
185/728
When the Function Module is created, the
Process Type Attribute is set to
Start Immediately
Set this option for high priority ("V1") functions that
run in a shared (SAP LUW). These functions can
be restarted by the update task in case of errors.
Immediate start but no restart
Set this option for high priority ("V1") functions that
run in a shared (SAP LUW). These functions may
not be restarted by the update task
S f ABAP St t t l d
Source Code Modules
-
7/27/2019 Complete Abap Basic
186/728
Sequence of ABAP Statements are placed
in a module
When the program is generated, the
source code in the modularization unit is
treated as though it were actually
physically present in the main program
ABAP Contains two source code modules
When the same set of statements has to
Macros
-
7/27/2019 Complete Abap Basic
187/728
When the same set of statements has to
be reused more than once in a program,
it can be included in a Macro.
Macro can only be used within the
program in which it is defined.
These statements can contain up to nine
placeholders (&1, &2,...., &9).
DATA: result TYPE i n1 TYPE i VALUE 5 n2
Macros Example
-
7/27/2019 Complete Abap Basic
188/728
DATA: result TYPE i, n1 TYPE i VALUE 5, n2
TYPE i VALUE 6.
DEFINE operation.
result = &1 &2 &3.output &1 &2 &3 result.
END-OF-DEFINITION.
DEFINE output.
write: / 'The result of &1 &2 &3 is', &4.
END OF DEFINITION
They are global R/3 Repository objects
Include Programs
-
7/27/2019 Complete Abap Basic
189/728
They are global R/3 Repository objects
The functions of Include Programs are
Library
It allows the usage of same source code in
different programs
Order
The names of specific developed objects
Naming Standards
-
7/27/2019 Complete Abap Basic
190/728
The names of specific developed objects
are identified, at the beginning of the word
(mostly), by characters Y or Z.
First character Y is reserved for Core system
First character Z is reserved for Localsystems
When standard SAP object will be copied,original name will be preceded by Y for a
core development and Z for a local one.
Packages allow a grouping of
Naming Standards -Packages
-
7/27/2019 Complete Abap Basic
191/728
Packages allow a grouping of
development objects and facilitate the
configuration management.
They guarantee that all objects of a topic
are correctly transported.
Every specific object must be linked to a
development class if it must be
transported.
-
7/27/2019 Complete Abap Basic
192/728
Data Dictionary
Data Definitions are created and Managed
Data Dictionary
-
7/27/2019 Complete Abap Basic
193/728
Data Definitions are created and Managed
in ABAP Dictionary
Describes the logical structure of objects
use in application development
Provides standard functions for editingfields on screens
Object Types in ABAP Dictionary are
ABAP Dictionary
-
7/27/2019 Complete Abap Basic
194/728
Object Types in ABAP Dictionary are
Tables
Defined in Dictionary
Independent of Database
Views Logical Views
Types
Data elements
Structures
Table Types
Domain
Integration in ABAP Workbench
Data Dictionary
-
7/27/2019 Complete Abap Basic
195/728
Integration in ABAP WorkbenchDEVELOPMENT ENVIRONMENT
ABAP
Tools
Data
Modeler
Screen
Painter
ABAP
Dictionary
Runtime Environment Of The Application
ABAPInterpreter
ScreenInterpreter
Interfaces.
DialogControl
Integration with ABAP Runtime
Data Dictionary
-
7/27/2019 Complete Abap Basic
196/728
Integration with ABAP Runtime
Environment
Changes can be made to the Dictionary
Objects before being activated
Objects can both be Active and Inactive in the
ABAP dictionary
Inactive Objects have no effect on runtime
System
Domain
Basic Objects
-
7/27/2019 Complete Abap Basic
197/728
Domain
Contains Technical Characteristics of a Field
Field Length
Data Type
Defines a Value Range
Can be restricted by defining Fixed Values
Domain
-
7/27/2019 Complete Abap Basic
198/728
Fixed Values
Used to restrict the values in the Domain
Used in input check in screen templates
If no other help is defined in field, Fixed Values
are offered in F4 help.
Value Range or Intervals can be defined by
specifying the upper and lower limits
Domain
-
7/27/2019 Complete Abap Basic
199/728
Fixed Values
Fixed Values are defined only for the following data
types
CHAR
NUMC
DEC
INT1 INT2
INT4
Relationship between Field Data Element
Domain
-
7/27/2019 Complete Abap Basic
200/728
Relationship between Field, Data Element
and Domain
DOMAIN
DATA ELEMENT 1 DATA ELEMENT 2
TABLE 1 TABLE 2 TABLE 3
Data Type and Field Length are consistent
Value Tables
Tables
-
7/27/2019 Complete Abap Basic
201/728
Value Tables
When a domain is defined, all the table fields
or structure component referring to this
domain can be checked against a table, theValue Table
A check is not implemented by simplyentering a value table.
The check against the value table only takes
Specifies the Semantic Characteristics of
Data Elements
-
7/27/2019 Complete Abap Basic
202/728
Specifies the Semantic Characteristics of
a Field
Describes an elementary type or a
Reference Type
Elementary type is defined by built-in data
type and length
These attributes can be defined directly or
Contains Field Label
Data Elements
-
7/27/2019 Complete Abap Basic
203/728
Contains Field Label
Field Labels are used to display a screen field
F1 Documentation
The text appearing in the Field Help (F1 Help)comes from the documentation
If there is no Documentation, the short text
Defined Independent Of Database
Tables - Introduction
-
7/27/2019 Complete Abap Basic
204/728
Defined Independent Of Database
Fields are defined with Data types and
Length
On activation of the Table, a physical table
definition is created in the database
Table Types
T t T bl
One-to-one relationship with tables in
Transparent Tables
-
7/27/2019 Complete Abap Basic
205/728
One to one relationship with tables in
database
Most commonly Used
Holds Application data
Master data or Transaction data Used by an
application
Many-to-One Relationship with the table in
Pooled Tables
-
7/27/2019 Complete Abap Basic
206/728
Many to One Relationship with the table in
Database
SAP Proprietary Construct
Stored in a Table Pool
Table Pools Hold large number of small
Tables
Holds CUSTOMIZING data
Pooled Tables (Contd.).
-
7/27/2019 Complete Abap Basic
207/728
Holds CUSTOMIZING data
Codes, Field Validations, number ranges,
parameters
Country Code table, Exchange Rate Table,
etc..,
Data in Customizing Table is set by
Functional Consultant during the initial
I l t ti
Definition of table pool contains 2 Key
Pooled Tables (Contd.).
-
7/27/2019 Complete Abap Basic
208/728
Definition of table pool contains 2 Key
fields
Tabname
Varkey (Contains Entry from all key fields)CA B
Pooled Table TAB A
E FD
Pooled Table TAB B
Key
Key
Data
Data
Table Pool in Database
TAB A
TAB B
A B C
E FD
Tab name Var Key DataLn Vardata
Many-to-One relationship with table in
Cluster Table
-
7/27/2019 Complete Abap Basic
209/728
Many to One relationship with table in
database
Cluster tables are stores in Table Cluster
in Database
Used when the tables have a part of
Primary Key in common
D t d Si lt l
Restrictions
Pooled and Clustered table
-
7/27/2019 Complete Abap Basic
210/728
Restrictions
Secondary Indexes cannot be created
Cannot Use ABAP/4 Constructs
Select DISTINCT
GROUP BY
Cannot Use Native SQL
C t S if Fi ld i ORDER BY
Components
Tables
-
7/27/2019 Complete Abap Basic
211/728
Components
Table Fields
Technical Settings
Foreign Keys
Indexes
Field Name
Table Fields
-
7/27/2019 Complete Abap Basic
212/728
e d a e
Should begin with an Alphabet
Key Flag
Determines the Primary Key
Field Type
Data Type
Field Length
Decimal Places
Number of Decimal Places
Sh t T t
Reference Fields required for the following
Reference Tables andReference Fields
-
7/27/2019 Complete Abap Basic
213/728
q g
Data Type
QUAN
CURR
Reference Fields should of Type
UNIT
CUKY
Reference Fields can be in the same table
Data Class
Technical Settings
-
7/27/2019 Complete Abap Basic
214/728
Defines the physical area of the database in
which tables should be created
Size Category
Defines the Expected Space for the table inthe Database
Buffering Permission
Define whether and how a table is buffered
Buffering Type
Full-Buffering
Types
Tables Buffering Types
-
7/27/2019 Complete Abap Basic
215/728
yp
Full Buffering
Either the Full table is Buffered or
The full table is not buffered
Buffered Data Records Sorted by Table Key
When to Use
Tables up to 30KB
Table Accessed Frequently
Most Read Access
Types
Tables Buffering Types(Contd.).
-
7/27/2019 Complete Abap Basic
216/728
yp
Generic Buffering
When a record of the table is accessed, all the
record whose generic key field match that record
is buffered
When to Use
When Certain areas of table are normally used for
processing Client-Specific Tables
Language Specific Tables
Types
Tables Buffering Types(Contd.).
-
7/27/2019 Complete Abap Basic
217/728
yp
Single Record Buffering
Only records that are actually read
Requires less storage space
More DB accesses are necessary to load therecords
When to Use
Select SINGLE is used mostly
Record Size Between 100 200 KB
Creation of Tables
Tables - Transparent
-
7/27/2019 Complete Abap Basic
218/728
Top-Down Approach
Table is first created
Domain and Data element are created after
creation of Table Easier to Use
Bottom-Up Approach
Domain and Data element are created
More intuitive for first timers
Cumbersome
Key Fields must be stored at the beginning
Constraints of TablesCreation
-
7/27/2019 Complete Abap Basic
219/728
y g g
of the field list
Non-Key fields may not occur between two
key fields
Maximum of 16 key fields per table is
allowed
T bl h h 249 fi ld
-
7/27/2019 Complete Abap Basic
220/728
Copy of Database Table reduced to certain
Indexes
-
7/27/2019 Complete Abap Basic
221/728
y
fields
Always in sorted form
Provides faster access to data records
Contains a pointer to corresponding record
of actual table
Indexes
Tables
-
7/27/2019 Complete Abap Basic
222/728
The Primary index of the Table
Secondary Index
Tables - Index
-
7/27/2019 Complete Abap Basic
223/728
Created if the table is frequently accessed
using fields which is not a part of primary key
Index distinguished with a three place
identifier
For certain database systems, the index
improves performance
-
7/27/2019 Complete Abap Basic
224/728
Important in client/server environment
Tables - Buffering
-
7/27/2019 Complete Abap Basic
225/728
Buffers reside in each application server
Improves Performance
Buffers are filled by
Program accesses data of a buffered table
If Program changes data in a table on
Buffer Synchronization
-
7/27/2019 Complete Abap Basic
226/728
Application Server, it is noted in log tableby Database Interface
A synchronization Mechanism runs at a
fixed time interval
Log table is read and buffer contents are
invalidated
Only Transparent and Pooled Tables
Buffering Tables
-
7/27/2019 Complete Abap Basic
227/728
Table that is frequently read and rarely
changed
The key fields of the buffered table should
of the Character data types ( C, N, D, T)
By pass the buffer if table data should be
read from Database
Select . BY PASSING BUFFER
Statements that by passbuffer
-
7/27/2019 Complete Abap Basic
228/728
Select FOR UPDATE
Select With Aggregate Functions
Select DISTINCT ..
Select . WHERE . IS NULL
Defines Relationship between Tables
Foreign Keys
-
7/27/2019 Complete Abap Basic
229/728
Create Value Checks for input fields
Link several tables in a view or a Lock
Object
Tables Foreign Keys
-
7/27/2019 Complete Abap Basic
230/728
Foreign Key Table T1
Field 1 Field 2 Field 3 Field 4
PrimaryKey
Check Table T2
Field 5 Field 6 Field 7
Primary
Key
Comparison
Check Table and Value Table
-
7/27/2019 Complete Abap Basic
231/728
Check Table Value Table
Field Level Data Validation Domain Level Data Validation
Maintained at a client level Maintained as a customization
Object
The contents of the check will
be used as an input help(F4
Help) for a particular field on
which a check table is
assigned.
The contents of Value Table are
not used in Input Help.
Checks are done for the foreign
key table against the check
table entries, once the foreign
key relationship is established.
All table fields referring to the
domain which has a value table
can then be checked against
the corresponding field of this
Text Tables
Tables
-
7/27/2019 Complete Abap Basic
232/728
The table has a additional key field of type
LANGK
1
K
2
F
1
F
2
1 1 X
X
Y
Y
1 2 Y
Y
X
X
K1 K2 L TEXT
1 1 D
E
Text 1 (
German)
1 1 E
N
Text 1
(English)
1 2 D
E
Text 2
(German)
Text Table A for B
Key Fields k1, k2 and L (Type
Lang)
Table B
Key Fields K1, K2
Table Types
Tables
-
7/27/2019 Complete Abap Basic
233/728
Describes the Structure and functional
attribute of an internal table in ABAP
DATA statement in ABAP is used to Reference
the table type
A user interface tool which is used to
What is a Table MaintenanceGenerator
-
7/27/2019 Complete Abap Basic
234/728
change the entry of the table or delete anentry from the table or create an entry for
the table.
To make this feature work care should be
taken while creating the database table
that in the 'Delivery & Maintenance' tab,the 'Table View Maint.' should have the
"Maintenance allowed" property defined.
Choose the table in SE11 for which Table
Table MaintenanceGenerator
-
7/27/2019 Complete Abap Basic
235/728
Maintenance Generator is to be defined.
Generate Table MaintenanceDialog
-
7/27/2019 Complete Abap Basic
236/728
In the Maintenance Screen, the
Maintenance Type
-
7/27/2019 Complete Abap Basic
237/728
Maintenance Type can be
One Step
One Screen is created for Table Maintenance
In SM30, after specifying the table name, the
overview screen is displayed and when choosing
New Entries, the records are entered in the same
screen
Multiple records can be entered at the same time
Generally used as it is user friendly
Structures
About Structures
-
7/27/2019 Complete Abap Basic
238/728
Contains Fields
Fields can refer to
An elementary data type
Another structure
Table type
Types :
Flat Structures
Maintain Foreign Keys if required
Creating Structures
-
7/27/2019 Complete Abap Basic
239/728
Save
Activate the Structure
To add fields of another structure in Tables
Includes
-
7/27/2019 Complete Abap Basic
240/728
or Structures
F1 F2 F3 F4
F5
F3
F4
F1
F2
F3
F4
F5
Structure
Tabl
e
Includes
Database
Only Flat Structures can be included
Structures
-
7/27/2019 Complete Abap Basic
241/728
A Structure can be included more than
once
The field name of the structure should not
be longer than 16 places
Append Structures
Append Structures
-
7/27/2019 Complete Abap Basic
242/728
Used for Table Enhancement
Structure that is assigned to exactly one table
The possible enhancements are
Insert New fields Define Foreign Keys for fields of table
Attach Search Help
View is data derived from one or more
About Views
-
7/27/2019 Complete Abap Basic
243/728
tables
Used in ABAP Program for data selection
Data is not stored physically
F1 F2
F3 F4
F5
F6 F7
F8
Table
T1 Table
T2
Table
T3
F1 F2 F4 F7
F8
View on tables
Database View
Types of Views
-
7/27/2019 Complete Abap Basic
244/728
Projection View
Maintenance View
Help View
Provides application specific view on data
Database View
-
7/27/2019 Complete Abap Basic
245/728
distributed in tables
Created in the database
accessed using Open SQL and Native
SQL
If there is only one table in the view , write
access is ossible
Used to hide fields of a table
Projection View
-
7/27/2019 Complete Abap Basic
246/728
Contains exactly one table
Selection conditions cannot be defined
Pooled and Clustered tables can beaccessed as the projection view is not
stored in the database
Allows To maintain data of an Application
Obj t
Maintenance View
-
7/27/2019 Complete Abap Basic
247/728
Object
All the tables in this view must be linked
with foreign keys
Join Conditions cannot be directly
specified
Im lements Outer Join
Created if a view with outer join is needed
l ti th d f h h l
Help View
-
7/27/2019 Complete Abap Basic
248/728
as selection method of search help
All tables in help view must be linked with
foreign Key
Implements Outer Join
Used to Display list of all possible input
l f fi ld th f F4
About Search Help
-
7/27/2019 Complete Abap Basic
249/728
values for a screen field on the press of F4
Useful when the field requires the input of
a formal key
Has to be assigned to the screen field
Types of Search Helps
Elementar
Selection Method
Selection Method
-
7/27/2019 Complete Abap Basic
250/728
Possible input values are determined at
runtime by database selection
If the values are from a single table, the
corresponding table is selected as selection
method
If the values are from multiple tables, they
must be linked with a view (Database or Help
Defines the fields of selection method that
h ld b d i i t h l
Search Help Parameters
-
7/27/2019 Complete Abap Basic
251/728
should be used in input help
Data element should be assigned to
Search Help Parameter
Import and Export Param