‎2007 Feb 06 4:38 AM
Hi,
How can I use select stat. rather than join to join to tables so that I have all the fields from both tables appearing in my output.
‎2007 Feb 06 5:20 AM
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1,
wa_linp type linp,
wa_link type link.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 where lgnum = pa_lgnum and ivnum in s_ivnum.
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
ENDIF.
append it_tab3.
clear it_tab3.
endloop.
can you please chech the above code.
‎2007 Feb 06 4:42 AM
Hi,
Performance wise it is better to use JOIN that to use nested selects.
Hope this helps.
Reward if helpful.
Regards,
Sipra
‎2007 Feb 06 4:44 AM
Hi Shaheen ,
In that cae you will have to use a nested select , i.e. one select statement inside another select.
Regards
Arun
‎2007 Feb 06 4:45 AM
Use can use for all entries.
select * from vbak into table itab1.
select * from vbap into table itab2
for all entries in itab1
where vbeln = itab1-vbeln.
loop at itab2.
read table itab1 with key vbeln = itab2-vbeln.
if sy-subrc = 0.
move-corresponding itab1 to itab3.
endif.
move-corresponding itab2 to itab3.
append itab3.
clear itab3.
endloop.
now itab3 contains data from both VBAP & VBAK table.
‎2007 Feb 06 4:46 AM
Hi,
You can use INNER JOIN...
Example
-
PARAMETERS: P_EBELN LIKE EKKO-EBELN.
SELECT AEBELN BEBELP BNETPR BMENGE
INTO TABLE ITAB
FROM EKKO AS A INNER JOIN EKPO AS B
ON AEBELN = BEBELN
WHERE A~EBELN = P_EBELN.
LOOP AT ITAB.
WRITE: / ITAB.
ENDLOOP.
Thanks,
Naren
‎2007 Feb 06 4:54 AM
shaeen,
Select required fields from table1 into table itab1
where condituions for first table.
if not itba1[] is initial.
select required fields from table2 into table itab2
for all entries in itab1
where keyfields = itab1-field.......
endif.
if you have duplicate values .
Delete adjusent duplicates from itab1 comparing your key fields.
sort : itab1 by key fields,
itab2 by key fields.
LOOP AT ITAB1
if you have multiple records use
loop at itab2 where keyfield = itab1-keyfield
Move : required values for itab1 and itab2 to i_final .
endloop.
if you have single record..
read table itab2 with key mainfield = itab1-keyfield binary serach.
if sy-subrc eq 0.
Move : required values for itab1 and itab2 to i_final .
endif.
ENDLOOP.
Pls. reward if useful
‎2007 Feb 06 5:20 AM
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1,
wa_linp type linp,
wa_link type link.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 where lgnum = pa_lgnum and ivnum in s_ivnum.
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
ENDIF.
append it_tab3.
clear it_tab3.
endloop.
can you please chech the above code.
‎2007 Feb 06 5:27 AM
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
lgtyp type lgtyp,
uname type LINK_UNAME,
ivpos type LVS_IVPOS,
lgpla type lgpla,
idatu type LVS_IDATU,
end of str1_tab.
Types: begin of str2_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
end of str2_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1,
wa_linp type linp,
wa_link type link.
DATA: it_tab3 TYPE TABLE OF str2_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
select lgnum ivnum lgpla idatu from linp into table it_tab3 for all entries in it_tab1 where lgnum = pa_lgnum and ivnum in s_ivnum.
sort it_itab1.
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum binary search .
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
ENDIF.
append it_tab3.
clear it_tab3.
endloop.
‎2007 Feb 06 5:29 AM
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1,
wa_linp type linp,
wa_link type link.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
****Declare one more table.
DATA: it_tab4 TYPE TABLE OF str1_tab,
wa_tab4 LIKE LINE OF it_tab4.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
if not it_itab1[] is initial.
sort it_itab1 by lgnum.
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 where lgnum = pa_lgnum and ivnum in s_ivnum.
endif.
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding wa_tab1 to it_tab4.
ENDIF.
move-corresponding wa_itab3 to it_itab4.
append it_tab4.
clear it_tab4.
endloop.
now itab4 contains all data.
‎2007 Feb 06 8:04 AM
Hi,
There are two ways to handle the problem.
1. For all entries
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
<b>if sy-subrc eq 0.</b>
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 <b>where lgnum = itab1-lgnum and ivnum = itab1-ivnum.</b><b>endif.</b>
LOOP AT it_tab3 INTO wa_tab3.
<b>clear wa_tab1.</b>
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
<b>modify it_tab3 from wa3 transporting lgtyp uname where lgnum = wa_tab3-lgnum
and ivnum = wa_tab3-ivnum.</b>ENDIF.
clear it_tab3.
endloop.
2. Use inner join
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
select linklgnum linkivnum linklgtyp linkuname linplgpla linpidatu FROM link inner join linp on linklgnum = linplgnum
and linkivnum = linkivnum
into TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
Now itab1 will contain all the values
‎2007 Feb 06 5:41 AM
I'm getting this error---->
THE WHERE CONDITION DOES NOT REFER TO THE FOR ALL ENTRIES TABLES
‎2007 Feb 06 5:49 AM
select lgnum ivnum lgpla idatu from linp into table it_tab3 for all entries in it_tab1 where lgnum = it_tab1-lgnum and ivnum = it_tab1- ivnum .
‎2007 Feb 06 6:57 AM
I'm still not getting the LGPLA AND IDATU recods of the linp tables.
‎2007 Feb 06 7:04 AM
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
*******See the mod below
if not it_itab1[] is initial.
sort it_itab1 by lgnum ivnum.
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 where lgnum = pa_lgnum and
ivnum = itab1-ivnum.
endif.
sort it_tab1 by lgnum ivnum.
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum binary search.
IF sy-subrc = 0.
move-corresponding wa_tab1 to it_tab4.
ENDIF.
move-corresponding wa_itab3 to it_itab4.
append it_tab4.
clear it_tab4.
endloop.
‎2007 Feb 06 7:15 AM
Instead of code
LOOP AT it_tab3 INTO wa_tab3.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum binary search.
IF sy-subrc = 0.
move-corresponding wa_tab1 to it_tab4.
ENDIF.
move-corresponding wa_itab3 to it_itab4.
append it_tab4.
clear it_tab4.
endloop.
write the below code:
data: p_index like sy-tabix.
LOOP AT it_tab3 INTO wa_tab3.
p_index = sy-tabix.
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum binary search.
IF sy-subrc = 0.
move-corresponding wa_tab1 to wa_itab3.
ENDIF.
modify it_tab3 from wa_itab3 index p_index transporting lgtyp uname.
endloop.
In the end it_tab3 will have all the required fields.
Thanks.
‎2007 Feb 06 7:23 AM
Hello,
Perfer a INNER JOIN instead of nested select atatements which can reduce the perfomance.
see the 'Tips & Tricks' in the transaction se30.
Regards,
Shehryar Dahar
‎2007 Feb 06 7:43 AM
Yes that's exactly what i'm doing but I don't know why i'm not getting those 2 feilds records.