SlideShare a Scribd company logo
1 of 44
Data structures and Internal
tables
SAP - ABAP
Topics
2
 Data structures and Internal tables
Objectives
3
The participants will be able to:
Create a Structure in an ABAP Program
Create an Internal Table in an ABAP program
Populate an Internal Table with data
Read Database information into an Internal Table
Data Structures
4
Address List
Structure
Address List
Internal Table
LN FN City ST. LN FN City ST.
LN FN City ST.
LN FN City ST.
Declaring a Structure - Method #1
5
5
1 REPORT YN1C0008.
2
3 TABLES: TABNA.
4 DATA: BEGIN OF ADDRESS,
5 FLAG TYPE C,
6 ID LIKE TABNA-ID,
7 NAME1 LIKE TABNA-NAME1,
8 CITY LIKE TABNA-CITY,
9 END OF ADDRESS.
10 MOVE ‘X’ TO ADDRESS-FLAG.
11 MOVE ‘0001’ TO ADDRESS-ID.
12 MOVE ‘Smith’ TO ADDRESS-NAME1.
13 MOVE ‘Philadelphia’ TO
14 ADDRESS- CITY.
15 WRITE ADDRESS.
16
17
Basic Syntax:
DATA: BEGIN OF <name>
<field1> . . .
<field2> . . .
. . .
END OF <name>.
Flag ID Name1 City
Address Structure
Is this statement
necessary for the
code?
Declaring a Structure - Method #2
6
6 Data Structure & Inter3.07
REPORT Yxxxxxxx.
TYPES: BEGIN OF ADDR,
FLAG,
ID LIKE EMPLOYEE-ID,
NAME1 LIKE EMPLOYEE-NAME1,
CITY LIKE EMPLOYEE-CITY,
END OF ADDR.
DATA: ADDRESS TYPE ADDR.
MOVE: ‘X’ TO ADDRESS-FLAG,
‘00001’ TO ADDRESS-ID,
‘Smith’ TO ADDRESS-NAME1,
‘Philadelphia’ TO ADDRESS-CITY.
WRITE ADDRESS.
Basic Syntax:
TYPES: BEGIN OF <name1>,
<field1> . . . ,
<field2> . . . ,
. . . ,
END OF <name1>.
DATA: <name2> TYPE
<name1>.
Flag ID Name1 City
Address Structure
Populating a Structure with Field-by-Field Transport
7
7 Data Structure & Internal Tables | 3.07
REPORT Y170DM37.
TABLES: EMPLOYEE.
DATA: BEGIN OF ADDRESS,
FLAG,
ID LIKE EMPLOYEE-ID,
NAME LIKE EMPLOYEE-NAME1,
CITY LIKE EMPLOYEE-CITY,
END OF ADDRESS.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE
TO ADDRESS.
WRITE: / ADDRESS-FLAG,
ADDRESS-ID, ADDRESS-NAME,
ADDRESS-CITY.
CLEAR ADDRESS.
ENDSELECT.
EMPLOYEE
Address
ID Name1 City
000000001 Electronics Inc. Waldorf
MOVE-CORRESPONDING EMPLOYEE
TO ADDRESS.
Flag ID Name City
000000001 Waldorf
Clear <f1>.
Demonstration
8
8 Data Structure & Internal Tables | 3.07
 Declaring a structure and populating the structure with values inside a program.
Practice
9
9 Data Structure & Internal Tables | 3.07
 Declaring a structure and populating the structure with values inside a program.
Internal Table Types
10
10 Data Structure & Internal Tables | 3.07
 Standard
 Sorted
 Hashed
Creating an Internal Table with Header Line
11
11 Data Structure & Internal Tables | 3.07
REPORT Y170DM38.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
ID LIKE EMPLOYEE-ID,NAME1
LIKE EMPLOYEE-NAME1,
COUNTRY LIKE
EMPLOYEE-COUNTRY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE
OF EMP INITIAL SIZE 10 WITH
HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO
EMPTAB.
APPEND EMPTAB.
ENDSELECT.
The TYPES statement defines the
structure and data type for the
internal table.
The DATA statement with an
INITIAL SIZE creates the actual
internal table capable of storing
data. Because of the WITH
HEADER LINE addition, this
internal table is created with a
header line.
Header Line
ID NAME1 COUNTRY
Size of an Internal Table
12
12 Data Structure & Internal Tables | 3.07
Loading an Internal Table with a Header Line
13
13 Data Structure & Internal Tables | 3.07
APPEND <int. table>
SORTED BY <field>.
APPEND <int. table>.
Department Salary
1
2
3
4
5
6
Department Salary
Header
R&D 400,000
PROD 7,800,000
MKTG 1,000,000
SALES 500,000
HR 140,000
IT 50,000
R&D 400,000
MKTG 1,000,000
SALES 500,000
PROD 7,800,000
IT 50,000
HR 140,000
Loading an Internal Table with a Header Line
14
14 Data Structure & Internal Tables | 3.07
REPORT Y170DM42.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
ID LIKE EMPLOYEE-ID,
SALARY LIKE EMPLOYEE-SALARY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE
OF EMP INITIAL SIZE 10 WITH HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB SORTED BY SALARY.
ENDSELECT.
More than ten entries can be
saved in the internal table.
A maximum of ten entries
can be saved in the internal
table. Any entries that
exceed the top ten will
be deleted.
With both versions of the
APPEND statement, memory
space for ten records is
allocated when the first record
is written to the internal table.
Example 1
Example 2
OR
Loading an Internal Table with a Header Line
15
15 Data Structure & Internal Tables | 3.07
REPORT Y170DM42.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
ID LIKE EMPLOYEE-ID,
SALARY LIKE EMPLOYEE-SALARY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE
OF EMP INITIAL SIZE 10 WITH HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB SORTED BY SALARY.
ENDSELECT.
More than ten entries can be
saved in the internal table.
A maximum of ten entries
can be saved in the internal
table. Any entries that
exceed the top ten will
be deleted.
With both versions of the
APPEND statement, memory
space for ten records is
allocated when the first record
is written to the internal table.
Example 1
Example 2
OR
Internal Table with Header Line
16
16 Data Structure & Internal Tables | 3.07
EMPLOYEE
COUNTRY ID FORMA NAME1 SORTL . . .
ID NAME1 COUNTRY
Header Line
A
B
Internal Table with Header Line
17
17 Data Structure & Internal Tables | 3.07
ID NAME1 COUNTRY
EMPLOYEE
USA 00000001 Company Baker Distributors BAKER . . .
COUNTRY ID FORMA NAME1 SORTL . . .
Header Line
1
Internal Table with Header Line
18
18 Data Structure & Internal Tables | 3.07
ID NAME1 COUNTRY
00000001 Baker Distributors USA
EMPLOYEE
Header Line
2
1
USA 00000001 Company Baker Distributors BAKER . . .
COUNTRY ID FORMA NAME1 SORTL . . .
Internal Table with Header Line
19
19 Data Structure & Internal Tables | 3.07
USA 00000001 Company Baker Distributors BAKER . . .
ID NAME1 COUNTRY
00000001 Baker Distributors USA
00000001 Baker Distributors USA
EMPLOYEE
COUNTRY ID FORMA NAME1 SORTL . . .
Header Line
2
3
1
2
3
10
.
.
.
.
.
.
This header line is
attached to the
body of the
internal table.
1
Internal Table with Header Line
20
20 Data Structure & Internal Tables | 3.07
ID NAME1 COUNTRY
00000001 Baker Distributors USA
00000002 Diversified Indust... USA
00000002 Diversified Indust... USA
USA 00000002 Company Diversified Indust.. DIVERS . . .
EMPLOYEE
COUNTRY ID FORMA NAME1 SORTL . . .
Header Line
5
6
1
2
3
10
.
.
.
.
.
.
4
Creating an Internal Table without a Header Line
REPORT Y170DM40.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
ID LIKE EMPLOYEE-ID,
NAME1 LIKE EMPLOYEE-NAME1,
COUNTRY LIKE EMPLOYEE-COUNTRY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE
OF EMP INITIAL SIZE 10,
EMPTAB_WA TYPE EMP.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB_WA.
APPEND EMPTAB_WA TO EMPTAB.
ENDSELECT.
ID NAME1 COUNTRY
APPEND <work area> to <EMPTAB>.
The TYPES statement defines the
structure and data type for the
internal table and its work area
Work Area
The DATA statement with an INITIAL
SIZE creates the actual internal table
without a header line. The DATA
statement without the INITIAL SIZE
creates the work area for the internal
table.
Internal Table without a Header Line WHY???
22
22 Data Structure & Internal Tables | 3.07
Separate Internal Table Work Area
Performance Issues
Nested Internal Tables
Internal Table without a Header Line
23
23 Data Structure & Internal Tables | 3.07
EMPLOYEE
COUNTRY ID FORMA NAME1 SORTL . . .
Work Area
A
B
ID NAME1 COUNTRY
Internal Table without a Header Line
24
24 Data Structure & Internal Tables | 3.07
ID NAME1 COUNTRY
ID NAME1 COUNTRY
00000001 Baker Distributors USA
00000001 Baker Distributors USA
USA 00000001 Company Baker Distributors BAKER . . .
EMPLOYEE
COUNTRY ID FORMA NAME1 SORT . . .
Work Area
1
2
3
1
2
3
10
.
.
.
This work area is
not attached to
the body of the
internal table.
Automatic Field Conversion
25
25 Data Structure & Internal Tables | 3.07
 MOVE-CORRESPONDING or MOVE field to field
– Individual field type conversion
 MOVE
– Structure to structure
– Field to structure
– Structure to field
• Intermediate C type
• Followed by adoption of new types
Mass Reading from Database Tables into Internal Tables
26
26 Data Structure & Internal Tables | 3.07
REPORT Y170DM69.
TABLES: EMPLOYEE.
DATA: EMPTAB LIKE STANDARD TABLE EMPLOYEE INITIAL
SIZE 10 WITH HEADER LINE.
SELECT * FROM EMPLOYEE INTO TABLE EMPTAB
WHERE COUNTRY = ‘USA’.
SELECT * FROM <table> . . .
1. INTO TABLE <EMPTAB>.
2. APPENDING TABLE <EMPTAB>.
Notice no ENDSELECT is
needed here because no loop
processing occurs.
Processing an Internal Table
27
27 Data Structure & Internal Tables | 3.07
REPORT Y170DM45.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
SALES LIKE EMPLOYEE-SALES,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER
LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
LOOP AT EMPTAB WHERE COUNTRY BETWEEN ‘A’ AND ‘D’.
WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1,
EMPTAB-SALES.
ENDLOOP.
IF SY-SUBRC NE 0.
WRITE: / ‘NO ENTRIES’.
ENDIF.
This LOOP AT <EMPTAB>
statement allows for a logical
expression in a WHERE clause to
limit the processing of the internal
table.
If no internal table entries
qualify under the logical
expression, the statement
within the loop is not executed
and SY-SUBRC is set to 4.
System Field SY-TABIX
28
28 Data Structure & Internal Tables | 3.07
REPORT Y170DM46.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP
INITIAL SIZE 10 WITH HEADER LINE.
PARAMETERS: START LIKE SY-TABIX DEFAULT 10,
END LIKE SY-TABIX DEFAULT 20.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
LOOP AT EMPTAB FROM START TO END.
WRITE: / SY-TABIX, EMPTAB-COUNTRY, EMPTAB-NAME1.
ENDLOOP.
Screen output
SY-TABIX
Accumulating Data within an Internal Table
29
29 Data Structure & Internal Tables | 3.07
REPORT Y170DM43.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
SALES LIKE EMPLOYEE-SALES,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL
SIZE 10 WITH HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
COLLECT EMPTAB.
ENDSELECT.
LOOP AT EMPTAB.
WRITE: / EMPTAB-COUNTRY, EMPTAB-SALES.
ENDLOOP.
COLLECT <EMPTAB>.
Country Sales
D 400,000
USA 1,000,000
GB 500,000
D 7,800,000
Header Line
A 371,065.00
CH 45,305.00
D 8,200,000.00
F 0.00
GB 500,000.00
NL 577,000.00
NO 234.00
USA 1,000,000.00
HK 0.00
Screen output
Sorting an Internal Table
30
30 Data Structure & Internal Tables | 3.07
REPORT Y170DM44.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
SALES LIKE EMPLOYEE-SALES,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP
INITIAL SIZE 10 WITH HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
SORT EMPTAB BY SALES DESCENDING.
LOOP AT EMPTAB.
WRITE: / ITAB-COUNTRY, ITAB-NAME1, ITAB-SALES.
ENDLOOP.
Sorting options:
1) SORT <EMPTAB> - sorts the
entries of the internal table
<EMPTAB> in ascending order.
2) SORT <EMPTAB> BY <field> - sorts
the table on one or more fields
within the table.
screen output
Control Level Processing
31
31 Data Structure & Internal Tables | 3.07
 AT FIRST
 AT NEW < field >
 AT END < field >
 AT LAST
Reading a Single Table Entry
32
32 Data Structure & Internal Tables | 3.07
REPORT Y170DM47.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMPTAB.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH
HEADER LINE.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
READ TABLE ….
Reading a Single Table Entry - Options
33
33 Data Structure & Internal Tables | 3.07
READ TABLE <EMPTAB> options:
1) READ TABLE <EMPTAB>.
2) READ TABLE <EMPTAB> WITH KEY <k1> = <v1>…
<kn> = <vn>.
3) READ TABLE <EMPTAB> WITH TABLE KEY <k1> = <v1> ...
<kn> = <vn>.
4) READ TABLE <EMPTAB> WITH KEY = <value>.
5) READ TABLE <EMPTAB> WITH KEY . . . BINARY SEARCH.
6) READ TABLE <EMPTAB> INDEX <i>.
7) READ TABLE <EMPTAB> COMPARING <f1> <f2> . . . .
8) READ TABLE <EMPTAB> COMPARING ALL FIELDS.
9) READ TABLE <EMPTAB> TRANSPORTING <f1> <f2> . . . .
10) READ TABLE <EMPTAB> TRANSPORTING NO FIELDS.
Maintaining Internal Tables
34
34 Data Structure & Internal Tables | 3.07
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
READ TABLE EMPTAB INDEX 1.
MOVE ‘ABC’ TO EMPTAB-NAME1.
MODIFY EMPTAB INDEX SY-TABIX.
IF SY-SUBRC NE 0.
WRITE / ‘Attempt to modify failed.’.
ELSE.
WRITE: / EMPTAB-COUNTRY,
EMPTAB-NAME1.
ENDIF.
INSERT EMPTAB INDEX 1.
DELETE EMPTAB INDEX SY-TABIX.
INSERT <EMPTAB> INDEX <i>.
MODIFY <EMPTAB> INDEX <i>.
DELETE <EMPTAB> INDEX <i>.
Check SY-SUBRC after
every attempt to change
an internal table entry.
Working with an Internal Table without a Header Line
35
35 Data Structure & Internal Tables | 3.07
APPEND <work area> TO <internal table>.
COLLECT <work area> INTO <internal table>.
INSERT <work area> INTO <internal table>.
MODIFY <internal table> FROM <work area>.
READ TABLE <internal table> INTO <work area>.
LOOP AT <internal table> INTO <work area>.
Deleting an Internal Table
36
36 Data Structure & Internal Tables | 3.07
CLEAR <internal table>
 Initialises the header line.
 Internal table lines remain
unchanged.
REFRESH <internal table>
 Deletes all table lines.
 Storage space is not released.
 Paging is released.
 Header line remains unchanged.
FREE <internal table>
 Deletes all table lines.
 Storage space is released.
 Header line remains
unchanged
Information about an Internal Table
37
37 Data Structure & Internal Tables | 3.07
REPORT Y170DM49.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH
HEADER LINE,
LINE_COUNT TYPE I,
INITIAL_COUNT TYPE I.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
DESCRIBE TABLE EMPTAB
LINES LINE_COUNT
OCCURS INITIAL_COUNT.
WRITE: / ‘ lines:’, LINE_COUNT,
/ ‘occurs:’, INITIAL SIZE_COUNT.
DESCRIBE TABLE <internal table>
LINES <var1>
OCCURS <var2>.
screen output
Calling the SAP Table Editor
38
38 Data Structure & Internal Tables | 3.07
REPORT Y170DM50.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMP,
DATA:EMPTAB TYPE STANDARD TABLE OF EMP
INITIAL SIZE 10 WITH HEADER LINE,
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
EDITOR-CALL FOR EMPTAB.
CHECK SY-SUBRC EQ 0.
LOOP AT EMPTAB WHERE NAME1 EQ ‘Maurice Cheeks’.
WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1.
ENDLOOP.
IF SY-SUBRC NE 0. WRITE: / ‘No records.’. ENDIF.
screen output
Demonstration
39
39 Data Structure & Internal Tables | 3.07
 Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
Practice
40
40 Data Structure & Internal Tables | 3.07
 Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
Summary
41
41 Data Structure & Internal Tables | 3.07
 Structures in code are temporary objects in program memory.
 A structure can be defined using a combination of the TYPES and DATA
statements.
 The statement MOVE-CORRESPONDING transports values field by field between
the ABAP data structures.
 Internal table, that can store records of data temporarily during the processing
of a program.
 3 different types of internal tables: Standard, Sorted, and Hashed.
 An internal table object is created with the DATA statement by referring to an
internal table type using the TYPE parameter
 APPEND statement adds the contents of the header line to the end of the
internal table.
 the system field SY-TABIX is set to the line number of the entry read.
Summary (Contd.)
42
42 Data Structure & Internal Tables | 3.07
 The CLEAR statement resets all fields to their initial value.
 The REFRESH statement deletes all table lines.
 The FREE statement releases the storage space required for a table.
Questions
43
43 Data Structure & Internal Tables | 3.07
 What is a Structure?
 What is an internal table?
 What are the different types of internal tables are there?
 Explain the following statements :
 Move corresponding
 Append
 Clear
 Refresh
 Free.
44
Thanks

More Related Content

What's hot

ABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infoABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infosapdocs. info
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniquesJugul Crasta
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answersUttam Agrawal
 
Bdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONBdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONHitesh Gulani
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Tablesapdocs. info
 
Sap abap database table
Sap abap database tableSap abap database table
Sap abap database tableDucat
 
Sap abap interview questions
Sap abap interview questionsSap abap interview questions
Sap abap interview questionskssr99
 
Sap abap real time questions
Sap abap real time questionsSap abap real time questions
Sap abap real time questionstechie_gautam
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPNoman Mohamed Hanif
 
SAP ABAP HR TRAINING
SAP ABAP HR TRAININGSAP ABAP HR TRAINING
SAP ABAP HR TRAININGJoshiRavin
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questionsKranthi Kumar
 

What's hot (20)

Module pool programming
Module pool programmingModule pool programming
Module pool programming
 
Abap reports
Abap reportsAbap reports
Abap reports
 
Abap dictionary 1
Abap dictionary 1Abap dictionary 1
Abap dictionary 1
 
ABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.infoABAP for Beginners - www.sapdocs.info
ABAP for Beginners - www.sapdocs.info
 
Sap abap
Sap abapSap abap
Sap abap
 
Reports
ReportsReports
Reports
 
SAP Modularization techniques
SAP Modularization techniquesSAP Modularization techniques
SAP Modularization techniques
 
Smartforms interview questions with answers
Smartforms interview questions with answersSmartforms interview questions with answers
Smartforms interview questions with answers
 
Bdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATIONBdc BATCH DATA COMMUNICATION
Bdc BATCH DATA COMMUNICATION
 
ABAP Open SQL & Internal Table
ABAP Open SQL & Internal TableABAP Open SQL & Internal Table
ABAP Open SQL & Internal Table
 
Badi document
Badi documentBadi document
Badi document
 
Sap abap database table
Sap abap database tableSap abap database table
Sap abap database table
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 
SAP Adobe forms
SAP Adobe formsSAP Adobe forms
SAP Adobe forms
 
Sap abap interview questions
Sap abap interview questionsSap abap interview questions
Sap abap interview questions
 
Bapi step-by-step
Bapi step-by-stepBapi step-by-step
Bapi step-by-step
 
Sap abap real time questions
Sap abap real time questionsSap abap real time questions
Sap abap real time questions
 
Object oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAPObject oriented approach to ALV Lists in ABAP
Object oriented approach to ALV Lists in ABAP
 
SAP ABAP HR TRAINING
SAP ABAP HR TRAININGSAP ABAP HR TRAINING
SAP ABAP HR TRAINING
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
 

Viewers also liked

Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Kranthi Kumar
 
Creating simple comp
Creating simple compCreating simple comp
Creating simple compKranthi Kumar
 
Open SQL & Internal Table
Open SQL & Internal TableOpen SQL & Internal Table
Open SQL & Internal Tablesapdocs. info
 
SAP FICO BBP Sample Document PDF NEW!
SAP FICO BBP Sample Document PDF NEW!SAP FICO BBP Sample Document PDF NEW!
SAP FICO BBP Sample Document PDF NEW!sapdocs. info
 

Viewers also liked (7)

Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1Chapter 08 abap dictionary objects views1
Chapter 08 abap dictionary objects views1
 
Creating messages
Creating messagesCreating messages
Creating messages
 
Creating simple comp
Creating simple compCreating simple comp
Creating simple comp
 
Dynamic binding
Dynamic bindingDynamic binding
Dynamic binding
 
Exercise in alv
Exercise in alvExercise in alv
Exercise in alv
 
Open SQL & Internal Table
Open SQL & Internal TableOpen SQL & Internal Table
Open SQL & Internal Table
 
SAP FICO BBP Sample Document PDF NEW!
SAP FICO BBP Sample Document PDF NEW!SAP FICO BBP Sample Document PDF NEW!
SAP FICO BBP Sample Document PDF NEW!
 

Similar to Data structures and Internal tables in SAP ABAP

Internal tables in sap
Internal tables in sapInternal tables in sap
Internal tables in sapDharma Raju
 
Lecture06 abap on line
Lecture06 abap on lineLecture06 abap on line
Lecture06 abap on lineMilind Patil
 
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxPart 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxhoney690131
 
HALL OF FAME INDUCTIONS
HALL OF FAME INDUCTIONSHALL OF FAME INDUCTIONS
HALL OF FAME INDUCTIONSTalia Strnad
 
Abap report
Abap reportAbap report
Abap reportDucat
 
Best SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireBest SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireAspire Techsoft Academy
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLPrashant Kumar
 
What is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdfWhat is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdfarjunstores123
 
Part 2Provider Database (Open Office Database)Use the project des.docx
Part 2Provider Database (Open Office Database)Use the project des.docxPart 2Provider Database (Open Office Database)Use the project des.docx
Part 2Provider Database (Open Office Database)Use the project des.docxdanhaley45372
 
SAP-ABAP-List-Processing.ppt
SAP-ABAP-List-Processing.pptSAP-ABAP-List-Processing.ppt
SAP-ABAP-List-Processing.pptGaneshP820675
 

Similar to Data structures and Internal tables in SAP ABAP (20)

Internal tables in sap
Internal tables in sapInternal tables in sap
Internal tables in sap
 
Lecture06 abap on line
Lecture06 abap on lineLecture06 abap on line
Lecture06 abap on line
 
Sq lite module7
Sq lite module7Sq lite module7
Sq lite module7
 
Basic programming
Basic programmingBasic programming
Basic programming
 
05 internal tables
05 internal tables05 internal tables
05 internal tables
 
07 sap scripts
07 sap scripts07 sap scripts
07 sap scripts
 
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxPart 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
 
Sql Document in Testing
Sql Document in TestingSql Document in Testing
Sql Document in Testing
 
HALL OF FAME INDUCTIONS
HALL OF FAME INDUCTIONSHALL OF FAME INDUCTIONS
HALL OF FAME INDUCTIONS
 
Normalization
NormalizationNormalization
Normalization
 
Sql Server 2000
Sql Server 2000Sql Server 2000
Sql Server 2000
 
Abap report
Abap reportAbap report
Abap report
 
Aspire it sap abap training
Aspire it   sap abap trainingAspire it   sap abap training
Aspire it sap abap training
 
Best SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | AspireBest SAP ABAP Training Institute with Placement in Pune | Aspire
Best SAP ABAP Training Institute with Placement in Pune | Aspire
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
What is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdfWhat is Database NormalizationExplain the guidelines for ensuring t.pdf
What is Database NormalizationExplain the guidelines for ensuring t.pdf
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
Part 2Provider Database (Open Office Database)Use the project des.docx
Part 2Provider Database (Open Office Database)Use the project des.docxPart 2Provider Database (Open Office Database)Use the project des.docx
Part 2Provider Database (Open Office Database)Use the project des.docx
 
SAP-ABAP-List-Processing.ppt
SAP-ABAP-List-Processing.pptSAP-ABAP-List-Processing.ppt
SAP-ABAP-List-Processing.ppt
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 

Recently uploaded

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Data structures and Internal tables in SAP ABAP

  • 1. Data structures and Internal tables SAP - ABAP
  • 2. Topics 2  Data structures and Internal tables
  • 3. Objectives 3 The participants will be able to: Create a Structure in an ABAP Program Create an Internal Table in an ABAP program Populate an Internal Table with data Read Database information into an Internal Table
  • 4. Data Structures 4 Address List Structure Address List Internal Table LN FN City ST. LN FN City ST. LN FN City ST. LN FN City ST.
  • 5. Declaring a Structure - Method #1 5 5 1 REPORT YN1C0008. 2 3 TABLES: TABNA. 4 DATA: BEGIN OF ADDRESS, 5 FLAG TYPE C, 6 ID LIKE TABNA-ID, 7 NAME1 LIKE TABNA-NAME1, 8 CITY LIKE TABNA-CITY, 9 END OF ADDRESS. 10 MOVE ‘X’ TO ADDRESS-FLAG. 11 MOVE ‘0001’ TO ADDRESS-ID. 12 MOVE ‘Smith’ TO ADDRESS-NAME1. 13 MOVE ‘Philadelphia’ TO 14 ADDRESS- CITY. 15 WRITE ADDRESS. 16 17 Basic Syntax: DATA: BEGIN OF <name> <field1> . . . <field2> . . . . . . END OF <name>. Flag ID Name1 City Address Structure Is this statement necessary for the code?
  • 6. Declaring a Structure - Method #2 6 6 Data Structure & Inter3.07 REPORT Yxxxxxxx. TYPES: BEGIN OF ADDR, FLAG, ID LIKE EMPLOYEE-ID, NAME1 LIKE EMPLOYEE-NAME1, CITY LIKE EMPLOYEE-CITY, END OF ADDR. DATA: ADDRESS TYPE ADDR. MOVE: ‘X’ TO ADDRESS-FLAG, ‘00001’ TO ADDRESS-ID, ‘Smith’ TO ADDRESS-NAME1, ‘Philadelphia’ TO ADDRESS-CITY. WRITE ADDRESS. Basic Syntax: TYPES: BEGIN OF <name1>, <field1> . . . , <field2> . . . , . . . , END OF <name1>. DATA: <name2> TYPE <name1>. Flag ID Name1 City Address Structure
  • 7. Populating a Structure with Field-by-Field Transport 7 7 Data Structure & Internal Tables | 3.07 REPORT Y170DM37. TABLES: EMPLOYEE. DATA: BEGIN OF ADDRESS, FLAG, ID LIKE EMPLOYEE-ID, NAME LIKE EMPLOYEE-NAME1, CITY LIKE EMPLOYEE-CITY, END OF ADDRESS. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO ADDRESS. WRITE: / ADDRESS-FLAG, ADDRESS-ID, ADDRESS-NAME, ADDRESS-CITY. CLEAR ADDRESS. ENDSELECT. EMPLOYEE Address ID Name1 City 000000001 Electronics Inc. Waldorf MOVE-CORRESPONDING EMPLOYEE TO ADDRESS. Flag ID Name City 000000001 Waldorf Clear <f1>.
  • 8. Demonstration 8 8 Data Structure & Internal Tables | 3.07  Declaring a structure and populating the structure with values inside a program.
  • 9. Practice 9 9 Data Structure & Internal Tables | 3.07  Declaring a structure and populating the structure with values inside a program.
  • 10. Internal Table Types 10 10 Data Structure & Internal Tables | 3.07  Standard  Sorted  Hashed
  • 11. Creating an Internal Table with Header Line 11 11 Data Structure & Internal Tables | 3.07 REPORT Y170DM38. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, ID LIKE EMPLOYEE-ID,NAME1 LIKE EMPLOYEE-NAME1, COUNTRY LIKE EMPLOYEE-COUNTRY, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. The TYPES statement defines the structure and data type for the internal table. The DATA statement with an INITIAL SIZE creates the actual internal table capable of storing data. Because of the WITH HEADER LINE addition, this internal table is created with a header line. Header Line ID NAME1 COUNTRY
  • 12. Size of an Internal Table 12 12 Data Structure & Internal Tables | 3.07
  • 13. Loading an Internal Table with a Header Line 13 13 Data Structure & Internal Tables | 3.07 APPEND <int. table> SORTED BY <field>. APPEND <int. table>. Department Salary 1 2 3 4 5 6 Department Salary Header R&D 400,000 PROD 7,800,000 MKTG 1,000,000 SALES 500,000 HR 140,000 IT 50,000 R&D 400,000 MKTG 1,000,000 SALES 500,000 PROD 7,800,000 IT 50,000 HR 140,000
  • 14. Loading an Internal Table with a Header Line 14 14 Data Structure & Internal Tables | 3.07 REPORT Y170DM42. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, ID LIKE EMPLOYEE-ID, SALARY LIKE EMPLOYEE-SALARY, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB SORTED BY SALARY. ENDSELECT. More than ten entries can be saved in the internal table. A maximum of ten entries can be saved in the internal table. Any entries that exceed the top ten will be deleted. With both versions of the APPEND statement, memory space for ten records is allocated when the first record is written to the internal table. Example 1 Example 2 OR
  • 15. Loading an Internal Table with a Header Line 15 15 Data Structure & Internal Tables | 3.07 REPORT Y170DM42. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, ID LIKE EMPLOYEE-ID, SALARY LIKE EMPLOYEE-SALARY, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB SORTED BY SALARY. ENDSELECT. More than ten entries can be saved in the internal table. A maximum of ten entries can be saved in the internal table. Any entries that exceed the top ten will be deleted. With both versions of the APPEND statement, memory space for ten records is allocated when the first record is written to the internal table. Example 1 Example 2 OR
  • 16. Internal Table with Header Line 16 16 Data Structure & Internal Tables | 3.07 EMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . . ID NAME1 COUNTRY Header Line A B
  • 17. Internal Table with Header Line 17 17 Data Structure & Internal Tables | 3.07 ID NAME1 COUNTRY EMPLOYEE USA 00000001 Company Baker Distributors BAKER . . . COUNTRY ID FORMA NAME1 SORTL . . . Header Line 1
  • 18. Internal Table with Header Line 18 18 Data Structure & Internal Tables | 3.07 ID NAME1 COUNTRY 00000001 Baker Distributors USA EMPLOYEE Header Line 2 1 USA 00000001 Company Baker Distributors BAKER . . . COUNTRY ID FORMA NAME1 SORTL . . .
  • 19. Internal Table with Header Line 19 19 Data Structure & Internal Tables | 3.07 USA 00000001 Company Baker Distributors BAKER . . . ID NAME1 COUNTRY 00000001 Baker Distributors USA 00000001 Baker Distributors USA EMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . . Header Line 2 3 1 2 3 10 . . . . . . This header line is attached to the body of the internal table. 1
  • 20. Internal Table with Header Line 20 20 Data Structure & Internal Tables | 3.07 ID NAME1 COUNTRY 00000001 Baker Distributors USA 00000002 Diversified Indust... USA 00000002 Diversified Indust... USA USA 00000002 Company Diversified Indust.. DIVERS . . . EMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . . Header Line 5 6 1 2 3 10 . . . . . . 4
  • 21. Creating an Internal Table without a Header Line REPORT Y170DM40. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, ID LIKE EMPLOYEE-ID, NAME1 LIKE EMPLOYEE-NAME1, COUNTRY LIKE EMPLOYEE-COUNTRY, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10, EMPTAB_WA TYPE EMP. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB_WA. APPEND EMPTAB_WA TO EMPTAB. ENDSELECT. ID NAME1 COUNTRY APPEND <work area> to <EMPTAB>. The TYPES statement defines the structure and data type for the internal table and its work area Work Area The DATA statement with an INITIAL SIZE creates the actual internal table without a header line. The DATA statement without the INITIAL SIZE creates the work area for the internal table.
  • 22. Internal Table without a Header Line WHY??? 22 22 Data Structure & Internal Tables | 3.07 Separate Internal Table Work Area Performance Issues Nested Internal Tables
  • 23. Internal Table without a Header Line 23 23 Data Structure & Internal Tables | 3.07 EMPLOYEE COUNTRY ID FORMA NAME1 SORTL . . . Work Area A B ID NAME1 COUNTRY
  • 24. Internal Table without a Header Line 24 24 Data Structure & Internal Tables | 3.07 ID NAME1 COUNTRY ID NAME1 COUNTRY 00000001 Baker Distributors USA 00000001 Baker Distributors USA USA 00000001 Company Baker Distributors BAKER . . . EMPLOYEE COUNTRY ID FORMA NAME1 SORT . . . Work Area 1 2 3 1 2 3 10 . . . This work area is not attached to the body of the internal table.
  • 25. Automatic Field Conversion 25 25 Data Structure & Internal Tables | 3.07  MOVE-CORRESPONDING or MOVE field to field – Individual field type conversion  MOVE – Structure to structure – Field to structure – Structure to field • Intermediate C type • Followed by adoption of new types
  • 26. Mass Reading from Database Tables into Internal Tables 26 26 Data Structure & Internal Tables | 3.07 REPORT Y170DM69. TABLES: EMPLOYEE. DATA: EMPTAB LIKE STANDARD TABLE EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE INTO TABLE EMPTAB WHERE COUNTRY = ‘USA’. SELECT * FROM <table> . . . 1. INTO TABLE <EMPTAB>. 2. APPENDING TABLE <EMPTAB>. Notice no ENDSELECT is needed here because no loop processing occurs.
  • 27. Processing an Internal Table 27 27 Data Structure & Internal Tables | 3.07 REPORT Y170DM45. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, SALES LIKE EMPLOYEE-SALES, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. LOOP AT EMPTAB WHERE COUNTRY BETWEEN ‘A’ AND ‘D’. WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1, EMPTAB-SALES. ENDLOOP. IF SY-SUBRC NE 0. WRITE: / ‘NO ENTRIES’. ENDIF. This LOOP AT <EMPTAB> statement allows for a logical expression in a WHERE clause to limit the processing of the internal table. If no internal table entries qualify under the logical expression, the statement within the loop is not executed and SY-SUBRC is set to 4.
  • 28. System Field SY-TABIX 28 28 Data Structure & Internal Tables | 3.07 REPORT Y170DM46. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. PARAMETERS: START LIKE SY-TABIX DEFAULT 10, END LIKE SY-TABIX DEFAULT 20. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. LOOP AT EMPTAB FROM START TO END. WRITE: / SY-TABIX, EMPTAB-COUNTRY, EMPTAB-NAME1. ENDLOOP. Screen output SY-TABIX
  • 29. Accumulating Data within an Internal Table 29 29 Data Structure & Internal Tables | 3.07 REPORT Y170DM43. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, SALES LIKE EMPLOYEE-SALES, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. COLLECT EMPTAB. ENDSELECT. LOOP AT EMPTAB. WRITE: / EMPTAB-COUNTRY, EMPTAB-SALES. ENDLOOP. COLLECT <EMPTAB>. Country Sales D 400,000 USA 1,000,000 GB 500,000 D 7,800,000 Header Line A 371,065.00 CH 45,305.00 D 8,200,000.00 F 0.00 GB 500,000.00 NL 577,000.00 NO 234.00 USA 1,000,000.00 HK 0.00 Screen output
  • 30. Sorting an Internal Table 30 30 Data Structure & Internal Tables | 3.07 REPORT Y170DM44. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, SALES LIKE EMPLOYEE-SALES, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. SORT EMPTAB BY SALES DESCENDING. LOOP AT EMPTAB. WRITE: / ITAB-COUNTRY, ITAB-NAME1, ITAB-SALES. ENDLOOP. Sorting options: 1) SORT <EMPTAB> - sorts the entries of the internal table <EMPTAB> in ascending order. 2) SORT <EMPTAB> BY <field> - sorts the table on one or more fields within the table. screen output
  • 31. Control Level Processing 31 31 Data Structure & Internal Tables | 3.07  AT FIRST  AT NEW < field >  AT END < field >  AT LAST
  • 32. Reading a Single Table Entry 32 32 Data Structure & Internal Tables | 3.07 REPORT Y170DM47. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, END OF EMPTAB. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. READ TABLE ….
  • 33. Reading a Single Table Entry - Options 33 33 Data Structure & Internal Tables | 3.07 READ TABLE <EMPTAB> options: 1) READ TABLE <EMPTAB>. 2) READ TABLE <EMPTAB> WITH KEY <k1> = <v1>… <kn> = <vn>. 3) READ TABLE <EMPTAB> WITH TABLE KEY <k1> = <v1> ... <kn> = <vn>. 4) READ TABLE <EMPTAB> WITH KEY = <value>. 5) READ TABLE <EMPTAB> WITH KEY . . . BINARY SEARCH. 6) READ TABLE <EMPTAB> INDEX <i>. 7) READ TABLE <EMPTAB> COMPARING <f1> <f2> . . . . 8) READ TABLE <EMPTAB> COMPARING ALL FIELDS. 9) READ TABLE <EMPTAB> TRANSPORTING <f1> <f2> . . . . 10) READ TABLE <EMPTAB> TRANSPORTING NO FIELDS.
  • 34. Maintaining Internal Tables 34 34 Data Structure & Internal Tables | 3.07 SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. READ TABLE EMPTAB INDEX 1. MOVE ‘ABC’ TO EMPTAB-NAME1. MODIFY EMPTAB INDEX SY-TABIX. IF SY-SUBRC NE 0. WRITE / ‘Attempt to modify failed.’. ELSE. WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1. ENDIF. INSERT EMPTAB INDEX 1. DELETE EMPTAB INDEX SY-TABIX. INSERT <EMPTAB> INDEX <i>. MODIFY <EMPTAB> INDEX <i>. DELETE <EMPTAB> INDEX <i>. Check SY-SUBRC after every attempt to change an internal table entry.
  • 35. Working with an Internal Table without a Header Line 35 35 Data Structure & Internal Tables | 3.07 APPEND <work area> TO <internal table>. COLLECT <work area> INTO <internal table>. INSERT <work area> INTO <internal table>. MODIFY <internal table> FROM <work area>. READ TABLE <internal table> INTO <work area>. LOOP AT <internal table> INTO <work area>.
  • 36. Deleting an Internal Table 36 36 Data Structure & Internal Tables | 3.07 CLEAR <internal table>  Initialises the header line.  Internal table lines remain unchanged. REFRESH <internal table>  Deletes all table lines.  Storage space is not released.  Paging is released.  Header line remains unchanged. FREE <internal table>  Deletes all table lines.  Storage space is released.  Header line remains unchanged
  • 37. Information about an Internal Table 37 37 Data Structure & Internal Tables | 3.07 REPORT Y170DM49. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, END OF EMP. DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE, LINE_COUNT TYPE I, INITIAL_COUNT TYPE I. SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. DESCRIBE TABLE EMPTAB LINES LINE_COUNT OCCURS INITIAL_COUNT. WRITE: / ‘ lines:’, LINE_COUNT, / ‘occurs:’, INITIAL SIZE_COUNT. DESCRIBE TABLE <internal table> LINES <var1> OCCURS <var2>. screen output
  • 38. Calling the SAP Table Editor 38 38 Data Structure & Internal Tables | 3.07 REPORT Y170DM50. TABLES: EMPLOYEE. TYPES: BEGIN OF EMP, COUNTRY LIKE EMPLOYEE-COUNTRY, NAME1 LIKE EMPLOYEE-NAME1, END OF EMP, DATA:EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE, SELECT * FROM EMPLOYEE. MOVE-CORRESPONDING EMPLOYEE TO EMPTAB. APPEND EMPTAB. ENDSELECT. EDITOR-CALL FOR EMPTAB. CHECK SY-SUBRC EQ 0. LOOP AT EMPTAB WHERE NAME1 EQ ‘Maurice Cheeks’. WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1. ENDLOOP. IF SY-SUBRC NE 0. WRITE: / ‘No records.’. ENDIF. screen output
  • 39. Demonstration 39 39 Data Structure & Internal Tables | 3.07  Declaring an internal table, populating it by selecting data from the table and then looping into it and displaying the data fetched.
  • 40. Practice 40 40 Data Structure & Internal Tables | 3.07  Declaring an internal table, populating it by selecting data from the table and then looping into it and displaying the data fetched.
  • 41. Summary 41 41 Data Structure & Internal Tables | 3.07  Structures in code are temporary objects in program memory.  A structure can be defined using a combination of the TYPES and DATA statements.  The statement MOVE-CORRESPONDING transports values field by field between the ABAP data structures.  Internal table, that can store records of data temporarily during the processing of a program.  3 different types of internal tables: Standard, Sorted, and Hashed.  An internal table object is created with the DATA statement by referring to an internal table type using the TYPE parameter  APPEND statement adds the contents of the header line to the end of the internal table.  the system field SY-TABIX is set to the line number of the entry read.
  • 42. Summary (Contd.) 42 42 Data Structure & Internal Tables | 3.07  The CLEAR statement resets all fields to their initial value.  The REFRESH statement deletes all table lines.  The FREE statement releases the storage space required for a table.
  • 43. Questions 43 43 Data Structure & Internal Tables | 3.07  What is a Structure?  What is an internal table?  What are the different types of internal tables are there?  Explain the following statements :  Move corresponding  Append  Clear  Refresh  Free.