4 6 Use an Exchange List and the OPTION ALWAYS Exchange Option

LANSA Application Design

4.6 Use an Exchange List and the OPTION(*ALWAYS) Exchange Option

The EXCHANGE LIST is the preferred way of passing information from function to function within LANSA applications. Only ever use PARAMETERS to pass information from RPGIII or CL into LANSA applications.

When a new application system is being defined, it is useful to identify any information which should always be available to be exchanged by every program within the application. This can save having to make later complex amendments to program suites, AND will often improve application performance by saving repetitive logic in many different programs.

Let's take an example of information falling into this category within an application suite - a general ledger system. During the design phase of this system the analyst or designer would fairly quickly identify that:

  • Nearly every program needs to know the company number of accounts being worked with.
  • Most online programs display the description of the company being worked with on line 2 of any screen.
  • Many programs request the user input an account number. It would be useful if the last account number being used was always presented as a default value.

The best way to achieve these aims is to define a "global" exchange list as in the example below. Such a list should be included into all programs which are part of the application system - whether these programs appear to use the information or not.

EXCHANGE FIELDS(#COMPNOUSE #COMPDSUSE #ACCNOUSE) 

         OPTION(*ALWAYS)

 

Some points to note about this command are:

  • The use of the names #COMPNOUSE, #COMPDSUSE and #ACCNOUSE. According to the standards of field naming recommended by this guide, these fields are clearly work fields. The actual database fields would be called #COMPNO, #COMPDS and #ACCNO.

The use of work fields is done for one reason only. To prevent an RDML function that is FETCHing or SELECTing data from the database (i.e., fields named #COMPNO, #COMPDS and #ACCNO) from inadvertently overwriting the global exchange values with something that may well be rubbish.   The three 'USE' versions of the fields would all be defined in the data dictionary.

  • The requirement that this command be included into every program in the suite can be more rigorously enforced if the command is included into any application templates used to generate this system.
  • Any template used by programs in this suite should contain the global EXCHANGE command. However, it may also be advantageous to include standard layouts for screens or reports with standard locations for the globally exchanged information.

   For instance, the following sample GROUP_BY (used for screens layouts) and DEF_HEAD (used for report layouts) commands might be included into a template:

     GROUP_BY NAME(#XXXXXXXXX) FIELDS((#COMPNOUSE *L3 *P2 *LABEL) +

              (#COMPDSUSE *L3 *P20 *NOID))

 

     DEF_HEAD NAME(#XXXXXXXXX) FIELDS((#COMPNOUSE *L1 *P1 *LABEL) +

              (#COMPDSUSE *L1 *P20 *NOID)(#TIMEDATE *L2 *P1 *LABEL) +

              (#JOB *L2 *P20 *LABEL)(#USER *L2 *P45 *NOID) +

              (#JOBNBR *L2 *P52 *NOID))