check that all lines contain the same account value or not

bino

Member
Hi all I was wondering what would you consider the best method to check that all the line records returned on a for each contain the same account number or not.

Code:
assuming the following simple for each.
 
for each Payment where 
            Payment.Payment-id eq 5678910: 
 
For example if this were my returned results
then the payment account is 23456.
 
   Account  Payment-id    Pay Total
1  23456    5678910       20.00
2  23456    5678910       23.00
3  23456    5678910       15.00
4  23456    5678910       200.00
5  23456    5678910       150.00
6  23456    5678910       60.00
 
 
However, if this were my returned results
then I know there is more than one payment 
account.
 
   Account  Payment-id    Pay Total
1  23456    5678910       20.00
2  23456    5678910       23.00
3  25555    5678910       15.00
4  22666    5678910       200.00
5  23456    5678910       150.00
6  23456    5678910       60.00
 
Well I'll just loop through the string of accts comparing to the first this should work.

Code:
test
 
def var v-delimter    as char no-undo.
def var v-acct-string as char no-undo.
def var v-i           as int  no-undo.
def var v-first-acct  as char no-undo.
def var v-diff-cnt    as int  no-undo.
 
assign v-delimter    = "|"
       v-acct-string = "23456|23456|23456|1111|2222".
 
/* assign values */
assign v-diff-cnt = 0.
do v-i = 1 to num-entries(v-acct-string, v-delimter):
      assign v-first-acct = entry(1,v-acct-string, v-delimter).
 
      /* if the account is different then the first */
      if entry(v-i,v-acct-string, v-delimter) ne v-first-acct then
      assign v-diff-cnt = v-diff-cnt + 1.
end.
display v-first-acct v-diff-cnt.
 
Try this:

def var isdifferent as logical no-undo.
def var this_acc_code as char initial ? no-undo. /* or int if defined as int */
for each Payment where
Payment.Payment-id eq 5678910 no-lock:

if this_acc_code = ? then this_acc_code = payment.acc_code. /* Or whatever the field is you want to check */

if this_acc_code <> payment.acc_code then do:
isdifferent = yes.
leave.
end.
end.

if isdifferent then message "More than one account" view-as alert-box.
 
Hi all I was wondering what would you consider the best method to check that all the line records returned on a for each contain the same account number or not.

Hi,

I don't know if this is the best method, but here's what I would do :

Code:
DEF VAR cpt AS INT NO-UNDO.

FOR EACH payment WHERE payment.payment-id = 5678910  BREAK BY account:
  IF LAST-OF(account)
  THEN cpt = cpt + 1.
END.

DISP (cpt = 1).
Hope that helps.

Julien

EDIT : take sphipp's code, it'll leave the loop as soon as the condition is false whereas mine will scan the whole table...
 
Back
Top