How can I make my Linkage parameters more flexible?

Question ID : 267
Created on 2016-04-05 at 8:27 AM
Author : Veryant Support []

Online URL :

By using standard COBOL variables in the Linkage Section of your program to receive strings and numbers, you force the calling programs to use specific data items to pass the parameters.
For example, if you define a parameter as PIC X(100), the calling program will be able to pass that parameter using a PIC X(100) data item or a constant string, but not a PIC X ANY LENGTH data item. On the other hand, if you define a parameter as PIC X ANY LENGTH, then the calling program will be forced to use a PIC X ANY LENGTH item to pass the parameter. If you define a parameter as PIC 9(2), the calling program will be able to pass the parameter using a PIC 9(2) data item, but not computational data item or a constant number.
You can get rid of these limitations and create more dynamic routines by defining your Linkage parameters as CobolVar objects and then using the toint() and toString() methods to get the parameter value.
The following test program demonstrates the procedure:

   program-id. callee.
   configuration section.
   class cobolvar as "com.iscobol.types.CobolVar".
   |note: if you're compiling with -cp, the class name is "com.iscobol.types_n.CobolVar"
   working-storage section.
   77 string-param pic x any length.
   77 numeric-param pic s9(9).
   linkage section.
   77 param-1 object reference cobolvar.
   77 param-2 object reference cobolvar.
   procedure division using param-1, param-2.
   set string-param to param-1:>toString()
   set numeric-param to param-2:>toint()
   display "First parameter (string): " string-param.
   display "Second parameter (number): " numeric-param.

Test it with
1) constant values:

   working-storage section.
   procedure division.
   call "callee" using "xxx" 123.

2) dynamic length items

   working-storage section.
   77 dynamic-string pic x any length.
   procedure division.
   move "xxx" to dynamic-string.
   call "callee" using dynamic-string 123.

3) fixed length items and comp items

   working-storage section.
   77 fixed-string pic x(10).
   77 my-number pic 9 comp-1.
   procedure division.
   move "xxx" to fixed-string
   move 123 to my-number
   call "callee" using fixed-string my-number.

Back to Original Question