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

How to join two ITAB

Former Member
0 Likes
1,493

Hai

i have created an program using ALV and i had created two internal tables namely ITAB and ITAB1.But i wasn't unable to get an output.so i like to know how to join two ITAB in ALV.

Hai

i have created an program using ALV and i had created two internal tables namely ITAB and ITAB1.But i wasn't unable to get an output.so i like to know how to join two ITAB in ALV.

11 REPLIES 11
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,446

LOop at itab.

read table itab1 with key <commonfield> = itab-field.

if sy-subrc = 0.

move to other itab2 or modify itab.

endif.

endloop.

Read only

Former Member
0 Likes
1,446

select vbeln vkorg vtweg from vbak into table it

where vbeln in s_order and

vkorg in s_div.

select vbeln lfstk from vbuk

into table it1

for all entries in it

where vbeln = it-vbeln.

or

select vbeln lfstk from vbuk

into corresponding fields of table it

for all entries in it

where vbeln = it-vbeln.

loop at it

read table it1 with key vbeln = it-vbeln.

if sy-subrc eq 0.

move to output table.

endif.

endloop.

Read only

Former Member
0 Likes
1,446

Hi mahesh

move these two internal tables into a new internal table which should be sent to the ALV.

Read only

former_member404244
Active Contributor
0 Likes
1,446

hi,

create a final nternal table with all the fields whcih u want to dispaly in the output..

Now merge itab and iatb1 to final internal table...

now pass the final internal table to alv..

loop at itab.

read table itab1 with key field = itab-field1...

if sy-subrc eq 0.

move-corresponding itab to finaltab.

move-corresponding itab1 to finaltab.

append finaltab.

endif.

endloop..

something like this u can do..

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,446

Hi,

Declare the third internal table which contains both the fields of the two internal tables.

For e.g

itab has fields pernr,werks and persg.

itab1 has fields pernr,bukrs,and persk.

declare the third internal table like this

itab2 which are having fields pernr,werks,persg,bukrs and persk.

Move all those values of itab and itab1 to itab2.

Then Give the internal table itab2 in the CALL FUNCTION t_OUTTAB = itab2.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IS_LAYOUT = LAYOUT

i_callback_top_of_page = 'TOP-OF-PAGE'

IT_FIELDCAT = INT_FCAT

TABLES

t_outtab = itab2.

Thanks,

Sakthi C

Read only

Former Member
0 Likes
1,446

MAhesh,

Check this ex:

ITAB1 is having fields "A","B", "C".

ITAB2 is having fields "A","D", "E".

Create i_final internal table to have all fields of 2 internal tables.

i_final is having "A","B","C","D","E".

SORT itab1 ,itab2 by A

LOOP AT ITAB1.

READ TABLE itab2 WITH KEY a = itab1-a BINARY

SEARCH.

IF SY-SUBRC EQ 0.

MOVE : itab1-a TO i_final-a,

itab1-b TO i_final-b,

itab1-c TO i_final-c,

itab2-d TO i_final-d,

itab2-e TO i_final-e.

APPEND i_final.

ENDIF.

ENDLOOP.

Don't forget to reward if useful.....

Read only

Former Member
0 Likes
1,446

Loop at it_tab into wa_tab.

Read table it_tab1 into wa_tab1 with key <field> = wa_tab-<field>.

if sy-subrc = 0.

  • move the data into another internal table

  • append

endif.

Endloop.

Read only

Former Member
0 Likes
1,446

Define third internal table itab3 with boththe fields and loop the itab1and read itab2 append all the values to third itab i.e itab3 or loop the itab1 and loop the itab2 with where condition if itab2 have multiple entries for a single entry in itab1.pass itba3 to alv.

Read only

Former Member
0 Likes
1,446

hi

be clear with TAB1 and TAB2 ... using two tables...

and about the Joins ..

Joins are two types

Inner Join or outer Join

syntax:

select tab1~fields

tab2~fields

into table <body>

from <tab1> inner join <tab2>

on <tab1field1> = <tab2field1>.

juz for outer join add in place of inner join.

other syntax

if suppose we have

begin of i_kna1 occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

vbeln like vbak-vbeln,

award points if useful

erdat like vbak-erdat,

end of i_kna1.

select kna1kunnr kna1name1 vbakvbeln vbakerdat into table i_kna1 from kna1 join vbak on kna1kunnr = vbakkunnr.

Read only

Former Member
0 Likes
1,446

Hi Mahesh,

may be this code will be helpful

SELECT VIQMELQMNUM VIQMELQMTXT VIQMELQMDAT VIQMELLTRMN VIQMEL~PRIOK

VIQMELBEZDT VIQMELAUFNR VIQMELTPLNR AFKOGLTRP into corresponding fields of table GT_ITAB

FROM VIQMEL INNER JOIN AFKO ON VIQMELAUFNR = AFKOAUFNR

WHERE VIQMELQMNUM IN N_NUMBER and VIQMELQMART IN N_TYPE AND VIQMEL~QMNAM IN NAME.

Regards

swaroop

Read only

Former Member
0 Likes
1,446

Hi

Can anyone tell me how to join Table BSEG & EKPO ,

My requirement is i want to show Purchase order item wrt to g/l account.

but i also want g/l account without PO & PO ITEM

Thanks & Regards

Lalith