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

Totals Problem

Former Member
0 Likes
1,001

Hi,

I have a table with several cols the 2 key are Quarter and COB ( class of business) I want to have a third col total by end of Quarter and end of COB. If I use AT END of Quarter it will only sum for the quarter. Is it possible to do something like

AT END OF quarter

AT END OF COB

SUM

.....

.....

....

END AT

END AT

Or is this going to have to be done manually?

Thanks,

George

1 ACCEPTED SOLUTION
Read only

former_member491305
Active Contributor
0 Likes
971

Hi George,

data:begin of wa_1,

quarter(10) type c,

COB(5) type n,

tot type i,

end of wa_1,

itab1 like standard table of wa_1.

Loop at itab1 into wa_1.

wa_2 = wa_1.

At end of COB.

sum.

wa2-tot = wa_1-tot.

append wa2 to itab2.

ENDAT.

endloop.

This above code will sum up based on both Quarter and COB.Meaning that even if any one of the field*quarter or COB) changes,the Block of statment beteween AT and ENDAT will be executed.

For eg:ITAB1

Quarter COB tot

-


A1011 340 2

A1011 340 3

A1011 341 11

A1012 341 6

O/P:ITAB2

Quarter COB tot

-


A1011 340 5

A1011 341 11

A1012 341 6

Regards,

Vigneswaran S

8 REPLIES 8
Read only

Former Member
0 Likes
971

Yes, you can nest the AT..ENDATs.

Read only

former_member491305
Active Contributor
0 Likes
972

Hi George,

data:begin of wa_1,

quarter(10) type c,

COB(5) type n,

tot type i,

end of wa_1,

itab1 like standard table of wa_1.

Loop at itab1 into wa_1.

wa_2 = wa_1.

At end of COB.

sum.

wa2-tot = wa_1-tot.

append wa2 to itab2.

ENDAT.

endloop.

This above code will sum up based on both Quarter and COB.Meaning that even if any one of the field*quarter or COB) changes,the Block of statment beteween AT and ENDAT will be executed.

For eg:ITAB1

Quarter COB tot

-


A1011 340 2

A1011 340 3

A1011 341 11

A1012 341 6

O/P:ITAB2

Quarter COB tot

-


A1011 340 5

A1011 341 11

A1012 341 6

Regards,

Vigneswaran S

Read only

0 Likes
971

Thanks for the replies, not sure if that is the answer though

Let's say for instance the data is like this

QTR COB Price

1 22 70.00

1 22 30.00

1 36 50.00

1 36 10.00

2 22 25.00

I would want totals like

Qtr COB Price

1 22 100.00

1 36 60.00

2 22 25.00

I tried the above code but it did not return the needed result

This is a fairly urgent matter so all input is appreciated

Read only

0 Likes
971

Hi,

Can u paste ur code here along with the itab declaration here?.Because the one which i shown in the Eg.is similar as the one which u have shown here.It will give the same result.

Read only

0 Likes
971

Hi,

Loop at itab.
At end of COB.
sum.
 write: / ITAB_data-qtr,
           ITAB_data-cob,
           ITAB_data-price.
ENDAT.
endloop.

Please reward points if it helps

Thanks

Vikranth

Read only

0 Likes
971

Here is what I have

TYPES: BEGIN OF ST_COLL_1,

QTR(2) TYPE N,

BRCHNR LIKE /MSG/RD_ABR_BU-BRCHNR, "COB

ABRNR LIKE /MSG/RD_ABR_BU-ABRNR,

ZJJ LIKE /MSG/RD_ABR_BU-ZJJ,

BIL_PERIOD LIKE /MSG/RD_ABR_BU-BIL_PERIOD,

BIL_DAT LIKE /MSG/RD_ABR_BU-BIL_DAT,

BUCONR LIKE /MSG/RD_ABR_BU-BUCONR,

OW_BETR LIKE /MSG/RD_ABR_BU-OW_BETR,

END OF ST_COLL_1.

DATA: T_COLL_1 TYPE ST_COLL_1 OCCURS 0,

WA_T_CO LIKE LINE OF T_COLL_1.

qtr_tot1 = 0.

qtr_tot2 = 0.

qtr_tot3 = 0.

LOOP AT t_coll_1 INTO wa_t_co.

AT END OF qtr.

SUM.

qtr_tot1 = qtr_tot1 + wa_t_co-ow_betr.

qtr_tot2 = qtr_tot2 + wa_t_co-ow_betr2.

qtr_tot3 = qtr_tot3 + wa_t_co-ow_betr3.

MOVE wa_t_co-qtr TO wa_t_cal-qtr.

MOVE qtr_tot1 TO wa_t_cal-earnprem.

MOVE qtr_tot2 TO wa_t_cal-paidloss.

MOVE qtr_tot3 TO wa_t_cal-oslr.

APPEND wa_t_cal TO t_yr_calc.

ENDAT.

ENDLOOP.

This is when I was just totaling by Quarter and it works fine, however I now need it to total by Quarter and Brchnr

Read only

0 Likes
971

Hi George,

THe summation will be done by system itself.You dont have to do it your program.

One more thing.You have to use at end of BRCHNR instead of At ENd of QTR ,if u want to have a sum based on both these fields.

Chk out this.

LOOP AT t_coll_1 INTO wa_t_co.

AT END OF BRCHNR.

SUM.

MOVE wa_t_co-qtr TO wa_t_cal-qtr.

MOVE wa_t_co-ow_betr TO wa_t_cal-earnprem.

MOVE wa_t_co-ow_betr2 TO wa_t_cal-paidloss.

MOVE wa_t_co-ow_betrTO wa_t_cal-oslr.

APPEND wa_t_cal TO t_yr_calc.

ENDAT.ENDLOOP.

Regards,

Vigneswaran S

Read only

Former Member
0 Likes
971

HI,

you do not need the AT END OF QTR, the AT END OF statement uses all fields before and with the field specified as the key. The below exapme gives the result you want:


data: begin of gs_data,
        qtr(1) type n,
        cob(2) type n,
        price type p,
      end of gs_data,
      gt_data like Standard TABLE OF gs_data.

start-of-selection.

  gs_data-qtr = '1'.
  gs_data-cob = '22'.
  gs_data-price = '70.00'.
  append gs_data to gt_data.
  gs_data-qtr = '1'.
  gs_data-cob = '22'.
  gs_data-price = '30.00'.
  append gs_data to gt_data.
  gs_data-qtr = '1'.
  gs_data-cob = '36'.
  gs_data-price = '50.00'.
  append gs_data to gt_data.
  gs_data-qtr = '1'.
  gs_data-cob = '36'.
  gs_data-price = '10.00'.
  append gs_data to gt_data.
  gs_data-qtr = '2'.
  gs_data-cob = '22'.
  gs_data-price = '25.00'.
  append gs_data to gt_data.

 loop at gt_data into gs_data.
   at end of cob.
     sum.
     write: / gs_data-qtr,
              gs_data-cob,
              gs_data-price.
   endat.
 endloop.

Hope this helps,

Gert