Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

fields sequence in the select statement

Former Member
0 Likes
2,807

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?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,614

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

7 REPLIES 7
Read only

SG141
Active Participant
0 Likes
1,614

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.

Read only

daixiong_jiang3
Active Participant
0 Likes
1,614

The second one is right and can have a better performance.

Read only

Former Member
0 Likes
1,615

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

Read only

1,614

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.

Read only

Former Member
0 Likes
1,614

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

Read only

Former Member
0 Likes
1,614

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

Read only

Former Member
0 Likes
1,614

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.