Programming Examples

In the example that uses the E@DBFINDBEGRNG call, we only define one value for the Sub Account key field. This means that the E@DBFINDBEGRNG and E@DBFINDPRVRNG calls get only those records where Company, Account, and Sub-Account exactly match the single key field values set in the D@ fields.

In this new example, we give two values for the last key field defining the range: a beginning value (in D@SBACCN) and an end value (in D#END#SBACCN). The E@DBFINDSUBRNG and E@DBFINDPRVRNG calls must still get only those records that exactly match the key field values set in the D@ fields for Company and Account. However, this time the returned records no longer need to have a value for Sub-Account that exactly matches the key field value defined in the D@field. Instead, the record must have a value for Sub-Account that lies within the range specified by the D@SBACCN and D#END#SBACCN fields.

      EVAL      D@CMPNY        = VIFACWS@CMPNY 
      EVAL      D@ACCUNT       = VIFACWS@ACCUNT
      EVAL      D@ACCNT        = VIFACWS@ACCNT 
      EVAL      D@SBACCN       = VIFACWS@SBACCN
      EVAL      D#END#SBACCN   = VACACWS@SBACCN
      EVAL      E@DBSUBRNG     = 3
      CALLP     DN@DBIFGLM1(E@DBFINDBEGRNG)
      DOW       DGLM@NOTFOUND  = FALSE                 
      CALLP     S1@L422                     Process Detail
      CALLP     DN@DBIFGLM1(E@DBFINDPRVRNG)

This sample assumes the code is from a batch program whose parameters include a Vendor Group field, a Vendor Class field, and two fields to set a range of vendors to be processed by the batch program.

  1. The first key variable (Vendor Group) for Vendor index #2 is populated from the Vendor Group field value.
  2. If the Vendor Class field has a value, that value is used to populate the second key (Vendor Class).
  3. If the second of the two vendor range fields has no value, then the special range variable, E@DBBEGRNG is set to 2. This variable is used to indicate the last key defining the range for the E@DBFINDBEGRNG function. In this case, this means that the last key to be used is Vendor Class. The third key, Vendor, is not being used.
  4. The E@DBFINDBEGRNG is then called.
  5. Then the two vendor range fields are used to populate two other variables used by subrange functions. The D@VENDOR and D#END#VENDOR set the beginning and ending values for the last key. In this case, the last key is Vendor, which is the third key for Vendor index #2.
  6. Thus, E@DBBEGRNG is set to 3 before the E@DBFINDSUBRNG function is called.
           EVAL      D@VNDGRP       = F1@VNDGRP  
           IF        F1@VNCLSS <> *BLANKS          
           EVAL      D@VNCLSS       = F1@VNCLSS       
           IF        F1@THVNDR = *BLANKS             
           EVAL      E@DBBEGRNG     = 2            
           CALLP     DN@DBAPVEN2(E@DBFINDBEGRNG)       
           ELSE                                      
           EVAL      D@VENDOR       = F1@FRVNDR    
           EVAL      D#END#VENDOR   = F1@THVNDR 
           EVAL      E@DBSUBRNG     = 3                
           CALLP     DS@DBAPVEN2(E@DBFINDSUBRNG)