I am trying to come up with a good approach to handle errors in an RPGLE program with a number of SubProcedures.
dcl-proc getWorkKeyString;
dcl-pi *n ind ;
workKeyArray likeDS(parentWorkKeyArray) dim(500);
workKeyString like(ISWCDUPDS.IWKEY_ISWC);
end-pi;
index = 1;
dow (index < 500);
monitor;
if ( workKeyArray(index).workKey <> 0);
if (index > 1);
workKeyString = %Trim(workKeyString) + '|';
endif;
workKeyString = %Trim(workKeyString) + %char(workKeyArray(index).workKey);
endif;
index = index + 1;
on-error;
return cFalse;
endmon;
enddo;
return cTrue;
end-proc;
As you can see, I have enclosed the do while body in a monitor group. If some error comes up, a false is returned from the sub procedure to indicate error. But please let me know if this looks like a good approach.