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: 

Doubt about using for all entries

Former Member
0 Kudos

I have to retrieve 3 columns from 2 tables(MARA and MAKT). How should i device the FOR ALL ENTRIES statement for such a situation??

What i need to retrieve is:

MATNR from MAKT

MAKTG from MAKT

MEINS from MARA.

6 REPLIES 6

abdulazeez12
Active Contributor
0 Kudos

first select matnr and meins from mara..

SELECT MATNR AND MEINS FROM MARA INTO TABLE I_MARA WHERE <CONDITIONS>.

THEN ,

SELECT MAKTG FROM MAKT INTO TABLE I_MAKT FOR ALL ENTRIES IN I_MARA WHERE MATNR = I_MARA-MATNR.

THEN USE LOOP-ENDLOOP AND READ TABLE COMBO TO GET ALL THE THREE FIELDS MATNR, MAKTG AND MEINS IN SAME INTERNAL TABLE.

cheers

Shakir

Former Member
0 Kudos

Hi,

SELECT matnr meins FROM mara
INTO TABLE i_mara
WHERE ......

IF i_makt[] IS NOT INITIAL.
SELECT meins maktg FROM makt
INTO TABLE i_makt
FOR AL ENTRIES in i_mara
WHERE matnr = i_mara-matnr.
ENDIF.

regs

Former Member
0 Kudos

HI

in final internal table you declare what ever you want from that 2 tables

MATNR

MAKTG

MEINS

and 2 more internal tables like this

1st : MATNR

MEINS from MARA

2nd : MATNR

MAKTG from MAKT

write a select query for 1st like this

SELECT MATNR MEINS from mara into itab1 where matnr = p_matnr.

if not itab1[] is initial.

SELECT MATNR MAKTG from MAKT into table itab2 FOR ALL ENTRIES IN itab1 where MATNR in itab1-matnr

endif.

loop at 1st itab1

read on itab2

move fields to final internal table only required fields

<b>reward if usefull</b>

JozsefSzikszai
Active Contributor
0 Kudos

hi,

better to use JOIN:

SELECT makt~matnr

makt~maktg

mara~meins

FROM makt AS makt

INNER JOIN mara AS mara

ON maktmatnr EQ maramatnr

INTO ==> your work area or internal table here

WHERE conditions

hope this helps

ec

Former Member
0 Kudos

Hi Prakash,

It is better to use the Inner jon in such a case where you fetch MATNR and MAKTG from MAKT on MATNR and MEINS from MARA.

The performance will also be good in this case.

Select maktmatnr maktmaktg mara~meins into itab from makt

Inner Join mara on maktmatnr = maramatnr

where<condtion>.

In case you have any further clarifications,do let me know.

Regards,

Puneet Jhari.

Former Member
0 Kudos

Hi Prakash,

I would suggest NOT using a for all entries statement, and instead doing an inner join on the MARA and MAKT tables.

data: wa_Matnr like mara-matnr,

wa_Maktx like makt-maktx.

SELECT MARA~MATNR MAKTX into (WA_MATNR, WA_MAKTX)

from MARA join MAKT

on MARAMATNR = MAKTMATNR

and MAKT~SPRAS = sy-langu

WHERE MARA~MATNR = 'XXX'.

ENDSELECT.

If this is not what you mean please give more information