AIV Variables

hi,

What is an AIV variable? What are they used for? The onlne documentation isnt of much help here.

please help
regards

AIV stands for Application Independent Variables. They are the “new” version of the old Version 1 global variables.

The old global variables relied on being able to define them on the fly. Since this is impossible in structured and mixed modes, a “new” version was required. This is AIVs.

steve

AIVs, or Application Independent Variables, are similar to the old global variables. They retain their value program to program and could be useful as environment variables.

Best practices are to limit the extent these are used… best to be decided by architect for the system and not to be implemented by developers on their own. If you need to pass values for a particular project, it is best to code according to structured programming methods and pass parameters via a PDA.

ok thanks. but do we have any links pointing to AIV documentation i may reference please?

I second Brian’s recommendation to limit the use of AIVs. Though in our shop, we put them to pretty good use as a way to cache information. AIVs are accessible to any module in a session once they are defined. They are created in the DEFINE DATA block with the statement INDEPENDENT and they must start with a + sign. They cannot be externalized into a data area.

Because they are accessible to any module, we recommend avoiding simple names that might get overlaid in another module.

For caching purposes, we only use the AIVs within the subprogram that retrieves file data, and this data needs to be fairly static. For example, we have a file that contains building information, including building-abbr and building-name. Then we have a module that is called to translate a building abbreviation. Since the code and name will not change frequently, we can cache the values in an AIV array and only read them once per session. Because we have some natural server sessions that can last for a week or more before restarting, we also use an AIV timestamp to refresh the data if it gets stale. “Stale” varies based on the data being cached and can be from 5 minutes to 24 hours.

I’ll add sample code if anyone wants it.

A link to documentation about AIVs:

http://servline24.softwareag.com/SecuredServices/document/java/nat414mf/sm/defineda_aiv_0360.htm

Thanks again.

The link to the documentation requires a username and password which i dont have. Is there a link open to all?

thanks

If you work for a customer of Software AG, you can be granted a documentation-only id for ServLine, the Customer Support website. Then you may access all the documentation links that will be posted on this forum without ability to open support tickets. Please ask your local DBA/sys admin for a documentation only ServLine id.

Likewise, your local DBA/sys admin could also provide the documentation to you that he/she received on CD with product distribution. There is no reason to keep it under lock and key.

Defining Application-Independent Variables
General Syntax of DEFINE DATA INDEPENDENT:

DEFINE DATA
INDEPENDENT AIV-data-definition …
END-DEFINE

The following topics are covered:

Function
Syntax Description
For an explanation of the symbols used in the syntax diagrams, see Syntax Symbols.


Function
The DEFINE DATA INDEPENDENT statement is used to define application-independent variables (AIVs).

An application-independent variable is referenced by its name, and its content is shared by all programming objects executed within one application that refer to that name. The variable is allocated by the first executed programming object that references this variable and is deallocated by the LOGON command or a RELEASE VARIABLES statement.

The optional INIT clause is evaluated in each executed programming object that contains this clause (not only in the programming object that allocates the variable).

Syntax Description
INDEPENDENT AIV-data-definition The DEFINE DATA INDEPENDENT statement can be used to define a single or multiple application-independent variables (AIVs). For each AIV, the syntax shown below applies.

END-DEFINE The Natural reserved word END-DEFINE must be used to end the DEFINE DATA statement.

AIV Data Definition

level variable-definition
redefinition
handle-definition

Syntax Element Description:

level An application-independent variable must be defined at Level 01. Other levels are only used in a redefinition.
variable-definition A variable definition is used to define a single field/variable that may be single-valued (scalar) or multi-valued (array). See Variable Definition.

Note:
The name of an application-independent variable must start with a “+” character.

redefinition A redefinition may be used to redefine a group, a view, a DDM field or a single field/variable (that is a scalar or an array). See Redefinition.

The fields resulting from the redefinition must not be application-independent variables, that is their name must not start with a ‘+’. These fields are treated as local variables.

handle-definition A handle identifies a dialog element in code and is stored in handle variables. See Handle Definition.

Note:
The first character of the name must be a “+”. Rules for Natural variable names apply, see Naming Conventions for User-Defined Variables (in the Natural Programming Guide).

Back to DEFINE DATA Overview.

Back to DEFINE DATA Syntax Overview.

Current version documentation is publicly available.

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat425mf/sm/defineda_aiv.htm#defineda_aiv

Hi,

 Can you please tell me if i am assigning one value to one AIV variable in my first program and then i have to use this AIV value in other program. Then how to code for this...

hi,

  I got the answer ......

program1

define data independent
1 +filed1
end-define
move ‘nitin’ to +field1
end

program2

input +field1
end

Why not:

program2

MOVE +field1 to #A

or

WRITE +field1

You do not have to INPUT +field1

steve

Hi,

Sorry for late reply… :frowning:

I have written code as per your instructions but its not working. Please check below code…

Program TESTAIV

define data
independent
1 +name (a10)
end-define
move ‘nitin’ to +name
write ‘+name1’ +name
callant ‘TESTAIV1’
end

Subprogram TESTAIV1

define data local
1 #name (a10)
end-define
move +name to #name
write +name
write ‘+name2’ #name
end

This is giving error in sugprogram :-

¦NAT0384 Explicit format specification required. ¦
¦ VVVVV ¦
¦0040 move +name to #name

Please help me out…

Hi,

The subprogram needs to know what the AIV looks like.

This can be done by adding the AIV to its DEFINE DATA clause or by executing another object with it defined before you catalog.

In the “old days” before GDAs, it was not uncommon for all an application’s AIVs to be defined in a single program (that did nothing) and for the program to be executed before invoking the syntax checker (CHECK/CAT/STOW).

In your simple example it would probably be easiest to change your DEFINE DATA to

DEFINE DATA 
INDEPENDENT
1 +NAME(A10)
LOCAL 
1 #NAME (A10) 
END-DEFINE 

Cheers,

Graeme Lane

Nitin,
Not sure what version you’re running on. The following code works fine for us on MF V4.2 and no need to define independent in sub-prog again.

PROG

DEFINE DATA INDEPENDENT
1 +NAME (A10) INIT <'NITIN'>
END-DEFINE
WRITE NOTITILE '+NAME IN PROG =' +NAME
CALLNAT 'TESTAIV1'
END

SUBPROG

DEFINE DATA LOCAL
1 #NAME (A10)
END-DEFINE
#NAME := +NAME
WRITE '#NAME IN SUB-PROG = ' #NAME
END

O/P

MORE,
+NAME IN PROG = NITIN
#NAME IN SUB-PROG =  NITIN

ohh… that may be the case… I am using Unix version Natural 5.1

I believe this should work under Unix as well!

Well, I got why you’re getting a NAT0384!

The AIV (+NAME in your case) should get the value assigned first in the environment. What I meant is run your main program without CALLNAT, and AIV will be initialized. Then STOW your subprogram and it should be fine (w/o NAT0384).

Now run your main program with CALLNAT and there you are!

bingooooooo…

its working… though I am not getting logic behind this as some point of time whenever you are coding and running program first time there will not be AIV… so is there logic behind this ??