What are the differences between GDA and AIV?
My initial understanding was to use a GDA if it is within a library, but use AIV when I want to share between libraries?

On-line help shows:
GLOBAL - data elements referenced by more than one program, routine, etc. (provided all are in same library).

INDEPENDENT - application independent data elements, which are global and can be shared with the STEPLIB.

I do not know all the differences, but you can share a GDA with programs that are executed from a steplib, the same can be said for AIV’s.

I know some people argue that AIV’s are more flexible, since you can declare them at any point and it does not require that your re-catalogue all your programs such as changing a GDA does.

Personally, I use a mix of them box. I set up a GDA to hold most of the variables that I need to be shared across all the programs in the library, but for those globals that only need to be shared within a small subset of the programs, I use AIV’s.

If it was a small set of programs, why not a smaller GDA or can it be a smaller block on the GDA? Although the no-recatalog for AIV is really a plus factor.
What about efficiency?
I also want to know why it states “can be shared with the STEPLIB” on AIV, but not on GDAs.

AIV’s actually come from NAT12 days where we had no GDA. Due to compatibility reasons they still exist today.
The main difference:

  • 1. It is not necessary to declare them at one place. Whenever a program is started that uses a new AIV this AIV is added to the existing AIV’s.
    2. A new GDA overlays a existing one. Multiple DEFINE DATA INDEPENDENT can coexist.
    3. Adressing of AIV’s is slower because they are adressed by name not by offset.


In my experience neither AIV’s or GDA’s can be shared across libraries. they can both share to a steplib though.

In Nat1 there didn’t exist AIVs, but Global Variables. They have been collected at compile/run time and were implicitly added to each program compiled. Thus compiled programs could have grown without the knowledge of the programmer (even unused global variables were kept!)
With Nat2 they introduced the GDA to collect all global variables explicitly. The old globals have only been available in report mode programs. With Nat2.2 (I think) they invented the INDEPENDENT clause of DEFINE DATA to make the old globals available to structured mode programs (and with intervention of the customers!). To distinguish these old globals from global variables in a GDA they called them AIVs.

Differences between GDA and AIV:
GDA can not be shared among CALLNAT! AIV can!
GDA can not be extended at runtime. AIV can!
Programs keep a timestamp of the catalogued GDA, thus need recompilation, when GDA changes (what a mess!)
With blocked GDA (iiiiiihh) you don’t know what’s in the global data, if on of the called programs uses other blocks of this GDA!

I suggest to use AIV to enable subprograms to keep their state between calls and not to pass the state information in the parameter data (for example data access programs, that create a result set and pass one record for each call). Each AIV should be preceded by the using program name to avoid naming conflicts.

On the other hand I suggest to avoid the usage of GDA. If you have to pass informations from one program to the other, use a PDA (PERFORM / CALLNAT), thus you can restrict the usage by the using program.

Just my opinion!