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

How to get data from multiple tables!

Former Member
0 Likes
1,113

What is the way to fetch data from different fields of multiple tables which are connected ?

Please give me an example of more than 3 tables .

What is the way to fetch data from different fields of multiple tables which are connected ?

Please give me an example of more than 3 tables .

2 REPLIES 2
Read only

former_member386202
Active Contributor
0 Likes
478

Hi,

Use FOR ALL ENTRIES

Refer this code

&----


*& Form SUB_READ_VBRK

&----


  • text

----


FORM sub_read_vbrk.

SELECT vbeln

rplnr

bukrs

FROM vbrk

INTO TABLE it_vbrk

WHERE vbeln IN s_vbeln

AND rplnr NE ' '.

IF sy-subrc EQ 0.

SORT it_vbrk BY rplnr.

ENDIF.

ENDFORM. " SUB_READ_VBRK

&----


*& Form SUB_READ_FPLTC

&----


  • text

----


FORM sub_read_fpltc.

IF NOT it_vbrk[] IS INITIAL.

SELECT fplnr

fpltr

ccnum

FROM fpltc

INTO TABLE it_fpltc

FOR ALL ENTRIES IN it_vbrk

WHERE fplnr EQ it_vbrk-rplnr

AND ccins EQ 'GIFC'.

IF sy-subrc EQ 0.

SORT it_fpltc BY fplnr.

ENDIF.

ENDIF.

ENDFORM. " SUB_READ_FPLTC

&----


*& Form SUB_COLLECT_DATA

&----


  • text

----


FORM sub_collect_data.

*--Local variables

DATA : lv_count(3) TYPE c.

IF NOT it_fpltc[] IS INITIAL.

LOOP AT it_fpltc INTO wa_fpltc.

lv_count = wa_fpltc-fpltr+3(3).

wa_final-ccnum = wa_fpltc-ccnum.

wa_final-rfzei = lv_count.

CLEAR : wa_vbrk.

READ TABLE it_vbrk INTO wa_vbrk WITH KEY rplnr = wa_fpltc-fplnr

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_final-vbeln = wa_vbrk-vbeln.

wa_final-bukrs = wa_vbrk-bukrs.

ENDIF.

APPEND wa_final TO it_final.

CLEAR : wa_vbrk,

wa_fpltc,

lv_count.

ENDLOOP.

ENDIF.

ENDFORM. " SUB_COLLECT_DATA

Regards,

PRashant

Read only

VikasB
Active Participant
0 Likes
478

Hi Jyotirmoy,

Try out with the following code.

SELECT a~matnr

a~berid

a~dismm

a~ausss

a~sobsl

b~berty

INTO TABLE it_mdma_mdlv_mdll

FROM mdma AS a

INNER JOIN mdlv AS b

ON aberid EQ bberid

INNER JOIN mdll AS c

ON bberid EQ cberid

FOR ALL ENTRIES IN it_bomitems

WHERE a~matnr EQ it_bomitems-idnrk

AND a~dispo IN s_cdispo

AND b~berty EQ '3'

AND a~sobsl IN s_csobsl

AND c~lbear IN s_lifnr.

this query contains join for 3 different tables.

regards,

vikas.

plz reward if helpful..