‎2014 Feb 27 10:08 AM
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.
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.
‎2014 Feb 27 10:17 AM
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
‎2014 Feb 27 10:17 AM
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
‎2014 Feb 27 10:27 AM
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
‎2014 Feb 27 10:49 AM
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
‎2014 Feb 27 10:54 AM
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.
‎2014 Feb 27 11:27 AM
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:
| DATFM | Date 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 |
Regards,
Hiriyappa