home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / CLATPL.ZIP / CLARION6.TPX < prev    next >
Text File  |  1993-07-26  |  29KB  |  610 lines

  1. #!-------------------------------------------------------------------------------#!
  2. #!      CLARION6.TPX
  3. #!
  4. #!      Child     Update a batch of child records.
  5. #!
  6. #!------------------------------------------------------------------------------
  7. #!
  8. #!                           The Child Template
  9. #!
  10. #!   The Child template scrolls child records from a file on the screen
  11. #!   and allows updating the records on the same screen.  A parent
  12. #!   file must be identified and a valid parent record must be in memory
  13. #!   when this procedure is called.
  14. #!
  15. #!   The QUEUE will contain all children records for a particular
  16. #!   Parent record.  Changes to the children records are made to the
  17. #!   QUEUE and are only written to disk upon completion of the OK
  18. #!   button.  The update process is framed within a logged transaction.
  19. #!   The child file must use a file driver which supports transaction
  20. #!   processing in order to use this template.
  21. #!
  22. #!   The Child template's screen will contain a scrolling listbox
  23. #!   With Add, Change, Delete, Ok and Cancel pushbuttons and a fixed
  24. #!   field entry area with Save and Exit Buttons.
  25. #!
  26. #!   The Child template does not support autonumbering of keys.
  27. #!
  28. #!------------------------------------------------------------------------------
  29. #PROCEDURE(Child,'Update child records from a parent'),SCREEN,PULLDOWN
  30. #!
  31. #DISPLAY('')
  32. #PROMPT('First Upd&ate Field',FIELD),%FirstUpdateField
  33. #PROMPT('Parent F&ile',FILE),%ParentFile
  34. #PROMPT('Exit on &Null Parent',CHECK),%NullParentExit
  35. #PROMPT('Upd&ate Parent on OK',CHECK),%PutParent
  36. #INSERT(%SetChildSymbols)
  37. #PROTOTYPE('')
  38.  
  39. %Procedure       PROCEDURE
  40.  
  41. #INSERT(%CloseFilesFlags)
  42. #FIX(%File,%Primary)
  43. RecordQueue      QUEUE,PRE(SAV)
  44. Line              STRING(%ScreenFieldQueueSize) #<! Line to be scrolled
  45. SaveRecord        LIKE(%FilePre:Record),PRE(SAV)
  46. SkipRecord        BYTE
  47. #FIX(%Key,%PrimaryKey)
  48. #SET(%FirstField, %Null)
  49. #SET(%SortString,%Null)
  50. #FOR(%KeyField)
  51.   #FIX(%Field,%KeyField)
  52.   #IF(%FirstField = %Null)
  53.     #SET(%FirstField, %KeyField)
  54.     #SET(%FirstFieldSequence, %KeyFieldSequence)
  55.   #ENDIF
  56.   #IF(%KeyFieldSequence <> 'DESCENDING')
  57.     #SET(%SortString, (CLIP(LEFT(%SortString)) & ',+SAV:' & %FieldID))
  58.   #ELSE
  59.     #SET(%SortString, (CLIP(LEFT(%SortString)) & ',-SAV:' & %FieldID))
  60.   #ENDIF
  61. #ENDFOR
  62. RecordPosition    STRING(256)
  63. #FOR(%Field)
  64.   #IF(%FieldType = 'MEMO')
  65.     #SET(%MemoField,%FieldID)
  66. %FieldID          STRING(SIZE(%Field))         #<! Restore the Memos
  67.   #ENDIF
  68. #ENDFOR
  69.                  .                             #<!End Queue structure
  70.  
  71. FirstPage        BYTE(1)                         ! Page display variable
  72. EntryMode        BYTE(0)                         ! Toggles for entry mode
  73. ScrollMode       EQUATE(1)                       !   ScrollMode or
  74. UpdateMode       EQUATE(2)                       !   UpdateMode
  75. DRecs            SHORT                           ! Number of Child records
  76. QRecs            SHORT                           ! Number of QUEUE records
  77. I                BYTE                            ! QUEUE record pointer
  78. ChildAction      BYTE(0)                         ! Update mode
  79. NoMoreFields     BYTE(0)                         ! No more fields
  80. TransactionError BYTE(0)                         ! Transaction Error
  81. RecordEntryOne   BYTE(0)                         ! Starting record in QUEUE
  82.  
  83. %LocalData
  84. %ScreenStructure
  85. %PulldownStructure
  86. #EMBED('Data Section')
  87.  
  88.   CODE
  89.   #EMBED('Setup Procedure')
  90.   #INSERT(%NullParentCheck)                     #!Return if blank parent
  91.   #INSERT(%OpenPrimary)                         #!Open Primary file
  92.   #INSERT(%OpenSecondaryFiles)                  #!Open any secondary files
  93.   #INSERT(%HoldParentRecord)                    #!Hold the parent record
  94.   OPEN(SCREEN)                                   !Open the screen
  95.   #EMBED('Setup Screen')
  96.   #IF(%Pulldown)                                #!If a Pulldown exists
  97.   OPEN(%Pulldown)                              #<!Open the Pulldown
  98.   #ENDIF
  99.   DO EnterScrollMode                             !Select Scrolling mode
  100.   DO FillQueues                                  !Fill the Queues
  101.   DRecs = RECORDS(RecordQueue)                   !Save the number of children
  102.   #FIX(%File,%Primary)
  103.   DISPLAY                                        !Show the listbox
  104.   LOOP
  105.     #INSERT(%GenerateFormulas)                  #!Generate all formulas
  106.     #EMBED('Top of Accept Loop')
  107.     CASE SELECTED()                              !Jump to setup routine
  108.       OF NoMoreFields
  109.         SELECT(?Save)
  110.         DO EnterScrollMode                       ! Switch modes
  111.       #INSERT(%ScreenSetupRoutines)
  112.     END                                          !End CASE
  113.     ACCEPT                                       !Accept user input
  114.  
  115.     CASE KEYCODE()
  116.     #FOR(%HotKey)
  117.     OF %HotKey                                 #<!User defined HotKey
  118.       %HotKeyProc                              #<!HotKey Procedure
  119.     #ENDFOR
  120.     END
  121.  
  122.     IF EntryMode = ScrollMode                    !If processing the ScrollMode
  123.       IF RECORDS(RecordQueue) = %FixRows       #<!  If deleted last record.
  124.         DISABLE(?Change)                         !    Disable the change button
  125.         DISABLE(?Delete)                         !    Disable the delete button
  126.       END                                        !  End IF
  127.       CASE FIELD()                               ! Jump to edit routine
  128.       OF ?List                                   ! Process the List box
  129.         GET(RecordQueue,CHOICE())              #<! Get the Record Data
  130.         IF ERRORCODE() THEN CYCLE.               ! Cycle if no records
  131.     #FIX(%File,%Primary)
  132.         %FilePre:Record = SAV:SaveRecord       #<! Fill the fields
  133.     #FOR(%Field)
  134.       #IF(%FieldType = 'MEMO')
  135.         #SET(%MemoField,%FieldID)
  136.         %Field = SAV:%FieldID                  #<!  Restore the Memos
  137.       #ENDIF
  138.     #ENDFOR
  139.         #INSERT(%GetChildSecondary)
  140.         DISPLAY                                  ! and re-display
  141.         IF KEYCODE() = MouseLeft2                ! On Mouse double click
  142.           PRESS(EnterKey)                        !  Press the EnterKey
  143.         END                                      ! End IF
  144.       OF ?Insert                                 ! Process the Insert Button
  145.         #FIX(%File,%Primary)
  146.         ChildAction = AddRecord                  !  Set to adding a record
  147.         #INSERT(%ClearFileFields)              #<!  Clear the record for entry
  148.         #INSERT(%GetChildSecondary)
  149.         DO EnterUpdateMode                       ! Switch to update mode
  150.         #IF(%InitRoutine)                        #<!Field(s) initial value
  151.         DO InitializeFields                      !Initial values from dictionary
  152.         #ENDIF
  153.       OF ?Change                                 ! Process the Change Button
  154.         ChildAction = ChangeRecord               !  Set to Changing a record
  155.         DO EnterUpdateMode                       !  Switch modes
  156.       OF ?Delete                                 ! Process the Delete Button
  157.         ChildAction = DeleteRecord               !  Set to Deleting a record
  158.         DELETE(RecordQueue)                      !  Delete Record Queue Entry
  159.         #INSERT(%ClearFileFields)              #<!  Clear the record for entry
  160.         DISPLAY                                  !  Redisplay the list box
  161.         IF RECORDS(RecordQueue) = %FixRows     #<!  If deleted last record.
  162.           DISABLE(?Change)                       !    Disable the change button
  163.           DISABLE(?Delete)                       !    Disable the delete button
  164.           SELECT(?Insert)                        !    Select the insert button
  165.         ELSE                                     !  Else
  166.           SELECT(?List)                          !    Select the list box
  167.         END                                      !  End IF
  168.         ChildAction = 0                          !  Reset the Action
  169.         CYCLE                                    !  Cycle to accept input
  170.       OF ?Ok                                     ! Process the Ok Button
  171.         QRecs = RECORDS(RecordQueue)             !  Save the queue record count
  172.   #FIX(%File, %Primary)
  173.         #INSERT(%ClearFileFields)              #<!Clear the record buffer
  174.         TransactionError = 0                     !Clear Transaction error
  175.   #FIX(%File, %ParentFile)
  176.   #FIX(%Relation,%Primary)
  177.   #IF(%RelationType = '1:MANY')
  178.     #FOR(%RelationKeyField)
  179.       #IF(%RelationKeyFieldLink)
  180.         %RelationKeyField = %RelationKeyFieldLink #<!Assign linking field value
  181.       #ENDIF
  182.     #ENDFOR
  183.   #ENDIF
  184.         SET(%RelationKey,%RelationKey)         #<!Set to the matching record
  185.         LOGOUT(2,%Primary)                     #<!Enable transaction logging
  186.         IF ERRORCODE() = BadTranErr              !If transaction error occurs
  187.           GLO:Message1 = 'Unable to save your changes at this time.'
  188.           GLO:Message2 = 'Another user may be saving a transaction.'
  189.           GLO:Message3 = 'Try again.'
  190.           ShowWarning                            ! Show the transaction error
  191.           SELECT(?Ok)                            ! Reselect the Ok button
  192.           CYCLE                                  ! Cycle to ACCEPT input
  193.         END                                      !End IF
  194.         #INSERT(%UpdateChildRecords)
  195.         IF TransactionError                      !If transaction error occurs
  196.           GLO:Message1 = 'Unable to save your changes at this time.'
  197.           GLO:Message2 = 'Error: '& ERROR()
  198.           GLO:Message3 = 'Make any necessary changes and try again.'
  199.           ShowWarning                            ! Show the transaction error
  200.           ROLLBACK                               ! Rollback the changes.
  201.           SELECT(?List,I)                        ! Reselect the List box
  202.           PRESS(EnterKey)                        ! Setup to change record
  203.           CYCLE                                  ! Cycle to ACCEPT input
  204.         ELSE                                     !Else
  205.           COMMIT                                 ! Commit the changes to disk
  206.         END                                      !End IF
  207.         #INSERT(%PutParentFile)
  208.         BREAK                                    ! Break to Return to Caller
  209.       OF ?Cancel                                 !Process the Cancel Button
  210.         BREAK                                    ! Break to Return to Caller
  211.       END                                        !End CASE
  212.     ELSE                                         ! Else if update mode
  213.       #INSERT(%GetChildSecondary)
  214.       DISPLAY                                    ! Display the new record
  215.       CASE FIELD()                               !
  216.       #INSERT(%ChildEditRoutines)
  217.       OF ?Save                                   ! Process the Save Button
  218.         CASE ChildAction                         ! Adding or Changing?
  219.         OF AddRecord                             ! When adding a new record.
  220.           #INSERT(%FillQueueFields)
  221.           ADD(RecordQueue %SortString)         #<! Add to the sorted queue
  222.           ChildAction = 0                        ! Reset the Action value
  223.         OF ChangeRecord                          ! When changing a record
  224.           #INSERT(%FillQueueFields)
  225.           PUT(RecordQueue %SortString)         #<! Add to the queue
  226.           ChildAction = 0                        ! Reset the Action value
  227.         END                                      ! Case
  228.         SELECT(1)                                !Start with the first field
  229.         SELECT                                   !and cycle non-stop
  230.         CYCLE                                    !restart main process loop
  231.       OF ?Exit                                   ! Process the Exit Button
  232.         DO EnterScrollMode                       ! Switch modes
  233.       END                                        !  End CASE
  234.     END                                          ! End IF
  235.     CASE FIELD()
  236.   #FOR(%PulldownField)
  237.     #IF(%PulldownFieldProc <> %NULL)
  238.     OF %PulldownField                          #<!For a selected menu item
  239.   %PulldownFieldProc                           #<!Call the procedure
  240.     #ENDIF
  241.   #ENDFOR
  242.     END                                          !End CASE for Pulldowns
  243.   END                                            !End LOOP
  244.   #EMBED('Prior to Return')
  245.   #IF(%Pulldown)                                #!If a Pulldown exists
  246.   CLOSE(%Pulldown)                             #<!Open the Pulldown
  247.   #ENDIF
  248.   #IF(%SharedFiles)
  249.   RELEASE(%ParentFile)                         #<!Release held parent record
  250.   #ENDIF
  251.   FREE(RecordQueue)                              !Free the QUEUE memory
  252.   #INSERT(%CloseOpenedFiles)
  253.  
  254. #EMBED('End of Procedure')
  255.  
  256. #INSERT(%ChildInitFields)
  257.  
  258. EnterScrollMode ROUTINE                          !Switch screen mode routine
  259.  
  260.   DISABLE(1,FIELDS())                            ! Disable listbox and buttons
  261.   ENABLE(?List)                                  ! Enable the list box
  262.   ENABLE(?Insert, ?Cancel)                       ! Enable the Buttons
  263.   IF RECORDS(RecordQueue) = %FixRows           #<!  If no records to scroll
  264.     IF EntryMode                                 !   If not before FillQueues
  265.       DISABLE(?Change)                           !    Disable the change button
  266.       DISABLE(?Delete)                           !    Disable the delete button
  267.       SELECT(?Insert)                            !    Select the insert button
  268.     END                                          !   End IF
  269.   ELSE                                           !  Else
  270.     SELECT(?List)                                !    Select the list box
  271.   END                                            !  End IF
  272.   EntryMode = ScrollMode                         ! Switch to scroll mode
  273.   #EMBED('Enter Scroll Mode Routine')
  274.  
  275. EnterUpdateMode ROUTINE
  276.  
  277.   EntryMode = UpdateMode                         !Switch screen mode routine
  278.   DISABLE(1,FIELDS())                            ! Disable listbox and buttons
  279.   ENABLE(?%FirstUpdateField, ?Exit)            #<! Enable the entry fields
  280.   Select(?%FirstUpdateField)                   #<! Select the first entry field
  281.   #EMBED('Enter Update Mode Routine')
  282.  
  283. FillQueues ROUTINE
  284.  
  285.   FREE(RecordQueue)                            #<!Clear the Record queue
  286.   #SET(%FixRows, '0')
  287.   #SET(%ListField,'?List')
  288.   #FIX(%ScreenField,%ListField)
  289.   #FOR(%ScreenFieldFix)
  290.     #SET(%FixRows, (%FixRows + 1))
  291.   SAV:Line = %ScreenFieldFix                   #<!Add list box fixed fields
  292.   ADD(RecordQueue %SortString)                 #<! Add to the sorted queue
  293.   DISPLAY(?List)                               #<!Blank the listbox
  294.   #ENDFOR
  295.   #FIX(%File, %Primary)
  296.   #INSERT(%ClearFileFields)                    #<!Clear the Child record
  297.   #FIX(%File, %ParentFile)
  298.   #FIX(%Relation,%Primary)
  299.   #IF(%RelationType = '1:MANY')
  300.     #FOR(%RelationKeyField)
  301.       #IF(%RelationKeyFieldLink)
  302.   %RelationKeyField = %RelationKeyFieldLink    #<!Assign linking field value
  303.       #ENDIF
  304.     #ENDFOR
  305.   #ENDIF
  306.   SET(%RelationKey,%RelationKey)               #<!Set to keyed order
  307.   LOOP                                           !Get all selected records
  308.     NEXT(%Primary)                             #<!Get the next record.
  309.     IF ERRORCODE() THEN BREAK.                   !Quit if an error occurs
  310.     #INSERT(%GetChildSecondary)
  311.   #FIX(%File,%Primary)
  312.   #FIX(%Key,%PrimaryKey)
  313.   #IF(%ChildRelationField)                      #!If using a Range
  314.     IF %ChildRelationField <> %ParentRelationField #<!If not in Range
  315.       IF RECORDS(RecordQueue) <> %FixRows      #<!  If records were added
  316.     #SET(%FirstNonFixedRecord,(%FixRows+1))
  317.         GET(RecordQueue,%FirstNonFixedRecord)  #<!   Get first non-fixed row
  318.         RESET(%RelationKey,SAV:RecordPosition) #<!  Reset to the last entry
  319.         NEXT(%Primary)                         #<!  Reread the last entry
  320.         BREAK                                  #<!  Break out of the Loop
  321.       ELSE                                       ! Else no children found
  322.         #INSERT(%ClearFileFields)              #<!  Clear the record
  323.         BREAK                                  #<!  Break out of the Loop
  324.       END                                        ! End IF
  325.     END                                          !End IF
  326.   #ENDIF
  327.   #IF(%RecordFilterFormula)
  328.     IF ~(%RecordFilterFormula)                 #<!If Filter condition not met
  329.       CYCLE                                      ! Try another record
  330.     END                                          !End IF
  331.   #ELSE
  332.     #FOR(%Formula)
  333.       #IF(UPPER(%FormulaClass) = 'FILTER')
  334.         #IF(%FormulaType <> 'COMPUTED')
  335.     IF ~(%FormulaCondition)                    #<!If Filter condition not met
  336.       CYCLE                                      ! Try another record
  337.     END                                          !End IF
  338.         #ELSE
  339.     IF ~(%FormulaComputation)                  #<!If Filter condition not met
  340.       CYCLE                                      ! Try another record
  341.     END                                          !End IF
  342.         #ENDIF
  343.       #ENDIF
  344.     #ENDFOR
  345.   #ENDIF
  346.   #FOR(%Formula)
  347.     #IF(UPPER(%FormulaClass) = 'LIST')
  348.     #INSERT(%GenerateFormula)                   #!Generate LIST formulas
  349.     #ENDIF
  350.   #ENDFOR
  351.   #FIX(%File,%Primary)
  352.   #SET(%ListField,'?LIST')
  353.   #FIX(%ScreenField,%ListField)
  354.     SAV:Line = %ScreenFieldExpression          #<! Fill the DisplayQueue line
  355.     SAV:SaveRecord = %FilePre:Record             ! Save the record data
  356.     SAV:RecordPosition = POSITION(%RelationKey)  ! Save the record position
  357.   #FOR(%Field)
  358.     #IF(%FieldType = 'MEMO')
  359.       #SET(%MemoField,%FieldID)
  360.     SAV:%FieldID = %Field                      #<!  Restore the Memos
  361.     #ENDIF
  362.   #ENDFOR
  363.     ADD(RecordQueue %SortString)               #<! Add to the sorted queue
  364.     IF ERRORCODE() THEN BREAK.                   ! Quit out if error
  365.     IF FirstPage                                 ! If page 1
  366.       IF RECORDS(RecordQueue) = ROWS(?List)      ! If we have a full screen
  367.         FirstPage = 0                            !   turn off the page flag
  368.       END                                        !  End IF
  369.       DISPLAY(?List)                             !  Display page 1
  370.     END                                          ! End IF
  371.   END                                            !End LOOP
  372.   IF RECORDS(RecordQueue) = %FixRows           #<!If the queue is empty
  373.     IF RECORDS(%Primary)                       #<! If file is not empty
  374.       IF ?List <> %FirstEntryField             #<!  And list is not first
  375.         SELECT(1)                                !   Select the first field
  376.       ELSE                                       !  Else
  377.         DISABLE(1,FIELDS())                      !   Disable all fields
  378.         ENABLE(?Insert)                          !   Enable the Insert and
  379.         ENABLE(?Cancel)                          !   the cancel buttons
  380.         SELECT(?Insert)                          !   Select the Insert Button
  381.       END                                        !  End IF
  382.     ELSE                                         ! Else the file is empty
  383.       DISABLE(1,FIELDS())                        !   Disable all fields
  384.       ENABLE(?Insert)                            !   Enable the Insert and
  385.       ENABLE(?Cancel)                            !   the cancel buttons
  386.       SELECT(?Insert)                            !   Select the Insert Button
  387.     END                                          ! End IF
  388.   ELSE                                           !Else records exist
  389.     GET(RecordQueue,%FirstNonFixedRecord)      #<! Get first non-fixed row
  390.     RESET(%RelationKey,SAV:RecordPosition)     #<! Reset to the last entry
  391.     NEXT(%Primary)                             #<! Reread the last entry
  392.     #INSERT(%GetChildSecondary)
  393.   END                                            !End IF
  394.   DISPLAY
  395. #!
  396. #!***************************************************************************
  397. #GROUP(%SetChildSymbols)
  398. #IF(%ParentFile = %Null)
  399.   #SET(%ErrorMessage, (%Procedure & ' ERROR: Parent File is required.'))
  400.   #ERROR(%ErrorMessage)
  401. #ENDIF
  402. #SET(%MemoExists,%Null)
  403. #FIX(%File,%Primary)
  404. #FIX(%File,%Primary)
  405. #FIX(%Relation,%ParentFile)
  406. #IF(%RelationType = 'MANY:1')
  407.   #FOR(%RelationKeyField)
  408.     #SET(%ParentRelationField, %RelationKeyField)
  409.     #SET(%ChildRelationField, %RelationKeyFieldLink)
  410.     #BREAK
  411.   #ENDFOR
  412. #ENDIF
  413. #SET(%ScreenFldSetupExists,%Null)
  414. #FIX(%File,%Primary)
  415. #FOR(%Field)
  416.   #IF(%FieldType = 'MEMO')
  417.     #SET(%MemoExists,'Yes')
  418.     #BREAK
  419.   #ENDIF
  420. #ENDFOR
  421. #SET(%FixRows, '0')
  422. #SET(%ListField,'?List')
  423. #FIX(%ScreenField,%ListField)
  424. #FOR(%ScreenFieldFix)
  425.   #SET(%FixRows, (%FixRows + 1))
  426. #ENDFOR
  427. #FOR(%ScreenField)
  428.   #IF(%ScreenFieldSetup)
  429.     #SET(%ScreenFldSetupExists,'YES')
  430.     #BREAK
  431.   #ENDIF
  432. #ENDFOR
  433. #SET(%FirstEntryField,%Null)
  434. #FOR(%ScreenField)
  435.   #IF(%ScreenFieldSkip = %Null)
  436.     #SET(%FirstEntryField,%ScreenField)
  437.     #BREAK
  438.   #ENDIF
  439. #ENDFOR
  440. #FOR(%Field)
  441.   #IF(%FieldInitial <> %NULL)
  442.     #SET(%InitRoutine,'TRUE')
  443.     #BREAK
  444.   #ENDIF
  445. #ENDFOR
  446. #!***************************************************************************
  447. #GROUP(%GetChildSecondary)
  448.   #FOR(%Secondary)                             #! for fields in the list box
  449.     #IF(%Secondary <> %ParentFile)
  450.       #IF(%SecondaryType = 'MANY:1')           #!Check for lookup files
  451.         #FIX(%File,%SecondaryTo)
  452.         #FIX(%Relation,%Secondary)
  453.         #FOR(%RelationKeyField)
  454. IF %RelationKeyField <> %RelationKeyFieldLink  #<!If Link fields don't match
  455.   %RelationKeyField = %RelationKeyFieldLink    #<! Assign linking field value
  456.         #ENDFOR
  457.   GET(%Secondary,%RelationKey)                 #<! Lookup record
  458.         #FIX(%File,%Secondary)
  459.   IF ERRORCODE()                               #<! Clear record if unsuccessful
  460.     #INSERT(%ClearFileFields)
  461.   END
  462. END                                            #<!End IF
  463.       #ENDIF
  464.     #ENDIF
  465.   #ENDFOR
  466. #!***************************************************************************
  467. #GROUP(%ChildInitFields)
  468. #IF(%InitRoutine = 'TRUE')
  469. InitializeFields ROUTINE
  470. #FOR(%Field)
  471. #IF(%FieldInitial <> %NULL)
  472.   %Field = %FieldInitial
  473. #ENDIF
  474. #ENDFOR
  475. #ENDIF
  476. #!***************************************************************************
  477. #GROUP(%ChildEditRoutines)
  478.   #FOR(%ScreenField)
  479.     #IF(%ScreenFieldUse <> '?Ok')
  480.       #IF(%ScreenFieldUse <> '?Cancel')
  481.       #INSERT(%RangeLookupCheck)
  482.         #IF(%ScreenFieldEdit OR %RangeCodeOn OR %FieldLookupOn)
  483. OF %ScreenField
  484.           #IF(%FieldLookupOn)
  485.   #INSERT(%FieldLookupCode)
  486.           #ENDIF
  487.           #IF(%RangeCodeOn)
  488.   #INSERT(%RangeCode)
  489.           #ENDIF
  490.           #IF(%ScreenFieldEdit)
  491.   %ScreenFieldEdit
  492.           #ENDIF
  493.         #ENDIF
  494.       #ENDIF
  495.     #ENDIF
  496.   #ENDFOR
  497.   #FOR(%PulldownField)
  498.     #IF(%PulldownFieldProc <> %NULL)
  499. OF %PulldownField                              #<! For a selected menu item
  500.   %PulldownFieldProc                           #<! Call the procedure
  501.     #ENDIF
  502.   #ENDFOR
  503. #!***************************************************************************
  504. #GROUP(%NullParentCheck)
  505.   #IF(%NullParentExit)
  506.     #FIX(%File,%ParentFile)
  507. IF %FilePre:RECORD = ''                        #<!If Parent record is blank
  508.   RETURN                                       #<! Return to the caller
  509. END                                            #<!End IF
  510.     #FIX(%File,%Primary)
  511.   #ENDIF
  512. #!***************************************************************************
  513. #GROUP(%HoldParentRecord)
  514.   #IF(%SharedFiles)
  515. HOLD(%ParentFile,5)                            #<! When sharing the files
  516. IF ERRORCODE() = isLockedErr                   #<! Hold the parent record.
  517.   GLO:Message1 = 'This %ParentFile Entry is being updated'
  518.   GLO:Message2 = 'by another user.    Try again later. '
  519.   GLO:Message3 = ''                            #<!  Show an error if another
  520.   ShowWarning                                  #<!  user has the parent held
  521.   RETURN                                       #<!  and exit
  522. END                                            #<! End IF
  523.   #ENDIF
  524. #!***************************************************************************
  525. #GROUP(%UpdateChildRecords)
  526. #FIX(%File,%Primary)
  527. LOOP                                           #<!For child records
  528.   NEXT(%Primary)                               #<! Get the next record
  529.   IF ERRORCODE()                               #<! IF Reading past EOF()
  530.     BREAK                                      #<!  BREAK out of the LOOP
  531.   ELSIF %ChildRelationField <> %ParentRelationField #<! or no child records
  532.     BREAK                                      #<!  BREAK out of the LOOP
  533.   END                                          #<! End IF
  534.   SAV:SaveRecord = %FilePre:RECORD             #<! Fill the Queue
  535.   GET(RecordQueue %SortString)                 #<! Get the matching QUEUE
  536.   IF ERRORCODE()                               #<! If Not found
  537.     DELETE(%Primary)                           #<!  Delete the file entry
  538.   ELSIF SAV:SaveRecord <> %FilePre:RECORD      #<! Else if Records don't match
  539.     DELETE(%Primary)                           #<!  Delete the file entry
  540. #FOR(%Field)
  541.   #IF(%FieldType = 'MEMO')
  542.   ELSIF SAV:%FieldID <> %Field                 #<! Else if Records don't match
  543.     DELETE(%Primary)                           #<!  Delete the file entry
  544.   #ENDIF
  545. #ENDFOR
  546.   ELSE                                         #<! Else
  547.     SAV:SkipRecord = 1                         #<!  Mark QUEUE record as skip
  548.     PUT(RecordQueue %SortString)               #<!  and PUT() back in QUEUE
  549.   END                                          #<! End IF
  550.   IF ERRORCODE()                               #<! If error on delete or PUT
  551.     TransactionError = ERRORCODE()             #<!  Save the error code
  552.     BREAK                                      #<!  and BREAK out of the loop
  553.   END                                          #<! End IF
  554. END                                            #<!End LOOP
  555. RecordEntryOne = %FixRows + 1                  #<!
  556. LOOP I = RecordEntryOne TO QRecs               #<! Loop through Queue
  557.   GET(RecordQueue,I)                           #<!  Get a QUEUE Element
  558.   IF ERRORCODE() THEN STOP(ERROR()).           #<!  Stop if Unexpected error
  559.   IF SAV:SkipRecord THEN CYCLE.                #<!  Skip unmodified records
  560.   %FilePre:RECORD = SAV:SaveRecord             #<!  Restore the Record
  561.   #FOR(%Field)
  562.     #IF(%FieldType = 'MEMO')
  563.       #SET(%MemoField,%FieldID)
  564.   %Field = SAV:%FieldID                        #<!  Restore the Memos
  565.     #ENDIF
  566.   #ENDFOR
  567.   ADD(%Primary)                                #<!  Add to the file.
  568.   IF ERRORCODE()                               #<!  If error during ADD
  569.     TransactionError = ERRORCODE()             #<!    Save the error
  570.     BREAK                                      #<!    and break from the loop
  571.   END                                          #<!  End IF
  572. END                                            #<! End LOOP
  573. #!***************************************************************************
  574. #GROUP(%PutParentFile)
  575.   #IF(%SharedFiles)
  576.     #IF(%PutParent)
  577. PUT(%ParentFile)                               #<!Put the parent record
  578. IF ERRORCODE()
  579.   GLO:Message1 = 'Unable to save %ParentFile Entry.'
  580.   GLO:Message2 = 'Error: '& ERROR()
  581.   GLO:Message3 = 'The entry has not been saved.' #<!Show an error if another
  582.   ShowWarning                                  #<!Show the transaction error
  583. END
  584.     #ELSE
  585. RELEASE(%ParentFile)                           #<!Release the held record
  586.     #ENDIF
  587.   #ENDIF
  588. #!***************************************************************************
  589. #GROUP(%FillQueueFields)
  590. #FIX(%File, %ParentFile)
  591. #FIX(%Relation,%Primary)
  592. #IF(%RelationType = '1:MANY')
  593.   #FOR(%RelationKeyField)
  594.     #IF(%RelationKeyFieldLink)
  595. %RelationKeyField = %RelationKeyFieldLink      #<!Assign linking field value
  596.     #ENDIF
  597.   #ENDFOR
  598. #ENDIF
  599. SAV:Line = %ScreenFieldExpression              #<! Fill the DisplayQueue line
  600. #FIX(%File, %Primary)
  601. SAV:SaveRecord = %FilePre:RECORD               #<! Fill the QUEUE Record
  602. #FOR(%Field)
  603.   #IF(%FieldType = 'MEMO')
  604.   #SET(%MemoField,%FieldID)
  605.   SAV:%FieldID = %Field                        #<! Fill the QUEUE Memo
  606.   #ENDIF
  607. #ENDFOR
  608. #!***************************************************************************
  609. #CHAIN('CLARION7.TPX')
  610.