Вы находитесь на странице: 1из 108

Introduction to ABAP Programming

Course Objectives
In this Course, the participant will learn:
ABAP Workbench Environment and Tools
An Introduction to ABAP Programming
Advanced techniques in ABAP Programming
BDCs and Interfacing in the SAP Environment
Enhancements & Modifications to SAP R/3
Designing and Using SAP Forms (SAP Script)
Dialog Programming

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output Statement
Data Declarations in ABAP
Control Statements
SELECT Statement
Internal Tables

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor
Editor and
and basics
Basicsof
ofan
anABAP
ABAPProgram
Program
ABAP

Simple Output Statement


Data Declarations in ABAP
Control Statements
SELECT Statement
Internal Tables

In this section, we will

Introduce the ABAP Programming Language


Explain the ABAP Programming Environment
Elucidate the different functions of ABAP editor
Learn about the Basic ABAP Program structure
Describe the different Program Attributes for
different types of programs
Describe the various methods to run an ABAP
program

ABAP Programming Language

Advanced

Business

Application Programming

Introduction to ABAP

Advanced Business Application Programming


SAPs proprietary language
Byte-code interpreted language
Event-Driven
Tightly integrated with ABAP workbench
Not case sensitive
COBOL-like language
Statement termination mark is Period (.)
No line-continuation mark
Commenting with Asterisk (*) and double-quote ()

Reporting using ABAP

Lists or Reports are produced using Report Programs


Reports can be made interactive by using some ABAP techniques
Programs can be executed both online and in background
Background jobs can be scheduled to run at specified intervals

Terms to Remember
Program
A series of ABAP statements.
Report:
An ABAP program whose output is a list:
Module Pool:
A dialog program which is a collection of screens
List:
The output generated by an ABAP report
program.

The ABAP Editor

Programming Environment: ABAP Editor

Programming Environment: Online Debugging

Basic Functions of the ABAP Editor

Find and
Repeat Find
Syntax
SyntaxCheck
Check
(Ctrl+F2)

Display/change mode
(Ctrl+F1)

Execution (F8)
ABAP help (F1)

Activation
(Ctrl+F3)

Where used list


(Ctrl+Shift+F3)

Standard toolbar

Basic ABAP Program syntax


DATA COUNT TYPE I.
DATA TITLE(25).
MOVE 1 TO COUNT.
MOVE President TO TITLE.
WRITE TITLE.

ABAP Program

WRITE COUNT.

Statement.

Word 1

Keyword or
Statement

Word2

Parameters, fields,
or constants

Word3

Word 4

Additions or
clauses

End of statement

ABAP Program Structure

Program Name Area


Use REPORT for listing programs
Use PROGRAM for online programs
Declaration Section
Used for defining tables,variables and constants

Statement Section
Used for coding executable ABAP statement

Chaining Statements in ABAP


DATA COUNT TYPE I.
DATA TITLE(25).
MOVE 1 TO COUNT.
MOVE President TO TITLE.
WRITE TITLE.
WRITE COUNT.

DATA: COUNT TYPE I,


TITLE(25).
MOVE: 1 TO COUNT,
President TO TITLE.
WRITE: TITLE, COUNT.

Comments in ABAP
A double quotation mark() anywhere on
a line makes everything
that follows a comment.

An asterisk (*) in column 1


makes the entire line
a comment line.

ABAP Program Attributes

ABAP Program Attributes (contd.)

Running an ABAP Program

An Alternative Method:
From the system
Menu,choose Services
->Reporting to launch
the program.

OR

From the ABAP Editor:


With the program displayed,
program->Execute

From the ABAP Editor: Initial Screen, type


the program name, then click on the
Execute push-button.

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output
Output Statement
Data Declarations in ABAP
Control Statements
SELECT Statement
Internal Tables

In this section, we will


Define a simple Hello World program
Explain the WRITE statement and its
variations
Know about ABAP format specifications
Define the NEW-PAGE statement
Explain Page Headers in reports
Describe the use of Text Symbols

The ABAP Hello World Program


report zitatrg1.
write Hello World SAP R/3.

WRITE Statement Simple Form


Syntax:
WRITE [AT] [/P(L)] v1[+O(SL)]
[UNDER v2 | NO-GAP].

Used to output contents of a field (or sub-field)


in a certain format
The output of the WRITE statement is printed
as a List
Specify additions to position, color, mask,
and format variables and print Symbols,
Icons and Lines

WRITE Statement (contd.)


WRITE **************************
SKIP 2.
WRITE:

The date today is:, SY-DATUM,


The current time is: SY-UZEIT.

SKIP 2.
WRITE ***************************.

Note that there is an automatic


space between the fields written
to the list.

< program title>


1
--------------------------------------------------------------------------------******************************
The date today is: 11/14/2001 The current time is:
12:32:06
******************************

ABAP Format Specifications


Write 10 ****City of Mumbai****.
SKIP2.
WRITE: 10 Ticket Date , SY-DATUM.
WRITE: /10 Ticket Time , SY-UZEIT.
ULINE /10(60).
SKIP2.
WRITE 10 ****Department of Public Safety****
**** City of Mumbai****
Ticket Date 11/14/2003
Ticket Time 18:01:00
-------------------------------------------------------------------****Department of Public Safety****

NEW-PAGE Statement
WRITE ****City of Mumbai****
SKIP.
WRITE: / Ticket Date,15 SY-DATUM.
WRITE: / Ticket Time,15 SY-UZEIT.
SKIP.
WRITE ****Department of Public Safety****.
NEW-PAGE.

<program title>

WRITE: Comments:. -----------------------------------------------------------------------------****City of Mumbai****


Ticket Date 11/14/2003
Ticket Time 18:01:00
****Department of Public Safety****
<program title>

_________________________________________________
Comments:

Maintaining Page Headers

List header will replace


title on first line of
standard header
Up to four lines of
column headings can
be maintained for the
list.

Numbered Texts ( Text Symbols )

WRITE: /TEXT-001,
TEXT-002,
SY-DATUM.
Text symbols
are referenced
by a unique
three character
code.

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output Statement
Data
Data Declarations
DeclarationsininABAP
ABAP
Control Statements
SELECT Statement
Internal Tables

In this section, we will

Explain the DATA statement and its variations


Define CONSTANTS
Define User-defined Types and their uses
Describe the various Assignment statements
Explain Arithmetic operators and functions
Using Parameters in report programs
Explain how to define and use Selection texts
Learn about Field Symbols and dynamic
assignment of variables

ABAP Elementary Data Types


C: Character Text

N: Numeric Text

I: Integer

D: Date

P: Packed#

T:Time

F: Floating Point#

X: Hexadecimal#

ABAP Data Types: Initial Value


C: (blank)

N:zeroes

I: zero

D: 00000000

P:zero

T:000000

F:zeroes

X:00

Declaring Variables
Syntax:
DATA v1[(l)] [TYPE t] [DECIMALS d] [VALUE xxx].

DATA: PLAYER(35) TYPE C,


NICKNAME(35),
POINTS TYPE I,
GAMES TYPE I VALUE 10,
AVERAGE(5) TYPE P,
STARTER,
ACQUIRED TYPE D.

Assigning Default Values


DATA: PLAYER(35) TYPE C,
NICKNAME(35)

VALUE Dr.J,

POINTS TYPE I VALUE 255,


GAMES TYPE I VALUE 10,
AVERAGE(5) TYPE P VALUE 25.5,
STARTER

VALUE Yes,

ACQUIRED TYPE D VALUE 20031114.

Declaring Like Fields

DATA : PLAYER(35) TYPE C VALUE Julius Erving,


NICKNAME(35),
ACQUIRED TYPE D.
Use the LIKE addition to declare
fields with the same format (i.e. data
type and length)

DATA: PLAYER(35) TYPE C VALUE Julius Erving,


NICKNAME LIKE PLAYER,
ACQUIRED LIKE SY-DATUM.

Declaring Constants
Syntax:
CONSTANTS c1[(l)] [TYPE t] [DECIMALS d] VALUE xxx.
(OR)

CONSTANTS c1 LIKE cv VALUE xxx.


The VALUE addition is
required.

Constants: TEAM1(120) TYPE C VALUE 76ers,


TEAM2

LIKE TEAM1 VALUE Celtics,

TOT_GAMES TYPE I VALUE 82.

If you attempt to change the value of a constant, a syntax error will occur.

Declaring User- Defined Data Types


Syntax:
TYPES t1[(l)] [TYPE t] [DECIMALS d].
(or)
TYPES t1 LIKE v1.
TYPES: NAME(35) TYPE C,
TEAMS(20) TYPE C.
DATA: PLAYER TYPE NAME VALUE Troy Aikman,
NICKNAME LIKE PLAYER.
CONSTANTS: TEAM1 TYPE TEAMS VALUE Cowboys
TEAM2 LIKE TEAM1 VALUE Packers.

A user-defined data type created with the TYPES statement is used to specify a
fields data type in the TYPE addition of the DATA or CONSTANTS
statements.

Output for Numeric Fields


DATA: FLOAT TYPE F VALUE 98.7654321E2.
PACK TYPE P VALUE 12,
INT TYPE I VALUE 32.
WRITE: / FLOAT,
/FLOAT EXPONENT 1 DECIMAL 3,
/FLOAT EXPONENT 0 DECIMALS 2,
/PACK,
/PACK DECIMALS 1,
/INT DECIMALS 2.

9.876543210000000E+03
987.654E+01
9876.54
12
12.0
32.00

Assigning Values to Fields


MOVE <value> TO <field>.
[COMPUTE] <field> = < value> or <expression>.
ADD <value> TO <field>.
SUBTRACT <value> FROM <field>.
MULTIPLY <field> BY <value>.
DIVIDE <field> BY <value>.

DATA: TITLE(25),
SALARY TYPE P,
CNVSALARY LIKE SALARY.
MOVE President TO TITLE.
COMPUTE SALARY = 5000000.
CNVSALARY = SALARY * 3.
ADD 1000 TO SALARY.

Arithmetic Expressions
Operators

Functions

+ - * / **

SQRT,EXP,LOG,SIN,

DIV and MOD

COS,STRLEN.

COUNTER = COUNTER + 1
SALARY = BASE * BONUS_PERCENT.
LENGTH = STRLEN( NAME ).
ANSWER = ( 10 + SQRT(NUM1) ) / ( NUM2 10 ).

Spacing is very important when using arithmetic expressions!!!

Sub-Fields in ABAP
Syntax:
<field>[+<offset>][(<length>)]
DATA: CUSTOMER(10) TYPE C,
INV_DATE LIKE SY-DATUM.
CUSTOMER = 1234567890.

Use an offset and length to


display or change portions
of a field.

INV_DATE = 20031115.
WRITE:/ CUSTOMER + 8(2), xx,
INV_DATE(4).
*Start of Month
INV_DATE + 6(2) = 01.

90 xx 1996

CUSTOMER + 6 = ABCD.

123456ABCD ----11/01/2003

WRITE: / CUSTOMER, ----,INV_DATE.

Date Calculations in ABAP


DATA : DAYSOLD TYPE P,
DOB TYPE D,
TODAY LIKE SY-DATUM.
DOB = 19621230
TODAY = SY-DATUM.
DAYSOLD = TODAY DOB.
WRITE: You are, DAYSOLD ,days old..
You are 12410 days old.

Date fields store


values as
YYYYMMDD.

Declaring Fields with PARAMETERS


Syntax:
PARAMETERS <name>[(<length>)] [TYPE <data type>]
[DEFAULT<default>].

PARAMETERS: NUM TYPE I,


NAME(20) DEFAULT AARON.
ADD 10 TO NUM.
WRITE: / NUM,
-----,
NAME.

32----AARON

Selection Texts

These selection
texts will be used
on the selection
screen instead of
parameter names.

Working with Field Symbols in ABAP


DATA: NUM TYPE I VALUE 12.
FIELD-SYMBOLS: <F1>,
<F2> TYPE I,
<F3> LIKE NUM.
ASSIGN: NUM TO <F1>,
NUM TO <F2>,
NUM TO <F3>.
WRITE:/Line 1:, NUM,<F1>,<F2>,<F3>.
<F1> = 32.
WRITE: / Line 2:,NUM,<F1>,<F2>,<F3>.
Line 1: 12 12 12 12
Line 2: 32 32 32 32

A field symbol is a
pointer that
assumes a fields
address not a fields
value.

Dynamic Assignment of Partial Strings


DATA: TEXT_LINE(30) VALUE ABCDEFGHIJK.
FIELD-SYMBOLS <FSYMBOL>.
ASSIGN TEXT_LINE + 2(5) TO <FSYMBOL>.
* This assigns 5 characters of text_line starting at position 3 to the field string.
WRITE: /

text line = , TEXT_LINE.

ULINE.
WRITE: /

field symbol =,<FSYMBOL>.

ULINE.
<FSYMBOL> = 1234567890.
WRITE: / field symbol = ,<FSYMBOL>.
ULINE.
WRITE:/ text line = , TEXT_LINE.

Dynamic Field Assignment


PARAMETERS FIELD(8) DEFAULT SY-UZEIT.
FIELD-SYMBOLS <FSYMBOL>.
ASSIGN (FIELD) TO <FSYMBOL>.
IF SY-SUBRC = 0.
WRITE: / The contents of field', FIELD,<FSYMBOL>.
ELSE.
WRITE:/ Failure assigning fields, FIELD, to field symbol.
ENDIF.

FIELD

SY-UZEIT

Selection Screen

The contents of field SY-UZEIT 12:32:06


List

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output Statement
Data Declarations in ABAP
Control
ControlStatements
Statements
SELECT Statement
Internal Tables

In this section, we will


Describe IF, CASE, and ON CHANGE OF
Statements
Explain DO and WHILE loops
Define CHECK, EXIT, and CONTINUE
Statements for use with loops
Define Relational operators
Explain Logical Expressions
Describe the MESSAGE statement

Relational Operators
Display

Meaning

EQ =

Equal to

NE <> ><

Not equal to

GT >

Greater than

GE >= =>

Greater than or equal to

LT <

Smaller than

LE <= =<

Smaller than or equal to

DATA: V_START TYPE D,


V_SUM1
TYPE F,
BETWEEN f1 and f2
V_SUM2
TYPE P.
IS INITIAL
.
.
.
IF V_START IS INITIAL ... .
IF V_SUM1 GT SUM2 ... .
IF V_SUM1 BETWEEN 0 AND 100
... .

Interval
Initial value

Logical Expressions
V_COUNTER GE 0

V_COUNTER GT 0 AND
V_FLAG IS INITIAL

( V_FLAG1 NE SPACE AND V_FLAG2


NE SPACE ) AND V_COUNTER
BETWEEN 0 AND 100

V_COUNTER EQ 0 AND NOT


( V_FLAG1 EQ SPACE AND V_FLAG2
EQ SPACE )

String Comparison Operators


Syntax:

V_C1 op V_C2 where op can be:

CO Contains Only (C1 contains only the characters in C2)


CN Contains Not Only (C1 contains not only the characters of C2)
CA Contains Any (C1 contains at least one character of C2)
NA Not Any (C1 does not contain any characters of C2)
CS

Contains String (C1 contains C2)

NS

No String (C1 does not contain C2)

CP

Contains Pattern (C1 matches the pattern of C2)

NP

No Pattern (C1 does not match the pattern of C2)

IF Statement
IF statement examples

Syntax:
IF <cond1>.

IF MARA-MATNR = 1000030.
MOVE Y TO mat_flag.
ENDIF.

(statements)
[ELSE.]

IF paid_amt GE 2500.40.
MOVE 2500.40 TO paid_amt.
ELSE.
MOVE temp_amt TO paid_amt.
ENDIF.

[ELSEIF <cond2>.]

[ELSEIF <cond3>.]

ENDIF.

IF MARA-MTART = FERT.
MOVE Fin Goods TO mat_type.
ELSEIF MARA-MTART = ROH.
MOVE Raw Matl TO mat_type.
ELSEIF MARAT-MTART = HAWA.
MOVE Trading TO mat_type.
ELSE.
Use
MOVE Others TO mat_type.
Use Pretty
Pretty Printer
Printer
to
ENDIF.
to format
format (indent)
(indent)
nested
nested IF
IF statements
statements !!

CASE Statement
Syntax:
CASE <cond1>.

[WHEN <value>.]

[WHEN OTHERS.]

ENDCASE.

CASE MARA-MTART.
WHEN FERT.
MOVE Fin. Goods
TO mat_type.
WHEN ROH.
MOVE Raw Matl
TO mat_type.
WHEN HAWA.
MOVE Trading
TO mat_type.
WHEN OTHERS.
MOVE OTHERS TOUse
Use Pretty
Pretty Printer
Printer
to
to format
format (indent)
(indent)
ENDCASE.

CASE
CASE statements
statements !!

ON CHANGE OF Statement
Syntax:
ON CHANGE OF <field>.

PROGRAM ZEXAMPLE.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT.
ON CHANGE OF SFLIGHT-CARRID.
NEW-PAGE.
ENDON.
WRITE: / SFLIGHT-CARRID,
SFLIGHT-CONNID, ... .
ENDSELECT.

Table SFLIGHT
CARRID

CONNID

AA

0017

AA

0017

AA

0017

DO and WHILE Loops


Syntax:
DO [<n> TIMES].

ENDDO.

DO 10 TIMES.
i = i + 1.
ENDDO.

SY-INDEX

Syntax:
WHILE <true_cond>.

ENDWHILE.

Loop index
WHILE VBAK-AUART = OR.
tot_value = tot_value +
VBAK-NETWR.
i = i + 1.
READ TABLE XVBAK
INTO VBAK INDEX i.
ENDWHILE.

CHECK Statement
Syntax:
CHECK <any logical expression>.
REPORT ZEXAMPLE.
DO 10 TIMES.
CHECK SY-INDEX BETWEEN 4 AND 7.
WRITE: / The index value is: , SY-INDEX.
ENDDO.

Report Output
Report ZEXAMPLE
-------------------The index value is 4
The index value is 5
The index value is 6
The index value is 7

Note that this line of code was


only executed when condition specified
in the CHECK statement was TRUE.

EXIT Statement
Syntax:
EXIT.
REPORT ZEXAMPLE.
DO 10 TIMES.
IF SY-INDEX = 4.
EXIT.
ENDIF.
WRITE: / The index value is: , SY-INDEX.
ENDDO.

Report Output
Report ZEXAMPLE
-------------------The index value is 1
The index value is 2
The index value is 3

Note that this line of code was


only executed 3 times. This is because
the EXIT statement terminated the loop
completely on the 4th loop pass prior to
this statement.

CONTINUE Statement
Syntax:
CONTINUE.
REPORT ZEXAMPLE.
DO 10 TIMES.
IF SY-INDEX < 8.
CONTINUE.
ENDIF.
WRITE: / The index value is: , SY-INDEX.
ENDDO.

Report Output
Report ZEXAMPLE
-------------------The index value is 8
The index value is 9
The index value is 10

Note that this line of code was


only executed once the index value
because greater than 8. When the
index value was less than 8, the
CONTINUE statement caused this
statement to be skipped.

FLAGS
REPORT ZEXAMPLE.
DATA: V_FLAG TYPE C.
DO 3 TIMES.
IF V_FLAG IS INITIAL.
WRITE: / First Time Through.
V_FLAG = X.
ELSE.
WRITE: / Hello!.
ENDIF.
ENDDO.

Report Output
Report ZEXAMPLE
-------------------First Time Through
Hello!
Hello!

Message
Syntax:
MESSAGE ID <id> TYPE <type> NUMBER <num>.
REPORT ZTESTRPT1 MESSAGE-ID ZZ.
.
.
.
MESSAGE E001.

E001 No company code authorization

Online Messages (Example)


REPORT <name> MESSAGE-ID ZZ.
TABLES LFB1.
SELECT-OPTIONS: KONTO FOR LFB1-LIFNR.
PARAMETERS P_BUKRS LIKE LFB1-BUKRS DEFAULT '0001'.
AT SELECTION-SCREEN.
SELECT SINGLE * FROM T001
WHERE BUKRS = P_BUKRS.
IF SY-SUBRC NE 0.
MESSAGE E001 WITH BUKRS.
ENDIF.
START-OF-SELECTION.
SELECT * FROM LFB1 WHERE LIFNR IN KONTO
AND BUKRS EQ BUKRS.
WRITE: / LFB1-LIFNR, LFB1-BUKRS, LFB1-ERNAM,
LFB1-ERDAT.
ENDSELECT.

Table: Message Texts

Table T100
S

ID

No..

Message Text

D
ZZ
. .. ......
D
ZZ
. .. ......
D
ZZ
. .. ......
D
ZZ

001

Record &&& exists

006

Customer record & does not exists

011

Error updating

027

No authorization for company code &

MESSAGE Statement: Example

REPORT ZTESTRPT1 MESSAGE-ID ZZ.

SE93
Message Class ZZ

SELECT * FROM MARA WHERE MATNR = 100030.


CASE sy-subrc.
WHEN 0.
MESSAGE I001 WITH 100030.
WHEN 4.
MESSAGE E002 WITH 100030.
WHEN OTHERS.
MESSAGE A003.
ENDCASE.

001 & was found


002 & not found
003 Severe Error

Qualifying an Online Message

Restart

Selection screen

A message

Selection screen

W message

Function
call

Reenter value

Function
call

Function
call

Selection screen

Function
call

Selection screen

I message

Transactions
code

Selection screen

E message

Reenter value

List

List

List with
S message

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output Statement
Data Declarations in ABAP
Control Statements
SELECT Statement
Statement
Internal Tables

In this section, we will


Explain Database Tables / Data Browser
Introduce the SELECT statement
Use the SELECT statement and the WHERE
clause
Describe the SELECT SINGLE statement
Explain the ORDER BY addition
Describe retrieving individual columns
Exclude duplicate records with SELECT
DISTINCT
Define Aggregate expressions

SAP Database Tables

Key
fields in
BLUE

Data Browser - SE16 with ALV Grid

SELECT Statement
Syntax:
SELECT [SINGLE] [DISTINCT] <result>
INTO <target>
FROM <source>
[WHERE <condition>]
[GROUP BY <fields>]
[HAVING <cond>]
[ORDER BY <fields>].

INTO clause:
... INTO [CORRESPONDING FIELDS OF] <wa>
| INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab>
| INTO (<f1>, <f 2>,...)

FROM clause:
... FROM [<tab> [INNER]|LEFT [OUTER] JOIN] <dbtab> [AS <alias>]
[ON <cond>]
[CLIENT SPECIFIED]
[BYPASSING BUFFER]
[UP TO <n> ROWS]

SELECT Statement - Basic Form


TABLE SFLIGHT
Table
SFLIGHT

Table work area SFLIGHT

CARRID CONNID

FLDATE

PROGRAM ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT.
WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,
SFLIGHT-FLDATE.
ENDSELECT.

Restricting Data Selection WHERE clause


REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT
WHERE CARRID = AA'.
statements

ENDSELECT.
IF SY-SUBRC NE 0.
statements

ENDIF.
Allowable comparison operators for WHERE conditions :
EQ,
Equal to
EQ, ==
NE,
NE, <>,
<>, ><
>< Not equal to
LT,
Less than
LT, <<

LE,
LE, <=
<= Less than or equal
GT,
GT, >> Greater than
GE,
GE, >=
>= Greater than or equal

Retrieving a Single Record SELECT SINGLE

REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT SINGLE * FROM SFLIGHT
WHERE CARRID = AA'
AND
CONNID = 0017
AND
FLDATE = 20000914.
IF SY-SUBRC NE 0.
statements

ENDIF.

No
No ENDSELECT
ENDSELECT
required
required

Example: Single AccessUP TO


<n> ROWS
REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT UP TO 1 ROWS
WHERE CARRID EQ AA.
WRITE: SFLIGHT-CARRID,
SFLIGHT-CONNID,
SFLIGHT-FLDATR.
ENDSELECT.
IF SY-SUBRC <> 0.
.
ENDIF.

Retrieving Records in Sequence ORDER BY


REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT
ORDER BY PRIMARY KEY.
statements

ENDSELECT.

REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT
WHERE CARRID = AA'
ORDER BY CONNID FLDATE.
statements

ENDSELECT.

Retrieving Individual Columns


REPORT ZDEMO.
TABLES: SFLIGHT.
DATA: V_FLDATE LIKE SFLIGHT-FLDATE.
SELECT FLDATE INTO (V_FLDATE)
FROM SFLIGHT.
statements

ENDSELECT.
REPORT ZDEMO.
TABLES: SFLIGHT.
DATA: V_CARRID LIKE SFLIGHT-CARRID,
V_CONNID LIKE SFLIGHT-CONNID.
SELECT CARRID CONNID INTO
(V_CARRID, V_CONNID)
FROM SFLIGHT.
statements

ENDSELECT.

Demo Transaction SE30

Excluding Duplicates - SELECT DISTINCT


REPORT B170D068.
TABLES: SFLIGHT.
DATA: V_CARRID LIKE SFLIGHT-CARRID.
SELECT DISTINCT CARRID INTO (V_CARRID)
FROM SFLIGHT.
Output
Output
WRITE:/ V_CARRID.
ENDSELECT.

REPORT B170D069.
TABLES: SFLIGHT.
DATA: V_CARRID LIKE SFLIGHT-CARRID,
V_CONNID LIKE SFLIGHT-CONNID.
SELECT DISTINCT CARRID CONNID
INTO (V_CARRID, V_CONNID)
FROM SFLIGHT.
Output
Output
WRITE:/ V_CARRID, V_CONNID.
ENDSELECT.

SFLIGHT
CARRID
AA
AZ
DL
LH
QF
SQ
UA

SFLIGHT
CARRID CONNID
AA
AA
AZ
AZ
AZ
AZ
DL

0017
0064
0555
0788
0789
0790
1699

Aggregate Expressions
REPORT ZDEMO.
TABLES: SFLIGHT.
DATA: V_TOTAL
TYPE I,
V_HIGH_PRICE LIKE SFLIGHT-PRICE,
V_LOW_PRICE LIKE SFLIGHT-PRICE.
SELECT COUNT( DISTINCT CARRID )
MAX( PRICE )
MIN( PRICE )
FROM SFLIGHT INTO (V_TOTAL,
W_HIGH_PRICE, W_LOW_PRICE).

After SELECT :
V_TOTAL

statements

ENDSELECT.

V_HIGH_PRICE

26,674.45
V_LOW_PRICE

485.00

Topic Objectives
In this Topic, the participant will learn about:
ABAP Editor and basics of an ABAP Program
Simple Output Statement
Data Declarations in ABAP
Control Statements
SELECT Statement
Tables
Internal
Internal Tables

In this section, we will


Explain Field Strings
Describe Internal Tables
Define Internal Table Types
Explain Header Line and Work Area
Declare an Internal Table 3.0
Declare an Internal Table 4.0
Use Standard Table Operations
Define Hashed and Sorted Tables

Declaring Field Strings


Syntax:
TYPE: BEGIN OF <name>,
<field1>, ..., <fieldn>,
END OF <name>.
PROGRAM <name>.
TYPE: BEGIN OF T_ADDRESS,
FLAG
TYPE C,
NAME(25) TYPE C,
Declaration
CITY(20) TYPE C,
PAYMENTSUM
LIKE AMOUNT,
field string.
END OF T_ADDRESS.
DATA: ADDRESS TYPE T_ADDRESS.
.
.
MOVE X TO ADDRESS-FLAG.
ADD AMOUNT TO ADDRESS-PAYMENTSUM.
.
.
WRITE: ADDRESS-FLAG, ADDRESS-NAME,
ADDRESS-CITY, ADDRESS-PAYMENTSUM.

of a

Using Field Strings


PROGRAM ZEXAMPLE.
TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6)
TYPE N,
LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: EMPL1 TYPE T_EMPLOYEE,
EMPL2 LIKE EMPL1.
.
.
MOVE 546259TO EMPL1-PERSNBR.
MOVE Salm TO EMPL1-LASTNAME.

Report Output

MOVE EMPL1 TO EMPL2.


WRITE: / EMPL2-LASTNAME,
/ EMPL2-PERSNBR.
SKIP.
WRITE: / EMPL1.

Salm
546259
546249Salm

Internal Tables
Internal tables
ADDRESS_LIST
Name
FLDATE
Name2
Name3
Name4
Name5
Name6

First Name
First Name 1
First Name 2
First Name 3
First Name 4
First Name 5
First Name 6

City

Street

City1
City2
City3
City4
City5
City6

Street1
Street2
Street3
Street4
Street5
Street6

Internal Table Attributes


REPORT
REPORT ZDEMO_TABLES
ZDEMO_TABLES ..
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.
DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE STANDARD
STANDARD TABLE
TABLE
OF
OF T_EMPLOYEE
T_EMPLOYEE WITH
WITH NON-UNIQUE
NON-UNIQUE
KEY
KEY PERSNBR
PERSNBR
INITIAL
INITIAL SIZE
SIZE 0,
0,

Line Type
Table
Type

WA_EMPLTAB
WA_EMPLTAB TYPE
TYPE T_EMPLOYEE.
T_EMPLOYEE.

Key
* All of the above syntax will be explained in detail later in this section!

INITIAL SIZE or OCCURS Clause


REPORT
REPORT ZDEMO_TABLES
ZDEMO_TABLES ..
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.
DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE STANDARD
STANDARD TABLE
TABLE
OF
OF T_EMPLOYEE
T_EMPLOYEE WITH
WITH NON-UNIQUE
NON-UNIQUE
KEY
KEY PERSNBR
PERSNBR
INITIAL
INITIAL SIZE
SIZE 0,
0,

Line Type
Table
Type

WA_EMPLTAB
WA_EMPLTAB TYPE
TYPE T_EMPLOYEE.
T_EMPLOYEE.

Size
* All of the above syntax will be explained in detail later in this section!

Internal Table Types and Keys


Standard

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

NON-UNIQUE

UNIQUE | NON-UNIQUE

UNIQUE

Constant

Access using

Uniqueness

Declaring an Internal Table


PROGRAM
PROGRAM Z40_EXAMPLE.
Z40_EXAMPLE.
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.
Type
declaration
remains the
same.

4.x

New
Syntax

DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE STANDARD
STANDARD TABLE
TABLE
OF
OF T_EMPLOYEE
T_EMPLOYEE WITH
WITH KEY
KEY PERSNBR
PERSNBR
INITIAL
INITIAL SIZE
SIZE 0,
0,
WA_EMPLTAB
WA_EMPLTAB TYPE
TYPE T_EMPLOYEE.
T_EMPLOYEE.

PROGRAM
PROGRAM Z30_EXAMPLE.
Z30_EXAMPLE.
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.

3.x

DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE T_EMPLOYEE
T_EMPLOYEE OCCURS
OCCURS 0,
0,
WA_EMPLTAB
WA_EMPLTAB TYPE
TYPE T_EMPLOYEE.
T_EMPLOYEE.

Old
Syntax

Referring to ABAP Dictionary


Structures: LIKE
REPORT

ZEXAMPLE.

TYPES:BEGIN OF T_SFLIGHT,
STRUCT1 LIKE SFLIGHT,
END OF T_SFLIGHT.
DATA: I_SFLIGHT TYPE STANDARD TABLE OF
T_SFLIGHT INITIAL SIZE 0,
WA_SFLIGHT TYPE T_SFLIGHT.
WA_SFLIGHT-STRUCT1-CARRID = . . .

Name
Key Type Length Description
----------------------------------------------------------------------------------------SFLIGHT-CARRID X CHAR
2
Carrier ID
SFLIGHT-CONNID X NUMC
4
Connection ID
SFLIGHT-FLDATE X DATS
8
Connection ID
SFLIGHT-FORM
CHAR
11
Form of address
SFLIGHT-FLDATE
CHAR
30
Name
.
.

Accessing Individual Table Entries


- Work Areas
PROGRAM
PROGRAM Z40_EXAMPLE.
Z40_EXAMPLE.
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.
DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE STANDARD
STANDARD TABLE
TABLE
OF
OF T_EMPLOYEE
T_EMPLOYEE WITH
WITH KEY
KEY PERSNBR
PERSNBR
INITIAL
INITIAL SIZE
SIZE 0,
0,
WA_EMPLTAB
WA_EMPLTAB TYPE
TYPE T_EMPLOYEE.
T_EMPLOYEE.

I_EMPLTAB
546259
163927
578110
803124
804320
.
.

WA_EMPLTAB
SALM
COSTIGAN
MIDDLEMARK
SIEBER
SIFFERMAN
.
.

578110

MIDDLEMARK

In order to manipulate a row in an


internal table, that row must first be put in
the work area (commands that put the
contents of a table row into the work area
will be discussed later on!)

Accessing Individual Table Entries


- Header Lines
PROGRAM
PROGRAM Z40_EXAMPLE.
Z40_EXAMPLE.
TYPES:
TYPES: BEGIN
BEGIN OF
OF T_EMPLOYEE,
T_EMPLOYEE,
PERSNBR(6)
TYPE
PERSNBR(6)
TYPE N,
N,
LASTNAME(20)
LASTNAME(20) TYPE
TYPE C,
C,
END
END OF
OF T_EMPLOYEE.
T_EMPLOYEE.
DATA:
DATA: I_EMPLTAB
I_EMPLTAB TYPE
TYPE STANDARD
STANDARD TABLE
TABLE
OF
OF T_EMPLOYEE
T_EMPLOYEE WITH
WITH KEY
KEY PERSNBR
PERSNBR
INITIAL
INITIAL SIZE
SIZE 0,
0,
WITH
WITH HEADER
HEADER LINE.
LINE.

I_EMPLTAB
578110

MIDDLEMARK

546259
163927
578110
803124
804320
...

SALM
COSTIGAN
MIDDLEMARK
SIEBER
SIFFERMAN
...

In order to manipulate a row in an


internal table, that row must first be put in
the header line (commands that put the
contents of a table row into the header line
will be discussed later on!)

Field by Field Transport


MOVE-CORRESPONDING <f1> TO <f2>.
REPORT ZEXAMPLE.
TABLES: SFLIGHT.
TYPES: BEGIN OF T_ADDRESS,
FLAG TYPE C,
ID LIKE SFLIGHT-ID,
NAME LIKE SFLIGHT-FLDATE,
CITY LIKE SFLIGHT-CITY,
END OF T_ADDRESS.
DATA:
ADDRESS TYPE T_ADDRESS.

MOVE-CORRESPONDING SFLIGHT TO ADDRESS.

SFLIGHT

ADDRESS

ID
FLDATE
00000001 WILLY

FLAG

ID
00000001

CITY
WALLDORF

NAME

CITY
WALLDORF

Filling an Internal Table


;

For internal tables WITH a header line


APPEND <itab> SORTED BY <field>.

APPEND <itab>.
;

For internal tables WITHOUT a header line


APPEND <wa> TO <itab>.

APPEND <wa> TO <itab>


SORTED BY <field>.

CARRID PAYMENTSUM
D

400 000 Header line


1 000 000

CARRID

GB

500 000

400 000

D
GB

7 800 000
50 000

3
4

7 800 000

USA

1 000 000

140 000

GB

500 000

A
GB

140 000
50 000

4
5

USA

7
8

PAYMENTSUM
Header line

APPEND SORTED BY
REPORT ZEXAMPLE.
TABLES:SFLIGHT.

INITIAL SIZE 3

TYPES: BEGIN OF T_FLT,


CARRID LIKE SFLIGHT-CARRID,
PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM,
END OF T_FLT.
DATA:

ITAB TYPE STANDARD TABLE OF T_FLT


WITH NON-UNIQUE KEY CARRID
INITIAL SIZE 3,
WA_ITAB TYPE T_FLT.

SELECT CARRID PAYMENTSUM INTO WA_ITAB FROM SFLIGHT .


APPEND WA_ITAB TO ITAB SORTED BY PAYMENTSUM.
ENDSELECT.
LOOP AT ITAB INTO WA_ITAB.
WRITE:/ WA_ITAB-CARRID, WA_ITAb-PAYMENTSUM.
ENDLOOP.

INITIAL SIZE 10

SELECT INTO...
SELECT * FROM <table> INTO <internal table>.
REPORT ZEXAMPLE.
TABLES: SFLIGHT.
TYPES: BEGIN OF T_TAB,
T_CNTRY LIKE SFLIGHT-CARRID,
T_PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM,
END OF T_TAB.
DATA: I_TAB TYPE STANDARD TABLE OF T_TAB
INITIAL SIZE 0,
WA_TAB TYPE T_TAB.
PARAMETERS: P_CARRID LIKE SFLIGHT-CARRID.
SELECT CARRID PAYMENTSUM FROM SFLIGHT INTO
TABLE I_TAB
WHERE CARRID = P_CARRID
ORDER BY PAYMENTSUM DESCENDING.

FOR ALL ENTRIESWHERE...


FOR ALL ENTRIES IN <internal table> where.
REPORT ZEXAMPLE.
TABLES: SFLIGHT.
TYPES: BEGIN OF T_CARRID,
CARRID LIKE SFLIGHT-CARRID,
END OF T_CARRID.
TYPES: BEGIN OF T_FLIGHTS,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
END OF T_FLIGHTS.
DATA: ITAB1 TYPE STANDARD TABLE OF T_CARRID,
WA_TAB1 TYPE T_CARRID,
ITAB2 TYPE STANDARD TABLE OF T_FLIGHTS,
WA_ITAB2 TYPE T_FLIGHTS.
WA_TAB1-CARRID = 'AA'.
APPEND WA_TAB1 TO ITAB1.
WA_TAB1-CARRID = 'LH'.
APPEND WA_TAB1 TO ITAB1.
SELECT CARRID CONNID FLDATE
FROM SFLIGHT INTO TABLE ITAB2
FOR ALL ENTRIES IN ITAB1
WHERE CARRID = ITAB1-CARRID.
LOOP AT ITAB2 INTO WA_ITAB2.
WRITE:/ WA_ITAB2-CARRID, WA_ITAB2-CONNID.
ENDLOOP.

Compressing Data with an Internal


Table
COLLECT <itab>.

REPORT ZEXAMPLE.
TABLES:SFLIGHT.
TYPES: BEGIN OF T_FLT,
CARRID LIKE SFLIGHT-CARRID,
PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM,
END OF T_FLT.
DATA: ITAB TYPE STANDARD TABLE OF T_FLT
WITH NON-UNIQUE KEY CARRID
INITIAL SIZE 0,
WA_ITAB TYPE T_FLT.
SELECT CARRID PAYMENTSUM INTO WA_ITAB FROM SFLIGHT .
COLLECT WA_ITAB INTO ITAB.
ENDSELECT.
LOOP AT ITAB INTO WA_ITAB.
WRITE:/ WA_ITAB-CARRID, WA_ITAb-PAYMENTSUM.
ENDLOOP.

Sorting an Internal Table


SORT <itab> BY <field1> <field2> . . . .
REPORT <name>.
TABLES: SFLIGHT.
TYPES:
BEGIN OF T_FLT,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM,
END OF T_FLT.
DATA:
ITAB TYPE STANDARD TABLE OF T_FLT
WITH NON-UNIQUE KEY
CARRID CONNID FLDATE,
WA_ITAB TYPE T_FLT.
SORT ITAB.
.
.
SORT ITAB BY CARRID PAYMENTSUM.
.
.
SORT ITAB BY CARRID
ASCENDING
PAYMENTSUM
DESCENDING.

Processing an Internal Table


LOOP AT <itab>. ... ENDLOOP.
REPORT <name>.
TABLES:
TYPES:

DATA:

SFLIGHT.
BEGIN OF T_FLT,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PAYMENTSUM
LIKE SFLIGHT-PAYMENTSUM,
END OF T_FLT.
ITAB TYPE STANDARD TABLE OF T_FLT
WITH NON-UNIQUE KEY CARRID CONNID FLDATE
INITIAL SIZE 0,
WA_ITAB TYPE T_FLT.

.
.
LOOP AT ITAB INTO WA_ITAB.
WRITE: / WA_ITAB-CARRID, WA_ITAB-CITY, ... .
ENDLOOP.
Test
Test SY-SUBRC
SY-SUBRC
.
.
LOOP AT ITAB INTO WA_ITAB WHERE CARRID BETWEEN 'AA' AND LH'.
WRITE: / WA_ITAB-CARRID, WA_ITAB-FLDATE, ... .
ENDLOOP.

Test
Test SY-SUBRC
SY-SUBRC

System Field SY-TABIX

REPORT <name>.
.
.
.

LOOP AT ITAB.
WRITE: / SY-TABIX, ITAB-CARRID, ... .
ENDLOOP.

REPORT <name>.
.
.
.

PARAMETERS: P_START LIKE SY-TABIX DEFAULT '10',


P_END
LIKE SY-TABIX DEFAULT '20'.
LOOP AT TAB FROM P_START TO P_END.
WRITE: / SY-TABIX, ITAB-CARRID, ... .
ENDLOOP.

AT Statement
AT NEW <field>.
AT END OF <field>.
AT FIRST.
AT LAST.

EXAMPLE

TYPES: BEGIN OF T_COMPANIES,


NAME(30)TYPE C,
PRODUCT(20)TYPE C,
PAYMENTSUM TYPE I,
END OF T_COMPANIES.
DATA: I_COMPANIES TYPE STANDARD TABLE
OF T_COMPANIES
INITIAL SIZE 10,
WA_COMPANIES TYPE T_COMPANIES.

LOOP AT I_COMPANIES INTO WA_COMPANIES.


AT NEW NAME.
NEW PAGE.
WRITE: / WA_COMPANIES-NAME.
ENDAT.
WRITE: / WA_COMPANIES-PRODUCT,
WA_COMPANIES-PAYMENTSUM.
AT END OF NAME.
SUM.
WRITE: / WA_COMPANIES-PRODUCT,
WA_COMPANIES-PAYMENTSUM.
ENDAT.
ENDLOOP.

Exercise
Exercise 18 - Create a Ranked List for Highest PAYMENTSUM,
50 minutes
Exercise 19 - Using the FOR ALL ENTRIES Statement, 60 minutes

Reading a Single Table Entry


READ TABLE <itab> [ INTO <wa> ] ... .
REPORT ZEXAMPLE.
TABLES: SFLIGHT.
TYPES: BEGIN OF T_TAB,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PAYMENTSUM
LIKE SFLIGHT-PAYMENTSUM,
END OF T_TAB.
DATA:
I_TAB TYPE STANDARD TABLE OF T_TAB,
WA_TAB TYPE T_TAB,
TAB_INDEX TYPE I.
CLEAR WA_TAB.
WA_TAB-CARRID = 'AA'.
WA_TAB-CONNID = '0017'.
WA_TAB-FLDATE = '20000914'.
READ TABLE I_TAB WITH KEY WA_TAB INTO WA_TAB.
IF SY-SUBRC NE 0. .. ENDIF.
READ TABLE I_TAB WITH KEY 'AA001720000914'
BINARY SEARCH INTO WA_TAB.
IF SY-SUBRC NE 0. .. ENDIF.
TAB_INDEX = 3.
READ TABLE I_TAB INDEX TAB_INDEX INTO WA_TAB.
IF SY-SUBRC NE 0. .. ENDIF.

Changing an Internal Table


INSERT <wa> INTO <itab> INDEX <i>.
MODIFY <itab> FROM <wa> INDEX <i>.
DELETE <wa> FROM <itab> INDEX <i>.
REPORT
ZEXAMPLE.
TABLES: SFLIGHT.
TYPES: BEGIN OF T_REC,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE
LIKE SFLIGHT-FLDATE,
END OF T_REC.
DATA: I_TAB TYPE STANDARD TABLE OF T_REC,
WA_TAB TYPE T_REC.
.
.
READ TABLE I_TAB WITH KEY AA0017 BINARY SEARCH INTO WA_TAB.
MOVE BB' TO I_TAB-CARRID.
MODIFY I_TAB FROM WA_TAB INDEX SY-TABIX.
READ TABLE I_TAB WITH KEY AA0017 BINARY SEARCH INTO WA_TAB.
MOVE ZZ TO WA_TAB-CARRID.
INSERT WA_TAB INTO I_TAB.
READ TABLE I_TAB WITH KEY ZZ0017 BINARY SEARCH INTO WA_TAB.
DELETE I_TAB INDEX SY-TABIX.

Changing an Internal Table in a


LOOP
REPORT <name>.
.
.
.
LOOP AT <itab> INTO <wa>.
.
.
.
MODIFY <itab> FROM <wa>.
.
.
.
INSERT <wa> INTO <itab>.
.
.
.
DELETE <itab>.
.
.
.
ENDLOOP.

Deleting an Internal Table


CLEAR <itab>.
For a table defined with a header line, this
statement initializes the header line.
For a table defined without a header line,
this statement works the same as REFRESH.

REFRESH <itab>.
Deletes all table lines except header line if
header line is used. Storage space is not released
Paging is released

FREE <itab>.
Deletes all table lines except header
line if a header line is used.
Storage space is released

Information About an Internal Table


DESCRIBE TABLE <itab>... .
REPORT <name>.
TABLES: SFLIGHT.
TYPES:

DATA:

BEGIN OF T_FLT,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PAYMENTSUM
LIKE SFLIGHT-PAYMENTSUM,
END OF T_FLT.
TAB TYPE STANDARD TABLE OF T_FLT,
WA_TAB TYPE T_FLT,
LINE_COUNT TYPE I,
OCCURS_COUNT TYPE I.

.
.
DESCRIBE TABLE TAB
LINES LINE_COUNT
OCCURS OCCURS_COUNT.
.
.

Hashed Table Restrictions


REPORT <name>.
TABLES: SFLIGHT.
TYPES:

BEGIN OF line_type,
f1,f2,
END OF line_type.
DATA:
TAB1 TYPE HASHED TABLE OF line_type
WITH UNIQUE KEY f1 with HEADER LINE.
TAB1-f1 = Y. TAB1-f2 = 1. INSERT TABLE tab1.
TAB1-f1 = X. TAB1-f2 = 1. INSERT TABLE tab1.
TAB1-f1 = A. TAB1-f2 = 1. INSERT TABLE tab1.
READ TABLE TAB1 WITH TABLE KEY f1 = A.
SORT TAB1 BY f1.
LOOP AT TAB1.
WRITE:/ TAB1-f1, TAB1-f2.
ENDLOOP.

Sorted Table Restrictions


REPORT <name>.
TABLES: SFLIGHT.
TYPES:

BEGIN OF line_type,
f1,f2,
END OF line_type.
DATA:
TAB1 TYPE SORTED TABLE OF line_type
WITH UNIQUE KEY f1 with HEADER LINE.
TAB1-f1 = Y. TAB1-f2 = 1. INSERT TABLE tab1.
TAB1-f1 = X. TAB1-f2 = 1. INSERT TABLE tab1.
TAB1-f1 = A. TAB1-f2 = 1. INSERT TABLE tab1.
READ TABLE TAB1 WITH TABLE KEY f1 = A.
SORT TAB1 BY f1.
LOOP AT TAB1.
WRITE:/ TAB1-f1, TAB1-f2.
ENDLOOP.