Application Development 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: 

code with minimal loops

Former Member
0 Kudos
79

Hi,

i have a requirement to process two internal tables in which i should update these two internal tables based on the conditions and for your convenience i'm describing the scenario in detail below.

1.batchquantity

plant|material|storageloc|batchqty|shelfexp.date|orderqty|

-


00100|10000000|0000000010|00000100|02/06/2009___|___0____|

00100|10000000|0000000010|00000150|02/06/2003___|___0____|

00100|10000000|0000000010|00000500|02/06/2010___|___10___|

2.orderqty

plant|material|storageloc|orderqty|goodsiss.date|

-


00100|10000000|0000000010|00000150|02/06/2008___|

00100|10000000|0000000010|00000300|02/06/2001___|

my requirment is that for orderqty-goodsiss.date < batchqty-shelfexpdate,

i need to distribute the orderqty in orderqty table to orderqty in batchquantity table

based on plant, material, storage loc... and the orderqty in batchqty table should not exceed batchqty in the same table

the result would be as follows in batchqty table( orderqty increased since the date condition matched and cannot go beyond the batchqty)

plant|material|storageloc|batchqty|shelfexp.date|orderqty|

-


00100|10000000|0000000010|00000100|02/06/2009___|___100__| <---

00100|10000000|0000000010|00000150|02/06/2003___|___0____|

00100|10000000|0000000010|00000500|02/06/2010___|___60___| <---

and orderqty would be ( the orderqty reduced since it got into batchqty tab)

plant|material|storageloc|orderqty|goodsiss.date|

-


00100|10000000|0000000010|00000000|02/06/2008___| <----

00100|10000000|0000000010|00000300|02/06/2001___|

There might be several thousand records in both the tables, how to update the batchqty table

with minimum loops.

Thanks,

ravi.

4 REPLIES 4

Former Member
0 Kudos
63

The best method to me seems to loop at the batch quantity table and read from the order qty table.

On the other hand, since both the itabs are created for the Plant/material/Sloc combination, would it not be easier to combine the two itabs and filter out the data, instead of trying to merge two differnt itabs?

Sudha

Former Member
0 Kudos
63

HI Ravi kumar

you have cant use loop at order quantity and read in batch quantity.

because the batchqtu has multiple values for one orderqty

so you have to use two loop statements.

loop at orderqty.

loop at batchqty where plant eq orderqty-plant and material eq orderqty-material and storageloc eq orderqty-storageloc and shelfexpdate lt goodissdate.

<your logic>

endloop.

endloop.

regards

kishore

Former Member
0 Kudos
63

hi ravi ,

proceed like this ..

1. u said (order qty vs batch qty) should not exceed

means to say order qty (max value) in batchqty table is the batch qty in the same table .

here1. loop at batchaty.

if batchqty-orderqty > batchqty-batchqty .

delete table entries from batch batchqty .

endif.

endloop.

now sort batchqty/orderqty based on the plant etc etc..

2.

loop at batchqty

read table batchqty with key plant = orderqty-plant

mat = orderqty-mat

location = orderqty-location

if sy-subrc = 0.

if ordqty-GIdate < batchqty-EXPdate.

| if itordqty-orderqty > itbatchqty-batqty.

| itbatchqty-ordqty = itbatchqty-batchqty

| else.

| itbatchqty-ordqty = itorderqty-orderqty.

| endif.

endif.

move it it_ordqty to itbatcqty-ordqty.

append itbatchqty or modify itbatchqty index cntr .

endif.

endloop.

if ur trying to modify the existing table tbatchqty then proceed with a cntr varaible as this may involve items also .

cntr = sy-tabix.

modify table itbatchqty index cntr.

_____________________________________________________

vijay

Former Member
0 Kudos
63

I know I sound like a broken record, but have a look at this <a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops

Rob