Application Development 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: 

date conversion

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member181962
Active Contributor
0 Kudos

use write statement:

write t_data-vfdat to v_date.

write: v_date.

or use fm:

CONVERT_DATE_TO_EXTERNAL

Regards,

ravi

Former Member
0 Kudos

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

Former Member
0 Kudos

use split and concatenate commands (read abap help)

BR, JAcek

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Venu,

Use write statement for ur requirement.

write t_data-vfdat to v_date

write: v_date.

Hope this is useful.

Regards,

Tushar

0 Kudos

thnx very much everybody.

the FM solved the problem.