Question

  1. How to declare a constant value in PICK/UniVerse database?
  2. How to pass an argument to a function by constant reference?

There is some information in the IBM's manual for UniVerse database about constants, but nothing in particular.

Please note that:

DEFINE statement value

is not what i'm looking for because it substitutes the statement with value at compile time and doesn't provide real constness of the value.

Does anyone know how to declare those?

Thanks.

Was it helpful?

Solution

It is the same statement as in UniData (UniVerse's sister database; both are collectively referred to as U2), which is: EQU and EQUATE

For example:

EQU statement TO value

I'm not entirely sure what you mean by point 2, but I'll give it a dig. By default, all parameters are 'pass by reference', but there is no form of const argument. It will still allow you to change the parameter value internally in the function/subroutine, but the results will not affect the values of the equates back in the calling program/function/subroutine.


Side note: If you want to ensure a subroutine/function does not change the value of an actual variable you pass (pass by value), you can either assign it to a temp variable and pass that, or surround it with parenthesis

For example:

CALL MySub(PassByRef, (PassByValue))

what the () does is create an temporary copy of PassByValue then pass the temp copy by reference. This stops the changes propagating back into PassByValue

OTHER TIPS

You do not need to define variables before they are used in Pick/Universe.

To assign a variable that is defined at compile time use

EQU PI TO 3.14

To assign it at run time use

PI = 3.14

The main difference here is that once assigned at compile time, using an EQUATE, the variable cannot be reassigned, whereas when it is assigned at run time it can be. Therefore compilation at compile time is usually reserved solely for constants, whereas assignment at run time may be used both for constants and for standard variable values.

I'd use the EQUATE statements to create constants, and if you want to have them available to multiple programs you should place them in their own record and use the $INCLUDE statement to pull the definitions into other programs. Note that all of the values are going to be established at compile time.

As to "constants" that are established at some time other than compile time, or indirectly referencing values through tags (passing a constant reference), most U2 programmers use control records of some sort. Since the file system and the programming language in U2 are so intertwined, nobody ever thinks twice about this. Most systems I've used have one or more files called something like, "SOMETHING.OR.OTHER.CTRL" with free-form record structures. The editor is used to stuff data into records in the control file with keys that describe the function, like, "INVENTORY.CONSTANTS".

For indirect references, set up the record with the first attribute having the "constant" names multivalued and the second field with the "constant" values, also multivalued. Like this:

INVENTORY.CONSTANTS:

001: JOHN*PAUL*GEORGE*RINGO
001: 100*57*83*19833

(where the "*" is actually a value mark).

Then the program would do the following:

SUBROUTINE SAMPLE(CONSTANT.NAME)
     .
     .
     .
OPEN "","SOMETHING.OR.OTHER.CONTROL" TO CTRL.FILE ELSE BOMB
READ CONST.REC FROM CTRL.FILE, "INVENTORY.CONTSTANTS" THEN
  LOCATE CONSTANT.NAME IN CONST.REC<1> SETTING CONST.POS THEN
    CONST.VALUE = CONST.REC<2,CONST.POS>
  END ELSE
    BOMB
  END
END ELSE
  BOMB
END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top