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 validation in the selection screen

Former Member
0 Likes
3,976

Hi

I am new to all this..so pls help me with this...

I need to validate my input field in the selection screen to have the format as YYYYMMDD i.e user is allowed to enter the date in this format only!!

Now how to validate this kind of a format??

12 REPLIES 12
Read only

Former Member
0 Likes
2,314

Hi,

Declare the date field in reference to Sy-datum.

Data p_date type sy-datum.

<b>Reward if helpful.</b>

Read only

Former Member
0 Likes
2,314

Hi

Check this... put is in at selection-screen event..

Thanks,

Mahesh

Read only

Former Member
0 Likes
2,314

Hi

That's INPUT format just one used to save a date, so u need to check it only.

It's the same if you used a DATS format, because its INPUT FORMAT is the same, for example, output format of SY-DATUM is DD.MM.YYYY, but input format is YYYYMMDD, so:

PARAMATERS: P_DATE LIKE SY-DATUM.

AT SELECTION-SCREEN.

IF P_DATE < SY-DATUM.

MESSAGE E208(00) 'Error'.

ENDIF.

In your case the INPUT and OUTPUT format are the same so:

PARAMATERS: P_DATE(8) TYPE N.

AT SELECTION-SCREEN.

IF P_DATE < SY-DATUM.

MESSAGE E208(00) 'Error'.

ENDIF.

Max

Read only

0 Likes
2,314

thanks for the quick response!!

one thing i want to add more is that if i make it as sy-datum then thew error msg i get (in case when the format entered is wrong is as:

Enter date in the format _ / _ /_ _ _ _

but what i want is YYYYMMDD

Read only

0 Likes
2,314

For this you have to change the usre profile attributes.

Go to transaction SU3 - in that default tab select your date format.

Reward if helpful.

Read only

0 Likes
2,314

but then this will be system dependent???

Read only

0 Likes
2,314

can we display error msg without creating any message class??

Read only

Former Member
0 Likes
2,314

LV_DAY = SY-DATUM+6(2).

LV_MON = SY-DATUM+4(2).

LV_YEAR = SY-DATUM+0(4).

in place of sy-datum you can take the date of your requirement.

verify that lv_day <= 31

and lv_month <= 12.

regards,

srinivas

<b>*reward for useful answers*</b>

Read only

0 Likes
2,314

thanks i think ur solution will work the best!!

one more thing ..can we display error msg without creating any message class??

Read only

Former Member
0 Likes
2,314

Hi,

Write the below code in the INITIALIZATION event.

data: OLD_DATE TYPE SY-DATUM,

NEW_DATE(10).

OLD_DATE = SY-DATUM.

CONCATENATE OLD_DATE0(4) '/' OLD_DATE4(2) '/' OLD_DATE+6(2) INTO

NEW_DATE.

write:/ 'OLD DATE:', old_date,

/ 'NEW_DATE:', new_date.

Read only

former_member194669
Active Contributor
0 Likes
2,314

Hi,

Try this way by using SAP standard message class

message e398(00) with 'Testing'.

aRs

Read only

former_member194669
Active Contributor
0 Likes
2,314

Hi,

Here in above example you have not created any message class. you are using sAP standard message class 00 and and its message number 398. Here message number 398 have 4 place holders (ie & & & & ) so you can pass 4 texts to shows as message

Otherwise if you want to display a message without using message statement then

use function module

POPUP_TO_INFORM.

aRs