Microsoft KB Archive/58104

Functions Cannot Return Strings to Calling COBOL Programs

PSS ID Number: Q58104 Article last modified on 01-30-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: It is not possible for a function created in assembly language, C, Pascal, or FORTRAN to return a string to a calling COBOL program as the return value of the function. This information applies to Microsoft COBOL Versions 3.00 and 3.00a for MS-DOS and MS OS/2. Although RETURN-CODE can be used in COBOL to retrieve the address of the string data in memory, COBOL cannot use this information or assign the string data to a PIC X field. In other words, the address returned by RETURN-CODE can be thought of as a “pointer” to the string. However, COBOL has no way of manipulating pointers or addresses to make them point to its own data items. Because it cannot use the pointer, it cannot access the data being returned from the C, Pascal, FORTRAN or assembly routine. To work around this, convert the function into a subroutine (or “procedure” as they are called in Pascal) with an extra parameter to pass back the returned string. The COBOL program can then call the routine and pass a PIC X field by reference. The other-language routine can then store the string information in the passed PIC X field.

Copyright Microsoft Corporation 1990.