# invoice number generator

**URL:** <https://techcommunity.softwareag.com/t/invoice-number-generator/101121>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [August 1, 2012, 10:53am UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121 "2012-08-01T10:53:01Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 1, 2012, 10:53am UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/1 "2012-08-01T10:53:01Z")

</div>

Hello all,

our invoice number is sequential (i.e. new invoice number = previous invoice number + 1). A simple subprogramm (running for many years) does the job as an invoice number generator.

```auto
get counter-view #ISN
add 1 to counter-view.counter
update
```

The calling program has to do the end/backout transaction. And that’s the problem. Not every calling program ends the transaction immediately. Sometimes that leads to deadlocks, NAT3009 etc. To do the end transaction inside the subprogram won’t work because it influences the transaction logic of the calling program.

So the question is: How to solve the problem?

Adabas/Natural is not able to handle nested ETs or something like that.  
One idea is to call the invoice number geneator as a RPC-Program (btw: is it possible to call a local Subprogram via RPC?). It has a different Adabas-Session and so we could to an ET inside the subprogram without influencing the calling program. Any other ideas?

Regards

Matthias

---

<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 1, 2012, 12:41pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/2 "2012-08-01T12:41:22Z")

</div>

Hi Matthias;

Instead of using a field as the counter, how about using the ISN itself as the invoice number.

Basically you would have an Adabas file devoted to nothing but keeping track of the invoice numbers.

Or, assuming you have a Master Invoice file, you could use a two step process.

STORE an invoice record  
MOVE \*ISN to ISN-COUNTER (field in the record)  
UPDATE the invoice record.

In both cases, of course, the file would have to have non reusable ISNs.

steve

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [August 1, 2012, 3:52pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/3 "2012-08-01T15:52:12Z")

</div>

Hi Matthias,  
According to the doc, “…The Natural RPC facility enables a client Natural program to issue a CALLNAT statement to invoke a subprogram in a server Natural. The Natural client and server sessions may run on the same or on a different computer”, your idea seems to be very “productive” 🙂 to me. Of course, there`s another “simple and stupid” solution: to force any calling program to issue ET (end transaction) just after after calling that generator to make sure that it (the calling program) got its own unique INVOICE NUMBER.

Like many shops we are also using the same logic (with the same drawbacks :-(; I`d be very interested in knowing about your progress in solving such a problem.

Best regards,  
Nikolay

---

<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:** [August 1, 2012, 8:13pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/4 "2012-08-01T20:13:47Z")

</div>

The first and most important question is:

Do the invoice numbers have to be sequential or are “gaps” allowed ?

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 2, 2012, 4:18pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/5 "2012-08-02T16:18:15Z")

</div>

Hi Steve!

> [@Steve Robinson](#):
>
> Instead of using a field as the counter, how about using the ISN itself as the invoice number.

Not a bad idea, but not every invoice number is numerical.  
We got several number ranges and one of them begins with “F” or “B”.

Matthias

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 2, 2012, 4:20pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/6 "2012-08-02T16:20:35Z")

</div>

> [@Wolfgang Winter](#):
>
> Do the invoice numbers have to be sequential or are “gaps” allowed ?

Gaps are allowed. Otherwise you couldn’t handle generate number, store invoice, backout transaction…

---

<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:** [August 2, 2012, 4:27pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/7 "2012-08-02T16:27:57Z")

</div>

> [@Matthias](#):
>
> > [@Wolfgang Winter](#):
> >
> > Do the invoice numbers have to be sequential or are “gaps” allowed ?
> 
> Gaps are allowed. Otherwise you couldn’t handle generate number, store invoice, backout transaction…

Ok, I don’t see the problem then, allocate the next invoice number independently of  
the actual invoice, i.e. the subprogram does the GET - UPDATE - ET, no nested transactions.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 2, 2012, 10:14pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/8 "2012-08-02T22:14:10Z")

</div>

> [@Wolfgang Winter](#):
>
> i.e. the subprogram does the GET - UPDATE - ET, no nested transactions.

… called via RPC.

So I’ll try it out.

---

<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:** [August 2, 2012, 10:34pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/9 "2012-08-02T22:34:57Z")

</div>

A plain subprogram should do, no RPC required when you allocate  
thet invoice number before any other updates have been issued.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 3, 2012, 8:11am UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/10 "2012-08-03T08:11:37Z")

</div>

> [@Wolfgang Winter](#):
>
> A plain subprogram should do, no RPC required when you allocate  
> thet invoice number before any other updates have been issued.

And that’s the point. As I wrote above:

> [@](#):
>
> To do the end transaction inside the subprogram won’t work because it influences the transaction logic of the calling program.

---

<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 3, 2012, 11:26am UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/11 "2012-08-03T11:26:16Z")

</div>

The code I suggested for using the ISN as the invoice number is easily modified since it is a two step process:

Instead of:

STORE an invoice record  
MOVE \*ISN to ISN-COUNTER (field in the record)  
UPDATE the invoice record.

you simply:

STORE an invoice record  
MOVE \*ISN to ISN-COUNTER (field in the record)  
IF prefix required  
compress #prefix isn-counter into isn-counter leaving no space  
end-if  
UPDATE the invoice record.

Where #prefix has the required value (F or B)

steve

---

<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:** [August 3, 2012, 12:56pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/12 "2012-08-03T12:56:01Z")

</div>

> [@Matthias](#):
>
> And that’s the point. As I wrote above:
> 
> > [@](#):
> >
> > To do the end transaction inside the subprogram won’t work because it influences the transaction logic of the calling program.

And what I tried to say was:

When the user invokes the invoice generation transaction the first thing done  
is get the invoice number generated, before any transaction has been started.

If this is possible depends on the context, of course, when a transaction has  
already been started when the invoice generation program is invoked then  
that won’t work, of course.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [September 27, 2012, 11:42am UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/13 "2012-09-27T11:42:48Z")

</div>

> [@Nikolay Kuhta](#):
>
> Like many shops we are also using the same logic (with the same drawbacks :-(; I`d be very interested in knowing about your progress in solving such a problem.

Just some news:  
We’ve implemented an RPC-Solution for the counter-problem. It’s just a simple subprogram in a special libary. Only the rpc-server knows this libary as a steplib.

Works good so far. 🙂

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [October 2, 2012, 5:34pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/14 "2012-10-02T17:34:30Z")

</div>

Thank you for letting me know that, Matthias  
(just got back from vacation in Andalusia: no NATURAL at all, but the nature itself was so beautiful! 🙂

Best regards

---

<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, 3:02pm UTC](https://techcommunity.softwareag.com/t/invoice-number-generator/101121/15 "2021-04-02T15:02:15Z")

</div>


