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

Fetching data form database tables

Former Member
0 Likes
1,518

Hi all,

i have a requirment as below:

i have to fetch EINA-LIFNR, EINE-EKORG, MARA-MTART, EINA-IDNLF,

EINA-MATNR(also there in MARA), MARA-LVORM, EINA-LOEKZ.

for a given vendor LFA1-LIFNR.

we should not use joins in this.

is there any other way other than FOR ALL ENTRIES.

please help me with code in any of the way, it is very urgent...

thanks,

Rama

9 REPLIES 9
Read only

Former Member
0 Likes
1,065

Hi

write the select query as below

Select EINALIFNR EINEEKORG EINAIDNLF EINALOEKZ

EINAMATNR MARAMTART MARA~LVORM

into table ITAB

from EINA as EINA JOIN MARA as MARA

on EINAmatnr = MARAMATNR

where EINA~LIFNR IN S_LIFNR.

Regards

ANJI

Message was edited by:

Anji Reddy Vangala

Read only

Former Member
0 Likes
1,065

Hi Rama,

Try this.

Select ALIFNR AIDNLF A~LOEKZ

AMATNR BMTART B~LVORM

into table ITAB

from EINA as A JOIN MARA as B

on Amatnr = BMATNR

where EINA~LIFNR IN S_LIFNR.

If sy-subrc eq 0.

select EKORG into table i_EKORG

from eine

for all entries in itab.

If sy-subrc ne 0.

*error.

endif.

endif.

Reward If Useful.

Regards,

Chitra

Read only

0 Likes
1,065

Hi Anji & Chitra,

thanks for replay...

but in my requirment i must use only for all entries only.

Thanks,

Rama

Read only

0 Likes
1,065

Hi Rama,

Try this.

select lifnr idnlf loekz matnr into table itab

from eina

where lifnr in s_lifnr.

If sy-subrc ne 0.

endif.

select matnr mtart lvorm into table itab2

from matnr

for all entries in itab

where matnr = itab-matnr.

if sy-subrc eq 0.

select EKORG into table i_EKORG

from eine

for all entries in itab1.

If sy-subrc ne 0.

*error.

endif.

endif.

Reward If Useful.

Regards,

Chitra

Read only

0 Likes
1,065

Hi chitra,

in the bellow code for the last select statement with out where condition its giving syntatical error.

please go through it n suggest me if any other atlernative for this

select lifnr idnlf loekz matnr into table itab

from eina

where lifnr in s_lifnr.

If sy-subrc ne 0.

endif.

select matnr mtart lvorm into table itab2

from matnr

for all entries in itab

where matnr = itab-matnr.

if sy-subrc eq 0.

select EKORG into table i_EKORG

from eine

for all entries in itab1.

If sy-subrc ne 0.

*error.

endif.

endif.

Thanks,

Rama

Read only

Former Member
0 Likes
1,065

Hi Rama,

Use FOR ALL ENTRIES only in your quey.

Regards,

Shilpi

Read only

Former Member
0 Likes
1,065

Hi Rama,

Select single LIFNR from LFA1 into table it_lfa1.

Select MATNR

MTART

MFRNR

LVORM

from MARA into corresponding fields of table it_mara

for all entries in it_lfa1

where mfrnr = it_lfa1-lifnr.

Select LIFNR

EKORG

IDNLF

MATNR

LOEKZ

from EINA into corresponding fields of table it_eina

for all entries in it_mara

where lifnr = it_mara-mfrnr

and matnr = it_mara-matnr.

I think this could help you to some extent.

Reward if it is helpful.

Thanks and Regards,

Krithika

Read only

0 Likes
1,065

Hi Krithika,

in the code given by u, there is no EKORG field in EINA it is available in EINE table. please go with the code and help me.

Select single LIFNR from LFA1 into table it_lfa1.

Select MATNR

MTART

MFRNR

LVORM

from MARA into corresponding fields of table it_mara

for all entries in it_lfa1

where mfrnr = it_lfa1-lifnr.

Select LIFNR

EKORG

IDNLF

MATNR

LOEKZ

from EINA into corresponding fields of table it_eina

for all entries in it_mara

where lifnr = it_mara-mfrnr

and matnr = it_mara-matnr.

Thanks,

Rama

Read only

Former Member
0 Likes
1,065

Hi Rama,

Please use the following code for your required Query with FOR ALL ENTRIES:-

tables: EINA, EINE , MARA, LFA1.

TYPES: BEGIN OF GS_DATA1,

LIFNR TYPE LFA1-LIFNR,

END OF GS_DATA1,

BEGIN OF GS_DATA2,

LIFNR TYPE EINA-LIFNR,

IDNLF TYPE EINA-IDNLF,

MATNR TYPE EINA-MATNR,

LOEKZ TYPE EINA-LOEKZ,

END OF GS_DATA2,

BEGIN OF GS_DATA3,

LIFNR TYPE EINA-LIFNR,

IDNLF TYPE EINA-IDNLF,

MATNR TYPE EINA-MATNR,

LOEKZ TYPE EINA-LOEKZ,

EKORG TYPE EINE-EKORG,

END OF GS_DATA3,

BEGIN OF GS_DATA4,

LIFNR TYPE LFA1-LIFNR,

IDNLF TYPE EINA-IDNLF,

LOEKZ TYPE EINA-LOEKZ,

EKORG TYPE EINE-EKORG,

MATNR TYPE MARA-MATNR,

MTART TYPE MARA-MTART,

LVORM TYPE MARA-LVORM,

END OF GS_DATA4.

DATA: ITAB1 TYPE STANDARD TABLE OF GS_DATA1,

ITAB2 TYPE STANDARD TABLE OF GS_DATA2,

ITAB3 TYPE STANDARD TABLE OF GS_DATA3,

ITAB4 TYPE STANDARD TABLE OF GS_DATA4,

WA1 LIKE LINE OF ITAB1,

WA2 LIKE LINE OF ITAB2,

WA3 LIKE LINE OF ITAB3,

WA4 LIKE LINE OF ITAB4.

START-OF-SELECTION.

SELECT LIFNR FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB1.

SELECT LIFNR

IDNLF

MATNR

LOEKZ

FROM EINA

INTO CORRESPONDING FIELDS OF TABLE ITAB2

FOR ALL ENTRIES IN ITAB1

WHERE LIFNR = ITAB1-LIFNR.

SELECT LOEKZ

EKORG

FROM EINE

INTO CORRESPONDING FIELDS OF TABLE ITAB3

FOR ALL ENTRIES IN ITAB2

WHERE LOEKZ = ITAB2-LOEKZ.

SORT ITAB2 BY LOEKZ.

LOOP AT ITAB3 INTO WA3.

READ TABLE ITAB2 INTO WA2 WITH KEY LOEKZ = WA3-LOEKZ BINARY SEARCH.

IF SY-SUBRC = 0.

WA3-IDNLF = WA2-IDNLF.

WA3-MATNR = WA2-MATNR.

WA3-LIFNR = WA2-LIFNR.

MODIFY ITAB3 FROM WA3 TRANSPORTING IDNLF MATNR LIFNR.

ENDIF.

ENDLOOP.

SELECT MATNR

MTART

LVORM

FROM MARA

INTO CORRESPONDING FIELDS OF TABLE ITAB4

FOR ALL ENTRIES IN ITAB3

WHERE MATNR = ITAB3-MATNR.

SORT ITAB3 BY MATNR.

LOOP AT ITAB4 INTO WA4.

READ TABLE ITAB3 INTO WA3 WITH KEY LOEKZ = WA4-LOEKZ BINARY SEARCH.

IF SY-SUBRC = 0.

WA4-LIFNR = WA3-LIFNR.

WA4-IDNLF = WA3-IDNLF.

WA4-LOEKZ = WA3-LOEKZ.

WA4-EKORG = WA4-EKORG.

MODIFY ITAB4 FROM WA4 TRANSPORTING LIFNR IDNLF LOEKZ EKORG.

ENDIF.

ENDLOOP.

Hope this will solve your problem.

Reward points are useful.

Regard,

Shilpi