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

avoiding loop within select statements

Former Member
0 Likes
550

Hi all,

Below i m providing my code where we are looping in between two select statements , but i dont want to use loop in between two select statements so can anyone give any other way of approach.

<code>

SELECT a~vbeln

a~erdat

a~erzet

a~auart

b~posnr

b~matnr

b~kwmeng

FROM vbak AS a INNER JOIN vbap AS b

ON amandt = bmandt

AND avbeln = bvbeln

INTO TABLE it_orders.

*append lines of it_orders-vbeln to it_vbeln-vbeln.

*append lines of it_orders to it_vbeln.

LOOP AT it_orders.

CLEAR it_vbeln.

it_vbeln-vbeln = it_orders-vbeln.

APPEND it_vbeln.

ENDLOOP.

IF NOT it_vbeln[] IS INITIAL.

SELECT objky

kschl

FROM nast

INTO TABLE it_nast

FOR ALL ENTRIES IN it_vbeln

WHERE objky = it_vbeln-vbeln.

ENDIF.

</code>

thanks,

satish

4 REPLIES 4
Read only

Former Member
0 Likes
531

Hi,

The loop which you are using is not WITHIN the select statement.

ie ... It is not executing within the select statement.

So it should not cause any kind of performance issues.

What exactly is the problem which you are facing ?

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
531

Hi,

SELECT a~vbeln

FROM vbak AS a INNER JOIN vbap AS b

ON amandt = bmandt

AND avbeln = bvbeln

INTO TABLE it_vbeln.

try this...

Read only

Former Member
0 Likes
531

Satish,

There is enough of your code missing that makes this a bit difficult to debug.

Like:

Is this code being performed from somewhere else?

How are the tables defined?

If the tables are defined like this,

DATA:

BEGIN OF vbeln_rec,

vbeln LIKE nast-objky,

END OF vbeln_rec,

it_vbeln LIKE vbeln_rec OCCURS 0 WITH HEADER LINE.

it is possible, that you need to refresh the table like this:

**append lines of it_orders-vbeln to it_vbeln-vbeln.

**append lines of it_orders to it_vbeln.

refresh: it_vbeln.

LOOP AT it_orders.

CLEAR it_vbeln.

it_vbeln-vbeln = it_orders-vbeln.

APPEND it_vbeln.

ENDLOOP.

Edited by: Paul Chapman on Mar 10, 2008 1:35 PM

Read only

Former Member
0 Likes
531

SELECT a~vbeln
       a~erdat
      a~erzet
      a~auart
      b~posnr
      b~matnr
      b~kwmeng
FROM vbak AS a INNER JOIN vbap AS b
ON a~mandt = b~mandt
AND a~vbeln = b~vbeln
INTO TABLE it_orders.

*append lines of it_orders-vbeln to it_vbeln-vbeln.
*append lines of it_orders to it_vbeln.

*LOOP AT it_orders.
*CLEAR it_vbeln.
*it_vbeln-vbeln = it_orders-vbeln.
*APPEND it_vbeln.
*ENDLOOP.
*
"Your final table is it_nast. 
"My doubt is why your filling it_vbeln in between???
"instead of  it_vbeln why can't you use it_orders???.

IF NOT it_orders[] IS INITIAL.
SELECT objky
             kschl
FROM nast
INTO TABLE it_nast
FOR ALL ENTRIES IN it_odrers
WHERE objky = it_orders-vbeln.
ENDIF.