home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / C7101.ZIP / BRWSGRPS.TPX < prev    next >
Text File  |  1994-02-01  |  42KB  |  909 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                              BrwsGrps.TPX              │Version: 3007.101│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│SetBrowseSymbols      GROUP                                               │
  7. #!│AddFixedListLines     GROUP                                               │
  8. #!│BeginBrowse           GROUP                                               │
  9. #!│FillKeyValues         GROUP                                               │
  10. #!│BrowseErrorCheck      GROUP                                               │
  11. #!│ClearFileFields       GROUP                                               │
  12. #!│TotalBeforeUpdate     GROUP                                               │
  13. #!│TotalAfterUpdate      GROUP                                               │
  14. #!│AddTotalValues        GROUP                                               │
  15. #!│UpdateTotalValues     GROUP                                               │
  16. #!│ClearTotalValues      GROUP                                               │
  17. #!│SetupKeyRangeFields   GROUP                                               │
  18. #!│SaveRangeFields       GROUP                                               │
  19. #!│RestoreRangeFields    GROUP                                               │
  20. #!│CheckKeyRangeFields   GROUP                                               │
  21. #!│RangeComparison       GROUP                                               │
  22. #!│EditCodeInsert        GROUP                                               │
  23. #!│EditCodeChange        GROUP                                               │
  24. #!│EditCodeDelete        GROUP                                               │
  25. #!│EditCodeSelect        GROUP                                               │
  26. #!│EditCodeExit          GROUP                                               │
  27. #!│EditCodeCancel        GROUP                                               │
  28. #!│EditCodeList          GROUP                                               │
  29. #!│ClearRecordHigh       GROUP                                               │
  30. #!│ClearRecordLow        GROUP                                               │
  31. #!│LookupValidateCode    GROUP                                               │
  32. #!│LookupRecord          GROUP                                               │
  33. #!│IsUpdateSuccessful    GROUP                                               │
  34. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  35. #!│Version   Comments                                                        │
  36. #!│────────  ────────────────────────────────────────────────────────────────│
  37. #!│3007.000  Release of CDD3 version 3007 templates                          │
  38. #!│3007.101  Repaired %SetBrowseSymbols GROUP                                │
  39. #!│          Repaired %UpdateTotalValues GROUP                               │
  40. #!└──────────────────────────────────────────────────────────────────────────┘
  41. #!
  42. #GROUP(%SetBrowseSymbols)
  43. #!
  44. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  45. #!│                            SetBrowseSymbols            │Version: 3007.101│
  46. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  47. #!│Purpose:      Determine operating parameters of a Browse-type procedure   │
  48. #!│Called From:  Browse,Validate,Lookup,Select                               │
  49. #!│Assumptions:  None                                                        │
  50. #!│Inserts:      None                                                        │
  51. #!│Symbols Set:  Most Browse Symbols                                         │
  52. #!│Notes:        None                                                        │
  53. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  54. #!│Version   Comments                                                        │
  55. #!│────────  ────────────────────────────────────────────────────────────────│
  56. #!│3007.000  Release of CDD3 version 3007 templates                          │
  57. #!│3007.101  Changed Hot Fields code to exclude the Locator from displayed   │
  58. #!│          fields and to add pre-?List fields                              │
  59. #!└──────────────────────────────────────────────────────────────────────────┘
  60. #!
  61.   #SET(%FirstEntryField,%Null)
  62.   #SET(%PreListEntry,%Null)
  63.   #SET(%UpdateButtonsExist,%Null)
  64.   #SET(%KeyboardInsert,%Null)
  65.   #SET(%KeyboardChange,%Null)
  66.   #SET(%KeyboardDelete,%Null)
  67.   #SET(%KeyboardSelect,%Null)
  68.   #SET(%InsertExists,%Null)
  69.   #SET(%ChangeExists,%Null)
  70.   #SET(%DeleteExists,%Null)
  71.   #SET(%SelectExists,%Null)
  72.   #SET(%ExitExists,%Null)
  73.   #SET(%FilterExists,%Null)
  74.   #SET(%HotKeyExists,%Null)
  75.   #SET(%ScreenFldSetupExists,%Null)
  76.   #SET(%ScreenFldEditExists,%Null)
  77.   #SET(%ControlRelatedFiles,%Null)
  78.   #SET(%TotalExists,%Null)
  79.   #SET(%TotalFormulas,%Null)
  80.   #SET(%FirstHotField,%Null)
  81.   #SET(%SecondHotField,%Null)
  82.   #SET(%ThirdHotField,%Null)
  83.   #SET(%FourthHotField,%Null)
  84.   #SET(%FifthHotField,%Null)
  85.   #SET(%SixthHotField,%Null)
  86.   #FIX(%File,%Primary)
  87.   #FOR(%HotKey)
  88.     #SET(%HotKeyExists,'YES')
  89.     #BREAK
  90.   #ENDFOR
  91.   #FOR(%Formula)
  92.     #IF(UPPER(%FormulaClass) = 'FILTER')
  93.       #SET(%FilterExists, 'YES')
  94.     #ENDIF
  95.   #ENDFOR
  96.   #IF(%RecordFilter)
  97.     #SET(%FilterExists, 'YES')
  98.   #ENDIF
  99.   #SET(%FirstEntryFound,%Null)
  100.   #FOR(%ScreenField)
  101.     #SET(%ScreenFieldExists,'YES')
  102.     #IF(%FirstEntryFound = %Null)
  103.       #SET(%FirstEntryField, (%FirstEntryField + 1))
  104.       #IF(%ScreenFieldSkip <> 'Y')
  105.         #SET(%FirstEntryFound,'YES')
  106.       #ENDIF
  107.     #ENDIF
  108.     #IF(%ScreenFieldType = 'BUTTON')
  109.       #IF(UPPER(%ScreenField) = '?INSERT')
  110.         #SET(%UpdateButtonsExist, 'YES')
  111.         #SET(%InsertExists, 'YES')
  112.         #SET(%KeyboardInsert,'YES')
  113.       #ELSIF(UPPER(%ScreenField) = '?CHANGE')
  114.         #SET(%UpdateButtonsExist, 'YES')
  115.         #SET(%ChangeExists, 'YES')
  116.         #SET(%KeyboardChange,'YES')
  117.       #ELSIF(UPPER(%ScreenField) = '?DELETE')
  118.         #SET(%UpdateButtonsExist, 'YES')
  119.         #SET(%DeleteExists, 'YES')
  120.         #SET(%KeyboardDelete,'YES')
  121.       #ELSIF(UPPER(%ScreenField) = '?SELECT')
  122.         #SET(%UpdateButtonsExist, 'YES')
  123.         #SET(%SelectExists, 'YES')
  124.         #SET(%KeyboardSelect,'YES')
  125.       #ELSIF(UPPER(%ScreenField) = '?EXIT')
  126.         #SET(%ExitExists, 'YES')
  127.       #ENDIF
  128.     #ENDIF
  129.   #ENDFOR
  130.   #IF(%UpdateButtonsExist=%Null)
  131.     #SET(%KeyboardInsert,'YES')
  132.     #SET(%KeyboardChange,'YES')
  133.     #SET(%KeyboardDelete,'YES')
  134.     #SET(%KeyboardSelect,'YES')
  135.   #ENDIF
  136.   #IF(%ScreenFieldSetup)
  137.     #SET(%ScreenFldSetupExists,'YES')
  138.   #ENDIF
  139.   #IF(%ScreenFieldEdit)
  140.     #SET(%ScreenFldEditExists,'YES')
  141.   #ENDIF
  142.   #SET(%FixRows, '0')
  143.   #FIX(%ScreenField,'?List')
  144.   #FOR(%ScreenFieldFix)
  145.     #SET(%FixRows, (%FixRows + 1))
  146.   #ENDFOR
  147.   #FOR(%Formula)
  148.     #IF(UPPER(%FormulaClass) = 'SUM')
  149.       #SET(%TotalFormulas,'TRUE')
  150.       #BREAK
  151.     #ELSIF(UPPER(%FormulaClass) = 'AVG')
  152.       #SET(%TotalFormulas,'TRUE')
  153.       #BREAK
  154.     #ELSIF(UPPER(%FormulaClass) = 'CNT')
  155.       #SET(%TotalFormulas,'TRUE')
  156.       #BREAK
  157.     #ENDIF
  158.   #ENDFOR
  159.   #IF(%TotalsOn OR %TotalFormulas)
  160.     #SET(%TotalExists, 'TRUE')
  161.     #IF(%KeyRangeField)
  162.       #FOR(%ScreenField)
  163.         #IF(UPPER(%ScreenField)='?LIST')
  164.           #BREAK
  165.         #ENDIF
  166.         #IF(%ScreenFieldType='ENTRY')
  167.           #IF(%ScreenFieldSkip <> 'Y')
  168.             #IF(UPPER(%ScreenFieldUse)<>UPPER(%Locator))
  169.               #SET(%PreListEntry,'TRUE')
  170.               #BREAK
  171.             #ENDIF
  172.           #ENDIF
  173.         #ENDIF
  174.       #ENDFOR
  175.     #ENDIF
  176.   #ENDIF
  177.   #IF(%HotBar)                                   #! IF updating screen on key
  178.     #SET(%ListFound,%Null)                       #! CLEAR Flag (Last Found?)
  179.     #SET(%LocatorFound,%Null)                    #! CLEAR Flag (Locator Found?)
  180.     #FOR(%ScreenField)                           #! Cycle through screen fields
  181.       #IF(%ListFound=%Null)                      #! IF ?List not processed
  182.         #IF(UPPER(%ScreenField)='?LIST')         #! IF %ScreenField is ?List
  183.           #SET(%ListFound,'TRUE')                #! SET the Flag
  184.         #ELSE                                    #! ELSE (IF %ScreenField...)
  185.           #IF(%FirstHotField)                    #! IF we've got a start
  186.             #SET(%SecondHotField,%ScreenField)   #! Get an end
  187.           #ELSE                                  #! ELSE (If we've got...)
  188.             #SET(%FirstHotField,%ScreenField)    #! Get a start
  189.           #ENDIF                                 #! END (If we've got...)
  190.         #ENDIF                                   #! END (If %ScreenField...)
  191.       #ELSIF(%LocatorFound=%Null)                #! ELSIF Locator not processed
  192.         #IF(UPPER(%ScreenFieldUse)=UPPER(%Locator)) #! IF %ScreenFieldUse is %Locator
  193.           #SET(%LocatorFound,'TRUE')             #! SET the Flag
  194.         #ELSE                                    #! ELSE (IF %ScreenField...)
  195.           #IF(%ThirdHotField)                    #! IF we've got a start
  196.             #SET(%FourthHotField,%ScreenField)   #! Get an end
  197.           #ELSE                                  #! ELSE (If we've got...)
  198.             #SET(%ThirdHotField,%ScreenField)    #! Get a start
  199.           #ENDIF                                 #! END (If we've got...)
  200.         #ENDIF                                   #! END (If %ScreenField...)
  201.       #ELSE                                      #! ELSE (Past Locator)
  202.         #IF(%FifthHotField)                      #! IF we've got a start
  203.           #SET(%SixthHotField,%ScreenField)      #! Get an end
  204.         #ELSE                                    #! ELSE (If we've got...)
  205.           #SET(%FifthHotField,%ScreenField)      #! Get a start
  206.         #ENDIF                                   #! END (If we've got...)
  207.       #ENDIF                                     #! END (IF List not...)
  208.     #ENDFOR                                      #! END (cycle through screen...)
  209.   #ENDIF                                         #! END (IF updating screen...)
  210. #!                                               #!
  211. #!***************************************************************************
  212. #GROUP(%AddFixedListLines)                   #!Group to add any QUEUE fixed
  213. #FIX(%ScreenField,'?List')                   #! lines to the QUEUE.
  214. #FOR(%ScreenFieldFix)
  215. Queue = %ScreenFieldFix                      #<!Add fixed listbox line
  216. ADD(Queue)                                     ! to the QUEUE
  217. #ENDFOR
  218. #!***************************************************************************
  219. #GROUP(%BeginBrowse)
  220. #IF(%NoMemo)
  221.   #IF(%Locator)                                #!Conditionally initialize
  222.     #IF(%IncrementalLocator)
  223.       #IF(%HotBar)                             #! the browse session manager
  224. BeginBrowse(?List,?%Locator,1,1,1) #<!Begin a browse session
  225.       #ELSE
  226. BeginBrowse(?List,?%Locator,,1,1)              #<!Begin a browse session
  227.       #ENDIF
  228.     #ELSE
  229.       #IF(%HotBar)                             #! the browse session manager
  230. BeginBrowse(?List,?%Locator,1,,1)              #<!Begin a browse session
  231.       #ELSE
  232. BeginBrowse(?List,?%Locator,,,1)               #<!Begin a browse session
  233.       #ENDIF
  234.     #ENDIF
  235.   #ELSE
  236.     #IF(%HotBar)
  237. BeginBrowse(?List,,1,,1)                       #<!Begin a browse session
  238.     #ELSE
  239. BeginBrowse(?List,,,,1)                        #<!Begin a browse session
  240.     #ENDIF
  241.   #ENDIF
  242. #ELSE
  243.   #IF(%Locator)                                #!Conditionally initialize
  244.     #IF(%IncrementalLocator)
  245.       #IF(%HotBar)                             #! the browse session manager
  246. BeginBrowse(?List,?%Locator,1,1) #<!Begin a browse session
  247.       #ELSE
  248. BeginBrowse(?List,?%Locator,,1)                #<!Begin a browse session
  249.       #ENDIF
  250.     #ELSE
  251.       #IF(%HotBar)                             #! the browse session manager
  252. BeginBrowse(?List,?%Locator,1)                 #<!Begin a browse session
  253.       #ELSE
  254. BeginBrowse(?List,?%Locator)                   #<!Begin a browse session
  255.       #ENDIF
  256.     #ENDIF
  257.   #ELSE
  258.     #IF(%HotBar)
  259. BeginBrowse(?List,,1)                          #<!Begin a browse session
  260.     #ELSE
  261. BeginBrowse(?List)                             #<!Begin a browse session
  262.     #ENDIF
  263.   #ENDIF
  264. #ENDIF
  265. #!***************************************************************************
  266. #GROUP(%FillKeyValues)
  267. #FOR(%KeyField)
  268. QUE::%KeyField =%KeyField                      #<!   Fill any key fields
  269. #ENDFOR
  270. #!
  271. #!***************************************************************************
  272. #GROUP(%BrowseErrorCheck)
  273. #!
  274. #IF(%Primary = %Null)
  275.   #SET(%ErrorMessage, (%Procedure & ' ERROR: No file has been chosen for this procedure.'))
  276.   #ERROR(%ErrorMessage)
  277.   #SET(%ErrorMessage, ' A file must be selected for this procedure.')
  278.   #ERROR(%ErrorMessage)
  279. #ENDIF
  280. #IF(%PrimaryKey = %Null)
  281.   #SET(%ErrorMessage, (%Procedure & ' ERROR: No Access Key has been chosen for this procedure.'))
  282.   #ERROR(%ErrorMessage)
  283.   #SET(%ErrorMessage, ' An Access Key must be identified on the File Schematic.')
  284.   #ERROR(%ErrorMessage)
  285. #ENDIF
  286. #IF(%KeyRangeField)
  287.   #IF(UPPER(%KeyRangeField) = UPPER(%RangeValue))
  288.     #SET(%ErrorMessage, (%Procedure & ' ERROR: Range Limit Field and Range Value fields must'))
  289.     #ERROR(%ErrorMessage)
  290.     #SET(%ErrorMessage, ' be separate fields.')
  291.     #ERROR(%ErrorMessage)
  292.   #ENDIF
  293. #ENDIF
  294. #FIX(%File,%Primary)
  295. #IF(%DisplayKey)
  296.   #FIX(%Key,%DisplayKey)
  297. #ELSE
  298.   #FIX(%Key,%PrimaryKey)
  299. #ENDIF
  300. #IF(%Locator)
  301.   #SET(%FieldFound,%Null)
  302.   #FOR(%KeyField)
  303.     #IF(UPPER(%KeyField) = UPPER(%Locator))
  304.       #SET(%FieldFound,'Yes')
  305.       #BREAK
  306.     #ENDIF
  307.   #ENDFOR
  308.   #IF(%FieldFound = %Null)
  309.     #SET(%ErrorMessage, (%Procedure & ' ERROR: the Locator Field must be a component of'))
  310.     #ERROR(%ErrorMessage)
  311.     #SET(%ErrorMessage, (' the ' & %Key & ' key.'))
  312.     #ERROR(%ErrorMessage)
  313.   #ENDIF
  314. #ENDIF
  315. #IF((UPPER(%ProcedureTemplate)='BROWSE' OR UPPER(%ProcedureTemplate)='SELECT'))
  316.   #FIX(%Key,%PrimaryKey)
  317. #ELSE
  318.   #IF(%DisplayKey)
  319.     #FIX(%Key,%DisplayKey)
  320.   #ELSE
  321.     #FIX(%Key,%PrimaryKey)
  322.   #ENDIF
  323. #ENDIF
  324. #IF(%KeyRangeField)
  325.   #SET(%FieldFound,%Null)
  326.   #FOR(%KeyField)
  327.     #IF(UPPER(%KeyField) = UPPER(%KeyRangeField))
  328.       #SET(%FieldFound,'Yes')
  329.       #BREAK
  330.     #ENDIF
  331.   #ENDFOR
  332.   #IF(%FieldFound = %Null)
  333.     #SET(%ErrorMessage, (%Procedure & ' ERROR: Key Range Limit Field must be a component of the'))
  334.     #ERROR(%ErrorMessage)
  335.     #SET(%ErrorMessage, ' File Access Key')
  336.     #ERROR(%ErrorMessage)
  337.   #ENDIF
  338. #ENDIF
  339. #!
  340. #!***************************************************************************
  341. #GROUP(%ClearFileFields)
  342. #!
  343. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  344. #!│                            ClearFileFields             │Version: 3007.101│
  345. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  346. #!│Purpose:      Clear out a File's record structure and memos.              │
  347. #!│Called From:  Various INSERTS from BROWSE type procedures                 │
  348. #!│Assumptions:  That %File is FIXed                                         │
  349. #!│Inserts:      None                                                        │
  350. #!│Symbols Set:  None                                                        │
  351. #!│Notes:        None                                                        │
  352. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  353. #!│Version   Comments                                                        │
  354. #!│────────  ────────────────────────────────────────────────────────────────│
  355. #!│3007.000  Release of CDD3 version 3007 templates                          │
  356. #!│3007.101  Modified to support the clearing of BINARY memos to low values  │
  357. #!│          CLEAR(%Field,-1).  Before, all memos were cleared to 0.         │
  358. #!└──────────────────────────────────────────────────────────────────────────┘
  359. #!
  360. CLEAR(%FilePre:Record)                           #<! CLEAR Record buffer
  361. #FOR(%FileMemo)                                  #! Cycle through each memo
  362.   #FIX(%Field,%FileMemo)                         #! FIX the field to the memo
  363.   #IF(%FieldMemoImage='Y')                       #! IF a Binary memo
  364. CLEAR(%Field,-1)                                 #<! CLEAR BINARY Memo buffer
  365.   #ELSE                                          #! ELSE (IF not a Binary...)
  366. CLEAR(%Field)                                    #<! CLEAR Memo buffer
  367.   #ENDIF                                         #! END (IF a Binary...)
  368. #ENDFOR                                          #! END (Cycle through each...)
  369. #!***************************************************************************
  370. #GROUP(%TotalBeforeUpdate)                       #!Group Containing Browse totals
  371. #IF(%TotalExists)                                #! If we are doing totals
  372. #INSERT(%GetSecondaryRecords)                    #! Lookup any secondaries
  373.   #IF(%TotalFormulas)                            #! If Formulas compute totals
  374.     #IF(%KeyboardChange OR %KeyboardDelete)      #! IF Change or Delete Active
  375. CASE UpdateMode                                  #<! Check how update is called
  376.       #IF(%KeyboardChange AND %KeyboardDelete)
  377. OF ChangeRecord OROF DeleteRecord                #<! Changing or Deleting
  378.       #ELSIF(%KeyboardChange)
  379. OF ChangeRecord                                  #<! Changing
  380.       #ELSE
  381. OF DeleteRecord                                  #<! Deleting
  382.       #ENDIF
  383.       #FOR(%Formula)                             #! Cycle through the formulas
  384.         #IF(%FormulaType = 'COMPUTED')           #! If using COMPUTED formula
  385.           #IF((UPPER(%FormulaClass)='SUM' OR UPPER(%FormulaClass)='AVG'))
  386.   Old::%Formula$ = %FormulaComputation           #<! TOTAL:%FormulaDescription
  387.           #ENDIF
  388.           #IF((UPPER(%FormulaClass)='CNT' OR UPPER(%FormulaClass)='AVG'))
  389.   Old::%Formula# = 1                             #<! TOTAL:%FormulaDescription
  390.           #ENDIF
  391.         #ELSE                                    #! otherwise (CONDITION formula)
  392.           #IF((UPPER(%FormulaClass)='SUM' OR UPPER(%FormulaClass)='AVG'))
  393.   Old::%Formula$ = 0                             #! If Average or Counting
  394.           #ENDIF
  395.           #IF((UPPER(%FormulaClass)='CNT' OR UPPER(%FormulaClass)='AVG'))
  396.   Old::%Formula# = 0                             #! If Average or Counting
  397.           #ENDIF
  398.   IF %FormulaCondition                           #<! TOTAL:%FormulaDescription
  399.           #IF((UPPER(%FormulaClass)='SUM' OR UPPER(%FormulaClass)='AVG'))
  400.     Old::%Formula$ = %FormulaTrue                #! If Average or Counting
  401.           #ENDIF
  402.           #IF((UPPER(%FormulaClass)='CNT' OR UPPER(%FormulaClass)='AVG'))
  403.     Old::%Formula# = 1                           #! If Average or Counting
  404.           #ENDIF
  405.           #IF(%FormulaFalse)                     #! If there is a FALSE value
  406.   ELSE                                           #<! otherwise (FALSE)
  407.             #IF((UPPER(%FormulaClass)='SUM' OR UPPER(%FormulaClass)='AVG'))
  408.     Old::%Formula$ = %FormulaFalse               #! If Average or Counting
  409.             #ENDIF
  410.             #IF((UPPER(%FormulaClass)='CNT' OR UPPER(%FormulaClass)='AVG'))
  411.     Old::%Formula# = 1                           #! If Average or Counting
  412.             #ENDIF
  413.           #ENDIF
  414.   END                                            #<! END (If condition is true)
  415.         #ENDIF                                   #! ENDIF (FormulaClass...)
  416.       #ENDFOR                                    #! ENDFOR (Formula...)
  417. END                                              #<! END (CASE KEYCODE()...)
  418.     #ENDIF                                       #! END (If Change or ...)
  419.   #ENDIF                                         #! END (If Formulas...)
  420. #ENDIF                                           #! ENDIF (TotalsExist...)
  421. #!***************************************************************************
  422. #GROUP(%TotalAfterUpdate)
  423. #IF(%TotalExists)
  424. #INSERT(%GetSecondaryRecords)
  425.   #IF(%TotalFormulas)                            #! If Formulas compute totals
  426. IF UpdateSuccessful
  427.     #IF(%KeyboardChange OR %KeyboardDelete)      #! IF Change or Delete Active
  428.       #IF(%KeyboardChange AND %KeyboardDelete)
  429.   IF UpdateMode = ChangeRecord OR UpdateMode = DeleteRecord
  430.       #ELSIF(%KeyboardChange)
  431.   IF UpdateMode = ChangeRecord
  432.       #ELSE
  433.   IF UpdateMode = DeleteRecord
  434.       #ENDIF
  435.       #FOR(%Formula)
  436.       #IF((UPPER(%FormulaClass) = 'AVG' OR UPPER(%FormulaClass)='CNT'))
  437.     %Formula# -= Old::%Formula#
  438.         #ENDIF
  439.         #IF((UPPER(%FormulaClass) = 'SUM' OR UPPER(%FormulaClass)='AVG'))
  440.     %Formula$ -= Old::%Formula$
  441.         #ENDIF
  442.       #ENDFOR
  443.   END
  444.     #ENDIF
  445.     #IF(%KeyboardChange OR %KeyboardInsert)      #! IF Change or Delete Active
  446.       #IF(%KeyboardChange AND %KeyboardInsert)
  447.   IF UpdateMode = ChangeRecord OR UpdateMode = AddRecord
  448.       #ELSIF(%KeyboardChange)
  449.   IF UpdateMode = ChangeRecord
  450.       #ELSE
  451.   IF UpdateMode = AddRecord                      #!If Changing or Adding
  452.       #ENDIF
  453.     LOOP
  454.       #IF(%KeyRangeField)                          #!If using range limits
  455.       #INSERT(%RangeComparison)
  456.         BREAK
  457.       END
  458.       #ENDIF
  459.       #IF(%FilterExists)
  460.         #IF(%RecordFilter)
  461.       IF ~(%RecordFilter)                        #<!If Filter condition not met
  462.         BREAK
  463.       END
  464.         #ENDIF
  465.         #FOR(%Formula)
  466.           #IF(UPPER(%FormulaClass) = 'FILTER')
  467.             #IF(%FormulaType <> 'COMPUTED')
  468.       IF ~(%FormulaCondition)                    #<!If Filter condition not met
  469.         BREAK
  470.       END                                          !End IF
  471.             #ELSE
  472.       IF ~(%FormulaComputation)                  #<!If Filter condition not met
  473.         BREAK
  474.       END                                          !End IF
  475.             #ENDIF
  476.           #ENDIF
  477.         #ENDFOR
  478.       #ENDIF
  479.       #INSERT(%AddTotalValues)
  480.       BREAK
  481.     END
  482.   END
  483.     #ENDIF
  484. END
  485. #INSERT(%UpdateTotalValues)
  486.   #ENDIF                                         #! END (If Formulas...)
  487. #ENDIF
  488. #!***************************************************************************
  489. #GROUP(%AddTotalValues)                          #! Adding values to totals
  490. #FOR(%Formula)                                   #! FOR each Formula
  491.   #IF(%FormulaType = 'COMPUTED')                 #! If COMPUTED formula
  492.     #IF((UPPER(%FormulaClass) = 'CNT' OR UPPER(%FormulaClass)='AVG'))
  493. %Formula# += 1                                   #<!TOTAL:%FormulaDescription
  494.     #ENDIF                                       #! ENDIF (Count or Avg)
  495.     #IF((UPPER(%FormulaClass) = 'SUM' OR UPPER(%FormulaClass)='AVG'))
  496. %Formula$ += %FormulaComputation                 #<!TOTAL:%FormulaDescription
  497.     #ENDIF                                       #! ENDIF (Sum or Avg)
  498.   #ELSE                                          #! If CONDITIONAL formula
  499. IF %FormulaCondition                             #<!TOTAL:%FormulaDescription
  500.     #IF((UPPER(%FormulaClass) = 'CNT' OR UPPER(%FormulaClass)='AVG'))
  501.   %Formula# += 1                                 #<!TOTAL:%FormulaDescription
  502.     #ENDIF                                       #! ENDIF (Count or Avg)
  503.     #IF((UPPER(%FormulaClass) = 'SUM' OR UPPER(%FormulaClass)='AVG'))
  504.   %Formula$ += %FormulaTrue                      #<!TOTAL:%FormulaDescription
  505.     #ENDIF                                       #! ENDIF (Sum or Avg)
  506.     #IF(%FormulaFalse)                           #! IF the formula has FALSE val
  507. ELSE                                             #<! IF the condition is FALSE
  508.       #IF((UPPER(%FormulaClass) = 'CNT' OR UPPER(%FormulaClass)='AVG'))
  509.   %Formula# += 1                                 #<! TOTAL:%FormulaDescription
  510.       #ENDIF                                     #! ENDIF (Count or Avg)
  511.       #IF((UPPER(%FormulaClass) = 'SUM' OR UPPER(%FormulaClass)='AVG'))
  512.   %Formula$ += %FormulaFalse                     #<! TOTAL:%FormulaDescription
  513.       #ENDIF                                     #! ENDIF (Sum or Avg)
  514.     #ENDIF                                       #! ENDIF (False condition...)
  515. END                                              #<! END (IF Condition...)
  516.   #ENDIF                                         #! ENDIF (Conditional formula)
  517. #ENDFOR                                          #! END (For Formula...)
  518. #!***************************************************************************
  519. #GROUP(%UpdateTotalValues)                       #! Updates Totals and screen
  520. #!
  521. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  522. #!│                           UpdateTotalValues            │Version: 3007.101│
  523. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  524. #!│Purpose:      Fill Total formula fields from the accumulation fields      │
  525. #!│Called From:  Browse,Validate,Lookup,Select                               │
  526. #!│Assumptions:  That the GROUP will be called only if totals exist          │
  527. #!│Inserts:      None                                                        │
  528. #!│Symbols Set:  None                                                        │
  529. #!│Notes:        None                                                        │
  530. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  531. #!│Version   Comments                                                        │
  532. #!│────────  ────────────────────────────────────────────────────────────────│
  533. #!│3007.000  Release of CDD3 version 3007 templates                          │
  534. #!│3007.101  Repaired code to handle divide by zero on COUNT totals          │
  535. #!└──────────────────────────────────────────────────────────────────────────┘
  536. #!
  537. #FOR(%Formula)                                   #! FOR each formula
  538.   #IF(UPPER(%FormulaClass) = 'SUM')              #! IF a SUM formula
  539. %Formula = %Formula$                             #<! Move sum to variable
  540.   #ELSIF(UPPER(%FormulaClass) = 'AVG')           #! If Average formula
  541. IF %Formula#                                     #<! IF not divide by zero
  542.   %Formula = %Formula$/%Formula#                 #<! Move average to variable
  543. ELSE                                             #<! ELSE (IF not divide...)
  544.   %Formula = 0                                   #<! Clear variable
  545. END                                              #<! END (If not divide...)
  546.   #ELSIF(UPPER(%FormulaClass) = 'CNT')           #! If Count formula
  547. %Formula = %Formula#                             #<! Move count to variable
  548.   #ENDIF                                         #! ENDIF (FormulaClass...)
  549. #ENDFOR                                          #! ENDFOR (Formula...)
  550. DISPLAY()                                        #! And display the values
  551. #!***************************************************************************
  552. #GROUP(%ClearTotalValues)                        #! Clears Totals and screen
  553. #FOR(%Formula)                                   #! FOR each formula
  554.   #IF(UPPER(%FormulaClass) = 'SUM')              #! IF a SUM formula
  555. %Formula$ = 0                                    #<! Clear variable
  556.   #ELSIF(UPPER(%FormulaClass) = 'AVG')           #! If Average formula
  557. %Formula$ = 0                                    #<! Clear variable
  558. %Formula# = 0                                    #<! Clear variable
  559.   #ELSIF(UPPER(%FormulaClass) = 'CNT')           #! If Count formula
  560. %Formula# = 0                                    #<! Clear variable
  561.   #ENDIF                                         #! ENDIF (FormulaClass...)
  562. #ENDFOR                                          #! ENDFOR (Formula...)
  563. #!***************************************************************************
  564. #GROUP(%SetupKeyRangeFields)
  565. #SET(%RangeSaveFields,%Null)
  566. #SET(%RangeRestoreFields,%Null)
  567. #SET(%RangeRestoreAll,%Null)
  568. #SET(%BreakAfterGenerate,%Null)
  569. #IF(%KeyRangeField)                              #!If range limit prompt
  570.   #IF(%TotalExists)
  571. SAV::RangeValueChanged BYTE
  572.   #ENDIF
  573.   #FIX(%File,%Primary)                           #!Fix to procedure's primary
  574.   #FIX(%Key,%PrimaryKey)                         #!Fix to primary access key
  575.   #FOR(%KeyField)                                #!For all key components
  576.     #SET(%RangeSaveFields,(%RangeSaveFields+1))
  577.     #IF(upper(%KeyField) = upper(%KeyRangeField))#!If on the range field
  578.       #SET(%GenerateSaveValues,%Null)
  579.       #SET(%BreakAfterGenerate,'TRUE')
  580.       #IF((UPPER(%RangeValue)=UPPER(%KeyField))) #!If a range value is given
  581.         #SET(%GenerateSaveValues,'TRUE')
  582.       #ELSIF(%RangeValue)
  583.       #ELSE
  584.         #SET(%GenerateSaveValues,'TRUE')
  585.       #ENDIF
  586.     #ELSE
  587.       #SET(%GenerateSaveValues,'TRUE')
  588.     #ENDIF
  589.     #IF(%GenerateSaveValues)                     #!Do Nothing, otherwise
  590.       #SET(%RangeRestoreFields,(%RangeRestoreFields+1))
  591.       #FIX(%Field,%KeyField)                     #!Fix to component of key
  592.       #IF(%FieldType = 'GROUP')                  #!If component is a group
  593. SAV::%KeyField  LIKE(%KeyField),PRE(SAV)         #<!Save Range Limit Group
  594.       #ELSE                                      #!Else component NOT a group
  595. SAV::%KeyField  LIKE(%KeyField)                  #<!Save Range Limit Field
  596.       #ENDIF                                     #!EndIf component is a group
  597.     #ENDIF                                       #!EndIf %RangeValue not used
  598.     #IF(%BreakAfterGenerate)
  599.       #BREAK
  600.     #ENDIF
  601.   #ENDFOR                                        #!EndFor all key components
  602.   #IF(%RangeSaveFields=%RangeRestoreFields)
  603.     #SET(%RangeRestoreAll,'TRUE')
  604.   #ENDIF
  605. #ENDIF                                           #!EndIf range limit prompt
  606. #!***************************************************************************
  607. #GROUP(%SaveRangeFields)
  608. #IF(%KeyRangeField)                              #!If using range limits
  609.   #SET(%FieldsToSave,%Null)
  610.   #FOR(%KeyField)                                #!for all key components
  611.     #IF(%RangeRestoreAll OR (%FieldsToSave<%RangeRestoreFields))
  612. SAV::%KeyField = %KeyField                       #<! Save Key Field
  613.     #ENDIF
  614.     #SET(%FieldsToSave,(%FieldsToSave+1))
  615.     #IF(%FieldsToSave=%RangeRestoreFields)
  616.       #BREAK
  617.     #ENDIF
  618.   #ENDFOR                                        #!EndFor KeyFields
  619. #ENDIF                                           #!EndIF KeyRangeField
  620. #!***************************************************************************
  621. #GROUP(%RestoreRangeFields)
  622. #IF(%KeyRangeField)                              #!If using range limits
  623.   #SET(%FieldsToSave,%Null)
  624.   #FOR(%KeyField)                                #!for all key components
  625.     #IF(%RangeRestoreAll)
  626. %KeyField = SAV::%KeyField                       #<! Restore Key Field
  627.     #ELSE
  628.       #IF(%FieldsToSave<%RangeRestoreFields)
  629. %KeyField = SAV::%KeyField                       #<! Restore Key Field
  630.       #ELSE
  631. %KeyField = %RangeValue                          #<! Restore Range Value
  632.       #ENDIF
  633.     #ENDIF
  634.     #SET(%FieldsToSave,(%FieldsToSave+1))
  635.     #IF(%FieldsToSave=%RangeSaveFields)
  636.       #BREAK
  637.     #ENDIF
  638.   #ENDFOR                                        #!EndFor KeyFields
  639. #ENDIF                                           #!EndIF KeyRangeField
  640. #!***************************************************************************
  641. #GROUP(%CheckKeyRangeFields)
  642. #IF(%KeyRangeField)                              #!If using range limits
  643.   #INSERT(%RangeComparison)
  644.   PREVIOUS(%Primary)                             #<! Signal build
  645.   #INSERT(%ClearFileFields)                      #!Clear for screen fields
  646.   #INSERT(%RestoreRangeFields)                   #!Restore range values
  647.   CYCLE                                          #<! Cycle
  648. END                                              #<! End IF
  649. #ENDIF                                           #!EndIF KeyRangeField
  650. #!***************************************************************************
  651. #GROUP(%RangeComparison)
  652. #SET(%IfWritten,%Null)                           #!Clear the %Found flag
  653. #SET(%FieldsToSave,%Null)
  654. #FOR(%KeyField)                                  #!for all key components
  655.   #IF((%RangeRestoreAll OR (%FieldsToSave<%RangeRestoreFields)))
  656.     #IF(%KeyNoCase)
  657.       #SET(%Comparison,('(UPPER(' & %KeyField & ') <> UPPER(SAV::' & %KeyField & '))'))
  658.     #ELSE
  659.       #SET(%Comparison,(%KeyField & ' <> SAV::' & %KeyField ))
  660.     #ENDIF
  661.   #ELSE
  662.     #IF(%KeyNoCase)
  663.       #SET(%Comparison,('(UPPER(' & %KeyField & ') <> UPPER(' & %RangeValue & '))'))
  664.     #ELSE
  665.       #SET(%Comparison,(%KeyField & ' <> ' & %RangeValue))
  666.     #ENDIF
  667.   #ENDIF
  668.   #SET(%FieldsToSave,(%FieldsToSave+1))
  669.   #SET(%LastComparison,%Null)
  670.   #IF(%FieldsToSave=%RangeSaveFields)
  671.     #SET(%LastComparison,'TRUE')
  672.   #ENDIF
  673.   #IF(%LastComparison)
  674.     #IF(%IfWritten)
  675. OR %Comparison
  676.     #ELSE
  677. IF %Comparison
  678.       #SET(%IfWritten,'TRUE')
  679.     #ENDIF
  680.     #BREAK
  681.   #ELSE
  682.     #IF(%IfWritten)
  683. OR %Comparison |
  684.     #ELSE
  685. IF %Comparison |
  686.       #SET(%IfWritten,'TRUE')
  687.     #ENDIF
  688.   #ENDIF
  689. #ENDFOR                                         #!EndFor KeyFields
  690. #!***************************************************************************
  691. #GROUP(%EditCodeInsert)
  692. #IF(%UpdateProc)
  693. OF ?Insert                                       !Process the Insert Button
  694.   #IF(%ScreenFieldEdit)
  695.   %ScreenFieldEdit                             #<! Insert button Edit Routine
  696.   #ENDIF
  697.   #INSERT(%ClearFileFields)
  698.   #INSERT(%RestoreRangeFields)
  699.   SETKEYCODE(InsKey)                             ! Set action to Insert
  700.   Do UpdateProcedure                             ! Call the update procedure
  701.   SELECT(?List)                                  ! Reselect the List field
  702. #ENDIF
  703. #!***************************************************************************
  704. #GROUP(%EditCodeChange)
  705. #IF(%UpdateProc)
  706. OF ?Change                                       !Process the Change Button
  707.   #IF(%ScreenFieldEdit)
  708.   %ScreenFieldEdit                             #<! Change button Edit Routine
  709.   #ENDIF
  710.   SETKEYCODE(EnterKey)                           ! Set action to Change
  711.   Do UpdateProcedure                             ! Call the update procedure
  712.   SELECT(?List)                                  ! Reselect the List field
  713. #ENDIF
  714. #!***************************************************************************
  715. #GROUP(%EditCodeDelete)
  716. #IF(%UpdateProc)
  717. OF ?Delete                                       !Process the Delete Button
  718.   #IF(%ScreenFieldEdit)
  719.   %ScreenFieldEdit                             #<! Delete button Edit Routine
  720.   #ENDIF
  721.   SETKEYCODE(DelKey)                             ! Set action to Delete
  722.   DO UpdateProcedure                             ! Call the update procedure
  723.   SELECT(?List)                                  ! Reselect the List field
  724. #ENDIF
  725. #!***************************************************************************
  726. #GROUP(%EditCodeSelect)
  727. OF ?Select
  728.   #IF(%ScreenFieldEdit)
  729.   %ScreenFieldEdit                             #<! Exit button Edit Routine
  730.   #ENDIF
  731.   #IF(%KeyboardSelect)
  732.   SETKEYCODE(EnterKey)
  733.   #ENDIF
  734.   DO ProcedureReturn
  735. #!***************************************************************************
  736. #GROUP(%EditCodeExit)
  737. OF ?Exit                                         !Process the Exit button
  738.   #IF(%ScreenFieldEdit)
  739.     %ScreenFieldEdit                           #<! Exit button Edit Routine
  740.   #ENDIF
  741.   #IF(%KeyboardSelect)
  742.   IF CalledAsLookup
  743.     SETKEYCODE(EscKey)
  744.     GET(%Primary,0)
  745.     #FIX(%File,%Primary)
  746.     CLEAR(%FilePre:Record,0)
  747.   END
  748.   #ENDIF
  749.   DO ProcedureReturn
  750. #!***************************************************************************
  751. #GROUP(%EditCodeCancel)
  752. OF ?Cancel                                       !Process the Exit button
  753.   #IF(%ScreenFieldEdit)
  754.     %ScreenFieldEdit                           #<! Exit button Edit Routine
  755.   #ENDIF
  756.   #IF(%KeyboardSelect)
  757.   IF CalledAsLookup
  758.     SETKEYCODE(EscKey)
  759.     GET(%Primary,0)
  760.     #FIX(%File,%Primary)
  761.     CLEAR(%FilePre:Record,0)
  762.   END
  763.   #ENDIF
  764.   DO ProcedureReturn
  765. #!***************************************************************************
  766. #GROUP(%EditCodeList)
  767. #IF(%UpdateProc)
  768. OF ?List                                         !Process the list field
  769.   CASE KEYCODE()                                 ! Jump to keycode routine
  770.   #IF(%KeyboardInsert)
  771.   OF InsKey                                      ! For the insert key
  772.     #INSERT(%ClearFileFields)
  773.     #INSERT(%RestoreRangeFields)
  774.     UpdateMode = AddRecord
  775.     DO UpdateProcedure                           !  Call the update procedure
  776.   #ENDIF
  777.   #IF(%KeyboardDelete)
  778.   OF DelKey                                      ! For the delete key
  779.     UpdateMode = DeleteRecord
  780.     DO UpdateProcedure                           !  Call the update procedure
  781.   #ENDIF
  782.   #IF(%KeyboardSelect)
  783.   OF EnterKey
  784.   OROF MouseLeft2
  785.     #IF((UPPER(%ProcedureTemplate)='BROWSE' OR UPPER(%ProcedureTemplate)='SELECT'))
  786.     IF CalledAsLookup
  787.       SETKEYCODE(EnterKey)
  788.       DO ProcedureReturn
  789.     ELSE
  790.       UpdateMode = ChangeRecord
  791.       DO UpdateProcedure                         !  Call the update procedure
  792.     END
  793.     #ELSE
  794.     #INSERT(%LookupValidateCode)
  795.     #ENDIF
  796.   OF CtrlEnter
  797.     IF CalledAsLookup
  798.       UpdateMode = ChangeRecord
  799.       DO UpdateProcedure                         !  Call the update procedure
  800.     END
  801.   #ELSIF(%KeyboardChange)
  802.   OF EnterKey                                    ! Or the enter key
  803.   OROF MouseLeft2                                ! Or a double mouse click
  804.     UpdateMode = ChangeRecord
  805.     DO UpdateProcedure                           !  Call the update procedure
  806.   #ENDIF
  807.   END                                            ! End CASE
  808. #ELSIF(%KeyboardSelect)
  809. OF ?List                                         !Process the list field
  810.   #IF((UPPER(%ProcedureTemplate)='BROWSE' OR UPPER(%ProcedureTemplate)='SELECT'))
  811.   SETKEYCODE(EnterKey)
  812.   DO ProcedureReturn
  813.   #ELSE
  814.   #INSERT(%LookupValidateCode)
  815.   #ENDIF
  816. #ENDIF
  817. #!***************************************************************************
  818. #GROUP(%ClearRecordHigh)
  819. CLEAR(%FilePre:Record,1)
  820. #FIX(%Key,%PrimaryKey)
  821. #FOR(%KeyField)
  822.   #IF(%KeyFieldSequence='DESCENDING')
  823. CLEAR(%KeyField,-1)
  824.   #ENDIF
  825. #ENDFOR
  826. #!***************************************************************************
  827. #GROUP(%ClearRecordLow)
  828. CLEAR(%FilePre:Record,-1)
  829. #FIX(%Key,%PrimaryKey)
  830. #FOR(%KeyField)
  831.   #IF(%KeyFieldSequence='DESCENDING')
  832. CLEAR(%KeyField,1)
  833.   #ENDIF
  834. #ENDFOR
  835. #!***************************************************************************
  836. #GROUP(%LookupValidateCode)
  837. #IF(%ScreenFieldEdit)
  838. %ScreenFieldEdit                               #<!Select button Edit Routine
  839. #ENDIF
  840. #IF(%Pulldown)                                 #!If a Pulldown exists
  841. CLOSE(%Pulldown)                               #<!Close the Pulldown
  842. #ENDIF
  843. CLOSE(%Screen)                                   !Close the screen
  844. #IF((UPPER(%ProcedureTemplate)='VALIDATE'))
  845. SELECT(?)                                        !Select the same field
  846. #ENDIF
  847. CHANGE(SELECTED(),%LookupField)                  !Change to New Value
  848. PRESS(TabKey)                                    !  and a tab key
  849. DO ProcedureReturn                               !Return to caller
  850. #!
  851. #!***************************************************************************
  852. #GROUP(%LookupRecord)                           #!Group to Lookup a record
  853. #IF(%FromLookup)
  854.   #IF(%LookupPicture)
  855. DeformatString = CONTENTS(SELECTED())          #<! Fill the Key Value
  856.   #ELSE
  857. %LookupField = CONTENTS(SELECTED())            #<! Fill the Key Value
  858.   #ENDIF
  859. #ELSE
  860.   #IF(%LookupPicture)
  861. DeformatString = CONTENTS(FIELD())             #<! Fill the Key Value
  862.   #ELSE
  863. %LookupField = CONTENTS(FIELD())               #<! Fill the Key Value
  864.   #ENDIF
  865. #ENDIF
  866. #IF(%LookupPicture)
  867. %LookupField = DEFORMAT(DeformatString,%LookupPicture)
  868. #ENDIF
  869. GET(%Primary,%LookupKey)                       #<! Get the matching record
  870. IF ~ERRORCODE()                                #<! If found then return
  871.   DO ProcedureReturn
  872. END
  873. #!***************************************************************************
  874. #GROUP(%IsUpdateSuccessful)
  875. UpdateSuccessful = True
  876. #IF(%KeyboardDelete)
  877. IF POSITION(%Primary)
  878.   IF UpdateMode = DeleteRecord
  879.     UpdateSuccessful = False
  880.   END
  881.   #IF(%KeyboardChange OR %KeyboardInsert)
  882. ELSE
  883.     #IF(%KeyboardChange AND %KeyboardInsert)
  884.   IF UpdateMode = ChangeRecord OR UpdateMode = AddRecord
  885.     #ELSIF(%KeyboardChange)
  886.   IF UpdateMode = ChangeRecord
  887.     #ELSE
  888.   IF UpdateMode = AddRecord                      #!If Changing or Adding
  889.     #ENDIF
  890.     UpdateSuccessful = False
  891.   END
  892.   #ENDIF
  893. END
  894. #ELSIF(%KeyboardChange OR %KeyboardInsert)
  895. IF NOT POSITION(%Primary)
  896.   #IF(%KeyboardChange AND %KeyboardInsert)
  897.   IF UpdateMode = ChangeRecord OR UpdateMode = AddRecord
  898.   #ELSIF(%KeyboardChange)
  899.   IF UpdateMode = ChangeRecord
  900.   #ELSE
  901.   IF UpdateMode = AddRecord                      #!If Changing or Adding
  902.   #ENDIF
  903.     UpdateSuccessful = False
  904.   END
  905. END
  906. #ENDIF
  907. #!***************************************************************************
  908. #CHAIN('ChldGrps.tpx')
  909.