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: 

Date formatting

Former Member
0 Kudos
181

Hi Gurus,

I am using a variable to capture the data for Current month(Minus) 3,like the one shown below, my problem is now when i am pulling the data for last year i.e i want for 11th month from this month i get the below value for t-moth (1-/08/2009)

in debugging mode and my select query is failing. Could you help me in getting the correct month stored in the variable. Thanks in advance

DATA : v_year(4) TYPE c,

v_mon(2) TYPE c,

v_day(2) TYPE c,

t_month(10) type c.

v_year = sy-datum+0(4).

v_mon = sy-datum+4(2) - 3.

v_day = sy-datum+6(2).

CONCATENATE v_mon'/' v_day'/' v_year INTO t_month.

Best Regards

Meenakshi

1 ACCEPTED SOLUTION

Former Member
0 Kudos
144

>

>v_mon = sy-datum+4(2) - 3.

The above statement is being treated as a string u cant apply numerical operations to it.

7 REPLIES 7

Former Member
0 Kudos
145

>

>v_mon = sy-datum+4(2) - 3.

The above statement is being treated as a string u cant apply numerical operations to it.

0 Kudos
144

use following fm insted:

RP_CALC_DATE_IN_INTERNAL

DATE_IN_FUTURE

0 Kudos
144

HR_PSD_DATES_ADD_MONTHS

MONTH_PLUS_DETERMINE

these FMs will help u to achieve ur requirement.

кu03B1ятu03B9к

faisalatsap
Active Contributor
0 Kudos
144

Hi,

Test the following Code it is working Fine.

DATA : v_year(4) TYPE c,
v_mon(2) TYPE c,
v_day(2) TYPE c,
t_month(10) TYPE c.

v_year = sy-datum+0(4).
v_mon = sy-datum+4(2).
v_day = sy-datum+6(2).

SUBTRACT 3 FROM v_mon.
IF v_mon < 1.
  SUBTRACT: 1 FROM v_year.
  v_mon = 12 + v_mon .
ENDIF.

Hope will solve out your problem,

Kind Regards,

Faisal

Former Member
0 Kudos
144

hi,


data:
w_date type sy-datum,
mnth(2) type n,
w_temp(2) type n,
w_month(2) type n.

w_month = w_date+4(2). " Current month
w_month = w_month - mnth. " Required month in the past
if w_month LT 1. " If w_month value is negative 12 is added
add 12 to w_month. " ex. current month feb, value 2, 5 months in the past
endif.                     " 2 - 5 = -3 + 12 = 9, i.e. september.
Do.
subtract 1 from w_date.
w_temp = w_date+4(2).
if w_month  =  w_temp.
exit.
endif.
enddo.

write: w_date. " last day of the required month.

Thanks

Sharath

Former Member
0 Kudos
144

Hi meenakshi,

You can as well use the given code to achieve this easily.

parameters : p_date like sy-datum,

p_mon(2) type n.

data : w_dummy_date like sy-datum.

start-of-selection.

w_dummy_date = p_date.

w_dummy_date+6(2) = 15. " For subtraction of month so that no discrepancy occurs even if feb

  • month comes

Do p_mon times.

subtract 30 from w_dummy_date. " going back 1 month from the given month.

enddo.

p_date4(2) = w_dummy_date4(2). " Changing month in the actual date parameter

p_date0(4) = w_dummy_date0(4). " changing year in the actual date parameter

  • day should not be changed.....

write p_date.

Hope this is helpful to you

Regards,

Siddarth

Former Member
0 Kudos
144

helpful