cancel
Showing results for 
Search instead for 
Did you mean: 

Function Module to get first and last day of financial year by passing date

former_member212786
Participant
0 Kudos

Hi All,

Is there any FM to get first and last day of financial year by passing date?

Thanks,

Rathinakumar

Accepted Solutions (1)

Accepted Solutions (1)

former_member186445
Active Contributor

FIRST_AND_LAST_DAY_IN_YEAR_GET


there are a number of posts with some code examples as well if you search...


M.

former_member212786
Participant
0 Kudos

I am passing date as input.

In the above FM, Year is input.

Rgds,

Rathinakumar

former_member186445
Active Contributor
0 Kudos

convert date to fiscal first

DATE_TO_PERIOD_CONVERT


M.

former_member212786
Participant
0 Kudos

Hi,

I have written the following code. But i am not getting year as output.

Could you please correct me where is the problem?

DATA: IT_TEMP TYPE STANDARD TABLE OF _ty_s_SC_1 ,

       IT_TEMP1 TYPE STANDARD TABLE OF _ty_s_SC_1,

       WA_TEMP TYPE _ty_s_SC_1.

     DATA: DT1 TYPE SY-DATUM,

           DT2 TYPE SY-DATUM,

           DTF TYPE SY-DATUM,

           DTL TYPE SY-DATUM,

           MY1  TYPE /BI0/OICALMONTH,

           DD1(2TYPE C,

           YEAR(4) TYPE N,

           FY(4) TYPE N,

           Period(3) TYPE N.


    DATA: w_period TYPE  t009b-poper,

               w_year   TYPE  t009b-bdatj.

        YEAR = W_YEAR.

        PERIOD = W_PERIOD.

      IT_TEMP = SOURCE_PACKAGE.

      SORT IT_TEMP BY PERNR.

      DELETE ADJACENT DUPLICATES FROM IT_TEMP COMPARING PERNR.

  

     LOOP AT IT_TEMP INTO WA_TEMP.

           DT2 = WA_TEMP-UPDATEDT.

        CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

           EXPORTING

             i_date         = DT2

             i_monmit       = 00

             i_periv        = 'v3'


           IMPORTING

             e_buper        = w_period

             e_gjahr        = w_year


           EXCEPTIONS

             input_false    = 1

             t009_notfound  = 2

             t009b_notfound = 3

             OTHERS         = 4.

     IF SY-SUBRC = 0.

         FY = YEAR.

     ENDIF.

Former Member
0 Kudos

DATA: IT_TEMP TYPE STANDARD TABLE OF _ty_s_SC_1 ,

       IT_TEMP1 TYPE STANDARD TABLE OF _ty_s_SC_1,

       WA_TEMP TYPE _ty_s_SC_1.

     DATA: DT1 TYPE SY-DATUM,

           DT2 TYPE SY-DATUM,

           DTF TYPE SY-DATUM,

           DTL TYPE SY-DATUM,

           MY1  TYPE /BI0/OICALMONTH,

           DD1(2TYPE C,

           YEAR(4) TYPE N,

           FY(4) TYPE N,

           Period(3) TYPE N.


    DATA: w_period TYPE  t009b-poper,

               w_year   TYPE  t009b-bdatj.

        YEAR = W_YEAR.

        PERIOD = W_PERIOD.

      IT_TEMP = SOURCE_PACKAGE.

      SORT IT_TEMP BY PERNR.

      DELETE ADJACENT DUPLICATES FROM IT_TEMP COMPARING PERNR.

 

     LOOP AT IT_TEMP INTO WA_TEMP.

*** This will give you first date and last date of Month ( from Updated date ) or if you like to fix it on Period 01 or 12, then you will get  first and last date of the year.

           DT2 = WA_TEMP-UPDATEDT.

*           concatenate wa_temp(4) '1215' into DT2_l " middle of month of Dec

*           concatenate wa_temp(4) '0115' into DT2_f  " middle of month of Jan

        CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

           EXPORTING

             i_date         = DT2

             i_monmit       = 00

             i_periv        = 'V3'


           IMPORTING

             e_buper        = w_period

             e_gjahr        = w_year


           EXCEPTIONS

             input_false    = 1

             t009_notfound  = 2

             t009b_notfound = 3

             OTHERS         = 4.

     IF SY-SUBRC = 0.

             

                  call function 'LAST_DAY_IN_PERIOD_GET'

                     exporting

                       i_gjahr = w_year

                       i_periv = ''

                       i_poper = w_period

                     importing

                       e_date  = zlastdate.


               wa_temp-<fieldforlastdate> = zlastdate

                  call function 'FIRST_DAY_IN_PERIOD_GET'

                     exporting

                       i_gjahr = w_year

                       i_periv = ''

                       i_poper = w_period

                     importing

                       e_date  = zfirstdate.


                wa_temp-<fieldforfirstdate> = zfirstdate

     ENDIF.

    

modify source_package from wa_temp.

   

endloop.

former_member212786
Participant
0 Kudos

Hi Sandeep,

Thanks for your reply.

In the first function module DATE_TO_PERIOD_CONVERT, i am not getting value for w_year and w_period.

I am getting for w_year as 0000 and w_period as 000

Rgds,

Rathinakumar

Former Member
0 Kudos

Try to first run FM in se37 with today's date and see the output. Use capital V3 as variant  or try K4

former_member212786
Participant
0 Kudos

Thanks, Sandeep. It is working after changing capital V3.

Thanks a lot.

Rgds,

Rathinakumar

former_member212786
Participant
0 Kudos

Hi Sandeep,

I have a field  UPDATEDT with records from 01.04.2013 to Till date.

I want to filter the records for 01.04.2016 To 31.03.2017(Current Fiscal Year).

But, my below start routine, is not providing the right right output. Could you please advice.?

DATA: IT_TEMP TYPE STANDARD TABLE OF _ty_s_SC_1 ,

       IT_TEMP1 TYPE STANDARD TABLE OF _ty_s_SC_1,

       WA_TEMP TYPE _ty_s_SC_1.

     DATA: DT1 TYPE SY-DATUM,

           DT2 TYPE SY-DATUM,

           DTF TYPE SY-DATUM,

           DTL TYPE SY-DATUM,

           zlastdate TYPE SY-DATUM,

           zfirstdate TYPE SY-DATUM,

           MY1  TYPE /BI0/OICALMONTH,

           DD1(2TYPE C,

           YEAR(4) TYPE N,

           FY(4) TYPE N,

           Period(3) TYPE N.

    DATA: w_period TYPE  t009b-poper,

           w_year   TYPE  t009b-bdatj.

        YEAR = W_YEAR.

        PERIOD = W_PERIOD.

      IT_TEMP = SOURCE_PACKAGE.

      SORT IT_TEMP BY PERNR.

      DELETE ADJACENT DUPLICATES FROM IT_TEMP COMPARING PERNR.

      DELETE IT_TEMP WHERE UPDATEDT = '00000000'.

*   LOOP AT IT_TEMP ASSIGNING <SOURCE_FIELDS>.

     LOOP AT IT_TEMP INTO WA_TEMP.

        CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

           EXPORTING

             i_date         = WA_TEMP-UPDATEDT

             i_monmit       = 00

             i_periv        = 'V3'

           IMPORTING

             e_buper        = w_period

             e_gjahr        = w_year

           EXCEPTIONS

             input_false    = 1

             t009_notfound  = 2

             t009b_notfound = 3

             OTHERS         = 4.

     IF SY-SUBRC = 0.

  CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'

   EXPORTING

     I_GJAHR        = w_year

     I_PERIV        = 'V3'

   IMPORTING

     E_FIRST_DAY    = zfirstdate

     E_LAST_DAY     = zlastdate

   EXCEPTIONS

     INPUT_FALSE    = 1

     T009_NOTFOUND  = 2

     T009B_NOTFOUND = 3

     OTHERS         = 4.

      DELETE IT_TEMP WHERE UPDATEDT < zfirstdate.

      DELETE IT_TEMP WHERE UPDATEDT > zlastdate.

      DELETE IT_TEMP WHERE WFOPR <> 'DEMP'.

      DELETE IT_TEMP WHERE INFTY <> '0002'.

ENDIF.

    ENDLOOP.

BREAK-POINT.

   SOURCE_PACKAGE[] = IT_TEMP[].

Answers (0)