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

REPORT

Former Member
0 Likes
508

Hi Frields,

I need to avoid select statements under loop statements. what should i do for avoiding this.

see the fallowing code insted of writing select stmt what should i do?

LOOP AT g_t_DETREP.

RESERVE 4 LINES.

SELECT SINGLE * FROM VBFA WHERE VBELN = g_t_DETREP-BILLDOC

AND VBTYP_V = 'J'.

SELECT SINGLE * FROM LIKP WHERE VBELN = VBFA-VBELV

AND VSTEL IN S_VSTEL.

CHECK SY-SUBRC EQ 0.

FORMAT COLOR COL_NORMAL.

WRITE : / g_t_DETREP-CUSTNO,

12(25) g_t_DETREP-CUSTNAME,

39 g_t_DETREP-SOFF,

43 g_t_DETREP-SGRP,

48 g_t_DETREP-PLANT,

54 LIKP-VSTEL,

60 g_t_DETREP-PONUM,

82 g_t_DETREP-BILLDATE,

95 g_t_DETREP-BILLDOC,

108 g_t_DETREP-MATNO,

130(25) g_t_DETREP-MATDESC,

160 g_t_DETREP-QTY,

178 g_t_DETREP-CURRY,

183 g_t_DETREP-DOCAMT,

205 g_t_DETREP-AMOUNT,

227 g_t_DETREP-MODETP,

231 g_t_DETREP-TRUCK,

242(10) g_t_DETREP-AVEAMT DECIMALS 4,

(3) g_t_DETREP-RFBSK.

"156 g_t_DETREP-uom,

IF g_t_DETREP-RFBSK NE SPACE.

DELETE g_t_DETREP.

ENDIF.

Endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
481

Hi,

Use For all entries.

Regards,

Balavardhan.K

Read only

0 Likes
481

LOOP AT g_t_DETREP.

RESERVE 4 LINES.

SELECT SINGLE * FROM VBFA

<b>FOR ALL ENTRIES IN g_t_DETREP</b>

WHERE

VBELN = g_t_DETREP-BILLDOC

AND VBTYP_V = 'J'.

..

..

Read only

Former Member
0 Likes
481

Hello Srinivas,

You can rewrite the select statements as follows.

Have these two data statements in the beginning

Data: it_vbfa TYPE TABLE OF VBFA.

Data:it_likp TYPE TABLE OF LIKP.

Then write the select statements as

SELECT * INTO CORRESPONDING FIELDS OF TABLE it_vbfa FROM VBFA FOR ALL ENTRIES IN g_t_DETREP WHERE VBELN = g_t_DETREP-BILLDOC

AND VBTYP_V = 'J'.

SELECT * INTO CORRESPONDING FIELDS OF TABLE it_likp FROM LIKP FOR ALL ENTRIES IN it_vbfa WHERE VBELN = it_vbfa-VBELV

AND VSTEL IN S_VSTEL.

You can put these statements outside the loop.

Please award points if helpful.

Avisesh

Read only

Former Member
0 Likes
481

> Hi Frields,

>

> I need to avoid select statements under loop

> statements. what should i do for avoiding this.

>

> see the fallowing code insted of writing select stmt

> what should i do?

>

> LOOP AT g_t_DETREP.

>

> RESERVE 4 LINES.

>

> SELECT SINGLE * FROM VBFA WHERE VBELN =

> g_t_DETREP-BILLDOC

> AND VBTYP_V = 'J'.

> SELECT SINGLE * FROM LIKP WHERE VBELN = VBFA-VBELV

> AND VSTEL IN S_VSTEL.

> WHERE VBELN = VBFA-VBELV

> AND VSTEL IN S_VSTEL.

>

Hello!

Before loop you can select all necessary data from VBFA and LIKP using for all entries like this:

select * from vbfa into table tab_vbfa for all entries in g_t_detrep where VBELN = g_t_DETREP-BILLDOC AND VBTYP_V = 'J'.

here tab_vbfa is a table of vbfa structure

After this you can use read with key statement in the loop to get selected data without actual select under loop.

Read only

Former Member
0 Likes
481

Dear Rao,

(1) Initially populate the internal tables --> g_t_DETREP

--> IT_VBFA where VBTYP_V = 'J'.

--> IT_LIKP

(2) Sort the tables.

(3) Then while Looping through g_t_DETREP,

LOOP AT G_T_DETREP.

READ TABLE IT_VBFA INTO WA_VBFA

WITH KEY VBELN = g_t_DETREP-BILLDOC

if sy-subrc eq 0.

  • Store it for future use !!!!!!!!!

-


GV_STORE_1 = WA_VBFA-VBELV

endif.

Similary do it for your LIKP --> WITH KEY VBELN = GV_STORE_1

ENDLOOP.

Regards,

Abir

***********************************

  • Don't forget to award Points *

Read only

Former Member
0 Likes
481

hi srinivas

try like this

take one internal tables for vbfa and likp with required fields.

select all requied fields from vbfa and likp using for entires of table g_t_detrep.