2009 Jun 12 12:51 PM
i have 5 internal table it_vbrk, it_vbrp, it_vbak,it_vbap, it_lips and it_kna1 ..( the select-options was likp-erdat and likp-vbeln)
based on that i have done select 'for all entries' on it_likp into it_likp have selected 3 flds from likp, 7 flds from lips. now using
for all entries on
it_lips i have selected 5 flds from vbrp into it_vbrp. based on for all entries on it_lips i have selected 5 flds from vbap.
now i have to populate my final internal table it_final.
****************************************************************************************************************
types: begin of it_final, "this is my internal table flds arranged according to the list output
vbeln type vbap-vbeln,
posnr type vbap-posnr,
erdat type vbak-erdat,
kunnr type likp-kunnr,
name1 type kna1-name1,
aufnr type vbak-aufnr,
matnr typr vbap-matnr,
arktx type vbap-arktx,
kwmeng type vbap-kwmeng,
vrkme type vbap-vrkme,
vbeln1 type lips-vbeln,
posnr 1type lips-posnr,
lfimg type lips-lfimg,
vrkme type lips-vrkme,
vbeln2 type vbrp-vbeln,
posnr2 type vbrp-posnr,
fklmg type vbrp-fklmg,
vrkme1 type vbrp-vrkme,
end of it_final.
now plz tell me how to populate this internal table? which is the right method :
(1) looping at it_likp into wa_likp. "based on the likp-vbeln i am fetching the flds from lips.
read table it_lips into wa_lips where vbeln = wa_likp-vbeln.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-fklmg = wa_lips-fkimg.
it_final-vrkme1 = wa_lips-vrkme.
append it_final. endloop.
loop at it_final.
read table it_vbrp where vgbel = it_final-vbeln.
it_final-vbeln2 = wa_vbrp-vbeln.
...........
modify it_final index sy-tabix transporting vbeln2....
similarly fetch the records from vbap, lips etc.
(2 )another method.
loop at it_likp into wa_likp.
read table it_lips into wa_lips where vbeln = wa_likp-vbeln.
read table it_vbrp into wa_vbrp where vgbel = wa_likp-vbeln.
read table it_vbap into wa_vbap where vbeln = wa_lips-vgbel.
[ps: i am selecting vgbel and vgpos from lips and vbrp but not populating into it_final as it is not reqd.]
it_final-vbeln = wa_vbap-vbeln.
it_final-posnr = wa_vbap-posnr.
it_final-matnr = wa_vbap-matnr.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-lfimg = wa_lips-lfimg.
it_final-vbeln2 = wa_vbrp-vbeln.
it_final-posnr3 = wa_vbrp-posnr.
it_final-fklmg = wa_vbrp-fklmg.
........
.........
append it_final.
clear it_final.
endloop.
*************************************************************************************************************
now plz suggest which one is a better method to follow and why? suggest me some tips to select which table to use loop first and how? where shud i use read table? plz site some codes as an example.
elaborate answers will be highly appreciated.
2009 Jun 12 1:24 PM
Hi,
Can you format your message.
It is difficult to understand.
regards,
Ankur Parab
2009 Jun 12 1:32 PM
Hi,
Second method where you are reading the data from other tables is better approach.
Also, sort the tables on key fiels like vbeln posnr etc. Use binary search addition to read statement.
One correction read statement don't have where clause instead use WITH KEY addition.
Loop at the table which have most of the fields which you want to populate in final internal table and read other tables.
KR Jaideep,
2009 Jun 12 1:36 PM
types: begin of it_final,
"this is my internal table flds arranged according to the list output
vbeln type vbap-vbeln,
posnr type vbap-posnr,
erdat type vbak-erdat,
kunnr type likp-kunnr,
name1 type kna1-name1,
aufnr type vbak-aufnr,
matnr typr vbap-matnr,
arktx type vbap-arktx,
kwmeng type vbap-kwmeng,
vrkme type vbap-vrkme,
vbeln1 type lips-vbeln,
posnr 1type lips-posnr,
lfimg type lips-lfimg,
vrkme type lips-vrkme,
vbeln2 type vbrp-vbeln,
posnr2 type vbrp-posnr,
fklmg type vbrp-fklmg,
vrkme1 type vbrp-vrkme,
end of it_final.
now plz tell me how to populate this internal table? which is the right method :
(1) looping at it_likp into wa_likp.
"based on the likp-vbeln i am fetching the flds from lips.
read table it_lips into wa_lips where vbeln = wa_likp-vbeln.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-fklmg = wa_lips-fkimg.
it_final-vrkme1 = wa_lips-vrkme.
append it_final.
endloop.
loop at it_final.
read table it_vbrp where vgbel = it_final-vbeln.
it_final-vbeln2 = wa_vbrp-vbeln. ...........
modify it_final index sy-tabix transporting vbeln2....
similarly fetch the records from vbap, lips etc.
(2 )another method.
loop at it_likp into wa_likp.
read table it_lips into wa_lips where vbeln = wa_likp-vbeln.
read table it_vbrp into wa_vbrp where vgbel = wa_likp-vbeln.
read table it_vbap into wa_vbap where vbeln = wa_lips-vgbel.
[ps: i am selecting vgbel and vgpos from lips and vbrp but not populating into it_final as it is not reqd.]
it_final-vbeln = wa_vbap-vbeln.
it_final-posnr = wa_vbap-posnr.
it_final-matnr = wa_vbap-matnr.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-lfimg = wa_lips-lfimg.
it_final-vbeln2 = wa_vbrp-vbeln.
it_final-posnr3 = wa_vbrp-posnr.
it_final-fklmg = wa_vbrp-fklmg.
........ ......... append it_final.
clear it_final.
endloop. *************************************************************************************************************
2method is the fine ,
Because performance wise it is good ,withi in sigle loop you do this.
All the tables relation is important for second method.
In 1st method Two loops are there so getting the data in final table is difficult
Thanks
2009 Jun 12 1:59 PM
There is a 2500 character limit on posting with formatting.
matt
2009 Jun 13 6:25 PM
my heartfelt thanks to all of you
you guys are really great and this forum is simply awesome .
buddy ankur, i am new to this forum in terms of content posting so i really dont know how to format
i wrote the whole thing within "<codes>" ,but its appearing unformatted.
-
THERE WAS A MISTAKE IN MY POST I AM CORRECTING IT. plz forgive me
types: begin of it_final,
"this is my internal table flds arranged according to the list output
vbeln type vbap-vbeln{code,
posnr type vbap-posnr,
erdat type vbak-erdat,
}kunnr type likp-kunnr,
lfdat type likp-lfdat,
name1 type kna1-name1,
aufnr type vbak-aufnr,
matnr typr vbap-matnr,
arktx type vbap-arktx,
kwmeng type vbap-kwmeng,
vrkme type vbap-vrkme,
vbeln1 type lips-vbeln,
posnr 1type lips-posnr,
lfimg type lips-lfimg,
vrkme type lips-vrkme,
vbeln2 type vbrp-vbeln,
posnr2 type vbrp-posnr,
fklmg type vbrp-fklmg,
vrkme1 type vbrp-vrkme,
end of it_final.
now plz tell me how to populate this internal table? which is the right method :
-
(1) looping at it_likp into wa_likp.
"based on the likp-vbeln i am fetching the flds from lips.
read table it_lips into wa_lips WITH KEY vbeln = wa_likp-vbeln.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-fklmg = wa_lips-fkimg.
it_final-vrkme1 = wa_lips-vrkme.
append it_final.
endloop.
loop at it_final.
read table it_vbrp WITH KEY vgbel = it_final-vbeln.
it_final-vbeln2 = wa_vbrp-vbeln. ...........
modify it_final index sy-tabix transporting vbeln2....
similarly fetch the records from vbap, lips etc.
-
(2 )another method. (in my earlier post i wrote loop at it_likp)
LOOP AT IT_LIPS INTO WA_LIPS._
_READ TABLE IT_LIKP INTO WA_LIKP WITH KEY VBELN = WA_LIPS-VBELN._
read table it_vbrp into wa_vbrp WITH KEY vgbel = wa_likp-vbeln.
read table it_vbap into wa_vbap WITH KEY vbeln = wa_lips-vgbel.
ps: i am selecting vgbel and vgpos from lips and vbrp but not populating into it_final as it is not reqd.
it_final-vbeln = wa_vbap-vbeln.
it_final-posnr = wa_vbap-posnr.
it_final-matnr = wa_vbap-matnr.
it_final-vbeln1 = wa_lips-vbeln.
it_final-posnr1 = wa_lips-posnr.
it_final-lfimg = wa_lips-lfimg.
it_final-lfdat = wa_likp-lfdat.
it_final-kunnr = wa_likp-kunnr.
it_final-vbeln2 = wa_vbrp-vbeln.
it_final-posnr3 = wa_vbrp-posnr.
it_final-fklmg = wa_vbrp-fklmg.
........ ......... append it_final.
clear it_final.
endloop.
-------------------------------------------------------------------------------------------------
*3rd method.*
itfinal is my internal table, it consists of the fields mentioned in "types" statement.select vbeln lfdat ....(etc) into it_likp ..(where clause)
select vbeln posnr matnr lfimg vrkme from lips into corresponding fields of table it_final for all entries in it_likp where vbeln = it_likp-vbeln.
"now looping on it_final and fetching other fields from other tables."
loop at it_final into wa_final.
l_tabix = sy-tabix. (why are we doing this?)
read table it_likp into wa_likp with key.....(contd)
wa_final-lfdat = wa_likp-lfdat.
wa_final-kunnr = wa_likp-kunnr.
read table it_vbap into wa_vbap with key....(contd)
wa_final-vbeln = wa_vbap-vbeln.
wa_final-posnr = wa_vbap-posnr.
read table it_vbrp ....
(contd)
modify it_final index l_tabix transporting lfdat kunnr vbeln posnr ...(etc).
endloop.
***********************************
my question is why will i loop into the item table and not into the header table. amongst the above 3 which is a better method to follow and why? if u have some other coding techniques then pls tell me.
will it be better if i use 'MODIFY' here instead of 'APPEND'? why are we storing the sy-tabix value here?