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

Internal table looping

Former Member
0 Likes
656

Hi all,

I used the code

SELECT aufnr bwart SUM( erfmg ) INTO TABLE qty FROM mseg WHERE bwart = '101' OR bwart = '102' GROUP BY aufnr bwart.

and im getting the output like this

order no movementtype quantity

1000400 101 5

1000400 102 2

1000401 101 10

1000402 101 4

i want the another output like this

if the same order no has both the movement type 101, 102

it should subtract the value

ie.

order no quantity

1000400 3 ( 5 - 2 )

otherwise if it has only one movement type 101

i should get

order no quantity

1000401 10

the over all output should be

order no quantity

1000400 3

1000401 10

1000402 4

Please send me the logic coding for this

Thanks,

Azhar

6 REPLIES 6
Read only

Former Member
0 Likes
616

you should use control break command

AT NEW <ORDER NO.>

then u need to have logic of substraction of the movements

then write statement.

ENDAT.

PLZ REWARD IF USEFUL

regards

vivek

Read only

abdulazeez12
Active Contributor
0 Likes
616

Hi Azhar

loop at itab.

at first.

gv_orderno = itab-orderno.

gv_quantity = itab-quantity.

endat.

at new movementtype.

if itab-orderno. = gv_orderno.

itab1-quantity = itab-quantity-gv_quantity.

itab1-movementtype = itab-movementtype.

itab1-orderno. = itab-orderno.

append itab1.

endat.

clear gv_orderno., quantity.

gv_orderno = itab-orderno.

gv_quantity = itab-quantity.

endloop.

I dont know if this code helps..pls try this way..iam in a hurry..best of luck mate..

Cheers

Shakir

Read only

Former Member
0 Likes
616

Hi,

Follow this thread

Regards,

Satish

Read only

Former Member
0 Likes
616

declare 2 variables a(1) type c,b like menge.

sort qty by aufnr bwart.

loop at qty.

at end of bwart. "(means at end of aufnr bwart combi)

if a = 'X'.

move qty-menge to b.

else.

subtract b from qty-menge.

endif.

endat.

at new aufnr.

clear: a,b.

endat.

modift qty.

endloop.

Read only

Former Member
0 Likes
616

AZAR,

For Ex :

You have internal table itab having the below records.

order no movementtype quantity

1000400 101 5

1000400 102 2

1000401 101 10

1000402 101 4

DATA : v_num type i ,

v_char

SORT itab BY order no movementtype decending.

LOOP AT itab.

v_num = v_num + 1.

IF v_num > 1.

ON CHANGE OF itab-order no.

v_char = 'X'.

ENDON.

ENDIF.

ENDLOOP.

IF v_char NE 'X'.

itab-order no = v_num -itab-order no.

MODIFY itab transporting order no.

ENDIF.

Don't forget to reward if useful.....

Read only

Former Member
0 Likes
616

Hi,

The requirement can be done using Conrol statements only. Initialy get the data from MSEG table into internal table (itab) and use control statement.

Check the below logic:

SELECT aufnr bwart erfmg INTO TABLE itab FROM mseg WHERE bwart = '101' OR bwart = '102' .

Sort itab BY aufnr bwart.

Loop at itab.

AT NEW bwart.

If itab-bwart = :101:.

sum = sum + itab-erfmg.

else.

sum = sum - itab-erfmg.

endif.

END AT.

AT END OF aufnr.

itab1-aufnr = itab-aufnr.

itab1-qty = sum.

Append itab1.

Clear: itab1, sum.

ENDAT.

Endloop.