Application Development 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: 

Changing the date to one year back

Former Member
0 Kudos

Dear all,

I would be really grateful if you could give any idea about this problem:

I have a cube (feeded from Oracle) which has a date field and, during transformation, I want that date to be taken one month back.

20100301----->20100201

20100101-----.>20091201

I am actually using this routine actually:

data:rundate like sy-datum.

write SOURCE_FIELDS-BILL_RUN_FROM to rundate.

RESULT = rundate.

I am extremely new to ABAP so I do not know if I have been able to explain exactly the problem.

Thanks

Edited by: shkelzen on Apr 12, 2010 5:20 PM

4 REPLIES 4

0 Kudos

Hello,

Please use the below FM

/BEV3/CHPS__ADD_MONTH_TO_DATE, use -1 for the months value, it will give you previous month date

former_member1245113
Active Contributor
0 Kudos

HI

Use HR_JP_ADD_MONTH_TO_DATE you can add/subtract

to go back use -1

DATA date TYPE sy-datum. " Just copy and Execute this
CALL FUNCTION 'HR_JP_ADD_MONTH_TO_DATE'
  EXPORTING
    iv_monthcount = -1
    iv_date       = sy-datum
  IMPORTING
    ev_date       = date.
.
IF sy-subrc = 0.
write : date.
ENDIF.

Cheerz

Ram

Former Member
0 Kudos

So, do you want exactly one month back or do you want the first day of the previous month, as you posting implies?

Personally, I would write the code to do, but for first of month, you could do something like the following, and test for every month until you always get correct date:

(note prior_date and current_date are declared as type d or type sydatum or like sy-datum)...

if current_date+4(2) eq '03'. "....March.

prior_date = current_date - 28.

else.

prior_date = current_date - 30.

endif.

prior_date+6(2) = '01'.

Or (for same day, last month).

year (type n, length 4) = current_date(4).

mo (type n, length 2) = current_date+4(2).

day(type n, length 2) = current_date+6(2).

if mo eq '01'.

year = year - 1.

mon = 12.

else.

mon = mon - 1.

endif.

concatenate year mon day into prior_date.

Former Member
0 Kudos

Moderator message - Please see before posting - post locked And please don't answer questions like this either. Date questions are not allowed in the forum because they have been asked and answered many times beofore. Rob