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

Validation on date field

PAL14
Participant
0 Likes
2,119

I need to validate a date field

for eg:

SELECT-OPTIONS : dat FOR ekko-aedat.

When user enter month less than 1 or greater than 12 an

error message must be shown.

Please help me with this

Thanks

Pradeep Alex

1 ACCEPTED SOLUTION
Read only

bpawanchand
Active Contributor
0 Likes
2,001

Hi

use AT SELECTION-SCREEN event to validate the fields on the selection-screen.

Regards

Pavan

Hi

use AT SELECTION-SCREEN event to validate the fields on the selection-screen.

Regards

Pavan

12 REPLIES 12
Read only

bpawanchand
Active Contributor
0 Likes
2,002

Hi

use AT SELECTION-SCREEN event to validate the fields on the selection-screen.

Regards

Pavan

Read only

former_member541575
Participant
0 Likes
2,001

Hi

AT SELECTION-SCREEN ON S_DATE.

SELECT date FROM vbrk

WHERE DATE IN S_DATE and (month >=1 || month <=12).

IF sy-subrc NE 0.

MESSAGE i000(z_msg).

ENDIF.

Read only

JozsefSzikszai
Active Contributor
0 Likes
2,001

hi Pradeep Alex,

welcome to SDN

you are on the right track already! you created the select option refering to a standard date field. it means, the check will happen automatically, no need for more coding! Just give it a try!

hoep this helps

ec

Read only

0 Likes
2,001

Is that possible to use offset for this validation,If so how it can be done.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,001

Hello,

Try this,


AT SELECTION-SCREEN ON S_DAT.
IF S_DAT-LOW+4(2) < 1 OR S_DAT-LOW+4(2) > 12.
  <ERROR MESSAGE>.
ENDIF.

I beleive this is irrelevant as SAP will automatically perform this check & throw an error message.

BR,

Suhas

Edited by: Suhas Saha on Aug 8, 2008 11:42 AM

Read only

Former Member
0 Likes
2,001

Pradeep,

AT SELECTION-SCREEN ON dat.

check here.

message.

When user enter month less than 1 or greater than 12 an

error message must be shown.

Please help me with this

am not sure from which date you want to compare month?as i believe there should be always two date for any kind of comparision.

is it with sy-datum?

Amit.

Read only

Former Member
0 Likes
2,001

Hi Pradeep,

There is no need to validate the date field. as it refers to the standard date format field, the date validation is performed automatically.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
2,001

Hi pradeep,

your field ekko-aedat has datatype DATS, i.e. dictionary standard type for date.

You do not need to give any validation.

Regards,

Anirban

Read only

Former Member
0 Likes
2,001

HI,

ekko-aedat is of type dats.

so system will automatically take care of your requirement.

No need of using at selection-screen and all theese things..

Read only

Former Member
0 Likes
2,001

SELECT-OPTIONS : dat FOR ekko-aedat.

AT SELECTION-SCREEN.

loop at dat.

if dat-low4(2) <1 and dat-low4(2) >12.

MESSAGE e000(ZRAM) with 'Enter Correct Date'.

endif.

endloop.

here ZRAM is message class you can here ur own class name.

rgds

rajesh

Read only

Former Member
0 Likes
2,001

Hi Pradeep,

As I understand your question is " How to validate and give error if the date range entered is for more than12 months or less than 1 month?"

As many of the repliers have suggested you can validate it in

At SELECTION-SCREEN ON dat. "dat is your select-option

Use FM HR_HK_DIFF_BT_2_DATES to get months between dat-low and dat-high.

If the months come out to be less than 1 or greater than 12 give appropriate error message.

Hope this solves your problem.

Thanks,

Hitesh

Read only

PAL14
Participant
0 Likes
2,001

Thanks every body for helping me