ILE COBOL Programmer's Guide

Passing Data to an ILE C Program or Procedure

You can pass data to a called ILE C program or procedure by using CALL...BY REFERENCE, CALL...BY VALUE, or CALL...BY CONTENT. Refer to Passing Data Using CALL...BY REFERENCE, BY VALUE, or BY CONTENT for a description of how to use CALL...BY REFERENCE, CALL...BY VALUE or CALL...BY CONTENT.

When data is passed to the ILE C program using CALL...BY REFERENCE, a pointer to the data item is placed into the argument list that is accepted by the ILE C program.

When data is passed to the ILE C program using CALL...BY CONTENT, the value of the data item is copied to a temporary location and then a pointer containing the address of the copy's temporary location is placed into the argument list that is accepted by the ILE C program.

For CALL...BY VALUE, the value of the item is placed into the argument list that is accepted by the ILE C program. CALL...BY VALUE can be used to call ILE C procedures but not ILE C program objects.

In your ILE COBOL program, you describe the arguments that you want to pass to the ILE C program or procedure, in the Data Division in the same manner as you describe other data items in the Data Division. Refer to Passing and Sharing Data Between Programs for a description of how to describe the arguments that you want to pass.

When the called ILE C program object begins running, the function main is automatically called. Every ILE C program object must have one function named main. When you pass parameters to the ILE C program object, you must declare two parameters with the function main. Although any name can be given to these parameters, they are usually referred to as argc and argv. The first parameter, argc (argument count), has type int and indicates how may arguments were supplied on the CALL statement that called the ILE C program object. The second parameter, argv (argument vector), has type array of pointers to char array objects.

The value of argc indicates the number of pointers in the array argv. If a program name is available, the first element in argv points to a character array that contains the program name of the invocation name of the ILE C program that is being run. The remaining elements in argv contain pointers to the parameters being passed to the called ILE C program. The last element, argv[argc], always contains NULL.

Refer to the WebSphere Development Studio: ILE C/C++ Programmer's Guide for further information on describing parameters in the called ILE C program or procedure.

Data Type Compatibility between ILE C and ILE COBOL

ILE C and ILE COBOL have different data types. When you want to pass data between programs written in ILE C and ILE COBOL, you must be aware of these differences. Some data types in ILE C and ILE COBOL have no direct equivalent in the other language.

Table 17 shows the ILE COBOL data type compatibility with ILE C.

Table 17. ILE COBOL Data Type Compatibility with ILE C

ILE COBOL ILE C declaration in prototype Length Description
PIC X(n). char[n]
or
char *
n A character field where n=1 to 16 711 568
FORMAT DATE literal. char[6] 6 A date field.
PIC X(5). char[5] 5 A day field.
PIC X. char 1 A day-of-week field.
FORMAT TIME literal. char[8] 8 A time field.
FORMAT TIMESTAMP. char[n] 26 A timestamp field.
PIC G(n) char[2n] 2n A graphic field.
PIC 1 INDIC .. char 1 An indicator.
PIC S9(n) DISPLAY char[n] n A zoned decimal.
PIC S9(n-p)V9(p) COMP-3 decimal(n,p) n/2+1 A packed decimal.
PIC S9(n-p)V9(p) PACKED-DECIMAL. decimal(n,p) n/2+1 A packed decimal.
PIC S9(4) COMP-4. short int 2 A 2-byte signed integer with a range of -9999 to +9999.
PIC S9(4) BINARY. short int 2 A 2-byte signed integer with a range of -9999 to +9999.
PIC S9(9) COMP-4. int 4 A 4-byte signed integer with a range of -999999999 to +999999999.
PIC S9(9) BINARY. int 4 A 4-byte signed integer with a range of -999999999 to +999999999.
PIC S9(9) COMP-4. long int 4 A 4-byte signed integer with a range of -999999999 to +999999999.
PIC S9(9) BINARY. long int 4 A 4-byte signed integer with a range of -999999999 to +999999999.
PIC S9(18) COMP-4. long long 8 An 8-byte integer.
PIC S9(18) BINARY. long long 8 An 8-byte integer.
05 VL-FIELD.
10 i PIC S9(4) COMP-4.
10 data PIC X(n).
_Packed struct {short i; char[n]} n+2 A variable length field where i is the intended length and n is the maximum length.
05 n PIC 9(9) COMP-4.
05 x redefines n PIC X(4).
struct {unsigned int : n}x; 4 Bitfields can be manipulated using hex literals.
01 record
05 field1...
05 field2...
struct n A structure. Use the _Packed qualifier on the struct. Structures passed should be passed as a pointer to the structure if you want to change the contents of the structure.
USAGE IS POINTER * 16 A pointer.
PROCEDURE-POINTER pointer to function 16 A 16-byte pointer to a procedure.
USAGE IS INDEX int 4 A 4-byte integer.
REDEFINES union.element n An element of a union.
OCCURS data_type[n] n*(length of data_type) An array.
USAGE IS COMP-1 float 4 A 4-byte floating-point.
USAGE IS COMP-2 double 8 An 8-byte floating-point.
Not supported. long double 8 An 8-byte long double.
Not supported. enum 1, 2, 4 Enumeration.
Note:
For all COMP-4 and BINARY data items, the range limitations indicated only apply when the *STDTRUNC value of the OPTION parameter of the CRTCBLMOD or CRTBNDCBL command is specified. If *NOSTDTRUNC is used, the range constraints need not be observed.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]