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

Move data between table type any with restrication

Former Member
0 Likes
1,548

HI ALL

I have table type any <fs_tab1> and another table type any <fs_tab2> and i need to move all the

data from table <fs_tab1> to table <fs_tab2> but the issue here that i have table itab3 (mapping table with the fields names ) that

just the fields that mapped there and are in itab3 need to be insert to table <fs_tab1>.

I try but i have some issues

LOOP AT <fs_tab1> ASSIGNING <ls_tab1>.
    LOOP AT itab3 INTO ls_flat_map.

*      DO.

*      ASSIGN COMPONENT ls_map-target OF STRUCTURE <ls_output> TO <lv_field>.



*
      ENDDO.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING <ls_outpu> TO <ls_itab2>.
        INSERT <ls_itab2  INTO TABLE <ls_itab2>..
      ENDIF.
    ENDLOOP.
  ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,300

Hi,

Here you go:


FIELD-SYMBOLS: <tab1> TYPE ANY TABLE,
               <tab2> TYPE ANY TABLE,
               <rec1> TYPE any,
               <rec2> TYPE any,
               <rec3> TYPE ty_fldname,
               <fld1> TYPE any,
               <fld2> TYPE any.

DATA: go_data TYPE REF TO data.

CREATE DATA go_data LIKE LINE OF <tab2>.
IF go_data IS BOUND.
  ASSIGN go_data->* TO <rec2>.
ENDIF.

LOOP AT <tab1> ASSIGNING <rec1>.

  LOOP AT gt_tab3 ASSIGNING <rec3>.

    ASSIGN COMPONENT <rec3>-target OF STRUCTURE <rec1> TO <fld1>.
    CHECK sy-subrc = 0.
    ASSIGN COMPONENT <rec3>-target OF STRUCTURE <rec2> TO <fld2>.
    CHECK sy-subrc = 0.
    <fld2> = <fld1>.

  ENDLOOP.
  INSERT <rec2> INTO TABLE <tab2>.
  CLEAR <rec2>.

ENDLOOP.

Kr,

m.

HI ALL

I have table type any <fs_tab1> and another table type any <fs_tab2> and i need to move all the

data from table <fs_tab1> to table <fs_tab2> but the issue here that i have table itab3 (mapping table with the fields names ) that

just the fields that mapped there and are in itab3 need to be insert to table <fs_tab1>.

I try but i have some issues

LOOP AT <fs_tab1> ASSIGNING <ls_tab1>.
    LOOP AT itab3 INTO ls_flat_map.

*      DO.

*      ASSIGN COMPONENT ls_map-target OF STRUCTURE <ls_output> TO <lv_field>.



*
      ENDDO.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING <ls_outpu> TO <ls_itab2>.
        INSERT <ls_itab2  INTO TABLE <ls_itab2>..
      ENDIF.
    ENDLOOP.
  ENDLOOP.

3 REPLIES 3
Read only

Former Member
0 Likes
1,301

Hi,

Here you go:


FIELD-SYMBOLS: <tab1> TYPE ANY TABLE,
               <tab2> TYPE ANY TABLE,
               <rec1> TYPE any,
               <rec2> TYPE any,
               <rec3> TYPE ty_fldname,
               <fld1> TYPE any,
               <fld2> TYPE any.

DATA: go_data TYPE REF TO data.

CREATE DATA go_data LIKE LINE OF <tab2>.
IF go_data IS BOUND.
  ASSIGN go_data->* TO <rec2>.
ENDIF.

LOOP AT <tab1> ASSIGNING <rec1>.

  LOOP AT gt_tab3 ASSIGNING <rec3>.

    ASSIGN COMPONENT <rec3>-target OF STRUCTURE <rec1> TO <fld1>.
    CHECK sy-subrc = 0.
    ASSIGN COMPONENT <rec3>-target OF STRUCTURE <rec2> TO <fld2>.
    CHECK sy-subrc = 0.
    <fld2> = <fld1>.

  ENDLOOP.
  INSERT <rec2> INTO TABLE <tab2>.
  CLEAR <rec2>.

ENDLOOP.

Kr,

m.

Read only

0 Likes
1,300

HI Manu,

Thanks you very much,

One question , do you think I can use something different instead of CHECK ?

Regards

Joy

Read only

0 Likes
1,300

Hi,

Well, this was just a basic form of algorithm...

You could of course handle exceptions with a TRY-CATCH block or an IF sy-subrc NE 0...

All depends on what you are expecting.. e.g. if a field from tab3 does not exist in tab1 or in tab2 or in both, ...

Kr,

m.