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

Fetching data for las 12 Months

Former Member
0 Likes
778

Dear All,

We are having one custom table where fields are customer no, material no, year, month, quantity1.

Now I want to create a report which on entering customer no & material no in input should add up the values for last 12 months from the current date and display as one value.

Example of entries in database:

custmr no matrl no. year month qty1

1 1 2006 01 45.00

1 1 2006 02 25.00

1 2 2006 01 10.00

After executing the report I want the result as

custmr no matrl no. year qty1

1 1 2006 70.00

1 2 2006 10.00

and this addition should be done for last 12 months from the current date.

Warm Regards,

Nishu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
633

SELECT cust matno year month qty1

into table itab

from ztable

where year in r_year.

ldt = sy-datum - 365.

concatenate ldt(6) '01' into ld2.

ld1 = sy-datum.

Loop at itab.

concatenate itab-year itab-month '01' into ldate.

check ldate <= ld1 and ldate >= ld2.

move-corresponding itab to itot.

collect itot.

endloop.

4 REPLIES 4
Read only

Former Member
0 Likes
634

SELECT cust matno year month qty1

into table itab

from ztable

where year in r_year.

ldt = sy-datum - 365.

concatenate ldt(6) '01' into ld2.

ld1 = sy-datum.

Loop at itab.

concatenate itab-year itab-month '01' into ldate.

check ldate <= ld1 and ldate >= ld2.

move-corresponding itab to itot.

collect itot.

endloop.

Read only

Former Member
0 Likes
633

Hi

DATA: PERIOD(6) TYPE N,
           PERIOD_FROM(6) TYPE N,
           PERIOD_TO(6)       TYPE N.

PERIOD_FROM(6) = SY-DATUM(4).
PERIOD_TO(4)       = SY-DATUM(4).
PERIOD_TO+4(2)   = '12'.

LOOP AT ITAB.
  PERIOD(4)     = ITAB-YEAR.
  PERIOD+4(2) = ITAB-MONTH. 
  IF PERIOD => PERIOD_FROM AND PERIOD <= PERIOD_TO.
    COLLECT ITAB INTO ITAB2.
  ENDIF.
ENDLOOP.

Max

Read only

Former Member
0 Likes
633

DATA: V1(4) TYPE N,

V2(2) TYPE N,

V3(2) TYPE N.

V1 = SY-DATUM+0(4) - 1.

V2 = SY-DATUM+4(2).

V3 = SY-DATUM+6(2).

contatenate V1 V2 V3 into date1.

select * from z-table into itab where date <= sy-datum

and date >= date1.

Read only

andreas_mann3
Active Contributor
0 Likes
633

hi,

1

) calculate previous_year = sy-datum(4) - 1.
2) calcualate period_from  = sy-datum+4(2) + 1.
   if period_from > 12.
      period_from = 1.
      prvious_year = sy-datum(4).
   endif.

3) select yout table with where clause:

where ( ( year = previous year 
   and month between previous_month and 12 )
     or year = sy-datum(4)  
   and month between 1 and sy-datum+4(2) ) )
...
  

A.