Problem with recursive procedure (buffer problem)

Beeb

Member
Dear All,

I have written the procedure below. What it should do: i goes over a table with a for each, containing parent lines, as well as, child lines. I know that this doesn't work due to a problem with the buffer but i don't know how to solve this without having to write a seperate procedure for each level. (a child can have a child as wel). In the table every record has a unique sequence numer (= numHeader), a level numer (= numLevel) and a parentnumber ( (= numParent) this contains the sequence number of the parent).

What happens:
The first parent is found. This parent has 2 children (and these children have no children). So, the parent is written in the xml file. (see /*1*/ in code) The 2 children are written (by running the same procedure again). (see /2*/ in code) The for each ends and progress goes toe the "end procedure". (/*3*/ in de code) Then it goes back to the line under the RUN createsubelements(INPUT buf_listmst.numheader). (/*4*/ in de code) And this is where it goes wrong. Here the buffer is no more.
What can i do to solve this? i'm really out of ideas!

PROCEDURE createsubelements:
DEFINE INPUT PARAMETER numParent$v AS INTEGER NO-UNDO.

FOR EACH buf_listmst NO-LOCK
WHERE buf_listmst.reccode = ""
AND buf_listmst.company = "020"
AND buf_listmst.doccde = "ActRepy"
AND buf_listmst.numParent = numParent$v:
IF CAN-FIND(FIRST buf2_Listmst NO-LOCK
WHERE buf2_Listmst.reccode = ""
AND buf2_Listmst.company = "020"
AND buf2_Listmst.doccde = "ActRepy"
AND buf2_Listmst.numparent = buf_listmst.numheader)
THEN DO:
lok = hSAXWriter:START-ELEMENT("Level" + STRING(buf_listmst.numlevel)). /*1*/

hSAXWriter:INSERT-ATTRIBUTE("Titel", buf_listmst.desctext).

RUN createsubelements(INPUT buf_listmst.numheader). /*2*/

lok = hSAXWriter:END-ELEMENT("Level" + STRING(buf_listmst.numlevel)). /*4*/
END. /*IF CAN-FIND(FIRST buf2_Listmst*/
ELSE hSAXWriter:WRITE-DATA-ELEMENT("level" + STRING(buf_listmst.numlevel), buf_listmst.desctext).
END. /*FOR EACH buf_listmst*/
END PROCEDURE. /*3*/

Thanks a lot fot all ideas or suggestions.

best regards,

Elise
 
What's the link between buf_Listmst.numparent and buf_listmst.numheader ?
If no link, its a problem.

Try
RUN createsubelements(INPUT buf2_Listmst.numparent ).

Regards.
 
numparent contains the numheader of the parent record (to link them ... to know which is the parent of the child. When numparent = 0, this is the Root)

Problem is .. the original query (parent level) is gone when i use the 'for each' again for a deeper level (child level).

What's the link between buf_Listmst.numparent and buf_listmst.numheader ?
If no link, its a problem.

Try
RUN createsubelements(INPUT buf2_Listmst.numparent ).

Regards.
 
put this inside of your procedure and it should work (i am guessing buf_listmst is a database table. If not, then define a buffer for the database table).
Code:
define buffer buf_listmst for buf_listmst.

It makes a new bf_listmst buffer to be scoped inside that procedure only for this iteration and it will be safe to query it without making it go out of scope elsewhere
 
It worked! Thanks a lot!!

put this inside of your procedure and it should work (i am guessing buf_listmst is a database table. If not, then define a buffer for the database table).
Code:
define buffer buf_listmst for buf_listmst.
It makes a new bf_listmst buffer to be scoped inside that procedure only for this iteration and it will be safe to query it without making it go out of scope elsewhere
 
Back
Top