Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Declare dynamically in SAP ABAP
In SAP ABAP, you can declare an internal table in a dynamic manner when the table type is not known at compile time. This approach is useful when working with generic programming or when the table structure depends on runtime conditions.
Dynamic Internal Table Declaration
To declare an internal table dynamically, you need to use data references and field symbols. Here's the basic syntax −
DATA: tbl_TEST TYPE REF TO DATA. FIELD-SYMBOLS: <tbl_TEST> TYPE STANDARD TABLE. CREATE DATA tbl_TEST TYPE (Received_Type). ASSIGN tbl_TEST->* TO <tbl_TEST>.
Complete Example
Here's a complete working example that demonstrates dynamic table declaration −
REPORT z_dynamic_table_demo.
DATA: tbl_ref TYPE REF TO DATA,
table_type TYPE string.
FIELD-SYMBOLS: <dynamic_table> TYPE STANDARD TABLE,
<work_area> TYPE any.
" Define the table type dynamically
table_type = 'SFLIGHT'.
" Create the internal table dynamically
CREATE DATA tbl_ref TYPE STANDARD TABLE OF (table_type).
ASSIGN tbl_ref->* TO <dynamic_table>.
" Create a work area for the dynamic table
CREATE DATA tbl_ref TYPE (table_type).
ASSIGN tbl_ref->* TO <work_area>.
" Now you can use the dynamic table
SELECT * FROM sflight INTO TABLE <dynamic_table> UP TO 5 ROWS.
" Process the dynamic table
LOOP AT <dynamic_table> INTO <work_area>.
WRITE: / 'Flight data processed dynamically'.
ENDLOOP.
Key Components
The dynamic declaration involves these essential elements −
-
Data Reference −
TYPE REF TO DATAcreates a reference to hold the table - Field Symbol − Acts as a placeholder for the actual table structure
- CREATE DATA − Dynamically creates the table based on the type passed at runtime
- ASSIGN − Links the data reference to the field symbol for actual usage
This dynamic approach provides flexibility when working with unknown table types at development time, making your ABAP programs more generic and reusable.
Advertisements
