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

Function Module required to convert the date coming from external system

Former Member
0 Likes
1,803

Hi Friends,

I need a Function Module that would convert the incoming date from external sytem in format YYYYMMDD to the SAP system in DDMMYYYY. The External system data type for the date is Numberic. Please suggest any FM if you know.I found out many in SAP but didn't find for this requirement

Hi Friends,

I need a Function Module that would convert the incoming date from external sytem in format YYYYMMDD to the SAP system in DDMMYYYY. The External system data type for the date is Numberic. Please suggest any FM if you know.I found out many in SAP but didn't find for this requirement

8 REPLIES 8
Read only

thomas_jung
Developer Advocate
Developer Advocate
0 Likes
1,401

If my external data format is fixed, I usually just program this myself like the following:


data: date1(8) type n.  "Format YYYYMMDD
data: date2(8) type n.  "Format DDMMYYYY

move date1+0(4) to date2+4(4).
move date1+4(2) to date2+2(2).
move date1+6(2) to date2+0(2).

call function 'DATE_CHECK_PLAUSIBILITY'
  exporting
     DATE = date2
  exceptions
     plausibility_check_failed = 1.
if sy-subrc ne 0.
  "Do Something.
endif.
   

Read only

0 Likes
1,401

Hi Thomas,

I tried this patch of code in the LSMW, but it gave me a dump CALL_FUNCTION_CONFLICT_TYPE on the Function Module DATE_CHECK_PLAUSIBILITY. Please help.

Read only

0 Likes
1,401

Sorry about that DATE_CHECK_PLAUSIBILITY is expecting its date input parameter to be like sy-datum. Just change the defintion of date2 to the following:


  date: date2 type sydatum.

Read only

0 Likes
1,401

Hi Thomas,

I am still getting some issue with the output for date. here's my code

data: date1(8) type c value '20051225'. "Format YYYYMMDD

data: date2 type sy-datum. "Format DDMMYYYY

data: f_date type datum.

data: l_year(4),

l_month(2),

l_day(2).

move date10(4) to date24(4).

move date14(2) to date22(2).

move date16(2) to date20(2).

l_year = date2+4(4).

l_month = date2+2(2).

l_day = date2+0(2).

concatenate l_day l_month l_year into f_date.

condense f_date.

write: f_date.

the expected should be 25122005 but I am getting the date output as 05.20.2512. I checked the UserProfile Own data of the system,it is set fine to DDMMYYYY.

Read only

0 Likes
1,401

Thanks Thomas ..I got the solution.The FM is CONVERSION_EXIT_PDATE_OUTPUT

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
1,401

Hello Mira,

In SAP, date is always stored in format YYYYMMDD. Depending on your format, it will be displayed on the screen or printer based on that format when you use WRITE statement to screen or text. You can't have a field in date format stored as DDMMYYYY.

Read only

0 Likes
1,401

Wait a minute. I am definetely missing something here. You want to convert from an external format YYYYMMDD to SAP's internal format? SAP's internal format is YYYYMMDD.

All you should have to do is move you external date directly to your internal date.


data: date1(8) type c value '20051225'. "Format YYYYMMDD
data: date2 type sy-datum. "Format (YYYYMMDD)

write: / date2.

When you write out date2 it will be in whatever format your user profile has.

If you want to force the date format independent of your user profile settings during the write statement:


write: / date2 DDMMYY.

Message was edited by: Thomas Jung

Read only

Former Member
0 Likes
1,401

If the user default settings are DD.MM.YYYY, you can use the WRITE statement, e.g.

DATA: v_date1 TYPE dats,

v_date2(8) TYPE c.

v_date1 = sy-datum.

WRITE v_date1 TO v_date2.

v_date1 will be in format YYYYMMDD

v_date2 will be in format DDMMYYYY (according to user settings)