View previous topic :: View next topic
|
Author |
Message |
surezznag
New User
Joined: 04 Aug 2023 Posts: 6 Location: India
|
|
|
|
I have requirement to calculate total count of records and Sum of comp-3 variable in flat file and it has to be done by JCL not by cobol. I coded sort card jcl where it will calculate in count and sum in trailer 1.
Now my question is does the Sum function automatically ignore null value appearing in numeric field while calculating or we need some exception handling. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1329 Location: Bamberg, Germany
|
|
|
|
Use CSF or FS as data format. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
surezznag wrote: |
I have requirement to calculate total count of records and Sum of comp-3 variable in flat file and it has to be done by JCL not by cobol. I coded sort card jcl where it will calculate in count and sum in trailer 1.
Now my question is does the Sum function automatically ignore null value appearing in numeric field while calculating or we need some exception handling. |
In case your data have been unloaded from DB2, the NULL values are indicated BY A SEPARATE FIELD associated with every nullable field of the unloaded table.
In case you have a non-DB2 related dataset, you MUST FIND OUT: how the NULL value is indicated in this home-made data? (May be any unacceptable value: a negative one, or invalid decimal packed, or 100 other options)
This is the first thing YOU MUST DO before posting your questions at this forum. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Or replace nulls to 0 in db2 |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
Rohit Umarjikar wrote: |
Or replace nulls to 0 in db2 |
1. There was nothing about DB2 in the original post. We can only guess what TS meant…
2. From the very beginning NULLS were introduced for situations where replacing them with zero (or whatever else) may produce absolutely wrong results.
For example, the record PERSON may include field SALARY to keep the salary of the person if he is working at current time. Assigning value 0.00 as SALARY of those persons who are not working (e.g. children, disabled persons, retired persons, etc.) would produce incorrect results when trying to calculate AVERAGE, MIN, Number_of_employed, etc. Any other “invalid” value, like -1.00 would not resolve the problem. In many situations like this one using special NULL values is absolutely necessary.
Highly likely, the TS has not a minor idea about data architecture problems. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
I don’t disagree but without converting to 0 it’s not goning to work .. I only suggested to fix the source ( most likely db2 only).
With your example TS can filter active employee only in Include cond than depending on nulls.
Anyways he can use DFSORT to convert nulls to 0 and do the calc. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
Rohit Umarjikar wrote: |
I don’t disagree but without converting to 0 it’s not goning to work .. I only suggested to fix the source ( most likely db2 only). |
It's not going to work neither with conversion to zero, nor without it.
The issue with NULLS (if it is really from DB2 - but still under question) cannot be resolved by setting to zero. |
|
Back to top |
|
|
|