DN API: Document Number Increase, Roll Back or Validate
In Elliott V8.5, the system supports alphabetic document numbers. The logic to sequentially assigning the next document number is complicated. For example, if the existing document number is AAZ999. Then the next document number will be ABA000. We use the algorithm so the alphabetic digits stay alphabetic and numeric stay numeric. Instead of imbedding this complicated logic in the application codes, it make sense to have a system-level API call to handle this complication.
A new API is available in V8.5 and up to increment the document fields by 1 and to also check if we can roll back (reverse) the increment if no other user has incremented the number. This type of code would be used when there is no user interface and the document numbers are incremented programmatically.
Move “DN,-” To Screen-Parameters
Move “AP-CTL-LAST-VOUCHER-NO” To Screen-Field-Domain
Move Last-Voucher-No to Screen-Alpha-Field
Perform Screen-Routine
The new value in AP-CTL-LAST-VOUCHER-NO is returned in SCREEN-ALPHA-FIELD. If an error occurs, SCREEN-ANSWER will contain "N."
Move “DN,+” To Screen-Parameters
Move “AP-CTL-LAST-VOUCHER-NO” To Screen-Field-Domain
Move Spaces to Screen-Alpha-Field
Perform Screen-Routine
Move Screen-Alpha-Field to New-AP-Voucher-No
Note: If the domain name contains the string "-LAST," the DN,+ call will increment the number on the file and then return that number in Screen-Alpha-Field. If the domain name does not contain "-LAST," that implies that the number in the file is the next available number, not the last used number. Accordingly, the DN,+ call will return the number in the file, and then increment the number in the file. This all means that the DN,+ call will always return the number you should use for a new document.
The DN API can also be used to increase or decrease an alpha document number without updating the master number. This is useful in situations where there is no master number on file but the application code computes the next number by finding the last record on file in the database. An example of this situation is alpha tag number support. The next tag number is calculated based on the highest tag number on file. Once the highest tag number is retrieved, the application will add 1 to the last value. This is not possible when using alpha document numbers. The DN API takes the place of the add statement, performs the computation and returns the value in SCREEN-ALPHA-FIELD. If an error occurs, SCREEN-ANSWER will contain "N."
Move “DN,+” To Screen-Parameters
Move Spaces To Screen-Field-Domain
Move Last-Tag-No to Screen-Alpha-Field
Perform Screen-Routine
Move Screen-Alpha-Field to Count-Tag-No
Move Screen-Alpha-Field to Last-Tag-No
Notes:
The DN API can also be used to validate a document number. This can be used, for example, when importing data from an outside source:
Move "DN,V" To Screen-Parameters
Move "COP-CTL-START-ORDER-NO" To
Screen-Field-Domain
Move IMP-ORDER-NO To Screen-Alpha-Field
Perform Screen-Routine
If Screen-Answer = "Y"
Move Screen-Alpha-Field To IMP-ORDER-NO
...
Else
Move Screen-Literal to Error-Message
End-If
If the format of the input matches the required format for that document, Screen-Answer will contain "Y." If not, Screen-Answer will contain "N" and Screen-Literal will contain a description of the error.
Note: Additionally, the application code can allow the DN,V code to properly align the input document number (e.g., right-justify and zero-fill a numeric document number) instead of coding that on the application side. When that is the case, the application code must move Screen-Alpha-Field back to the source field after the DN,V call, because what is in Screen-Alpha-Field passed the validation, not the input source. For example, if the input value is "AB123," it will result in error since the value is alphabetic and hence the length must be 6 digits long. On the other hand, if the input value is numeric, then the length of the value is OK when it is less than or equal to 6 digits.
There is a special logic for domain PO-CTL-STARTING-PO-NO where systems can validate input with or without a dash. For example, if the input is "9999," the system will deem this to be OK and return 0099999 by filling in leading zeroes on the left in the SCREEN-ALPHA-FIELD. On the other hand, if the input is "9-99," the system will validate this to be OK and return 000009-99 as the return value.
The DN API can also be used to validate a "next" document number like the next order number for COP:
Move "DN,F" To Screen-Parameters
Move "COP-CTL-START-ORDER-NO" To
Screen-Field-Domain
Move COP-CTL-NEXT-ORDER-NO To Screen-Alpha-Field
Perform Screen-Routine
If Screen-Answer = "Y"
...
Else
Move Screen-Literal to Error-Message
End-If
CLS/JEG
Updated: 6/8/23