UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.
Absent Member.
Absent Member.
4548 views

Loading a cobol program and calling its entry (procedural cobol)

[Migrated content. Thread originally posted on 21 March 2012]

From the documentation I didn't find a hint to preload cobol objects in a procedural cobol program and calling the entry. Similar like java cobload.

I could call the program itself, which is then loaded and immediate returned by goback and call the entry afterwards.

program-id. subprog.
procedure division.
goback.

entry "entry1" using input.

---
program-id. mainprog.
call "subprog"
call "entry1" using


As a background. Using Java CobolBean with a static block with cobload to load a Cobol program. The business methods call entry points. The entries themselves call Cobol subprograms, preferable entries.
An option is to cobload the subprograms in Cobol but i like to have a dependency separation.

What are my options, how can I preload a subprogram from Cobol ?

Simon

Bookshelf > COBOL Language &> Procedure Division &> Statements > ENTRY Statement

Note that program files containing executable COBOL code typically have names that are essentially the same as the program-name. When a CALL is made and the program-name or entry-name is not already loaded into memory, program files are located by filename but can appear to be located by program-name. In such circumstances, a CALL that references a program-name may succeed but a CALL that references an entry-name may fail.


0 Likes
5 Replies
Micro Focus Expert
Micro Focus Expert

simon originally wrote:
From the documentation I didn't find a hint to preload cobol objects in a procedural cobol program and calling the entry.


You don't say what COBOL product this is. I'll answer for MF COBOL (Studio/Server/Net Express/Server Express/etc); if you're using Acu, or some non-Micro Focus COBOL, the answer is probably different.

Use a procedure-pointer and the "set ... to entry" syntax:


77 entry-not-found     procedure-pointer.
77 default-entry       procedure-pointer.
77 other-entry         procedure-pointer.
...
*> Set a procedure pointer to a nonexistent entry point
set entry-not-found to entry "DoesNotExist"
*> Load module "prog1" and get its default entry point
set default-entry to entry "prog1"
*> Find an entry point "prog2"
set other-entry to entry "prog2"
*> See if an entry point was resolved
if default-entry = entry-not-found
    display "prog1 not found"
    stop run
end-if
*> Call an entry point
call default-entry using ...


The "set [procedure-pointer-item] to entry [name]" statement will look in the current process for an entry point by that name. If it doesn't find one, it will try to load a module (INT, GNT, DLL [Windows], or CSO [Unix]) by that name, and if it can, it will set the procedure-pointer to the default entry point. (The default entry point is the same one that would be called by "call 'name'", where 'name' is the name of the module.)

In newer versions of COBOL, if the entry point can't be resolved, the procedure-pointer item will be set to null (by default - there may be a tunable for this). In older versions, though, it would be set to point to a routine that displays an error message or something along those lines. That's why I used the entry-not-found procedure-pointer above - that test works in any MF COBOL release.
0 Likes
Absent Member.
Absent Member.

Using Server Express.
I saw similar code in the demo directory. The documentation did not explain that "set" loads data, thanks for explaining. One thing is still not answered, when the entry name is not the same as the prog name it will not be loaded. How can the mainprog be loaded and the entry be called.

Is the following working:

77 default-entry procedure-pointer.
set default-entry to entry "mainprog"
call "entry1" using ...

Simon
0 Likes
Micro Focus Expert
Micro Focus Expert

Actually when you set the procedure-pointer to entry "mainprog" as in your example then that will make all the entry points in mainprog visible to the run-time system.

So if you have:

77 default-entry procedure-pointer.

set default-entry to entry "mainprog"
call "entry1" using ...

and mainprog looks like:

program-id. mainprog.
procedure division.
...
entry "entry1" using...

then your call to entry1 should be resolved.

Is this not working for you?
Are you checking that the set procedure-pointer statement was successful as Michael described above?


0 Likes
Micro Focus Expert
Micro Focus Expert

Hi,

As you are using CobolBean's then you can use the .cobload method preload an program, for example:

          program-id. subprog.
          procedure division.
            goback.

           entry "entry1".
                display "Hello from entry1"
                goback.


With the Java being:

import com.microfocus.cobol.CobolBean;
import com.microfocus.cobol.CobolException;

public class BeanEPCall
{
    public static void main(String[] args) throws CobolException, Exception
    {
        CobolBean myBean = new CobolBean();

        myBean.cobload("subprog");
        myBean.cobcall("entry1");
        myBean.dispose();
    }
}


The to compile it: (remember the data-context)
>cobol subprog.cbl int() data-context;

G:\java.playground>java -cp "bin;%CLASSPATH%" BeanEPCall
Hello from entry1


On reason why this could fail is that if you mix a 32bit & 64bit exe's, for example: using a 32bit Java cannot load a 64bit DLL/CSO.
0 Likes
Absent Member.
Absent Member.

Hello
Thanks to all of you for your help.

The Java cobload method I do not like personally, as I don't want any Cobol dependencies to be taken care of in Java.

set default-entry to entry "mainprog"
and
calling mainprog before calling the entry
both work.

Thanks
Simon
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.