Defining Functions › Function Types, Message Types, and Function Fields › DSPTRN Device Function › Automatic Line Numbering
Automatic Line Numbering
A common requirement when using Edit Transaction functions is to have line numbers for the subfile records issued automatically.
For example, Order and Order Line files could be defined as follows:
FIL Order CPT Known by FLD Order CDE
FIL Order CPT Has FLD Order date DTE
FIL Order line CPT Owned by FIL Order CPT
FIL Order line CPT Known by FLD Order date DTE
FIL Order line CPT Refers to FIL Product REF
FIL Order line CPT Has FLD Order quantity QTY
If an EDTTRN type function called Edit Order is created over the Order and Order Line files, you might want the order line numbers issued automatically. This can be done as follows:
- Change the Edit Order function:
- Use the Edit Device Design panel to add a function field of type MAX to the order header format (F19), the Highest Line number. This field should be defined as a REF field, based on the line number, so that it calculates the highest line number used so far. Neither the MAX field nor the line number fields need appear on the screen, but can be hidden.
- Use the Edit Action Diagram panel to change the call the Create Order Line function so that the Highest Line number field from the CTL context is passed to the Order Line number parameter of the CRTOBJ function.
- Change the Create Order line function:
- Use the Edit Function Parameters panel to change the Order Line number parameter to be a Both parameter rather than Input parameter so that the incremented value is returned to the Highest Line number field.
- Use the Edit Action Diagram panel to increment the Highest line number field by one before writing to the database. Return the incremented value to the order line number parameter after writing the record to the database.
For more information on user points, see the chapter "Modifying Action Diagrams."