![]() |
|
Natural Tip of Week of March 24, 2008 |
||
Subject:
Natural subprograms An optional parameter is a field defined with the keyword OPTIONAL in the DEFINE DATA PARAMETER. Here is an example of the Natural code: DEFINE DATA PARAMETER Invoking Object: The nX notation informs natural whaich positional parameter is to be skipped. This means that the address for that parmater is not passed to the invoked subprogram. This can only be mapped to a variable with the attribute OPTIONAL. However, you MUST write your subprogram with the foreknowledge that someone may invoke you and NOT pass the address of the variable. If one writes CALLNAT 'MYSUBPGM' #ARG1 #ARG2 #ARG3 and this is matched against PARAMETER You cannot (or I should say SHOULD not) write IF #NEW-OPTION ... If you do and the original program does the CALLNAT like above, then you will be referencing a variable with no address since it was not included in the parameter list and a Natural error occurs. The subprogram should then never reference such a variable directly, but instead should use the SPECIFIED Option in Logical Condition instead. With the new SPECIFIED option , you are able to check whether or not a parameter has received a value from the invoking object. Example: For a field not defined as OPTIONAL the SPECIFIED condition is "TRUE". I currrently try to keep ALL optional variables at the end, especially when extending an existing subprogram where every referenc does not need change. However the flexibility of the syntax does not force this as any requirement. Now there is a case I can fabricate that shows when this may not be important. Suppose like the old days you created a super module that can do a variety of activities based on input, for example a core date routine. Maybe you want one of several calculations it can provide. Let's say it has 10 inputs and 5 outputs and when a particular 2 are provided a specific output should get generated. Then if they are all optional (which is possible) then you would need to code CALLNAT 'DATERTNE' #A #B 8X #OUT1 or And the routine is smartly written to know which pair force a computation for which output which it can do with IF SPECIFIED. Here is to what I am refering: PARAMETER In combination with CALLNAT 'module' #A #B 1X #D You could write: IF #F3 SPECIFIED There are a few important errors which a user of the OPTIONAL attribute should be aware. - Natural System Message NAT0648 - NAT1322 Parameter 2 missing (invoked at line …). NAT0648 Parameter 3 inconsistently specified. Reason code 16. |
||
Here are three sponsors who have more materials on Natural & Adabas tips and techniques:
![]() |
![]() |
![]() |