Mark Jacobs wrote:
This might not be the right forum for this question, but...

Doing some very limited in initial research I've found three documented methods of performing Dynamic Allocation in COBOL ( Enterprise COBOL 4.2), BPXWDYN, CEEENV or setenv.

Q1) Are there any others?We already use a home grown assembler program for dynamic allocation, but our direction is to move as much to the OS as possible.
Q2) Is there any reason to pick one over the others?


I use BPXWDYN where I can. Unfortunately, with tape datasets all the needed parameters a sometimes not there. So I have a alternative process for those uses. COBOL can call the C runtime library functions. C has dynalloc() and dynfree() to dynamically allocate and free datasets. The linkage is a bit different. And C doesn't set the high bit in it's parameter lists, so one has to call the function with a extra parameter to keep the high bit in the address from being set like this:

CALL 'DYNALLOC' USING BY REFERENCE LS-DYNT
   BY VALUE ZERO
   RETURNING WS-RETURN-CODE.

A gotcha is being C, character strings need to be NULL terminated (PIC Z). And another is some of the functions in the C runtime have to be statically linked at compile time. I use a small COBOL wrapper that links the C routine statically which I then can call dynamically. The runtime functions also allow text units to be passed which make them flexible. A nice thing is since they are part of the IBM C runtime, you don't have to maintain a routine or distribute one. It's already there with Language Environment.

Alan

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to