Re: converting OpenVMS COBOL program to "callable" sub-program (4658 Views)
Reply
Occasional Visitor
Z.G. Wiedemann
Posts: 4
Registered: ‎09-23-2004
Message 1 of 9 (4,658 Views)

converting OpenVMS COBOL program to "callable" sub-program

(pardon if this is a "cross post" but I think I was on a HP specific forum)

would like to find "best way" to take part of an existing OpenVMS (alpha) COBOL program (with FMS input) and make that "screen" and associated logic "callable" from other COBOL programs ...

We currently have small data manipulating and spooling routines in the system shared Linked Library but would like to link to code we would extract from an existing program (e.g. product update screen and validation/synchronization/etc. logic now part of a product maintenance program) and make that "callable" from both that "original" program and other programs (e.g. an order entry program)

what is the "best" way(s) to pass "lots" of working set and file record data from the calling programs to the "new" "callable" program ... (e.g. Common, Global, Linkage/Use, Initial ??)

we would like certain values in the calling program to be "changeable" by the "called" sub-program (including read/write/re-write/delete records in "shared" RMS files ...

this is a "simple" (non-clustered, single group) system

all tricks, hints, subtile suggestions, examples, reference citations, and watch-outs appreciated ...

Honored Contributor
Bojan Nemec
Posts: 842
Registered: ‎06-02-2004
Message 2 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Hi,

Velcome to the OpenVMS forum!

Each COBOL program is already a subprogram. From the calling program you just call the name which is defined in PROGRAM-ID. You declare the parameters to be passed to this program in the LINKAGE SECTION and PROCEDURE DIVISION USING ... GIVING. All parameters are passed by reference.
There are some things to be careful when using cobol as subprograms. First, dont use STOP RUN to end the routine (this will stop the whole program) use EXIT PROCEDURE. All variables in WORKING-STORAGE are allocated in static memory! So if you call a subprogram twice (or more times) you must init by hand all the variables. With by hand I mean with a MOVE or INITIALIZE and not VALUE something in the WORKING-STORAGE. All files must be closed before exiting the routine or some special handling must be writen to avoid opening the same file twice (which will produce an error).
If you have all the data, which you want to pass to the subprogram, in the memory of the calling program, pass this data as parameters this is the fastest and cleanest way to pass data. Be avare that all the data is passed by reference, so you must know the type and length of this data.


Bojan
Honored Contributor
Kris Clippeleyr
Posts: 954
Registered: ‎04-19-2004
Message 3 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Hi,

I hope you have the sources of the program in question.
If so, a way to proceed is to isolate those parts of the program you want to share with others (i.e. "make them callable"); compile those modules, and put the objects in an object library. You can then use that library, to create various other programs.
You may consult the manual "Guide to Creating OpenVMS Modular Procedures" at http://h71000.www7.hp.com/doc/73final/4518/4518PRO.HTML.

I'm not sure what you mean by

what is the "best" way(s) to pass "lots" of working set and file record data from the calling programs to the "new" "callable" program ... (e.g. Common, Global, Linkage/Use, Initial ??)

we would like certain values in the calling program to be "changeable" by the "called" sub-program (including read/write/re-write/delete records in "shared" RMS files ...


Do you mean sharing data between processes? In that case, global sections come in handy.
Concurrent file handling using RMS is also very straightforward. Please check on the manual "Guide to OpenVMS File Applications" at http://h71000.www7.hp.com/doc/731FINAL/4506/4506PRO.HTML.

Hope this helps a bit.

Greetz,

Kris
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Honored Contributor
Antoniov.
Posts: 3,182
Registered: ‎07-08-2003
Message 4 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Hi,
adding to Bojan post, when you start a new program your variable can be set using VALUE clause.
You cannot pass a file handler or something other like this, so every program have to open its files.
For little data I use logical name to pass values but to make this I wrote a little C routine.

Antonio Vigliotti
Antonio Maria Vigliotti
Occasional Visitor
Z.G. Wiedemann
Posts: 4
Registered: ‎09-23-2004
Message 5 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Thank you all for your replies â ¦

I have some understanding for the Digital Calling Standard (errrrrâ ¦ Compaâ ¦. Errrrr HP) ---

I guess my request may have not been specific enough â ¦

It seems that there are three MAJOR ways of inter-program communication in OpenVMS COBOL

(from the Compaq COBOL Userâ s Manual ZK6297 September 2001 )

12.4 Accessing Another Programâ s Data Division

In a multiple COBOL program run unit, a called subprogram can access some of
its calling programâ s Data Division. The calling program controls how much of it
will be accessible to the called subprogram in the following ways:

â ¢ The USING phrase in both the CALL statement and the Procedure Division
header (see Section 12.4.1)

â ¢ The Linkage Section (see Section 12.4.2)
â ¢ The EXTERNAL clause (see Section 12.2.2)
â ¢ The GLOBAL clause (see Section 12.5.2)


Defining a DATA item or a File Connector as â is EXTERNAL â

Declaring a DATA-name, FILE-name (or REPORT-name) as â is GLOBAL â

â Passingâ the DATA via the USING phrase and the LINKAGE Section


With three major methods I seem to think there are reasons for their separate existence.

It appears that the USING/LINKAGE is when â smallâ amounts of data need to be passed back and forth â ¦

The EXTERNAL / GLOBAL declaring/defining options seem to have been created with different intentions. (the exclusion of renaming for the EXTERNAL vs the GLOBAL clauses leads me to believe that). Also the inability to use the VALUE clause â ¦




I have also noted the INITIAL Clause â resetsâ all internal program data

The INITIAL Clause
A COBOL program with an INITIAL clause is returned to its initial state
whenever that program exits. This ensures that it will be in its initial state the
next time it is called.

During this initialization process, all internal program data whose description
contains a VALUE clause is initialized to that defined value. Any item whose
description does not include a VALUE clause will be initialized, and contain an
undefined value.

When an INITIAL clause is present and when the program is called, an implicit
CLOSE statement executes for all files in the open mode associated with internal


When an INITIAL clause is not present, the status of the files and internal
program data are the same as when the called program was exited.

The initial attribute is attained by specifying the INITIAL clause in the programâ s
PROGRAM-ID paragraph. For example:

IDENTIFICATION DIVISION.
PROGRAM-ID. TEST-PROG INITIAL.

If the â calledâ program/routine has an INITIAL clause does that mean when â leavingâ such a program all the â GLOBALâ and/or â EXTERNALâ data is also â resetâ ?

Will this then effect â sharedâ data (files, working-storage) ????

I am trying to Modularize the existing programs ... for a least one module there would be the need to "pass" large (dozens) of data variables back and forth

several (6-10) of the same RMS files would need to be accessed by the Main (calling) and Sub (called) programs .... (and potentially records reaccessed ??? by the by
Occasional Visitor
Z.G. Wiedemann
Posts: 4
Registered: ‎09-23-2004
Message 6 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

oops ... that was kind of ugly ... (moderator please delete the post above ... repeated for clarity and addition)

Thank you all for your replies ...

I have some understanding for the Digital Calling Standard (errrrr ... Compa.. Errrrr HP) ---

I guess my request may have not been specific enough ...

It seems that there are three MAJOR was of inter-program communication in OpenVMS COBOL

(from the on-line PDF Compaq COBOL User's Manual ZK6297 September 2001 )

12.4 Accessing Another Program's Data Division

In a multiple COBOL program run unit, a called subprogram can access some of
its calling program's Data Division. The calling program controls how much of it
will be accessible to the called subprogram in the following ways:

- The USING phrase in both the CALL statement and the Procedure Division
header (see Section 12.4.1)

- The Linkage Section (see Section 12.4.2)
- The EXTERNAL clause (see Section 12.2.2)
- The GLOBAL clause (see Section 12.5.2)


Defining a DATA item or a File Connector as " is EXTERNAL "

Declaring a DATA-name, FILE-name (or REPORT-name) as " is GLOBAL "

"Passing" the DATA via the USING phrase and the LINKAGE Section


With three major methods I seem to think there are reasons for their separate existence.

It appears that the USING/LINKAGE is when "small" amounts of data need to be passed back and forth ...

The EXTERNAL / GLOBAL declaring/defining options seem to have been created with different intentions. (the exclusion of renaming for the EXTERNAL vs the GLOBAL clauses leads me to believe that). Also the inability to use the VALUE clause ...




I have also noted the INITIAL Clause "resets" all internal program data

The INITIAL Clause
A COBOL program with an INITIAL clause is returned to its initial state whenever that program exits. This ensures that it will be in its initial state the next time it is called.

During this initialization process, all internal program data whose description
contains a VALUE clause is initialized to that defined value. Any item whose
description does not include a VALUE clause will be initialized, and contain an
undefined value.

When an INITIAL clause is present and when the program is called, an implicit
CLOSE statement executes for all files in the open mode associated with internal


When an INITIAL clause is not present, the status of the files and internal
program data are the same as when the called program was exited.

The initial attribute is attained by specifying the INITIAL clause in the program's PROGRAM-ID paragraph.

For example:

IDENTIFICATION DIVISION.
PROGRAM-ID. TEST-PROG INITIAL.

If the "called" program/routine has an INITIAL clause does that mean when "leaving" such a program all the "GLOBAL" and/or "EXTERNAL" data is also "reset"?

Will this then effect "shared" data (files, working-storage)

I am trying to Modularize the existing programs ... for a least one module there would be the need to "pass" large (dozens) of data variables back and forth

several (6-10) of the same RMS files would need to be accessed by the Main (calling) and Sub (called) programs .... and potentially records reaccessed ??? by the "calling" program ...

for example:
say the "calling" program had a stock file record open when it called a program that manipulated the Stock File ... currently I "store" the key and the pending "changes" to the record open in the "calling" program BEFORE the call ... and then using that "stored" key do a "re"-READ of the record after "returning" from the "called" program ...and re-applied any "pending" changes just to make sure ....

it there a "better" way ???


Again I appreciate the help ...
Advisor
Jim Strehlow
Posts: 30
Registered: ‎06-07-2004
Message 7 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

COBOL programs I wrote and managed at various large companies (years ago) used common storage for sharing variables in many programs.
We often created one text file for those variables and included a COPY statement in the many programs that shared those variables.
e.g.
COPY A-B IN "directory:textLibraryName.TLB".

or COPY â dir:A_B.TXTâ

When you do the above and then make a change to the copied text file (change a variable's size or add new variables), you must recompile all programs sharing that "common block".
You will get very undesirable and unpredictable results if you only recompile one of the programs.

Sounds as if you may need a "legacy programmer's" assistance with your project.

Jim, Alameda, CA
Honored Contributor
Bojan Nemec
Posts: 842
Registered: ‎06-02-2004
Message 8 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Hi,

Sorry if my previous post was not to specific.
Cobol is not the best language to write "callable" programs, but with some extra work can be done.

The GLOBAL clause is used only for contained programs. This mean, programs in the same source file.

The EXTERNAL clause create a special PSECT for each external variable or file. It is similar (equal) to FORTRAN COMMON. So the variable or file is shared in all subprograms where is it declared. The INITIAL clause does not affect external data.

In my opinion the best practice to share data betwen subprograms is the linkage section. So you can mix different languages and the subprograms are much more transparent. If you have many parameters to pass, you can always collect them in one record (which is true also for EXTERNAL data). There is a problem with files. In Cobol you can not pass a file as a parameter. To owercome this you can use EXTERNAL clause, but this makes programs much more complex and hard to support.

One different aproach is to write a "file handling subprogram". This subprogram defines the file and all the operations on it (open,write,read,etc...). If you need an operation on the file, you call this subprogram with a parameter which tells which operation you need.

One more thing, sorry if this is obvious to you, but many programmers dont know this, if you define the same file twice or more (different selects and fd but pointing to the same file), you can open a file more times.

Bojan
Occasional Visitor
Z.G. Wiedemann
Posts: 4
Registered: ‎09-23-2004
Message 9 of 9 (4,658 Views)

Re: converting OpenVMS COBOL program to "callable" sub-program

Thanks Jim and Bojan

will give it a shot with the EXTERNAL clause

the "double" opening of a file technique is a good idea ... unfortunatly the nature of the routine may change the "Calling" record and the "main" program will need this "updated" data when it "resumes"

I especially appreciate the info about the INITALIZE clause

thanks again
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.