C4b - Copying Parent and Children 
Author Message
 C4b - Copying Parent and Children

I want to highlight a parent record in a browse then copy the parent
AND all of it children to another pair of files then delete the parent
and children from the original files.  

The child records are cascaded on delete in the relationship.
Deleting the parent from the browse deletes parent and children but I
need them copied first.

Is there a simple way or do I use the SET(file,key) and NEXT(file)
process?

Brian



Fri, 15 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children
Quote:

> Is there a simple way or do I use the SET(file,key) and NEXT(file)
> process?

Is there a simple way: Yes
Do you need to use set(key,key),Next(file): Yes unless abc.

From your question I assume you are using non-abc template. The general
type of code would be:
!open parent/child source/dest files
  ErrorFlag=false
  Logout(.1,destParent,destChild,SourceParent,Sourcechild)
  If Errorcode() then
    ErrorFlag=true
    exit !Return
  end  
  !Get SoruceParent record
  DestParent:Record :=: SourceParent:Record
  !fixup any autonumber keys, check any unique keys for dups
  add(DestParent)
  If errorcode()
    message('didnt work, Rollback')
    Errorflag=true
    Rollback()
    exit !return
  end  
  delete(SourceParent)
  Clear(ChildSourceFile:Record)
  !Prime Key fields of the child
  ChildlimitField = SomeLinkFieldFromParent
  Set(Key,Key)
  Loop
    Next(SourceChild)
    If errorcode() or ChildLImitField<>SomeLinkFieldFromParent then
break.
    !Copy SourceChild to dest child
    !fixup any linking fields
    add(destChild)
    If Errorcode()
      message('children never go where you tell them')
      ErrorFlag=true
      rollback
      Errorflag=true
      break
    end  
    Delete(SourceChild)
    If errorcode() then
      Message('Getting rid of a child is difficult')
      ErrorFlag=True
      Rollback()
      break
    end
    If not ErrorFlag then
      Commit()
      Message('On this rare ocassion you won over the children and
moved them.')
    end
    Exit !Return

Key thing here is using logout and commit so if something goes wrong
you and recover    

---
Jim Kane  - TeamTopSpeed
Productive Software Solutions
Can't Find that Message?
Get Organized, Get ForKeeps!
www.fkeeps.com



Fri, 15 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children

Thanks Jim,  I'll take a look at your solution and see what I can do
with it.

Brian



Quote:

>> Is there a simple way or do I use the SET(file,key) and NEXT(file)
>> process?



Fri, 15 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children
Quote:

> If in ABC, what is the different in this code (copying parent and
> children)?

>    Thansk in advance. I'm newer in C4ABC.

Several things. The main one in this case would be calling
PrimeRecord(1). The 1 is the suppressClear flag. That would allow you
to autonumber without saving the buffer. Also the Savebuffer() and
SaveFile() access methods would be handy when ever saving is needed.
---
Jim Kane  - TeamTopSpeed
Productive Software Solutions
Can't Find that Message?
Get Organized, Get ForKeeps!
www.fkeeps.com


Mon, 18 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children
Quote:

> But I still don't understand, would you mind to show me the code in ABC
> for copying parent and children record.

Really not much different from what I posted other than in the sequence:
  DestParent:Record :=: SourceParent:Record
  !fixup any autonumber keys, check any unique keys for dups
  add(DestParent)
is added in ABC as you could:
  DestParent:Record :=: SourceParent:Record
  Access:DestParent.PrimeRecord(1)
  Access:DestParent.Insert(DestParent)

That would take care of autonumbering, and insert with error checking
without all the additional coding requried in 2.003  

---
Jim Kane  - TeamTopSpeed
Productive Software Solutions
Can't Find that Message?
Get Organized, Get ForKeeps!
www.fkeeps.com



Wed, 20 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children
Thanks Jim,

   But I still don't understand, would you mind to show me the code in ABC
for copying parent and children record.

   Thanks

Terry Ho



Thu, 21 Jun 2001 03:00:00 GMT  
 C4b - Copying Parent and Children
Thanks Jim, I will try it.

Regards

Terry Ho
Jim Kane ???g??31 ...



Fri, 22 Jun 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Copying grand parent, parent, and child records

2. Copying autonumbered parent, child, grandchild records...

3. Copying Parent, Child, Grandchild....

4. Copying Parent, Child, Grandchild Records...

5. Copying Parent, Child, Grandchild autonumbered records...

6. Copying Parent child grandchild records

7. parent-child's child process interaction

8. C4b ABC - Find and highlight a certain record in a child browse

9. C4b: Error:ViewOpenError after returning from update child-record

10. SQL - adding child record from parent form

11. Parent-child browse scrolling problem

12. How To restrict child browse to selected parent browse record

 

 
Powered by phpBB® Forum Software