Page 1 of 1

SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 1:18 am
by schneiderusa
Hello,

Is it possible to add an IF statement or any other comand before SUM FIELDS.
Currenly I am adding below fields without any conditions. But I need to add condition to sum these filds only when (3,6,CH,A) not equal.

SORT FIELDS=(52,8,CH,A,3,6,CH,A,828,9,CH,A,362,6,CH,A,783,4,CH,A,
895,9,CH,A)
SUM FIELDS=(138,9,371,9,395,9,407,9,469,9,843,9,852,9,
861,9,870,9),FORMAT=PD

Thank you.

Re: SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 1:36 am
by Frank Yaeger
Well, you can use INREC with IFTHEN before SORT and SUM. But it's not clear from your description what you want to do exactly or whether that will help.

Perhaps the sequence of DFSORT processing shown here will help:

http://publibz.boulder.ibm.com/cgi-bin/ ... FIGSTMTSEQ

If you need more specific help, give a better description of the rules for getting from input to output. Give the RECFM and LRECL of the input file. Give the starting position, length and format of each relevant field. It would also help if you'd show an example of the records in your input file (relevant fields only) and what you expect for output.

Re: SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 1:55 am
by schneiderusa
File is regular sequential and fixed format. LREC= 1000 and RECFM= FB

First 80 bytes look like this:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
DMCREDIT100820 10932485 03887100
DMCREDIT100820 10932485 03887100
DMDEBIT 100820 10932485 03887100

This is my current sort card.
SORT FIELDS=(52,8,CH,A,3,6,CH,A,828,9,CH,A,362,6,CH,A,783,4,CH,A,
895,9,CH,A)
SUM FIELDS=(138,9,371,9,395,9,407,9,469,9,843,9,852,9,
861,9,870,9),FORMAT=PD

New task is to SUM above fields only when one record is CREDIT and another is DEBIT.

Re: SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 2:45 am
by Frank Yaeger
New task is to SUM above fields only when one record is CREDIT and another is DEBIT.


Huh? I don't see how the input example you gave relates to the fields you show or the very vague "rule" you stated. I see two records with CREDIT and one with DEBIT. What is the complete set of "rules" for "when one record is CREDIT and another is DEBIT". In the entire file? In a group of records (what is a group)? You need to do a much better job of explaining the rules for what you want to do before anyone can help you. A good example of input and expected output related to the rules and your SORT and SUM fields would help immensely.

Re: SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 7:07 pm
by schneiderusa
Sorry for the confusion.

Let’s try to simplify the input file.

Fld1 pic xx
Fld2 pic 99.
Fld3 pic 999.
Fld4 pic 99.

For example I need to sum Fld4 if values in fld3 are the same and values in fld1 are NOT the same.

Re: SUM fields with IF statement?

PostPosted: Tue Aug 24, 2010 11:44 pm
by DieZ
if values in fld3 are the same
over how many records ? Or, just one record ?
values in fld1 are NOT the same.
over how many records ? Or, just one record ?

:roll:

Re: SUM fields with IF statement?

PostPosted: Wed Aug 25, 2010 12:53 am
by schneiderusa
I think it could be many or 1 for both fields.

Can you give syntax for both scenarios? Thanks.

Re: SUM fields with IF statement?

PostPosted: Wed Aug 25, 2010 2:40 am
by Frank Yaeger
Still not clear what you want to do (to me anyway). If you want help:

For the various possible cases, show an example of the records in your input file (relevant fields only) and what you expect for output. Explain the rules for getting from input to output.

If you can't explain clearly what you want, then it will be difficult for anyone to help you.