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

fetch data

Former Member
0 Likes
799

hi

i need to fetch data from five related tables based on the entries in selection screen....can anybody help me....

regards

vinod

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
776

Hi

Here is a sample code.. try to use primary key fields for joining tables,

**********************************************************************************

SELECT distinct AGJAHR AVERSN AVRGNG AKSTAR AOBJNR AWRTTP A~BEKNZ

ALEDNR ABUKRS ATWAER AWTG001 AWOG001 AMEG001

BBELNR BCPUTM BBLDAT BUSNAM BXBLNR BBLART BGLVOR BKUTY2

CBUZEI CEBELN CVBUND CSGTXT C~WERKS

DSCOPE DWKGBTR DBELTP DGKONT DGKOAR DOWAER D~MEINB "COEP

EERSDA EBKZKP E~PKZKP

F~LTEXT

INTO CORRESPONDING FIELDS OF TABLE ITAB FROM

CSKU AS F

INNER JOIN COSP AS A ON FKSTAR = AKSTAR

INNER JOIN BKPF AS B ON AGJAHR = BGJAHR

INNER JOIN COEP AS D ON BBELNR = DBELNR

INNER JOIN CSKS AS E ON DKOKRS = EKOKRS

WHERE A~VERSN EQ P_VERSN AND

A~GJAHR EQ P_GJAHR AND

A~PERBL EQ P_PERBL .

( BSEG~KOKRS EQ P_KOKRS ) AND

( BSEG~KOSTL EQ P_KOSTL ).

plz reward if it s helpful

6 REPLIES 6
Read only

Former Member
0 Likes
776

post the table names

Read only

Former Member
0 Likes
776

Hi,

Post the table names.

Regards,

Ramya

Read only

Former Member
0 Likes
777

Hi

Here is a sample code.. try to use primary key fields for joining tables,

**********************************************************************************

SELECT distinct AGJAHR AVERSN AVRGNG AKSTAR AOBJNR AWRTTP A~BEKNZ

ALEDNR ABUKRS ATWAER AWTG001 AWOG001 AMEG001

BBELNR BCPUTM BBLDAT BUSNAM BXBLNR BBLART BGLVOR BKUTY2

CBUZEI CEBELN CVBUND CSGTXT C~WERKS

DSCOPE DWKGBTR DBELTP DGKONT DGKOAR DOWAER D~MEINB "COEP

EERSDA EBKZKP E~PKZKP

F~LTEXT

INTO CORRESPONDING FIELDS OF TABLE ITAB FROM

CSKU AS F

INNER JOIN COSP AS A ON FKSTAR = AKSTAR

INNER JOIN BKPF AS B ON AGJAHR = BGJAHR

INNER JOIN COEP AS D ON BBELNR = DBELNR

INNER JOIN CSKS AS E ON DKOKRS = EKOKRS

WHERE A~VERSN EQ P_VERSN AND

A~GJAHR EQ P_GJAHR AND

A~PERBL EQ P_PERBL .

( BSEG~KOKRS EQ P_KOKRS ) AND

( BSEG~KOSTL EQ P_KOSTL ).

plz reward if it s helpful

Read only

rahulkavuri
Active Contributor
0 Likes
776

Thats a very vague question..

there are many ways to fetch the data from related tables ..

we can either go for ABAP selection in a program or create a VIEW or do an ABAP query for it..

Read only

Former Member
0 Likes
776

thanks 2 all

Read only

Former Member
0 Likes
776

hi ,

here i am giving the data for 4 tables ..look at this..

report ztest.

tables:pa0002,pa0008,pa0021,pa0041.

data: begin of itab occurs 0,

pernr like pa0002-pernr,

vorna like pa0002-vorna,

nachn like pa0002-nachn,

end of itab.

data: begin of itab1 occurs 0,

pernr like pa0008-pernr,

begda like pa0008-begda,

stvor like pa0008-stvor,

ansal like pa0008-ansal,

end of itab1.

data :begin of itab2 occurs 0,

pernr like pa0021-pernr,

favor like pa0021-favor,

fanam like pa0021-fanam,

end of itab2.

data:begin of itab3 occurs 0,

pernr like pa0041-pernr,

dar01 like pa0041-dar01,

dat01 like pa0041-dat01,

end of itab3.

data:begin of final occurs 0,

pernr like pa0002-pernr,

vorna like pa0002-vorna,

nachn like pa0002-nachn,

begda like pa0008-begda,

stvor like pa0008-stvor,

ansal like pa0008-ansal,

favor like pa0021-favor,

fanam like pa0021-fanam,

dar01 like pa0041-dar01,

dat01 like pa0041-dat01,

end of final.

select-options:s_pernr for pa0002-pernr.

select pernr

vorna

nachn

from pa0002

into table itab

where pernr in s_pernr.

select pernr

begda

stvor

ansal

from pa0008

into table itab1

for all entries in itab

where pernr = itab-pernr.

select pernr

favor

fanam

from pa0021

into table itab2

for all entries in itab1

where pernr = itab1-pernr.

select pernr

dar01

dat01

from pa0041

into table itab3

for all entries in itab2

where pernr = itab2-pernr.

loop at itab.

final-pernr = itab-pernr.

final-vorna = itab-vorna.

final-nachn = itab-nachn.

read table itab1 with key pernr = itab-pernr.

final-begda = itab1-begda.

final-stvor = itab1-stvor.

final-ansal = itab1-ansal.

read table itab2 with key pernr = itab1-pernr.

final-favor = itab2-favor.

final-fanam = itab2-fanam.

read table itab3 with key pernr = itab2-pernr.

final-dar01 = itab3-dar01 .

final-dat01 = itab3-dat01.

append final.

clear final.

endloop.

loop at final.

write:final-pernr ,

final-vorna ,

final-nachn ,

final-begda ,

final-stvor ,

final-ansal ,

final-favor ,

final-fanam ,

final-dar01 ,

final-dat01 .

endloop.

regards,

venkat.