- SAP ABAP - Web Dynpro
- SAP ABAP - Business Add-Ins
- SAP ABAP - User Exits
- SAP ABAP - Customer Exits
- SAP ABAP - SAPscripts
- SAP ABAP - Smart Forms
- SAP ABAP - Dialog Programming
- SAP ABAP - Report Programming
- SAP ABAP - Object Events
- SAP ABAP - Interfaces
- SAP ABAP - Encapsulation
- SAP ABAP - Polymorphism
- SAP ABAP - Inheritance
- SAP ABAP - Classes
- SAP ABAP - Objects
- SAP ABAP - Object Orientation
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Copying Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Creating Internal Tables
- SAP ABAP - Internal Tables
- SAP ABAP - Native SQL Overview
- SAP ABAP - Open SQL Overview
- SAP ABAP - Include Programs
- SAP ABAP - Function Modules
- SAP ABAP - Macros
- SAP ABAP - Subroutines
- SAP ABAP - Modularization
- SAP ABAP - Lock Objects
- SAP ABAP - Search Help
- SAP ABAP - Views
- SAP ABAP - Structures
- SAP ABAP - Tables
- SAP ABAP - Data Elements
- SAP ABAP - Domains
- SAP ABAP - Dictionary
- SAP ABAP - Exception Handling
- SAP ABAP - Formatting Data
- SAP ABAP - Date & Time
- SAP ABAP - Strings
- SAP ABAP - Decisions
- SAP ABAP - Loop Control
- SAP ABAP - Operators
- SAP ABAP - Constants & Literals
- SAP ABAP - Variables
- SAP ABAP - Data Types
- SAP ABAP - Basic Syntax
- SAP ABAP - Screen Navigation
- SAP ABAP - Environment
- SAP ABAP - Overview
- SAP ABAP - Home
SAP ABAP Useful Resources
- SAP ABAP - Discussion
- SAP ABAP - Useful Resources
- SAP ABAP - Quick Guide
- SAP ABAP - Questions Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SAP ABAP - Creating Internal Tables
DATA statement is used to declare an internal table. The program must be told where the table begins and ends. So use the BEGIN OF statement and then declare the table name. After this, the OCCURS addition is used, followed by a number, here 0. OCCURS tells SAP that an internal table is being created, and the 0 states that it will not contain any records initially. It will then expand as it is filled with data.
Following is the syntax −
DATA: BEGIN OF <internal_tab> Occurs 0,
Let’s create the fields on a new pne. For instance, create ‘name’ which is declared as LIKE ZCUSTOMERS1-name. Create another field called ‘dob’, LIKE ZCUSTOMERS1-dob. It is useful initially to give the field names in internal tables the same names as other fields that have been created elsewhere. Finally, declare the end of the internal table with “END OF <internal_tab>.” as shown in the following code −
DATA: BEGIN OF itab01 Occurs 0, name LIKE ZCUSTOMERS1-name, dob LIKE ZCUSTOMERS1-dob, END OF itab01.
Here ‘itab01’ is commonly used shorthand when creating temporary tables in SAP. The OCCURS clause is used to define the body of an internal table by declaring the fields for the table. When the OCCURS clause is used, you can specify a numeric constant ‘n’ to determine additional default memory if required. The default size of memory that is used by the 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 pne. To create an internal table with a header pne, 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 pne, 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 −
TYPES <internal_tab> TYPE|LIKE <internal_tab_type> OF <pne_type_itab> WITH <key> INITIAL SIZE <size_number>.
Here the <internal_tab_type> specifies a table type for an internal table <internal_tab> and <pne_type_itab> specifies the type for a pne of an internal table. In TYPES statement, you can use the TYPE clause to specify the pne type of an internal table as a data type and LIKE clause to specify the pne 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> creates an internal table object by allocating an initial amount of memory to it. In the preceding syntax, the INITIAL SIZE clause reserves a memory space for size_number table pnes. Whenever an internal table object is declared, the size of the table does not belong to the data type of the table.
Note − Much less memory is consumed when an internal table is populated for the first time.
Example
Step 1 − Open the ABAP Editor by executing the SE38 transaction code. The initial screen of ABAP Editor appears.
Step 2 − In the initial screen, enter a name for the program, select the Source code radio button and cpck the Create button to create a new program.
Step 3 − In the ABAP: Program Attributes dialog box, enter a short description for the program in the Title field, select the Executable program option from the Type drop-down menu in the Attributes group box. Cpck the Save button.
Step 4 − Write the following code in ABAP editor.
REPORT ZINTERNAL_DEMO. TYPES: BEGIN OF CustomerLine, Cust_ID TYPE C, Cust_Name(20) TYPE C, END OF CustomerLine. TYPES mytable TYPE SORTED TABLE OF CustomerLine WITH UNIQUE KEY Cust_ID. WRITE:/ The mytable is an Internal Table .
Step 5 − Save, activate and execute the program as usual.
In this example, mytable is an internal table and a unique key is defined on the Cust_ID field.
The above code produces the following output −
The mytable is an Internal Table.Advertisements