Using Type Definitions

When you use call prototypes in your programs, an error occurs if there is a mismatch between data-types. To avoid this error, and to code the CALL statement and USING parameters correctly, the data description entry of the USING parameter in the call prototype must be duplicated in the program calling that prototype. If you were to do this manually, such duplication could lead to code maintenance problems, and perhaps lead to inconsistencies when you were creating programs.

To enable easy duplication of data description entries, you can create COBOL type definitions in the Linkage Section of the call prototype, which you can then reference in the calling and called programs. To create a COBOL type definition, you code a data description that includes the TYPEDEF clause. The name you give the data item then becomes a type definition. You can then code a data item with a USAGE clause that references the type definition. For example:

 01  callee-value-t           pic x(2) comp-5 is typedef.
 01  callee-value             usage callee-value-t.
 

In this example the type definition is callee-value-t.

Here is the complete call prototype and a program that calls a subroutine based on this prototype:

program-id. MYROUTINE is EXTERNAL.
 linkage section.
 01  callee-value-t           pic x(2) comp-5 is typedef.
 01  callee-value             usage callee-value-t.
 procedure division using callee-value.
 end program MYROUTINE.

 program-id. MYMAIN.
 working-storage section.
 01  .
     05 caller-value          usage callee-value-t.
 procedure division.
     call 'MYROUTINE' using caller-value
 end program MYMAIN.

You can use the TYPEDEF clause not only on elementary data descriptions, but also on group items and even on entire record structures. For example:

program-id. MYROUTINE is EXTERNAL.
 linkage section.
 01  callee-value-t is typedef.
     05  callee-value-item-1  pic x(2) comp-5.
     05  callee-value-item-2  pic x(4).
 01  callee-value             usage callee-value-t.
 
 procedure division using callee-value.
 end program MYROUTINE.

 program-id. MYMAIN.
 working-storage section.
 01  .
     05 caller-value          usage callee-value-t.
 procedure division.
     move 123      to callee-value-item-1 of caller-value
     move 'abcdef' to callee-value-item-2 of caller-value
     call 'MYROUTINE' using caller-value
 end program MYMAIN.

All data items defined as type definitions in a call prototype are available to any programs using that prototype.

For detailed information on the TYPEDEF clause, see the topic The TYPEDEF Clause in the section Data Division - File and Data Description in your Language Reference.