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

calculation on year

Former Member
0 Likes
1,083

Hi,

if the current date falls between april and december,the year should be same year and if the current date falls between january to march,year should be previous year.For example

if the date is 23.5.2008, year = 2008 and if the date is 23.3.2008,year = 2007

23.3.2009,year = 2008. how can i program this.Please help.

Thanks,

K Srinivas

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,060

>

> Hi,

>

> if the current date falls between april and december,the year should be same year and if the current date falls between january to march,year should be previous year.For example

> if the date is 23.5.2008, year = 2008 and if the date is 23.3.2008,year = 2007

> 23.3.2009,year = 2008. how can i program this.Please help.

>

> Thanks,

> K Srinivas


data : l_date type d,
         l_month(2) type n.
         l_year(4) type n.

l_date = sy-datum.
l_month = sy-datum+4(2).
l_year = sy-datum(4).

if l_month <= 3.
l_year = l_year - 1.
endif.


write l_year.


10 REPLIES 10
Read only

Former Member
0 Likes
1,061

>

> Hi,

>

> if the current date falls between april and december,the year should be same year and if the current date falls between january to march,year should be previous year.For example

> if the date is 23.5.2008, year = 2008 and if the date is 23.3.2008,year = 2007

> 23.3.2009,year = 2008. how can i program this.Please help.

>

> Thanks,

> K Srinivas


data : l_date type d,
         l_month(2) type n.
         l_year(4) type n.

l_date = sy-datum.
l_month = sy-datum+4(2).
l_year = sy-datum(4).

if l_month <= 3.
l_year = l_year - 1.
endif.


write l_year.


Read only

Former Member
0 Likes
1,060

Hi ,

if date+4(2) le '03'.

date0(4) = date0(4) - 1.

Endif.

Thanks,

Ananth

Read only

Former Member
0 Likes
1,060

data : l_date type d,

l_month(2) type n.

l_year(4) type n.

l_date = sy-datum.

l_month = sy-datum+4(2).

l_year = sy-datum(4).

if l_month LE 3.

l_year = l_year - 1.

endif.

write l_year.

Read only

Former Member
0 Likes
1,060

use the fm

data : year(4).

CALL FUNCTION 'GM_GET_FISCAL_YEAR'
  EXPORTING
   I_DATE                           = SY-DATUM
    I_FYV                            = 'V3'
 IMPORTING
   E_FY                             = year
 EXCEPTIONS
   FISCAL_YEAR_DOES_NOT_EXIST       = 1
   NOT_DEFINED_FOR_DATE             = 2
   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write : / year.

Read only

Former Member
0 Likes
1,060

Hi Dude,

Here is the Solution for this.

U use the FM RKE_CONVERT_DATE_TO_PERIOD.

pass the parameters as follows,

Import parameters Value

DATE 22.02.2008

PERFLAG 1

PERIV V3

U will get the output as,

Export parameters Value

PERIO 011.2007

U take the PERIO+4(4) so 2007 will come because DATE is in

2nd month.

if Date is say 4th month we will get 2008.

Hope this solves UR problem.

Read only

Former Member
0 Likes
1,060

Hi Srini,

Try the following:

data:
w_date type sy-datum,
w_year(4) type n,
w_year1(4) type n,
w_month(2) type n.

w_date = sy-datum.

w_month = w_date+4(2).
w_year = w_date(4).

if w_month ge 03.
 w_year1 = w_year.
else.
 w_year1 = w_year + 1.
endif.

Regards,

Chandra Sekhar

Edited by: Chandrasekhar Gandla on Aug 27, 2008 4:49 PM

Read only

Former Member
0 Likes
1,060

hii

use following code

PARAMETERS : p_date TYPE sy-datum.
DATA:


date TYPE sy-datum,
wa_year TYPE i,
wa_month TYPE i,
wa_ext(4) TYPE c VALUE '.txt',
v_result(18) TYPE c.

date = p_date.

wa_year = date+0(4).
wa_month = date+4(2).

IF wa_month < 12 AND wa_month > 4.
  wa_month = '2008'.
  date+0(4) = wa_month.
ELSE.
  wa_month = '2007'.
  date+0(4) = wa_month.
ENDIF.

WRITE date.

regards

twinkal

Read only

anversha_s
Active Contributor
0 Likes
1,060

hi,

Pls try this.

data: wa_date like sy-datum.
data: month(2),      
      year(4),
      int_mnth type int2,
      int_yr type int4,
      int_yr_temp type int4.
     
move sy-datum to wa_date.

month = wa_date+4(2).
year = wa_date+0(4).

move month to int_mnth.
move year to int_yr_temp.

if ( int_mnth GE 4 and int_mnth LE 12).
move year to iny_yr.
else.
int_yr_temp = int_yr_temp - 1.
move int_yr_temp  to iny_yr.
endif.

Regards,

Anversha

Read only

bpawanchand
Active Contributor
0 Likes
1,060

Hi

SELECT-OPTIONS:
    s_dat FOR sy-datum.

DATA :
  w_p1 TYPE i,
  w_p2 TYPE i.



w_p1 = s_dat-low+4(2).
w_p2 = s_dat-high+4(2).

IF w_p1 GT 5 AND w_p2 LT 12.
  WRITE : /'YEar 2008'.
ELSEIF w_p1 GT 1 AND w_p2 LT 5.
  WRITE :
   / '2007'.
ENDIF.

Regards

Pavan

Read only

Former Member
0 Likes
1,060

Hi,

if the current date falls between april and december,the year should be same year and if the current date falls between january to march,year should be previous year.For example

if the date is 23.5.2008, year = 2008 and if the date is 23.3.2008,year = 2007

23.3.2009,year = 2008. how can i program this.Please help.

Thanks,

K Srinivas

Hey Srinivas,

Maybe this should help...


data: lv_var type i,
        lv_date type sy-datum.

   lv_date = sy-datum.



      lv_var = lv_date+4(2).

      if lv_var > 3 and lv_date < 12.
       
      else.

              lv_date+0(4) = lv_date+0(4) - 1.

      endif.


Cheers,

Vishnu