Run sentences from variable

Hi,

i’m looking for if it’s posible to move data into a variable, when that variable is defined into another one (their name) or same other solution to my problem. I will explain you.

We need some similar to this ’ CALLNAT W-VARIABLE ’ where w-variable have the name of the program we want to run.

The problem is that we have to move data into a field of a parameter, but what it is that field i dont know in compilation time, only in ejecution time.

Unique solution i can think is prepare a big DECIDE VALUE with all the fields of the parameter (more 100) with a MOVE into each field. I’m looking for another alternatives.

Thanks!

Hi Antonio,

I am not certain whether I understand your problem.

I have two ideas re the problem, which are basically the converse of one another.

Idea 1)

There is an already written subprogram called W-VARIABLE, which has a field in the parameter data area defined as shown below:

DEFINE DATA PARAMETER
1 #ALL-VARIABLES (A100)
1 REDEFINE #ALL-VARIABLES
2 #V1 (a3)
2 #V2 (a5)
etc.

You are going to write a program that CALLNATs this subprogram. Based on the value of some field(s?) , you have to do something like MOVE some-value TO #V14 before doing the CALLNAT.

Idea 2

You are going to be writing the subprogram W-VARIABLE. Based on the value(s?) of some field(s) before returning to a program that is using your subprogram you must do something like MOVE some-value TO #V9.

Questions:

Is idea 1 or idea 2 (or something else) the problem you actually have?

You said you were thinking of doing a DECIDE VALUE to perform the MOVE. Does that mean there is an array subscript available to you? If so, instead of #V1 #V2… etc, you could have #ALL-VARIABLES defined as some sort of array, which would simplify the coding.

Is W-VARIABLE already written (idea 1)? If so, I presume (is this correct?) you cannot alter it.

If you are basically forced to do something like you suggested, you should at least have a DECIDE FIRST with the most likely values first.

Please expand your problem description and re-post.

Hi,

i’m going to extend the situation.

There is nothing about a CALLNAT in my problem, that was only an example of the sentence i’m finding.

How you know well, Natural can run a CALLNAT recovering the subprogram from the content of a variable.
if i run “CALLNAT W-PROGRAM” not ‘W-PROGRAM’ be executed but it’s run the subrprogram loaded like text in this variable W-PROGRAM. That is i am finding to resolve my situación, to load data into a variable whos name is into another variable.

MOVE ‘field3’ TO W-VARIABLE
*

  • more sentences…

MOVE ‘XXXX’ TO W-VARIABLE

I want to load ‘XXXX’ into variable FIELD3, not into W-VARIABLE.
Something like MOVE ‘XXXX’ to VAR(W-VARIABLE)’.

I dont know exist something in Natural to do this. This is i’m asking you, if there are some possibility to get this, with some hack, userexit from SYSEXT, some utility or another thing.

For example, i have a parameter, with 100 diferent fields (no array) like this:

1 W-PARAMETER
2 field1 (A20)
2 field2 (a14)
2 filed3 (N8)

2 filed100 (a1)

1 TAB-FILE view of TAB-FILE
2 USER
2 FUNCIONALITY
2 PROFILE
2 etc. etc. etc
2 NAME-OF-FIELD-TO-RESET (A40/50) <------------

I have to reset the content of some of that field in this parameter, but what fields i have to reset i dont know in the code, because i will identify what concret field to reset from a ADABAS file (TAB-FILE in this example), recovered according a differnte situación, like funcionality running, *USER, etc, etc. The name of the fields are stored in the file like text, for example into a MU field.

With a FIND i recover the name of fields to reset, for example, ‘field3, field24, field47 and field78’.

Now, how i reset or move some data to field3, field24, etc, etc?

Any of the fields of the parameter are likely to be recover from the file.

Only solution i know it’s something like

FOR W-I to NUM-FIELDS-TO-RESET (or similar sentence)
DECIDE FOR FIRST VALUE NAME-OF-FIELD-TO-RESET(W-I)
value ‘FIELD1’
RESET field1
value ‘FIELD2’
RESET field2

  ... All the 100 fields would have to be declarated here

  value 'FIELD100'
          RESET field100

END-DECIDE
END-FOR

Nothing to talk about if it’s more or less eficient use FOR FIRST CONDITION or another. That it isn’t the problema. I know the answer.

I’m finding some more ‘professional’ method to do this than a DECIDE.

I tell you, there isn’t possibilities to recover the fields to reset from another methology. I have to recover from that ADABAS parametric file.

Thanks again.

Natural has a facility I call “ampersand variables” although they are not “variables” at all.

Here is a program:

MOVE ‘ABC’ to &TARGET
END

You can SAVE this program; suppose it is called SAVEPR

Now, from within another program, you can:

MOVE ‘#WHERE’ TO +TARGET /* +TARGET is either an old style global variable, or in a GDA
RUN ‘SAVEPR’

Basically, &TARGET is a text string, which the compiler will replace with the contents of +TARGET at compile time.

I have over simplified this above. There are navigation issues etc.

A major use would be in enduser query facilities. For example:

“driver” program

INPUT here you ask the user to enter a file name, a search criteria, display fields
after validating user input, move values to +FILE +SEARCH +DISPLAY
STACK TOP COMMAND ‘EXECUTE DRIVER’
RUN ‘REPORTER’

program reporter

FIND &FILE WITH &WITH
DISPLAY &DISPLAY

Works great. Usually, you would instead present the user with choices rather than giving them freedom to enter anything (validation could be expensive and time consuming). This essentially makes the system “idiot proof”, but you need different drivers for different people/projects etc.

This is at least something you might be able to use.

Hi again,

I don’t quite understand what you say.

You propose, if I misunderstood, to use an INDEPENDENT variable to save the name of the field?

But, how i can then move data into the variable named like the content of the independent? With & before?

i have tried do it with a & and not compile.

A resumed what i would like to get ( its posible to do this with the ‘&’ ? )

1 FIELD1 (A10)
2 FIELD2 (A20)

1 W-ASK (A50)

INPUT ‘Field you want to load data (FIELD1/FIELD2):’ W-ASK

MOVE ‘XXXX’ TO &W-ASK

If you load W-ASK in the input with ‘FIELD1’ i need to load ‘XXXX’ into variable FIELD1.

Regards!

As I mentioned in my last post, this can be quite complicated: I have written something that is a lot closer to what you want to do. I also suggest you read up on ampersand variables.

First, here is a driver program, called AMP01

  • THIS IS THE DRIVER PROGRAM
    DEFINE DATA LOCAL
    1 #FIELD1 (A10)
    1 #FIELD2 (A10)
    1 #SELECT (A8)
    1 #DUMMY (A3)
    END-DEFINE

RESET +SELECTER (A8)
IF DATA NE 3
INPUT 3/10 ‘ENTER #FIELD1 OR #FIELD2 HERE==>’ #SELECT
MOVE #SELECT TO +SELECTER
STACK TOP DATA #FIELD1 #FIELD2 /
IN CASE THEY ARE NEEDED IN AMP02
WRITE ‘=’ #FIELD1 ‘=’ #FIELD2 ‘=’ +SELECTER '… IN ’ *PROGRAM
RUN ‘AMP02’
END-IF
*
INPUT #FIELD1 #FIELD2 #DUMMY
WRITE ‘=’ #FIELD1 ‘=’ #FIELD2 ‘=’ +SELECTER ‘… BACK IN’ *PROGRAM
END

Now another program, AMP02. This program is to be SAVEd, NOT STOW’ed

  • THIS IS THE ACTION PROGRAM
    DEFINE DATA LOCAL
    1 #FIELD1 (A10)
    1 #FIELD2 (A10)
    1 #SELECT (A8)
    END-DEFINE

INPUT #FIELD1 #FIELD2 /* IN CASE THEY ARE NEEDED HERE
MOVE ‘SOMETHING’ TO &SELECTER /* THIS WILL MOVE TO #FIELD1 OR #FIELD2
WRITE ‘=’ #FIELD1 ‘=’ #FIELD2 ‘=’ +SELECTER ‘… IN’ PROGRAM
*
STACK TOP DATA #FIELD1 #FIELD2 '
**’
FETCH ‘AMP01’
END

This “system” works. If you run AMP01, you will see that you wind up back in AMP01 and either #field1 or #field2 has “something” in it.

If you want to pursue this further, I have an article I wrote on ampersand variables and will dig it out and post it. That will be easier than digging out the snow which is blocking our driveway.

Thank you very much for the help.

Regards!