‎2008 Jun 25 8:48 AM
i have a dyanmic table say t1. now i have craeted another dynamic table say t2 with some fields in common with table t1. i won't be knowing which fields are in common. the common fields will be stord in another table t3. now i need to copy the common fields from t1 to t2 after reading them from t3. how do i go about it???
‎2008 Jun 25 8:50 AM
‎2008 Jun 25 8:50 AM
‎2008 Jun 25 8:59 AM
TYPES:
BEGIN OF s_t3.
INCLUDE TYPE A.
INCLUDE TYPE B.
TYPES:
END OF s_t3.
DATA:
t1 TYPE TABLE OF A,
t2 TYPE TABLE OF B,
ls_t3 TYPE s_t3,
t3 TYPE TABLE OF s_t3.
FIELD-SYMBOLS:
<fs_t1> TYPE A,
<fs_t2> TYPE B.
LOOP AT t1 ASSIGNING <fs_t1>.
READ TABLE t2 ASSIGNING <fs_t2>
WITH KEY
[key_t2] = [key_t1].
CHECK sy-subrc IS INITIAL.
MOVE-CORRESPONDING <fs_t1> TO <ls_t3>.
MOVE-CORRESPONDING <fs_t2> TO <ls_t3>.
APPEND ls_t3 TO t3.
ENDLOOP.
‎2008 Jun 25 9:07 AM
Hm, ok, that doesn't work. You cannot include the same structure fields twice...
‎2008 Jun 25 9:13 AM
OK, first you have to find out what are the common fields of A and B.
You can use FM 'DDIF_NAMETAB_GET' to read the structure fields.
Then you have to create a dynamic type with the common fields of A and B and assign the values as described above in my first answer.
It's quite tricky...
‎2008 Jun 25 9:16 AM
Oh, I think for your requirement you don't need t3 at all.
This should be the solution:
FIELD-SYMBOLS:
<fs_t1> TYPE A,
<fs_t2> TYPE B.
LOOP AT t1 ASSIGNING <fs_t1>.
READ TABLE t2 ASSIGNING <fs_t2>
WITH KEY
[key_t2] = [key_t1].
CHECK sy-subrc IS INITIAL.
MOVE-CORRESPONDING <fs_t1> TO <fs_t2>.
ENDLOOP.But in this case you have to know what is the key field for t1 and t2.