‎2009 Aug 18 3:14 AM
experts, help needed
itab has following fields,
vbeln posnr erdat erzet vkorg vtweg
kunnr posnr matnr bmeng status.
i have written like this
SELECT avbeln aerdat aerzet avkorg a~vtweg
akunnr bposnr b~matnr
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
endif.
but my internal table fields sequence are different. so i changed the posnr field in the select query to the second place.
SELECT avbeln bposnr aerdat aerzet avkorg avtweg
akunnr bmatnr
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
endif.
so in above two select statements which one is right , according to coding standards,?
in this case do i need to use the into corresponding fields addition because i am not selecting bmeng , status fields into the itab?
‎2009 Aug 18 3:41 AM
thank you for the answers.
my internal table has the fields in this sequence
itab :-
vbeln
posnr
erdat
erzet
vkorg
vtweg
kunnr
matnr
bmeng
status.
1)so which select query i need to use in the above for this sequence either first or second, if so why not other
2) do i need to use the into corresponding fields addition because i am not using the fields bmeng and status and also in the first query the posnr in not in sequence to itab
‎2009 Aug 18 3:31 AM
Hi,
Change the field sequence in the internal table as per the first select query. I don't think there will be any performance/ run time difference between first and second select statements. Also, avoid using corresponding fields addition as it a performance killer.
‎2009 Aug 18 3:36 AM
‎2009 Aug 18 3:41 AM
thank you for the answers.
my internal table has the fields in this sequence
itab :-
vbeln
posnr
erdat
erzet
vkorg
vtweg
kunnr
matnr
bmeng
status.
1)so which select query i need to use in the above for this sequence either first or second, if so why not other
2) do i need to use the into corresponding fields addition because i am not using the fields bmeng and status and also in the first query the posnr in not in sequence to itab
‎2009 Aug 18 4:58 AM
Hi,
1. Use second query because select statement will always fill internal table in a sequence order in which fields have been declared.
2. For second query u do not need to use 'INTO CORRESPONDING FIELDS OF' because the field names in select query is in same sequence with internal table fields. Since 'bmeng' and 'status' fields is at the end it will affect the sequence.
'INTO CORRESPONDING FIELDS OF' is only used when sequence of field names in select query and internal table declaration differs. Otherwise type and length mismatch of fields will occur.
‎2009 Aug 18 5:04 AM
Hi,
Of the two select statements,
SELECT a~vbeln b~posnr a~erdat a~erzet a~vkorg a~vtweg
a~kunnr b~matnr
FROM vbak AS a INNER JOIN vbap AS b
ON a~vbeln = b~vbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
is the better one. I,e specifyiig the field sequence exactly as you have in the internal table. Even according to standards, this is better.
If you are chaning the sequence of select fields, then you have to use the INTO CORRESPONDING FILEDS OF TABLE addition, so that the system itself finds the relevant order of fields and fill them automatically.
This is a additional work which has to be performed by the compiler.
Thus its better to use INTO CORRESPONDING FILEDS OF TABLE only when you are using select * , or when you are not sure of the field sequence inthe table.
Regards,
Vik
‎2009 Aug 18 5:09 AM
Hi,
This will be good select query in accordance with performance and standard.
if not itab[] is initial.
SELECT avbeln bposnr aerdat aerzet
avkorg avtweg akunnr bmatnr
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE a~vbeln = itab-vbeln.
endif.
Regards,
Vijay
‎2009 Aug 18 6:21 AM
Hello,
You should always follow ABAP standard while coding. Select query should have all the fields in sequence as per the order defined in the database table. This will definetly help indexes to improve performance.
Hope this helps!
Thanks,
Augustin.