Skip to Content
author's profile photo Former Member
Former Member

Validate month and year

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 09:01 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 09:08 AM

    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... 😔

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 09:11 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 09:31 AM

    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?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Posted on Apr 08, 2008 at 09:38 AM

    Yes,

    Alexander

    Its correct either you can declear with char.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 10:32 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 03:13 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 03:30 PM

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

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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 04:00 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.