01-07-2014 11:57 AM
hi abapers,
how i can achieve the following steps?? please help me as i am new to this abap thing.
Thanks in adv.
1. Select field1, field2 from table db1
Where field1 starts with ‘PR’ and
Field2 starts with ‘DJ’
2. for each field2 value, select field3 and field4
From db2 where
Field1 = field2 (from selection in 1.)
3. for each field1 value [from 1.] select field5 from db3
4. hold these combinations in LT_tab (field1[from 1.], field5 [from 3.], field3 [from 2.], field4 [from 2.])
01-07-2014 12:48 PM
It is better to provide actual table and field names, such generic placeholders make in unnecessarily difficult for others to properly understand the issue, and important information might be missing.
If data from two or more DB tables must end up in one internal table, and these DB tables are logically related, then first look into using JOIN SELECTs as suggested by Asim. You can save yourself a lot of internal table handling and performance issues.
Thomas
01-07-2014 12:12 PM
Hi Dhananjay ,
I actually read your combination 3 times but i did not get it but you can use in select
"WHERE field1 EQ 'PR%'. to choose which ones starting with PR if you just needs this than here is your answer if you need the all query if you can be more clear i will try to help you ...
01-07-2014 12:19 PM
Hi Asim,
No i dnt want tht thing.. I know it.
I had 3 database tables and on basis of that contitions i had to fill the lt_tab internal tables...
Field1, field2,field3,field4,field5 all fields are present in all database tables..
01-07-2014 12:31 PM
SELECT DB1~FIELD1 DB1-~FIELD2 DB2~FIELD3 DB2~FIELD4 DB3~FIELD5
INTO CORRESPONG OF TABLE LT_TAB
FROM DB1 INNER JOIN DB2 ON DB1~FIELD2 EQ DB2~FIELD3
INNER JOIN DB3 ON DB1~FIELD1 EQ DB3~FIELD5
WHERE DB1~FIELD1 EQ 'PR%' AND DB1~FIELD2 EQ 'DJ%'.
01-07-2014 1:13 PM
Hi Dhanjay,
tables : db2, db3.
Select field1 field2 into corresponding fields of table lt_tab from table db2 where field1 like 'PR%' and field2 like 'DJ%'.
loop at lt_tab into lw_tab.
select single * into db2 from db2 where field2 = lw_tab-field2.
select single * into db3 from db3 where field1 = lw_tab-field1.
lw_tab-field3 = db2-field3.
lw_tab-field4 = db2-field4.
lw_tab-field5 = db5-field5.
modify lt_tab from lw_tab.
endloop.
Else, use a join statement as suggested by Isik.
01-07-2014 12:16 PM
hi,
You can make use of FOR ALL ENTRIES IN for the second and third select statements.
now you will have 3 internal tables with correct values.. Move the values into one internal table by using MOVE-CORRESPONDING IT_T100 TO IT_ZT100.
Regards,
sivaganesh
01-07-2014 12:21 PM
hey i used the for all entries... but can i move contents of one itab to another directly by move corresponding or i need to use work area for it????
Thanks
01-07-2014 12:27 PM
01-07-2014 12:38 PM
hi,
my internal table doesn't contain the header line. I am also getting this as error and when i am using 'WITH HEADER LINE' then i am getting the error that 'Tables with headers are not supported in OO Context'.
01-07-2014 12:23 PM
Hi,
Create an internal table LT_tab containing (field1[from 1.], field5 [from 3.], field3 [from 2.], field4 [from 2.]) and a work area wa_final.
Create internal table and work area of type db1, db2 and db3.
1) Select field1 field2 from table db1
Into Table int_tab1
Where field1+0(2) = ‘PR’ and
Field2+0(2) = ‘DJ’.
2) Select field3 field4
From db2 into table int_tab2
for all entries in int_tab1
where Field3 = int_tab1-field2.
3) Select field5
From db3 into table int_tab3
for all entries in int_tab1
where Field5 = int_tab1-field1.
Loop at int_tab1 into wa1.
Loop at int_tab2 into wa2 where field3 = wa1-field2.
Loop at int_tab3 into wa3 where field5 = wa2-field1.
wa_final-field1 = wa1-field1.
wa_final-field3 = wa2-field3.
wa_final-field4 = wa2-field4.
wa_final-field5 = wa3-field5
Append wa_final to lt_tab.
clear wa_final.
Endloop.
Endloop.
Endloop.
Regards
01-07-2014 12:33 PM
Hi,
Using of three loops is good for better programming. I have already done what u have said but i want to know that is there any other idea than performing it in three loops??
Thanks.
01-07-2014 12:46 PM
Instead of loop you can use read statement. Even that will work fine.
Make sure you sort the table before loop and read.
Read int_tab2 into wa2 with key field3 = wa1-field2.
Read int_tab3 into wa3 with key field5 = wa2-field1.
Hope this helps
Regards
01-07-2014 12:48 PM
It is better to provide actual table and field names, such generic placeholders make in unnecessarily difficult for others to properly understand the issue, and important information might be missing.
If data from two or more DB tables must end up in one internal table, and these DB tables are logically related, then first look into using JOIN SELECTs as suggested by Asim. You can save yourself a lot of internal table handling and performance issues.
Thomas
01-07-2014 1:11 PM
Hi Thomas,
This is the actual thing what i wanna to ask.. please watch it and tell me the right concept.
i have the value of lv_fiscal_year_v9.
1. Select OBJNR, PAROB from table COSS
Where OBJNR starts with ‘PR’ and
VERSN = ‘PCS’ and
GJAHR = LV_FISCAL_YEAR_V9 and
WRTTP = ‘1’ and
PAROB starts with ‘KLAMDI’
2. for each PAROB value, select KOSTL (cost center) and LSTAR (activity type)
From CSSL where
OBJNR = PAROB (from selection in 1.) and
GJAHR = LV_FISCAL_YEAR_V9
3. for each OBJNR value [from 1.] select POSID from PRPS
4. hold these combinations in LT_DEL_PLAN (OBJNR [from 1.], POSID [from 3.], KOSTL [from 2.], LSTAR [from 2.])
Thanks
01-07-2014 1:24 PM
SELECT COSS~OBJNR CSSL~KOSTL CSSL~LSTAR PRPS~POSID
INTO CORRESPONG FIELD OF LT_DEL_PLAN
FROM COSS INNERJOIN CSSL ON COSS~OBJNR EQ CSSL~PAROB
INNER JOIN PRPS ON COSS~OBJNR EQ PRPS~OBJNR
WHERE COSS~OBJNR EQ 'PR%' AND COSS~VERSN EQ 'PCS'
AND COSS~GJAHR EQ LV_FISCAL_YEAR_V9 AND COSS~WRTTP EQ '1'
AND COSS~PAROB EQ 'KLAMDI%' AND CSSL~GJAHR EQ LV_FISCAL_YEAR_V9.
01-07-2014 1:55 PM
Hi Asim,
Is there will be any performance issue in using inner join on three tables??
Really your concept is great, it was the thing i just needed and u had replied the right answer even i provided the generic placeholders. thank you.
Thanks.
01-07-2014 2:03 PM
This is the best performance i think so better than using 3 loops or using read table going all 3 tables once and taking all contents just with 1 internal table . Please mark if its right
01-07-2014 2:08 PM
Hi Dhananjay,
There won't be any "Performance Depreciation" but only "Appreciation'' if you use joins, since joins are better performers than ''FOR ALL ENTRIES IN''. FOR ALL ENTRIES show poor performance when the internal table size grows. What better solution you could ask when your need is fulfilled in one neat SELECT query.
Regards,
Philip.