Local procedures are very easy to create and use. They are added to a procedure and share the local data of the parent procedure, but can also have their own data. They provide an easy way to isolate chunks of code that is being used repeatedly. Routines provide that too, but local procedures have the advantage that they can take parameters and return values, which routines can not.
You need two things to create a local procedure.
- Add a MAP statement in the "Declaration Section" embed in the procedure
- Add the procedure into the "Local Procedure" embed.
In the "Declaration Section" embed - I always put the MAP first in it so it appears as close to the top as possible - you put the declaration for your procedures:
MAP !! Declare Local Procedure(s)
In the "Local Procedures" embed you put in the implementation code for the procedure:
MyLocalProcedure PROCEDURE()!!,LONG CODE
And then you add your code. Remember that in the MAP section you define any data type that the procedure might return, in this case a LONG. When you implement the procedure you need to either remove the return type or comment it out. I always use comment as then I can see what the return type is.
Once you have declared and implemented the procedure, you call it like any other procedure in your code. In this case you would use:
ReturnValue = MyLocalProcedure()