Total amt

sreekuax

Member
Hi ,

For a ck_nbr value lets say there are two ckd_amt values. How can I sum those and get inside a data output stream under one ck_nbr value.

i.e
ck_nbr = 0001 & ckd_amt = 100 ,ckd_amt = 200 & ck_date = 01/01/01
want to sum ckd_amt = > 100 + 200 = 300

put stream out-stream unformatted
ck_nbr "|" ckd_amt ck_date skip. =>

this should give me :
0001 | 300 | 01/01/01 ... How is this possible ? Any functions etc. Thanks for any help..
 

Cringer

ProgressTalk.com Moderator
Staff member
I really don't understand your requirements. x-ttl = ckd_amt + ckd_amt will just end up with whatever value is in ckd_amt doubled. There must be something that changes the value stored in ckd_amt, so before it changes, put it in another variable and then add the next one to it. It's a very basic concept, surely?
 

sreekuax

Member
Sorry ...May be I was not clear in explaining what I need....
Here is it :

for a ck_nbr value there are multiple ckd_amt values existing for a unique date.
now if I want to get this data in a file... I should get all the amounts added up under the same ck_nbr...
I used ACCUM function... but its not helping me.. or may be I am using it wrong.. here is the code part ...

for each ck_mstr where ck_bank <> '09' no-lock :
for each ap_mstr where ap_ref = ck_ref
and ap_type = 'CK'
and ap_effdate > 06/01/12 no-lock :
for each ckd_det where ckd_ref = ck_ref no-lock :
ACCUMULATE ckd_amt(TOTAL).
display ck_nbr (ACCUM TOTAL ckd_amt) ap_date.
end.
end.
end.
and the result is :

Check TOTAL Date │
│──────── ────────── ────────│
│00151355 1,200.00 06/06/12│
│00151355 1,579.18 06/06/12│
│ │

Now my aim was to make │00151355 2,779.00 06/06/12│ but ACCUM is not helping or I am using it wrong...
 

Cringer

ProgressTalk.com Moderator
Staff member
That makes more sense to me. The answer is as follows:
Code:
DEFINE VARIABLE lv-MyTotal AS DECIMAL     NO-UNDO.

for each ck_mstr where ck_bank <> '09' no-lock :
  for each ap_mstr where ap_ref = ck_ref
    and ap_type = 'CK'
    and ap_effdate > 06/01/12 no-lock :
    lv-MyTotal = 0.
    for each ckd_det where ckd_ref = ck_ref no-lock :
      lv-MyTotal = lv-MyTotal + ckd_amt.
    end.
    display ck_nbr lv-MyTotal ap_date.
  end.
end.
 

sreekuax

Member
That makes more sense to me. The answer is as follows:
Code:
DEFINE VARIABLE lv-MyTotal AS DECIMAL     NO-UNDO.

for each ck_mstr where ck_bank <> '09' no-lock :
  for each ap_mstr where ap_ref = ck_ref
    and ap_type = 'CK'
    and ap_effdate > 06/01/12 no-lock :
    lv-MyTotal = 0.
    for each ckd_det where ckd_ref = ck_ref no-lock :
      lv-MyTotal = lv-MyTotal + ckd_amt.
    end.
    display ck_nbr lv-MyTotal ap_date.
  end.
end.

Coooooooool.... I got the result... ! Thank you so much ... seems I forgot basics... need to brush up.. :(
 

Cringer

ProgressTalk.com Moderator
Staff member
If you find that this sort of thing regularly crops up (I mean struggling to find the logic), then try drawing it out on a piece of paper, forgetting the joins of on the db or whatever, making the clauses as simple as possible, and it should help you. So for your example:

Code:
each ck_mstr:
  each ap_mstr:
    each ckd_det:
    end. 
  end. 
end.
 

GregTomkins

Active Member
I have found a good rule of thumb with Progress, if you find yourself typing keywords like ACCUMULATE, delete them immediately and replace them with a simple variable addition like above. You will end up doing it eventually anyway.
 
Top