Counting records

tolits009

New Member
A user asked me the following:
count transactions where a table contains example:

document# idno code

0001 001 CS001
0001 002 CS002
0001 003 CS001
003 CS002
0001 004 CS001
004 CS002
0001 005 CS001
005 CS002
0001 006 CS001
006 CS002

my problem is i have to count document 0001 ONLY ONCE
where the code contains [CS001 AND CS002]
and so on....

how do I do it?
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
Does the data really look like that? Some records have a value for document# and others have... the empty string? Or unknown? Or zero?

Did the user really ask you to "count transactions"? You don't define what you mean by "transactions". Are they business transactions? Database transactions? Is "transactions" the name of the table you are describing? If so, the task seems to be not "count transactions" but rather "count some of the transactions". You haven't provide a precise meaning for "some of".

What are the exact criteria for counting a record versus not counting one? You mention one specific case, where records with document# "0001" and idno values "CS001" and "CS002" should not both be counted, if I understand you correctly. What is the general rule? Do you want to count every unique combination of document# and idno?
 

luckboter

New Member
Apparently, by the model you presented, you want to store the number of transactions with different initial codes happen ...
In this case, when performing a FOR EACH store this code in a variable, then compare it with the next record, if it is the same ignore the count, if it is different add +1 to your counter.

Ex:

Code:
DEF VAR v_Cod as INT NO-UNDO INIT 0.
DEF VAR v_Cont AS INT NO-UNDO INIT 0.

FOR EACH "TABLE" NO-LOCK:

IF v_Cod <> "Transaction Code" THEN DO:
   v_Cont = v_Cont + 1.
END.

v_Cod = "Transaction ID"

At the end, just display the value of v_Cont.
 
Last edited by a moderator:

chrisds

New Member
Code:
DEFINE VARIABLE cnt AS INTEGER.

cnt = 0.

FOR EACH < Table Name > NO-LOCK BREAK BY document# :

        IF FIRST-OF(document#) THEN DO :
            cnt = cnt + 1.
        END.
END.

DISPLAY cnt.
 
Last edited by a moderator:

Rob Fitzpatrick

ProgressTalk.com Sponsor
For those posting code snippets, please enclose them in CODE tags. You can find it under the three-vertical-dots button on the right side of the toolbar. Appropriate indentation is helpful as well.
 
Top