Business Requirement.
In SAP Saudi Implementations, the HR Module that has lot of Dates that are being captured for the employee. However, in the reports and/or display the respective dates are being displayed in synch with Hijiri Calendar and not in regular English (Gregorian) Calendar. So we need a conversion from Gregorian Date to Hijiri Date.
Hijri Calendar - The Hijri calendar is a lunar calendar, consisting of 12 months of 354 or 355 days. As it is a lunar calendar, there is an annual drift of 10 days.
How We implement.
- Go to SE37.
- Create a new function
- Provide Input parameter specification
- Provide Output parameter specification
- complete the Source code.
Input Parameter Specification.
Output Parameter Specification.
Source Code
DATA: LOC_MM(2) TYPE N,
LOC_DD(2) TYPE N,
LOC_YY(4) TYPE N.
DATA: LOC_HIJ_MM(2) TYPE N,
LOC_HIJ_DD(2) TYPE N,
LOC_HIJ_YY(4) TYPE N.
DATA: LOC_JD TYPE P DECIMALS 2,
LOC_LL TYPE P DECIMALS 2,
LOC_LN TYPE P DECIMALS 2,
LOC_LJ TYPE P DECIMALS 2.
LOC_YY = P_GREG_DATE+0(4).
LOC_MM = P_GREG_DATE+4(2).
LOC_DD = P_GREG_DATE+6(2).
IF ( LOC_YY > 1582 ) OR
( LOC_YY = 1582 AND LOC_MM > 10 ) OR
( LOC_YY = 1582 AND LOC_MM = 10 AND LOC_DD > 14 ).
LOC_JD = TRUNC( ( 1461 * ( LOC_YY + 4800 + TRUNC( ( LOC_MM - 14 ) / 12 ) ) ) / 4 ) +
TRUNC( ( 367 * ( LOC_MM - 2 - 12 * ( TRUNC( ( LOC_MM - 14 ) / 12 ) ) ) ) / 12 ) -
TRUNC( ( 3 * ( TRUNC( ( LOC_YY + 4900 + TRUNC( ( LOC_MM - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) + LOC_DD - 32075.
ELSE.
LOC_JD = 367 * LOC_YY - TRUNC( 7 * ( LOC_YY + 5001 + TRUNC( ( LOC_MM - 9 ) / 7 ) ) ) / 4 +
TRUNC( ( 275 * LOC_MM ) / 9 ) + LOC_DD + 1729777.
ENDIF.
LOC_LL = LOC_JD - 1948440 + 10632.
LOC_LN = TRUNC( ( LOC_LL - 1 ) / 10631 ).
LOC_LL = LOC_LL - 10631 * LOC_LN + 354.
LOC_LJ = ( TRUNC( ( 10985 - LOC_LL ) / 5316 ) ) * ( TRUNC( ( 50 * LOC_LL ) / 17719 ) ) +
( TRUNC( LOC_LL / 5670 ) ) * ( TRUNC( ( 43 * LOC_LL ) / 15238 ) ).
LOC_LL = LOC_LL - ( TRUNC( ( 30 - LOC_LJ ) / 15 ) ) * ( TRUNC( ( 17719 * LOC_LJ ) / 50 ) ) -
( TRUNC( LOC_LJ / 16 ) ) * ( TRUNC( ( 15238 * LOC_LJ ) / 43 ) ) + 29.
LOC_HIJ_MM = TRUNC( ( 24 * LOC_LL ) / 709 ).
LOC_HIJ_DD = LOC_LL - TRUNC( ( 709 * LOC_HIJ_MM ) / 24 ).
LOC_HIJ_YY = 30 * LOC_LN + LOC_LJ - 30 .
CONCATENATE LOC_HIJ_YY LOC_HIJ_MM LOC_HIJ_DD INTO P_HIJRA_DATE.
Output Verification
Hope this document may help you.