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 Format

Former Member
0 Likes
1,177

hi,

In my Internal table date field is of format dd/mm/yyyy

In the selection-screen there is an option that user can select any Date format.

If user selects any date format, It chould be converted to mm/dd/yyyy .

I have to display the date with format mm/dd/yyyy.

please help me on this .

asap

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
965

Hi,

check the code:

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-031.

PARAMETERS: date1 RADIOBUTTON GROUP rad1 DEFAULT 'X', "SAP date format YYYYDDMM

date2 RADIOBUTTON GROUP rad1, "Date format like aprial31, 2006

date3 RADIOBUTTON GROUP rad1, "Date format like 31 apr,2006

date4 RADIOBUTTON GROUP rad1, "Date format like DD/MM/YYYY

date5 RADIOBUTTON GROUP rad1. "Date format like DD.MM.YYYY

SELECTION-SCREEN END OF BLOCK b2

FORM getmonth .

SELECT mnr

ktx

ltx

INTO TABLE T_month

FROM t247

WHERE spras = 'EN'.

IF sy-subrc NE '0'.

MESSAGE I "Message - Not able to get month values from the table T247

ENDIF.

ENDFORM.

DATA : temp_date(16) TYPE c,

temp1_date(60) TYPE c,

year(4) TYPE c,

daymonth(11) TYPE c,

daymonth1(11) TYPE c,

month(9) TYPE c,

day(2) TYPE c,

mon LIKE t247-ktx,

len TYPE i .

MOVE date TO temp1_date .

CONDENSE temp1_date NO-GAPS.

MOVE temp1_date TO temp_date .

IF date2 EQ 'X'. "The date format is like Aprial 31, 2007

CONDENSE temp_date NO-GAPS.

SPLIT date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

_len = STRLEN( _daymonth1 ).

l_len = 13 - len.

SHIFT daymonth1 RIGHT BY len PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

SORT t_month BY monthltx.

READ TABLE t_month WITH KEY monthltx = month.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

len = STRLEN( month ).

CONDENSE daymonth NO-GAPS.

SHIFT daymonth LEFT BY len PLACES.

day = daymonth.

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date3 EQ 'X'. "The date format is like 31 apr, 2007

CONDENSE temp_date NO-GAPS.

SPLIT i_date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

SHIFT daymonth1 LEFT BY 2 PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

TRANSLATE month TO UPPER CASE.

SORT t_month BY monthstx.

MOVE month to mon.

READ TABLE t_month WITH KEY monthstx = mon.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

CONDENSE daymonth NO-GAPS.

day = daymonth+0(2).

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date4 EQ 'X' OR p_date5 EQ 'X'. "Date format is like DD.MM.YYYY or DD/MM/YYYY

CONDENSE temp_date NO-GAPS.

IF STRLEN( temp_date ) EQ 10.

o_date0(4) = temp_date6(4).

o_date4(2) = temp_date3(2).

o_date6(2) = temp_date0(2).

ELSE.

error = 'X'.

WRITE : 'Invalid date format.' .

ENDIF.

ENDIF.

IF STRLEN( o_date ) NE '8'.

error = 'X'.

WRITE : 'Invalid date format.'.

ENDIf.

ENDFORM. " f0100_conv_date

<b>Reward points</b>

Regards

8 REPLIES 8
Read only

Former Member
0 Likes
966

Hi,

check the code:

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-031.

PARAMETERS: date1 RADIOBUTTON GROUP rad1 DEFAULT 'X', "SAP date format YYYYDDMM

date2 RADIOBUTTON GROUP rad1, "Date format like aprial31, 2006

date3 RADIOBUTTON GROUP rad1, "Date format like 31 apr,2006

date4 RADIOBUTTON GROUP rad1, "Date format like DD/MM/YYYY

date5 RADIOBUTTON GROUP rad1. "Date format like DD.MM.YYYY

SELECTION-SCREEN END OF BLOCK b2

FORM getmonth .

SELECT mnr

ktx

ltx

INTO TABLE T_month

FROM t247

WHERE spras = 'EN'.

IF sy-subrc NE '0'.

MESSAGE I "Message - Not able to get month values from the table T247

ENDIF.

ENDFORM.

DATA : temp_date(16) TYPE c,

temp1_date(60) TYPE c,

year(4) TYPE c,

daymonth(11) TYPE c,

daymonth1(11) TYPE c,

month(9) TYPE c,

day(2) TYPE c,

mon LIKE t247-ktx,

len TYPE i .

MOVE date TO temp1_date .

CONDENSE temp1_date NO-GAPS.

MOVE temp1_date TO temp_date .

IF date2 EQ 'X'. "The date format is like Aprial 31, 2007

CONDENSE temp_date NO-GAPS.

SPLIT date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

_len = STRLEN( _daymonth1 ).

l_len = 13 - len.

SHIFT daymonth1 RIGHT BY len PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

SORT t_month BY monthltx.

READ TABLE t_month WITH KEY monthltx = month.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

len = STRLEN( month ).

CONDENSE daymonth NO-GAPS.

SHIFT daymonth LEFT BY len PLACES.

day = daymonth.

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date3 EQ 'X'. "The date format is like 31 apr, 2007

CONDENSE temp_date NO-GAPS.

SPLIT i_date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

SHIFT daymonth1 LEFT BY 2 PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

TRANSLATE month TO UPPER CASE.

SORT t_month BY monthstx.

MOVE month to mon.

READ TABLE t_month WITH KEY monthstx = mon.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

CONDENSE daymonth NO-GAPS.

day = daymonth+0(2).

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date4 EQ 'X' OR p_date5 EQ 'X'. "Date format is like DD.MM.YYYY or DD/MM/YYYY

CONDENSE temp_date NO-GAPS.

IF STRLEN( temp_date ) EQ 10.

o_date0(4) = temp_date6(4).

o_date4(2) = temp_date3(2).

o_date6(2) = temp_date0(2).

ELSE.

error = 'X'.

WRITE : 'Invalid date format.' .

ENDIF.

ENDIF.

IF STRLEN( o_date ) NE '8'.

error = 'X'.

WRITE : 'Invalid date format.'.

ENDIf.

ENDFORM. " f0100_conv_date

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
965

Hello,


data:
w_date1 type sy-datum,
w_date2(10) type c,
w_date3(10) type c,
w_dd(2) type c,
w_mm(2) type c,
w_yy(4) type c.

w_date1 = sy-datum.
write w_date1 to w_date2.
split w_date2 at '.' into w_mm w_dd w_yy.
concatenate w_dd '.' w_mm '.' w_yy into w_date3.
write w_date3.

reagrds,
Vasanth

Read only

Former Member
0 Likes
965

use this FM to convert external into internal format

CONVERT_DATE_TO_INTERNAL

Read only

0 Likes
965

Hi

Check this sample

data: lv_date type sy-datum.
data: lv_date1 type sy-datum.

data: lv_formatdate(10) type c.
data: lv_formatdate1(10) type c.

data: var1(4) type c,

var2(2) type c,

var3(2) type c.

lv_date = sy-datum.
var1 = lv_date+(4).
var2 = lv_date+4(2).
var3 = lv_date+6(2).

concatenate var3 var2 var1 into lv_formatdate separated by '.'.


Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
965

Hi,

your internal table date field is type sy-datum?

you can define it like char (len 10) but you have to perform validation control manually.

The format is a parameter of user. I don't know if there is a way to change it dinamically. I try to find somethin.

Bye

enzo

Read only

Former Member
0 Likes
965

Hi,

U can use this Following in ur code,

DATA : L_DATE(8) TYPE C VALUE '29102005', " DD/MM/YYYY

L_NEW_DATE TYPE DATS. " MM/DD/YYYY

CONCATENATE L_DATE2(2) L_DATE0(2) L_DATE+4(4)

INTO L_NEW_DATE.

Regards,

Padmam.

Read only

Former Member
0 Likes
965

hello SUDHA

the system accepts the date format as yyyymmdd.

so u hav to change format to ur required format by using following func. modules

CONVERT_DATE_TO_INTERNAL

CONVERT_DATE_TO_external.

thanks for giving solution 4 one of my thread....

definately it will works.....

Regards,

Arjun.

arjun.abap@gmail.com

Read only

Former Member
0 Likes
965

hi,

thank you for your replies.

I found the solution