Application Development 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: 

Technique to move data between 2 tables using <FS>

Former Member
0 Kudos
141

Hi,

I am trying to learn the technique for moving data between to tables (and switching the order of name1 and kunnr) using Field Symbols. I have a simple example, but am getting a compile error saying:

i_cm_alv and <x_cm_alv> are type-incompatible.

Here is my code:

TYPES: BEGIN OF tt_cm.

TYPES: kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm.

TYPES: BEGIN OF tt_cm_alv.

TYPES: name1 TYPE kna1-name1,

kunnr TYPE kna1-kunnr,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm_alv.

DATA: i_cm TYPE TABLE OF tt_cm,

i_cm_alv TYPE TABLE OF tt_cm_alv.

FIELD-SYMBOLS: <x_cm> LIKE LINE OF i_cm,

<x_cm_alv> LIKE LINE OF i_cm_alv.

SELECT

hkunnr hname1 ivkbur ikonda

INTO TABLE i_cm

FROM kna1 AS h

JOIN knvv AS i ON ikunnr = hkunnr.

ASSIGN i_cm_alv TO <x_cm_alv>.

LOOP AT i_cm ASSIGNING <x_cm>.

<x_cm>-kunnr = <x_cm_alv>-kunnr.

<x_cm>-name1 = <x_cm_alv>-name1.

<x_cm>-vkbur = <x_cm_alv>-vkbur.

<x_cm>-konda = <x_cm_alv>-konda.

ENDLOOP.

Any help is greatly appreciated!

Thx,

Andy

1 ACCEPTED SOLUTION

Former Member
0 Kudos
90

Check the following code, it should ideally work...

TYPES: BEGIN OF tt_cm.

TYPES: kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm.

TYPES: BEGIN OF tt_cm_alv.

TYPES: name1 TYPE kna1-name1,

kunnr TYPE kna1-kunnr,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm_alv.

DATA: i_cm TYPE TABLE OF tt_cm,

i_cm_alv TYPE TABLE OF tt_cm_alv.

FIELD-SYMBOLS: <x_cm_alv> LIKE LINE OF i_cm,

<x_cm1> LIKE LINE OF i_cm,

<x_cm> type table. -


> Declared it as type table.

SELECT

hkunnr hname1 ivkbur ikonda

INTO TABLE i_cm

FROM kna1 AS h

JOIN knvv AS i ON ikunnr = hkunnr.

ASSIGN i_cm TO <x_cm>. -


> Table to Table movement

LOOP AT <x_cm> ASSIGNING <x_cm_alv>.

"process code.

ENDLOOP.

Regards,

S.Dakshna Nagaratnam.

10 REPLIES 10

Former Member
0 Kudos
91

Check the following code, it should ideally work...

TYPES: BEGIN OF tt_cm.

TYPES: kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm.

TYPES: BEGIN OF tt_cm_alv.

TYPES: name1 TYPE kna1-name1,

kunnr TYPE kna1-kunnr,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm_alv.

DATA: i_cm TYPE TABLE OF tt_cm,

i_cm_alv TYPE TABLE OF tt_cm_alv.

FIELD-SYMBOLS: <x_cm_alv> LIKE LINE OF i_cm,

<x_cm1> LIKE LINE OF i_cm,

<x_cm> type table. -


> Declared it as type table.

SELECT

hkunnr hname1 ivkbur ikonda

INTO TABLE i_cm

FROM kna1 AS h

JOIN knvv AS i ON ikunnr = hkunnr.

ASSIGN i_cm TO <x_cm>. -


> Table to Table movement

LOOP AT <x_cm> ASSIGNING <x_cm_alv>.

"process code.

ENDLOOP.

Regards,

S.Dakshna Nagaratnam.

Former Member
0 Kudos
90

Hi ,

As for my understanding you need to move entries for one tabel to another table if i am right below is my code .

TYPES: BEGIN OF tt_cm.

TYPES: kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm.

TYPES: BEGIN OF tt_cm_alv.

TYPES: name1 TYPE kna1-name1,

kunnr TYPE kna1-kunnr,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm_alv.

DATA: i_cm TYPE TABLE OF tt_cm,

i_cm_alv TYPE TABLE OF tt_cm_alv.

FIELD-SYMBOLS: <x_cm> LIKE LINE OF i_cm,

<x_cm_alv> LIKE LINE OF i_cm_alv.

SELECT

h~kunnr

h~name1

i~vkbur

i~konda INTO TABLE i_cm

FROM kna1 AS h

JOIN knvv AS i

ON ikunnr = hkunnr.

*ASSIGN i_cm_alv TO <x_cm_alv>.

LOOP AT i_cm ASSIGNING <x_cm>.

<x_cm_alv>-kunnr = <x_cm>-kunnr .

<x_cm_alv>-name1 = <x_cm>-name1 .

<x_cm_alv>-vkbur = <x_cm>-vkbur .

<x_cm_alv>-konda = <x_cm>-konda .

APPEND <x_cm_alv> to i_cm_alv.

endloop.

BREAK-POINT.

Former Member
0 Kudos
90

Hi,

Try to remove the statement...

ASSIGN i_cm_alv TO <x_cm_alv>.

Instead, do the below:

LOOP AT i_cm ASSIGNING <x_cm>.

Read table i_cm_alv into <x_cm_alv> with key kunnr = <x_cm_alv>-kunnr

<x_cm>-kunnr = <x_cm_alv>-kunnr.

<x_cm>-name1 = <x_cm_alv>-name1.

<x_cm>-vkbur = <x_cm_alv>-vkbur.

<x_cm>-konda = <x_cm_alv>-konda.

ENDLOOP.

Regards

Shiva

Former Member
0 Kudos
90

Hi Andrew,

Find below the corrected code:

TYPES: BEGIN OF tt_cm.

TYPES: kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm.

TYPES: BEGIN OF tt_cm_alv.

TYPES: name1 TYPE kna1-name1,

kunnr TYPE kna1-kunnr,

vkbur TYPE knvv-vkbur,

konda TYPE knvv-konda,

END OF tt_cm_alv.

DATA: i_cm TYPE TABLE OF tt_cm,

i_cm_alv TYPE TABLE OF tt_cm_alv WITH HEADER LINE.

FIELD-SYMBOLS: <x_cm> LIKE LINE OF i_cm,

<x_cm_alv> LIKE LINE OF i_cm_alv.

SELECT

hkunnr hname1 ivkbur ikonda

INTO TABLE i_cm

FROM kna1 AS h

JOIN knvv AS i ON ikunnr = hkunnr.

ASSIGN i_cm_alv TO <x_cm_alv>.

LOOP AT i_cm ASSIGNING <x_cm>.

<x_cm_alv>-kunnr = <x_cm>-kunnr .

<x_cm_alv>-name1 = <x_cm>-name1.

<x_cm_alv>-vkbur = <x_cm>-vkbur.

<x_cm_alv>-konda = <x_cm>-konda.

APPEND i_cm_alv.

ENDLOOP.

Thanks,

Kirubs

Former Member
0 Kudos
90

HI,

DATA: i_cm TYPE TABLE OF tt_cm,
i_cm_alv TYPE TABLE OF tt_cm_alv.

DATA
wa_cm  TYPE tt_cm,
wa_cm_alv TYPE tt_cm_alv,

LOOP AT i_cm ASSIGNING wa_cm.

MOVE-CORRESPONDING wa_cm TO wa_cm_alv . 
APPEND wa_cm_alv  TO i_cm_alv .
CLEAR wa_cm_alv ,
ENDLOOP.

0 Kudos
90

For some reason my post keeps failing saying that I am violating some posting rules. I will try to post my reply in several posts to see what the problem is.

0 Kudos
90

Thank you all for your suggestions.

Each one seems close, but none are working correctly,

Dakshna, I am getting an error saying "<x_cm> is a table without a header line and therefore has no component called kunnr"

Sai and Shiva, I am getting a dump saying that Field Symbol has not been assigned.

0 Kudos
90

Kirubs, your suggestion seems gives me an error on the cl_salv_table-> factory method saying that "i_cm_alv is not type-compatible with formal parameter t_table." Sorry I didn't mention that ultimately I needed to print this. I didn't think that was important. Can you tell I'm a newbie?

Avinash, Not sure how to ask this, but I was under the impression that using field symbols was supposed to eliminate the use of MOVE-CORRESPONDING. I'm not sure why I would want to combine both techniques.

0 Kudos
90

This is not important. I am just trying to learn how to handle this because I know it will come up in the future.

I will continue to mess around with it. If anyone has any other suggestions, great, but please don't kill yourselves trying to solve this, it's not critical. I thought there was a simple answer. Guess not!

Thank you again,

Andy

0 Kudos
90

Hmmmm...I had the word "ur gent" in my post and it didn't like that.