Function Object Type in Natural

I encountered object type FUNCTION when I was reviewing my basics on Natural’s objects. I have never encountered a program using this object type before. I see that it has quite a few restrictions so I am not sure when exactly it would be beneficial to use this object type. Has anyone used Function before? What do you usually do it for?


That you never encountered a user function before is probably because it was added to Natural quite recently.

If and how you would use it depends a little on personal preference I would say. People who are used to programming in a more recent language like Java or C# or whatever would be right at home since most modern languages use functions almost exclusively when separating/isolating functionality. In Natural you already have subprograms, copycodes, in- & external subroutines and programs that you can FETCH RETURN so you have a bit more choice depending on your specific situation.

The ‘advantage’ of user functions is that you (can) use them within another program statement which, depending on your personal preference, might make it a bit easier to read. Since function names can be 32 characters long it should be possible to come up with some very descriptive names. So when you for example have a date field where you want to find out which day of the week it was and put that result in some other variable, the ‘old’ way could look something like this :


with a function it could look like this:


I guess it’s up to the individual reader to determine if they think this looks better or not.


Thanks Ronald!

I tried this out of interest; created a function (DBFIBF) and called it from a program - all works OK in my private library. But when I copy it to our application library I get NAT0728 error on the invocation statement:
#FN := DBFIBF (<#N>)
Error message: NAT0728 Keyword “(PT=…” OR “(IR=…” expected.
But I cannot find any doco as to how to code these keywords (PT/IR). Any ideas?
(on Natural 8.2.3 under z/OS 1.12)

Hi Kevin;

Check the Natural Documentation

Follow the links for IR and PT.

Or, take a look at the help for the DEFINE PROTOTYPE statement.

Did you compile the function in the new environment? I believe that error can be generated when it can’t find the compiled object. I’ve yet to encounter a situation where I need to worry about PT or IR. If you have just created a simple function, I wouldn’t think you’d need to either.

Aha - a sneaky one.
As well as creating my first Function object, I was using a recursive call technique. It could not compile as it was checking to see if the invoked function (itself) already exists.
Solution was to remove the recursive call; stow the object; then reinstate the call and restow.