ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Check for blank dates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check for blank dates

    I am using

    Code:
    A            S2CMDT          L  B 21 23DSPATR(CS)  
    A                                DATFMT(*MDY)
    in my spec for dates. I call them true dates because we commonly use decimals for dates as well.

    I created a program to maintain a file, which recently I went back and added some more date fields, again using 'true' dates.

    The problem is that when I open a pre-existing item from the table, using a chain, I get errors becase the year portion on the date isn't in the correct year.

    Code:
     The year portion of a Date or Timestamp value is not in the correct range
    So, I tried using MAPVAL, with 01/01/40, 01/01/1940, with a combo of *BLANKS and *ZEROS.

    I then tried to check to see if the date was blank or zeros, or
    Code:
     if mydate = d'01/01/40'
    and I can't get the program to compile.

    My question is, how do I not read a blank date from the file if it exists? How can I either check for it during the chain, or override the blank with something in the DDS.

    Thanks!

    Adein

  • #2
    Re: Check for blank dates

    try if date = *LOVAL
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Check for blank dates

      When you compile the program, the RPG compiler create a hidden routine to convert the date data type S2CMDT field in you program to the S2CMDT *MDY field on the screen. If the program field contains a year less than 1940 then you are going to crash.

      So, assuming *ISO dates internally, in your program you need to convert the '0001-01-01' in S2CMDT to '1940-01-01'. In the DDS MAPVAL(('1940-01-01' *BLANK)) DATFMT(*MDY) or I prefer DATFMT(*JOB).

      Since your date is also an input field, after the EXFMT you will have to test for S2CMDT = d '1940-01-01' and convet it back to '0001-01-01'.
      Denny

      If authority was mass, stupidity would be gravity.

      Comment


      • #4
        Re: Check for blank dates

        What is the value in the date field?

        Also what are your H specs?
        Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

        Comment


        • #5
          Re: Check for blank dates

          The thing that is getting me right now, is that no matter what order I put the MAPVAL(('1940-01-01' *BLANK)) DATFMT(*MDY) in (speaking of the date) I can't get the screen file to compile.

          I changed the *Blank to *Blanks just in case that was the issue, but no.

          It tells me.

          PHP Code:
           CPD5117      30        1      Message . . . . :   Syntax of datetime or timestamp value is not valid.
           * 
          CPD7494      20        1      Message . . . . :   Keyword value not allowed.
           * 
          CPD7520      20        1      Message . . . . :   Keyword ignored because of error in list of values

          With the if date = *loval I get right and left operands are not equal error.


          Any more thoughts?

          Thanks again!

          -Adein

          Comment


          • #6
            Re: Check for blank dates

            Hi Adein:

            I got this:
            Code:
            00030A            DATFLD1         L         DATFMT(*MDY) DATSEP('/')
            00040A                                      MAPVAL(('01/01/40' *BLANK))
            Here:


            If the explicit value is a date (L) value, you must use the format that the DATFMT keyword specifies. If the DATFMT keyword is not specified or if DATFMT specifies *JOB, then you must use the *ISO format. Also, you must use the separator that the DATSEP keyword specifies. If the DATSEP keyword is not specified for the separator specified on DATSEP is *JOB, a slash (/) must be used for the separator.
            Best of Luck
            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment


            • #7
              Re: Check for blank dates

              Originally posted by DeadManWalks View Post
              What is the value in the date field?

              Also what are your H specs?
              The date is blank. I added a date field to the program after someone started entering in information. Now, I could fix all this by writing a quick script to fill the dates, but I am trying to get the real answer.

              H DATFMT(*MDY)

              Comment


              • #8
                Re: Check for blank dates

                Hi Adein:
                Code:
                 MAPVAL(('1940-01-01' *BLANK)) DATFMT(*MDY)
                If the DATSEP keyword is not specified for the separator specified on DATSEP is *JOB, a slash (/) must be used for the separator.
                1. You can't use - without using datsep('-')
                2. 1940-01-01 is NOT *MDY format
                see my post above for IBM reference material

                Best of Luck
                GLS
                The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                Comment


                • #9
                  Re: Check for blank dates

                  Originally posted by GLS400 View Post
                  Hi Adein:

                  I got this:
                  Code:
                  00030A            DATFLD1         L         DATFMT(*MDY) DATSEP('/')
                  00040A                                      MAPVAL(('01/01/40' *BLANK))
                  Here:




                  Best of Luck
                  GLS
                  That seemed to work. That is a great reference!

                  Comment


                  • #10
                    Re: Check for blank dates

                    I am still getting a crash when loading the program.

                    Right after the *INZR I do the following for each of the dates.

                    Code:
                    IF ISTARDT = d'01/01/40';
                       S2ASGDT = d'01/01/40';
                    ELSE;                    
                       S2ASGDT = ISASGDT;    
                    ENDIF;
                    Code:
                     A            S2ASGDT         L  B 19 23DATFMT(*MDY)               
                     A                                      MAPVAL(('01/01/40' *BLANK))
                     A                                      DSPATR(CS)
                    With S2 being the screen date and IS being the physical file variable name from a chain. The program compiles, but when you open a record that already existed before I added the dates, it fails.

                    I really appreciate the help everyone!

                    -Adein

                    Comment


                    • #11
                      Re: Check for blank dates

                      what is the value of ISASGDT when it blows up? you should verify that that value is a valid date prior to assigning the value to the S2 field.
                      Last edited by tomholden; February 23, 2010, 03:57 PM.
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: Check for blank dates

                        Originally posted by tomholden View Post
                        what is the value of ISASGDT when it blows up? you should verify that that value is a valid date prior to assigning the value to the S2 field.
                        Ok, now I am all kinds of backwards. I don't know my dates from the next one...I guess. Ok. If I wrkqry the file I get 01/01/0001 for the dates. I don't understand how that is possible....

                        If I run a debug statement, I get to the chain, it fails on the read.

                        Comment


                        • #13
                          Re: Check for blank dates

                          01/01/0001 = *USA format
                          All my answers were extracted from the "Big Dummy's Guide to the As400"
                          and I take no responsibility for any of them.

                          www.code400.com

                          Comment


                          • #14
                            Re: Check for blank dates

                            Im lost as to what you are doing.

                            On my system this
                            PHP Code:
                             S2CMDT          L  B 21 23DSPATR(CS)  
                            A                                DATFMT(*MDY
                            would be this - putting format of *MDY would only confuse it! cause its a length of 10
                            S2CMDT D(10*ISO-)
                            All my answers were extracted from the "Big Dummy's Guide to the As400"
                            and I take no responsibility for any of them.

                            www.code400.com

                            Comment


                            • #15
                              Re: Check for blank dates

                              What is the format of the date on the database?

                              If it is the default of *ISO then a "blank" date field will probably contain 0001-01-01 since that is not acceptable for a two digit year date it can never work.

                              Maybe you have an *MDY on the H-spec? so all dates being read are forced to *MDY and away she blows. That will happen within the CHAIN/READ itself.

                              Only cure is to ensure that the date field in question is read into the program with a four digit year. Do that by explicitly defining the date field in the program. Then you can test it for *LOVAL and adjust to the 2 digit year *lowval (1949-01-01) if needed.

                              Comment

                              Working...
                              X