IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Global & External variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jose.jeyan

New User


Joined: 28 Jul 2006
Posts: 60
Location: Mumbai

PostPosted: Wed Jan 17, 2007 2:40 pm
Reply with quote

can anyone pls describe me wats global & external variables in cobol.wats the use of it.with an example

Thanks in advance
Jose
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 17, 2007 3:14 pm
Reply with quote

Look here:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR10/5.2.2?DT=20020920180651
The EXTERNAL clause specifies that the storage associated with a data item is associated with the run unit rather than with any particular program within the run unit. An external data item can be referenced by any program in the run unit that describes the data item. References to an external data item from different programs using separate descriptions of the data item are always to the same data item. In a run unit, there is only one representative of an external data item.
And here:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR10/5.2.3?SHELF=&DT=20020920180651
The GLOBAL clause specifies that a data-name is available to every program contained within the program that declares it, as long as the contained program does not itself have a declaration for that name. All data-names subordinate to or condition-names or indexes associated with a global name are global names.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Wed Jan 17, 2007 3:16 pm
Reply with quote

Hi !

The EXTERNAL and GLOBAL clauses allow you to share data and files between different COBOL subprograms. EXTERNAL is used to access globally declared data, including data declared EXTERNAL by other COBOL programs. GLOBAL is only applicable when sharing data among nested programs in an ANSI85 dialect.

The EXTERNAL clause is used to designate data or a file outside the scope the current program unit. In order for the data or file to share access, you must declare it exactly the same in another program unit. You must put the keyword EXTERNAL on all declarations. Otherwise, those lacking EXTERNAL will be considered regular data and you will not be accessing shared data or files. To ensure that you define EXTERNAL data consistently, define them in a copy file and use the COBOL COPY verb to copy them into the modules that need access to them.

Declarations having the EXTERNAL clause cannot have VALUE clauses. The exception is the 88 level items. The 88 level items can have VALUE clauses associated with them. Using EXTERNAL on a group item makes the group item and all those items subordinate to it externally visible.

Note that INDEX data of a table that are defined as EXTERNAL are not shared. You can override this restriction by using the compiler directive EXTINDEX.

Example of External CopyBook. There the data is present in all the
comunicating programms, which have included the Book.
No Fields in Linkage needed for programm-comunication.

Programm-A / und -B in Working-Strorage:

COPY CIPUFMSG.

CopyBook:

01 IFP-MSG-MESSAGES EXTERNAL.

10 MSG-VERARB-ART PIC X(004).
10 MSG-FILLER-001 PIC X(001).
10 MSG-VERARB-CDE PIC X(002).

Then programm-a calls programm-b:

Move blablabla to copybook-fields
Call programm-b End-Call

Regards, UmeySan
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts JCL with variables JCL & VSAM 1
No new posts JCL Variables JCL & VSAM 1
No new posts reset/clear ALL application profile v... TSO/ISPF 3
No new posts defining a global LUA function in Inf... IBM Tools 1
Search our Forums:

Back to Top