COBOL: ADD or Subtract Sample Logic

In COBOL, there are scenarios you need to use ADD or Subtract. In all these programmers confuse which format they need to choose. Here are my ideas.

Let me take an example of Subtract and explain it. Here are two formats. You can choose any one depending on your requirement.

1. Format-1

Subtract a1 b1 c1 from T1 T2 T3

In the above code, you are subtracting three values from the source values. This happens the way you have given the order, and it subtracts in the order you mentioned.

Example: a1 b1 c1 is subtracted from T1….and so on

2. Format-2

Subtract a1 b1 c1 from T1

Subtract a1 b1 c1 from T2

Subtract a1 b1 c1 from T3

How to choose format? In the Format-1, you can cannot retain the values of T2,T3. Since all the values (T1,T2, T3) will be subtracted in sequence at a time.

Where as in the Format-2, you can retain the values of T2 and T3. Since, after T1 is subtracted still you have time to check values of T2 and T3.

You need to choose a format depends upon your requirement.

General rule

After Subtract or ADD  statement you need to give one space. Comma is an optional, but space is must.

Keep Reading

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.