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

Optimizing an SQL Select Statement

walkerist79
Participant
0 Likes
1,434

Irrelevant question

6 REPLIES 6
Read only

former_member808116
Participant
0 Likes
1,320

Hello walkerist. I found a question similar to yours on SAP Question. Check out the link below.

Selecting single value using for all entries. | SAP Community

Read only

Sandra_Rossi
Active Contributor
1,320

SINGLE must not be used with FOR ALL ENTRIES. Just store the result into an internal table. I guess storing into an internal table will have much less performance impact than using FOR ALL ENTRIES.

Read only

venkateswaran_k
Active Contributor
1,320

Hi

In both the cases, INTO clause is missing. Please review.

Read only

walkerist79
Participant
0 Likes
1,320

Thanks sandra.rossi and venkateswaran.k however, I'm experiencing another error which is "LT_MCH1" is a table without a header line and therefore does not have a component called "VFDAT".

this is my code:

 DATA: lt_mch1 TYPE STANDARD TABLE OF mch1.
IF tvbdpr IS NOT INITIAL.
SELECT *
FROM mch1
FOR ALL ENTRIES IN @tvbdpr
WHERE matnr = @tvbdpr-matnr
AND charg = @tvbdpr-charg
INTO CORRESPONDING FIELDS OF TABLE @lt_mch1.
IF sy-subrc = 0.
l_mat_exp = lt_mch1-vfdat.
ENDIF.
ENDIF.
Read only

walkerist79
Participant
0 Likes
1,320

Tried adding temporary line "with header line" for the mean time

 DATA: t_mch1 TYPE STANDARD TABLE OF mch1 with header line.

Also, the selection is successfull and the t_mch1 is being populated. However the t_mch1-vfdat fetches 0000000 instead of the correct date. Why is that?

   SELECT vfdat
FROM mch1
FOR ALL ENTRIES IN @tvbdpr
WHERE matnr = @tvbdpr-matnr
AND charg = @tvbdpr-charg
INTO CORRESPONDING FIELDS OF TABLE @t_mch1.
IF sy-subrc = 0.
l_mat_exp = t_mch1-vfdat.
ENDIF.
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,320

Header lines are prone to errors, and so were made obsolete, two reason to not used them.

T_MCH1 is an internal table, you must read the line which you're interested in (READ TABLE as you seem to use old ways of programming / better use Table Expressions instead).