program generation

Hi
I need to generate a subprogram programmatically.
Not using construct or any such ready made utilities.
To start with can you provide a template program which will enable to this ?
I assume we would be using STACK commands for STRUCT , GLOBALS SM=ON …etc…
Would be great if someone could help on this.
Thanks ,
Anila

Hi Anila;

There are two ways to approach this challenge. I have attached an issue of Inside Natural that addresses both.

The first (page 33) uses the %C command to allow you to WRITE to the editor area.

The second involves using “ampersand variables”, which are not variables at all. They are text which will be substituted for. (page 34)

If you have questions, please just post them here.

steve

Whoops; forgot to attach the Inside Natural issue:

steve
IN Vol 11 No 4.pdf (176 KB)

Hi Steve ,

Thank you for the answer.
I tried the small sample code given in the document and for
‘INCLUDE AASETC’ , it gives me a compilation error ‘NAT0082 Invalid command, or AASETC does not exist in library.’
Maybe this utility does not exist in our system ??

Thanks ,
Anila

Sorry; AASETC and AATITLER are just small pieces of copycode that have nothing to do with thw code itself. AATITLER is an override WRITE TITLE statement, and AASETC is a SET CONTROL ‘C’ that I use to place the output in the editor area.

steve

Thanks again .
Actually the scenario here is that earlier this program was reading a CONNECT document (which had all the &variables) . Another natural program used to read this CONNECT document line by line and replace all the ‘&’ variables with the values from a particular adabas file.
Now this CONNECT documents is not used (it looks just like a program).
So i hadto copy the lines inside the CONNECT document to another
another program and i have replaced the ‘&’ varaibles with the file variables inside this program.
This CONNECT document is actually the generated code required finally.
But now this CONNECT document is in the form of a program(with me having replaced all the & variables from files and with input from the online screen…). so do i give write statements for every single line so that it writes to the new editor screen ?
regards
Anila

Hi Anila;

It sounds as if you were “manually” doing what the ampersand variables were designed to do. When you RUN a program with ampersand variables, the Natural compiler substitutes the value of a corresponding global variable. Thus, if you have DISPLAY &DISPLAY in the program, and the contents of +DISPLAY is NAME CITY, this would become DISPLAY NAME CITY.

Take a look at the example in the Inide Natural issue I attached earlier.

You should be able, if I am understanding the problem correctly, to put the ampersands back in the program, save the program, then, during execution, get the appropriate values from an Adabas file, move the values into the appropriate global variables, and RUN the program with the ampersands.

Let me know if I have interpreted the problem correctly.

steve

Hi Steve ,
Thanks again for the patient reply.
You got my question right and I did try to use the program with the ampersands again and just save the program not stowed it.
But am not sure what is the type I should save the program as (P or N ) as it finally gives me the error that the module is not found cos it is just saved and not stowed.
Actually I tried it yesterday too(with type 'T for TEXT) before reading your reply mail but since i got this error I thought I was going wrong somewhere.
So if you could tell me what is the type I should store that module as I can try it once again.

Regards
Anila

Hi Steve ,
Sorry I had made a mistake . I had given a callnat …but should have actually given a RUN . But I still have the question as to how we should ideally store that module which has ampersand variables. Should it be a type P or type N or anything else.

Regards
Anila

The ampersand program should be type P.

steve

Hi Steve ,

Am back again !
Actually your inputs were sufficient to display some text in a new editor screen .
But here the scenario seems little more complicated.
Calling program P1 makes a callnat to subprogram S1. There is some logic in the program to access some files and then I have the RUN statement for my program with ‘&’ variables’(call it R1).
When I execute the RUN, the contents of R1 are displayed in a seperate editor screen. But this is not the required result.
R1 has a logic like READ OBJEKT FILE WITH #KEY
COMPRESS &OBJEKT TO VALUETABLE(I)

The output expected in the editor are values of &OBJEKT
eg. COMPRESS ‘A’ TO VALUETABEL(1)
COMPRESS ‘B’ TO VALUETABEL(2)

instead now what appears in the editor is ‘COMPRESS &OBJEKT TO VALUETABLE(I)’

I hope am clear in explaining it to you .
Looking forward to your reply.
Thanks again :slight_smile:
Anila

Hi Anila

You will never see the substituted values. When you do the RUN statement, Natural reads the program (with the ampersands) into the editor area. Then it compiles the program, then it executes the resultant object code. The editor area does not change. The resultant object code does not get stowed.

Do you need the source code after the substitution? Or just need to have the code executed?

steve

If I understand your question correctly, it

Thanks to Steve and Curtis for the replies.

Steve , for the question you asked the answer is yes . I would need to keep the source code (which should have the substituted values)

Earlier what was happening is the program with the ‘&’ variables were stored as a CONNECT document and there was another natural subprogram which reads this CONNECT document line by line and replaces the ‘&’ variables and the final result was a program with no ‘&’ variables (I donno how !! ).Now that CONNECT document is no longer available and thats why I’m doing all this.
In case there is a way to display values through some other method other than what I’m following currently , so let me know.

Thanks and regards
Anila

Hi Anila;

I can think of two ways to approach the problem of not only creating, but saving, the programs.

The first involves a USR (do not remember the number off hand, but you can look it up) which allows you to maintain source code. I think this would be a bit cumbersome for what you want to do; but it is certainly possible.

The second is to use the %C command. This not only writes output to the screen, it also appends to the editor area. To see how this works, run the following program.

SET CONTROL ‘Z’ /* EMPTIES THE EDITOR AREA
AT END OF PAGE
SET CONTROL ‘C’
END-ENDPAGE
WRITE ‘THIS MIGHT BE A FIND STATEMENT’
WRITE 'THIS MIGHT BE A DISPLAY STATEMENT
WRITE ‘END’
END

You will want to save this program before running it, otherwise you will lose all your typing when the %Z is executed.

steve

Hi Steve ,

I tried the sample program you gave . In fact I had tried it once earlier after reading the Natural pdf document you shared with me. I’m able to generate a new program with it and it does serve the purpose also .

But here in my case am not using hardcorded or predefined text like '‘THIS MIGHT BE A FIND STATEMENT’

For example , I need to display
Compress ‘A’ into #value (I)
where ‘A’ is the value of the ‘&’ variable which is in turn populated only at runtime. Populated but not replaced and in my case it is like I would need it replaced.
Also the number of compress statements varies with the number of records got from the FIND statement. If have 10 values then I woulkd have to print 10 statements.
COMPRESS ‘A’ TO VALUE(1)
COMPRESS’B’ TO VALUE(2)…ETC
The sum up my question, it is about how to replace the ‘&’ variables with values.

Regards
Anila

I think you misunderstood my last posting.

In the “driver” program, you would get the data that will determine what you want the “report” program to contain.

Then you will have

WRITE ‘FIND VIEW WITH…’
FOR #LOOP = 1 TO some value
WRITE 'COMPRESS “A” TO VALUE (#LOOP) /* WHY NOT MOVE?
END-FOR

etc.

The driver program is creating the final report program, which would have all the appropriate ampersand substitutions made.

steve

Hi Steve ,
Actually in the generated program I dont want the FIND statements .
It should have only the Compress statements.

When I try to use the ‘&’ variable in the FIND statement like FIND view-name with ‘&key’ in the output program then its ok .
But in my case i dont need any find statements .
I should display some thing like
COMPRESS ‘&value’ into VALUE (where VALUE is a field declared in the DEFINE DATA of the called program )

But it gives me a syntax error when i try to use ‘&’ variable in a COMPRESS statement. Maybe thts the wrong usage ? Is it meant only to be used to replace key values in READ and FIND statements ??

Regards
Anila

Hi Anila;

Clearly we have a communication problem here. javascript:emoticon(’:)’)

What do you mean you want the generated program to have only COMPRESS statements? Are the FINDs just to get the proper values for the COMPRESS?

&variables can be used absolutely anywhere in Natural. It is not just for READ and FINDs. Actually, in the first example I sent you, I had DISPLAY &DISPLAY with the names of the display fields in +DISPLAY.

Show me the program where you get the syntax error with a COMPRESS.

steve:)

Hi Steve ,
Sorry for the delayed response but I hadnt checked the forum posts for few days .
My output program should like this .
This isthe program which shouldbe generated so that the end user can jus stow and use this program for future purposes.

DEFINE DATA
PARAMETER
01