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 conversion

Former Member
0 Likes
1,814

Hi experts,

I'm doing a date converstion on my existing date field in a internal table.

the current logic is like this.

<b>data: v_date(10).</b>

actually the current date format for this variable is: mm/dd/yyyy.

<b>data: begin of i_table occurs 0,

sdate(10) type c,

end of i_table.</b>

then i'm doing the date conversion like this:

<b> move t_data-vfdat to v_date.

move '20' to t_data-vfdat(2).

move v_date6(2) to t_data-vfdat2(2).

move v_date(2) to t_data-vfdat+4(2).

move v_date3(2) to t_data-vfdat6(2).</b>

this logic is working fine if the date is for eg: 12/25/2006.

but it is failing when the dates are like: 2/22/2004.

could you please tell me how to overcome this.

thnx much for the help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,031

Hi venu. Try using FM CONVERT_DATE_TO_INTERNAL.

You will need to replace every / with . for the FM to work.

Hope it helps

Message was edited by: Jesus Bohorquez

8 REPLIES 8
Read only

Former Member
0 Likes
1,031

use write statement:

write t_data-vfdat to v_date.

write: v_date.

or use fm:

CONVERT_DATE_TO_EXTERNAL

Regards,

ravi

Read only

Former Member
0 Likes
1,032

Hi venu. Try using FM CONVERT_DATE_TO_INTERNAL.

You will need to replace every / with . for the FM to work.

Hope it helps

Message was edited by: Jesus Bohorquez

Read only

Former Member
0 Likes
1,031

use split and concatenate commands (read abap help)

BR, JAcek

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,031

Your code looks familiar, I think I answered a question like this yesterday. Anyway here is how you can convert the date. Notice that column 1 is formatted externally, and the second is the internally formatted.



data: begin of i_table occurs 0,
      sdate(10) type c,
      fdate type sy-datum,
      end of i_table.

i_table-sdate = '2/22/2006'.  append i_table.
i_table-sdate = '12/31/2006'.  append i_table.


loop at i_table.
  call function 'CONVERT_DATE_TO_INTERNAL'
       exporting
            date_external = i_table-sdate
       importing
            date_internal = i_table-fdate.
  modify i_table.

endloop.


loop at i_table.
  write:/ i_table-sdate, i_table-fdate.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,031

Hi Venu,

Consider this code.



REPORT zztest_arun_2.

DATA: e_date(10) type c VALUE '2/2/2006',
      i_date(10).

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    date_external            = e_date
  IMPORTING
    date_internal            = i_date
  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.

WRITE : / 'My   Date:' , e_date,
          'Conv Date:',  i_date.

Regards,

Arun Sambargi.

Read only

Former Member
0 Likes
1,031

Hi Venu,

Use the Function module <b>CONVERT_DATE_TO_INTERNAL</b>

  CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
       EXPORTING
            DATE_EXTERNAL            = External date
       IMPORTING
            DATE_INTERNAL            = Internal Date
       EXCEPTIONS
            DATE_EXTERNAL_IS_INVALID = 1
            OTHERS                   = 2

.

or else you can write the code as below.

<b>data: v_date(10). 
data: date like sy-datum.

move: V_DATE to DATE.
write : Date to V_DATE.</b>

so this V_DATE now contain the user format date ...

Close the thread if your problem solved

Thanks

Sudheer

Read only

Former Member
0 Likes
1,031

Hi Venu,

Use write statement for ur requirement.

write t_data-vfdat to v_date

write: v_date.

Hope this is useful.

Regards,

Tushar

Read only

0 Likes
1,031

thnx very much everybody.

the FM solved the problem.