Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: DGENDBS

DGENDBS.m

Go to the documentation of this file.
  1. DGENDBS ;ALB/RMO/CJM,JAM - Database Server Utilities; [ 03/23/95 11:08 AM ]
  1. ;;5.3;Registration;**122,147,182,1040**;08/13/93;Build 15
  1. ;
  1. UPD(FILE,DGENDA,DATA,ERROR) ;File data into an existing record.
  1. ; Input:
  1. ; FILE - File or sub-file number
  1. ; DGENDA - New name for traditional DA array, with same meaning.
  1. ; Pass by reference.
  1. ; DATA - Data array to file (pass by reference)
  1. ; Format: DATA(<field #>)=<value>
  1. ;
  1. ; Output:
  1. ; Function Value - 0=error and 1=no error
  1. ; ERROR - optional error message - if needed, pass by reference
  1. ;
  1. ; Example: To update a record in subfile 2.0361 in record with ien=353,
  1. ; subrecord ien=68, with the field .01 value = 21:
  1. ; S DATA(.01)=21,DGENDA=68,DGENDA(1)=353 I $$UPD^DGENDBS(2.0361,.DGENDA,.DATA,.ERROR) W !,"DONE"
  1. ;
  1. ; DG*5,3*1040;jam; Add New of DTOUT to protect it from FILE^DIE which will kill this variable.
  1. N FDA,FIELD,IENS,ERRORS,DTOUT
  1. ;
  1. ;IENS - Internal Entry Number String defined by FM
  1. ;FDA - the FDA array as defined by FM
  1. ;
  1. I '$G(DGENDA) S ERROR="IEN OF RECORD TO BE UPDATED NOT SPECIFIED" Q 0
  1. S IENS=$$IENS^DILF(.DGENDA)
  1. S FIELD=0
  1. F S FIELD=$O(DATA(FIELD)) Q:'FIELD D
  1. .S FDA(FILE,IENS,FIELD)=$G(DATA(FIELD))
  1. D FILE^DIE("K","FDA","ERRORS(1)")
  1. I +$G(DIERR) D
  1. .S ERROR=$G(ERRORS(1,"DIERR",1,"TEXT",1))
  1. E D
  1. .S ERROR=""
  1. ;
  1. I $S(+$G(DIERR):0,1:1) D CLEAN^DILF Q 1
  1. E D CLEAN^DILF Q 0
  1. ;
  1. ADD(FILE,DGENDA,DATA,ERROR,IEN) ;
  1. ;Description: Creates a new record and files the data.
  1. ; Input:
  1. ; FILE - File or sub-file number
  1. ; DGENDA - New name for traditional FileMan DA array with same
  1. ; meaning. Pass by reference. Only needed if adding to a
  1. ; subfile.
  1. ; DATA - Data array to file, pass by reference
  1. ; Format: DATA(<field #>)=<value>
  1. ; IEN - internal entry number to use (optional)
  1. ;
  1. ; Output:
  1. ; Function Value - If no error then it returns the ien of the created record, else returns NULL.
  1. ; DGENDA - returns the ien of the new record, NULL if none created. If needed, pass by reference.
  1. ; ERROR - optional error message - if needed, pass by reference
  1. ;
  1. ; Example: To add a record in subfile 2.0361 in the record with ien=353
  1. ; with the field .01 value = 21:
  1. ; S DATA(.01)=21,DGENDA(1)=353 I $$ADD^DGENDBS(2.0361,.DGENDA,.DATA) W !,"DONE"
  1. ;
  1. ; Example: If creating a record not in a subfile, would look like this:
  1. ; S DATA(.01)=21 I $$ADD^DGENDBS(867,,.DATA) W !,"DONE"
  1. ;
  1. N FDA,FIELD,IENA,IENS,ERRORS
  1. ;
  1. ;IENS - Internal Entry Number String defined by FM
  1. ;IENA - the Internal Entry Numebr Array defined by FM
  1. ;FDA - the FDA array defined by FM
  1. ;IEN - the ien of the new record
  1. ;
  1. S DGENDA="+1"
  1. S IENS=$$IENS^DILF(.DGENDA)
  1. S FIELD=0
  1. F S FIELD=$O(DATA(FIELD)) Q:'FIELD D
  1. .S FDA(FILE,IENS,FIELD)=$G(DATA(FIELD))
  1. I $G(IEN) S IENA(1)=IEN
  1. D UPDATE^DIE("","FDA","IENA","ERRORS(1)")
  1. I +$G(DIERR) D
  1. .S ERROR=$G(ERRORS(1,"DIERR",1,"TEXT",1))
  1. .S IEN=""
  1. E D
  1. .S IEN=IENA(1)
  1. .S ERROR=""
  1. D CLEAN^DILF
  1. S DGENDA=IEN
  1. Q IEN
  1. ;
  1. TESTVAL(FILE,FIELD,VALUE) ;
  1. ;Description: returns 1 if VALUE is a valid value for FIELD in FILE
  1. ;
  1. Q:(('$G(FILE))!('$G(FIELD))) 0
  1. ;
  1. N DISPLAY,VALID,RESULT
  1. S VALID=1
  1. ;
  1. ;if there is no external value then it is not valid
  1. S DISPLAY=$$EXTERNAL^DILFD(FILE,FIELD,"F",VALUE)
  1. I (DISPLAY="") S VALID=0
  1. ;
  1. I VALID,$$GET1^DID(FILE,FIELD,"","TYPE")'["POINTER" D
  1. .D CHK^DIE(FILE,FIELD,,VALUE,.RESULT) I RESULT="^" S VALID=0 Q
  1. Q VALID