Professional Documents
Culture Documents
Agenda
1
Objectives
ABAP Dictionary
Data Declarations
Report Development
Q&A
End of Meeting
Objectives
Chapter
Objectives
This course will enable you to:
Acquire knowledge of ABAP Workbench components and capabilities
Learn the basics of ABAP
Chapter
Presentation and
user interaction with
the system
Programs required
to process a
business transaction
Contains the
database
R/3 Repository
Database contains, along with the Repository, application and customizing tables that are
usually client-specific.
Repository objects are not client-specific (cross-client).
Presentation
Server
Layer
Application
Server
Layer
ABAP Program
Cross-client
Database
Repository
Client-specific
Customizing tables
Application tables
Change
Request
Development System
Production System
Transport Requests
Workbench Organizer: Transportable Requests
Report source
ZBC400_00_GETTING_STARTED
Request
IT3K900051
Double-click
on the
request number
ABAP Dictionary
Chapter
Dictionary Transactions
SE15
DATA DICTIONARY
SE11
DATA BROWSER
SE16
SM30
TABLE MAINTENANCE
SM31
DB objects
Type definitions
Table
Structure
DB Table
Data elements Table type
Services
Poss. Values
Screen
F4
F4
Table
Table
field
uses
Data Element
uses
Domain
Personnel No.
NUMC10
PO No.
Invoice No.
DOMAIN
DATA ELEMENT
MANDT
Table:: SPLFI
SPLFI
Table
CARRID CONNID ... AIRPFROM ... AIRPTO
Domain S_AIRPID
Table: SCARR
Carrier ID
AA
DL
LH
SA
UA
Name
American
Delta
Lufthansa
Singapore
United
Tables
Table - a two-dimensional matrix which describes a relation in the database system, each
row in a table contains precisely one data value or each of the fields defined in the table
structure
Rows (tuples)
Carrier ID
AA
DL
LH
UA
...
Primary key
Carrier Name
American Airlines
Delta
Lufthansa
United Airlines
...
(Field) values
Table
Field 1 Field 2
ABAP Dictionary
Field 3 Field 4
Field 1 Field 2
Structure
Field 3 Field 4
Database
Table
Field 1
Field 2
Field 3
Field 4
Size category: determines the space required for a table in the database
Buffering type: determines whether and how a table is to be buffered
Single, Generic, Full, Not Buffered
Logging: automatic logging of database changes by users for the table (for row
size < 455)
Organizational data
Table 1
Table 3
Table 4
Table 2
Table 6
Transaction data
Table 5
Table 9
System data
Table 7
Table 8
Database
Tablespace
Master data
Table 1
Table 3
Table 4
Tablespace
Tablespace
Table 2
Table 6
Table 5
Table 9
Org. data
Trans. data
Tablespace
System data
Table 7
Table 8
First
Extent
Second
Extent
Database
TABA
TABB
TABC
Size category
TABA
TABB
TABC
Application server 2
Program
Table buffer
Program
Table buffer
TAB
Database
CARRID
AA
BA
BA
BA
BA
LH
LH
LH
LH
LH
LH
LH
LH
UA
Buffer contents
COUNTNUM
AIRPORT
00000001
00000001
00000002
00000003
00000004
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000001
ACA
ACE
BER
LCY
LHR
BER
DEN
FRA
LCY
LGW
LHR
MUC
RTM
HAM
001
001
001
001
001
001
001
001
001
001
001
001
001
001
AA
BA
BA
BA
BA
LH
LH
LH
LH
LH
LH
LH
LH
UA
00000001
00000001
00000002
00000003
00000004
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000001
ACA
ACE
BER
LCY
LHR
BER
DEN
FRA
LCY
LGW
LHR
MUC
RTM
HAM
Application server
SELECT * FROM SCOUNTER WHERE
MANDT = '001' AND CARRID = 'LH'
AND COUNTNUM = '00000004'.
CARRID
COUNTNUM
Buffer contents
AIRPORT
001
AA
00000001
ACA
001
LH
00000001
BER
001
BA
00000001
ACE
001
LH
00000002
DEN
001
BA
00000002
BER
001
LH
00000003
FRA
001
BA
00000003
LCY
001
LH
00000004
LCY
001
BA
00000004
LHR
001
LH
00000005
LGW
001
LH
00000001
BER
001
LH
00000006
LHR
001
LH
00000002
DEN
001
LH
00000007
MUC
001
LH
00000003
FRA
001
LH
00000008
RTM
001
LH
00000004
LCY
001
LH
00000005
LGW
001
LH
00000006
LHR
001
LH
00000007
MUC
001
LH
00000008
RTM
001
UA
00000001
HAM
Application server
Generic key
CARRID
COUNTNUM
Buffer contents
AIRPORT
001
AA
00000001
ACA
001
BA
00000001
ACE
001
BA
00000002
BER
001
BA
00000003
LCY
001
BA
00000004
LHR
001
LH
00000001
BER
001
LH
00000002
DEN
001
LH
00000003
FRA
001
LH
00000004
LCY
001
LH
00000005
LGW
001
LH
00000006
LHR
001
LH
00000007
MUC
001
LH
00000008
RTM
001
UA
00000001
HAM
001
LH
00000004
LCY
Application server
SELECT SINGLE * FROM SCOUNTER WHERE
MANDT = '001' AND CARRID = 'LH' AND
COUNTNUM = '00000004'.
No
Yes
Table may be buffered.
Yes
Full buffering
No
Is the table mostly accessed with
SELECT SINGLE?
Yes
No
Is the expected table size larger
than 1MB (>> 1000 records)?
Yes
No
Yes
Is a left-justified part of the
key usually specified when
the table is accessed
No
Single-record buffering
Indexes
To improve performance, database indexes are created in the Data Dictionary via
transparent tables
Index on
AIRPORT
SELECT
SELECT* *FROM
FROM
SCOUNTER
SCOUNTERWHERE
WHERE
AIRPORT
AIRPORT==LHR.
LHR.
Binary
search
AIRPORT P
ACA
1
ACE
2
BER
3
BER
6
DEN
7
FRA
8
HAM
14
LCY
4
LCY
9
LGW 10
LHR
5
LHR
11
MUC 12
RTM
13
Database Views
A view is a virtual table that doesnt physically contain any data, information is generated at run-time
A view is a definition based on the relationship between one or more tables
Benefits of views:
Allows for restricting or limiting the access to information by areas, plants, etc.
Reduces the need to create new tables with specific data for each application.
Can be used to improve performance. Using a view is more efficient than programming nested selects or joins.
ABAP program
F1
F2
F3
F5
F8
Database interface
Is created in the
DB during activation
F1
F1
F2
Table 1
F3
View definition in
the database
F2
F3
F4
F5
Table 2
F5
F8
F6
F7
F8
Table 3
ID
001
NAME
122356
MANDT
Smith
CARRID
CITY
...
New York
...
SCUSTOM
CONNID
FLDATE
BOOKID
CUSTOMID
...
001
AA
48
...
3689
122356
...
001
LH
324
...
3690
122356
...
CONNID
... CITYFROM
...
CITYTO
...
New York
...
Berlin
...
MANDT
CARRID
001
AA
48
...
001
LH
324
...
Berlin
...
Tokyo
SBOOK
SPFLI
...
ID
NAME
CITY
CARRID CONNID
FLDATE
001
122356 Smith
New York
AA
48
4.9.1999
3689
001
122356 Smith
New York
LH
324
9.9.1999
3690
New York
Berlin
Berlin
Tokyo
Search Helps
offer the advantage of being able to return multiple field values to the underlying screen
The search key is invoked automatically from a search help when the user presses the F4
key to display allowable values for the field.
The Search path used the last
time is displayed, user may
choose a different search path
User chooses
F4 on field
Selection
Method
(transparent
table)
Fields
(search help
components)
Dialog Type
34
Search Helps
2 Types of Search Helps:
Elementary search help - this search help corresponds to a search path. The
elementary search help must define where the data of the hit list should be read
(selection method), how the exchange of values between the screen mask and selection
method is implemented (interface of the search help) and how the online input help
should be defined (online behavior of the screen help).
Collective search help - this search help comprises several elementary search helps.
It combines all the search paths which make sense for a field.
Search Help
Data Browser
Chapter
ABAP Editor
Menu path: Tools>ABAP Workbench>Development>ABAP Editor
Transaction code: SE38
Used to develop, debug, and run programs
F4
F4
REPORT
sbc400_carrier.
TABLES
DATA
wa_sbc400 TYPE sbc400_carrier.
PARAMETERS pa_car TYPE scarr-carrid.
ABAP
KEYWORD
START-OF-SELECTION.
SELECT SINGLE * FROM scarr
INTO CORRESPONDING FIELDS OF wa_sbc400
WHERE carrid = pa_car.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_sbc400 TO sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier TO wa_sbc400.
WRITE wa_sbc400-carrid COLOR COL_KEY.
WRITE wa_sbc400-carrname.
ENDIF.
COMMENT
COMMENT
CHAINED
STATEMENT
Definition of Structure
(or of structured field)
Keyword Documentation
Keyword Documentation in the Editor
Editor
Help
START-OF-SELECTION.
SELECT SINGLE * FROM scarr
Editor Help
INTO wa_scarr
ABAP Overview
WHERE
carrid = pa_car.
ABAP Term
WRITE
IF
sy-subrc
=
0.
ABAP News
MOVE-CORRESPONDING wa_scarr TO
ABAP Docu and Examples
sbc400_carrier.
CALL SCREEN 100.
MOVE-CORRESPONDING sbc400_carrier
TO wa_scarr.
WRITE
WRITE: wa_scarr-carrid,
F1 wa_scarr-carrname,
wa_scarr-currcode.
Keyword
ENDIF.
Documentation
New Session
Pattern Pushbutton
allows the user to insert statement templates into the program code by providing a skeleton
for the program code
It is possible to select one of the following:
CALL FUNCTION - inserts a function call.
MESSAGE - inserts a MESSAGE statement for a specified message. Enter a message ID,
message type, and a number.
SELECT * FROM - inserts a SELECT from <table> statement. Enter the table name in the
field provided.
PERFORM - inserts a PERORM statement for a specified form routine.
AUTHORITY - CHECK - inserts an AUTHORITY - CHECK statement for a specified
authorization object.
WRITE - inserts a WRITE statement for a specified structure or table.
CASE for status - inserts a CASE statement for a specified status.
Internal table - inserts an internal table. It is possible to copy the fields or the structure of
an existing table.
CALL DIALOG - inserts a CALL DIALOG statement for a specified dialog module.
Other pattern - inserts a predefined or user-defined ABAP statement.
After selecting a statement in code, fill out the template as the program requires.
Pattern Pushbutton
Ctrl + F6
Program Checks
In the ABAP Editor, Program>Check
SYNTAX
CHECK
EXTENDED
PROGRAM CHECK
CODE INSPECTOR
ABAP Editor
Data Declaration
Chapter
Data Types
DATA TYPE
Pre-Defined
User Defined
(P,I,F,C,N,D,T,X)
Elementary
Structured
Structure Type
Table Type
Initial value
Standard
length
type
type
Permitted
length
numeric
Meaning
packed number
1-16
integer
0.000...
alpha-numeric
Data type
numeric text
00...0
1-max.
text
blank
1-max.
date (YYYYMMDD)
00000000
time (HHMMSS)
000000
hexadecimal
X'00'
1-max.
R
TYPE <ABAP-data-type>.
DATA: <varname>
TYPE <user-defined-type>.
LIKE <ABAP-dictionary-object>.
. . . VALUE <literal>
. . . DECIMALS <n>
TYPE I,
TYPE C,
TYPE D,
TYPE I VALUE 1,
TYPE P DECIMALS 2.
0000
00000000
0001
00000
TYPE <ABAP-data-type>.
TYPES: <varname>
TYPE <user-defined-data-type>.
LIKE <ABAP-dictionary-object>.
CONSTANTS: pi
TYPE P DECIMALS 4 VALUE '3.1415',
boss(4) TYPE C VALUE 'Hugo'.
Number literals
715, -431
Text literals
'abc', '2.17', '1.213E15', '0FFF', 'A''B'
Sequence of characters enclosed in
apostrophes. Max. 255 chars
Literal type
Assigning Values
There are a number of ABAP statements which assign a value to a field. One of
the most important is the MOVE statement.
The equals symbol = can also be used to assign a value to a field. In this case
the field on the left of the equals symbol is assigned the value of the
field/literal/arithmetic expression on the right.
If the type and length of the field does not match the assigned value, the system
carries out automatic type conversion.
Assigning Values
MOVE <data object1> TO <data object2>.
<data object2> = <data object1>.
TYPES: BEGIN OF rec_type,
flag
TYPE c,
name(30) TYPE c,
sum_field TYPE p DECIMALS 2,
END OF rec_type.
DATA: name(25)
TYPE c,
sort_name
LIKE name,
first_line(4)
TYPE n,
rec1
TYPE rec_type,
rec2
TYPE rec_type.
MOVE BEN' TO name.
MOVE 5 TO FIRST_LINE.
sort_name
= name.
rec2
= rec1.
Type Conversion
Fields of type C are stored left-justified and filled with blanks from the right if they
are longer than the destination field.
If a field of type C is assigned to a field of type P, only figures, the plus/minus
sign, and the decimal point are allowed otherwise a RUNTIME ERROR will
occur.
If a packed field is assigned to a field of type C, the numerical value is formatted
(commas to separate thousands, decimal comma, sign) and the leading zeros
are converted to blanks (see WRITE statement).
If this type of formatting is undesirable, use the UNPACK statement.
Depending on whether the packed field is defined with decimal places, the
appropriate number of figures after an existing decimal point are transferred from
the C field:
For example: C field
-47.110
P field (DECIMALS 2)
47.11-
For a list of all possible type conversions and their results, refer to the online
documentation for the MOVE statement.
Target field
Source field
Type
Length
1
Value
A8
Type
Length
Value
A____
ABCD
AB
-47110
47110-
12345-
12.345-
pack
text3
rec2 text1
YYYYY
pack
text3
0000000000072.34 Z
rec2 text1
pack
AAABB C ? ? ?
text3
?
BEGIN OF rec_type,
flag TYPE C,
carrid LIKE spfli
- carrid,
connid LIKE spfli
- connid,
END OF rec_type.
DATA: wa_spfli LIKE spfli,
rec TYPE rec_type.
SELECT mandt carrid connid from spfli
INTO CORRESPONDING FIELDS OF wa_spfli.
...
MOVE
- CORRESPONDING wa_spfli TO rec.
MANDT
401
CARRID
LH
CONNID
2407
...
wa_spfli
CARRID
LH
CONNI D
2407
rec
SOMEWHERE
PARAMETERS Statement
The PARAMETERS statement is used to declare fields for use within a program.
In contrast to fields declared with the DATA statement, the user is prompted to
enter initial values for these fields on a selection screen when the program is
invoked. The user supplies the necessary value(s) and then clicks on the
Execute pushbutton to execute the program.
Some of the additions of the DATA statement can also be used with the
PARAMETERS statement (for example, TYPE, LIKE, DECIMALS, etc.).
While DATA allows the assignment of initial values to fields with VALUE,
PARAMETERS allows the assignment of a default value with DEFAULT. These
default values are shown on the selection screen. The user does have the ability
to change these values prior to clicking on the Execute pushbutton.
Fields defined using the PARAMETERS statement can be used within a program
in the same way as fields defined using the DATA statement.
Note - the length of PAR1 and PAR2 is defined by the standard lengths
belonging to the field type.
PARAMETERS Statement
PARAMETERS <field>.
REPORT YA70D050.
PARAMETERS: p_PAR1 TYPE P,
p_PAR2
DEFAULT 'X'.
..
.
MOVE
p_PAR1 TO ... .
P_PAR1
P_PAR2 X
Selection
Screen
P_PARM1
P_PARM2
P_PARM3
300
p_PARM1
p_PARM2
p_PARM3
p_PARM4
Group G1
Group G2
SELECT-OPTIONS Statement
SELECT-OPTIONS: <field> FOR <type>.
S_CARR
TO
RANGES Statement
Effect of SELECT-OPTIONS
System Fields
SYSTEM FIELD
Name
Type
Length
SY-DATUM
DATE
SY-UZEITTIME
Meaning
Date
Time
SY-UNAME
CHAR
12
User Name
SY-SUBRC
HEX
Return code
SY-RAPID
CHAR
Program name
SY-LANGU
CHAR
Logon language
Report Development
Chapter
WRITE Statement
The WRITE statement outputs the contents of a field or constant in a format appropriate to
the data type. ABAP data types will be discussed in detail during the next topic, ABAP
Data.
Successive WRITE statements output data, separated by one space, on the same
output line. When an output line is full, output continues on the next line.
The SKIP statement generates blank lines.
WRITE <varname>.
WRITE <constant>.
WRITE : <var1>, <var2>, <constant>.
DATA :
first_name(15) TYPE C,
last_name(15) TYPE C.
MOVE : MY FNAME TO first_name,
MY LNAME TO last_name.
WRITE FIRST NAME:.
WRITE first_name.
WRITE : / Full Name:, first_name, last_name.
first_name(15) TYPE C,
last_name(15) TYPE C.
first_name = MY FNAME.
last_name = MY LNAME.
WRITE / FIRST NAME:.
WRITE /12(15) first_name.
WRITE AT /25(15) Full Name:.
WRITE (2) last_name.
DATA:
FORMAT Statement
FORMAT [INTENSIFIED] [INTENSIFIED OFF]
[COLOR color] [COLOR OFF]
[INVERSE] [INVERSE OFF]
[RESET]
DATA :
first_name(15) TYPE C,
last_name(15) TYPE C.
MOVE :
MY FNAME TO first_name,
MY LNAMETO last_name.
FORMAT COLOR 7.
WRITE FIRST NAME:.
FORMAT RESET.
FORMAT INTENSIFIED.
WRITE first_name.
FORMAT INTENSIFIED OFF.
FORMAT INVERSE.
WRITE : / Full Name:, first_name, last_name.
Text Elements
REPORT Z170D037.
WRITE: TEXT-001, 10 SY-Datum . . . .
'Time'(002), 10 SY-UZEIT . . .
ABAP Text Elements: Change Text Symbols
Text elements
Text symbols
Program name
ZDEMO001
Lang. E
Text - Text
Symbol ....+....1....+....2....+....3....+
Date
001
Date
002
Time
Time
01.01.1996
21:07:54
Text Symbols are maintained using the TEXT ELEMENTS function either from the
editors initial screen, from within the editor Edit -> Text elements, or from the
program code (Goto -> Text elements), or by double-clicking on the text(003) word.
The primary advantage of Text symbols is that they can be managed separately for
different languages (Goto -> Translation).
MESSAGE Statements
CONSTANTS c_ua TYPE s_carr_id VALUE 'UA'.
READ TABLE itab INTO wa_itab WITH TABLE KEY carrid = c_ua.
IF sy-subrc <> 0.
*Message
MESSAGE ID 'BC400' TYPE 'I'
NUMBER '041' WITH wa_itab-carrid.
ELSE.
MESSAGE ID 'BC400' TYPE 'I'
NUMBER '040' WITH wa_itab-carrid wa_itab-carrname
ENDIF.
Message classBC400
BC400
Message:
040
047: The name of the airline &1 is &2
041
048: Airline &1 is not available
Meaning
Behavior
Message appears in
Status Message
Program continues
without interruption
Information
Program interrupted
Warning
Depends on context
Error
Depends on context
Termination
Program aborted
Short dump
Runtime Error
MESSAGE_TYPE_X
WRITE Statement
a = (B+EXP(C))*E/SIN(3-G).
a = ( B + EXP( C ) ) * E / SIN( 3 - G ).
Operators
+ DIV
/ *
MOD **
SQRT EX P LOG
SIN COS STRLEN
TAN ...
PROGRAM ....
DATA: counter
TYPE I,
amount
TYPE P VALUE 1000,
sum
TYPE P,
result
TYPE P,
number(2)
TYPE C VALUE '99',
root
TYPE F.
counter = counter + 2.
result = amount * counter.
sum = result + number
- counter.
result = counter * ( amount + number ).
root = sqrt( number + counter ).
NAME (30).
NAME(10) = ' Dr..
NAME+10(10) = 'Michael.
NAME+20(10) = 'Hofmann'.
CONDENSE NAME.
WRITE NAME.
NAME = NAME+4(14).
WRITE NAME.
Date Calculations
If a date field is assigned to a packed field, ABAP calculates the number of days
since the beginning of the year 1900.
Conversely, if a packed field is assigned to a date field, it is interpreted as the
number of days since the beginning of the year 1900.
Before an arithmetic operation is performed, the values of the date fields are
converted to packed values (number of days since the beginning of the year
1900).
Beware - it is not possible to ADD 1 to the current month like: DATE_2 (6) =
DATE_2 (6) +1
In this case a conversion is made and the field no longer contains 19980331 but
00000431!
Date Calculations
PROGRAM YA70D049.
DATA: v_DIFF TYPE P,
v_DATE_1 LIKE SY-DATUM,
v_DATE_2 LIKE SY-DATUM.
* Initialize to value of System Date
v_DATE_1 = SY-DATUM.
V_DATE_2 = SY-DATUM.
ABAP Events
ABAP is event driven. This means that program processing is not necessarily carried out
in the order which the code is written in. It is processed in the established events
sequence.
INITIALIZATION - processed prior to the display of the Selection Screen.
AT SELECTION-SCREEN - processed immediately after the selection screen is
processed.
START-OF-SELECTION - processed immediately after INITIALIZATION.
GET - retrieves data from a logical database (this will be discussed later in this course).
GET LATE - processed after all records in a lower logical database hierarchy have been
processed (this will be discussed later in this course).
END-OF-SELECTION - processed at the end of the program, after all GET events.
TOP-OF-PAGE - processed before the first Write statement of a new page.
AT LINE-SELECTION - picks up lines for drill-down reports (drill-down reports are not
covered in this course).
INITIALIZATION.
P_NAME = SY-UNAME.
P_DATE = SY-DATUM - 1.
START-OF-SELECTION.
WRITE: / P_NAME.
WRITE: / P_DATE.
AT-SELECTION-SCREEN Event
The event AT SELECTION-SCREEN is processed after the selection screen
from a program is processed. For example, the selection screen is brought up
on-screen, the user enters data, and then clicks the Execute button. Before any
code starts, the code after the AT SELECTION-SCREEN command is executed.
The event AT SELECTION-SCREEN is particularly useful to check user input for
valid or implausible values. The user can then reprocess the screen if the initial
data input was invalid.
Every error message processed at the event AT SELECTION-SCREEN
immediately stops the execution of the report and displays the selection screen
again. All selection criteria can be changed.
In the example above, if the user doesnt enter any data but clicks the Execute
button anyway, the message Please enter some data pops up, and the
selection screen is reprocessed.
AT-SELECTION-SCREEN Event
REPORT ZABAP.
PARAMETERS:
AT SELECTION-SCREEN.
IF P_NAME <> .
MESSAGE I999 WITH Please enter some data.
ENDIF.
START-OF-SELECTION.
WRITE: The current user is, P_NAME.
REPORT YA01DH01.
SELECTION-SCREEN BEGIN OF BLOCK B1
WITH FRAME TITLE TITLE1.
PARAMETERS: P_INT1 TYPE I DEFAULT 20,
P_INT2 TYPE I.
SELECTION-SCREEN END OF BLOCK B1.
INITIALIZATION.
TITLE1 = TEXT-001.
Processing Data
Case distinction
IF
CASE
ENDIF
ENDCASE
DO
WHILE
ENDDO
ENDWHILE
Loops
CONTINUE
* previous command
log_expr_1
true
Block 1
Statement block 1
false
log_expr_2
true
Block 2
false
false
log_expr_n
false
Block n+1
Next statement
true
optional
Block n
ELSE
ELSE.
Statement block n+1
ENDIF
ENDIF .
* next command
do_1 = do_2
true
Block 1
false
do_1 = do_3
or
do_1 = do_4
* previous command
CASEdo_1.
CASE
WHENdo_2.
Statement block 1
true
Block 2
WHEN do
_3 OR
ORdo _4 ..
Statement block 2
false
optional
true
false
Block n+1
Next statement
Block n
Statement block n
WHEN OTHERS
OTHERS
WHEN
.
Statement block n+1
ENDCASE .
* next command
WHEN OTHERS.
statements
ENDCASE.
IF <logical expression>.
statements
ELSE.
ENDIF.
statements
<operator>
<literal> ...
<field2> ...
DATA:
start
sum1
IF sum2 GE 1000.
IF start IS INITIAL.
IF sum1 GT sum2 AND
sum1 BETWEEN 0 AND 100.
IF sum1 = 1000 AND
( sum2 LE 2000 OR
start IS INITIAL ).
IF NOT start IS INITIAL.
TYPE D,
TYPE P,
sum2
Operator
EQ
NE
GT
GE
=
<>
>
>=
LT
LE
<
<=
TYPE P.
Meaning
=>
Equal
Unequal
Greater than
Greater than or equal
=<
Less than
Less than or equal
><
BETWEEN f1 and f2
Interval
IS INITIAL
Initial value
DO [ < n>
TIMES ].
statements
statements
ENDWHILE.
ENDDO.
DO.
WRITE / sy-index.
IF sy-index > 10.
EXIT.
ENDIF.
ENDDO.
SY-INDEX
Loop index
counter = 10.
WHILE counter > 0.
statements
In this section the focus is on the 1st application, conditional termination of a loop
pass. The other uses for the CHECK statement will be discussed in later
sections of the course.
The CHECK statement is accompanied by a logical expression (i.e. v_counter >
1, v_date = 03/22/1999).
When the logical expression accompanying the CHECK is TRUE, processing of the loop
pass continues without interruption.
When the logical expression accompanying the CHECK is FALSE, the subsequent
statements in the current loop pass are skipped and processing resumes with the next
loop pass.
Key point -> A FALSE CHECK does not terminate the loop, it only affects the
current loop pass.
Report Output
Report ZEXAMPLE
-------------------The index value is 8
The index value is 9
The index value is 10
Flags
Flags are a good way to keep track of variable changes or first time loop entries/
exits. A flag can be defined as simply as a one character variable which initially
is left blank and populated when a change occurs.
Flags are often teamed up with IF statements and used to help determine the
next step of the program based on their value.
REPORT ZEXAMPLE.
DATA: FLAG TYPE C.
DO 3 TIMES.
IF FLAG IS INITIAL.
WRITE: / First Time Through.
FLAG = X.
ELSE.
WRITE: / Hello!.
ENDIF.
ENDDO.
Report Output
Report ZEXAMPLE
-------------------First Time Through
Hello!
Hello!
Control Statements
Internal Tables
Internal tables are tables which are defined within an ABAP program and exist
only within system memory. They are not stored or maintained in the database.
These tables are used within programs for temporary storage and processing
and are not meant for long term storage of information.
An internal table consists of a number of identically structured table lines.
Internal tables fulfil the same function as arrays in C. They are dynamic data
objects (dynamic in that they are created at runtime) and save the programmer
the task of dynamically managing memory within his or her ABAP program.
Internal tables are the best way of including complicated data structures within
an ABAP program.
Internal Tables
Data type
Predefined
(P, I, F, C, N, D, T, X)
User-defined
Elementary
Structure type
Structured
Table type
standard key - made up of all non-numeric fields (columns) in the internal table
user-defined key - made up of fields specified by the user (in this example, the field
PERSBR is the key)
Table type - The table type defines how ABAP accesses individual table entries. There
are 3 types of internal tables (STANDARD, SORTED and HASHED), each with a
different access method. These will be discussed in more detail later in this section.
TYPES: itabtype TYPE table_kind OF line_type WITH key_def [INITIAL SIZE n].
DATA:
TABLE KIND
STANDARD TABLE
KEY_DEF
[NON-UNIQUE] KEY col1coln
DEFAULT KEY
SORTED TABLE
HASHED TABLE
New
Syntax
PROGRAM Z30_EXAMPLE.
TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6)
TYPE N,
LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA:
I_EMPLTAB TYPE T_EMPLOYEE OCCURS 10,
WA_EMPLTAB TYPE T_EMPLOYEE.
Old
Syntax
DATA
TYPES: BEGIN OF
struc ,
name(10) TYPE c,
age(3) TYPE n,
END OF struc .
TYPES: itab _type TYPE
STANDARD TABLE OF
struc
WITH KEY name.
DATA : itab
TYPE itab _type.
atab
TYPE atab
_type.
DATA : btab
LIKE STANDARD
TABLE OF spfli WITH KEY
carrid.
The availability of 3 different internal table types is new for SAP 4.0. Prior to 4.0,
the standard table was the only table type.
Sorted
Hashed
Key access
Table Scan
Access time
for n entries
Binary Search
Hash Function
Increases linearly
(O(n))
Increases
logarithmically
(O(log(n)))
Predominantly index
Predominantly key
Key only
NONUNIQUE
UNIQUE | NON-UNIQUE
UNIQUE
Constant
Access using
Uniqueness
APPEND
APPEND wa_itab to itab.
Insert
INSERT
Read
Change
Delete
DELETE
DELETE itab <condition>.
itab <condition>.
wa_itab <condition>.
wa [<condition>].
0017
0400
MODIFY <itab>
DELETE <itab>
SORT <itab> BY <field1><fieldn>.
CLEAR < itab >.
CONNID
0017
0400
CONNID
0017
0400
APPEND <itab>.
MODIFY <itab> INDEX <n>.
LOOP AT <itab>.
WRITE <itab>-< field>.
ENDLOOP.
tables without a header line) the work area <wa> at the end of the internal table.
The maximum number of table entries is determined by the INITIAL SIZE
(OCCURS in R/3) parameter. If there is no space in the table for a further entry,
the last table entry is written to the roll area.
The APPEND <tab> SORTED BY <f> statement adds a new entry to an internal
table and sorts the table by field f in descending order. Again, the maximum
number of table entries is determined by the INITIAL SIZE parameter. However,
with this variation of the APPEND statement, if there is no space in the table for
a further entry, the last table entry is removed. This variation, therefore, is
most commonly used for created ranked lists - the top ten companies according
to sales figures, for example.
Internal table
SPFLI
AA
SELECT
0026
AA
0026
APPEND
it_flightinfo
CARRID
CONNID
...
AA
0026
...
SPFLI
0017
0017
0026
0026
0064
it_flightinfo
CARRID
CONNID
...
AA
AA
AA
AA
AA
0017
0017
0026
0026
0064
...
...
...
...
...
The sequence in which the entries occur in the loop depend on the table type specified in the table
definition (unless the table has been explicitly resorted using the SORT statement:
STANDARD TABLE: The system processes entries according to their logical index. At the beginning
of a loop pass, SY-TABIX is set to the logical index of the current table entry.
SORTED TABLE: The system processes entries according to their sort order. As with standard
tables, the system sets SY-TABIX to the logical index of the current table entry.
HASHED TABLE: The system processes entries in the order in which they were inserted into the
table. Since hashed tables have no logical index, SY-TABIX is always set to 0.
REPORT sapbc400itd_itab_loop.
DATA: it_ flightinfo LIKE TABLE OF spfli WITH KEY carrid.
DATA: wa_ flightinfo LIKE spfli.
SELECT * FROM spfli INTO TABLE it_flightinfo.
LOOP AT it_flightinfo INTO wa_flightinfo FROM 5 TO 10.
WRITE: / wa_flightinfo-carrid,
ENDLOOP.
LOOP AT it_flightinfo INTO wa_flightinfo
WHERE carrid = 'LH'
.
WRITE: / wa_ flightinfo-carrid, wa_flightinfo -connid...
ENDLOOP.
IF sy- subrc NE 0.
WRITE: 'No records met selection criteria.'.
ENDIF.
Internal Tables
SY-TABIX
R
REPORT sapbc400itd_itab_change_index.
:
MOVE: 'LH' to wa_flightinfo-carrid,
'0400' to wa_flightinfo-connid.
READ TABLE it_ flightinfo INTO wa_ flightinfo
FROM wa_flightinfo.
MOVE NEW YORK' TO wa_flightinfo-cityfrom .
MODIFY it_ flightinfo FROM wa_flightinfo INDEX sy- tabix.
IF sy-subrc
NE 0. ...ENDIF.
..
INSERT wa_flightinfo INTO it_ flightinfo INDEX 5.
IF sy-subrc
NE 0. ...ENDIF.
..
.
DELETE it_ flightinfo INDEX 3.
IF sy-subrc
NE 0. ...ENDIF.
REPORT sapbc400itd_itab_change_key.
MOVE: 'LH' to wa_flightinfo-carrid,
0400 to wa_flightinfo-connid.
READ TABLE it_flightinfo FROM wa_flightinfo INTO wa_flightinfo.
IF sy-subrc <> 0. ENDIF.
MOVE NEW YORK TO wa_flightinfo-cityfrom.
MODIFY TABLE it_flightinfo FROM wa_flightinfo.
IF sy-subrc <> 0. ENDIF.
..
INSERT wa_flightinfo INTO TABLE it_flightinfo.
..
.
DELETE TABLE it_flightinfo FROM wa_ flightinfo.
IF sy-subrc NE 0. ENDIF.
DELETE <itab>.
..
ENDLOOP.
CLEAR <wa>.
Work area<wa>
CARRID
AA
LH
CONNID
0017
0400
DELETE <itab>.
DELETE <itab> WHERE <logical Expression>.
DELETE <itab> FROM <index1> TO <index2>.
wa_table-field1 = JET.
wa_table-field2 = 25.
COLLECT wa_table INTO it_table .
Field1
Field2
-------------- ------1 JET
225
2 PLANE
100
3 CAR
300
Internal Tables
ABAP
Open SQL Native SQL
Database interface
Which columns?
SELECT
<result>
FROM <table>
INTO <target>
Where to?
WHERE <condition>
Which entries?
GROUP BY <fields>
ORDER BY <fields>.
Single line
}
Particular
column
Which tables?
Several lines
seltab >.
ENDSELECT.
=
>=
<=
NE
GT
LT
<>
>
<
=>
=<
><
table entry
multiple condition using logical gates like AND, OR, NOT, if required
It then locates the table entry meeting the WHERE condition in the table work area
Its return code (SY-SUBRC) is:
0 : if it does locate a table entry
4 : if such a table entry does not exist in the defined table work area
INTO <wa>
...
...
Table fields and work area fields have the same names
REPORT sapbc400ddd_select_single.
DATA wa_spfli LIKE spfli.
Table SPFLI
SELECT SINGLE
carrid connid airpfrom airpto
FROM spfli
INTO CORRESPONDING FIELDS OF wa_spfli
WHERE carrid = 'LH' AND connid = '400'.
WRITE: / wa_spfli-carrid, wa_spfli-connid,
wa_spfli-airpfrom, wa_spfli-airpto.
INTO <wa>
...
...
SELECT loop
Table SPFLI
ENDSELECT.
2nd pass
ENDSELECT.
REPORT B170D069.
TABLES: TABNA.
DATA: W_ID
LIKE TABNA-ID,
W_COUNTRY LIKE TABNA-COUNTRY
SELECT DISTINCT ID COUNTRY
INTO (W_ID, W_COUNTRY)
FROM TABNA.
statements
ENDSELECT.
TABNA
Country
AU
AU
USA
USA
USA
ID
12345678
22009520
10034766
22009520
99985763
TABNA
Country
1st pass
2nd pass
AU
AU
USA
USA
USA
ID
12345678
22009520
10034766
22009520
99985763
Aggregate Expressions
A number of Aggregate Expressions can be specified as part of the SELECT
statement.
The Aggregate Expressions currently available are:
AVG( )
MAX( )
MIN( )
SUM( )
Aggregate Expressions
TABNA
Country
REPORT B170D06A.
TABLES: TABNA.
DATA: W_TOTAL TYPE I,
W_HIGH_ID LIKE TABNA-ID,
W_LOW_ID LIKE TABNA-ID.
SELECT COUNT( DISTINCT ID )
MAX( ID )
MIN( ID )
FROM TABNA INTO (W_TOTAL, W_HIGH_ID,
W_LOW_ID).
statements
ENDSELECT.
AU
AU
USA
USA
USA
ID
12345678
22009520
10034766
22009520
99985763
After SELECT :
W_TOTAL
4
W_HIGH_ID
99985763
W_LOW_ID
10034766
SELECT Statements
Subroutines
Large programs need modularization. Subroutines can be used to break
programs into logical groups.
Subroutines keep the source code clearer and allow the reuse of program
sections.
When a program contains several identical or similar statement sequences,
repetition can be avoided through the use of subroutines.
Subroutines can receive parameters and change parameters.
For the sake of clarity, all subroutines should be grouped together at the start or
end of a program. This is automatically done if systems tools are used to create
them.
Subroutines
PROGRAM RSDEM001.
Calculate tax
PROGRAM RSDEM004.
Call calculate_tax
Call calculate_tax
Calculate tax
Subroutine
Calculate_tax
Defining a Subroutine:
FORM subroutine USING lp1 lp2.
...
...
ENDFORM.
Calling a Subroutine:
PERFORM subroutine USING f1 f2.
Example:
PERFORM CALCULATE_TAX USING FL1.
FORM CALCULATE_TAX USING F1.
CLEAR ITAB.
MOVE:
F1
TO ITAB-FL1.
APPEND ITAB.
ENDFORM.
By Value - When parameters are passed by value, any changes to the parameter
(formal parameter) during the execution of the subroutine wont affect the original
variable (current parameter).
TABLES - Tables can only be passed by reference to a subroutine. The TABLES
parameter must always appear first in the FORM statement, before any USING or
CHANGING.
CHANGING - The CHANGING option passes parameters by value, but also transfers
any change of a parameter value back to the original variables when ENDFORM is
reached. This option is only appropriate for recursive subroutine calls, for which the
variable shouldnt be changed immediately but only when the subroutine ends.
USING
Pass By Reference
Pass By Value
TABLES
Pass By Reference
CHANGING
Parameters Example
When calling a subroutine, data is transferred. Data determined within the
subroutine is passed back to the calling program.
When a subroutine is declared, Formal Parameters are defined.
When a subroutine is called, Current Parameters are specified, which are then
assigned to the formal parameters according to the sequence in the parameter
list. The calling program and the called program communicate with one another.
It is more efficient (i.e. cost effective) to pass by reference than to pass by value.
Parameters Example
Current Parameters
PERFORM CALCULATE_TAX USING FL1 FL2.
FORM CALCULATE_TAX USING F1 F2.
CLEAR ITAB.
MOVE F1 TO ITAB-FL1.
APPEND ITAB.
ENDFORM.
Formal
Parameters
Passing Parameters
Both fields or tables of the current program can be included as current
parameters. Both are passed by reference.
Field and field strings are passed with the keyword USING.
Putting VALUE immediately before the parameter name allows the developer to
specify the formal parameters and defines a pass by value.
TYPE identifies the type of each of the formal parameters being passed.
The method for passing parameters determines how the formal and current
parameters are stored and how/if they are updated.
Pass by Value - When the subroutine is called, the formal parameters are copies of the
current parameters, with their own storage location.
Pass by Value and Result - The formal parameters have a separate storage location.
At the end of the subroutine, the value of the formal parameter is passed to the storage
location of the current parameter assigned to it.
Pass by Reference -The address of the current parameter is passed. When called, the
formal parameters are not allocated a separate storage location.
Passing Parameters
PROGRAM <name>.
TABLES:
....
DATA: ....
.
.
.
PERFORM <name> USING
<a1> <a2>
<a3> <a4>.
.
.
.
FORM <name> USING
VALUE(<f1>)
VALUE(<f2>)
<f3>
<f4>.
<statements>
a1
a2
f1
f2
a3
a4
Pass by value
Pass by reference
ENDFORM.
X1 Y1
Call Subroutine
Subroutines
Passed Parameters
DATA:
X Y
local data
statements
Passes Parameters
Data:
local data X1
statements
Y1
Subroutines
Debugging
Tool used to identify and eliminate errors in ABAP programs
Allows the verification of program logic in a step-by-step manner by examining
the results of individual statements
Key Debugging Concepts
Debugger modes
Examining the value of variables
Changing the value of variables
Setting breakpoints
Setting watchpoints
Viewing contents of internal tables
Object List
Development object ... ... ...
...
Test/execute
...
Debugging
Program
B170D051
Any screen
Breakpoints
/h
...
Utilities
...
...
Debug ABAP
...
Debugging Display
The source code window displays the statements currently being executed or
may be used to scroll through the code to set breakpoints.
Breakpoints are identified with a stop sign
The field evaluation window displays the value of selected fields.
F5 single step; commonly used for watching values or thorough step by step
process
F6 almost the same with single step but skips sub-routines
F7 for forwarding to the next break-point or finishing a loop
F8 run execution
Debugging Display
Debugging Mode
When entering the debugger there is a choice of 6 different views:
Fields - Displays the fields content and technical characteristics.
Table- Displays the contents of an internal table.
Breakpoint - Interrupts a program at a given line of code. Breakpoints can be static or
dynamic.
Watchpoint - Interrupts a program only when there is a change in the contents of a
particular field or filed string. It is possible to define multiple watchpoints, attach
conditions to them, and link two or more watchpoints using a relational operator.
Calls - Displays an active event chain and the call sequence up to the current
breakpoint. The most recent active call appear at the top of the list and the previous
calls appear underneath.
Overview - Displays the structure of the programs being debugged. This view shows the
event names and event types within a program and indicates which section is currently
being used.
Settings - Displays the different options and error handling a user has when debugging.
Debugging Mode
Execute
Continue
Table
Breakpoint
Watchpoint
Editor
Hexadecimal display
Replace
Setting Breakpoints
ABAP Editor
Debugging Mode
Menu:
Utilities
-> Breakpoints
Keyword:
BREAK-POINT
Watchpoints
A watchpoint is a signal within a programs code that tells the ABAP runtime processor to
interrupt a program at a particular point in the code.
Watchpoints are set from the debugger. Set and remove watchpoints as needed.
Watchpoints are field-specific. Use a watchpoint to observe the changes to a particular
field. The debugger interrupts the program when the fields contents change.
Watchpoints can be set either locally and globally. Global watchpoints are valid in all
programs that is called. Local watchpoints are only valid within a specified program.
Watchpoints:
Up to five watchpoints can be defined.
Conditional watchpoints using <, <=, =, <>, >=, >.
Can combine watchpoints with AND or OR.
Local and global watchpoints ( i.e. stop only in my program).
Menu from Debugging mode: Breakpoint -> Create Breakpoint.
Watchpoints
High Reusability
Clear import and
export parameters
STRING_CONCENATE/
READ_CALENDAR/
CURRENCY_CONVERSION/
ACCOUNT_CHECK/ ...
Search
Create
Change
Document
Application
Exception
Test Environment
handling
Function Groups
Several logically related function modules are combined in a function group
(also known as a function pool). Logically related function modules are typically
function modules that perform similar functions and/or use the same data).
Function modules contained in the same function group can share common data
declarations.
To create or maintain a function group, select Goto -> Function Groups -> Create
Group from the initial screen of the ABAP Function Builder transaction.
Function Groups
ABAP Function Builder: Initial Screen
Tools
ABAP Workbench
Function module
Function Builder
.
.
Function groups
.
.
....
How to call a
Function Module
CALL FUNCTION
'FM_02'
EXPORTING ...
IMPORTING ...
TABLES ...
(EXCEPTIONS ...)
Interfaces
One of the key differences between function modules and subroutines is the clearly
defined formal parameter interface.
Import parameters correspond to the formal input parameters of subroutines. They pass
data from the calling program to the function module. A default value can be assigned to
each import parameter in the Proposal column. This value may be a system field value
(ex. SY-DATUM), a literal that is enclosed in inverted commas, or the predefined field
SPACE. Import parameters with proposed values are optional. If no such parameter is
specified when the function module is called, the proposed value is used.
Changing parameters are import parameters which will be passed back to the calling
program (their values may or may not have been changed).
Export parameters correspond to the formal output parameters of subroutines. They are
optional - the calling program need only specify those parameters for which it wants a
value returned.
Struct./field column allows to specify a reference structure/field for a parameter. By
specifying these, it improves the run-time of function modules.
The Type column allows the specification of a user-defined data type.
Import values are passed by value. Changing and Export parameters are passed by
reference.
Interfaces
Import/Export Parameters Z_FUNC_DEMO1
Import parameters
Parameters
Struct./field
Type
Type
Type
Ref.
Changing parameters
Parameters
Struct./field
Export parameters
Parameters
Struct./field
Exception Processing
Table Parameters/Exceptions STRING_SPLIT
Exceptions
NO_DATA
DATA_NOT_VALID
STRING_TOO_LONG
...
FUNCTION STRING_SPLIT.
...
IF ...
RAISE NO_DATA.
ENDIF
Import
Parameters
Export
Parameters
L<gr> TOP
FUNCTION-POOL <gr>.
DATA: X.
TABLES: ... .
Function module
Subroutines
L<gr> U01
L<gr> F01
FUNCTION ... .
DATA:... .
MOVE X TO ... .
ENDFUNCTION.
Function Modules
R/3
Presentation
server
Mainframe
RFC with
C-interface
RFC
RFC
RFC
AP
R/3
System
RFC
System
AP
DB
R/3
System
DB
Tools
Tools
Tools
ABAP Workbench
ABAP Workbench
ABAP Editor
Function Builder
Function module
Z_FUNC_DEMO1
ABAP Workbench
Create
Function Builder
Administration
Import/Export
Import/Export Parameters
Parameters
Up to 30 characters long
Alphanumeric and underscore only
Table Parameters/Exceptions
Documentation
Source code
ZGR1
Basis (System)
Z_ANOTHER_FUNC_MOD
Process type
Normal
Remote Function Call supported
.
.
.
Function Modules
60 minutes
ALV Reporting
The ALV grid control ( ALV = ABAP List Viewer ) is a flexible tool
for displaying lists.
This allows you to use the ALV grid control in a wide range of
application programs.
Title
Generic Function
of the Toolbar
Output Table in
the Grid Control
ALV Constraints
The ALV grid control does not allow you to display block or hierarchical
lists. Currently, simple lists can be displayed in single line format only.
However, users can define multiple-line format in the print preview and
print the list as such.
A
B
C
Type1
Type2
Type3
Data
Dictionary
Field
Catalog
<name>
A B C
DECLARATION OF
REFERENCE VARIABLES
DATA grid TYPE REF TO
cl_gui_alv_grid
DATA container TYPE REF TO
cl_gui_custom_container
Screen
a1 b1 c1
a2 b2 c2
a3 b3 c3
Data
Internal Table
a1 b1 c1
a2 b2 c2
a3 b3 c3
List Display
GRID
( Linked to Screen
through container
A B C
Container with
Integrated ALV
Control
Flush
Subroutine Build_Table
Form Build_Table Using
P_FIELDNAME,
P_TABNAME,
P_REFFIELD,
P_FIELDTEXT.
Clear <FieldCat_Itable>.
<FieldCat_Itable>-row_pos
= 1.
<FieldCat_Itable>-col_pos
= l_column.
<FieldCat_Itable>-fieldname
= P_FIELDNAME.
<FieldCat_Itable>-seltext_l = P_FIELDTEXT.
<FieldCat_Itable>-ref_tabname
= P_TABNAME.
<FieldCat_Itable>-ref_fieldname
= P_REFFIELD.
Append <FieldCat_Itable>.
Endform.
Form Build_Layout.
Clear <Layout>.
<Layout>-no_input
= X.
<Layout>-colwidth_optimize
= X.
<Layout>-window_titlebar = SY-TITLE.
Endform.
ALV Reporting
TYPE-POOLS: SLIS.
Types: Begin of T_Mara.
Include Structure MARA.
Types: End of T_Mara.
Data: I_Mara Type Table of T_Mara,
W_Mara Type T_Mara.
ALV Declaration
Data : V_FIELDCAT type SLIS_T_FIELDCAT_ALV
with Header Line,
V_LAYOUT type SLIS_LAYOUT_ALV,
V_REPID like SY-REPID.
Data : V_EVENTS type SLIS_T_EVENT.
Subroutine USER_COMMAND
Form USER_COMMAND
Using R_UCOMM like sy-ucomm
RS_SELFIELD type SLIS_SELFIELD
Perform the Necessary Command Here
Endform.
Chapter
Customer
Customer system
system
Customer
Customer
program
program
Sequential
Sequential
file
file
SAP
SAP System
System
SAP
SAP
program
program
Processing Files
Before data records can be read from a file or written
to a file, the file must be opened.
The file is closed again after processing (i.e. after the
read/write operations have been completed).
Within an ABAP program, a file is referenced to by its
absolute file name. The absolute file name is made
up of the precise path and the actual file name, for
example, '/tmp/bc180/d01' or c:\myfile. Note, file
names may or may not be case sensitive depending
on the underlying operating system
Depending on the particular operating system in use,
files may be stored in different directories. Also, file
and path names must conform with different syntax
requirements. This is why platform independent
filenames are often used. The physical name and
location of the file can then be changed through
configuration rather than through program or
parameter changes.
Open
Open file
file
Process
Process file
file
Close
Close file
file
Opening Files
The statement OPEN DATASET <file name> is used to open a file.
Depending on the success, SY-SUBRC is set to 0 or to 8.
When an addition is not provided, the file is opened for reading. Possible
additions:
FOR OUTPUT - opens the file for writing. (If the file already exists, its content is deleted.
If the file does not exist, it is created.)
FOR INPUT - opens an already existing file for reading. (If the file has already been
opened, it returns to the beginning of the file. FOR INPUT does not have to be entered
explicitly.)
FOR APPENDING - opens the file for writing at the end of the file. (If the file does not yet
exist, it is created. If the file has already been opened, only return to the end.)
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
FOR
FOR
OUTPUT
OUTPUT
INPUT
INPUT
APPENDING
APPENDING
Opening Files
When opening a file, it is also possible to choose between binary mode and text mode.
IN BINARY MODE (default)
The content of the file is not structured in lines. The data areas entered for these
language elements are entered or displayed directly. IN BINARY MODE does not have to
be entered explicitly.
IN TEXT MODE
If a file is opened with this addition, it is assumed that the file is structured in lines. Every
time READ DATASET or TRANSFER is called, exactly one line is always entered or
displayed. If the data area is too large when reading for the line read, the rest is filled
with blanks. If it is too small, the rest of the line is lost. (READ DATASET and
TRANSFER will be detailed in the following sections).
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
FOR
FOR
IN
IN
OUTPUT
OUTPUT
INPUT
INPUT
APPENDING
APPENDING
BINARY
BINARY MODE
MODE (default)
(default)
TEXT
TEXT MODE
MODE
Text mode
ABC
AB
ABCD
ABAP
ABAP
program
program
TRANSFER
ABC
AB
ABCD
TRANSFER
ABCABABCD
READ DATASET
ABAP
ABAP
program
program
A B C
A B A
B C D
A B C
A B
READ DATASET
ABAP
ABAP
program
program A B C
A B
A B C
A B C D
Opening Files
Additions available for the OPEN statement:
AT POSITION <position> - With this addition, an explicit file item
can be entered in bytes from the beginning of the file. The next
reading or write operation occurs then at this point. It is not
possible to position the cursor in front of the beginning of the
file.This addition can be used together with the addition IN TEXT
MODE.
MESSAGE <field> - The field <field> is filled with the relevant
operating system message when an error occurs during file open.
TYPE <attr> - The TYPE parameter allows the specification of
further file attributes. The system passes the contents of the field
<attr> to the operating system without performing any checks.
FILTER <filter> - Under Unix and Windows NT, the field <filter>
can contain an operating system command. Under Unix, the
statement OPEN DATASET DSN FOR OUTPUT FILTER
compress will open the file DSN and then write the output data to
the file in compressed format using the Unix command
compress.
OPEN
OPEN DATASET
DATASET <file
<file name>
name>
AT
ATPOSITION
POSITION <position>
<position>
MESSAGE
MESSAGE
<field>
<field>
TYPE
TYPE
<attr>
<attr>
FILTER
FILTER
<filter>
<filter>
Non-SAP
Non-SAP System
System
SAP
SAP R/2
R/2
SAP
SAP R/3
R/3
Batch Input
Historically, batch input (commonly referred to as BDC - Batch Data
Communications) has been the most popular and widely used method for the
data interchange between SAP and the other information systems.
Use of batch input provides the following features:
Large data volumes can be processed in batch.
Can be scheduled and submitted in the background.
Can be processed automatically without human intervention.
Uses standard SAP transactions, just as if the data were entered manually. This
simulation of a user dialog ensures that data entered via BDC is subject to the same
checks and updates as data entered on line by the user.
Data is entered into another system first and then interfaced to the SAP afterwards.
Batch Input
Non-SAP
Non-SAP System
System
SAP
SAP R/2
R/2
SAP
SAP R/3
R/3
Queue
Batch
Input
Sessions
Application
program
Format checks
Automatic value range check
(against check table or value range)
Conversion of input data into program
data (and vice versa)
Field default values
Automatic
Checks
SAP
Customer
Master Data
Sequential
File
Batch
Batch input
input program
program
Queue
File
Function
Function "Batch
"Batch input"
input"
Vendor
Master Data
Document
Data
ABAP
Dictionary
Structure
Structure
BDCDATA
BDCDATA
READ DATASET
Batch
Batch input
input program
program
BDC
table
CALL FUNCTION
Queue
File
Sequential
File
Screens
SAP
Database
Batch
Batch input
input
Transaction 1
Screen 1
Transaction 2
Screen 2
Screen 1
Screen 2
Log
File
Customer
Master
Data
Vendor
Master Data
Document
Data
Transaction
Transaction (APQD)
(APQD)
...
Session
Session End
End
Open
Open
batch
batch input
input session
session
Enter
Enter
transaction
transaction data
data
Close
Close
batch
batch input
input session
session
BDC_INSERT
BDC_INSERT
Transaction
Transaction code
code
BDC
BDC table
table
BDC_CLOSE_GROUP
BDC_CLOSE_GROUP
CLIENT
CLIENT
GROUP
GROUP
HOLD
HOLD
KEEP
KEEP
USER
USER
TCODE
TCODE
DYNPROTAB
DYNPROTAB
CALL
CALL FUNCTION
FUNCTION BDC_OPEN_GROUP
BDC_OPEN_GROUP
EXPORTING
EXPORTING
CLIENT
CLIENT
GROUP
GROUP
HOLDDATE
HOLDDATE
KEEP
KEEP
USER
USER
==
==
==
==
==
<client>
<client>
<session
<session name>
name>
<lock
<lock date>
date>
<deletion
<deletion indicator>
indicator>
<batch
user
<batch user name>
name>
EXCEPTIONS
EXCEPTIONS RUNNING
RUNNING
QUEUE_ERROR
QUEUE_ERROR
CLIENT_INVALID
CLIENT_INVALID
GROUP_INVALID
GROUP_INVALID
==
==
==
11
22
33
CALL
CALL FUNCTION
FUNCTION BDC_INSERT
BDC_INSERT
EXPORTING
EXPORTING
TABLES
TABLES
TCODE
TCODE
DYNPROTAB
DYNPROTAB
== <transaction
<transaction code>
code>
== <bdc_table>
<bdc_table>
EXCEPTIONS
EXCEPTIONS
INTERNAL_ERROR
INTERNAL_ERROR
== 11
NOT_OPEN
NOT_OPEN
== 22
QUEUE_ERROR
QUEUE_ERROR
== 33
TCODE_INVALID
TCODE_INVALID
== 44
DATA:
DATA: <bdc
<bdc table>
table> LIKE
LIKE BDCDATA
BDCDATA
OCCURS
OCCURS <occurs
<occurs parameter>.
parameter>.
BDCDATA
BDCDATA
Field
Field name
name
Type
Type
Length
Length
Description
Description
PROGRAM
PROGRAM
DYNPRO
DYNPRO
DYNBEGIN
DYNBEGIN
FNAM
FNAM
FVAL
FVAL
CHAR
CHAR
NUMC
NUMC
CHAR
CHAR
CHAR
CHAR
CHAR
CHAR
88
44
11
35
35
80
80
BDC
BDC Module
Module pool
pool
BDC
BDC Screen
Screen number
number
BDC
BDC Starting
Starting aa screen
screen
BDC
BDC Field
Field name
name
BDC
BDC Field
Field value
value
CALL
CALL FUNCTION
FUNCTION BDC_CLOSE_GROUP
BDC_CLOSE_GROUP
EXCEPTIONS
EXCEPTIONS
NOT_OPEN
NOT_OPEN
QUEUE_ERROR
QUEUE_ERROR
==
==
11
22
Customer
4711
Address
Name
Region
Save
Save
Miller
03
BDC Programming
Questions?
SAP ABAP/4 Training
Thank you
SAP ABAP/4 Training
7 January 2017
No. 287