Database Function Code Samples

The following samples show the basic setup for several database find functions. Examine the source files for examples of other database functions.

E@DBFINDGE

C                   EVAL      D@CMPNY        = F1@DPTCMP 
C                   EVAL      D@PRCSLV       = F1@PTDPLV     
C                   EVAL      D@DPRTMN       = F1@PTDPDP     
C                   CALLP     DN@DBHRDPT1(E@DBFINDGE)        
C                   IF        F1@FC = '-'                    
C                   CALLP     DN@DBHRDPT1(E@DBFINDPRV)       
C                   ENDIF                                    
C                   IF        DDPT@NOTFOUND <> FALSE         
C                             OR  DDPTCMPNY <> D@CMPNY       
C                   EVAL      E@ERRORNBR     = 105       
C                   EVAL      E@FIELDNBR     = F1FN@FC   
C                   RETURN                               

This sample assumes the code is from an online program for departments. The key fields for the Department primary index are Company, Process Level, and Department. In this sample, all keys are populated although with the E@DBFINDGE function you do not need to place specific values in all key variables. Instead, you can simply initialize some with blanks or zeroes and the function will find the next "greater" record based on the key values you do supply.

  1. The key variables of the Department primary index are populated from a Company field and two "position-to" fields.

  2. The procedure for E@DBFINDGE is called.

  3. If the department is not found or the company in the record does not match the one being used in the Find function, then message 105 is returned ("No more departments for company").

E@DBFINDBEGRNG and E@DBFINDSUBRNG

C                   EVAL      D@VNDGRP       = F1@VNDGRP
C                   IF        F1@VNCLSS <> *BLANKS         
C                   EVAL      D@VNCLSS       = F1@VNCLSS   
C                   IF        F1@THVNDR = *BLANKS          
C                   EVAL      E@DBBEGRNG     = 2           
C                   CALLP     DN@DBAPVEN2(E@DBFINDBEGRNG)  
C                   ELSE                                   
C                   EVAL      D@VENDOR       = F1@FRVNDR   
C                   EVAL      D#END#VENDOR   = F1@THVNDR   
C                   EVAL      E@DBSUBRNG     = 3           
C                   CALLP     DS@DBAPVEN2(E@DBFINDSUBRNG)  
C                   ENDIF                                  

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 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.