Join 2 internal tables
Hello,
i have to join the whole content of a table with the content of a aggregated table. i "moved" the content of the 2 dictionary tables into 2 internal tables and i want to join these 2 internal tables now.
first of all, is it generally possible to join 2 internal tables, for example with a read or loop statement?!
at second, i know how i would solve the problem in oracle 10g, but it looks like that open-sql supports not the same features like orcale. knows anyone of you how i can rebuild the following oracle statement in abap.
select a.id, a.col1, b.col2
from table_a as a, (select id, sum(col2) as col2 from table_c group by id) as b where a.id = b.id order by 1
thx
Hello Markus
ABAP open sql ahould be something like
select aid acol1 sum( b~col2 )
from table_a as a
join table_c as b
on aid = bid
group by b~id
not sure abour the order by; don't know oracle syntax exactly.
Try!
Regards,
Clemens
Similar Messages
-
Join Internal Table for all entries
Hi,
I have put the LIKP data in the internal table and then use the for all entries statement to join the table with LIPS. Besides, i specifiy an additional condition to filter empty batch.
But, i found that the empty batch record still exist in the result. Any idea??
SELECT *
FROM LIPS INTO TABLE I_DELIVERY_INFO
FOR ALL ENTRIES IN I_DELIVERY
WHERE
VBELN = I_DELIVERY-VBELN.
AND
CHARG IS NOT NULL.
Regards,
KitHi Kit,
If you are using LIKP and LIPS then you can directly join them since these tables are HEADER & ITEM table.
regd ur query you can use CHARG NE ' '.
Regards
Gopi -
Newbie: Joining internal tables
I would like to join two internal tables, but it looks like I cannot run INNER JOIN / LEFT OUTER JOIN statements on internal tables. Is there an efficient way of achieving the same result or would I be better off creating physical tables and join them that way.
The tables have roughly 10000 records and about 15 colums each which I think would be better dealt with in memory rather that going back to the database. Any thoughts?
Here is the code:
DATA: BEGIN OF WA_USREPORT,
WA_US_GLOBN TYPE ZCA_PRODUCT-GLOBN,
WA_US_GLOBT TYPE ZCA_PRODUCT-GLOBT,
WA_US_DESCR TYPE ZCA_PRODUCT-DESCR,
WA_US_INTOR TYPE ZCA_PRODUCT-INTOR,
WA_US_ACT TYPE ZCA_PRODUCT-ACT,
WA_US_TUOME TYPE ZCA_PRODUCT-TUOME,
WA_US_USITM TYPE ZCA_USITM-USITM,
WA_US_USEUMAT TYPE ZCA_USITM-USEUMAT,
WA_US_GPSUOMC TYPE ZCA_USITM-GPSUOMC,
WA_US_GPSDENOM TYPE ZCA_USITM-GPSDENOM,
WA_US_GPSNUMER TYPE ZCA_USITM-GPSNUMER,
WA_US_USPLANT TYPE ZCA_USITM-USPLANT,
WA_US_USITMDESC TYPE /BIC/TUSITM-TXTMD,
WA_US_USDIVSN TYPE /BIC/PUSITM-/BIC/USDIVSN,
WA_US_USERL TYPE /BIC/PUSITM-/BIC/US_ERL,
WA_US_USSTKTYP TYPE /BIC/PUSITMSTR-/BIC/USSTKTYP,
WA_US_USSUPNO TYPE /BIC/PUSITMSTR-/BIC/USSUPNO,
END OF WA_USREPORT,
TBL_USREPORT LIKE TABLE OF WA_USREPORT WITH HEADER LINE.
DATA: BEGIN OF WA_EUREPORT,
WA_EU_GLOBN TYPE ZCA_PRODUCT-GLOBN,
WA_EU_GLOBT TYPE ZCA_PRODUCT-GLOBT,
WA_EU_EUMAT TYPE ZCA_EUMAT-EUMAT,
WA_EU_USITM TYPE ZCA_EUMAT-USITM,
WA_EU_GPSUOMC TYPE ZCA_EUMAT-GPSUOMC,
WA_EU_GPSDENOM TYPE ZCA_EUMAT-GPSDENOM,
WA_EU_GPSNUMER TYPE ZCA_EUMAT-GPSNUMER,
WA_EU_EUMATTXT TYPE /BI0/TMATERIAL-TXTMD,
WA_EU_PRODH1 TYPE /BI0/PMATERIAL-PRODH1,
WA_EU_PRODH2 TYPE /BI0/PMATERIAL-PRODH2,
WA_EU_MSTAE TYPE /BI0/PMATERIAL-/BIC/MSTAE,
WA_EU_VENDOR TYPE /BI0/PMATERIAL-VENDOR,
END OF WA_EUREPORT,
TBL_EUREPORT LIKE TABLE OF WA_EUREPORT WITH HEADER LINE.
DATA: BEGIN OF WA_REPORT,
from ZCA_Product, ZCA_USITM, USITM and USITMSTR
WA_US_GLOBN TYPE ZCA_PRODUCT-GLOBN,
WA_US_GLOBT TYPE ZCA_PRODUCT-GLOBT,
WA_US_DESCR TYPE ZCA_PRODUCT-DESCR,
WA_US_INTOR TYPE ZCA_PRODUCT-INTOR,
WA_US_ACT TYPE ZCA_PRODUCT-ACT,
WA_US_TUOME TYPE ZCA_PRODUCT-TUOME,
WA_US_USITM TYPE ZCA_USITM-USITM,
WA_US_USEUMAT TYPE ZCA_USITM-USEUMAT,
WA_US_GPSUOMC TYPE ZCA_USITM-GPSUOMC,
WA_US_GPSDENOM TYPE ZCA_USITM-GPSDENOM,
WA_US_GPSNUMER TYPE ZCA_USITM-GPSNUMER,
WA_US_USPLANT TYPE ZCA_USITM-USPLANT,
WA_US_USITMDESC TYPE /BIC/TUSITM-TXTMD,
WA_US_USDIVSN TYPE /BIC/PUSITM-/BIC/USDIVSN,
WA_US_USERL TYPE /BIC/PUSITM-/BIC/US_ERL,
WA_US_USSTKTYP TYPE /BIC/PUSITMSTR-/BIC/USSTKTYP,
WA_US_USSUPNO TYPE /BIC/PUSITMSTR-/BIC/USSUPNO,
from ZCA_Product, ZCA_EUMAT and 0Material
WA_EU_EUMAT TYPE ZCA_EUMAT-EUMAT,
WA_EU_USITM TYPE ZCA_EUMAT-USITM,
WA_EU_GPSUOMC TYPE ZCA_EUMAT-GPSUOMC,
WA_EU_GPSDENOM TYPE ZCA_EUMAT-GPSDENOM,
WA_EU_GPSNUMER TYPE ZCA_EUMAT-GPSNUMER,
WA_EU_EUMATTXT TYPE /BI0/TMATERIAL-TXTMD,
WA_EU_PRODH1 TYPE /BI0/PMATERIAL-PRODH1,
WA_EU_PRODH2 TYPE /BI0/PMATERIAL-PRODH2,
WA_EU_MSTAE TYPE /BI0/PMATERIAL-/BIC/MSTAE,
WA_EU_VENDOR TYPE /BI0/PMATERIAL-VENDOR,
END OF WA_REPORT,
TBL_REPORT LIKE TABLE OF WA_REPORT WITH HEADER LINE.
SQL Queries *
SELECT
PGLOBN PGLOBT PDESCR PINTOR PACT PTUOME
UUSITM UUSEUMAT UGPSUOMC UGPSDENOM UGPSNUMER UUSPLANT
ITMT~TXTMD
ITMA/BIC/USDIVSN ITMA/BIC/US_ERL
ITMSTR/BIC/USSTKTYP ITMSTR/BIC/USSUPNO
FROM ZCA_PRODUCT AS P
INNER JOIN ZCA_USITM AS U ON PGLOBN = USYNPROD
INNER JOIN /BIC/TUSITM AS ITMT ON UUSITM = ITMT/BIC/USITM
INNER JOIN /BIC/PUSITM AS ITMA ON UUSITM = ITMA/BIC/USITM
LEFT OUTER JOIN /BIC/PUSITMSTR AS ITMSTR ON UUSITM = ITMSTR/BIC/USITMSTR AND ITMSTR/BIC/USBRPLANT = UUSPLANT
INTO TABLE TBL_USREPORT
WHERE ITMA~OBJVERS = 'A'
ORDER BY PGLOBT UUSITM.
SELECT
PGLOBN PGLOBT
EEUMAT EUSITM EGPSUOMC EGPSDENOM E~GPSNUMER
T~TXTMD
MPRODH1 MPRODH2 M/BIC/MSTAE MVENDOR
FROM ZCA_PRODUCT AS P
INNER JOIN ZCA_EUMAT AS E ON PGLOBN = ESYNPROD
INNER JOIN /BI0/TMATERIAL AS T ON EEUMAT = TMATERIAL
INNER JOIN /BI0/PMATERIAL AS M ON EEUMAT = MMATERIAL
INTO TABLE TBL_EUREPORT
WHERE M~OBJVERS = 'A'
ORDER BY PGLOBT EEUMAT.
TODO: join TBL_USREPORT and TBL_EUREPORT into TBL_REPORT and output as a list
Thank you for your help,
DennisHi,
Martin :-->I missed the binary search , thanks for pointing out.
loop at tbl_usreport.
move-corresponding tbl_usreport to tbl_report.
append tbl_report.
endloop.
sort tbl_report by globn globt.
loop at tbl_eureport.
read table tbl_report with key globn = tbl_eureport
globt = tbl_eureport
binary search.
if sy-subrc eq 0.
move-corresponding tbl_eureport to tbl_report.
modify tbl_report index sy-tabix.
else.
move-corresponding tbl_eureport to tbl_report.
append tbl_report.
endif.
endloop.
aRs -
How to 'inner join' internal table or cluster table ??
Hi,
when i inner join table BSEG it said is a cluster table can't be inner joined .
i wonder how i can "inner join" bseg with a internal table such as
data: begin of i_bseg_trans,
bukrs like bseg-bukrs,
gjahr like bseg-gjahr,
belnr like bseg-belnr,
total_runtimes like i_runtimes-total,
already_runtimes like i_runtimes-already,
left_runtimes like i_runtimes-left,
end of i_bseg_trans.
and similar things trouble me when considering several internal tables .
thanks for any help!!Hi,
but if there's more than 2 tables, for example
data: begin of it_bseg occurs 0,
bukrs like bseg-bukrs,
else_1 type i,
end of it_bseg.
data: begin of t occurs 0,
bukrs like bseg-bukrs,
end of t.
data: begin of r occurs 0,
bukrs like bseg-bukrs,
else type c,
end of r.
select bukrs from bkdf into table t.
select bukrs from bkdf into corresponding fields of table it_bseg.
select bseg~bukrs "else_1
from bseg "it_bseg
into table r
for all entries in t
where bseg~bukrs = t-bukrs.
" and it_bseg-bukrs = t-bukrs.
in the select clause i mean whether there's a method similar to the way just drop the " in my code.
now my solution is to use another loop on it_bseg, but i think when table amount is large this is really a boring solution. -
Hi all,
I have an internal table it_ekpo with the following data :
EBELN EBELP MATNR MENGE
5000000023 0001 test 5
I have another internal table it_ekbe with the following data :
EBELN EBELP BELNR BUZEI DMBTR
5000000023 00001 4900002212 0001 804.04
5000000023 00001 4900002213 0001 804.04
My requirement is to club these 2 internal tables and get a single ALV Internal table as output to generate ALV report.
I tried to modify the it_ekpo by transporting BELNR and DMBTR to it_ekpo. Since there is no differentiator to separate the two records, I am getting a single record output, instead of two records as follows :
EBELN EBELP MATNR MENGE BELNR
5000000023 0001 test 5 4900002213
BUZEI BUDAT MENGE_GI DMBTR
0001 20090317 1.000 804.04
I tried to use sy-tabix also and could not succeed.
I need your guidance in solving this problem.
Thanks in advance.
Rgds
MuraliHi,
Use the following:
types:
begin of ty_output,
ebeln type ebeln,
ebelp type ebelp,
matnr type matnr,
menge type menge,
belnr type belnr,
buzei type buzei,
dmbtr type dmbtr,
end of ty_output.
data: wa_output type ty_output,
it_output type table of ty_output.
sort it_ekpo by ebeln ebelp.
delete adjacent duplicates from it_ekpo comparing ebeln ebelp.
sort it_ekbe by ebeln ebelp.
loop at it_ekpo into wa_ekpo.
clear wa_output.
clear wa_ekbe.
wa_output-ebeln = wa_ekpo-ebeln.
wa_output-ebelp = wa_ekpo-ebelp.
wa_output-matnr = wa_ekpo-matnr.
wa_output-menge = wa_ekpo-menge.
loop at it_ekbe into wa_ekbe where ebeln = wa_ekpo-ebeln and ebelp = wa_ekpo-ebelp.
wa_output-belnr = wa_ekbe-belnr.
wa_output-buzei = wa_ekbe-buzei.
wa_output-dmbtr = wa_ekbe-dmbtr.
append wa_output to it_output.
clear wa_ekbe.
endloop.
clear wa_ekpo.
endloop.
Then write the logic to displaying ALV output using IT_OUTPUT internal table.
Best Regards,
Suresh -
Hi 2 all,
How to join two internal tables in abap,
give me a exampleHi raja,
We have to use FOR ALL ENTRIES
to join internal tables.
1. INNER JOIN
DBTAB1 <----
> DBTAB2
It is used to JOIN two DATABASE tables
having some COMMON fields.
2. Whereas
For All Entries,
DBTAB1 <----
> ITAB1
is not at all related to two DATABASE tables.
It is related to INTERNAL table.
3. If we want to fetch data
from some DBTABLE1
but we want to fetch
for only some records
which are contained in some internal table,
then we use for alll entries.
1. simple example of for all entries.
2. NOTE THAT
In for all entries,
it is NOT necessary to use TWO DBTABLES.
(as against JOIN)
3. use this program (just copy paste)
it will fetch data
from T001
FOR ONLY TWO COMPANIES (as mentioned in itab)
4
REPORT abc.
DATA : BEGIN OF itab OCCURS 0,
bukrs LIKE t001-bukrs,
END OF itab.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
itab-bukrs = '1000'.
APPEND itab.
itab-bukrs = '1100'.
APPEND itab.
SELECT * FROM t001
INTO TABLE t001
FOR ALL ENTRIES IN itab
WHERE bukrs = itab-bukrs.
LOOP AT t001.
WRITE :/ t001-bukrs.
ENDLOOP.
regards,
amit m. -
Possible to join multiple internal tables ?
Is it possible to join internal tables like this:
itab1:
fields are matnr f1 f2
itab2:
fields are matnr f3 f4
itab3:
fields are matnr f5 f6
required final-itab:
fields are - matnr f1 f2 f3 f4 f5 f6
(which are joined by matnr)
Thanks.Ok, then we need to take all three ITABs and get all of the MATNRs into another internal table, then loop at this internal table and read the records for ITAB1, ITAB2, and ITAB3.
data: begin of imatnr occurs 0,
matnr type mara-matnr,
end of imatnr.
loop at itab1.
imatnr-matnr = itab1-matnr.
collect imatnr.
endloop.
loop at itab2.
imatnr-matnr = itab2-matnr.
collect imatnr.
endloop.
loop at itab3.
imatnr-matnr = itab3-matnr.
collect imatnr.
endloop.
Loop at imatnr.
clear final_itab.
final_itab-matnr = imatnr-matnr.
clear itab1.
read table itab1 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f1 = itab1-f1.
final_itab-f2 = itab1-f2.
endif.
clear itab2.
read table itab2 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f3 = itab2-f3.
final_itab-f4 = itab2-f4.
endif.
clear itab3.
read table itab3 with key matnr = imatnr-matnr.
if sy-subrc = 0.
final_itab-f5 = itab3-f5.
final_itab-f6 = itab3-f6.
endif.
append final_itab.
endloop.
REgards,
Rich Heilman -
Hi Experts,
I am new comer to ABAP, have some very important task to be done, need help from all of you. I have a program which displays the results(inform about the infocubes). I want to insert the output of this prgm into an internal table, I am looking lot into the documentation, but so far not much help and i am not able to execute it. And one more task, I want to join this internal table and one database table and get the result, my question is , Is it possible to join this internal table and database table based on some common field.
Any help will be of grt help
Thanks,
Hem.Hi,
For joining internal table with database table,you need to write the logic as below.
This is the pseudo code.
select * from database into table itab2 where condition.
loop at itab1 into wa1.
move-corresponding wa1 to wa3.
loop at itab2 into wa2 where field = wa1-field.
move-corresponding wa2 to wa3.
endloop.
append wa3 to itab3.
endloop.
1. select the required data from database table into internal table.
2. loop the first internal table which you already have.
3. Based on the key fields in these two internal tables[database],place the condition in READ or LOOP statement for the second internal table inside the loop of the first internal table.
4. If there are more records in second internal table for a single record in first internal table,then use LOOP the second internal table within the first internal table.Otherwise, read the second internal table within the first internal table.
5.Then move the corresponding fields from both the internal tables inside the loop to third internal table.Append the record to the third internal table.
Hope it helps.
Regards,
J.Jayanthi -
hi all
please give a query for joining of three internal tables and store into another table,and we should retrive data from that third table
please take those fields as material number,plant,storage location,stock,unitsHello Raja,
SELECT EKKNEBELN EKKNEBELP EKKNKOSTL EKKNPS_PSP_PNR EKKN~SAKTO
EKETWEMNG EKETETENR EKETBEDAT EKPOKNTTP EKPOLOEKZ EKPOMATNR
EKPOWERKS EKPOMATKL EKPOMENGE EKPOMEINS EKPONETPR EKPOPEINH
EKPONETWR EKPOMTART EKPOEFFWR EKKOBUKRS EKKOBSART EKKOERNAM
EKKOLIFNR EKKOEKORG EKKOEKGRP EKKOWAERS EKKO~BEDAT
EKKO~MEMORY INTO TABLE G_T_OUTTAB
FROM ( EKKN
INNER JOIN EKET
ON EKETEBELN = EKKNEBELN
AND EKETEBELP = EKKNEBELP
INNER JOIN EKPO
ON EKPOEBELN = EKETEBELN
AND EKPOEBELP = EKETEBELP
INNER JOIN EKKO
ON EKKOEBELN = EKPOEBELN )
WHERE EKKN~EBELN IN S_EBELN
AND EKKN~EBELP IN S_EBELP
AND EKKN~KOSTL IN S_KOSTL
AND EKKN~PS_PSP_PNR IN S_WBS
AND EKKN~SAKTO IN S_SAKTO
AND EKPO~KNTTP IN S_KNTTP
AND EKPO~LOEKZ IN S_LOEKZ
AND EKPO~MATKL IN S_MATKL
AND EKPO~MATNR IN S_MATNR
AND EKPO~WERKS IN S_WERKS
AND EKKO~BEDAT IN S_BEDAT
AND EKKO~BSART IN S_BSART
AND EKKO~BUKRS IN S_BUKRS
AND EKKO~EKGRP IN S_EKGRP
AND EKKO~EKORG IN S_EKORG
AND EKKO~ERNAM IN S_ERNAM
AND EKKO~LIFNR IN S_LIFNR
AND EKPO~MTART IN S_MTART
AND EKKO~MEMORY IN S_MEMORY
AND EKET~BEDAT IN S_DAT_ET.
Try with this code.
If useful reward.
Vasanth -
Left ouer join with internal table
Good morning to everybody
I need created a internal table with 2 internal table but 1 is primary.
I tried use "left outer join" but it allows only with table and not with internal tabel
I would to be this result
a a xxx
b
c c zzz
d d sss
e
f f ttt
How can i do it?
Thanks a lot for your support
Beste regatrdsHi,
The following code is for your reference:
data: begin of wa1,
key type c,
end of wa1.
data: begin of wa2,
key type c,
var(3) type c,
end of wa2.
data: begin of wa3,
key1 type c,
key2 type c,
var(3) type c,
end of wa3.
data: itab1 like standard table of wa1,
itab2 like standard table of wa2,
itab3 like standard table of wa3.
wa1-key = 'a'.
append wa1 to itab1.
wa1-key = 'b'.
append wa1 to itab1.
wa1-key = 'c'.
append wa1 to itab1.
wa1-key = 'd'.
append wa1 to itab1.
wa1-key = 'e'.
append wa1 to itab1.
wa1-key = 'f'.
append wa1 to itab1.
clear wa1.
wa2-key = 'a'.
wa2-var = 'zzz'.
append wa2 to itab2.
wa2-key = 'c'.
wa2-var = 'yyy'.
append wa2 to itab2.
wa2-key = 'd'.
wa2-var = 'ttt'.
append wa2 to itab2.
wa2-key = 'f'.
wa2-var = 'sss'.
append wa2 to itab2.
clear wa2.
loop at itab1 into wa1.
read table itab2 into wa2
with key key = wa1-key
binary search.
if sy-subrc = 0.
wa3-key1 = wa1-key.
wa3-key2 = wa2-key.
wa3-var = wa2-var.
append wa3 to itab3.
clear wa3.
else.
append wa1 to itab3.
endif.
endloop.
loop at itab3 into wa3.
write:/ wa3-key1, wa3-key2,wa3-var.
endloop.
Hope it helps.
Regards,
Chris Gu -
Select (join) into internal table with nested structures
Hello Experts,
i wonder about the correct notation of a select statement.
I have an internal table it_zoll including two structures as defined below.
The select is a join on the two tables zollp and zolls. As coded below the select is syntactically correct, but the fields
in the nested structures are not filled ....
Any ideas how to write the select statement ? (The internal table it_zoll must have the nested structures for other reasons ..)
Declaration:
TYPES: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
TYPES: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
DATA: zollp type ty_zollp.
DATA: zolls type ty_zolls.
DATA: END OF wa_zoll.
DATA: it_zoll LIKE TABLE OF wa_zoll.
Select:
SELECT
zollp~belnr zollp~werks zollp~gebnr
zolls~grnum zolls~werks zolls~name1
FROM zollp
JOIN zolls ON zolls~werks = zollp~werks
AND zolls~grnum = zollp~grnum
INTO CORRESPONDING FIELDS OF TABLE it_zoll
WHERE zollp~werks = werks
AND zollp~gebnr IN s-gebnr
AND ...
Thank you !DATA: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
END OF ty_zollp.
DATA: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
Include structure ty_zollp.
Include structure ty_zolls.
DATA: END OF wa_zoll.
The above declaration had worked. Please try.
Regards,
Satish Kanteti -
Can we apply join between two internal tables?
Itab has fields A,B,C.
Data: begin of itab occurs 1,
A type I,
B type I,
C type I,
End of itab.
Jtab has fields A, I, J.
Data: begin of itab occurs 1,
A type I,
I type I,
J type I,
End of itab
The common field between itab and jtab is u201CAu201D.
Now I need to collect A,B,C,I, J in another internal table ktab.
How should I be doing this.
If I use a SELECT query with inner join between itab and jtab it says u201Citab is not a database tableu201D.
How should I get the result ktab with A B C I J fields?
Please help, nay help will be highly appreciated?a®s wrote:
>
> sort itab_all by A
> delete adjacent duplicates from itab_all comparing A.
>
>
Do you have the above code in ?
Here A is common field between both tables, first we are appending itab_1 & itab_2 into table itab_all then deleting the adjacent duplicates from itab_all. then we are reading itab_1 & itab_2 for possible matches and update the same values in itab_all
so there will NOT be a chance of duplicates in itab_all
a® -
SAP query change the internal table extracted after a join instruction
Hi Gurus
I would like to know if it is possible to change the data in internal table after that the
join instruction has been executed .
I should have to delete some lines extracted if some conditions are satisfied.
Do you think that it is not possible and it is better to crete a program?
Thanks in advanceHI,
use select and end select.
select single msegbukrs msegwerks msegmatnr msegmenge msegaufnr msegsmbln msegbwart msegshkzg mseg~meins
afkorsnum afpoverid
maststlnr maststlal stpoidnrk stpomenge stpomeins stkobmeng
into (itab-mblnr,
itab-budat,
itab-bktxt,
itab-bukrs,
itab-werks,
itab-matnr,
itab-menge,
itab-aufnr,
itab-smbln,
itab-bwart,
itab-shkzg,
itab-meins,
itab-rsnum,
itab-verid,
itab-stlnr,
itab-stlal,
itab-matnr_r,
itab-bdmng,
itab-meins_r,
itab-bmeng)
from mkpf
inner join mseg on msegmblnr eq mkpfmblnr and mkpfmjahr eq msegmjahr
inner join mara on maramatnr eq msegmatnr
inner join afpo on afpoaufnr eq msegaufnr
inner join mast on mastmatnr eq msegmatnr and mastwerks eq msegwerks
inner join afko on afkoaufnr eq msegaufnr and afkostlal eq maststlal
inner join stko on stkostlnr eq maststlnr and stkostlal eq maststlal
inner join stpo on stpostlnr eq stkostlnr
inner join stas on stasstlnr eq maststlnr and stasstlal eq maststlal and stasstlkn eq stpostlkn
where mseg~werks in s_werks
and mseg~matnr in s_matnr
and mkpf~budat in s_budat
and mseg~aufnr in s_aufnr
and mseg~bwart eq '101'
and mast~stlan eq '1'
and stko~stlty eq 'M'
and stpo~stlty eq 'M'.
if condtion .
append: itab.
endif.
clear: itab.
endselect.
Edited by: ZAHID HAMEED on Oct 12, 2011 3:56 PM -
Best way to JOIN 3 tables into internal table ?
Hi friends,
i have the following issue:
i need to join information of 3 different tables ( BUT000, BUT020 and ADRC ) concerning Business Partners and i need them into one internal table.
how would this be achieved with best performance ?
regards,
CLHi clemens,
As per my understanding, u can further improve this SQL By:
1. first select only BU000 and BU020 with inner join and then select material details in different different itabs. and process This will surely reduce load on DB and may increase load on ABAP which u can improve by using BINARY SERARCH!.
(Important: if u are using two table in join and giviing only PARTNER which is primary key field in both tables in WHERE clasuse ... this should be the only criteria in where clasue then i Dont think it will affect performance .... how many record may be there, this query will be BEST performer... I hope it will fetch 750000 records whithin few seconds)
2. Generally, U try to give more and more conditions in where clause on PRIMARY KEY fiedls only and not on not KEY fields...
3. In worst case, fetch data from three differnt tables into three different itabs and then process, this is best and last way to reduce load on DB and will increase load on ABAP which can be manages as above..
Still u want more info .. send codes to me.. We will try to make it more and more fast....
Jogdand M B
null
Message was edited by:
Jogdand M B -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
How to join two internal table rows in alternative manner into one internal table?
How to join two internal table rows in alternative manner into one internal table?
two internal tables are suppose itab1 & itab2 & its data
Header 1
Header 2
Header 3
a
b
c
d
e
f
g
h
i
Header 1
Header 2
Header 3
1
2
3
4
5
6
7
8
9
INTO itab3 data
Header 1
Header 2
Header 3
a
b
c
1
2
3
d
e
f
4
5
6
g
h
i
7
8
9Hi Soubhik,
I have added two additional columns for each internal table.
Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
Row_Count - It represents the Row Count Number, increase the row count value 1 by one..
ITAB1:
Header 1
Header 2
Header 3
Table_Count
Row_Count
a
b
c
1
1
d
e
f
1
2
g
h
i
1
3
ITAB2:
Header 1
Header 2
Header 3
Table_Count
Row_Count
1
2
3
2
1
4
5
6
2
2
7
8
9
2
3
Create the Final Internal table as same as the ITAB1/ITAB2 structure.
"Data Declarations
DATA: IT_FINAL LIKE TABLE OF ITAB1. "Final Internal Table
FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1, "TAB1
<FS_TAB2> TYPE TY_TAB2. "TAB2
"Assign the values for the additional two column for ITAB1
LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
<FS_TAB1>-TABLE_COUNT = 1. "Table value same for all row
<FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Assign the values for the additional two column for ITAB2
LOOP AT ITAB2 ASSIGNING <FS_TAB2>.
<FS_TAB2>-TABLE_COUNT = 2. "Table value same for all row
<FS_TAB2>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Copy the First Internal Table 'ITAB1' to Final Table
IT_FINAL[] = ITAB1[].
"Copy the Second Internal Table 'ITAB2' to Final Table
APPEND IT
LOOP AT ITAB2 INTO WA_TAB2.
APPEND WA_TAB2 TO IT_FINAL.
ENDLOOP.
"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
SORT IT_FINAL BY ROW_COUNT TABLE_COUNT.
After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
Regards
Rajkumar Narasimman
Maybe you are looking for
-
Creating a Maintenance Iview.
Dear Experts. I want create Maintenance Iview that I need use for a configuration customer and that I will use for hide o show service in the portal with the value of the fields of this Maintenance Iview . The table have the following fields. Field
-
HP LaserJet Pro CP1525nw Color Printer with Apple iPad & iPhones
I have an HP LaserJet Pro CP1525nw Color Printer that I've successfully used as an "air print" device to print from both iPhones and iPads. For some unknown reason, I can't print from iPhones and iPads anymore. Is anyone else experiencing this prob
-
SQL*Loader and unzipping with uploaded file
hi, everybody i was trying to integrate some functionalities, today separated. i made a simple Apex page that uploads a file, and now i need to process that file. is there any way to process that uploaded file and load it onto a table, just like i'd
-
Hi All, I have a simple stored proc in SQL server 2000 CREATE PROCEDURE dbo.sp_myProc AS SELECT CategoryID,CategoryName from Categories GO My java code is CallableStatement cs = connection.prepareCall("{? = call sp_myProc}"); cs.registerOutParameter(
-
All photos in the LR Catalog?
Hi Folks, Well, after using LR for quite some time now it suddenly occured to me that I may not have all of my photos in the catalog. With over 17,000 photos in my catalog, I'm wondering if anyone knows how I can check (compare?) to see if all photo