TomBascom
Curmudgeon
Can I put in the same procedure two DO FOR <tablename> TRANSACTION with the same Table Name ?
No, you should not do that. That misses the whole point of what I just said.
Can I put in the same procedure two DO FOR <tablename> TRANSACTION with the same Table Name ?
And also I understand that I lack of knowledge in the good way of programming with progress. Do you know where I can find a good "tuto" where all the concept and idea are explained?
Of courser quite a simple way I will try itIF NOT AVAILABLE( bCustomer ) then ...
No, you should not do that. That misses the whole point of what I just said.
The gold standard for such things is, sadly, long out of print. But if you can find a copy of "Programmers Progress" that would be perfect.
https://www.amazon.com/Programmers-Progress-guide-progress-language/dp/B0006P8X5S
Ok so if I devide my 1 procedure into two procedure to do each updates is this better ?
DEFINE BUFFER updCustomer FOR Customer. /* Buffer for update */
DEFINE BUFFER bcCustomer FOR Customer. /* Buffer for reading next rows in the tables */
1 DO FOR updCustomer TRANSACTION :
1 FIND updCustomer WHERE ROWID(updCustomer) = ROWID(Customer) EXCLUSIVE-LOCK NO-WAIT NO-ERROR.
1 IF AVAILABLE updCustomer THEN
1 updCustomer.validate = true.
1 END.
IF Customer.international = TRUE THEN DO:
FIND bcCustomer WHERE bcCustomer.country = Customer.country
AND bcCustomer.position = Customer.position + 1 NO-LOCK NO-ERROR.
IF AVAILABLE bcCustomer AND some other condition THEN DO:
2 DO FOR updCustomer TRANSACTION :
2 FIND updCustomer WHERE ROWID(updCustomer) = ROWID(bcCustomer) EXCLUSIVE-LOCK NO-WAIT NO-ERROR.
2 IF AVAILABLE bcCustomer THEN DO:
2 updCustomer.validate = true.
2 END.
2 END.
END.
END.
procedure updateCustomer_validate:
define input parameter customerRowid as rowid no-undo.
define input parameter custValidate as logical no-undo.
define buffer updCustomer for customer.
define variable
do for updCustomer transaction:
find updCustomer exclusive-lock where rowid( updCustomer ) = customerRowid no-wait no-error.
if available( updCustomer ) then
assign
updCustomer.validate = custValidate
.
else
do:
/* perhaps handle available() = false... */
end.
return.
end.
/* at some point FIND Customer must have occurred... */
run updateCustomer( rowid( Customer ), true ).
if customer.international = true then
do:
find Customer no-lock where Customer.country = Customer.country
and Customer.position = Customer.position + 1 no-error.
if available( Customer ) and ( some other condition ) then
do:
run updateCustomer( rowid( Customer ), true ).
end.
end.
DO:
DEFINE VARIABLE cDero AS CHARACTER NO-UNDO. /* Liste of user in case of proxy signature */
DEFINE VARIABLE iNextSig AS INTEGER NO-UNDO. /* Number of the next signatory guy */
DEFINE BUFFER updDAWFLW FOR DAWFLW. /* Buffer for update */
DEFINE BUFFER bcDAWFLW FOR DAWFLW. /* Because the table is directly link to a Browse I need a buffer for reading other line */
/* We applied the signature */
IF DAWFLW.orisig <> c-uticod THEN /* If proxy signature we build a list of usercod to mail them at the end */
cDero = DAWFLW.orisig + ",":U + c-uticod.
DO FOR updDAWFLW TRANSACTION :
FIND updDAWFLW WHERE ROWID(updDAWFLW) = ROWID(DAWFLW) EXCLUSIVE-LOCK NO-WAIT NO-ERROR.
ASSIGN
updDAWFLW.utisig = c-uticod
updDAWFLW.datsig = TODAY
updDAWFLW.hmssig = STRING(TIME, "HH:MM:SS")
updDAWFLW.stasig = 1
updDAWFLW.remarq = FI-Remarq:SCREEN-VALUE. /* Info write done by the signatory guy */
END.
/* We search for the type of buying request */
FIND FIRST VAFDAI WHERE VAFDAI.danum = SACDPE.acddemnum NO-LOCK NO-ERROR.
IF NOT AVAILABLE VAFDAI THEN DO: /* standard buying request: 3 signatory */
IF DAWFLW.numsig < 3 THEN DO: /* the signatory is not the last of the list */
FIND bcDAWFLW WHERE bcDAWFLW.danum = DAWFLW.danum
AND bcDAWFLW.numsig = DAWFLW.numsig + 1 NO-LOCK NO-ERROR.
/* Send email to the next seignatory */
RUN 2-prc-envoiemail("nextsig":u,bcDAWFLW.orisig).
END.
ELSE DO: /* Last signatory */
RUN 3-prc-DaToCde. /* procedure to transform the request into an order */
/* Send email to the requester */
RUN 2-prc-envoiemail("accept":u,SACDPE.dpeutidem).
END.
END.
ELSE DO: /* buying request on project: 4 signatory */
IF DAWFLW.numsig < 4 THEN DO:
FIND bcDAWFLW WHERE bcDAWFLW.danum = DAWFLW.danum
AND bcDAWFLW.numsig = DAWFLW.numsig + 1 NO-LOCK NO-ERROR.
IF AVAILABLE bcDAWFLW AND bcDAWFLW.cansig AND bcDAWFLW.numsig = 2
AND (bcDAWFLW.orisig = c-uticod OR bcDAWFLW.orisig = SACDPE.dpeutidem) THEN DO:
DO FOR updDAWFLW TRANSACTION :
FIND updDAWFLW WHERE ROWID(updDAWFLW) = ROWID(bcDAWFLW) NO-ERROR.
ASSIGN
updDAWFLW.utisig = updDAWFLW.orisig
updDAWFLW.datsig = TODAY
updDAWFLW.hmssig = STRING(TIME, "HH:MM:SS")
updDAWFLW.stasig = 1
updDAWFLW.remarq = ""
updDAWFLW.autsig = TRUE.
END.
/* Mail to inform the request or the actual user that is approval is automaticly applied for the next signature request on this buying demand */
RUN 2-prc-envoiemail("autsig":u, bcDAWFLW.orisig).
FIND bcDAWFLW WHERE bcDAWFLW.danum = DAWFLW.danum
AND bcDAWFLW.numsig = DAWFLW.numsig + 2 NO-LOCK NO-ERROR.
/* Sending mail to the next next signatory */
RUN 2-prc-envoiemail("nextsig":u, bcDAWFLW.orisig).
END.
ELSE DO:
/* Sending mail to the next signatory */
RUN 2-prc-envoiemail("nextsig":u, bcDAWFLW.orisig).
END.
END.
ELSE DO:
RUN 3-prc-DaToCde.
/* sending mail to inform the requester that is demand is approved */
RUN 2-prc-envoiemail("accept":u, DAWFLW.orisig).
END.
END.
IF cDero <> "" THEN
RUN 2-prc-envoiemail("dero":u, cDero).
END.
define variable xyzzy as integer no-undo.
procedure test:
define variable xyzzy as integer no-undo. /* comment out this line to see side effects, keep it to avoid them... */
xyzzy = 2.
end.
xyzzy = 1.
message "a" xyzzy.
pause.
run test.
message "b" xyzzy.
pause.