Wednesday, June 4, 2008

Dynamic Assignment of variables

FORM populate_segmant_itabs TABLES lt_idoc_data STRUCTURE edidd.
DATA: counter_new TYPE i.
DATA: seg_name LIKE edidd-segnam,
it_name(40),
count_name(40),
field_name(40),
l_tabix LIKE sy-tabix.
FIELD-SYMBOLS: ,
TYPE STANDARD TABLE,
,
,
.
* Move segment data into corresponding Internal tables for easy data
* access
LOOP AT lt_idoc_data.
CHECK lt_idoc_data-segnam = c_e1tpsls OR
lt_idoc_data-segnam = c_e1tptrm OR
lt_idoc_data-segnam = c_e1tploc OR
lt_idoc_data-segnam = c_e1edt17 OR
lt_idoc_data-segnam = c_e1tpsha.
IF lt_idoc_data-segnam = c_e1tpsls. " Starts a new leg
counter_new = counter_new + 1.
ENDIF.
CONCATENATE 'IT_' lt_idoc_data-segnam INTO it_name.
CONCATENATE it_name '-' lt_idoc_data-segnam INTO seg_name.
CONCATENATE it_name '-' 'SEGNUM' INTO field_name.
ASSIGN (field_name) TO .
MOVE lt_idoc_data-segnum TO .
CONCATENATE it_name '-' 'SEGNAM' INTO field_name.
ASSIGN (field_name) TO .
MOVE lt_idoc_data-segnam TO .
CONCATENATE it_name '-' 'PSGNUM' INTO field_name.
ASSIGN (field_name) TO .
MOVE lt_idoc_data-psgnum TO .
CONCATENATE it_name '-' 'HLEVEL' INTO field_name.
ASSIGN (field_name) TO .
MOVE lt_idoc_data-hlevel TO .
CONCATENATE it_name '-' 'COUNTER' INTO count_name.
ASSIGN (it_name) TO .
CONCATENATE it_name '[]' INTO it_name.
ASSIGN (it_name) TO .
ASSIGN (seg_name) TO .
ASSIGN (count_name) TO .
MOVE lt_idoc_data-sdata TO .
MOVE counter_new TO .
APPEND TO .
ENDLOOP.
ENDFORM. " populate_segmant_itabs

No comments: