Multiple Return Values in COBOL
COBOL, being a procedural language primarily used for business applications, doesn’t have a direct equivalent for multiple return values as seen in more modern languages. However, we can simulate this behavior using multiple parameters passed by reference. Here’s how we might approach this:
In this COBOL program:
We define three working-storage variables:
WS-A
,WS-B
, andWS-C
.The
VALS-PROCEDURE
simulates returning multiple values by settingWS-A
to 3 andWS-B
to 7.In the
MAIN-PROCEDURE
, we callVALS-PROCEDURE
and then display the values ofWS-A
andWS-B
.To simulate using only a subset of the “returned” values, we call
VALS-PROCEDURE
again but only displayWS-B
.
COBOL doesn’t have a built-in concept of ignoring values (like the blank identifier _
in some languages). Instead, we simply don’t use the variable we’re not interested in.
To run this COBOL program:
This example demonstrates how to simulate multiple return values in COBOL. While it’s not as elegant as in more modern languages, it achieves a similar result by using variables in the working-storage section.
In COBOL, passing parameters by reference is a common practice for simulating multiple return values from a procedure. This approach is often used in business applications where COBOL is prevalent.