09-15-2011 10:24 PM
Hi,
I have a question that is affecting my project delivery :
I have below structure and i want to change the data type of addr field to f or n DYNAMICALLY during runtime.
TYPES : BEGIN OF st_demo,
reg_no(10) TYPE c,
name(20) TYPE c,
addr(20) TYPE c,
END OF st_demo.
DATA : wa_demo TYPE st_demo,
it_demo TYPE TABLE OF st_demo,
Can anyone guru in abap advice me.
09-15-2011 11:19 PM
Dear MercAMG,
sure.
This is an easy one.
You need to use FIELD SYMBOLS.... don't be afraid of them.
;o)
Here's the code with explanations.
REPORT zrq.
* Ricardo Quintas 2011/09
* Here you declare your 2 field symbols
FIELD-SYMBOLS <field_n> TYPE n.
FIELD-SYMBOLS <field_d> TYPE d.
TYPES : BEGIN OF st_demo,
reg_no(10) TYPE c,
name(20) TYPE c,
addr(20) TYPE c,
END OF st_demo.
* Now you declare your line type
DATA : wa_demo TYPE st_demo.
* And you choose dinamically what data type you want to assign
* your addr field.
* (the IF-ENDIF is just an example)
IF bla bla bla...
ASSIGN wa_demo-addr TO <field_n> CASTING.
ELSE.
ASSIGN wa_demo-addr TO <field_d> CASTING.
ENDIF.
* And finally you declare your internal table, with your
* dinamically created line type. Pay attention to the "LIKE" instead of "TYPE"
DATA: it_demo LIKE TABLE OF wa_demo.
Just to let you know that you might get errors at run-time if you don't take care of data conflicts.
You've been warned. ;o)
Kind Regards
/Ricardo Quintas
09-15-2011 11:19 PM
Dear MercAMG,
sure.
This is an easy one.
You need to use FIELD SYMBOLS.... don't be afraid of them.
;o)
Here's the code with explanations.
REPORT zrq.
* Ricardo Quintas 2011/09
* Here you declare your 2 field symbols
FIELD-SYMBOLS <field_n> TYPE n.
FIELD-SYMBOLS <field_d> TYPE d.
TYPES : BEGIN OF st_demo,
reg_no(10) TYPE c,
name(20) TYPE c,
addr(20) TYPE c,
END OF st_demo.
* Now you declare your line type
DATA : wa_demo TYPE st_demo.
* And you choose dinamically what data type you want to assign
* your addr field.
* (the IF-ENDIF is just an example)
IF bla bla bla...
ASSIGN wa_demo-addr TO <field_n> CASTING.
ELSE.
ASSIGN wa_demo-addr TO <field_d> CASTING.
ENDIF.
* And finally you declare your internal table, with your
* dinamically created line type. Pay attention to the "LIKE" instead of "TYPE"
DATA: it_demo LIKE TABLE OF wa_demo.
Just to let you know that you might get errors at run-time if you don't take care of data conflicts.
You've been warned. ;o)
Kind Regards
/Ricardo Quintas
09-16-2011 3:41 PM