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

Error in Date Conversion

Former Member
0 Likes
1,383

Hi,

I am getting erro in the date conversion.

If i pass the value as 07/16/2008 into p_indate

DATA: l_v_datval(10) TYPE c,

l_v_datfm TYPE usr01-datfm,

l_v_delim(1) TYPE c.

l_v_datval = p_indate.

  • "-----------------------------------------------

  • " Strip date of all delimiters and spaces.

  • "-----------------------------------------------

DO.

IF sy-subrc <> 0. EXIT. ENDIF.

REPLACE l_v_delim WITH '' INTO l_v_datval.

ENDDO.

CLEAR sy-subrc.

CONDENSE l_v_datval NO-GAPS.

  • "-----------------------------------------------

  • " Put date in standard SAP format of YYYYMMDD.

  • "-----------------------------------------------

CASE l_v_datfm.

WHEN '1'.

CONCATENATE l_v_datval4(4) l_v_datval2(2) l_v_datval(2)

INTO l_v_datval.

WHEN '2'.

CONCATENATE l_v_datval+4(4) l_v_datval(4)

INTO l_v_datval.

Here aftr the conversion i'm getting the value as 008716 in l_v_datval.

WHEN '3'.

CONCATENATE l_v_datval+4(4) l_v_datval(4)

INTO l_v_datval.

WHEN OTHERS. "Already in YYYYMMDD format

ENDCASE.

p_outdate = l_v_datval.

Any sugestions..

Thanks.

Kumar.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,338

Hi Kumar

Have you try this ?

5.1 FORMATTIME

Selects the format of date and time.

5.1.1 Format

FORMATTIME

ABSTIME(data-area)

[DATE(data-area)]

[DATEFORM(data-area)]

[DATESEP[(data-value)]]

[DAYCOUNT(data-area)]

[DAYOFMONTH(data-area)]

[DAYOFWEEK(data-area)]

[DDMMYY(data-area)]

[DDMMYYYY(data-area)]

[MMDDYY(data-area)]

[MMDDYYYY(data-area)]

[MONTHOFYEAR(data-area)]

[TIME(data-area) [TIMESEP[(data-value)]]]

[YEAR(data-area)]

[YYDDD(data-area)]

[YYDDMM(data-area)]

[YYMMDD(data-area)]

[YYYYDDD(data-area)]

[YYYYDDMM(data-area)]

[YYYYMMDD(data-area)]

ps: ref site http://www1.sqp.com/MasterIndex/release_notes/release_notes_010afa7c.txt

Enjoy!

Wiparat

8 REPLIES 8
Read only

Former Member
0 Likes
1,338

Ram,

Use the function HRGPBS_HESA_DATE_FORMAT to convert to YYYYMMDD format.

Rgds,

Naren

Read only

0 Likes
1,338

Hi,

I need the format in yyyyddmm.

like if i pass 07/16/2008 i need it in 2008716.

Thanks

Kumar

Read only

0 Likes
1,338

Try CONVERT_DATE_TO_INTERNAL or here is another way to do it....

data: date(8),
date1(10) type c,
day(2),
Month(2),
year(4).

date1 = '06/29/2007'.
day = date1+3(2).
month = date1+0(2).
year = date1+6(4).

concatenate year month dat into date.

write :/ date1.
write :/ date.

Read only

0 Likes
1,338

Hi,

Is it possible to get those values after condensing the value in the field.

Thanks

Kumar

Read only

0 Likes
1,338

Check the date format in SU3 and if it in the same format like mm/dd/yyyy....then do this...

WHEN '2'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    date_external                  =  date_external "has format mm/dd/yyyy
*   ACCEPT_INITIAL_DATE            = ACCEPT_INITIAL_DATE
  IMPORTING
  DATE_INTERNAL                  = DATE_INTERNAL "has format yyyymmdd
* EXCEPTIONS
*   DATE_EXTERNAL_IS_INVALID       = 1
*   OTHERS                         = 2
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*

If you want your code to work then let me know what is the value in the date variable l_v_datval by putting a break point there....

Ram,

After looking at your code I dont see any reason for using the code

REPLACE l_v_delim WITH '' INTO l_v_datval.
ENDDO.
CLEAR sy-subrc.
CONDENSE l_v_datval NO-GAPS.

Why do you want to strip all slashes and spaces? your requirement is to convert the date format to YYYYMMDD based on the value in datfm field....right?

Am I missing somethign here?

Rgds,

Naren

Edited by: Naren K Someneni on Jul 17, 2008 10:52 AM

Edited by: Naren K Someneni on Jul 17, 2008 10:55 AM

Read only

Former Member
0 Likes
1,339

Hi Kumar

Have you try this ?

5.1 FORMATTIME

Selects the format of date and time.

5.1.1 Format

FORMATTIME

ABSTIME(data-area)

[DATE(data-area)]

[DATEFORM(data-area)]

[DATESEP[(data-value)]]

[DAYCOUNT(data-area)]

[DAYOFMONTH(data-area)]

[DAYOFWEEK(data-area)]

[DDMMYY(data-area)]

[DDMMYYYY(data-area)]

[MMDDYY(data-area)]

[MMDDYYYY(data-area)]

[MONTHOFYEAR(data-area)]

[TIME(data-area) [TIMESEP[(data-value)]]]

[YEAR(data-area)]

[YYDDD(data-area)]

[YYDDMM(data-area)]

[YYMMDD(data-area)]

[YYYYDDD(data-area)]

[YYYYDDMM(data-area)]

[YYYYMMDD(data-area)]

ps: ref site http://www1.sqp.com/MasterIndex/release_notes/release_notes_010afa7c.txt

Enjoy!

Wiparat

Read only

0 Likes
1,338

Hi,

Thanks for the replies,

The issues is resolved.

Thanks & Regards.

Kumar.

Read only

Former Member
0 Likes
1,338

Issue Resolved