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,521

Hi Abapers,

I'm reading data from an excel into a internal table.

Date format in excel is: MM/DD/YYYY

so its reading the same into my internal table.

I want to convert it into 'YYYYMMDD' format.

I'm able to do this with below logic: below logic works for 12/27/2007

MOVE: wa_infile-begda+0(2) TO v_mth,

wa_infile-begda+3(2) TO v_day,

wa_infile-begda+6(4) TO v_year.

CONCATENATE v_year v_mth v_day INTO wa_modify-begda.

But this is not working when day and month is greater than 9.

for example: 1/1/2007

this should be converted to 20070101

How can i achieve this.

Please help me. its urgent.

1 ACCEPTED SOLUTION
Read only

former_member386202
Active Contributor
0 Likes
1,294

Hi,

Try this FM " CONVERT_DATE_TO_INTERNAL "

Regards,

Prashant

6 REPLIES 6
Read only

naimesh_patel
Active Contributor
0 Likes
1,294

You can avoid it with SPLIT command.

data: v_month(2) type n,
v_day(2) type n,
v_year(4) type n.

data: l_date(10) value '1/1/2007'.

split l_date at '/' into v_month v_day v_year.
concatenate v_year v_month v_day into l_begda.

write: l_begda.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,294

Use the FM CONVERT_DATE_INPUT......it will convert 1/1/2007 to 01/01/2007 then use u'r logic.......

Regards,

Arun.

Read only

former_member386202
Active Contributor
0 Likes
1,295

Hi,

Try this FM " CONVERT_DATE_TO_INTERNAL "

Regards,

Prashant

Read only

0 Likes
1,294

Thanks a lot prashant. its done.

Read only

Former Member
0 Likes
1,294

REPORT ztest37.

DATA: l_month(2) TYPE n,

l_day(2) TYPE n,

l_year(4) TYPE n.

DATA l_begda(10).

DATA: l_date(10) VALUE '01/01/2007'.

DATA : BEGIN OF itab OCCURS 0,

ddate(10) TYPE c,

dkey(10) TYPE c,

name(20) TYPE c,

END OF itab.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = 'Z:\ABAP\files\Job Tracking1.txt'

filetype = 'DAT'

  • ITEM = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

TABLES

data_tab = itab[]

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • OTHERS = 7

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT itab.

SPLIT itab-ddate AT '/' INTO l_month l_day l_year.

CLEAR itab-ddate.

CONCATENATE l_year l_month l_day INTO itab-ddate .

MODIFY itab.

WRITE : /10 itab-ddate,30 itab-dkey,50 itab-name.

ENDLOOP.

Read only

saurabhjitkr
Member
0 Likes
1,294

"""""""""""YYYYMMDD TO DD/MM/YYYY"""and DDMMYYYY To DD/MM/YYYY """"""""""""

DATA(LV_DATE) = '10122023'. "DDMMYYYY
DATA(LV_DATE2) = '20231210'. "YYYYMMDD

DATA : LV_FORMAT(10) TYPE C,
LV_FORMAT2(10) TYPE C,
LV_FORMAT3(10) TYPE C,
LV_FORMAT4(10) TYPE C.

CONCATENATE LV_DATE+(2) '/' LV_DATE+2(2) '/' LV_DATE+4(4) INTO LV_FORMAT. ""DDMMYYYY To DD/MM/YYYY

CONCATENATE LV_DATE2+6(2) '/' LV_DATE2+4(2) '/' LV_DATE2+0(4) INTO LV_FORMAT4. "YYYYMMDD TO DD/MM/YYYY

LV_FORMAT2 = LV_DATE+(2) && '/' && LV_DATE+2(2) && '/' && LV_DATE+4(4). ""DDMMYYYY To DD/MM/YYYY

LV_FORMAT3 = LV_DATE2+6(2) && '/' && LV_DATE2+4(2) && '/' && LV_DATE2+0(4). "YYYYMMDD TO DD/MM/YYYY

WRITE : LV_FORMAT , LV_FORMAT2 , LV_FORMAT3 , LV_FORMAT4.