On  Aug 6, 2005, Ramya Ramaswamy wrote:

> I have a requirement which states like this:
>
> Given records like
>
> 1~ABC~99.99~12345
> 123~AB~9.99~567
> 34~c~1.99~345
>
> where there are 4 fields in each record, each separated by a '~'. The
third
> field is the price field, which i need to sum up. I wont know the
starting
> position / length of the fields. Is there any way that i can sum up the
> price, using Sort or DYL, without having to write a COBOL program using
> UNSTRING?

You can now do this with the new PARSE function available with z/OS DFSORT
V1R5 PTF UK90007 or DFSORT R14 PTF UK90006 (April, 2006), as shown in the
DFSORT job below.  I assumed your input file has RECFM=FB and LRECL=80, and
that you want a trailer with the total of the price values, but you can
change the job appropriately for other attributes and output requirements.
You didn't say what the maximum price value was, so I added another record
with a larger price field for illustration.

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
821~XYZ~25,821.03~5
1~ABC~99.99~12345
123~AB~9.99~567
34~c~1.99~345
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
* Ignore first ~ delimited field.
  INREC PARSE=(%=(ENDBEFR=C'~'),
* Ignore second ~ delimited field.
               %=(ENDBEFR=C'~'),
* Extract third ~ delimited field into
* a 9-byte %00 fixed parsed field.
               %00=(ENDBEFR=C'~',FIXLEN=9)),
* Add %00 after end of each record so we can total it.
        OVERLAY=(81:%00)
* Remove ANSI carriage control characters from output.
  OUTFIL REMOVECC,
* Write trailer record with total of %00 values -
* use UFF format to handle comma and decimal point.
    TRAILER1=(/,'Sum of Prices: ',
              TOT=(81,9,UFF,EDIT=(II,IIT.TT))),
* Remove %00 value from each record.
    BUILD=(1,80)
/*

SORTOUT would be RECFM=FB and LRECL=80 with these output records:

821~XYZ~25,821.03~5
1~ABC~99.99~12345
123~AB~9.99~567
34~c~1.99~345

Sum of Prices: 25,933.00

For complete details on DFSORT's new PARSE function, see:

www.ibm.com/servers/storage/support/software/sort/mvs/peug/

Frank Yaeger - DFSORT Team (IBM)
 Specialties: PARSE, JFY, SQZ, ICETOOL, IFTHEN, OVERLAY, Symbols, Migration

 => DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort/
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to