How to Create Internal Tables?

Answer

Creating Internal Tables

There are many ways to create an Internal Table. Lets look at them one by one-

1.By Using the Type Statement

Let us now create a Internal table itab using the TYPE statement.

The syntax is -

 

Types : begin of line,
 
column1 type I,
 
column2 type I,
 
end of line.

 

Example:

1
2
3
4
5
6
7
TYPES : begin of line,
 
empno       type I,
 
empname(20)     type c  ,
 
end of line.

 

The TYPES statement creates a structure line as defined.

To actually create an Internal Table itab use the following command-
 

1
Data itab type line occurs 10.

 

An internal table itab is created with the structure of line.Besides declaring the structure of an internal table, the OCCURS clause also defines how many table entries are maintained in main storage(in this case 10). Extra records are written out to paging area and can effect performance

2.By referring to another Table

You can  create an internal table by referring to an existing table. The existing table could be a standard SAP table, a Z table or another internal table.

Syntax-

1
Data <f> <type> [with header line].

 

Example-

1
DATA itab TYPE line OCCURS 10 with header line.

 

Here an internal table itab is created of the type line with a header line. Please note "with header line" is optional

3.By referring to existing Structure

Syntax-

1
Data    <f> LIKE <struct> occurs n [with header line].

 

Example-

1
DATA itab LIKE sline OCCURS 10.

 

Here  a table itab is created having a structure same as that of sline

4.By creating a new Structure

Let us now create an internal table with a structure of our own. Here the table is created with an Header line, by default.

Syntax -

1
2
3
4
5
6
7
Data : Begin of <f> occurs <n>,
 
<component declaration>,
 
.................................,
 
End of <f>.

 

Example -

1
2
3
4
5
6
7
8
9
Data : Begin of itab occurs 10,
 
column1       type I,
 
column2(4)  type C,
 
column3      like  mara-ernam,
 
End of itab.

 

Internal table itab is created

All SAP ABAP Questions

Ask your interview questions on sap-abap

Write Your comment or Questions if you want the answers on sap-abap from sap-abap Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---