× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 2024-02-14 7:34 p.m., smith5646midrange@xxxxxxxxx wrote:
I really failed by omitting too much code from my example. I really can't stack them because not every procedure will be called every time. For example, the middle procedure might only run if it is processing a specific type of record but the last procedure will always be called, assuming errors were not found in the previously called procedures.

I was really hoping there was some new type of GOTO that was available in free format but not as ugly to the program internally. We all know how wonderful a GOTO out of a procedure cleaned up after itself.


Instead of using an indicator to keep track of whether an error occurred, you could define a set of error codes to describe all the possible error conditions.

Then code something like this modification from the original post in this thread.

Begin Main;
dcl-s rc int(10) inz(0);
Display screen for input;
rc = Procedure1();
... check rc
Display screen showing results of processing;
End Main;

Begin Procedure1
dcl-s rc int(10) inz(0);
rc = Procedure2();
If rc > 0;
return rc;
endif;
rc = Procedure3();
If rc > 0;
return rc;
endif;
rc = Procedure4();
If rc > 0;
return rc;
endif;
.more code

return 0; // ok
End Procedure1;

Begin Procedure2;
dcl-s rc int(10) inz(0);
Whatever code is needed
If an error is encountered.
rc = some_specific_error_code;
Return rc;
Endif;
return 0; // ok
End Procedure2;

Begin Procedure3;
dcl-s rc int(10) inz(0);
Whatever code is needed
If an error is encountered.
rc = some_specific_error_code;
Return rc;
Endif;
return 0; // ok
End Procedure3;

Something similar could be done with SND-MSG and ON-EXCP. If an error message is sent deep into the calls, it will get handled by the Main procedure and all the intermediate procedures will just end. If those intermediate procedures needed to do some cleanup, they could have an ON-EXIT section to handle that.

Begin Main;
Display screen for input;
MONITOR;
Procedure1();
ON-EXCP MSG_BAD_THING_A; // named constant for some message ID
// bad thing A happened
ON-EXCP MSG_BAD_THING_B;
// bad thing B happened
ENDMON;
Display screen showing results of processing;
End Main;

Begin Procedure1
Procedure2();
Procedure3();
Procedure4();
.more code
End Procedure1;

Begin Procedure2;
Whatever code is needed
If an error is encountered.
SND-MSG *ESCAPE %MSG(MSG_BAD_THING_A);
Endif;
End Procedure2;

Begin Procedure3;
Whatever code is needed
If an error is encountered.
SND-MSG *ESCAPE %MSG(MSG_BAD_THING_B);
Endif;
End Procedure3;

Me, I prefer handling errors with exceptions rather than using error indicators or return codes. It's too easy to forget to code the check for an error.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.