Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Gregorian-Hijri Dates Converter

Hello Experts;

I am looking for ABAP Report/Function module for "Gregorian <=> Hijri Dates Converter".

Any assistance in this regards would be highly appriciated and points will be rewarded.

Looking forward for your usual prompt and professional advice...

Best Regards,

Aslam

You may ask... What is Hijri Calender?

<a href="http://en.wikipedia.org/wiki/Hijri">en.wikipedia.org/wiki/Hijri</a>

The Islamic calendar or Muslim calendar (also called "Hijri calendar", Arabic) is the calendar used to date events in many predominantly Muslim countries, and used by Muslims everywhere to determine the proper day on which to celebrate Islamic holy days. It is a lunar calendar having 12 lunar months in a year of about 354 days. Because this lunar year is about 11 days shorter than the solar year, Islamic holy days, although celebrated on fixed dates in their own calendar, usually shift 11 days earlier each successive solar year, such as a year of the Gregorian calendar. Islamic years are also called Hijra years because the first year was the year during which the Hijra occurred— Muhammad's emigration from Mecca to Medina. Thus each numbered year is designated either H or AH, the latter being the initials of the Latin anno Hegirae (in the year of the Hijra).

Tags:
Former Member
Former Member replied

Hi,

use the below sub-routines in ABAP to convert Gregorian to Hijri dates and vice versa

DATA: WF_RESULT1 TYPE I,

WF_RESULT2 TYPE C,

WF_DATE1 TYPE SY-DATUM,

WF_DATE2 TYPE SY-DATUM.

*WF_DATE1 = '14271123'.

WF_DATE1 = SY-DATUM.

PERFORM F_GREGORIANTOHIJRA1 USING WF_DATE1

CHANGING WF_DATE2.

WRITE:/ WF_DATE1,WF_DATE2.

PERFORM F_HIJRATOGREGORIAN1 USING WF_DATE2

CHANGING WF_DATE1.

WRITE:/ WF_DATE1,WF_DATE2.

&----


*& Form F_GREGORIANTOHIJRA1

&----


  • text

----


  • -->P_GREG_DATEtext

  • -->P_HIJRA_DATtext

----


FORM F_GREGORIANTOHIJRA1 USING P_GREG_DATE

CHANGING P_HIJRA_DATE.

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.

ENDFORM. "F_HIJRATOGREGORIAN1

&----


*& Form F_HIJRATOGREGORIAN1

&----


  • text

----


  • -->P_HIJRA_DATtext

  • -->P_GREG_DATEtext

----


FORM F_HIJRATOGREGORIAN1 USING P_HIJRA_DATE

CHANGING P_GREG_DATE.

DATA: LOC_MM(2) TYPE N,

LOC_DD(2) TYPE N,

LOC_YY(4) TYPE N.

DATA: LOC_HIJ_MM TYPE I,

LOC_HIJ_DD TYPE I,

LOC_HIJ_YY TYPE I.

DATA: LOC_HIJ_MM1(2) TYPE N,

LOC_HIJ_DD1(2) TYPE N,

LOC_HIJ_YY1(4) TYPE N.

DATA: LOC_JD TYPE P DECIMALS 2,

LOC_LL TYPE P DECIMALS 2,

LOC_LN TYPE P DECIMALS 2,

LOC_LK TYPE P DECIMALS 2,

LOC_LI TYPE P DECIMALS 2,

LOC_LJ TYPE P DECIMALS 2.

LOC_YY = P_HIJRA_DATE+0(4).

LOC_MM = P_HIJRA_DATE+4(2).

LOC_DD = P_HIJRA_DATE+6(2).

LOC_JD = ( ( 11 * LOC_YY + 3 ) / 30 ) +

354 * LOC_YY + 30 * LOC_MM -

( ( LOC_MM - 1 ) / 2 ) + LOC_DD + 1948440 - 385 .

IF LOC_JD > 2299160.

LOC_LL = LOC_JD + 68569.

LOC_LN = TRUNC( ( 4 * LOC_LL ) / 146097 ).

LOC_LL = ( LOC_LL - TRUNC( ( 146097 * LOC_LN + 3 ) / 4 ) ).

LOC_LI = TRUNC( ( 4000 * ( LOC_LL + 1 ) ) / 1461001 ).

LOC_LL = ( LOC_LL - TRUNC( ( 1461 * LOC_LI ) / 4 ) + 31 ).

LOC_LJ = TRUNC( ( 80 * LOC_LL ) / 2447 ).

LOC_HIJ_DD = LOC_LL - TRUNC( ( 2447 * LOC_LJ ) / 80 ).

LOC_LL = TRUNC( LOC_LJ / 11 ).

LOC_HIJ_MM = LOC_LJ + 2 - ( 12 * LOC_LL ).

LOC_HIJ_YY = 100 * ( LOC_LN - 49 ) + LOC_LI + LOC_LL.

ELSE.

LOC_LJ = LOC_JD + 1402.

LOC_LK = TRUNC( ( LOC_LJ - 1 ) / 1461 ).

LOC_LL = LOC_LJ - 1461 * LOC_LK.

LOC_LN = TRUNC( ( LOC_LL - 1 ) / 365 ) - TRUNC( LOC_LL / 1461 ).

LOC_LI = LOC_LL - 365 * LOC_LN + 30.

LOC_LJ = TRUNC( ( 80 * LOC_LI ) / 2447 ).

LOC_HIJ_DD = LOC_LI - TRUNC( ( 2447 * LOC_LJ ) / 80 ).

LOC_LI = TRUNC( LOC_LJ / 11 ).

LOC_HIJ_MM = LOC_LJ + 2 - ( 12 * LOC_LI ).

LOC_HIJ_YY = 4 * LOC_LK + LOC_LN + LOC_LI - 4716.

ENDIF.

LOC_HIJ_MM1 = LOC_HIJ_MM.

LOC_HIJ_DD1 = LOC_HIJ_DD.

LOC_HIJ_YY1 = LOC_HIJ_YY.

CONCATENATE LOC_HIJ_YY1 LOC_HIJ_MM1 LOC_HIJ_DD1

INTO P_GREG_DATE.

ENDFORM. "F_HIJRATOGREGORIAN1

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question