ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

change %date() to something other than today

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

  • change %date() to something other than today

    We use %date() to get today's date in many programs. Sometimes we want to re-run with yesterday's date (or some date that is not today).
    Is there a way to change this outside the RPG program?
    Ideally something we can add to CL or the command line.

    Changing system value QDATE is not useful, as it would affect all users.

    Maybe I should go back to UDATE 0r *date for jobs I am sure will not run past midnight (but we have some of those).

    So far my solution is to comment out %date() and replace with %date(102621: *MDY), recompile, rinse and repeat. Old, slow, annoying, but effective.


  • #2
    How about an optional parm for the date?

    Comment


    • #3
      You can use %date(*DATE) to retrieve the job date.

      now = %date(); // current system date
      jobDate = %date(*DATE); // Job Date

      Comment


      • B.Hauser
        B.Hauser commented
        Editing a comment
        Should be %Date(*JOB)

      • Peder Udesen
        Peder Udesen commented
        Editing a comment
        I also thought it was *JOB but according to the manual it is *DATE

        "The special fields UDATE and *DATE contain the job date. These values are not updated when
        midnight is passed, or when the job date is changed during the running of the program."

    • #4
      Imho, it's a bad idea to use the job date. Although it takes time, it eventually almost always results in an inaccurate record being created somewhere. An invoice date is off by a day or a weekend. Or a paid date. Or something. Frequently this goes unnoticed -- but it still bothers me. Sometimes users note it and just chalk it up to "a computer error". In reality, it's not a computer error, it's a poor programming practice. If your goal is to use the current date, use the current date NOT the date the job started.

      If the only reason you're doing this is so that you can override it on special occasions, write your programs to handle those occasions. Personally, I would use an environment variable since this can be either either at the job-level or system-level and doesn't involve changing the program's interface. Seriously, to do this in just one program would take less time than it took me to type these two paragraphs. Trivial to code, powerful, and simple.

      Comment


      • #5
        I would write a procedure in a service program to return that special date value. You could then have an environment variable that your procedure would check. The environment variable could be set by some nice command or commands that could be used from the command line.

        Or, instead of an environment variable, you could have another procedure in the service program to set the type of date to return, and then your command-line programs would also bind to the service program.
        Last edited by Barbara Morris; October 28, 2021, 03:32 PM. Reason: Edit: Add info about how a service program could be used for this.

        Comment


        • #6
          For some reason I am not getting emails when this thread is updated.
          thanks for the suggestions, I will look at environment variables.
          It was also good to learn I can also use:
          jobDate = %date(*DATE); // Job Date

          Comment

          Working...
          X