Looping Question

mgerbi

New Member
Ok, so I have to loop through a table multiple times in one master loop. I'm outputting a BOM from a part table and you have a part field (parent part number) and a material part number (current material Part). The material part can also be in the part field if it has sub-parts of its own and so on and so on. So I'm just wondering how I would loop the same table multiple times. Don't need anything too complex (although if you could give me perfomance pointers that would be great too). I just need the basic idea.

Logic - Should be dynamic so I'm guessing a Do Loop may suffice and just use a boolean to flag whether there are more subs or not, but I havn't figure that out yet and is not a big concern right now. I'm more interested in the looping structure.
Loop through table for parent part numbers
get Material part number and loop through Part table to get sub-parts of current sub-part.
If records, then loop through them and continue on looping again until there are no more loops
End.
End.

BOM Structure
Parent Part
Sub Part 1
Sub Sub Part 1
Sub Sub Part 2
Sub Sub Part 3
Sub Part 2
Sub Sub Part 1
Sub Sub Part 2
........
 

tamhas

ProgressTalk.com Sponsor
Not sure what your issue is ... standard for BoM is recursion ... with a check to prevent infinite loops.
 

mgerbi

New Member
Well the requirement is not important, so the basic question is how would you loop a table multiple times? Would you need to create temp tables?

For each Part
For First Part Where Part.PartMtlPart = Part.PartNum etc I don't think this would work, wouldn't you need to create a temp table to loop through, so you can maintain the parent loop?
For Each Part and so on....
 

tamhas

ProgressTalk.com Sponsor
The general technique for accessing the same table with pointers at more than one location is using buffers. But for BoM, the buffer has to be private to that which is recursing so that you can have as many copies as you want.

As Tom suggests ... not really clear what your problem is.
 

TomBascom

Curmudgeon
Iteration can always be expressed as recursion and vice versa.

As Tamhas indicates this problem is usually solved with recursion -- most people consider it cleaner and easier to understand.

But if you really want to iterate over a table multiple times you could do something like:
Code:
loop: do while true:
  for each whatever no-lock where somefield = somevalue:
    /* some logic */
    if something = "done" then leave loop.
  end.
end.
 

mgerbi

New Member
Well I'm just asking how to loop a table multiple times. That is the problem. I'm not a progress expert and while I know how I can accomplish this in other languages I was hoping that someone could show me how that could be done in a simple format. This is not something where I need someone to code the project for me or understand the db structure of the data. It's all in one table, that's it. So you mention pointers and buffers, what are those? Thank you for your reply.
 

TomBascom

Curmudgeon
Recursively you might do something like this:
Code:
procedure getParts:

  define input parameter depth     as integer no-undo.
  define input parameter partNum as integer no-undo.

  for each part no-lock where part.parent = partNum:
    display depth part.partNo.
    run getParts( depth + 1, part.partNo ).
  end.
  return.

end.

run getParts( 0, 42 ).  /* 42 is the part# we want to get a BOM for */
 

tamhas

ProgressTalk.com Sponsor
Try looking up DEFINE BUFFER. If you don't already know that, then you need someone to help you code it.
 

mgerbi

New Member
ok, thank you. I do have some of the OpenEdge manuals and some coding examples. I will look it up and hopefully I wont have any more questions, again thank you for your help.
 

tamhas

ProgressTalk.com Sponsor
Get part of the way there, *then* ask questions. The questions will make more sense and people will be much happier about answering.
 

tamhas

ProgressTalk.com Sponsor
Why not? Is this supposed to be a stand alone .p or an IP. If an IP, then not using a buffer is going to end up with the buffer scoped to the procedure, no?
 

TomBascom

Curmudgeon
Because I have no requirements -- I just started writing code...

That sample code has many flaws, poorly scoping the buffer is one of the smaller issues.
 

mrobles

Member
Why a buffer?
In 116407 "Recursive progrss query for parent-child tree structure". 26 Nov 2009
are 2 samples, with and without buffer. Both works.
 
Top