SAP ABAP Creating Internal Tables - SAP ABAP

What is the process of creating internal tables?

To declare an internal table a temporary table must be created within the program. In this there are certain options for the program to tell where the table begins and ends. SO with the BEGIN OF statement you can declare an internal table name. And second one is OCCURS addition creates a number value as 0. With the help of this option SAP confirms that internal table has been created. The 0 signifies that it does not contain any records. As the data is to be filled in the internal table, it expands.

Following is the syntax −

Here, enter the fields on a new line. You have to start always the field name on the new line. For example enter ‘name’ declared as LIKE ZCUSTOMERS1-name. Create another field called ‘dob’, LIKE ZCUSTOMERS1-dob. The user benefits by giving the field names in internal tables initially because the same names can be used for other fields which have been already created somewhere else. At last, to end the statement, declare an internal table with “END OF <internal tab>.” as shown in the following code −

To create a temporary table the most commonly used shorthand in SAP is itab01. The OCCURS clause determines the body of an internal table it also helps in declaring the fields for the table. With the OCCURS clause you can specify a number as ‘n’. It also helps in storing the additional memory if required and the size of the memory for OCCUR 0 clause is 8 KB. The structure of the internal table is now created, and the code can be written to fill it with records.

An internal table can be created with or without using a header line. To create an internal table with a header line, use either the BEGIN OF clause before the OCCURS clause or the WITH HEADER LINE clause after the OCCURS clause in the definition of the internal table. To create an internal table without a header line, use the OCCURS clause without the BEGIN OF clause.

You can also create an internal table as a local data type (a data type used only in the context of the current program) by using the TYPES statement. This statement uses the TYPE or LIKE clause to refer to an existing table.

The syntax to create an internal table as a local data type is −

Here the <internal_tab_type> specifies a table type for an internal table <internal_tab> and <line_type_itab> specifies the type for a line of an internal table. In TYPES statement, you can use the TYPE clause to specify the line type of an internal table as a data type and LIKE clause to specify the line type as a data object. Specifying a key for an internal table is optional and if the user does not specify a key, the SAP system defines a table type with an arbitrary key.

INITIAL SIZE <size_number> helps in reserving initial amount of memory which is easy to create an internal table object, and also for size number table lines. There is no correlation with the size of the object with that of data type of the table. you can create the internal table object without thinking of the size.

Note −Less memory is consumed when an internal table is populated for the first time.

Example

Step 1 – Click the ABAP Editor so that the SE38 transaction code appears. The initial screen of ABAP Editor appears.

Step 2 – Next type a name for the program; click the Source code radio button. To create a new program click create button.

Step 3 − The 'ABAP: Program Attributes' dialog box appears, type a short description in the Title field. Activate the 'Executable program' option from the Type drop-down menu in the Attributes group box. Click the Save button.

Step 4 − Write the following code in ABAP editor.

Step 5 – you have to save, activate and execute the program as directed.

In this example, you can see below the text my table is an internal table and a unique key is defined on the Cust_ID field.

The above code displays the following output-

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAP ABAP Topics