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

to put validatition check on date

hi

there is data being loaded from a flat file i want to input check on date format as yyyymmdd format only please suggest how to put this check

regards

arora

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 11:07 AM

    hi Mathew and all

    its not the validation on selection screen on but date is being entered from flat file being u\plodaed and i need to check if in case use enters the wrong format in flat file for the date

    it should be validated before uploading

    in format yyyymmdd format as for dats field so user should put in this format only.

    if wrong it should be validated

    regards

    arora

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 16, 2008 at 08:00 AM
    PARAMETERS: p_dat TYPE c LENGTH 8.
    
    DATA: test_date TYPE d,
          input_date TYPE d.
    
    input_date = p_dat.
    
    test_date = input_date - 1.
    ADD 1 TO test_date.
    
    IF test_date = input_date.
      WRITE: / 'valid'.
    ELSE.
      WRITE: / 'invalid'.
    ENDIF.

    Or use FM DATE_CHECK_PLAUSIBILITY. But my code is quicker.

    matt

    Add a comment
    10|10000 characters needed characters exceeded

    • If you want to understand - run the program in debug and watch what happens to the values. Or add some more write statements like this.

      PARAMETERS: p_dat TYPE c LENGTH 8.
      
      DATA: test_date TYPE d,
            input_date TYPE d.
      
      input_date = p_dat.
      
      WRITE:/ 'Value of p_dat', p_dat DD/MM/YYYY.
      WRITE:/ 'Value of input_date', input_date DD/MM/YYYY.
      
      test_date = input_date - 1.
      WRITE:/ 'Subtracted one from input_date to give', test_date DD/MM/YYYY.
      
      ADD 1 TO test_date.
      WRITE:/ 'Added one to test_date to give', test_date DD/MM/YYYY.
      
      IF test_date = input_date.
        WRITE: / 'Test_date same as input_date, so the original date was valid'.
      ELSE.
        WRITE: / 'Test_date NOT the same as input_date, so the original date was invalid'.
      ENDIF.

      If p_dat contains an invalid date, then when you subtract one from input_date it gives you '00000000' - i.e. INITIAL for a type D.

      So you could rewrite the code:

      PARAMETERS: p_dat TYPE c LENGTH 8.
      
      DATA: input_date TYPE d.
      
      input_date = p_dat.
      SUBTRACT 1 FROM input_date.
      
      IF input_date IS NOT INITIAL.
        WRITE: / 'Subtraction from input date is not blank so the original date was valid'.
      ELSE.
        WRITE: / 'Subtraction from input date is blank so the original date was invalid'.
      ENDIF.

      matt

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 10:20 AM

    Hi Matthew

    the format which i am having is entry date is in format yyyymmdd

    i want to check on this format it should be like this only in format yyyymmdd

    regards

    arora

    Add a comment
    10|10000 characters needed characters exceeded

    • >

      > HI Nishant,

      >

      > try following

      >

      > PARAMETERS : DATE TYPE SY-DATUM.

      > THIS WILL GIVE YOU F4 HELP ON DATE.

      > OF TRY

      >

      > PARAMETERS : DATE TYPE D.

      > IN BOTH CASES YOU ARE GETTING DEFAULT CHECK.

      > I THINK THIS SHOULD WORK IN YOUR CASE.

      >

      > regards,

      >

      > Ani

      Try reading the question again. He says he's validating dates LOADED FROM A FLAT FILE.

      matt

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 12:05 PM

    hi Matthew

    i missed ur last reply for the query i raised hence raised the question which u thought i am raising again i want to have that q answered before putting the code and checking meanwhile on othe code hence didnt tried it i was about to try and test it once i have finished with up my other work meanwhile i am trying to get a feasable answere for my query and in that process missed ur below reply

    hence which u though as sppon feeding??? i think if u had problmes in the answere there is no force for it or its not binding only thing was that presently i am not in a positong to test ur code and one last query i had in my mid that woul hvve givng problem i have asked that simply and missed ur reply on it hence the confustion

    please take care for ur language for replying ......anayhow thanks for putting effort and replying...i will check on it later

    If you put any other format than a valid yyyymmdd into the program, it will tell you that it is invalid. If you put AAAAAAAAA it will say invalid. If you put in 120198 it will say invalid. If you put in 20030229 it will say invalid.

    You've asked a specific question. I've given you a specific answer. What do you not understand?

    Add a comment
    10|10000 characters needed characters exceeded

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.