Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

converting data types dynamically

Former Member
0 Likes
727

Hi all,

i am converting all data type to CHAR statically as below.

tasktype* (raw)* to comp1(char)

time(tims) to comp2(char)

LOOP AT vmc INTO wa_vmctmp.
    WRITE: wa_vmctmp-tasktype         TO wa_zvmctmp-comp1,
           wa_vmctmp-time             TO wa_zvmctmp-comp2,
           wa_vmctmp-entry_id         TO wa_zvmctmp-comp3,
           wa_vmctmp-counter          TO wa_zvmctmp-comp4,
           wa_vmctmp-mem_alloc_local  TO wa_zvmctmp-comp5,
    APPEND wa_zvmctmp  TO  zvmc1.
  ENDLOOP.

can anybody suggest me,how do i do it dynamically if i have the table data in a field symbol..

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
691

Check the [CASTING|http://help.sap.com/abapdocu_702/en/abapassign_casting.htm] addition of the ASSIGN statement.

5 REPLIES 5
Read only

former_member214857
Contributor
0 Likes
691

Hello Sam

You can use this on same way as you have coded, instead of use work area, you can use Field-Symbol

LOOP AT vmc ASSIGNING <FS>.
    WRITE: <fs>-tasktype         TO wa_zvmctmp-comp1,
           <fs>-time             TO wa_zvmctmp-comp2,
           <fs>-entry_id         TO wa_zvmctmp-comp3,
           <fs>-counter          TO wa_zvmctmp-comp4,
           <fs>-mem_alloc_local  TO wa_zvmctmp-comp5,
    APPEND wa_zvmctmp  TO  zvmc1.
  ENDLOOP.

However if you do not know exactly structure, you can use ASSIGN COMPONENT statement to refer unkown field

ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>.

Kind regards

Carlos Machado

Read only

0 Likes
691

thank you ......

since i am new ,i am asking this question

as i have huge data in internal tables ..and i have many internal tables also .........i cant hard code all the fields ....

can you suggest me any other way where i can do it dynamically..........

Regards

sam

Read only

RaymondGiuseppi
Active Contributor
0 Likes
691

Try something like

LOOP AT itab1 ASSIGNING <record>.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <record> TO <source>.
    IF sy-subrc NE 0. EXIT. ENDIF.
    ASSIGN COMPONENT sy-index OF STRUCTURE record2 TO <target>.
    IF sy-subrc NE 0. EXIT. ENDIF.
    WRITE <source> TO <target>.
  ENDDO.
  APPEND record2 TO itab2.
ENDLOOP.

Regards,

Raymond

Read only

0 Likes
691

Hi Raymond Giuseppi

thank you,the reply is some thing what i was expecting.....

As i have more number of internal tables,could you tell me what may be structure of itab2 in your code

and record2... is static or dynamic..

As i was mentioning i have data in field symbol then itab1 is static i guess ..if it is so what may be structure of itab1

Thanks and Regards

sam

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
692

Check the [CASTING|http://help.sap.com/abapdocu_702/en/abapassign_casting.htm] addition of the ASSIGN statement.