Hi,
I need assistance to achieve the below output:
I have a Program with IF condition:
IF #Cnt = 0
Escape Bottom
END-IF
I need to achieve:
IF #Cnt = 0 Write ‘Inside If Condition 1’
Escape Bottom
END-IF
This new code should be written into a new Program and Stowed.
I have tried the below reference Programs but could not achieve the final outcome:
USR0210P - Save, CAT, STOW a module
USR1057N Read a Natural source code into an array
USR2019N Read or save Natural source code from/to the source area
Hi,
I need a create a new version of the existing code with new lines of code introduced inside every If and Else conditions for testing purpose.
So, I intend to read the existing Program in to memory/array using the system program and insert a new WRITE statement inside IF / Else Conditions.
Then, write this as a new Program and STOW to execute.
When I use the system programs I am able to retrieve the program into an array and insert lines in between but unable to save and stow them as new program.
Hi Giles,
Unfortunately it does not give an error, the execution completes. The new module gets created and STOWed with the contents of the Program that is being executed and not the one that I have edited with inserting statements in it.
Ex: RUN program A to read Program B to insert new lines and STORE as C.
C is created with contents of A but not with that of B. It does not fail with any error.
I have used:
USR1057N Read a Natural source code into an array
Callnat ‘USR1057N’ with Parameters to READ Program ‘B’.
Examine the Array for ‘IF’. when the index > 0, te insert a WRITE statement
Break out of the loop once I encounter an END Statement.
I have then used:
USR0210P - Save, CAT, STOW a module
To STOW the new Module ‘C’.
But when I open the new Module, the contents are that of Module A with every line of it from Define Data till END including ‘CALLNAT’, ‘EXAMINE’ statement but not of B.
You better read the description of USR0210N again. It will save the source that is currently in the edit buffer. Since you used USR1057, program B is NOT in the edit buffer but in a normal data array.
There are 2 ways of doing this:
You can use something like USR2019 to read program B into the edit buffer and then use USR0210 to write it.
or
use USR1057 to read program B into an array and maybe use USR4208 to write the new program.
Hi Ronald,
Greetings.
Thankyou for the inputs.
Yes, I have tried the first option you have mentioned (USR2019 and USR0210)already but the Output is that I am unable to edit the Buffer. The New program is just a copy of the existing Program asis.
I did try the second option you mentioned (USR1057 and USR4208), but after reading the Program into an array when I write using USR4208 it creates a Resource type new module which is empty.
Have you considered unloading the source using SYSOBJ then manipulating that ? I have done something similar in the past. You can process then unloaded file as a work file in a Natural program then re-upload the source.
However, there is already a utility that does this quite nicely; it is Natural’s debugger. It does not require creating second copies of all your code. It works without altering your source code.
The facility you describe would basically require the placement of “breakpoints” throughout code. Natural’s breakpoints would add functionality such as examining the values of any/all variables .
The debugger also has a mode called single step that would allow you to follow an execution one Natural statement at a time.
Of course, you would not only have to add line inside of IFs. You would have to have similar code inside of DECIDEs as well. Then there are implicit CALLNATs, commands placed on the Stack, etc etc.
Even working with just IFs, what you propose is a daunting task. Suppose you have only five IFs in a program. You would have to test every T/F permutation of the five IFs, or thirty two paths of execution.
Hi Steve / Ronald,
Yes you are Correct that Debussger is a better approach.
But, we are trying to check if the Developer executes test cases satisfying all the conditions and not to see what values the variables contain. We do not want to execute one line by line with breakpoints in Debugger.
We are trying to execute Batch modules and at the end see if all conditions have been covered.
Hence we are trying to put in some Display statements to make sure every condition is tested.
Hi Ronald,
Could I request you to kndly advice on the USR module to modify the edit buffer?
I have looked thru the “SYSEXT” library - Examples of Application Programming Interfaces, but could not find one.
Not sure if I have overlooked and missed the one important to me. Kindly assist.
Aha! Explaining what you are trying achieve helps us help you. Have you looked at the profiler utility built into MF Natural? It can tell you how often a statement has been executed. NaturalONE has recently added a GUI interface for the utility as well.
This approach has the big advantage that you are testing the actual code and not a modified version.
Interface Versions … USR1035N, USR2014N
.
Function … Maintain the sources of Natural objects that
can be edited with the program editor (programs,
subprograms, subroutines, helproutines,
copycode, text, class, function).