Application Development and Automation 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: 
Read only

Date format

Former Member
0 Likes
2,417

Hi Experts,

I want to create a FM to convert any date format to system date format ( yyyymmdd ),

for that i am following string operation approach and taking some help from this doc.

ABAP - Function module for converting any External date format to Internal format - Code Gallery - S....

Now my problem is when user will enter date in ddmmyyy & yyyymmdd format, I am not able to differentiate & perform string operation to convert in yyyymmdd format.

 

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,676

Hi,

The code in the wiki only works because each format has unique seperators, you can only apply the rules of date structure to formats ddmmyyyy and yyyymmdd and manipulate them when those rules are met.

So,

dd is a number between 01 and 31

mm is a number between 01 and 12

yy(2) is a number between 01 and 99, but is most likely 19 or 20 (depending on context)

yy+2(2) is a number between 01 and 99

If applying this logic is inconclusive, your FM should raise an exception.

Regards,

Nick

5 REPLIES 5
Read only

Former Member
0 Likes
1,677

Hi,

The code in the wiki only works because each format has unique seperators, you can only apply the rules of date structure to formats ddmmyyyy and yyyymmdd and manipulate them when those rules are met.

So,

dd is a number between 01 and 31

mm is a number between 01 and 12

yy(2) is a number between 01 and 99, but is most likely 19 or 20 (depending on context)

yy+2(2) is a number between 01 and 99

If applying this logic is inconclusive, your FM should raise an exception.

Regards,

Nick

Read only

Former Member
0 Likes
1,676

Hi Farid,

The link given by is validated with separators ( Length = 10 ).

You can check for the Length of the characters as you are maintaining the string format and validate the input for Length = 8 characters for your inputs. Regarding the logic, you need to try with what Nick has suggested.

Regards,

AyyamPerumal

Read only

Former Member
0 Likes
1,676

Hello Farid,

Assume P_PERIOD contains MMYYYY, checking P_PERIOD contains valid data or not.

   IF p_period+0(2) CO '0 '.
      IF p_period+2(2) CN '0 ' AND
         p_period+4(2) CN '0 '.
        MOVE p_period+2(2) TO p_period+0(2).
        IF p_period+4(2) LE'70'.
          MOVE '20' TO p_period+2(2).
        ENDIF.
        IF p_period+4(2) GT'70'.
          MOVE '19' TO p_period+2(2).
        ENDIF.
      ELSE.
        MESSAGE 'Invalid' TYPE 'E'.
      ENDIF.
    ENDIF.

    IF p_period+4(2) EQ space.
      IF p_period+0(2) CN '0 ' AND
         p_period+2(2) CN ' '.
        MOVE p_period+2(2) TO p_period+4(2).
        IF p_period+2(2) LE'70'.
          MOVE '20' TO p_period+2(2).
        ENDIF.
        IF p_period+2(2) GT'70'.
          MOVE '19' TO p_period+2(2).
        ENDIF.
      ELSE.
        MESSAGE 'Invalid' TYPE 'E'.
      ENDIF.
    ENDIF.

    IF p_period+0(2) GT '12' OR
       p_period+0(2) LT '01'.
      MESSAGE 'Invalid' TYPE 'E'.
    ENDIF.

Hope it helps.

Rgrds,

Sravan

Read only

former_member192023
Active Participant
0 Likes
1,676

Hi Farid,

I don't think it is necessary to do this since global area people have the own format habit.

Just use sy-datum and it will automatic check whether it is right and have the search help.

Some people will maintain the format in tr-code su3.

Read only

hiriyappa_myageri
Participant
0 Likes
1,676

Hi Farid,

you can use simple write statement by specifying country specific .

You can directly convert to islamic format.

WRITE DATE yymmdd to DATE."or else u can use sy-datum.

The date format is specified by column DATFM, where "mm", "dd", and "yyyy" stand for day, month, and year. The following country-specific formats are available:

DATFMDate Format
"1"dd.mm.yyyy
"2"mm/dd/yyyy
"3"mm-dd-yyyy
"4"yyyy.mm.dd
"5"yyyy/mm/dd
"6"yyyy-mm-dd
"7"ggyy.mm.dd, Japanese date
"8"ggyy/mm/dd, Japanese date
"9"ggyy-mm-dd, Japanese date
"A"yyyy/mm/dd, Islamic date 1
"B"yyyy/mm/dd, Islamic date 2
"C"yyyy/mm/dd, Iranian date

  • In the Japanese formats for values "7", "8", and "9", the first two characters "gg" of a four-digit year are prepared as a Japanese Unicode character for the current Japanese Emperor. The last two characters "yy" signify the year of his reign.
  • In the Islamic formats for values "A" and "B", the date is prepared according to the Islamic moon calendar, which calculates time starting from 16th July 622, which is the date on which Mohammed left Mecca (Hijra). Since this calculation can be different in different Islamic countries, two formats are offered, each of which can be set individually. The respective settings are in database table TISLCAL, and can be changed using program I18N_MAINTAIN_TISLCAL.
  • The Iranian format for value "C" is based on an Islamic sun calendar, which calculates in sun years starting from the Hijra.

Regards,

Hiriyappa