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

logic- for required format output

Former Member
0 Likes
1,367

Hi,

I have a situation where material number has multiple entries(rows).

I required to show only single row output some of the respective material number quantity fields needs to be ADDED and some of the quantity should be same as a single row field value.

example :

following below code gives us output

<b>'Material' 'Quant1' 'Quant2'</b>

1000-A 10 999

1000-A 20 999

1000-B 10 700

1000-B 20 700

1000-B 30 700

but i need output in 2 lines only.

<b>'Material' 'Quant1' 'Quant2'</b>

1000-A 30 999

1000-B 60 700

i.e Quant1 values should be added and Quant2 values should remain same.

report x.

data: begin of itab occurs 0,

matnr(10) type c,

quant1(4) type c,

qunat2(4) type c,

end of itab.

itab-matnr = '1000-A'.

itab-quant1 = '10'.

itab-quant2 = '999'.

APPEND itab.

itab-matnr = '1000-A'.

itab-quant1 = '20'.

itab-quant2 = '999'.

APPEND itab.

itab-matnr = '1000-B'.

itab-quant1 = '10'.

itab-quant2 = '700'.

APPEND itab.

itab-matnr = '1000-B'.

itab-quant1 = '20'.

itab-quant2 = '700'.

APPEND itab.

itab-matnr = '1000-B'.

itab-quant1 = '30'.

itab-quant2 = '700'.

APPEND itab.

write : /10 'Material' , 30 'Quant1' , 45 'Quant2' .

loop at itab.

write : /10 itab-matnr , 30 itab-quant1 , 45 itab-quant2 .

endloop.

Any ideas?

Regards

Praveen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,306

Hi,

Please try this.


...
data: wa_itab like itab.

sort itab by matnr.

loop at itab.
  move itab to wa_itab.

  at end of matnr.
    sum.
    write : /10 wa_itab-matnr , 30 itab-quant1 , 45 itab-quant2 .
  endat.
endloop.

...

Regards,

Ferry Lianto

10 REPLIES 10
Read only

amit_khare
Active Contributor
0 Likes
1,306

When you are doing loop-Endloop use AT NEW and SUM for Quant1 field,

And display there only.

Regards,

Amit

Reward all helpful replies.

Read only

0 Likes
1,306

If i use AT NEW ... right hand side values are becomming ****** values.

regards

praveen

Read only

0 Likes
1,306

Yeah they will for that you have to store the values coming before the field used in At new in the variable and then pass it into the block.

that is if u r using 3rd field of the table in at new then pass 1st and 2nd using variables.

Regards,

Amit

Check reply from Suresh and change your Quant1 field to type quantity from character.

Message was edited by:

Amit Khare

Read only

0 Likes
1,306

Amit,

I am not getting you.

do you mind modifying my simple code and showing me output.

regards

praveen

Read only

0 Likes
1,306

tr this..

data:w_mat like itab-material, 
w_qt1 like itab-quant1,
w_qt2 like itab-quant2.
sort itab.
loop at itab.
w_qt1 = w_q1 + itab-quant1.
w_qt2 = itab-quant2.
at new itab-material.
write: / itab-material,w_qt1,w_qt2.
clear: w_qt1,w_qt2.
endat.
endloop.

~Suresh

Read only

0 Likes
1,306

Suersh,

with ur logic SUM value is not displaying correctly.

it is displaying 10 and 30 but my output required was 30 and 60.

regards

praveen

Read only

0 Likes
1,306

replace AT NEW with AT END OF in the code.. it should work..

~Suresh

Read only

0 Likes
1,306

Regards,

Amit

Read only

0 Likes
1,306

Ferry,

it resolved my issue with your logic.

thank you.

regards

praveen

Read only

Former Member
0 Likes
1,307

Hi,

Please try this.


...
data: wa_itab like itab.

sort itab by matnr.

loop at itab.
  move itab to wa_itab.

  at end of matnr.
    sum.
    write : /10 wa_itab-matnr , 30 itab-quant1 , 45 itab-quant2 .
  endat.
endloop.

...

Regards,

Ferry Lianto