‎2008 Nov 24 10:05 AM
Hi there. I've got a question. Is there some possibility to declare data type during program flow depending on some conditions
For example:
IF ( cond1 ) .
DATA: var LIKE someitab1 .
ELSEIF ( cond2 ) .
DATA: var LIKE someitab2 .
ENDIF .
I'll be thankful for help . Greetings .
‎2008 Nov 24 10:09 AM
‎2008 Nov 24 10:09 AM
‎2008 Nov 24 10:13 AM
‎2008 Nov 24 10:15 AM
Check out this code:
PARAMETERS: P_TABLE LIKE DD03L-TABNAME.
FIELD-SYMBOLS: <FS_TABLE> TYPE TABLE,
<WA_TABLE> TYPE ANY.
DATA: XTABLE TYPE REF TO DATA." It tells compiler that the data object type will be defined at runtime
CREATE DATA XTABLE TYPE TABLE OF (P_TABLE)." It creates data XTABLE at runtime
ASSIGN XTABLE->* TO <FS_TABLE>." before using this field symbol in LOOP, its must be assigned
SELECT * FROM (P_TABLE) INTO TABLE <FS_TABLE> ORDER BY PRIMARY KEY.
LOOP AT <FS_TABLE> ASSIGNING <WA_TABLE>.
ENDLOOP.
‎2008 Nov 24 10:21 AM
if test = 'name1'.
field-symbols: <table1> type table ,
<field1> type any .
elseif test = 'name2'.
field-symbols: <table2> type table ,
<field2> type any .
endif .
‎2008 Nov 24 10:39 AM
It will be better to define data and than assign it to field symbol at runtime.
Data : someitab1 type table of itab1,
someitab2 type table of itab2.
field-symbols : <f_itab> type table.
IF ( cond1 ).
assign SOMEITAB1[] to <f_itab>.
ELSEIF ( cond2 ) .
assign SOMEITAB2[] to <f_itab>.
ENDIF.Similarly you can have condition for variable. Above example is for internal tables.
Regards,
Mohaiyuddin