Request assistance to Dynamicallyt add code in to an esisting Module

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

Regards
Sreekanth Prasad

that’s not enough information. You need to supply more about exactly what you are doing.
What error message you are getting?

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.

I hope this gives more info.

It all sounds a bit odd. But if you supplied the error message you are receiving that might give some clues about what you are doing wrong.

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.

Looks like you will have to fix your own bug :lol:

Hi,

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.

vh
Ronald

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.


OPT-ACCESS := 'R'                                   
LIBRARY        := *LIBRARY-ID      
USR1057L.OBJECT-NAME    := 'TST213'
OPT-LINE-NUM   := 'Y'              
OPT-REDEF-DIR  := TRUE             
OPT-AMOUNT     := 20               
OPT-LINESIZE   := 72               
V3-EMPTY-BLANK := 'Y'              
CALLNAT 'USR1057N' USR1057L  USR1057N.EXTENDED-PARMS
  NAD-MSG   NAD-FLD                                 
*
RESOURCE-FUNCTION := 'W'                               
LIBRARY-NAME      :=  *LIBRARY-ID                      
USR4208L.OBJECT-NAME       := 'TST230'                 
OPTION-REPLACE    := 'N'                               
/*                                                     
*                                                      
RD-RESOURCE-LIBRARY     := LIBRARY-NAME                
RD-RESOURCE-OBJECT-NAME := USR4208L.OBJECT-NAME        
RD-RESOURCE-NAME        := RESOURCE-NAME               
RD-RESOURCE-TYPE        := 'N'                         
RESOURCE-FUNCTION := 'W'         /* WRITE THE RESOURCE 
CALLNAT 'USR4208N'                                     
  USR4208L    USR4208N.EXTENDED-DATA (*)               
  NAD-MSG     NAD-FLD                                  
*                                                      
It creates an empty Resource file in the library.

Name Type S/C
TST*_____ *__________ *__
TST230 Resource S

I am basically trying to add a line inside every IF condition to make sure we test and satisfy all conditions during testing.

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.

An ambitious goal.

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.

Good luck.

well, I have to agree with Steve. If this is just a matter of testing then you should use the debugger.

but as an aside: of course there is also a USR module that lets you modify the edit buffer… :slight_smile:

regards,
Ronald

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.

Regards
Sreekanth Prasad

Hi Sreekanth,

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.

Cheers, Graeme

Hi Graeme,

greetings.

Unfortunately profiler is not available for use. Hence we are trying for a work around to ensure the developers test all conditions.

Thankyou for your suggestion. Please advice any other approach.

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).