Here's a pretty straight forward way to add messages to the job log from your RPGLE program.
I do not remember where I originally found this technique but I have been using IBM's Qp0zLprintf API for quite some time now. This API works like the "C" language printf() function. I'll leave it up to the reader to look up all the options for printf().
Here is an example program:
**FREE
DCL-PR WriteToJoblog INT(10) EXTPROC('Qp0zLprintf');
*n POINTER VALUE OPTIONS(*STRING);
*n POINTER VALUE OPTIONS(*STRING:*NOPASS);
// you can repeat the second parm more if desired
END-PR;
DCL-S identity INT(10) INZ(22);
DCL-S name CHAR(20);
EXEC SQL SELECT NAME INTO :name
FROM CUSTOMER WHERE IDENTITY = :identity;
IF SQLSTATE = '02000';
WriteToJoblog('No record found in CUSTOMER for identity %s.' + x'25':
%CHAR(identity));
ENDIF;
RETURN;
I prototyped the Qp0zLprintf API with two parameters here and took advantage of the %s replacement character. You can add more optional parameters if you want to allow for more replacement characters. You can also just use one parameter and concatenate the string yourself. The important thing is to be sure to add the x'25' (line feed character) to the end of the string. Without that, your message will not show up in the job log.
In the example program, you can see I am testing the results of an SQL statement and writing a job log message based on that.
Here's what the job log looks like after running this example program:
Now, don't go crazy and write lots of messages to the job log. To me, the biggest use of this is to write out some details that would make errors more clear when they happen. A good example may be following an ON-ERROR statement where you can write out some key variables that could have triggered the error.
I hope this was helpful. Leave a comment if you have any questions.
Here's a pretty straight forward way to add messages to the job log from your RPGLE program.
I do not remember where I originally found this technique but I have been using IBM's Qp0zLprintf API for quite some time now. This API works like the "C" language printf() function. I'll leave it up to the reader to look up all the options for printf().
Here is an example program:
I prototyped the Qp0zLprintf API with two parameters here and took advantage of the %s replacement character. You can add more optional parameters if you want to allow for more replacement characters. You can also just use one parameter and concatenate the string yourself. The important thing is to be sure to add the x'25' (line feed character) to the end of the string. Without that, your message will not show up in the job log.
In the example program, you can see I am testing the results of an SQL statement and writing a job log message based on that.
Here's what the job log looks like after running this example program:
Now, don't go crazy and write lots of messages to the job log. To me, the biggest use of this is to write out some details that would make errors more clear when they happen. A good example may be following an
ON-ERROR
statement where you can write out some key variables that could have triggered the error.I hope this was helpful. Leave a comment if you have any questions.