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

SELECT question.

Former Member
0 Likes
724

Hi people,

I don't have more choice to take out the selects from this loop. Now the question is if I insert the data of a select in a internal table when the loop is running like this:


LOOP AT t_regup INTO wa_regup .

    SELECT  usnam cpudt belnr stblg
     FROM bkpf INTO CORRESPONDING FIELDS OF table t_bkpf1
        WHERE belnr = wa_regup-belnr
        AND   bukrs = wa_regup-bukrs.

     SELECT znme1 lifnr laufd laufi zbukr hbkid   
                 waers zaldt
                 hktid vblnr chect zland rzawe uzawe voidr
      FROM payr INTO CORRESPONDING FIELDS OF table t_payr1
           WHERE  hbkid = wa_regup-hbkid
             AND  hktid = wa_regup-hktid
             AND  zbukr = wa_regup-zbukr
             AND  voidr = ''.

the lines are inserted line by line, so I don't need to use an append?, because I try to not use the 'ENDSELECT.' statement.

Thanks for the help.

8 REPLIES 8
Read only

suresh_datti
Active Contributor
0 Likes
695

Replace INTO with APPENDING in both the SELECT Statements. Otherwise, the itabs might be overwritten with each loop pass.

Regards,

Suresh Datti

Read only

abdul_hakim
Active Contributor
0 Likes
695

hi structure ur SELECT as follows for better performance..

IF NOT t_regup IS INITIAL.

SELECT usnam cpudt belnr stblg FROM bkpf INTO CORRESPONDING FIELDS OF table t_bkpf1

FOR ALL ENTRIES IN t_regup

WHERE belnr = t_regup -belnr AND

bukrs = t_regup -bukrs.

ENDIF.

IF NOT t_regup IS INITIAL.

SELECT znme1 lifnr laufd laufi zbukr hbkid waers zaldt hktid vblnr chect zland rzawe uzawe voidr FROM payr INTO CORRESPONDING FIELDS OF table t_payr1

FOR ALL ENTRIES IN t_regup

WHERE hbkid = t_regup -hbkid AND

hktid = t_regup -hktid AND

zbukr = t_regup -zbukr AND voidr = ''.

ENDIF.

Cheers,

Abdul Hakim

Read only

Former Member
0 Likes
695

Carlos,

There is no need to use an APPEND in your case. As you are populating an internal table in your select.

SELECT....ENDSELECT is like a loop and you have to use APPEND to add record to an internal table.

Hope this is what you have asked.

Thanks,

Read only

Former Member
0 Likes
695

So, if I replace the into by the append I don't need to use ENDSELECT statement right?

Read only

0 Likes
695

YES.

Suresh Datti

Read only

0 Likes
695

Yes...if you replace into with appending there is no need to use endselect.

Thanks,

Read only

0 Likes
695

hi

you could use my above logic to fetch the data from the tables in one shot and keep it in two internal tables and later you can loop thru the two tables based on the key fields and append it to the final table.this will improve ur performance a lot.if you place SELECT query in between LOOP and ENDLOOP it will affect your performance.

Plz check the performance tuning of ABAP programs under the knowledge pool portal http://help.sap.com

Cheers,

Abdul Hakim

Read only

Former Member
0 Likes
695

Before you make any changes, we should know your requirements. The code snippet you have shwon us will overwrite your internal table for each loop pass. That may be what you want if you are processing each line of t_regup individually; however, if you want to get all of your data up front and process it outside of the loop, then you need to do the FOR ALL ENTRIES as suggested by Abdul.

Rob

Message was edited by: Rob Burbank