Using session variables across different programming languages

While working in one language, you can declare session variables that you can continue to use after calling in a load module of a different language. The table below shows how the attributes of session variables are mapped across programming languages. Session variables with attributes not shown in the table cannot be accessed from other programming languages. (Some attributes supported for C and C++ or PL/I session variables cannot be mapped to other languages; session variables defined with these attributes cannot be accessed outside the defining language. However, all of the supported attributes for COBOL session variables can be mapped to equivalent supported attributes in C and C++ and PL/I, so any session variable that you declare with COBOL can be accessed from C and C++ and PL/I.)

Machine attributes PL⁄I attributes C and C++ attributes COBOL attributes Assembler, disassembly, and LangX COBOL attributes
byte
CHAR(1)
unsigned char
PICTURE X
DS X or
DS C
byte string
CHAR(j)
unsigned char[j]
PICTURE X(j)
DS XLj or
DS CLj
halfword
FIXED BIN(15,0)
signed short int
PICTURE S9(j≤4)
USAGE BINARY
DS H
fullword
FIXED BIN(31,0)
signed long int
PICTURE S9(4<j≤9)
USAGE BINARY
DS F
floating point
FLOAT BIN(21) or
FLOAT DEC(6)
float
USAGE COMP-1
DS E
long floating point
FLOAT BIN(53) or
FLOAT DEC(16)
double
USAGE COMP-2
DS D
extended floating
point
FLOAT BIN(109) or
FLOAT DEC(33)
long double
n/a
DS L
fullword pointer
POINTER
*
USAGE POINTER
DS A
Note: When registering session variables in PL/I, the DECIMAL type is always the default. For example, if C declares a float, PL/I registers the variable as a FLOAT DEC(6) rather than a FLOAT BIN(21).

When declaring session variables, remember that C and C++ variable names are case-sensitive. When the current programming language is C and C++, only session variables that are declared with uppercase names can be shared with COBOL or PL/I. When the current programming language is COBOL or PL/I, session variable names in mixed or lowercase are mapped to uppercase. These COBOL or PL/I session variables can be declared or referenced using any mixture of lowercase and uppercase characters and it makes no difference. However, if the session variable is shared with C and C++, within C and C++, it can only be referred to with all uppercase characters (since a variable name composed of the same characters, but with one or more characters in lowercase, is a different variable name in C and C++).

Session variables with incompatible attributes cannot be shared between other programming languages, but they do cause session variables with the same names to be deleted. For example, COBOL has no equivalent to PL/I's FLOAT DEC(33) or C's long double. With the current programming language COBOL, if a session variable X is declared PICTURE S9(4), it will exist when the current programming language setting is PL/I with the attributes FIXED BIN(15,0) and when the current programming language setting is C with the attributes signed short int. If the current programming language setting is changed to PL/I and a session variable X is declared FLOAT DEC(33), the X declared by COBOL will no longer exist. The variable X declared by PL/I will exist when the current programming language setting is C with the attributes long double.

Refer to the following topics for more information related to the material discussed in this topic.