home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / ppstpx.zip / OM5.TPX < prev    next >
Text File  |  1993-05-13  |  58KB  |  1,380 lines

  1. #!***************************************************************************
  2. #GROUP(%RelUpdate)                               #<!RelationalUpdate ROUTINE
  3.  
  4. #IF(%RelatedUpdateRoutine)
  5.  
  6. RelationalUpdate ROUTINE
  7.  AbortTransaction# = 0                           !Reset transaction indicator
  8.   #IF(%CascadeUpdate OR %ClearOnUpdate)
  9.       #SET(%SetFile,%Primary)
  10.   #IF(%NoLogoutSupport = %NULL)
  11.       #SET(%LogoutList,'LOGOUT(2')
  12.       #INSERT(%SetupLogout)
  13.       #Set(%Logoutlist,(%Logoutlist & ')'))
  14.  %LogoutList
  15.    #INSERT(%InitLogout)
  16.   #ENDIF
  17.       #SET(%SetFile,%Primary)
  18.         #IF(%RestrictUpdate)
  19.    DO CheckRestrictedUpdate                      #<!Check RESTRICT update
  20.    IF RestrictUpdate#                            #<!Restrict this update
  21.   #IF(%NoLogoutSupport = %NULL)
  22.      ROLLBACK                                    #<!Terminate the transaction
  23.   #ENDIF
  24.      EXIT                                        #<!Exit the update
  25.    END
  26.         #ENDIF
  27.    #INSERT(%RelationUpdate)
  28.  
  29.    PUT (%Primary)                                #<!Write the Parent record
  30.    #IF(%NoLogoutSupport = %NULL)
  31.    IF ~ERRORCODE()                               #<!If the Parent update is Ok
  32.     COMMIT
  33.    ELSE
  34.     GLO:Message1 = 'Unable to complete the transaction'
  35.     GLO:Message2 = 'Error: ' & ERRORCODE() & ' ' & ERROR()
  36.     GLO:Message3 = 'Files will be restored to their original values'
  37.     ShowWarning                                  #<!Notify the user
  38.     ROLLBACK                                     #<!Rollback the transaction
  39.    END                                           #<!End IF ERRORCODE()
  40.    #ELSE                                         #! NoLogoutSupport
  41.    IF ERRORCODE()
  42.     GLO:Message1 = 'Unable to complete the Referential Update'
  43.     GLO:Message2 = 'Error: ' & ERRORCODE() & ' ' & ERROR()
  44.     GLO:Message3 = 'File: %Primary could not be updated !'
  45.     ShowWarning                                  #<!Notify the user
  46.    END
  47.    #ENDIF                                        !# NoLogoutSupport
  48.   #ELSE
  49.     #IF(%RestrictUpdate)
  50.    DO CheckRestrictedUpdate                      #<!Check RESTRICT update
  51.    IF RestrictUpdate#                            #<!Restrict this update
  52.      AbortTransaction# = 1                       #<!Turn AbortTransaction# ON
  53.      EXIT                                        #<!Exit the update
  54.    END
  55.     #ENDIF
  56.    PUT(%Primary)                                 #<!Write the Primary file
  57.   #ENDIF
  58. #ENDIF
  59. #!***************************************************************************
  60. #GROUP(%RelationUpdate)
  61. #FIX(%File,%SetFile)
  62. #FOR(%Relation)
  63. #IF(%RelationType = '1:MANY')
  64.     #IF(%RelationConstraintUpdate = 'CASCADE')
  65. #INSERT(%ClearCascadeUpdate)
  66.     #ELSIF(%RelationConstraintUpdate = 'CLEAR')
  67. #INSERT(%ClearCascadeUpdate)
  68.     #ENDIF
  69. #SET(%SetFile,%Relation)
  70. #INSERT(%RelationUpdate)
  71. #ENDIF
  72. #ENDFOR
  73. #!***************************************************************************
  74. #GROUP(%ClearCascadeUpdate)
  75.       #SET(%LinkToParent,%NULL)
  76.       #FOR(%RelationKeyField)
  77.       #IF(%RelationKeyFieldLink)
  78.        #SET(%TheLink,%RelationKeyFieldLink)
  79.        #IF(INSTRING(%TheLink,%LevelOneLinks,1,1) <> '0')
  80.         #SET(%LinkToParent,'TRUE')
  81.        #ENDIF
  82.        #IF(INSTRING(%TheLink,%LinkPool,1,1) <> '0')
  83.         #SET(%LinkToParent,'TRUE')
  84.        #ENDIF
  85.       #ENDIF
  86.       #ENDFOR
  87. #IF(%LinkToParent)
  88. #INSERT(%ChildCheck)
  89.   #FOR(%RelationKeyField)
  90.   #IF(%RelationKeyFieldLink <> %NULL)
  91.   IF %RelationKeyFieldLink <> %Relation:Lnk:%RelationKeyFieldLink #<!Has Link changed?
  92.     LinkFieldChged# = 1                          #<!Turn on LinkFieldChged#
  93.     UpdRelation = POSITION(%Relation)            #<!Save position of update
  94.   ELSE
  95.     CLEAR(UpdRelation)                           #<!Clear position variable
  96.   END
  97.   #ENDIF
  98.   #ENDFOR
  99.   IF LinkFieldChged#                              #<!did the LINK field change
  100.     SET(%RelationKey,%RelationKey)               #<!Set by key to related record
  101.     LOOP UNTIL EOF(%Relation)                    #<!Loop thru the file
  102.     #IF(%NoLogoutSupport)
  103.       HOLD(%Relation,10)                         #<!Set HOLD retry for 10 seconds
  104.     #ENDIF
  105.       NEXT(%Relation)                            #<!Read the record
  106.       DO CheckTransaction                        #<!Error check
  107.     #IF(%NoLogoutSupport = %NULL)
  108.       IF AbortTransaction# THEN EXIT.            #<!IF error EXIT
  109.     #ENDIF
  110.     #FOR(%RelationKeyField)
  111.     #IF(%RelationKeyFieldLink <> %NULL)
  112.       IF %RelationKeyField <> %Relation:Lnk:%RelationKeyFieldLink #<!Is this a related record?
  113.         BREAK                                    #<!Not related, BREAK from Loop
  114.       END                                        #<!End link field check
  115.     #ENDIF
  116.     #ENDFOR
  117.     #FOR(%RelationKeyField)
  118.     #IF(%RelationKeyFieldLink <> %NULL)
  119.       #IF(%RelationConstraintUpdate = 'CLEAR')
  120.       CLEAR(%RelationKeyField)                   #<!Enforce CLEAR constraint
  121.       #ELSIF(%RelationConstraintUpdate = 'CASCADE')
  122.       %RelationKeyField = %RelationKeyFieldLink #<!Enforce CASCADE constraint
  123.       #ENDIF
  124.     #ENDIF
  125.     #ENDFOR
  126.        PUT(%Relation)                            #<!Write the record
  127.        DO CheckTransaction                       #<!Check for an error
  128.     #IF(%NoLogoutSupport = %NULL)
  129.       IF AbortTransaction# THEN EXIT.            #<!IF error EXIT
  130.     #ENDIF
  131.     END                                          #<!End file process Loop
  132.     IF UpdRelation                               #<!Position of last update
  133.       RESET(%Relation,UpdRelation)               #<!Position to updated record
  134.       NEXT(%Relation)                            #<!read updated record into buffer
  135.     END                                          #<!End IF UpdRelation
  136.   END                                            #<!End IF LinkFieldChgd#
  137. END                                              #<!End IF record related?
  138. LinkFieldChged# = 0                              #<!Turn LinkFieldChged# OFF
  139. #ENDIF
  140. #!***************************************************************************
  141. #GROUP(%ChildCheck)
  142.   #FOR(%RelationKeyField)
  143.     #IF(%RelationKeyFieldLink <> %NULL)
  144. %RelationKeyField = %Relation:Lnk:%RelationKeyFieldLink #<!Prime access component
  145.     #ELSE
  146. CLEAR(%RelationKeyField)                         #<!CLEAR the NO LINK component
  147.     #ENDIF
  148.   #ENDFOR
  149. SET(%RelationKey,%RelationKey)                   #<!Set to record by key
  150. NEXT(%Relation)                                  #<!Read the record
  151. #SET(%Counter,%NULL)
  152.  #FOR(%RelationKeyField)
  153.    #IF(%RelationKeyFieldLink <> %NULL)
  154.     #SET(%Counter,(%Counter + 1))
  155.     #IF(%Counter = '1')
  156.      #SET(%IfLine,('IF '& %RelationKeyField &' = '& %Relation &':Lnk:' & %RelationKeyFieldLink))
  157.     #ELSE
  158.      #SET(%IfLine,(%IfLine & ' AND ' & %RelationKeyField &' = '& %Relation&':Lnk:' & %RelationKeyFieldLink))
  159.     #ENDIF
  160.    #ENDIF
  161.  #ENDFOR
  162. %IfLine                                          #<!Is this a related record?
  163. #!***************************************************************************
  164. #GROUP(%RestrictUpdateCheck)
  165.  
  166. CheckRestrictedUpdate ROUTINE
  167.   RestrictUpdate# = 0
  168.   SetWarning# = 0
  169. #FIX(%File,%Primary)
  170. #FOR(%Relation)
  171.  #IF(%RelationConstraintUpdate = 'RESTRICT')
  172.   #IF(%RelationType = '1:MANY')
  173.    #FOR(%RelationKeyField)
  174.      #IF(%RelationKeyFieldLink <> %NULL)
  175.   %RelationKeyField = %Relation:Lnk:%RelationKeyFieldLink #<!Prime the Key component
  176.      #ELSE
  177.   CLEAR(%RelationKeyField)                       #<!Clear this Key component
  178.      #ENDIF
  179.    #ENDFOR
  180.   SET(%RelationKey,%RelationKey)                 #<!Set to record by key
  181.   NEXT(%Relation)                                #<!Read the record
  182.   CASE ERRORCODE()
  183.   OF BadRecErr                                   !No records update is OK
  184.     EXIT                                         !Exit the routine
  185.   ELSE                                           !else check for other errors
  186.    IF ERRORCODE()                                !if any errorcode was set
  187.     GLO:Message1 = 'Unable to process the file: %Relation '
  188.     GLO:Message2 = 'Error: '& ERRORCODE() & ' ' & ERROR()
  189.     GLO:Message3 = 'The transaction cannot be completed'
  190.     ShowWarning                                  #<!Notify the user
  191.     DISABLE(1,FIELDS())                          #<!Disable screen fields
  192.     ENABLE(?Cancel)                              #<!Enable the CANCEL button
  193.     RestrictUpdate# = 1                          #<!Turn on RestrictUpdate#
  194.     EXIT                                         #<!Exit the Routine
  195.    END                                           !End IF ERRORCODE()
  196.   END                                            !End CASE ERRORCODE()
  197.   #SET(%Counter,%NULL)
  198.    #FOR(%RelationKeyField)
  199.      #IF(%RelationKeyFieldLink <> %NULL)
  200.       #SET(%Counter,(%Counter + 1))
  201.       #IF(%Counter = '1')
  202.        #SET(%IfLine,('IF '& %RelationKeyField &' <> '& %Relation & ':Lnk:' & %RelationKeyFieldLink))
  203.       #ELSE
  204.        #SET(%IfLine,(%IfLine & ' OR ' & %RelationKeyField &' <> '& %Relation & ':Lnk:' & %RelationKeyFieldLink))
  205.       #ENDIF
  206.      #ENDIF
  207.    #ENDFOR
  208.   %IfLine                                        #<!Compare Link field(s)
  209.     EXIT                                         #<!Not related so exit
  210.   END                                            #<!End error check
  211.   #INSERT(%RestrictUpdateCode)
  212.   #ENDIF
  213.  #ENDIF
  214. #ENDFOR
  215. #!***************************************************************************
  216. #GROUP(%RestrictUpdateCode)
  217. #FOR(%RelationKeyField)
  218. #IF(%RelationKeyFieldLink <> %NULL)
  219. IF %RelationKeyFieldLink <> %Relation:Lnk:%RelationKeyFieldLink #<!Parent restricted field
  220.   SetWarning# = 1                                #<!Turn on warning switch
  221.   RestrictUpdate# = 1                            #<!Turn on Restrict switch
  222.   %RelationKeyFieldLink = %Relation:Lnk:%RelationKeyFieldLink #<!Reset to original value
  223.   DISPLAY                                        !Refresh the screen
  224. END                                               #<!End field compare
  225. #ENDIF
  226. #ENDFOR
  227.   IF SetWarning#                                 #<!If SetWarning is ON
  228.     GLO:Message1 = 'This record is referenced from other file(s)'
  229.     GLO:Message2 = 'Link field(s) are RESTRICTED from change'
  230.     GLO:Message3 = ' and have been reset to original values '
  231.     ShowWarning                                  #<!Notify the user
  232.     DISPLAY                                      #<!Update the screen
  233.   END                                            #<!End SetWarning
  234. #!***************************************************************************
  235. #GROUP(%ConcurrentWrite)
  236. #IF(%ConcurrentWriteOn)
  237.  
  238. ConcurrentWrite ROUTINE
  239.  AbortWrite# = 0                                 #<!Initialize AbortWrite#
  240.  IF ~AutoIncAdd                                  #<!Not an Autoincrement ADD
  241.    Sav:SaveRecord = %FilePre:Record              #<!Save Record to the Queue
  242.    #IF(%MemoChk)
  243.    #FOR(%Field)
  244.    #IF(%FieldType = 'MEMO')
  245.    SAV:%FieldID   = %Field                       #<!Save Memo to the Queue
  246.    #ENDIF
  247.    #ENDFOR
  248.    #ENDIF
  249.    ADD(RecordQueue,2)                            #<!Add the changed record
  250.    GET(RecordQueue,1)                            #<!Get the original record
  251.    RESET(%Primary,SavePointer)                   #<!Position to record on disk
  252.    HOLD(%Primary,2)                              #<!Set HOLD retry for 2 seconds
  253.    NEXT(%Primary)                                #<!Read the record into buffer
  254.    IF ERRORCODE()                                #<!Was there an error?
  255.      CASE ERRORCODE()                            #<!Process recoverable errors
  256.        OF IsHeldErr                              #<!Record is already held
  257.          GLO:Message1 = 'The Record is locked by another workstation '
  258.          GLO:Message2 = 'when you return to the entry FORM choose OK '
  259.          GLO:Message3 = 'to try the update again, or CANCEL to abort '
  260.          ShowWarning                             #<!Show user a warning
  261.          SELECT(1)                               #<!Place cursor on 1st field
  262.          RELEASE(%Primary)                       #<!Release the HOLD
  263.          AbortWrite# = 1                         #<!Turn on AbortWrite#
  264.          EXIT                                    #<!Back to main Loop
  265.        ELSE                                      #<!On any other error
  266.          IF DiskError('File Access Error')       #<!Call the Diskerror function
  267.            RELEASE(%Primary)                     #<!Release the hold
  268.            FREE(RecordQueue)                     #<!Free the memory Queue
  269.            DISABLE(1,FIELDS())                   #<!Disable all screen fields
  270.            ENABLE(?Cancel)                       #<!Enable the Cancel button
  271.            SELECT(?Cancel)                       #<!Place cursor on Cancel
  272.            AbortWrite# = 1                       #<!Turn on AbortWrite#
  273.            EXIT                                  #<!and exit the routine
  274.          END                                     #<!End IF Diskerror
  275.      END                                         #<!End CASE Errorcode()
  276.    ELSIF Sav:SaveRecord <> %FilePre:Record       #<!Has the record been changed
  277.      Sav:SaveRecord = %FilePre:Record            #<!Then update the Queue record
  278.      #IF(%MemoChk = 'TRUE')
  279.      #FOR(%Field)
  280.      #IF(%FieldType = 'MEMO')
  281.      IF SAV:%FieldID <> %Field                   #<!Has the Memo been changed?
  282.        SAV:%FieldID = %Field                     #<!Then update the Queue memo
  283.      END                                         #<!End IF Memo changed
  284.      #ENDIF
  285.      #ENDFOR
  286.      #ENDIF
  287.      #INSERT(%ConflictUpdate)
  288.    #IF(%MemoChk = 'TRUE')
  289.      #FOR(%Field)
  290.      #IF(%FieldType = 'MEMO')
  291.    ELSIF SAV:%FieldID <> %Field                  #<!Has the Memo been changed?
  292.      SAV:%FieldID = %Field                       #<!Then update the Queue memo
  293.      #INSERT(%ConflictUpdate)
  294.      #ENDIF
  295.      #ENDFOR
  296.    #ENDIF
  297.    ELSE                                          #<!Its ok to update the file
  298.      GET(RecordQueue,2)                          #<!Retrieve the users changes
  299.      %FilePre:Record = Sav:SaveRecord            #<!Move changes to record buffer
  300.      #IF(%MemoChk)
  301.      #FOR(%Field)
  302.      #IF(%FieldType = 'MEMO')
  303.      %Field = SAV:%FieldID                       #<!Move Memo to buffer
  304.      #ENDIF
  305.      #ENDFOR
  306.      #ENDIF
  307.    END                                           #<!End IF Errorcode()
  308.  END                                             #<!End IF ~AutoIncAdd
  309.  #ENDIF
  310. #!***************************************************************************
  311. #GROUP(%RelDelete)                               #<!RealationalDelete ROUTINE
  312.  
  313. #IF(%RelatedDeleteRoutine)
  314. RelationalDelete ROUTINE
  315.       #SET(%SetFile,%Primary)
  316.   #IF(%NoLogoutSupport = %NULL)
  317.       #SET(%LogoutList,'LOGOUT(2')
  318.       #INSERT(%SetupLogoutDel)
  319.       #Set(%Logoutlist,(%Logoutlist & ')'))
  320.   %LogoutList
  321.     #INSERT(%InitLogout)
  322.   #ENDIF
  323.       #SET(%SetFile,%Primary)
  324.     #INSERT(%RelationDelete)
  325.     #IF(%CascadeDelete OR %ClearOnDelete)
  326.     DELETE(%Primary)                             #<!Delete record Primary file
  327.     #INSERT(%CommitCheck)
  328.     #ELSE
  329.     DELETE(%Primary)                             #<!Delete record Primary file
  330.     #ENDIF
  331. #ENDIF
  332. #!***************************************************************************
  333. #GROUP(%RelationDelete)
  334. #FIX(%File,%SetFile)
  335. #FOR(%Relation)
  336. #IF(%RelationType = '1:MANY')
  337.     #IF(%RelationConstraintDelete = 'CASCADE')
  338. #INSERT(%ClearCascadeDelete)
  339.     #ELSIF(%RelationConstraintDelete = 'CLEAR')
  340. #INSERT(%ClearCascadeDelete)
  341.     #ENDIF
  342. #SET(%SetFile,%Relation)
  343. #INSERT(%RelationDelete)
  344. #ENDIF
  345. #ENDFOR
  346. #!***************************************************************************
  347. #GROUP(%ClearCascadeDelete)
  348. #INSERT(%ChildCheck)
  349.   SET(%RelationKey,%RelationKey)                 #<!Set to first occurence
  350.     LOOP UNTIL EOF(%Relation)                    #<!Loop thru the file
  351.     #IF(%NoLogoutSupport)
  352.       HOLD(%Relation,10)                         #<!Set HOLD retry for 10 seconds
  353.     #ENDIF
  354.       NEXT(%Relation)                            #<!Read the record
  355.       DO CheckTransaction                        #<!Check for error
  356.     #IF(%NoLogoutSupport = %NULL)
  357.       IF AbortTransaction# THEN  EXIT.           #<!IF error exit the routine
  358.     #ENDIF
  359.     #FOR(%RelationKeyField)
  360.     #IF(%RelationKeyFieldLink <> %NULL)
  361.       IF %RelationKeyField <> %Relation:Lnk:%RelationKeyFieldLink #<!Is this a related record?
  362.         BREAK                                    #<!Not Related, BREAK from Loop
  363.       END
  364.       #IF(%RelationConstraintDelete = 'CLEAR')
  365.       CLEAR(%RelationKeyField)                   #<!Enforce the relation constraint
  366.       #ENDIF
  367.     #ENDIF
  368.     #ENDFOR
  369.       #IF(%RelationConstraintDelete = 'CLEAR')
  370.       PUT(%Relation)                             #<!Enforce CLEAR constraint
  371.       #ELSIF(%RelationConstraintDelete = 'CASCADE')
  372.       DELETE(%Relation)                          #<!Enforce CASCADE constraint
  373.       #ENDIF
  374.       DO CheckTransaction
  375.     #IF(%NoLogoutSupport = %NULL)
  376.       IF AbortTransaction# THEN EXIT.
  377.     #ENDIF
  378.     END                                          #<!End Loop
  379. END                                              #<!Is record related?
  380. #!***************************************************************************
  381. #GROUP(%RestrictDeleteCode)
  382.  
  383. CheckRestrictedDelete ROUTINE
  384.   RestrictDelete# = 0
  385. #FIX(%File,%Primary)
  386. #FOR(%Relation)
  387.  #IF(%RelationConstraintDelete = 'RESTRICT')
  388.   #IF(%RelationType = '1:MANY')
  389.    #FOR(%RelationKeyField)
  390.      #IF(%RelationKeyFieldLink <> %NULL)
  391.   %RelationKeyField = %Relation:Lnk:%RelationKeyFieldLink #<!Prime the Key component
  392.      #ELSE
  393.   CLEAR(%RelationKeyField)                       #<!Clear this Key component
  394.      #ENDIF
  395.    #ENDFOR
  396.   SET(%RelationKey,%RelationKey)                 #<!Set to record by key
  397.   NEXT(%Relation)                                #<!Read the record
  398.   CASE ERRORCODE()
  399.   OF BadRecErr                                   !No records delete is OK
  400.     EXIT
  401.   ELSE
  402.    IF ERRORCODE()
  403.     GLO:Message1 = 'Unable to process the file: %Relation '
  404.     GLO:Message2 = 'Error: '& ERRORCODE() & ' ' & ERROR()
  405.     GLO:Message3 = 'The transaction cannot be completed'
  406.     ShowWarning                                  #<!Notify the user
  407.     DISABLE(1,FIELDS())                          #<!Disable screen fields
  408.     ENABLE(?Cancel)                              #<!Enable the CANCEL button
  409.     RestrictDelete# = 1                          #<!Turn on RestrictDelete#
  410.     EXIT                                         #<!Exit the Routine
  411.    END                                           !End IF ERRORCODE()
  412.   END                                            !End CASE ERRORCODE()
  413.   #SET(%Counter,%NULL)
  414.    #FOR(%RelationKeyField)
  415.      #IF(%RelationKeyFieldLink <> %NULL)
  416.       #SET(%Counter,(%Counter + 1))
  417.       #IF(%Counter = '1')
  418.        #SET(%IfLine,('IF '& %RelationKeyField &' = '& %RelationKeyFieldLink))
  419.       #ELSE
  420.        #SET(%IfLine,(%IfLine & ' AND ' & %RelationKeyField &' = '& %RelationKeyFieldLink))
  421.       #ENDIF
  422.      #ENDIF
  423.    #ENDFOR
  424.   %IfLine
  425.     GLO:Message1 = 'This record is restricted from deletion'
  426.     GLO:Message2 = 'It is referenced from other files'
  427.     ShowWarning                                  #<!Notify the user
  428.     DISABLE(1,FIELDS())                          #<!Disable screen fields
  429.     ENABLE(?Cancel)                              #<!Enable the CANCEL button
  430.     RestrictDelete# = 1                          #<!Turn on RestrictDelete#
  431.     EXIT                                         #<!Exit the Routine
  432.   END                                            #<!End error check
  433.   #ENDIF
  434.  #ENDIF
  435. #ENDFOR
  436. #!***************************************************************************
  437. #GROUP(%SetupLogout)
  438. #FIX(%File,%SetFile)
  439. #FOR(%Relation)
  440. #IF(%RelationType = '1:MANY')
  441.     #IF(%RelationConstraintUpdate = 'CASCADE')
  442.     #SET(%Temp, %Relation)
  443.     #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  444.     #ELSIF(%RelationConstraintUpdate = 'CLEAR')
  445.     #SET(%Temp, %Relation)
  446.     #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  447.     #ELSIF(%RelationConstraintUpdate = 'RESTRICT')
  448.     #SET(%Temp, %Relation)
  449.     #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  450.     #ENDIF
  451. #SET(%SetFile,%Relation)
  452. #INSERT(%SetupLogout)
  453. #ENDIF
  454. #ENDFOR
  455. #!***************************************************************************
  456. #GROUP(%SetupLogoutDel)
  457. #FIX(%File,%SetFile)
  458. #FOR(%Relation)
  459. #IF(%RelationType = '1:MANY')
  460.     #IF(%RelationConstraintDelete = 'CASCADE')
  461.       #SET(%Temp, %Relation)
  462.       #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  463.     #ELSIF(%RelationConstraintDelete = 'CLEAR')
  464.       #SET(%Temp, %Relation)
  465.       #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  466.     #ELSIF(%RelationConstraintDelete = 'RESTRICT')
  467.       #SET(%Temp, %Relation)
  468.       #SET(%Logoutlist,(%Logoutlist &','& %Temp))
  469.     #ENDIF
  470. #SET(%SetFile,%Relation)
  471. #INSERT(%SetupLogoutDel)
  472. #ENDIF
  473. #ENDFOR
  474. #!***************************************************************************
  475. #GROUP(%InitLogout)
  476. IF ERRORCODE()                                   #<!Was Logout OK?
  477.   AbortTransaction# = 1                          #<!Turn AbortTransaction ON
  478.   CASE ERRORCODE()                               #<!Process recoverable error
  479.     OF IsLockedErr                               #<!Was the file locked?
  480.       GLO:Message1 = 'The transaction cannot be completed'
  481.       GLO:Message2 = 'at this time.  One or more of the files'
  482.       GLO:Message3 = 'is already locked.  You may retry the operation'
  483.       ShowWarning                                #<!Notify the user
  484.       SELECT(?Ok)                                #<!Place cursor on OK
  485.       ROLLBACK                                   #<!End LOGOUT
  486.       EXIT                                       #<!Exit the Routine
  487.     ELSE                                         #<!Any other error
  488.       GLO:Message1 = 'The transaction cannot be completed'
  489.       GLO:Message2 = 'at this time.  The error posted was: '
  490.       GLO:Message3 = ERROR()
  491.       ShowWarning                                #<!Notify the user
  492.       DISABLE(1,FIELDS())                        #<!Disable the screen fields
  493.       ENABLE(?Cancel)                            #<!Enable the Cancel button
  494.       SELECT(?Cancel)                            #<!Place the cursor on Cancel
  495.       ROLLBACK                                   #<!End LOGOUT
  496.       EXIT                                       #<!Exit the Routine
  497.   END                                            #<!End CASE errorcode
  498. END                                              #<!No errors, start transaction
  499. AbortTransaction# = 0                            #<!Set Abort switch to off
  500. #!***************************************************************************
  501. #GROUP(%ConcurrentDelete)
  502. #IF(%ConcurrentDeleteOn)
  503.  
  504. ConcurrentDelete ROUTINE
  505.   AbortDelete# = 0
  506.   RESET(%Primary,SavePointer)                    #<!Set position in Primary file
  507.   HOLD(%Primary,2)                               #<!Hold the record
  508.   NEXT(%Primary)                                 #<!Read the record into buffer
  509.   IF POSITION(%Primary) <> SavePointer           #<!Is the record already deleted?
  510.     RELEASE(%Primary)                            #<!Relase record Hold
  511.     FREE(RecordQueue)                            #<!Free the memory Queue
  512.     #IF(%PullDownStructure)
  513.     CLOSE(%PullDown)
  514.     #ENDIF
  515.     RETURN                                       #<!Return to the calling procedure
  516.   END                                            #<!End IF position check
  517.   IF ERRORCODE()                                 #<!Check for file access error
  518.     CASE ERRORCODE()                             #<!Case for recoverable errors
  519.       OF IsHeldErr                               #<!Record is already held
  520.         GLO:Message1 = 'The Record is locked by another workstation '
  521.         GLO:Message2 = 'when you return to the entry FORM choose OK '
  522.         GLO:Message3 = 'to try the update again, or CANCEL to abort '
  523.         ShowWarning                              #<!Notify the user
  524.         SELECT(1)                                #<!Place cursor on 1st field
  525.         RELEASE(%Primary)                        #<!Release HOLD request
  526.         AbortDelete# = 1                         #<!Set AbortDelete# ON
  527.         EXIT                                     #<!Re-start main LOOP
  528.       ELSE                                       #<!for any other error
  529.         IF DiskError('Unable to process current Record') #<!Call error function
  530.           GLO:Message2 = 'Unable to continue, Press OK to exit'
  531.           ShowWarning                            #<!Notify the user
  532.           #IF(SharedFiles = 'TRUE')
  533.           FREE(RecordQueue)                      #<!Free the memory queue
  534.           #ENDIF
  535.           #IF(%PullDownStructure)
  536.           CLOSE(%PullDown)
  537.           #ENDIF
  538.           RETURN                                 #<!Return to calling procedure
  539.         END                                      #<!End IF Diskerror
  540.     END                                          #<!End CASE errorcode
  541.   END                                            #<!End IF errorcode()
  542. #ENDIF
  543. #!***************************************************************************
  544. #GROUP(%CheckTransaction)
  545.  
  546. CheckTransaction ROUTINE
  547.   IF ERRORCODE()
  548.   #IF(%NoLogoutSupport = %NULL)
  549.     AbortTransaction# = 1
  550.     GLO:Message1 = 'The transaction cannot be completed'
  551.     GLO:Message2 = 'Error: '&ERROR()
  552.     GLO:Message3 = 'Files will be restored to original values'
  553.     ShowWarning                                  #<!Notify the user
  554.     DISABLE(1,FIELDS())                          #<!Disable all screen fields
  555.     ENABLE(?Cancel)                              #<!Activate the Cancel button
  556.     SELECT(?Cancel)                              #<!Place the cursor on Cancel
  557.     ROLLBACK                                     #<!Restore original records
  558.     IF ERRORCODE() <> NoDriverSupport
  559.       GLO:Message1 = 'Files could not be restored to original values'
  560.       GLO:Message2 = 'Error: '&ERROR()
  561.       ShowWarning                                #<!Notify the user
  562.     END
  563.   END                                            #<!End error check
  564.   #ELSE                                          #! NoLogoutSupport
  565.     GLO:Message1 = 'The Referential Update/Delete encountered an error'
  566.     GLO:Message2 = 'Error: '& ERRORCODE() & ' ' & ERROR()
  567.     GLO:Message3 = 'Relational integrity for: ' & ERRORFILE() & 'is suspect'
  568.     ShowWarning                                  #<!Notify the user
  569.   END
  570.   #ENDIF
  571. #!***************************************************************************
  572. #GROUP(%RelUpdSave)
  573.  
  574. RelationAccessSave ROUTINE
  575. #SET(%SetFile,%Primary)
  576. #INSERT(%RelUpdateSave)
  577. #!***************************************************************************
  578. #GROUP(%RelUpdateSave)
  579. #FIX(%File,%SetFile)
  580. #FOR(%Relation)
  581.     #IF(%RelationType = '1:MANY')
  582.   CheckOpen(%Relation)
  583.   #SET(%SetFile,%Relation)
  584.   #INSERT(%ChildSave)
  585. #INSERT(%RelUpdateSave)
  586.  
  587.     #ENDIF
  588. #ENDFOR
  589. #!***************************************************************************
  590. #GROUP(%ChildSave)
  591.   #FOR(%RelationKeyField)
  592.     #IF(%RelationKeyFieldLink <> %NULL)
  593.   #IF(INSTRING(%SetFile,%LevelOne,1,1) <> '0')
  594. %Relation:Lnk:%RelationKeyFieldLink = %RelationKeyFieldLink #<!save original link
  595. %RelationKeyField = %RelationKeyFieldLink        #<!Prime key component
  596.   #ELSE
  597.   #SET(%SaveLine,(%RelationKeyField &' <> '& %RelationKeyFieldLink))
  598. %Relation:Lnk:%RelationKeyFieldLink = %RelationKeyFieldLink #<!save original link
  599. %RelationKeyField = %RelationKeyFieldLink        #<!Prime key component
  600.   #ENDIF
  601.     #ELSE
  602. CLEAR(%RelationKeyField)                         #<!Clear NoLink field
  603.     #ENDIF
  604.   #ENDFOR
  605. SET(%RelationKey,%RelationKey)                   #<!Set by RelationAccess Key
  606. NEXT(%Relation)                                  #<!Read the record
  607. #FOR(%RelationKeyField)
  608.   #IF(%RelationKeyFieldLink <> %NULL)
  609. IF %RelationKeyField <> %RelationKeyFieldLink    #<!Is the record related?
  610.    NotRelated# = 1                                  #<!No, then set NotRelated# ON
  611. END
  612.   #ENDIF
  613. #ENDFOR
  614. IF ERRORCODE() OR NotRelated#                       #<!Check error or not related
  615.   #FIX(%File,%Relation)
  616.   CLEAR(%FilePre:Record)                         #<!Clear the record if needed
  617. END                                              #<!End IF Errorcode
  618. #!***************************************************************************
  619. #GROUP(%InitQue)
  620. #IF(%SharedFiles = 'TRUE')
  621.  
  622. InitializeQueue ROUTINE                          #<!save initial record values
  623.   Sav:SaveRecord = %FilePre:Record               #<!Save the current record
  624.   #IF(%MemoChk)
  625.   #FOR(%Field)
  626.   #IF(%FieldType = 'MEMO')
  627.   SAV:%FieldID   = %Field                        #<!Save the memo
  628.   #ENDIF
  629.   #ENDFOR
  630.   #ENDIF
  631.   ADD(RecordQueue,1)                             #<!add record to Queue
  632.   ADD(RecordQueue,2)                             #<!add record again
  633.   IF ERRORCODE()                                 #<!check Queue add error
  634.     CASE ERRORCODE()
  635.       OF NoMemErr                                #<!Is there enough memory?
  636.       GLO:Message1 = 'Not Enough Memory to proceed'
  637.       GLO:Message2 = 'with this operation . . . . '
  638.       ShowWarning                                #<!Notify the user
  639.       DISABLE(1,FIELDS())                        #<!Disable the screen fields
  640.       ENABLE(?Cancel)                            #<!Enable the Cancel button
  641.       SELECT(?Cancel)                            #<!Place cursor on Cancel
  642.       DISPLAY                                    #<!Update screen display
  643.     ELSE                                         #<!On any other error
  644.       GLO:Message1 = ERRORCODE() & ' ' & ERROR()
  645.       GLO:Message2 = 'Unable to continue . . . .'
  646.       ShowWarning                                #<!Show user the error
  647.       DISABLE(1,FIELDS())                        #<!Disable screen fields
  648.       ENABLE(?Cancel)                            #<!Enable Cancel button
  649.       SELECT(?Cancel)                            #<!Place cursor on Cancel
  650.       DISPLAY                                    #<!re-display the screen
  651.     END                                          #<!End CASE Errorcode
  652.   END                                            #<!End IF Errorcode
  653. #ENDIF
  654. #!***************************************************************************
  655. #GROUP(%InitFields)
  656. #IF(%InitRoutine = 'TRUE')
  657.  
  658. InitializeFields ROUTINE
  659. #FOR(%Field)
  660. #IF(%FieldInitial <> %NULL)
  661.    %Field = %FieldInitial
  662. #ENDIF
  663. #ENDFOR
  664. #ENDIF
  665. #!***************************************************************************
  666. #GROUP(%SecondaryLookups)
  667.  
  668. SecondaryLookups ROUTINE
  669.   #INSERT(%GetSecondaryRecords)                  #<!Lookup into Secondary files
  670.   DISPLAY
  671. #!***************************************************************************
  672. #GROUP(%InsertMessage)
  673. #IF(%InsertMsg <> %NULL)
  674. LOC:Message = CENTER('%InsertMsg',SIZE(LOC:Message)) #<!Assign ADD message
  675. #ELSE
  676. LOC:Message = CENTER(GLO:InsertMsg,SIZE(LOC:Message))#<!Assign ADD message
  677. #ENDIF
  678. #!***************************************************************************
  679. #GROUP(%ChangeMessage)
  680. #IF(%ChangeMsg <> %NULL)
  681. LOC:Message = CENTER('%ChangeMsg',SIZE(LOC:Message)) #<!Assign CHANGE message
  682. #ELSE
  683. LOC:Message = CENTER(GLO:ChangeMsg,SIZE(LOC:Message))#<!Assign CHANGE message
  684. #ENDIF
  685. #!***************************************************************************
  686. #GROUP(%DeleteMessage)
  687. #IF(%DeleteMsg <> %NULL)
  688. LOC:Message = CENTER('%DeleteMsg',SIZE(LOC:Message)) #<!Assign DELETE message
  689. #ELSE
  690. LOC:Message = CENTER(GLO:DeleteMsg,SIZE(LOC:Message))#<!Assign DELETE message
  691. #ENDIF
  692. #!***************************************************************************
  693. #GROUP(%AutoIncCode)
  694. #IF(%AutoInc = 'TRUE')
  695.  
  696. AutoNumber Routine
  697.   LOOP                                            #<!Loop for autonumbering
  698.    #FIX(%File,%Primary)
  699. #FOR(%Key)
  700.  #IF(%KeyAuto)                                   #! <> %NULL
  701.      #FOR(%KeyField)
  702.       #FIX(%Field,%KeyField)
  703.       #IF(UPPER(%FieldType) = 'PICTURE')         #!Autonumber Picture data type
  704.         #IF(INSTRING('@N',UPPER(%FieldRecordPicture),1,1)) #!If its an @n picture
  705.    %KeyField = ALL('9')                          #<!Fill strings with 9's
  706.         #ELSE
  707.    CLEAR(%KeyField,1)                            #<!Clear Ascending to high value
  708.         #ENDIF
  709.       #ELSE
  710.    CLEAR(%KeyField,1)                            #<!Clear Ascending to high value
  711.       #ENDIF
  712.      #ENDFOR
  713.    #FOR(%Formula)
  714.     #IF(UPPER(%FormulaClass) = 'PRIMEKEY')
  715.    #INSERT(%GenerateFormula)
  716.     #ENDIF
  717.    #ENDFOR
  718.    #IF(%PrimeKeysExist)
  719.       #FOR(%KeyField)
  720.        #IF(%KeyField <> %KeyAuto)
  721.    Prime::%KeyField = %KeyField
  722.        #ENDIF
  723.       #ENDFOR
  724.    #ENDIF
  725.    SET(%Key,%Key)                                #<!For each autoincrement key
  726.    PREVIOUS(%Primary)                            #<!Read last record (Ascending)
  727.    IF ERRORCODE() = BadRecErr                    #<!If Errorcode No Records
  728.      %KeyAuto:AutoInc# = 1                       #<!then start numbering at 1
  729.    ELSIF ERRORCODE()                             #<!On any other error
  730.        GLO:Message1 = 'Unable to READ keyed record'
  731.        GLO:Message2 = 'Cannot continue update....'
  732.        GLO:Message3 = 'Error: '&ERRORCODE() & ' ' & ERROR()
  733.        ShowWarning                               #<!Show user the error
  734.        #IF(%PullDownStructure)
  735.        CLOSE(%PullDown)
  736.        #ENDIF
  737.        RETURN                                    #<!and return to caller
  738.    ELSE
  739.    #IF(%PrimeKeysExist)
  740.    #SET(%Pass,'1')
  741.       #FOR(%KeyField)
  742.        #IF(%KeyField <> %KeyAuto)
  743.         #IF(%Pass = '1')
  744.    #SET(%MatchSubset,('IF ' & 'Prime::'& %KeyField & ' = ' & %KeyField))
  745.         #ELSE
  746.    #SET(%MatchSubset,(%MatchSubset & ' AND ' & 'Prime::'& %KeyField & ' = ' & %KeyField))
  747.         #ENDIF
  748.         #SET(%Pass,(%Pass + 1))
  749.        #ENDIF
  750.       #ENDFOR
  751.     %MatchSubset
  752.       %KeyAuto:AutoInc# = %KeyAuto + 1           #<!Subset incremented value
  753.     ELSE                                         !Is this is a new subset?
  754.      %KeyAuto:AutoInc# = 1                       #<!then start numbering at 1
  755.     END                                          !End test subset match
  756.    #ELSE                                         #!No subset support
  757.      %KeyAuto:AutoInc# = %KeyAuto + 1            #<!Save incremented value
  758.    #ENDIF
  759.    END                                           #<!End IF errorcode
  760.  #ENDIF                                          #!end if keyauto
  761. #ENDFOR                                          #!end for key
  762.    #INSERT(%ClearValues)
  763.    #FOR(%Formula)
  764.     #IF(UPPER(%FormulaClass) = 'PRIMEKEY')
  765.    #INSERT(%GenerateFormula)
  766.     #ENDIF
  767.    #ENDFOR
  768.    #FOR(%Key)
  769.     #IF(%KeyAuto <> %NULL)
  770.    %KeyAuto = %KeyAuto:AutoInc#                  #<!Move the incremented value
  771.     #ENDIF
  772.    #ENDFOR
  773.    ADD(%Primary)                                 #<!Add the record now
  774.    IF ERRORCODE()                                #<!Was there an error?
  775.      CASE ERRORCODE()                            #<!Process errors
  776.        OF DupKeyErr                              #<!Is it a duplicate key?
  777.         CYCLE                                    #<!then try again
  778.        ELSE                                      #<!Else
  779.          IF DiskError('Record could not be ADDed') #<!Check any other error
  780.           #IF(%SharedFiles = 'TRUE')
  781.           FREE(RecordQueue)                      #<!Free the memory Queue
  782.           #ENDIF
  783.           #IF(%PullDownStructure)
  784.           CLOSE(%PullDown)
  785.           #ENDIF
  786.           RETURN                                 #<!Return to caller
  787.        END                                       #<!End IF Diskerror
  788.      END                                         #<!End CASE errorcode
  789.    ELSE                                          #<!Else no error
  790.      BREAK                                       #<!so BREAK Loop
  791.    END                                           #<!End IF errorcode
  792.   END                                            #<!End LOOP for Autonumbering
  793.   AutoIncAdd = 1                                 #<!Switch AutoIncAdd ON
  794.   AutoAddPtr = POSITION(%Primary)                #<!Save the record position
  795.   RESET(%Primary,AutoAddPtr)                     #<!Position to record we added
  796.   HOLD(%Primary,4)                               #<!Hold the record
  797.   NEXT(%Primary)                                 #<!and read it in to buffer
  798.   IF DiskError('Could not READ Record')          #<!Check for I/O error
  799.     #IF(%SharedFiles = 'TRUE')
  800.     FREE(RecordQueue)                            #<!Free the memory Queue
  801.     #ENDIF
  802.     #IF(%PullDownStructure)
  803.     CLOSE(%PullDown)
  804.     #ENDIF
  805.     RETURN                                       #<!And return to caller
  806.   END                                            #<!End IF Diskerror
  807.   Action = ChangeRecord                          #<!Action is now change
  808.   EXIT                                           #<!Exit the routine
  809.   #ENDIF
  810. #!***************************************************************************
  811. #GROUP(%RestoreAuto)
  812.     #FOR(%Key)
  813.     #IF(%KeyAuto <> %NULL)
  814. %KeyAuto = %KeyAuto:AutoInc#                     #<!Restore incremented value
  815.     #ENDIF
  816.     #ENDFOR
  817. #!***************************************************************************
  818. #GROUP(%SetupConcurrency)
  819. DO InitializeQueue                               #<!Save record to QUEUE
  820. SavePointer = POSITION(%Primary)                 #<!Save the record position
  821. #!***************************************************************************
  822. #GROUP(%ConflictUpdate)
  823. PUT(RecordQueue)                                 #<!Update the memory Queue
  824. GLO:Message1 = 'The Record was changed by another station '
  825. GLO:Message2 = 'your screen now reflects the changed data '
  826. GLO:Message3 = 'OK button to continue, or CANCEL to abort '
  827. ShowWarning                                      #<!Notify the user of changes
  828. SELECT(1)                                        #<!Place cursor on 1st field
  829. DISPLAY                                          #<!Update the screen
  830. AbortWrite# = 1                                  #<!Turn AbortWrite# ON
  831. EXIT                                             #<!Exit the Routine
  832. #!***************************************************************************
  833. #GROUP(%FormEditRoutines)
  834.    #FOR(%ScreenField)
  835.     #IF(%ScreenFieldUse <> '?Ok')
  836.      #IF(%ScreenFieldUse <> '?Cancel')
  837.       #IF(%ScreenFieldUse <> '?Next_Page')
  838.        #IF(%ScreenFieldUse <> '?Previous_Page')
  839.         #IF(%ScreenFieldUse <> '?Base_Page')
  840.          #IF(%ScreenFieldUse <> '?Last_Page')
  841.          #SET(%RangeCodeOn,%NULL)
  842.          #SET(%FieldLookUpOn,%NULL)
  843.       #INSERT(%RangeLookupCheck)
  844.       #IF(%ScreenFieldEdit OR %RangeCodeOn OR %FieldLookUpOn)
  845.   OF %ScreenField                                !Screen field selected
  846.         #IF(%FieldLookupOn)
  847.     #INSERT(%FieldLookupCode)
  848.         #ENDIF
  849.         #IF(%RangeCodeOn)
  850.     #INSERT(%RangeCode)
  851.         #ENDIF
  852.         #IF(%ScreenFieldEdit)
  853.     %ScreenFieldEdit                             !Screen field edit proc
  854.         #ENDIF
  855.          #ENDIF
  856.         #ENDIF
  857.        #ENDIF
  858.       #ENDIF
  859.      #ENDIF
  860.      #ENDIF
  861.     #ENDIF
  862.    #ENDFOR
  863.   #FOR(%PulldownField)                          #! add all procedure or
  864.     #IF(%PulldownFieldType = 'PROCEDURE')       #! source code calls
  865. OF %PulldownField                              #<!For a Pulldown field
  866.   %PulldownFieldProc                           #<!  execute its procedure
  867.     #ENDIF
  868.   #ENDFOR
  869. #!***************************************************************************
  870. #GROUP(%RangeLookupCheck)
  871.     #IF(%ScreenFieldType = 'ENTRY')
  872.       #FIX(%Field,%ScreenFieldUse)
  873.         #IF(%Field = %ScreenFieldUse)
  874.           #IF(%FieldRangeLow <> %NULL OR %FieldRangeHigh <> %NULL)
  875.             #SET(%RangeCodeOn,'TRUE')
  876.           #ELSE
  877.             #SET(%RangeCodeOn,%NULL)
  878.           #ENDIF
  879.           #IF(%FieldLookup)
  880.             #SET(%FieldLookupOn,'TRUE')
  881.           #ELSE
  882.             #SET(%FieldLookupOn,%NULL)
  883.           #ENDIF
  884.         #ENDIF
  885.     #ENDIF
  886. #!***************************************************************************
  887. #GROUP(%RangeCode)
  888. #IF(%ScreenFieldType = 'ENTRY')
  889.   #FIX(%Field,%ScreenFieldUse)
  890.     #IF(%Field = %ScreenFieldUse)
  891.       #IF(%FieldRangeLow <> %NULL OR %FieldRangeHigh <> %NULL)
  892.         #IF(%FieldRangeLow = %NULL)
  893. IF KEYCODE() <> EscKey
  894.   IF %ScreenFieldUse > %FieldRangeHigh
  895.   GLO:Message1 = 'The value entered in %FieldID'
  896.   GLO:Message2 = 'cannot exceed %FieldRangeHigh'
  897.         #ELSIF(%FieldRangeHigh = %NULL)
  898. IF KEYCODE() <> EscKey
  899.   IF %ScreenFieldUse < %FieldRangeLow
  900.   GLO:Message1 = 'The value entered in %FieldID'
  901.   GLO:Message2 = 'cannot be less than %FieldRangeHigh'
  902.         #ELSE
  903. IF KEYCODE() <> EscKey
  904.   IF ~INRANGE(%ScreenFieldUse,%FieldRangeLow,%FieldRangeHigh)
  905.     GLO:Message1 = 'Valid entries for %FieldID'
  906.     GLO:Message2 = 'are from %FieldRangeLow TO  %FieldRangeHigh'
  907.         #ENDIF
  908.     ShowWarning
  909.     SELECT(%ScreenField)
  910.     CYCLE
  911.   END
  912. END                                              !Not EscKey
  913.       #ENDIF
  914.     #ENDIF
  915. #ENDIF
  916. #!***************************************************************************
  917. #GROUP(%FieldLookupCode)
  918.     #IF(%ScreenFieldType = 'ENTRY')
  919.       #FIX(%Field,%ScreenFieldUse)
  920.       #IF(%Field = %ScreenFieldUse)
  921.         #IF(%FieldLookup)
  922.           #FIX(%File,%FieldFile)
  923.           #FIX(%Relation,%FieldLookup)
  924.          #IF(%RelationType = 'MANY:1')
  925.         #FOR(%RelationKeyField)
  926. IF KEYCODE() <> EscKey
  927.   %RelationKeyField = %RelationKeyFieldLink      #<!Assign linking field value
  928.         #ENDFOR
  929.   GET(%Relation,%RelationKey)                    #<!Lookup record
  930.   IF ERRORCODE()                                 #<!Did the GET succeed ?
  931.   #FIX(%File,%FieldLookup)
  932.     CLEAR(%FilePre:Record)                       #<!Clear record if unsuccessful
  933.     GLO:Message1 = 'Error: ' & ERRORCODE() & ' '& ERROR() #<!Build error message
  934.     GLO:Message2 = 'The value you enter must exist in the'
  935.     GLO:Message3 = 'File: %FieldLookup'          #<!Identify the Lookup file
  936.     ShowWarning                                  !Notify the user
  937.     SELECT(%ScreenField)                         !Reselect the screen field
  938.   END                                            !End IF Errorcode
  939. END                                              !Not EscKey
  940.          #ENDIF
  941.         #ENDIF
  942.       #ENDIF
  943.     #ENDIF
  944. #!***************************************************************************
  945. #GROUP(%FieldLookupOpen)
  946.   #FOR(%ScreenField)
  947.     #IF(%ScreenFieldType = 'ENTRY')
  948.      #FIX(%Field,%ScreenFieldUse)
  949.         #IF(%Field = %ScreenFieldUse)
  950.           #IF(%FieldLookup)
  951.            #FIX(%File,%FieldFile)
  952.            #FIX(%Relation,%FieldLookup)
  953.             #IF(%RelationType = 'MANY:1')
  954.              #FIX(%Secondary,%Relation)
  955.              #IF(%Secondary = %NULL)
  956. CheckOpen(%Relation)                             #<!Is Lookup file is OPEN ?
  957.              #ENDIF
  958.             #ENDIF
  959.           #ENDIF
  960.         #ENDIF
  961.     #ENDIF
  962.   #ENDFOR
  963. #!***************************************************************************
  964. #GROUP(%DupKeyCode)
  965. #FIX(%File,%Primary)
  966. IF ERRORCODE() = DupKeyErr                       #<! Duplicate key detected
  967.   #FOR(%Key)
  968.   #IF(UPPER(%KeyDuplicate) <> 'Y')
  969.   IF DUPLICATE(%Key)                             #<!check unique keys
  970.     GLO:Message3 = '[ '
  971.     #FOR(%KeyField)
  972.     GLO:Message3 = Clip(GLO:Message3) & (' %KeyField ')
  973.     #ENDFOR
  974.     GLO:Message3 = Clip(GLO:Message3)&' ]'
  975.   END
  976.   #ENDIF
  977.   #ENDFOR
  978.   GLO:Message1 = 'This record creates a duplicate key entry'
  979.   GLO:Message2 = 'The unique key field(s) are listed below: '
  980.   ShowWarning                                    #<!inform the user
  981.   SELECT(1)                                      #<!select first field
  982.   DISPLAY                                        #<!re-display the screen
  983.   CYCLE                                          #<!back to main loop
  984. END                                              #<!End IF Duplicate errorcode
  985. #!***************************************************************************
  986. #GROUP(%PositionCheck)
  987. IF POSITION(%Primary) <> SavePointer             #<!compare the positions
  988.   GLO:Message1 = 'The Record was Deleted by another workstation'
  989.   GLO:Message2 = 'when you return to the entry FORM choose OK  '
  990.   GLO:Message3 = 'to ADD as a new record, or CANCEL to abort   '
  991.   ShowWarning
  992.   #INSERT(%InsertMessage)
  993.   Action = AddRecord
  994.   GET(RecordQueue,2)                             #<!Get the users changes
  995.   %FilePre:Record = Sav:SaveRecord               #<!Update the Record buffer
  996.   #IF(%MemoChk = 'TRUE')
  997.   #FOR(%Field)
  998.   #IF(%FieldType = 'MEMO')
  999.   %Field = SAV:%FieldID                          #<!Update the Memo buffer
  1000.   #ENDIF
  1001.   #ENDFOR
  1002.   #ENDIF
  1003.   DISPLAY                                        #<!Update the screen
  1004.   SELECT(1)                                      #<!Place the cursor on 1st field
  1005.   RELEASE(%Primary)                              #<!Release HOLD request
  1006.   CYCLE                                          #<!Re-start the Loop
  1007. END                                              #<!End Position check
  1008. #!***************************************************************************
  1009. #GROUP(%ClearValues)
  1010. CLEAR(%FilePre:Record)                           #<!CLEAR Record buffer
  1011. #FOR(%FileMemo)
  1012. CLEAR(%FileMemo)                                 #<!CLEAR Memo buffer
  1013. #ENDFOR
  1014. #!***************************************************************************
  1015. #GROUP(%InitFormSymbols)
  1016. #FIX(%File,%Primary)
  1017. #SET(%PrimaryDriver,%FileType)
  1018. #FOR(%HotKey)
  1019.  #IF(%HotKeyProc)
  1020.   #SET(%HotKeysExist,'TRUE')
  1021.   #BREAK
  1022.  #ENDIF
  1023. #ENDFOR
  1024. #FOR(%Key)
  1025.   #IF(%KeyAuto <> %NULL)
  1026.     #SET(%AutoInc,'TRUE')
  1027.   #ENDIF
  1028.   #IF(%KeyDuplicate <> 'Y')
  1029.     #SET(%DupKeyCheck,'TRUE')
  1030.   #ENDIF
  1031. #ENDFOR
  1032. #FOR(%Formula)
  1033.   #SET(%FormulasExist,'TRUE')
  1034.   #IF(UPPER(%FormulaClass) = 'PRIMEKEY')
  1035.     #SET(%PrimeKeysExist,'TRUE')
  1036.   #ENDIF
  1037. #ENDFOR
  1038. #FOR(%Filememo)
  1039.   #SET(%MemoChk,'TRUE')
  1040.   #BREAK
  1041. #ENDFOR
  1042. #FOR(%Field)
  1043.   #IF(%FieldInitial <> %NULL)
  1044.     #SET(%InitRoutine,'TRUE')
  1045.     #BREAK
  1046.   #ENDIF
  1047. #ENDFOR
  1048. #FOR(%Relation)
  1049.  #IF(%RelationType = '1:MANY')
  1050.    #SET(%Instance,%Relation)
  1051.    #SET(%LevelOne,(%LevelOne & ','& %Instance))
  1052.    #FOR(%RelationKeyField)
  1053.      #IF(%RelationKeyFieldLink)
  1054.        #SET(%Link,%RelationKeyField)
  1055.        #SET(%RKFL,%RelationKeyFieldLink)
  1056.         #SET(%LevelOneLinks,(%LevelOneLinks & ','& %Link))
  1057.         #SET(%LinkPool,(%LinkPool & ','& %RKFL))
  1058.      #ENDIF
  1059.    #ENDFOR
  1060.   #IF(%RelationConstraintUpdate OR %RelationConstraintDelete)
  1061.     #SET(%RelatedFiles,'TRUE')
  1062.     #INSERT(%PrimaryDriverChk)
  1063.   #ENDIF
  1064.   #IF(%RelationConstraintDelete = 'RESTRICT')
  1065.     #SET(%RestrictDelete,'TRUE')
  1066.   #ENDIF
  1067.   #IF(%RelationConstraintUpdate = 'RESTRICT')
  1068.     #SET(%RestrictUpdate,'TRUE')
  1069.   #ENDIF
  1070.   #IF(%RelationConstraintDelete = 'CASCADE')
  1071.     #SET(%CascadeDelete,'TRUE')
  1072.   #ENDIF
  1073.   #IF(%RelationConstraintUpdate = 'CASCADE')
  1074.     #SET(%CascadeUpdate,'TRUE')
  1075.   #ENDIF
  1076.   #IF(%RelationConstraintDelete = 'CLEAR')
  1077.     #SET(%ClearOnDelete,'TRUE')
  1078.   #ENDIF
  1079.   #IF(%RelationConstraintUpdate = 'CLEAR')
  1080.     #SET(%ClearOnUpdate,'TRUE')
  1081.   #ENDIF
  1082.  #ENDIF
  1083. #ENDFOR
  1084. #FOR(%Secondary)
  1085. #IF(%SecondaryType = 'MANY:1')
  1086.   #SET(%SecondaryExist,'TRUE')
  1087. #ENDIF
  1088. #ENDFOR
  1089. #SET(%SetFile,%Primary)
  1090. #INSERT(%SpatialRelate)
  1091. #!***************************************************************************
  1092. #GROUP(%DeclareRelatedData)
  1093. #FIX(%File,%Primary)
  1094. #FOR(%Relation)
  1095.  #FOR(%RelationKeyField)
  1096.    #IF(%RelationKeyFieldLink <> %NULL)
  1097. %Relation:Lnk:%RelationKeyFieldLink LIKE(%RelationKeyFieldLink) !Relation Link field
  1098.    #ENDIF
  1099.  #ENDFOR
  1100. #ENDFOR
  1101. #!***************************************************************************
  1102. #GROUP(%RelationalAccessFlds)
  1103. #FIX(%File,%SetFile)
  1104. #FOR(%Relation)
  1105.  #IF(%RelationType = '1:MANY')
  1106.   #FOR(%RelationKeyField)
  1107.    #IF(%RelationKeyFieldLink <> %NULL)
  1108.     #SET(%Constructor,(%Relation & ':Lnk:' & %RelationKeyFieldLink))
  1109.      #IF(INSTRING(%Constructor,%Array,1,1) = '0')
  1110. %Relation:Lnk:%RelationKeyFieldLink LIKE(%RelationKeyFieldLink) #<!Define a link field
  1111.     #SET(%Element,(',' & %Constructor))
  1112.     #SET(%Array,(%Array & %Element))
  1113.      #ENDIF
  1114.    #ENDIF
  1115.   #ENDFOR
  1116.    #SET(%SetFile,%Relation)
  1117. #INSERT(%RelationalAccessFlds)
  1118.  #ENDIF
  1119. #ENDFOR
  1120. #!**************************************************************************
  1121. #GROUP(%GenFormulas)
  1122. #IF(%GenerateFormulasOn)
  1123.  
  1124. FormulaFields ROUTINE
  1125.  #FOR(%Formula)
  1126.   #IF(UPPER(%FormulaClass) <> 'PRIMEKEY')
  1127.    #IF(%CodePosition = %NULL OR %CodePosition = %FormulaClass)
  1128.      #IF(%FormulaType = 'COMPUTED')
  1129.   %Formula = %FormulaComputation
  1130.      #ELSE
  1131. IF %FormulaCondition                             #<!If formula condition
  1132.   %Formula = %FormulaTrue
  1133.        #IF(%FormulaFalse)
  1134. ELSE
  1135.   %Formula = %FormulaFalse
  1136.        #ENDIF
  1137. END                                              #<!End formula condition
  1138.      #ENDIF
  1139.    #ENDIF
  1140.   #ENDIF
  1141.  #ENDFOR
  1142.   DISPLAY                                        #<!Update screen display
  1143. #ENDIF
  1144. #!***************************************************************************
  1145. #GROUP(%SpatialRelate)
  1146. #FIX(%File,%SetFile)
  1147. #FOR(%Relation)
  1148.  #IF(%RelationType = '1:MANY')
  1149.   #INSERT(%DriverCheck)
  1150.   #IF(INSTRING(%SetFile,%LevelOne,1,1) = '0')
  1151.    #FOR(%RelationKeyField)
  1152.     #IF(%RelationKeyFieldLink)
  1153.      #SET(%RKFL,%RelationKeyFieldLink)
  1154.      #IF(INSTRING(%RKFL,%LinkPool,1,1) = '0')
  1155.       #SET(%LinkPool,(%LinkPool & ','& %RKFL))
  1156.      #ENDIF
  1157.     #ENDIF
  1158.    #ENDFOR
  1159.   #ENDIF
  1160. #SET(%SetFile,%Relation)
  1161. #INSERT(%SpatialRelate)
  1162. #ENDIF
  1163. #ENDFOR
  1164. #!**************************************************************************
  1165. #GROUP(%SecondaryChanged)
  1166. #FOR(%Secondary)                                #! for fields on the form
  1167.   #IF(%SecondaryType = 'MANY:1')                #!Check for lookup files
  1168.     #FIX(%File,%SecondaryTo)
  1169.     #FIX(%Relation,%Secondary)
  1170.      #FOR(%RelationKeyField)
  1171. IF %RelationKeyField <> %RelationKeyFieldLink    #<!Check for changes
  1172.   DO SecondaryLookups                            #<!Call lookup Routine
  1173. END
  1174.       #ENDFOR
  1175.   #ENDIF
  1176. #ENDFOR
  1177. #!***************************************************************************
  1178. #GROUP(%FieldDups)
  1179.  #FOR(%ScreenField)
  1180.  #IF(%ScreenFieldUse)
  1181.    #SET(%Fld,%ScreenFieldUse)
  1182.    #FIX(%Field,%ScreenFieldUse)
  1183.   #IF(SUB(%Fld,1,1) <> '?')
  1184.     #IF(%FieldID)
  1185.       #IF(%FieldFile = %Primary)
  1186.        #IF(%FieldDimension1)
  1187.         #SET(%DimField,%Field)
  1188.         #IF(INSTRING(%DimField,%DimPool,1,1) = '0')
  1189.          #SET(%DimPool,(%DimPool & ',' & %DimField))
  1190. Dup::%Field   LIKE(%Field)
  1191.         #ENDIF
  1192.        #ELSE
  1193. Dup::%ScreenFieldUse LIKE(%ScreenFieldUse)
  1194.        #ENDIF
  1195.       #ENDIF
  1196.     #ENDIF
  1197.   #ENDIF
  1198.  #ENDIF
  1199.  #ENDFOR
  1200. #!***************************************************************************
  1201. #GROUP(%SaveScrFlds)
  1202.  
  1203. SaveScrFlds ROUTINE
  1204.  #FOR(%ScreenField)
  1205.  #IF(%ScreenFieldUse)
  1206.   #SET(%Fld,%ScreenFieldUse)
  1207.    #FIX(%Field,%ScreenFieldUse)
  1208.   #IF(SUB(%Fld,1,1) <> '?')
  1209.     #IF(%FieldID)
  1210.       #IF(%FieldFile = %Primary)
  1211.   Dup::%ScreenFieldUse = %ScreenFieldUse         #<!Save screen entry
  1212.       #ENDIF
  1213.     #ENDIF
  1214.   #ENDIF
  1215.  #ENDIF
  1216.  #ENDFOR
  1217. #!***************************************************************************
  1218. #GROUP(%DupFldCall)
  1219. IF KEYCODE() = %CopyKey                          #<!User requested field copy
  1220.   DO DupField                                    #<!Call duplication Routine
  1221. END                                              #<!End copy key check
  1222. #!***************************************************************************
  1223. #GROUP(%DupField)
  1224.  
  1225. DupField ROUTINE
  1226.   CASE SELECTED()                                !Which field is selected?
  1227.  #FOR(%ScreenField)
  1228.  #IF(%ScreenFieldUse)
  1229.   #SET(%Fld,%ScreenFieldUse)
  1230.    #FIX(%Field,%ScreenFieldUse)
  1231.   #IF(SUB(%Fld,1,1) <> '?')
  1232.     #IF(%FieldID)
  1233.       #IF(%FieldFile = %Primary)
  1234.     OF ?%ScreenFieldUse
  1235.       %ScreenFieldUse = Dup::%ScreenFieldUse     #<!Move saved entry to screen
  1236.       #ENDIF
  1237.     #ENDIF
  1238.   #ENDIF
  1239.  #ENDIF
  1240.  #ENDFOR
  1241.   END                                            #<!End Case Selected
  1242.   DISPLAY                                        #<!Update screen display
  1243. #!***************************************************************************
  1244. #GROUP(%CommitCheck)
  1245. #IF(%NoLogoutSupport = %NULL)
  1246. IF ~ERRORCODE()
  1247.   COMMIT                                         #<!Commit the transaction
  1248. ELSE                                             !If there was an error
  1249.   GLO:Message1 = 'Unable to complete the transaction'
  1250.   GLO:Message2 = 'Error: ' & ERRORCODE() & ' ' & ERROR()
  1251.   GLO:Message3 = 'Files will be restored to their original values'
  1252.   ShowWarning                                    #<!Notify the user
  1253.   ROLLBACK                                       #<!Rollback the transaction
  1254. END                                              !End error check
  1255. #ELSE
  1256. IF ERRORCODE()                                   !Check for error
  1257.     GLO:Message1 = 'The Referential Update/Delete encountered an error'
  1258.     GLO:Message2 = 'Error: '& ERRORCODE() & ' ' & ERROR()
  1259.     GLO:Message3 = 'Relational integrity for: ' & ERRORFILE() & 'is suspect'
  1260.   ShowWarning                                    #<!Notify the user
  1261. END                                              !End error check
  1262. #ENDIF
  1263. #!***************************************************************************
  1264. #GROUP(%AltKeys)
  1265. #IF(%Page2Proc)
  1266. OF Alt2                                          !Hotkey to Page 2
  1267.   PRESS(AltN)                                    !Press Next_Page Key
  1268. #ENDIF
  1269. #IF(%Page3Proc)
  1270. OF Alt3                                          !Hotkey to Page 3
  1271.   LOC:Page = 2                                   !Press Next_Page Key
  1272.   PRESS(AltN)
  1273. #ENDIF
  1274. #IF(%Page4Proc)
  1275. OF Alt4                                          !Hotkey to Page 4
  1276.   LOC:Page = 3                                   !Press Next_Page Key
  1277.   PRESS(AltN)
  1278. #ENDIF
  1279. #IF(%Page5Proc)
  1280. OF Alt5                                          !Hotkey to Page 5
  1281.   LOC:Page = 4                                   !Press Next_Page Key
  1282.   PRESS(AltN)
  1283. #ENDIF
  1284. #IF(%Page6Proc)
  1285. OF Alt6                                          !Hotkey to Page 6
  1286.   LOC:Page = 5                                   !Press Next_Page Key
  1287.   PRESS(AltN)
  1288. #ENDIF
  1289. #IF(%Page7Proc)
  1290. OF Alt7
  1291.   LOC:Page = 6                                   !Hotkey to Page 7
  1292.   PRESS(AltN)                                    !Press Next_Page Key
  1293. #ENDIF
  1294. #IF(%Page8Proc)
  1295. OF Alt8
  1296.   LOC:Page = 7                                   !Hotkey to Page 8
  1297.   PRESS(AltN)                                    !Press Next_Page Key
  1298. #ENDIF
  1299. #IF(%Page9Proc)
  1300. OF Alt9
  1301.   LOC:Page = 8                                   !Hotkey to Page 9
  1302.   PRESS(AltN)                                    !Press Next_Page Key
  1303. #ENDIF
  1304. #!***************************************************************************
  1305. #GROUP(%ProcCounter)
  1306.       #IF(%Page2Proc)
  1307.         #SET(%ProcCount,'2')
  1308.         #IF(%Page3Proc)
  1309.             #SET(%ProcCount,(%ProcCount + 1))
  1310.          #ENDIF
  1311.          #IF(%Page4Proc)
  1312.             #SET(%ProcCount,(%ProcCount + 1))
  1313.          #ENDIF
  1314.          #IF(%Page5Proc)
  1315.             #SET(%ProcCount,(%ProcCount + 1))
  1316.          #ENDIF
  1317.          #IF(%Page6Proc)
  1318.             #SET(%ProcCount,(%ProcCount + 1))
  1319.          #ENDIF
  1320.          #IF(%Page7Proc)
  1321.             #SET(%ProcCount,(%ProcCount + 1))
  1322.          #ENDIF
  1323.          #IF(%Page8Proc)
  1324.             #SET(%ProcCount,(%ProcCount + 1))
  1325.          #ENDIF
  1326.          #IF(%Page9Proc)
  1327.             #SET(%ProcCount,(%ProcCount + 1))
  1328.          #ENDIF
  1329.       #ENDIF
  1330. #!***************************************************************************
  1331. #GROUP(%ButtonCheck)
  1332.    #FOR(%ScreenField)
  1333.      #IF(UPPER(%ScreenFieldUse) = '?BASE_PAGE')
  1334.       #SET(%BasePageExists,'TRUE')
  1335.      #ENDIF
  1336.      #IF(UPPER(%ScreenFieldUse) = '?LAST_PAGE')
  1337.       #SET(%LastPageExists,'TRUE')
  1338.      #ENDIF
  1339.    #ENDFOR
  1340. #!***************************************************************************
  1341. #GROUP(%SavePrimedFields)
  1342. #FOR(%Key)
  1343.  #IF(%KeyAuto)
  1344.   #FOR(%KeyField)
  1345.    #IF(%KeyField <> %KeyAuto)
  1346. Prime::%KeyField  LIKE(%KeyField)
  1347.    #ENDIF
  1348.   #ENDFOR
  1349.  #ENDIF
  1350. #ENDFOR
  1351. #!***************************************************************************
  1352. #GROUP(%DriverCheck)
  1353. #IF(%FileType <> %PrimaryDriver)
  1354.   #SET(%ErrorMessage,%NULL)
  1355.   #ERROR(%ErrorMessage)
  1356.   #SET(%ErrorMessage,(' WARNING during Source Code Generation in Procedure: '& %Procedure ))
  1357.   #ERROR(%ErrorMessage)
  1358.   #SET(%ErrorMessage, ' the FILE Relationship uses multiple file drivers')
  1359.   #ERROR(%ErrorMessage)
  1360.   #SET(%ErrorMessage,(' see FORM Template Help, TOPIC: No Transaction Framing'))
  1361.   #ERROR(%ErrorMessage)
  1362.   #SET(%ErrorMessage, %NULL)
  1363.   #ERROR(%ErrorMessage)
  1364.   #SET(%NoLogoutSupport,'TRUE')
  1365. #ENDIF
  1366. #!***************************************************************************
  1367. #GROUP(%PrimaryDriverChk)
  1368. #IF((UPPER(%PrimaryDriver) <> 'BTRIEVE') AND (UPPER(%PrimaryDriver) <> 'CLARION'))
  1369.   #SET(%ErrorMessage,%NULL)
  1370.   #ERROR(%ErrorMessage)
  1371.   #SET(%ErrorMessage,(' WARNING during Code Generation in Procedure: '& %Procedure ))
  1372.   #ERROR(%ErrorMessage)
  1373.   #SET(%ErrorMessage,( ' PRIMARY file driver (' & %PrimaryDriver & ') does not support LOGOUT() '))
  1374.   #ERROR(%ErrorMessage)
  1375.   #SET(%ErrorMessage,('   see FORM Template Help, Topic: No Transaction Framing'))
  1376.   #ERROR(%ErrorMessage)
  1377.   #SET(%NoLogoutSupport,'TRUE')
  1378. #ENDIF
  1379. #CHAIN('OM6.TPX')
  1380.