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

sy-datum problem

Former Member
0 Likes
983

hi friends,

given a period how to find previos month.

ie.

datum format is yyyymm.

datum = 200401

i should get previous month 200312

how do i do this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
877

Hi,

Try this..


DATA: V_INPUT(6) TYPE N VALUE '200401'.
DATA: V_OUTPUT(6) TYPE N.
DATA: V_DATE TYPE D.

CONCATENATE V_INPUT '01' TO V_DATE.

call function 'RE_ADD_MONTH_TO_DATE'
         exporting
              months  = '-1'
              olddate = v_date
         importing
              newdate = v_date.



V_OUTPUT = V_DATE(6).

WRITE: / V_OUTPUT.

Thanks,

Naren

10 REPLIES 10
Read only

Former Member
0 Likes
877

Hi

Try using sy-datum-30.

Thanks

Read only

Former Member
0 Likes
878

Hi,

Try this..


DATA: V_INPUT(6) TYPE N VALUE '200401'.
DATA: V_OUTPUT(6) TYPE N.
DATA: V_DATE TYPE D.

CONCATENATE V_INPUT '01' TO V_DATE.

call function 'RE_ADD_MONTH_TO_DATE'
         exporting
              months  = '-1'
              olddate = v_date
         importing
              newdate = v_date.



V_OUTPUT = V_DATE(6).

WRITE: / V_OUTPUT.

Thanks,

Naren

Read only

gopi_narendra
Active Contributor
0 Likes
877

try this FM : CCM_GO_BACK_MONTHS

Regards

Gopi

Read only

Former Member
0 Likes
877

data :v_date(6) type c.

data v_dat(2) type c.

data :v_mon(2) type c

start-of-selection.

v_dat = v_date+4(2).

case v_dat.

when '01'.

v_mon = '12'

when '02'

v_mon = '01'

when '03'

v_mon = '02'

when '04'

v_mon = '03'

when '05'

v_mon = '04'

when '06'

when '07'

when '08'

when '09'

when '10'

when '11'

when '12'

endcase.

use case statement and concatenate to one more varaible

Read only

former_member186741
Active Contributor
0 Likes
877

if you are talking about periods maintained in table t009 you can use this fm:

ISB_PREVIOUS_PERIOD_GET

Read only

Former Member
0 Likes
877

Hi,

There are a lot of function module for Date caculations, so U can go to SM37 to find out the appropriate function for your use.

Hope this helps

Bob

Read only

Former Member
0 Likes
877

Hi Saritha,

Try this simple coding.

DATA datum(6).

DATA last_month(6).

datum = '200501'.

If datum+4(2) = '01'.

last_month0(4) = datum0(4) - 1.

last_month+4(2) = '12'.

else.

last_month = datum - 1.

endif.

WRITE / last_month.

Regards,

Atish

Read only

Former Member
0 Likes
877

Hi Saritha,

I'm not sure if there is a function module for this..

you can actually write the logic for this as follows:

data : date(6) value '200401'.
data : month(2), year(4).
data : final(6).
month = date+4(2).
year = date+0(4).
month = month - 1.
if month = 0.
  year = year - 1.
  month = 12.
endif.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = month
 IMPORTING
   OUTPUT        = month
          .
concatenate year month into final.
write : final.

Hope this helps

Regards

Anil Madhavan

Read only

Former Member
0 Likes
877

thank you friends.

Read only

Former Member
0 Likes
877

Hi,

Please make sure to reward points for helpful answers..and close the thread if the problem is solved..

Thanks,

Naren