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: 

fiscal quarter from sy-datum

Former Member
0 Kudos

Hi Gurus!

I need to calculate the past quarter of the year from sy-datum.

can somebody please advise?

points will be rewarded!

Felix

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can check with FM 'HR_99S_GET_QUARTER'.

It will return the current quarter.

You can subtract 1 from that to get past quarter.

Reward if helpful.

RSS.

6 REPLIES 6

former_member210123
Active Participant
0 Kudos

g_date = sy-datum.

g_test = g_date+2(2).

the g_test gives the month.

if G_test/4 < 1 it is quarter 1.(example if 2 the quarter is 1)

so the previous quarter is 4.

Former Member
0 Kudos

Hi,

You can check with FM 'HR_99S_GET_QUARTER'.

It will return the current quarter.

You can subtract 1 from that to get past quarter.

Reward if helpful.

RSS.

Former Member
0 Kudos

hi check this..

use the HR_99S_GET_QUARTER ..it will give the quarter no and for the past quarter u can substract 1 from it..

regards,

venkat.

Former Member
0 Kudos

check this...


TYPE-POOLS p99sg .

DATA : s_date TYPE BKK_PSTDAT.
DATA : e_date TYPE BKK_PSTDAT.
DATA : qrtr TYPE p99sg_quarter.

CALL FUNCTION 'BKK_GET_QUARTER_DATE'
 EXPORTING
   I_DATE                = SY-DATUM
*   I_PERIOD              =
 IMPORTING
   E_QUARTER_START       = s_date
   E_QUARTER_END         = e_date.

WRITE : s_date,
        / e_date.

CALL FUNCTION 'HR_99S_GET_QUARTER'
  EXPORTING
    im_date             = sy-datum
*   IM_ABKRS            =
*   IM_PERMO            =
 IMPORTING
   EX_QUARTER          = qrtr.
*   EX_RETURNCODE       =

WRITE 😕 qrtr-q.

Former Member
0 Kudos

Hi,

Please refer the code below:


Assuming sp_monat is the period 

    IF sp_monat BETWEEN '01' AND '03'.
      lv_monat = '01'.

    ELSEIF sp_monat BETWEEN '04' AND '06'.
      lv_monat = '04'.

    ELSEIF sp_monat BETWEEN '07' AND '09'.
      lv_monat = '07'.

    ELSEIF sp_monat BETWEEN '10' AND '12'.
      lv_monat = '10'.

    ENDIF.

    PERFORM f_get_first_day USING lv_monat.

    PERFORM f_get_last_day USING sp_monat.

FORM f_get_first_day  USING    iv_gp_monat.
  DATA lv_poper LIKE t009b-poper.

  lv_poper = iv_gp_monat.

  CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = sp_gjahr
      i_periv        = 'K4'
      i_poper        = lv_poper
    IMPORTING
      e_date         = gv_firstday
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.

ENDFORM.                    " f_get_first_day


FORM f_get_last_day  USING    iv_gp_monat.
  DATA lv_poper LIKE t009b-poper.

  lv_poper = iv_gp_monat.

  CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = sp_gjahr
      i_periv        = 'K4'
      i_poper        = lv_poper
    IMPORTING
      e_date         = gv_lastday
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.
ENDFORM.                    " f_get_last_day

Thanks,

Sriram Ponna.

Former Member
0 Kudos

Your question asks for fiscal quarter from the date. If that's the case, then you need to base the quarter on the fiscal period, not the calendar month.

The following will give you the current fiscal quarter. I'll leave it to you to calculate the previous quarter.

REPORT zz_temp.

DATA g_v_buper     TYPE t009b-poper.
DATA g_v_bdatj     TYPE t009b-bdatj.
DATA g_v_fyqtr(5)  TYPE n.
DATA g_v_qtr         TYPE n.

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
  EXPORTING
    i_date         = '20080101'
    i_periv        = 'Z0'
  IMPORTING
    e_buper        = g_v_buper
    e_gjahr        = g_v_bdatj
  EXCEPTIONS
    input_false    = 1
    t009_notfound  = 2
    t009b_notfound = 3
    OTHERS         = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.



CONCATENATE g_v_bdatj g_v_buper INTO g_v_qtr.

g_v_qtr = CEIL( g_v_buper / 3 ).

WRITE:/ g_v_bdatj,g_v_buper,g_v_qtr.