Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modules in COBOL

Status
Not open for further replies.

spyderman

Programmer
Apr 8, 2001
4
AU
I need help in seeting up modules in COBOL. eg. a main module and a date module. More importantly the code that lets the two transfer data.

If anyone can help or show me some example code it would be really appreciated.


 
hi spyderman,

Are you trying to link two sub-programs?
I haven't had much experience but i'll give it a go.

What you need is to define the data which will be passed between the programs, in the working storage section of your main-module this may look something like this:

WORKING-STORAGE SECTION.
01 W-DATE PIC 9(6).
01 W-ERROR-FLAG PIC X VALUE 'N'.

(I am assuming that you are writing a date validation)

You would then call the date-module in the procedure division thus:

CALL DATE-MODULE USING W-DATE W-ERROR-FLAG

In the recieving module (date module) you would define the data in the LINKAGE SECTION which comes after the WORKING STORAGE SECTION THUS:

LINKAGE SECTION

01 L-DATE
03 L-DAY PIC 99.
03 L-MONTH PIC 99.
03 L-YEAR PIC 99.

01 03 L-ERROR-FLAG PIC X.
Then the procedure division heading would look like this:

PROCEDURE DIVISION USING L-DATE L-ERROR-FLAG

then just go ahead and code the rest of the program like normal.

IMPORTANT!!

** L-DATE and L-ERROR-FLAG are explicit redefinitions of the data used in the call statemant in the main program.
ie. they occupy the same area of storage, so must appear in the relevant order:-

hope this is some help jimlee
 
Hi All,

Bori's comment about GOBACK reminded me of something I used to do w/subpgms.

If you take param data from a higher level pgm you code the LINKAGE SECT:

Code:
     01  LK-PARM-DATA.
         05  LK-PARM-DT-CYMD   etc.
         05  etc.

If you take param data from a the EXEC statement you code the LINKAGE SECT:

     01  LK-PARM-DATA.
         05  LK-LEN            pic s9(004).
         05  LK-PARM-DT-CYMD   etc.
         05  etc.

Sooo, if you add that LK-len 05 to the USING and the LS when you call the subpgm from a pgm (move, say -1 to it before you do the CALL), you can run the subpgm both as a mainpgm and a subpgm. And best of all, you can test the subpgm without the mainpgm by providing the param data in the PARM of the EXEC JCL stmt. Alas you're limited to 100 bytes if you plan to use the EXEC PARM data. Also I only pass one parm to the subpgm, e.g.CALL X USING WS-PARM-DATA. WS-PARM-DATA is an 01 level having as many 05s etc. as you need. At least, I think that's the way it was done.

Regards, Jack.

P.S. That's why I got in the habit of using GOBACK for main AND sub pgms.



 
Hi,

the 'normal' way to end a subprogram is with EXIT PROGRAM.

The GOBACK is an IBM invention and means to goback to the nearest higher level.
That can be the operating system or the calling module.

Also the length field in the example above should be a comp field.

Regards,

Crox

 
Slade,

How come some of your post looks jumbled to me? I can't read the example code - it looks encrypted with lines and dots...strange. I've seen other posts like this as well.

I'm using IE 4.0 (at work) to view this.

Thanks!

-Tyler
 
Hi Tyler,

I don't know why it happens to you; probably your browser.
I can tell you that I use Tek-Tips' TGML (Tecumseh Group Mark-up Language) to format and align the COBOL code that I present. That is probably what is causing it. Select the "Preview Post" button and scroll to the bottom to see what's available.

Maybe someone else can tell you how to get around it.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top