Java Reference
In-Depth Information
M ETHOD O VERLOADING IN COBOL
There is no direct analogy to method overloading in COBOL, but there is a coding
technique that is pretty close. COBOL compilers will generally let you call a sub-
routine and pass fewer parameters than specified in the USING statement. Suppose
you designed a subroutine where some actions performed by the subroutine might
require two parameters, and other actions might require three. Calling programs
can pass either two or three parameters but would be responsible for passing the
correct number of parameters, based on the action requested. It would then be the
responsibility of the subroutine to make sure that no missing parameters are ac-
cessed by the subroutine during this particular call. Parameters that have been
passed can be accessed by the subroutine, but the subroutine designer must be
careful not to perform any statement that accesses an item defined in LINKAGE
SECTION but not passed by the caller. In fact, some compilers support this tech-
nique explicitly by providing a mechanism to detect (at runtime) the number of
passed parameters. In some systems, you may have to call an Assembler program to
detect the number of parameters.
MYSUB COBOL
This example manages different numbers of parameters. It uses the "GET$NARGS"
function as provided by the AcuCorp COBOL compiler.
IDENTIFICATION DIVISION.
PROGRAM-ID. MYSUB.
************************************************************************
* This routine accepts a text item as a parameter and *
* evaluates the text. If the text is all spaces, *
* MSG-SIZE will be set to 0. Else, MSG-SIZE *
* will be set to 1. *
* If requested, the text item will also be stored in the *
* passed control structure. *
* If the text item is not passed, then MSG-TEXT *
* will be evaluated instead. *
************************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ARGUMENT-COUNT PIC 9.
01 LOCAL-TEXT PIC X(20).
Search WWH ::




Custom Search