Solutions to exercises
dcl-s myCharfield char(5);
myCharField = 'hello';
The CHAR data type always has the same length, so the variable contains trailing blanks, which are used when the variable is concatenated with other text.
Bonus question: What RPG built-in function could be used in the concatenation expression to produce the same output in the version where the variable is defined with the CHAR type rather than the VARCHAR type?
When the RETURN opcode is used, and *INLR is not on when the program returns, the RPG compiler does not implicitly close the file. The next time the program is called, the file is still open and still at end of file, so subsequent READ operations do not find any records and the loop exits immediately.
Bonus activity to correct the problem: Add a SETLL *START operation for the file, before the READ loop. That sets up the file so it is positioned at beginning of file, and the program works the same both times.
setll *start rpgtestf;
When the RETURN opcode is used, the RPG compiler does not implicitly close the file. The next time the program is called, the OPEN operation fails because the file already open.
Bonus activity to correct the problem: Add a check to see whether the file is already open before using the OPEN opcode.
if not %open(rpgtestf);