cancel
Showing results for 
Search instead for 
Did you mean: 

Re:for all entries

Former Member
0 Kudos

I wrote the code like is this correct is it is code is correct , i am not using the is initial statement before using the for all entries statement but it will show the same results, in this code any mistakes can any one plz modify and give the correct code. THANKS in Advance

DATA : BEGIN OF i_sales OCCURS 5,

vbeln LIKE vbak-vbeln,

erdat LIKE vbak-erdat,

netwr LIKE vbak-netwr,

END OF i_sales.

DATA: BEGIN OF itab OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

END OF itab.

SELECT-OPTIONS sno FOR i_sales-vbeln.

SELECT vbeln

erdat

netwr

INTO TABLE i_sales

FROM vbak

where vbeln in sno.

*LOOP AT i_sales.

  • WRITE:/ i_sales-vbeln,i_sales-erdat,i_sales-netwr.

*ENDLOOP.

select vbeln

posnr

matnr

INTO TABLE itab

FROM vbap

FOR ALL ENTRIES IN i_sales

WHERE vbeln = i_sales-vbeln.

LOOP AT itab.

WRITE:/ itab-vbeln,itab-posnr,itab-matnr.

ENDLOOP.

Accepted Solutions (1)

Accepted Solutions (1)

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

It is mandatory to check the driver table is initial or not before using FOR ALL ENTRIES. Other wise it will select all the data from the table VBAP.

In ur case it might worked because VBAP(Item table) will contain records only if VBAK(header table) has a record.

U can check ur results by making i_sales table empty. i.e. in selection screen give some wrong sales order numbers which doesn't exist in VBAK table and check ur result.

Check below the effective way of coding.

SELECT vbeln

erdat

netwr

INTO TABLE i_sales

FROM vbak

where vbeln in sno.

*LOOP AT i_sales.

WRITE:/ i_sales-vbeln,i_sales-erdat,i_sales-netwr.

*ENDLOOP.

i_salestemp[] = i_sales[].

SORT i_salestemp BY VBELN.

DELETE ADJACENT DUPLICATES FROM i_sales COMPARING vbeln.

CHECK NOT i_salestemp[] IS INITIAL.

select vbeln

posnr

matnr

INTO TABLE itab

FROM vbap

FOR ALL ENTRIES IN i_salestemp

WHERE vbeln = i_salestemp-vbeln.

LOOP AT itab.

WRITE:/ itab-vbeln,itab-posnr,itab-matnr.

ENDLOOP.

Thanks,

Vinod.

Edited by: Vinod Vemuru on Feb 29, 2008 7:22 PM

Answers (0)