6 Columns with Active Background
Active List Item Background

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.

  1. 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.

 

  1. 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.

 

  1. 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.

 

  1. 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    

6 Columns with Active Background

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.

  1. 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.

 

  1. 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.

 

  1. 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.

 

  1. 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