Passing data by value between C++ and COBOL

Copies of variables can be passed between C++ and COBOL. On return, the actual value of the variable remains unchanged, regardless of how it may have been modified in the called routine.

To pass data by value (direct) from C++ to COBOL, the variables are passed by C++ as arguments on a function call and received by COBOL as BY VALUE parameters. Conversely, to pass data by value (direct) from COBOL to C++, the variables are passed by COBOL as BY VALUE arguments and received by C++ as function parameters. In all cases, the variable must be declared in C++ and COBOL with compatible base data types. For example, if a C++ function called FROMCOB is to receive a parameter passed by value (direct) of type int, the function prototype declaration would look like this:
void FROMCOB(int)
Data can also be passed by value (indirect) from COBOL to C++. In this case, the variable is passed as a BY CONTENT argument and received by C++ as a pointer to the given type. For example, if a C++ function called FROMCOB is to receive a parameter passed by value (indirect) of type int, the function prototype declaration would look like this:
void FROMCOB(int *)

The C++ function must dereference the pointer to access the actual value. If the value of the pointer is modified by the C++ function, as opposed to modifying the value that the pointer points to, the results on return to COBOL are unpredictable. Thus, passing values by value (indirect) from COBOL to C++ should be used with caution, and only in cases where the exact behavior of the C++ function is known.

Table 1 shows the supported data types for passing by value (direct) and Table 1 shows the supported data types for passing by value (indirect).