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

Coupling INNER JOIN with FOR ALL ENTRIES statement

Former Member
0 Likes
868

Hi All,

I am coupling INNER JOIN with FOR ALL ENTRIES statement .....

Would you please highlight its implications ?? Is it a best practise ?

Is it advicable to use MULTIPLE INNER JOINs with a FOR ALL ENTRIES ???

SORT itab BY matnr.

IF NOT itab[] IS INITIAL.

SELECT epmatnr epebeln ep~ebelp

epwerks epmenge ep~netpr

ekps_psp_pnr ebbelnr eb~menge

INTO TABLE iekpo

FROM ekpo AS ep

INNER JOIN ekkn AS ek

ON ekebeln = epebeln

AND ekebelp = epebelp

INNER JOIN ekbe AS eb

ON ebebeln = epebeln

AND ebebelp = epebelp

AND eb~bwart = '101'

FOR ALL ENTRIES IN itab

WHERE ep~matnr = itab-matnr.

IF sy-subrc EQ 0.

SORT iekpo BY matnr werks.

LOOP AT itab ASSIGNING <itab>.

READ TABLE iekpo WITH KEY matnr = <itab>-matnr

werks = <itab>-werks

BINARY SEARCH.

IF sy-subrc EQ 0.

MOVE iekpo-matnr TO itab1-matnr.

MOVE iekpo-ebeln TO itab1-ebeln.

MOVE iekpo-ebelp TO itab1-ebelp.

MOVE iekpo-netpr TO itab1-poprice.

MOVE iekpo-werks TO itab1-werks.

MOVE iekpo-menge TO itab1-menge1.

MOVE iekpo-menge1 TO itab1-menge2.

MOVE iekpo-belnr TO itab1-belnr.

MOVE iekpo-ps_psp_pnr TO itab1-pspel.

MOVE <itab>-pspel TO itab1-tpspel.

MOVE <itab>-sobkz TO itab1-sobkz.

MOVE <itab>-fo_qty TO itab1-fo_qty.

MOVE <itab>-schgt TO itab1-schgt.

MOVE <itab>-postp TO itab1-postp.

MOVE <itab>-beskz TO itab1-beskz.

pend_qty = iekpo-menge1 - iekpo-menge2.

MOVE pend_qty TO itab1-pending.

APPEND itab1.

pend_qty = 0.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

Regards

Jaman

Edited by: ABAP Techie on Sep 15, 2008 12:39 PM

Edited by: ABAP Techie on Sep 15, 2008 12:41 PM

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
818

I don't see a problem with it as long as qualified keys (primary, secondary, foreign) are being used for linking the tables and in the WHERE conditions. As always.

Thomas

Hi All,

I am coupling INNER JOIN with FOR ALL ENTRIES statement .....

Would you please highlight its implications ?? Is it a best practise ?

Is it advicable to use MULTIPLE INNER JOINs with a FOR ALL ENTRIES ???

SORT itab BY matnr.

IF NOT itab[] IS INITIAL.

SELECT epmatnr epebeln ep~ebelp

epwerks epmenge ep~netpr

ekps_psp_pnr ebbelnr eb~menge

INTO TABLE iekpo

FROM ekpo AS ep

INNER JOIN ekkn AS ek

ON ekebeln = epebeln

AND ekebelp = epebelp

INNER JOIN ekbe AS eb

ON ebebeln = epebeln

AND ebebelp = epebelp

AND eb~bwart = '101'

FOR ALL ENTRIES IN itab

WHERE ep~matnr = itab-matnr.

IF sy-subrc EQ 0.

SORT iekpo BY matnr werks.

LOOP AT itab ASSIGNING <itab>.

READ TABLE iekpo WITH KEY matnr = <itab>-matnr

werks = <itab>-werks

BINARY SEARCH.

IF sy-subrc EQ 0.

MOVE iekpo-matnr TO itab1-matnr.

MOVE iekpo-ebeln TO itab1-ebeln.

MOVE iekpo-ebelp TO itab1-ebelp.

MOVE iekpo-netpr TO itab1-poprice.

MOVE iekpo-werks TO itab1-werks.

MOVE iekpo-menge TO itab1-menge1.

MOVE iekpo-menge1 TO itab1-menge2.

MOVE iekpo-belnr TO itab1-belnr.

MOVE iekpo-ps_psp_pnr TO itab1-pspel.

MOVE <itab>-pspel TO itab1-tpspel.

MOVE <itab>-sobkz TO itab1-sobkz.

MOVE <itab>-fo_qty TO itab1-fo_qty.

MOVE <itab>-schgt TO itab1-schgt.

MOVE <itab>-postp TO itab1-postp.

MOVE <itab>-beskz TO itab1-beskz.

pend_qty = iekpo-menge1 - iekpo-menge2.

MOVE pend_qty TO itab1-pending.

APPEND itab1.

pend_qty = 0.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

Regards

Jaman

Edited by: ABAP Techie on Sep 15, 2008 12:39 PM

Edited by: ABAP Techie on Sep 15, 2008 12:41 PM

6 REPLIES 6
Read only

Former Member
0 Likes
818

why r u using inner joins & for all entries at a time.

use only FOR ALL ENTRIES.

Firtst find relation between the table & use for all entries.

Read only

ThomasZloch
Active Contributor
0 Likes
819

I don't see a problem with it as long as qualified keys (primary, secondary, foreign) are being used for linking the tables and in the WHERE conditions. As always.

Thomas

Read only

Former Member
0 Likes
818

I really don't know if this will help, but you could take the condition:

AND eb~bwart = '101'

out of the JOIN condition and put it into the WHERE.

Rob

Read only

Former Member
0 Likes
818

.

Read only

Former Member
0 Likes
818

best practise ... don't know ... it is allowed and o.k.

If possible you should of coourse to have no FOR ALL ENTRIES at all !

Joins, there is no general rule, check indexes etc.

The first SORT, I don't that it help for anything, use it together with the delete adjacent duplicates if you expect duplicates in the driver table.

o.k., it can help, if there is a loop afterwards and an append inside, because the new table itab1 is then sorted.

Siegfried

Read only

HermannGahm
Product and Topic Expert
Product and Topic Expert
0 Likes
818

Hi,

well I see such coding in many places. Sometimes with and sometimes without problems.

If your statement is too slow a deeper analysis on detailed execution should be done to

see if a or what kind of improvement is possible.

Kind regards,

Hermann