# Sum AT break

**URL:** <https://techcommunity.softwareag.com/t/sum-at-break/91059>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [August 25, 2009, 5:47pm UTC](https://techcommunity.softwareag.com/t/sum-at-break/91059 "2009-08-25T17:47:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PalDesh](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@PalDesh](https://techcommunity.softwareag.com/u/PalDesh)\
**Post date:** [August 25, 2009, 5:47pm UTC](https://techcommunity.softwareag.com/t/sum-at-break/91059/1 "2009-08-25T17:47:39Z")

</div>

I have the following logic in my code  
AT BREAK OF #FIELD1  
WRITE(1) OLD(#AMOUNT-CODE)  
OLD(#FIELD1)  
OLD(#FIELD2)  
SUM(#AMOUNT) (EM=+ZZZ,ZZZ,ZZZ,ZZ9.99)  
ADD SUM(#AMOUNT) TO #TOTAL-AMOUNT

What does the ‘AT BREAK’ do?  
does it sum up the amounts of the previous bunch when break is encountered?  
Please help!  
If there is any material available for natural commands, please let me know.

Thanks,  
Pallavi

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [August 25, 2009, 6:39pm UTC](https://techcommunity.softwareag.com/t/sum-at-break/91059/2 "2009-08-25T18:39:31Z")

</div>

Education, Education, Education !! There is no substitute for it.

Try [http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat425mf/sm/atbreak.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat425mf/sm/atbreak.htm)

Briefly, AT BREAK is a non procedural specification of code to be executed when the value of a variable (#FIELD1 in your example) changes.

OLD is a system function which retrieves the last value of the specified variable.

SUM the sum of the specified variable since the last “break”

The statement: ADD SUM(#AMOUNT) TO #TOTAL-AMOUNT is probably an indication that the person who wrote the code originally did not know the difference between SUM and TOTAL. TOTAL is a running sum, which appears to be what is being computed in the code excerpt you posted.

So, you are probably trying to learn Natural, without a class, by reading code, which seems to have been written by someone who is not very familiar with Natural.

steve

---

<div class="post-metadata">

**Author:** ![PalDesh](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@PalDesh](https://techcommunity.softwareag.com/u/PalDesh)\
**Post date:** [August 26, 2009, 10:37am UTC](https://techcommunity.softwareag.com/t/sum-at-break/91059/3 "2009-08-26T10:37:34Z")

</div>

Thanks!! This helped!!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:57pm UTC](https://techcommunity.softwareag.com/t/sum-at-break/91059/4 "2021-04-02T14:57:25Z")

</div>


