10-23-2009 6:03 AM
My requirement is to populate an itab by retrieving data from three diff db tables,
ekko,ekpo and Ekbe.
below is the code for data retrieval .
SELECT EBELN INTO TABLE IT_EKKO FROM EKKO WHERE EBELN IN S_EBELN.
IF NOT IT_EKKO[] IS INITIAL.
SELECT EBELP TXZ01 NETWR BUKRS INTO CORRESPONDING FIELDS OF TABLE IT_EKPO FROM EKPO FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN EQ IT_EKKO-EBELN.
IF NOT IT_EKPO[] IS INITIAL.
SELECT EMATN WAERS WERKS GJAHR BEWTP INTO CORRESPONDING FIELDS OF TABLE IT_EKBE FROM EKBE FOR ALL ENTRIES IN IT_EKPO
WHERE EBELN EQ IT_EKPO-EBELN
AND EBELP EQ IT_EKPO-EBELP
AND BEWTP EQ 'E' OR BEWTP EQ 'Q'.
ENDIF.
ENDIF.
please tell me how to populate data from it_ekko,it_ekpo and it_ekbe into an internal table ITAB.
10-23-2009 6:49 AM
Hi Mayana,
You take one final structure & final internal table, & within that structure take all the fields which is required to be displayed as a final output.
for data fetching from different table, you take three different structures & three internal table for that, because into corresponding fields of table is not good for performance wise. Use into table syntax.
follow the below example:(similarly)
sort it_klah by key fields.
LOOP AT IT_KSSK INTO WA_KSSK.
READ TABLE IT_KLAH INTO WA_KLAH WITH KEY CLINT = WA_KSSK-CLINT
KLART = WA_KSSK-KLART.
IF SY-SUBRC EQ 0.
MOVE: WA_KLAH-OBJEK to WA_final-OBJEK.
Read another table........(2nd one)
IF SY-SUBRC EQ 0.
MOVE: ....................................
APPEND WA_final TO IT_final.
ENDIF.
clear wa_final.
ENDLOOP.
finally display it_final records.
Hope this can solve your problems.
Regards,
Tutun
10-23-2009 6:08 AM
hi
Please search before posting que in forum.
you will fid lots of threads on combining three internal table into single internal table.
use Append statement
Sai
10-23-2009 6:10 AM
IF IT_EKBE[] IS NOT INITIAL.
SORT IT_EKBE BY EBELN EBELP.
SORT IT_EKPO BY EBELN EBELP.
SORT IT_EKKO BY EBELN.
LOOP AT IT_EKBE INTO WA_EKBE.
" WA_FINAL = WA_EKBE - ADD THE RELEVANT FIELDS IN WA_FINAL WORKAREA.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_EKBE-EBELN
EBELP = WA_EKBE-EBELP BINARY SEARCH.
IF SY-SUBRC = 0.
" WA_FINAL = WA_EKPO - ADD THE RELEVANT FIELDS IN WA_FINAL WORKAREA.
READ TABLE IT_EKKO INTO WA_EKKO WITH KEY EBELN = WA_EKPO-EBELN BINARY SEARCH.
IF SY-SUBRC = 0.
" WA_FINAL = WA_EKKO - ADD THE RELEVANT FIELDS IN WA_FINAL WORKAREA.
APPEND WA_FINAL TO IT_FINAL.
ENDIF.
ENDIF.
CLEAR WA_FINAL.
CLEAR WA_EKKO.
CLEAR WA_EKPO.
ENDLOOP.
ENDIF.
10-23-2009 6:10 AM
Hi,
You could consider using a select statement with JOIN on the 3 tables to populate the final internal table at one go, if you want avoid the extra processing of collecting the data in a single internal table.
Vikranth
10-23-2009 6:49 AM
Hi Mayana,
You take one final structure & final internal table, & within that structure take all the fields which is required to be displayed as a final output.
for data fetching from different table, you take three different structures & three internal table for that, because into corresponding fields of table is not good for performance wise. Use into table syntax.
follow the below example:(similarly)
sort it_klah by key fields.
LOOP AT IT_KSSK INTO WA_KSSK.
READ TABLE IT_KLAH INTO WA_KLAH WITH KEY CLINT = WA_KSSK-CLINT
KLART = WA_KSSK-KLART.
IF SY-SUBRC EQ 0.
MOVE: WA_KLAH-OBJEK to WA_final-OBJEK.
Read another table........(2nd one)
IF SY-SUBRC EQ 0.
MOVE: ....................................
APPEND WA_final TO IT_final.
ENDIF.
clear wa_final.
ENDLOOP.
finally display it_final records.
Hope this can solve your problems.
Regards,
Tutun
10-23-2009 10:17 AM
Hi thanks to all,
My problem is solved,
@Tutu: ur reply helped me alot ,i awarded points to you,
Even i awarded my points to all useful answers
10-23-2009 7:54 AM
The best way is to either go with iner joining the 3 tables..
else..
1) As you are just retrieving the ebeln from ekko rather than 2 diffrent selects go with inner join of ekko and ekpo on ebeln.
2) slect ebeln also from ekbe.
3)loop at the first table and read the it_ekbe with key ebeln.
fill the data into the final table...
dont use move corresponding fields directly use the field reference...
Edited by: imran khan on Oct 23, 2009 8:55 AM
10-24-2009 11:49 PM
Hi Mayana,
Even though you already got an answer, I will point you to this code sample, showing how to join three database tables in one query.
http://mysapsource.com/abap-tables/run-a-database-query-in-abap-with-a-join-on-3-tables
Best Regards
Peter