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

itab problem

Former Member
0 Likes
725

Hi experts,

I have itab like this/


 GSBER  AMT1    AMT2
 8003 7,450.52 7,450.52 
 8003 8,166.40 8,166.40 
 8007 7,630.20 7,630.20 
 8007 6,510.80 6,510.80 
                        

Iam trying to collect like this.

loop at itab.

move-corresponding itab to itab2.

collect itab2.

endloop.

Why it is not summing AMT1 & AMT2?

thanks

kaki

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
710

plz see for the type of your fields. Only numeric components( i, p , f) are added in collect statement.

plz do some work with data type of ur variables...ur work ll be done..

regards.

7 REPLIES 7
Read only

Former Member
0 Likes
711

plz see for the type of your fields. Only numeric components( i, p , f) are added in collect statement.

plz do some work with data type of ur variables...ur work ll be done..

regards.

Read only

Former Member
0 Likes
710

Is your data type a Packed number?

Check this code... It works with data type p.

DATA: BEGIN OF itab OCCURS 0,
  gsber(10),
  amt TYPE p DECIMALS 2,
  amt2 TYPE p DECIMALS 2,
END OF itab.
DATA itab1 LIKE TABLE OF itab WITH HEADER LINE.
itab-gsber = '1'.
itab-amt = '100.23'.
itab-amt2 = '100.23'.
APPEND itab.
APPEND itab.
APPEND itab.

itab-gsber = '2'.
itab-amt = '10.23'.
itab-amt2 = '100.23'.
APPEND itab.
APPEND itab.
APPEND itab.

LOOP At itab.
move-corresponding itab to itab1.
collect itab1.
ENDLOOP.
WRITE : 'f'.

Read only

Former Member
0 Likes
710

Hi Kaki,

Check whether the field declaration of both AMT1 & AMT2 are declared with same data type i.e,( i,N ) ...

Regards,

Santosh P

Read only

Former Member
0 Likes
710

hi Kaki,

REPORT  ZTEST.

data: begin of itab occurs 0,
       gsber type gsber,
       amt1 type p decimals 2,
       amt2 type p decimals 2,
      end of itab.
data: itab2 like itab occurs 0 with header line.
      itab-GSBER = '8003'.
      itab-AMT1  = '8166.40'.
      itab-AMT2  = '8166.40'.
      append itab.

            itab-GSBER = '8003'.
      itab-AMT1  = '7450.52'.
      itab-AMT2  = '7450.52' .
      append itab.

            itab-GSBER = '8007'.
      itab-AMT1  = '7630.20'.
      itab-AMT2  = '7630.20'.
      append itab.

            itab-GSBER = '8007'.
      itab-AMT1  = '6510.80'.
      itab-AMT2  = '6510.80'.
      append itab.
clear itab.
sort itab by gsber.
loop at itab.
move-corresponding itab to itab2.
collect itab2.

endloop.

break-point.

Regards

vijay

Read only

Former Member
0 Likes
710

hi Kaki,

I hope it is a currency field..

i think the currency field will not be added when you use collect..

if you want to add when you append you can do like this..

data : itab1_wa like line of itab.
.....
loop at itab.
move itab to itab1_wa.
itab1_wa-amt1 = itab1-amt1 + itab1_wa-amt1.
itab1_wa-amt2 = itab1-amt2 + itab1_wa-amt2.
itab1 = itab1_wa.
append itab1.
endloop.

regards

satesh

Read only

abdul_hakim
Active Contributor
0 Likes
710

Hi Kaki,

COLLECT will only work with number type fields(I,P,F).

Regards,

Abdul Hakim

Read only

Former Member
0 Likes
710

Hi kaki,

1. Make sure the FIELD-NAMES

AMT1, AMT2, GSBER

are same in ITAB2. (same like itab1)

2. Instead of trying with COLLECT,

just use APPEND to see

if ITAB2 really gets the data or not !

regards,

amit m.