Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ABAP AT END OF Statement issue

Hi,

I have a report with selection screen year(ls_nd_year) & period (ls_nd_period)

internal table it_cosp has following values

costelemnt	year    period1 period2  period3....... 							period 12

0000540000	2009	6	7	80	9	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00
0000540000	2009	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	77.00
0000541000	2009	10	20	30	40	80	0.00	0.00	0.00	0.00	0.00	0.00	0.00
0000541000	2008	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	0.00	77.00

My requirement is whenever user enters current year say for eg: 2009 it should also add per costcenter previuos years values

for eg:

if user enters: year: 2009 & period : 05 ---it should add 2009 -1020304080+ 2008 -77

if user enters : year :2008 & period :12 ---it should just add 2008 period 12- value : 77.00

As of now this is truncating 2008 values.. how do i handle this? also Each costelment may have single entry for year or multiple years

I am using following code to sum it up.

SORT it_cosp by KSTAR.
LOOP AT it_cosp INTO wa_cosp  .

       
          wa1_cosp-wtg001 = wa1_cosp-wtg001 + wa_cosp-wtg001 .
          wa1_cosp-wtg002 = wa1_cosp-wtg002 + wa_cosp-wtg002 .
          wa1_cosp-wtg003 = wa1_cosp-wtg003 + wa_cosp-wtg003 .
          wa1_cosp-wtg004 = wa1_cosp-wtg004 + wa_cosp-wtg004 .
          wa1_cosp-wtg005 = wa1_cosp-wtg005 + wa_cosp-wtg005 .
          wa1_cosp-wtg006 = wa1_cosp-wtg006 + wa_cosp-wtg006 .
          wa1_cosp-wtg007 = wa1_cosp-wtg007 + wa_cosp-wtg007 .
          wa1_cosp-wtg008 = wa1_cosp-wtg008 + wa_cosp-wtg008 .
          wa1_cosp-wtg009 = wa1_cosp-wtg009 + wa_cosp-wtg009 .
          wa1_cosp-wtg010 = wa1_cosp-wtg010 + wa_cosp-wtg010 .
          wa1_cosp-wtg011 = wa1_cosp-wtg011 + wa_cosp-wtg011 .
          wa1_cosp-wtg012 = wa1_cosp-wtg012 + wa_cosp-wtg012 .

          AT END OF kstar.
            ULINE.
            WRITE: / wa1_cosp-wtg001,
            wa1_cosp-wtg002,
              wa1_cosp-wtg003,
                wa1_cosp-wtg004,
                  wa1_cosp-wtg005,
                    wa1_cosp-wtg006,
                      wa1_cosp-wtg007,
                        wa1_cosp-wtg008,
                          wa1_cosp-wtg009,
                            wa1_cosp-wtg010,
                              wa1_cosp-wtg011,
                                wa1_cosp-wtg012.




            IF ls_nd_perio = '005'.

              IF wa1_cosp-gjahr < ls_nd_year.

                v_calc = 'X'.

              ENDIF.


              IF v_calc = ' '.

                wa_item-cjtdat = wa1_cosp-wtg001 + wa_cosp-wtg001  + wa1_cosp-wtg002 + wa_cosp-wtg002 + wa1_cosp-wtg003 + wa_cosp-wtg003 + wa1_cosp-wtg004 + wa_cosp-wtg004 + wa1_cosp-wtg005 + wa_cosp-wtg005 .
              ELSE.

         wa_item-cjtdat = wa1_cosp-wtg001 + wa_cosp-wtg001  + wa1_cosp-wtg002 + wa_cosp-wtg002 + wa1_cosp-wtg003 + wa_cosp-wtg003 + wa1_cosp-wtg004 + wa_cosp-wtg004 + wa1_cosp-wtg005 + wa_cosp-wtg005 + wa1_cosp-wtg006 + wa_cosp-wtg006 + wa1_cosp-wtg007 +
       wa_cosp-wtg007 +
       wa1_cosp-wtg008 + wa_cosp-wtg008 + wa1_cosp-wtg009 + wa_cosp-wtg009 + wa1_cosp-wtg010 + wa_cosp-wtg010 + wa1_cosp-wtg011 + wa_cosp-wtg011 + wa1_cosp-wtg012 + wa_cosp-wtg012.

              ENDIF.
.
.
.
....... conituning with remaining periods...

MODIFY final internal table
Clear wa1_cosp
ENDAT.

Edited by: Vara K on Mar 5, 2009 6:45 PM

Edited by: Vara K on Mar 5, 2009 6:50 PM

Former Member
Former Member replied

HI,

DATA PERIOD TYPE IT_COSP-PERIOD1.

SORT it_cosp by KSTAR.
LOOP AT it_cosp INTO wa_cosp  WHERE YEAR LE P_YEAR.

DO 12 TIMES VARYING period FROM PERiOD1 NEXT PERIOD2.

IF SY-INDEX LE P_PERIOD.
TOT_PER = TOT_PER +  period.
ELSe.
 exit.
ENSIF.
ENDDO.

AT END OF kstar.
 WRITE :/ TOT_PER.
CLEAR TOT_PER.
ENDOF.

ENDLOOP.

Edited by: Avinash Kodarapu on Mar 5, 2009 11:25 PM

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question