02 - introduction to abap programming
DESCRIPTION
Introduction to ABAP ProgrammingTRANSCRIPT
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
An Introduction to ABAP 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 and basics of an ABAP Program
• Simple Output Statement
• Data Declarations in ABAP
• Control Statements
• SELECT Statement
• Internal Tables
ABAP Editor and Basics of an ABAP Program
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
Business Application ProgrammingAdvanced
Introduction to ABAP
• Advanced Business Application Programming• SAP’s 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
Display/change mode
(Ctrl+F1).
Syntax CheckSyntax Check (Ctrl+F2)
Activation (Ctrl+F3)
Execution (F8)
Where used list (Ctrl+Shift+F3)
ABAP help (F1)
Find and Repeat Find
Standard toolbar
Basic ABAP Program syntax
DATA COUNT TYPE I.DATA TITLE(25).MOVE 1 TO COUNT.MOVE ‘President’ TO TITLE.WRITE TITLE.WRITE COUNT. ABAP Program
Statement.
Word 1 Word2 Word3 Word 4
Keyword or Statement
Parameters, fields, or constants
Additions or clauses
.
End of statement
ABAP Program Structure
Program Name AreaUse REPORT for listing programsUse PROGRAM for online programs
Declaration SectionUsed for defining tables,variables and constants
Used for coding executable ABAP statement
Statement Section
Chaining Statements in ABAP
DATA COUNT TYPE I.DATA TITLE(25).MOVE 1 TO COUNT.MOVE ‘President’ TO TITLE.WRITE TITLE.WRITE COUNT.
MOVE: 1 TO COUNT,‘President’ TO TITLE.
DATA: COUNT TYPE I,TITLE(25).
WRITE: TITLE, COUNT.
Comments in ABAP
A double quotation mark(“) anywhere ona line makes everything that follows a comment.
An asterisk (*) in column 1makes 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.
ORFrom the ABAP Editor: Initial Screen, type the program name, then click on the “Execute” push-button.
From the ABAP Editor:With the program displayed, program->Execute
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
Simple Output Statement
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 ‘***************************’.
< program title> 1---------------------------------------------------------------------------------******************************
The date today is: 11/14/2001 The current time is: 12:32:06
******************************
Note that there is an automatic space between the fields written to the list.
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/2003Ticket 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.WRITE: ‘Comments:’.
<program title> 1------------------------------------------------------------------------------****City of Mumbai****Ticket Date 11/14/2003Ticket Time 18:01:00****Department of Public Safety****<program title> 2_________________________________________________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 )
Text symbols are referenced by a unique three character code.
WRITE: /TEXT-001,TEXT-002, SY-DATUM.
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
Data Declarations in ABAP
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
I: Integer
P: Packed#
F: Floating Point#
N: Numeric Text
D: Date
T:Time
X: Hexadecimal#
ABAP Data Types: Initial Value
C: (blank)
I: zero
P:zero
F:zeroes
N:zeroes
D: 00000000
T:000000
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.
DATA: PLAYER(35) TYPE C VALUE ‘Julius Erving’,NICKNAME LIKE PLAYER,ACQUIRED LIKE SY-DATUM.
Use the “LIKE” addition to declare fields with the same format (i.e. data type and length)
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 field’s 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+019876.54
1212.0
32.00
Assigning Values to FieldsMOVE <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+ - * / **DIV and MOD
FunctionsSQRT,EXP,LOG,SIN,COS,STRLEN….
COUNTER = COUNTER + 1SALARY = 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’.INV_DATE = ‘20031115’.WRITE:/ CUSTOMER + 8(2), ‘xx’,
INV_DATE(4).*Start of MonthINV_DATE + 6(2) = ’01’.CUSTOMER + 6 = ‘ABCD’.WRITE: / CUSTOMER, ‘----’,INV_DATE.
90 xx 1996123456ABCD ----11/01/2003
Use an offset and length to display or change portions of a field.
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 12Line 2: 32 32 32 32
A field symbol is a “pointer” that assumes a field’s address not a field’s 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
The contents of field SY-UZEIT 12:32:06
Selection Screen
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 Statements
• SELECT Statement
• Internal Tables
Control Statements
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
EQ = Equal to
NE <> >< Not equal to
GT > Greater than
GE >= => Greater than or equal to
LT < Smaller than
LE <= =< Smaller than or equal toDATA: V_START TYPE D,
V_SUM1 TYPE F,V_SUM2 TYPE P.
.
.
.IF V_START IS INITIAL ... .IF V_SUM1 GT SUM2 ... .IF V_SUM1 BETWEEN 0 AND 100 ... .
BETWEEN f1 and f2 Interval
IS INITIAL Initial value
Display Meaning
Logical Expressions
V_COUNTER GE 0
V_COUNTER GT 0 ANDV_FLAG IS INITIAL
( V_FLAG1 NE SPACE AND V_FLAG2NE SPACE ) AND V_COUNTERBETWEEN 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
CN
CA
NA
CS
NS
CP
NP
Contains Only (C1 contains only the characters in C2)
Contains Not Only (C1 contains not only the characters of C2)
Contains Any (C1 contains at least one character of C2)
Not Any (C1 does not contain any characters of C2)
Contains String (C1 contains C2)
No String (C1 does not contain C2)
Contains Pattern (C1 matches the pattern of C2)
No Pattern (C1 does not match the pattern of C2)
IF StatementIF statement examples
IF MARA-MATNR = ‘1000030’.MOVE ‘Y’ TO mat_flag.
ENDIF.
IF paid_amt GE ‘2500.40’.MOVE ‘2500.40’ TO paid_amt.
ELSE.MOVE temp_amt TO paid_amt.
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.MOVE ‘Others’ TO mat_type.
ENDIF.Use Pretty Printer to format (indent)nested IF statements !
Use Pretty Printer to format (indent)nested IF statements !
Syntax:IF <cond1>.…(statements)[ELSE.]…[ELSEIF <cond2>.]…[ELSEIF <cond3>.]…ENDIF.
CASE StatementSyntax: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’ TO…
ENDCASE.Use Pretty Printer to format (indent)CASE statements !
Use Pretty Printer to format (indent)CASE statements !
ON CHANGE OF Statement
PROGRAM ZEXAMPLE.TABLES: SFLIGHT.
SELECT * FROM SFLIGHT.ON CHANGE OF SFLIGHT-CARRID.
NEW-PAGE.ENDON.WRITE: / SFLIGHT-CARRID,
SFLIGHT-CONNID, ... .ENDSELECT.
Syntax:ON CHANGE OF <field>.
Table SFLIGHTCARRID CONNID
AA 0017
AA 0017
AA 0017
DO and WHILE LoopsSyntax:DO [<n> TIMES].… ENDDO.
Syntax:‘WHILE <true_cond>.…ENDWHILE.
DO 10 TIMES.i = i + 1.
ENDDO.
SY-INDEX
Loop indexWHILE 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 ZEXAMPLE--------------------The index value is 4The index value is 5The index value is 6The index value is 7
Report OutputNote that this line of code wasonly executed when condition specifiedin 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 ZEXAMPLE--------------------The index value is 1The index value is 2The index value is 3
Report OutputNote that this line of code wasonly executed 3 times. This is becausethe EXIT statement terminated the loopcompletely on the 4th loop pass prior tothis 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 ZEXAMPLE--------------------The index value is 8The index value is 9The index value is 10
Report OutputNote that this line of code wasonly executed once the index valuebecause greater than 8. When the index value was less than 8, theCONTINUE statement caused thisstatement 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 ZEXAMPLE--------------------First Time ThroughHello!Hello!
Report Output
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 T001WHERE 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 001 Record &&& exists. .. ... ...D ZZ 006 Customer record & does not exists. .. ... ...D ZZ 011 Error updating. .. ... ...D ZZ 027 No authorization for company code &
MESSAGE Statement: Example
REPORT ZTESTRPT1 MESSAGE-ID 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.
SE93Message Class ZZ
001
002
003
& was found
& not found
Severe Error
……
Qualifying an Online MessageFunctioncall
Functioncall
Selection screen Selection screen
W messageA message
Transactionscode
Selection screen
E message
Functioncall
Selection screen
I message
Functioncall
Selection screen
List
Res
tart
Ree
nter
val
ue
Ree
nter
val
ueList 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
• Internal Tables
SELECT Statement
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
CARRID CONNID FLDATE
PROGRAM ZDEMO.TABLES: SFLIGHT.SELECT * FROM SFLIGHT.
WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,SFLIGHT-FLDATE.
ENDSELECT.
Table work area SFLIGHT
TableSFLIGHT
TABLE SFLIGHT
Restricting Data Selection -WHERE clause
REPORT ZDEMO.TABLES: SFLIGHT.SELECT * FROM SFLIGHT
WHERE CARRID = ‘AA'.
ENDSELECT.IF SY-SUBRC NE 0.
ENDIF.
statements
statements
Allowable comparison operators for WHERE conditions :EQ, = LE, <=NE, <>, >< GT, >LT, < GE, >=
EQ, = LE, <=NE, <>, >< GT, >LT, < GE, >=
Less than or equalGreater thanGreater than or equal
Equal to Not equal toLess than
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.
ENDIF.
statements
No ENDSELECT requiredNo ENDSELECT required
Example: Single Access…UP TO <n> ROWS
REPORT ZDEMO.
TABLES: SFLIGHT.
SELECT * FROM SFLIGHT UP TO 1 ROWSWHERE 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.
ENDSELECT.
statements
REPORT ZDEMO.TABLES: SFLIGHT.SELECT * FROM SFLIGHT
WHERE CARRID = ‘AA'ORDER BY CONNID FLDATE.
ENDSELECT.
statements
Retrieving Individual Columns
REPORT ZDEMO.TABLES: SFLIGHT.DATA: V_FLDATE LIKE SFLIGHT-FLDATE.SELECT FLDATE INTO (V_FLDATE)FROM SFLIGHT.
ENDSELECT.
statements
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.
ENDSELECT.
statements 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.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.WRITE:/ V_CARRID, V_CONNID.
ENDSELECT.
SFLIGHTCARRIDAAAZDLLHQFSQUA
Output Output
SFLIGHTCARRID CONNIDAA 0017AA 0064AZ 0555AZ 0788AZ 0789AZ 0790DL 1699
Output Output
Aggregate Expressions
statements
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).
ENDSELECT.
After SELECT :V_TOTAL
7V_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
• Internal TablesInternal 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
PROGRAM <name>.TYPE: BEGIN OF T_ADDRESS,
FLAG TYPE C,NAME(25) TYPE C,CITY(20) TYPE C,PAYMENTSUM LIKE AMOUNT,
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.
Syntax:TYPE: BEGIN OF <name>,
<field1>, ..., <fieldn>,END OF <name>.
Declaration of afield string.
Using Field StringsPROGRAM 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 ‘546259’TO EMPL1-PERSNBR.MOVE ‘Salm’ TO EMPL1-LASTNAME.
MOVE EMPL1 TO EMPL2.
WRITE: / EMPL2-LASTNAME,/ EMPL2-PERSNBR.
SKIP.
WRITE: / EMPL1.
Salm546259
546249Salm
Report Output
Internal Tables
Internal tablesInternal tables
Name First Name City StreetADDRESS_LIST
FLDATE First Name 1 City1 Street1Name2 First Name 2 City2 Street2Name3 First Name 3 City3 Street3Name4 First Name 4 City4 Street4Name5 First Name 5 City5 Street5Name6 First Name 6 City6 Street6
Internal Table Attributes
REPORT ZDEMO_TABLES .TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLEOF T_EMPLOYEE WITH NON-UNIQUE
KEY PERSNBRINITIAL SIZE 0,
WA_EMPLTAB TYPE T_EMPLOYEE.
REPORT ZDEMO_TABLES .TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLEOF T_EMPLOYEE WITH NON-UNIQUE
KEY PERSNBRINITIAL SIZE 0,
WA_EMPLTAB TYPE T_EMPLOYEE.
Line TypeLine Type
KeyKey
Table TypeTable Type
* All of the above syntax will be explained in detail later in this section!
INITIAL SIZE or OCCURS Clause
REPORT ZDEMO_TABLES .TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLEOF T_EMPLOYEE WITH NON-UNIQUE
KEY PERSNBRINITIAL SIZE 0,
WA_EMPLTAB TYPE T_EMPLOYEE.
REPORT ZDEMO_TABLES .TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLEOF T_EMPLOYEE WITH NON-UNIQUE
KEY PERSNBRINITIAL SIZE 0,
WA_EMPLTAB TYPE T_EMPLOYEE.
Line TypeLine Type
SizeSize
Table TypeTable Type
* All of the above syntax will be explained in detail later in this section!
Internal Table Types and Keys
Standard Sorted Hashed
Key access
Access time for n entries
Access using
Uniqueness NON-UNIQUE UNIQUE | NON-UNIQUE UNIQUE
Predominantly index Predominantly key Key only
Table Scan Binary Search Hash Function
Increases linearly(O(n))
Increaseslogarithmically(O(log(n))) Constant
Declaring an Internal Table
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 0,WA_EMPLTAB TYPE T_EMPLOYEE.
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 0,WA_EMPLTAB TYPE T_EMPLOYEE.
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WA_EMPLTAB TYPE T_EMPLOYEE.
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WA_EMPLTAB TYPE T_EMPLOYEE.
4.x
3.x
NewSyntaxType
declarationremains thesame.
OldSyntax
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 IDSFLIGHT-CONNID X NUMC 4 Connection IDSFLIGHT-FLDATE X DATS 8 Connection IDSFLIGHT-FORM CHAR 11 Form of addressSFLIGHT-FLDATE CHAR 30 Name
.
.
Accessing Individual Table Entries - Work Areas
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WA_EMPLTAB TYPE T_EMPLOYEE.
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WA_EMPLTAB TYPE T_EMPLOYEE.
546259163927578110803124804320..
SALMCOSTIGANMIDDLEMARKSIEBERSIFFERMAN..
I_EMPLTAB578110 MIDDLEMARK
WA_EMPLTAB
In order to manipulate a row in aninternal table, that row must first be put inthe work area (commands that put the contents of a table row into the work areawill be discussed later on!)
Accessing Individual Table Entries - Header Lines
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WITH HEADER LINE.
PROGRAM Z40_EXAMPLE.TYPES: BEGIN OF T_EMPLOYEE,
PERSNBR(6) TYPE N,LASTNAME(20) TYPE C,
END OF T_EMPLOYEE.
DATA: I_EMPLTAB TYPE STANDARD TABLE OF T_EMPLOYEE WITH KEY PERSNBRINITIAL SIZE 0,WITH HEADER LINE.
546259163927578110803124804320...
SALMCOSTIGANMIDDLEMARKSIEBERSIFFERMAN...
I_EMPLTAB578110 MIDDLEMARK
In order to manipulate a row in aninternal table, that row must first be put inthe header line (commands that put the contents of a table row into the header linewill be discussed later on!)
Field by Field TransportMOVE-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.
ID FLDATE CITY00000001 WILLY WALLDORF
00000001 WALLDORFADDRESS FLAG ID NAME CITY
SFLIGHT
Filling an Internal TableFor internal tables WITH a header line
APPEND <itab> SORTED BY <field>.APPEND <itab>.
CARRID PAYMENTSUM
D 400 000 Header lineUSA 1 000 000 1GB 500 000 2D 7 800 000 3GB 50 000 4A 140 000 5
67
8
CARRID PAYMENTSUM
D 400 000 Header lineD 7 800 000 1USA 1 000 000 2GB 500 000 3
A 140 000 4GB 50 000 5
For internal tables WITHOUT a header line
APPEND <wa> TO <itab>. APPEND <wa> TO <itab> SORTED BY <field>.
APPEND SORTED BYREPORT 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 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 3
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 ENTRIES…WHERE...…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 FLDATEFROM SFLIGHT INTO TABLE ITAB2
FOR ALL ENTRIES IN ITAB1WHERE 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 CARRIDINITIAL 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 TableSORT <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_FLTWITH NON-UNIQUE KEYCARRID CONNID FLDATE,
WA_ITAB TYPE T_FLT.SORT ITAB...SORT ITAB BY CARRID PAYMENTSUM...SORT ITAB BY CARRID ASCENDING
PAYMENTSUM DESCENDING.
Processing an Internal TableLOOP AT <itab>. ... ENDLOOP.
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_FLTWITH NON-UNIQUE KEY CARRID CONNID FLDATEINITIAL SIZE 0,
WA_ITAB TYPE T_FLT...
LOOP AT ITAB INTO WA_ITAB.WRITE: / WA_ITAB-CARRID, WA_ITAB-CITY, ... .
ENDLOOP...
LOOP AT ITAB INTO WA_ITAB WHERE CARRID BETWEEN 'AA' AND ‘LH'.WRITE: / WA_ITAB-CARRID, WA_ITAB-FLDATE, ... .
ENDLOOP.
Test SY-SUBRCTest SY-SUBRC
Test SY-SUBRCTest 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 StatementTYPES: 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_COMPANIESINITIAL 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.
AT NEW <field>.
AT END OF <field>.
AT FIRST.
AT LAST.
EXAMPLE
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 EntryREAD 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, thisstatement 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 ifheader line is used. Storage space is not releasedPaging is released
FREE <itab>.
Deletes all table lines except headerline if a header line is used.Storage space is released
Information About an Internal TableDESCRIBE TABLE <itab>... .
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: 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_COUNTOCCURS 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.