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: 

Validate month and year

Former Member
0 Kudos

Hi!

I'm a very beginner in ABAP so please don't hurt me for my question.

On my dynpro I have two fields which the user has to fill out. One for the month (01 - 12) and the second is for the year (4 characters). Now I want to validate both fields in PAI. I also want that the user could enter either e.g. "08" or "2008". If he enters just "08", the system should complete it to "2008".

Is there a easy way to do this?

Thanks for your help,

Alex

15 REPLIES 15

Former Member
0 Kudos

create the input field as standard field type.. so it'l get validted automatically.. (if validation exists for the standard one)

or do the coding manually

Former Member
0 Kudos

Hi and thanks for your very quick answer!

But could you go a bit more in detail? As I wrote above I'm very new in ABAP...

Former Member
0 Kudos

Hi,

In Flow logic editor.

PROCESS AFTER INPUT.

MODULE validate_0100.

IN ABAP editor....

DATA : v_len TYPE I.

MODULE validate_0100 INPUT.

If field1 LT 1 OR

field1 GT 12.

Message ......... "Pls. enter valid month."

ENDIF.

v_len = strlen(field2 ) .

IF v_len eq 2.

CONCATENATE '20' field2 INTO field2.

ENDIF.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 8, 2008 11:32 AM

Former Member
0 Kudos

Thanks for that!

One last question concerning this. How should I define field1 and field2? Right now I have it field1 as N(2) and field2 as N(4). Is that correct?

0 Kudos

here is one example :

field2 type ALYEAR

field1 type AFWGO_MONTH

you can search for such more data elements in SE11

0 Kudos

Hi Alexander,

Just a quick observation from the above comments..

if user enters 08 it hould be 2008

what if he enters 00 .....then it will be 2000

what if he enters 98 ..will be 1998 or 2098?????

If it is 2098..you can do as suggested,but if it is 1998..then you can't provide the user the requirement to enter just 2 of the 4 digits..he has to enter it completely

Hope i have made my point clear...

Regards

Byju

0 Kudos

Hi Alexander,

Just a quick observation from the above comments..

if user enters 08 it hould be 2008

what if he enters 00 .....then it will be 2000

what if he enters 98 ..will be 1998 or 2098?????

If it is 2098..you can do as suggested,but if it is 1998..then you can't provide the user the requirement to enter just 2 of the 4 digits..he has to enter it completely

Hope i have made my point clear...

Regards

Byju

former_member181995
Active Contributor
0 Kudos

Yes,

Alexander

Its correct either you can declear with char.

Former Member
0 Kudos

Thanks everybody for helping me!!!!

You are right. If the user enters 98 it could be 1998 and also 2098. But I would say 2098 is ok. If he need some old data from 1998 he should enter the whole year and not just 98. But thanks a lot for that!

I will check all these this evening and will let you know if it's work for me!

Regards, Alex

Former Member
0 Kudos

I'm nearly there!

The year-field is declared as NUMC (4) on my dynpro. If I enter just 08, the field is filled up with 0. So I have 0008 in there and I the length is surely 4.... where is my mistake?

Alex

0 Kudos

Go with Sharayu's suggestion, is better to declare the field with an standard data element, because they already have attached the conversion routine

Former Member
0 Kudos

I tried it already but I just have a few formats in the dynpro F6 Selection.

In my program it's declared as ALYEAR....

0 Kudos

You usually use dictionary fields in dynpros.

A good way to do it, since you are using alyear.

Type in the name of the field BSIK-GJAHR when a window asks you to refer to the dictionary, click yes, after that change the name again to the variable you are using in your program and you'll keep the conversion routines of BSIK-GJAHR

Former Member
0 Kudos

Sorry if I have to ask, but where should I enter BSIK-GJAH?

0 Kudos

In the screen painter, in the attributes of your year field. Change the name to bski-gjahr so you bring the attributes of the dictonary, after that you can change the name of the field to the variable you are using in your program