Defining User Exits

This section explains what a user exit is and how to select and define one in NaturalONE. The following topics are covered:


Introduction

By default, the generated source code is protected from editing and changes can only be made within user exits, positions within the generated code where you can insert customized or specialized processing. Changes to the user exit code are always preserved upon subsequent regeneration of the module. We recommend that you only add custom code within user exits.

Warning:
Although it is not recommended, you can edit the protected lines in the generated source code outside of the user exits. However, your changes will not be preserved upon regeneration. For information about the protected lines in the generated source code, see Using the Source Editor/Protected Lines in Sources Generated by Construct or Code Generation in Using NaturalONE.

The code generation wizards provide a wide variety of user exits, which vary based on the type of module you are generating. Some exits contain sample code or subprograms, while others generate the **SAG DEFINE EXIT and **SAG END-EXIT tags only — you provide the actual code. You can modify any user exit code generated into the edit buffer.

Notes:

  1. For information on the supplied user exits, refer to User Exits for the Generation Models, Natural Construct Generation.
  2. For information about the User Exit editor, refer to User Exit Editor, Natural Construct Generation.
  3. If you require code to be inserted in the generated module where no user exit currently exists, have your Natural Construct administrator recommend a suitable exit or add a new exit to the wizard.

Define a User Exit

When a generated module is open in the Eclipse editor, all available user exits for the module are displayed in the Outline view. This section covers the following topics:

Tip:
If the user exits are not displayed in the Outline view, select graphics/user-exit-icon.png on the toolbar.

Access a User Exit

Start of instruction setTo access a user exit

  1. Select the user exit in the Outline view.

  2. Open the context menu for the user exit.

    For example:

    graphics/context-menu-for-user-exit.png

  3. Select one of the options listed.

    The user exit is displayed in the editor view. For example:

    graphics/user-exit-in-editor.png

    The **SAG EXIT POINT tag indicates that the exit does not exist and you must use the Outline view to add code or generate sample code.

Add Code to a User Exit

Start of instruction setTo add code to a user exit

  1. Open the context menu for the user exit.

  2. Select Add Code.

    The exit is displayed in the editor view. For example:

    graphics/user-exit-add-code.png

    The **SAG DEFINE EXIT and **SAG END-EXIT tags indicate that the user exit exists, even when there is currently no code in it, and you can define or modify the exit directly in the editor.

  3. Move the cursor to the end of the **SAG DEFINE EXIT user-exit-name line.

  4. Select Enter.

  5. Add the code on the lines provided.

Generate Sample

Start of instruction setTo add code to a user exit

  1. Open the context menu for the user exit.

  2. Select Generate Sample.

    The **SAG DEFINE EXIT and **SAG END-EXIT lines are displayed with sample code. For example:

    graphics/user-exit-generate-sample.png

  3. Move the cursor to the end of the **SAG DEFINE EXIT user-exit-name line.

  4. Modify the sample code as required.

Generate User Exit

This context menu is enabled only for special user exits such as WRITE-FIELDS and LOCAL-DATA. If you select this option, a dialog wizard that collects data for generating a user exit code is displayed.

To use this functionality you need to install Natural Business Services version 8.2.2.6 or higher on the NDV server.

Generate a LOCAL-DATA User Exit

If you specify a program view name on a Browse, Browse-Select, or Object-Browse model specification wizard panel, you must define the view for the file as a LOCAL-DATA user exit.

Start of instruction setTo generate a Local-Data user exit

  1. Open the context menu for the user exit.

  2. Select Generate User Exit. The Generate LOCAL-DATA user exit dialog wizard is displayed.

    The Generate LOCAL-DATA user exit window which shows the 'Define Entire View of Primary File' checkbox and the 'View is Defined in Local Data Area' text field.

    Using this widow, you can:

    Field Description
    Define Entire View of Primary File Mark this field to define the entire view of a primary file within a user exit. You can then edit the sample code and delete the fields you do not want.
    View is Defined in Local Data Area If the view is defined in a local data area (LDA), enter the name of the LDA in this field.
  3. Modify this wizard as desired.

  4. Click Finish to generate the user exit contents.

Note:
If you are using the LOCAL-DATA user exit with a model that is not a Browse, Browse-Select, or Object-Browse model, no wizard is displayed.

Generate a WRITE-FIELDS User Exit

The WRITE-FIELDS user exit offers the possibility to generate more complex user exit code based on the contents of the #PANEL variable.

Start of instruction setTo generate a Write-Fields user exit

  1. Open the context menu for the user exit.

  2. Select Generate User Exit. The Generate WRITE-FIELDS user exit dialog wizard is displayed.

  3. On the Select Predict Views page, you can select up to six Predict views. The Predict view from the model is added by default.

    The Select Predict Views window which prompts you to select up to 6 Predict Views.

    The following fields and buttons are available on this wizard page:

    Field/Button Description
    Name Shows name of the view.
    Fields Choose Select to display a selection page from which you can select the fields or All to select all the fields from the corresponding view.
    Add Shows a list of all available Predict views and adds the view you have selected.
    Remove Removes the selected view.
    Up Moves the selected view up.
    Down Moves the selected view down.
  4. Modify this wizard as desired.

  5. Click Next >.

  6. The Select Fields Page is displayed. It shows all fields from all Predict views whose Fields parameter you have set to Select.

    Select the fields to be used for the WRITE-FIELDS code.

    If you select a group field, all children of the group will be selected.

    The Select Fields window which prompts you to tick which fields to add to your write-fields code.

  7. Click Next >.

  8. The Enter Default Parameters page is displayed. On this wizard page you can specify the statement type, size, and spacing of the report.

    The Enter Default Parameters window which prompts you to specify the statement type, size, and spacing of the report.

    The following fields and buttons are available on this wizard page:

    Field/Button Description
    Generate statement type Type of Natural statement (DISPLAY or WRITE) used for the report. By default, DISPLAY is selected. If more than one panel is generated, but you have selected DISPLAY, the code will, nevertheless, be created using WRITE statements.
    Leading blank columns Number of blank columns preceding the report columns.
    Column spacing factor Number of spaces between fields on the report. The default is one space.
    Window/Line width Number of columns used for the generated report. If this field is empty, 80 is used.
    Underline Headings Tick this box to add or remove a line under headings. This field is selected by default.
    Blank lines after headings Number of blank lines below the header to be displayed in the ready report.
  9. Modify this wizard as desired.

  10. Click Next >.

  11. The Define the Appearance of the Report page appears. On this wizard page you can define the layout of the WRITE-FIELDS panels.

    The Enter Default Parameters window which prompts you to specify the statement type, size, and spacing of the report.

    The position of the fields is calculated automatically for any change affecting the field width, field order, or the line width of the report.

    If new fields are selected by going back to the Select Fields wizard page, these fields are added at the end of the report.

    The following fields and buttons are available on this wizard page:

    Field/Button Modifiable Description
    On Panel x Pick either Default or All from the drop-down list. All displays the field on all panels, and in such case the Panel value will be *. Default displays the field on one panel, and this case the Panel value will be the number of the panel where the field is located.
    Panel(Order)   Number of the panel and order on this panel where the corresponding field will be displayed.
    Label x Qualifier of the field. By default, the name of the view is selected.
    Field Prompt x Field names displayed on the report. The default headings in Predict are displayed. Entering a slash (/) can split the header over several rows.
    Field Name   The name of the field.
    Format   The format and length of the field.
    AL= x To override the default length of the corresponding field, type the new length in this field.
    OCC depends on field Number of occurrences of the corresponding field. If a fixed number is specified, that number is always displayed on the report (even if some occurrences are empty).
    SG=ON depends on field Sign option. Check this box to include a sign option for the corresponding field (SG=ON) in the generated report.
    AD=I x Check this box to intensify the corresponding field (AD=I).
    EM=ON depends on field Check this box to use the Predict edit mask for the corresponding field (EM=ON).
    CD x Select the color definition for the corresponding field from the drop-down list.
    Up   Moves the selected field up.
    Down   Moves the selected field down.
  12. Click Finish to generate the user exit.

    Depending on the input values, this generation could also create code in the user exits BUILD-REPORT-LOCAL-VARS and TOP-OF-PAGE.

Note:
After creating the user exit code in the model source, you must save the source and regenerate it. Regeneration can be achieved by selecting the menu Code Generation > Regenerate… for the source.

Clear Exit

Start of instruction setTo clear code from an existing user exit

  1. Open the context menu for the user exit in the Outline view.

  2. Select Clear Exit.

    All lines of code within the selected exit are deleted and the comment line that identifies the insertion point for the exit within the editor is restored.

Modify Code in a User Exit

Start of instruction setTo modify code in a user exit

  1. Select the user exit in the Outline view.

    The user exit is displayed in the editor.

  2. Modify and save the user exit.

Note:
You can make changes to user exits equivalent to the Add Code and Clear Exit options by modifying these lines in the editor view — without using the context menu for the Outline view. If you do this, ensure you do not change the ** SAG comment lines.