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

JOIN on internal table

Former Member
0 Likes
1,880

Hi can any body give me a sample code on joining 2 internal tables having the common field.

thanks in advance

kp

6 REPLIES 6
Read only

Former Member
0 Likes
1,172

Hi,

Check this example..

I am joining the internal table where VBELN is the common field..

DATA: ITAB_VBAK LIKE VBAK OCCURS 0 WITH HEADER LINE.

DATA: ITAB_VBAP LIKE VBAP OCCURS 0 WITH HEADER LINE.

DATA: V_TABIX TYPE SYTABIX.

SORT ITAB_VBAP BY VBELN.

LOOP AT ITAB_VBAK.

READ TABLE ITAB_VBAP TRANSPORTING NO FIELDS

WITH KEY VBELN = ITAB_VBAK-VBELN

BINARY SEARCH.

IF SY-SUBRC = 0.

  • Store the row number.

V_TABIX = SY-TABIX.

LOOP AT ITAB_VBAP FROM V_TABIX.

  • Exit condition for the loop.

IF ITAB_VBAK-VBELN <> ITAB_VBAP-VBELN.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

ENDLOOP.

Thanks,

Naren

Read only

Former Member
0 Likes
1,172

Hi KP,

There wr no joins on internal tables. You have to use loop-read-endloop.

loop at itab.

read table itab2 with key field1 = itab-field1.

if sy-subrc = 0.

move itab-field1 = itab_final-field1.

move itab2-field2 = itab_final-field2.

.

.

append itab_final.

clear itab_final.

endif.

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
1,172

It is only possible through LOOPs and READ WITH KEY.

If you are expecting to use SQL JOINS on internal tables, then this is not possible as ABAP follows OPEN SQL.

Thanks,

Santosh

Read only

Former Member
0 Likes
1,172

Hi,

SELECT AEQUNR BDATAB BILOAN CSWERK

INTO TABLE ITEQ

FROM ( EQUI AS A INNER JOIN EQUZ AS B

ON AEQUNR = BEQUNR ) INNER JOIN ILOA AS C

ON BILOAN = CILOAN

WHERE A~EQART = 'ESTPL'

AND B~IWERK = 'M011'

AND B~INGRP = 'SLM'

AND BDATAB GE SDATE-LOW AND BDATAB LE SDATE-HIGH

AND C~SWERK IN S_WERK.

Hope this helps.

Reward if helpful.

Regards,

Sipra

Read only

Former Member
0 Likes
1,172

a simple select statement:

SELECT amvgr3 bbezei

FROM tvm3 AS a INNER JOIN tvm3t AS b

ON amvgr3 = bmvgr3

INTO TABLE lt_tab

WHERE b~spras = 'EN'.

regards,

naren

Read only

Former Member
0 Likes
1,172

Hi,

s_werks for mvke-dwerk obligatory. " Plant

select marcmatnr marcwerks marcdisgr mbewsalk3

into table t_marc

from marc join mbew on ( mbewbwkey = marcwerks and

mbewmatnr = marcmatnr )

where werks in s_werks.

For mor info

http://goldenink.com/abap/select_statements.html

regards

Shiva