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: 

how to get out put

Former Member
0 Kudos
74

hi i have to get 4 fields from 4 different tables and i have to put those fields in the final internal table for output purpose how can i do this?

7 REPLIES 7

Former Member
0 Kudos
57

Please close ur previous threads if u have got satisfactory answers.

Former Member
0 Kudos
57

Hi,

Follow the below logic.

loop at itab1.

it_final-<field1> = itab1-<field1>.

read table itab2 with key <field2> = itab1-<field>.

if sy-subrc = 0.

it_final-<field2> = itab2-<field2>.

endif.

read table itab3 with key <field3> = itab1-<field>.

if sy-subrc = 0.

it_final-<field3> = itab2-<field3>.

endif.

read table itab4 with key <field4> = itab1-<field>.

if sy-subrc = 0.

it_final-<field4> = itab2-<field4>.

endif.

append it_final.

clear it_final.

endloop.

Former Member
0 Kudos
57

Hello,

You can create an internal table with the 4 fields and do a select with INNER JOIN.

Regards,

Former Member
0 Kudos
57

Hi,

Try this code snippet just to have idea. I have used Inner join.

&----


*& Report ZTEST_LAKSHMI1

*&

&----


*&

*&

&----


REPORT ztest_lakshmi1.

TABLES: mara, marc, vbap, vbak.

TYPES: BEGIN OF ty_final,

matnr LIKE mara-matnr,

mtart LIKE mara-mtart,

werks LIKE marc-werks,

vkgrp LIKE vbak-vkgrp,

END OF ty_final,

BEGIN OF ty_test,

matnr LIKE mara-matnr,

mtart LIKE mara-mtart,

werks LIKE marc-werks,

mmatnr LIKE marc-matnr ,

vbeln LIKE vbap-vbeln,

vmatnr LIKE vbap-matnr,

vwerks LIKE vbap-werks,

vkgrp LIKE vbak-vkgrp,

vvbeln LIKE vbak-vbeln,

END OF ty_test.

DATA: it_final TYPE STANDARD TABLE OF ty_final WITH HEADER LINE,

it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.

SELECT mara~matnr

mara~mtart

marc~werks

marc~matnr

vbap~vbeln

vbap~matnr

vbap~werks

vbak~vkgrp

vbak~vbeln

FROM ( mara

INNER JOIN marc

ON marcmatnr = maramatnr

INNER JOIN vbap

ON vbapmatnr = marcmatnr

AND vbapwerks = marcwerks

INNER JOIN vbak

ON vbakvbeln = vbapvbeln )

INTO TABLE it_test.

LOOP AT it_test.

MOVE it_test-matnr TO it_final-matnr.

MOVE it_test-mtart TO it_final-mtart.

MOVE it_test-werks TO it_final-werks.

MOVE it_test-vkgrp TO it_final-vkgrp.

APPEND it_final.

CLEAR it_final.

ENDLOOP.

LOOP AT it_final.

WRITE: /10 it_final-matnr,

25 it_final-mtart,

40 it_final-werks,

60 it_final-vkgrp.

ENDLOOP.

Cheers,

Ramalakshmi

Reward points if useful.

Former Member
0 Kudos
57

data:

begin of itab occurs 10,

carrname type scarr-carrname,

carrid type spfli-carrid,

connid type sflight-connid,

fldate type sflight-fldate,

bookid type sflight-bookid,

end of itab.

select scarr~carrname

spfli~carrid

spfli~connid

sflight~fldate

sbook~bookid

from ( ( ( scarr inner join spfli on

scarrcarrid eq spflicarrid )

inner join sflight on

spflicarrid eq sflightcarrid

and spfliconnid eq sflightconnid )

inner join sbook on

sbookcarrid eq sflightcarrid and

sbookconnid eq sflightconnid and

sbookfldate eq sflightfldate )

into table itab.

loop at itab.

write 😕 itab-carrid ,

itab-connid ,

itab-fldate,

itab-bookid.

endloop.

try this example code u will get data from four different tables

Former Member
0 Kudos
57

Hi ,

Try creating a view and access the data from that view, this would be faster in fetching the records.

This view needs to be created if ur going to consider more than 3 fields from the table.

Former Member
0 Kudos
57

Hi,

I think Inner Join is the best solution but if you have performance problems. Use 4 select single in 4 variables and then append you internal table.

Regards,

Fernando