Search code examples
dateibm-midrangerpglerpg

In RPG, use a date, in *job format from a file


I'm trying to convert, in a RPG program, a date from a file (it's from the DSPJRN command, so the field si 6 numeric, in JOB format). I want to use it as a date in my program, but I can't achieve it correctly.

I have tried to describe a field with type "D": date, keyword datfmt(*job) to convert the value from the file, but datfmt(*job) is incorrect (error RNF0612)

I have tried to retrieve the job Date format from a CLP program with RTVJOBA DATFMT(&FMT), and use the variable in RPG to convert the date like this

eval ztJODATE = %date(JODATE:FMT)

but it doesn't compile : error RNF0606 . I think that I can't use a variable for the format in the %date built-in function.

Is this a way to do what I want, or am I forced to transform the date value in SQL before using its value in RPG? PS: I don't want to hardcode the format in my RPG program!


Solution

  • You can specify *JOBRUN for %DATE.

    eval      ztJODATE = %date(JODATE:*JOBRUN)
    

    Note that RPG retrieves the job date format during initialization of the module, so if you change the job date format while the program is running, RPG will not understand the date.