Function Module (Custom) to get Fiscal Week from Date



FUNCTION zemfi_date_to_fiscal_week.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_DATE) TYPE  DATUM
*"     REFERENCE(I_PERIV) TYPE  PERIV
*"  EXPORTING
*"     REFERENCE(E_WEEK) TYPE  SCAL-WEEK
*"     REFERENCE(E_GJAHR) TYPE  GJAHR
*"----------------------------------------------------------------------


  
DATA: l_first_day_of_year LIKE sy-datum,
        l_weeks(
5)          TYPE p,
        l_week01            
TYPE d,  "First Day of Week/First Day of Period
        l_run_date          
TYPE d.  "Run Date in type D format


* Convert Date to Period

  
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
    
EXPORTING
      i_date               = i_date
*   I_MONMIT             = 00
      i_periv              = i_periv
   
IMPORTING
*   E_BUPER              =
     e_gjahr              = e_gjahr
   
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.

* Get First day of the Fiscal Year

  
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
    
EXPORTING
      i_gjahr              = e_gjahr
*   I_MONMIT             = 00
      i_periv              = i_periv
      i_poper              = 
'001'
   
IMPORTING
     e_date               = l_first_day_of_year
   
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.

    l_week01   = l_first_day_of_year.
    l_run_date = i_date.

    l_weeks = ( ( l_run_date - l_week01 ) 
DIV 7 ) + 1.
    e_week  = l_weeks.


ENDFUNCTION.


Comments

  1. Thank you for your codes. Saved my project!

    ReplyDelete

Post a Comment

Popular posts from this blog

ABAP Tips - 1 : How to Display a Popup and Get Values from User ?

Help on BAPI_ACC_DOCUMENT_POST and BAPI_ACC_DOCUMENT_POST

Few Tips for Transport Request Manipulation