2020 Aug 16 9:51 AM
Hi
I have 2 internal tables,
ill give example:
itab1:
wa_1
vbeln
posnr
material (no value)
field4
field5
field6......
itab2
wa_2
vbeln
posnr
material (has value)
i want to join both in a way that ill get itab2-material value into itab1-material,
where itab1-vbeln = itab2 -vbeln
and itab1-posnr = itab2-posnr.
(their structure is different)
I guess its quite a simple question but would be great if someone can help with the way to achive this,
Thank you very much.
Hi
I have 2 internal tables,
ill give example:
itab1:
wa_1
vbeln
posnr
material (no value)
field4
field5
field6......
itab2
wa_2
vbeln
posnr
material (has value)
i want to join both in a way that ill get itab2-material value into itab1-material,
where itab1-vbeln = itab2 -vbeln
and itab1-posnr = itab2-posnr.
(their structure is different)
I guess its quite a simple question but would be great if someone can help with the way to achive this,
Thank you very much.
2020 Aug 16 10:02 AM
Ill just add that on my case unfortunately I cant join everything into 1 internal table from the first place so I have to find a way to merge both
thanks again.
2020 Aug 16 10:04 AM
Hi,
You could try something like following:
FIELD-SYMBOLS: <fs_itab1> LIKE LINE OF itab1,
<fs_itab2> LIKE LINE OF itab2.
LOOP AT itab1 ASSIGNING <fs_itab1>.
READ TABLE itab2 ASSIGNING <fs_itab2> WITH KEY vbeln = <fs_itab1>-vbeln
posnr = <fs_itab1>-posnr.
IF sy-subrc = 0.
<fs_itab1>-material = <fs_itab2>-material.
ENDIF.
ENDLOOP.Best regards,
Geert-Jan Klaps
2020 Aug 16 10:22 AM
Hi, thank you very much, ive tried but it still dosent fetch the value... any idea why maybe?
2020 Aug 16 10:32 AM
Maybe post the actual code so we can have a better look. Above example should work if itab1 and itab2 contain the data you described.
2020 Aug 17 11:31 AM
<fs_itab2> should be defined with as HASHED table with UNIQUE-KEY vbeln posnr, and the read should be:
READ TABLE itab2 ASSIGNING <fs_itab2> WITH TABLE KEY vbeln = <fs_itab1>-vbeln
posnr = <fs_itab1>-posnr.
otherwise you are likely to have performance problems.
(Also, using fs inside the angle brackets to indicate a field symbol when you already know that it's a field symbol due to the angle bracket... 😮 ).
2020 Aug 16 10:15 AM
Please use the button CODE to format your examples, like this:
itab1:
vbeln posnr material field4 field5 field6
----- ----- ---------- ------ ------ ------
XX XX (no value) XX XX XX
itab2:
vbeln posnr material
----- ----- ----------
XX XX aaaaa
I want to join both in a way that ill get itab2-material value into itab1-material:
vbeln posnr material field4 field5 field6
----- ----- ---------- ------ ------ ------
XX XX aaaaa XX XX XX
2020 Aug 16 10:32 AM
Hello usersant077
The solution provided by 8d8214c7f9734f45be69f95cc0d5aeee should work. If it does not then please share the definition of ITAB1 and ITAB2 types. There might by some inconsistencies in the field types (probably missing zeros in the VBELN and/or POSNR fields).Posted on2020 Aug 17 3:25 AM
usersant077, 'joining' two internal tables based on two corresponding values (e.g. vbeln, posnr), should indeed be a 'quite simple' task. A very standard answer to solve this 'problem' has been presented to you, and if the data and the structures are ok, it works 100%.
There is nothing else the community can do for you now, unless you also post the relevant parts of the coding (data definition and 'joining' technique, e.g. loop/read table) and possible give information about the data that should match but doesnt (e.g. screenshot of itabs in debugger showing the two fields).
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |