- SAP ABAP
- What is SAP ABAP
- SAP ABAP Data Dictionary and Domain
- SAP ABAP Data Element
- SAP ABAP Database Table
- SAP ABAP Database tables and views
- SAP ABAP Foreign Key
- SAP ABAP Indexes
- SAP ABAP Structure
- SAP ABAP Package
- SAP ABAP Adding Fields to SAP Standard Table
- SAP ABAP Internal Table and Database Table
- SAP ABAP Select Option and Parameter
- SAP ABAP Types of Internal Table
- SAP ABAP ways of Declaring Internal Tables
- SAP ABAP Mastering Initialization Technique
- SAP ABAP Operations on Internal Table
- SAP ABAP Record Retrieval
- SAP ABAP Insert, Modify and Delete data in the Internal table by using Keywords
- SAP ABAP Sorting and Removing Adjacent Duplicates
- SAP ABAP Seamless Data Transfer Between Internal Tables
- SAP ABAP Search Help Types
- SAP ABAP Lock Objects and Types
- SAP ABAP Buffering and Its Types
- SAP ABAP TMG
- SAP ABAP Table Types
- SAP ABAP Views
- SAP ABAP Control Break Statement
- SAP ABAP COMMIT and ROLLBACK
- SAP ABAP Joins
- SAP For All Entries
- SAP ABAP Procedure to Fill Final Internal Table
- SAP ABAP Modularization
- SAP ABAP Function Group and Function Module
- SAP ABAP SELECT Options
24DDIC2207 – Ways of Declaring Internal Tables in SAP ABAP Programming
In ABAP programming, internal tables are pivotal for handling datasets dynamically. This blog post explores various methods for declaring internal tables offering practical examples to demonstrate each approach. Understanding these methods enhances your capability to manipulate data efficiently within your SAP applications.
- Declaring an Internal Table with Selected Fields from a Database Table
This method involves declaring an internal table with a subset of fields from an existing database table.
Syntax:
DATA: BEGIN OF <work area>,
<field1> TYPE <data type>,
<field2> TYPE <data type>,
…
END OF <work area>.
DATA <IT> LIKE TABLE OF <work area>.
Example:
DATA: BEGIN OF wa_t001,
bukrs TYPE t001-bukrs,
ort01 TYPE t001-ort01,
END OF wa_t001.
DATA IT LIKE TABLE OF wa_t001.
- Declaring an Internal Table with All Fields from a Database Table
This method uses the INCLUDE STRUCTURE statement to include all fields of a database table in the work area.
Syntax:
DATA BEGIN OF <work area>.
INCLUDE STRUCTURE <database table>.
DATA END OF <work area>.
DATA <internal table> LIKE TABLE OF <work area>.
Example:
DATA BEGIN OF wa_t001.
INCLUDE STRUCTURE t001.
DATA END OF wa_t001.
DATA IT LIKE TABLE OF wa_t001.
- Declaring an Internal Table by Referring to a Database Table
This method directly refers to the structure of a database table or an existing work area.
Syntax:
DATA <work area> LIKE <database table>.
DATA <internal table> LIKE TABLE OF <work area/database table>.
Example:
DATA wa LIKE t001.
DATA IT LIKE TABLE OF wa.
OR
DATA IT LIKE TABLE OF t001.
DATA wa LIKE LINE OF IT.
- Declaring Internal Tables Using the TYPES Keyword
This approach defines a new data type using the TYPES keyword and then declares the work area and internal table based on this type.
Syntax:
TYPES: BEGIN OF <type name>,
<field1> TYPE <data type>,
<field2> TYPE <data type>,
…
END OF <type name>.
DATA <wa> TYPE <type name>.
DATA <internal table> TYPE TABLE OF <type name>.
Example:
TYPES: BEGIN OF ty_t001,
bukrs TYPE t001-bukrs,
ort01 TYPE t001-ort01,
END OF ty_t001.
DATA wa_t001 TYPE ty_t001.
DATA IT TYPE TABLE OF ty_t001.
OR
DATA IT LIKE TABLE OF wa_t001.
Note on TYPE vs. LIKE
TYPE: Used to assign a data type directly to a data object during declaration.
LIKE: Used to reference the data type of an existing object, thereby indirectly assigning the data type.
Commenting in ABAP
To comment multiple lines in ABAP select the lines and press CTRL + <. To uncomment select the lines and press CTRL + >.
Author : Aniket Pawar, 9373518385
24DDIC2207 – Ways of Declaring Internal Tables in SAP ABAP Programming
In ABAP programming, internal tables are pivotal for handling datasets dynamically. This blog post explores various methods for declaring internal tables offering practical examples to demonstrate each approach. Understanding these methods enhances your capability to manipulate data efficiently within your SAP applications.
- Declaring an Internal Table with Selected Fields from a Database Table
This method involves declaring an internal table with a subset of fields from an existing database table.
Syntax:
DATA: BEGIN OF <work area>,
<field1> TYPE <data type>,
<field2> TYPE <data type>,
…
END OF <work area>.
DATA <IT> LIKE TABLE OF <work area>.
Example:
DATA: BEGIN OF wa_t001,
bukrs TYPE t001-bukrs,
ort01 TYPE t001-ort01,
END OF wa_t001.
DATA IT LIKE TABLE OF wa_t001.
- Declaring an Internal Table with All Fields from a Database Table
This method uses the INCLUDE STRUCTURE statement to include all fields of a database table in the work area.
Syntax:
DATA BEGIN OF <work area>.
INCLUDE STRUCTURE <database table>.
DATA END OF <work area>.
DATA <internal table> LIKE TABLE OF <work area>.
Example:
DATA BEGIN OF wa_t001.
INCLUDE STRUCTURE t001.
DATA END OF wa_t001.
DATA IT LIKE TABLE OF wa_t001.
- Declaring an Internal Table by Referring to a Database Table
This method directly refers to the structure of a database table or an existing work area.
Syntax:
DATA <work area> LIKE <database table>.
DATA <internal table> LIKE TABLE OF <work area/database table>.
Example:
DATA wa LIKE t001.
DATA IT LIKE TABLE OF wa.
OR
DATA IT LIKE TABLE OF t001.
DATA wa LIKE LINE OF IT.
- Declaring Internal Tables Using the TYPES Keyword
This approach defines a new data type using the TYPES keyword and then declares the work area and internal table based on this type.
Syntax:
TYPES: BEGIN OF <type name>,
<field1> TYPE <data type>,
<field2> TYPE <data type>,
…
END OF <type name>.
DATA <wa> TYPE <type name>.
DATA <internal table> TYPE TABLE OF <type name>.
Example:
TYPES: BEGIN OF ty_t001,
bukrs TYPE t001-bukrs,
ort01 TYPE t001-ort01,
END OF ty_t001.
DATA wa_t001 TYPE ty_t001.
DATA IT TYPE TABLE OF ty_t001.
OR
DATA IT LIKE TABLE OF wa_t001.
Note on TYPE vs. LIKE
TYPE: Used to assign a data type directly to a data object during declaration.
LIKE: Used to reference the data type of an existing object, thereby indirectly assigning the data type.
Commenting in ABAP
To comment multiple lines in ABAP select the lines and press CTRL + <. To uncomment select the lines and press CTRL + >.
Author : Aniket Pawar, 9373518385