The SUBDIALOG clause

The SUBDIALOG clause attaches a declarative dialog to the current procedural DIALOG block. The declarative dialog must be implemented as a DIALOG block, outside of the scope of the current dialog, at the same level as a function. The declarative dialog can be defined in a different module.

Declarative DIALOG blocks

A declarative dialog block is defined as a module element, at the same level as a FUNCTION or REPORT routine. The purpose of a declarative DIALOG block is to be referenced in a procedural dialog block. Defining a part of a dialog in a separate module enforces code readability and reusability.

Module orders.4gl:

SCHEMA stock
DEFINE arr DYNAMIC ARRAY OF RECORD LIKE orders.*
DIALOG orders_dlg()
  DEFINE x INT
  DISPLAY ARRAY arr TO sr_orders.*
     ...
  END DISPLAY 
END DIALOG

The name of a declarative dialog is mandatory. It will be referenced by the SUBDIALOG clause, and will be used to identify sub-dialog actions with a prefix.

Procedural DIALOG blocks

A procedural dialog block is defined with the DIALOG keyword in the scope of a FUNCTION. It defines local sub-dialogs or references declarative dialogs with the SUBDIALOG keyword:
Module customers.4gl:

SCHEMA stock
DEFINE rec RECORD LIKE customers.*
FUNCTION co_list()
  DIALOG ...
    INPUT BY NAME rec.*
      ...
    END INPUT
      ...
    SUBDIALOG orders.orders_dlg
      ...
  END DIALOG
END FUNCTION

Semantics of a declarative DIALOG block

In terms of semantics, behavior and control block execution, a declarative dialog attached to a procedural dialog behaves like a sub-dialog that is defined inside the procedural DIALOG block. For example, the BEFORE INPUT control block will be executed for a declarative dialog when the focus goes to one of the fields of that sub-dialog.

Other sub-dialogs can reference the attached declarative dialog in the current scope, for example to execute a NEXT FIELD instruction referencing a field in another sub-dialog.

When using the DIALOG keyword inside a declarative dialog block to use ui.Dialog class methods, it references the current procedural dialog object.

Identifying a declarative dialog

Like other module elements such as functions and reports, the name specification is mandatory when defining a declarative dialog. The name of the declarative dialog will be referenced in a SUBDIALOG clause of a procedural dialog instruction.

Reusing form parts with the FORM layout clause

Implementing a sub-dialog as a declarative dialog in a separate module can be used in conjunction with the form inclusion directive in the LAYOUT section of form specification files. With form inclusion and declarative dialogs, you enforce code reusability in your application sources.