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

regarding select statement

Former Member
0 Likes
1,122

can i put select statement into the loop statement

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,100

Hi rajesh

we can use loop in select statement

as follows


LOOP AT ITAB.
SELECT * FROM ZPAVAN_EMP INTO CORRESPONDING FIELDS OF ITAB.

            APPEND ITAB.

            ENDSELECT.

 



            WRITE : / ITAB-EMPNO, ITAB-EMPNAME,ITAB-DEPTNO.

            ENDLOOP.

but it was not advisable it may lead to problem in SAP system so u plz follow this


SELECT * FROM ZPAVAN_EMP INTO CORRESPONDING FIELDS OF ITAB.

            APPEND ITAB.

            ENDSELECT.

 

            LOOP AT ITAB.

            WRITE : / ITAB-EMPNO, ITAB-EMPNAME,ITAB-DEPTNO.

            ENDLOOP.

Rewards if helpfull

Regards

Pavan

12 REPLIES 12
Read only

Former Member
0 Likes
1,100

technically, yes you can.

It may not be always gud from performance perspective.

You can fetch all the data into internal table at once.

Or you can use FOR ALL ENTRIES.

Read only

Former Member
0 Likes
1,100

hi,

yes,u can

Read only

Former Member
0 Likes
1,100

Hi,

Yes, but its never adviced...

As it reduces the performance

Regards,

pritha

Read only

Former Member
0 Likes
1,100

Hi,

You can do but its not advisable. As an alternative you can use read statement inside the loop.

Regards,

Ram

Read only

Former Member
0 Likes
1,100

No, u shud not.

Regards

Kannaiah

Read only

Former Member
0 Likes
1,100

yes you can use but it may affect your performance . better to use for all entries statement with different itab.

reagrds

shiba dutta

Read only

Former Member
0 Likes
1,100

Ya why not

Loop at <itab>

select single ..

select...

endloop.

Read only

0 Likes
1,100

can u send me one example code

with steps

Read only

Former Member
0 Likes
1,100

hi,

u can loop at read statement.

here is an example,

LOOP AT IT_VBAP INTO WA_VBAP.

READ TABLE IT_VBAK INTO WA_VBAK WITH KEY VBELN = WA_VBAP-VBELN BINARY SEARCH.

IF SY-SUBRC = 0.

*MOVE DATA INTO IT_FINAL.

MOVE: WA_VBAK-VBELN TO WA_FINAL-VBELN,

WA_VBAK-AUGRU TO WA_FINAL-AUGRU,

WA_VBAP-POSNR TO WA_FINAL-POSNR,

WA_VBAP-MATNR TO WA_FINAL-MATNR,

WA_VBAP-ZMENG TO WA_FINAL-ZMENG.

ENDIF.

endloop.

Regards,

pritha

Message was edited by:

Pritha Agrawal

Read only

Former Member
0 Likes
1,101

Hi rajesh

we can use loop in select statement

as follows


LOOP AT ITAB.
SELECT * FROM ZPAVAN_EMP INTO CORRESPONDING FIELDS OF ITAB.

            APPEND ITAB.

            ENDSELECT.

 



            WRITE : / ITAB-EMPNO, ITAB-EMPNAME,ITAB-DEPTNO.

            ENDLOOP.

but it was not advisable it may lead to problem in SAP system so u plz follow this


SELECT * FROM ZPAVAN_EMP INTO CORRESPONDING FIELDS OF ITAB.

            APPEND ITAB.

            ENDSELECT.

 

            LOOP AT ITAB.

            WRITE : / ITAB-EMPNO, ITAB-EMPNAME,ITAB-DEPTNO.

            ENDLOOP.

Rewards if helpfull

Regards

Pavan

Read only

Former Member
0 Likes
1,100

hi,

We should try to avoid writing select statements inside the loop.It decreases the performance of the program as it hits the database as many times you are looping.You can select the data from database table outside the loop and read those tables indide the loop.

instead of this use FORALL ENTRIES.

SELECT * FROM BSAK INTO TABLE T_IBSAK

FOR ALL ENTRIES IN T_IAUG

WHERE BUKRS = T_IAUG-BUKRS

AND AUGDT = T_IAUG-AUGDT

AND AUGBL = T_IAUG-AUGBL

regards

null

Read only

Former Member
0 Likes
1,100

yeah u can but it effects the performance .

so it is better to go for other options