Mario,

I first tried with WHEN=GROUP but with no success.

After that I hopefully succeeded with a JOIN.
The main idea is to extract keys from file and number those simply by
sequential number.
So the STAMPA "view" at ST010 should show something like this:

SUGAR100       000001
SUGAR97        000002
SUGAR93        000003
XXXXX20        000004
YYYYY150       000005
YYYYY140       000006

then try to JOIN every key with the relative (+1) of the original file.
So SUGAR-000002 of the original file must match with SUGAR-000001 of the
keys subset.
This has been done with the JNF2CNTL ADD statement.

The final sample output is:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2
SUGAR,2022/08/01,100                              000001
  1  000000
SUGAR,2022/08/02,97                               000002SUGAR100
000002B  000003
SUGAR,2022/08/03,93                               000003SUGAR97
 000003B  000004
XXXXX,2022/08/03,20                               000004SUGAR93
 000004B  000000
YYYYY,2022/08/01,150                              000005XXXXX20
 000005B  000000
YYYYY,2022/08/01,140                              000006YYYYY150
000006B  000010

where first piece (1-56) is the original record, the second piece (57-80)
is the trace of the JOIN process and last column (81:86) is the result you
need.
Double check if the idea is effective.

//*-------------------------------------------------------------------*
//* EXTRACT KEYS AND SEQNUM FROM ORIGINAL FILE                        *
//* FILE SHOULD BE ORDERED BY PRODUCT AND DATE.                       *
//*-------------------------------------------------------------------*
//ST010   EXEC PGM=SORT
//SYSOUT  DD SYSOUT=*
//SORTOUT DD DSN=&F2,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)
//STAMPA  DD SYSOUT=*
//SORTIN  DD *
SUGAR,2022/08/01,100
SUGAR,2022/08/02,97
SUGAR,2022/08/03,93
XXXXX,2022/08/03,20
YYYYY,2022/08/01,150
YYYYY,2022/08/01,140
/*
//SYSIN  DD *
 SORT FIELDS=(1,5,A,7,10,A),FORMAT=BI
 OUTFIL FNAMES=SORTOUT,
  OUTREC=(1,5,18,10,SEQNUM,6,ZD)
 OUTFIL FNAMES=STAMPA,
  OUTREC=(1,5,18,10,SEQNUM,6,ZD)
/*
//*-------------------------------------------------------------------*
//* JOIN WITH ORIGINAL FILE ON SEQNUM + 1                             *
//*-------------------------------------------------------------------*
//ST020   EXEC PGM=SORT
//SYSOUT  DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//F1      DD *
SUGAR,2022/08/01,100
SUGAR,2022/08/02,97
SUGAR,2022/08/03,93
XXXXX,2022/08/03,20
YYYYY,2022/08/01,150
YYYYY,2022/08/01,140
/*
//JNF1CNTL DD *
 INREC FIELDS=(1,50,SEQNUM,6,ZD)
/*
//F2      DD DSN=&F2,DISP=(OLD,DELETE)
//JNF2CNTL DD *
 INREC FIELDS=(1,15,16,6,ZD,ADD,+1,TO=ZD,LENGTH=6)
/*
//SYSIN  DD *
 JOINKEYS F1=F1,FIELDS=(51,6,A)
 JOINKEYS F2=F2,FIELDS=(16,6,A)
 JOIN UNPAIRED,F1
 REFORMAT FIELDS=(F1:1,56,F2:1,21,?)
 SORT FIELDS=COPY
 OUTFIL FNAMES=SORTOUT,REMOVECC,
  IFTHEN=(WHEN=(1,5,CH,EQ,56,5,CH),
   OVERLAY=(81:61,10,UFF,SUB,18,10,UFF,EDIT=(TTTTTT))),
  IFTHEN=(WHEN=NONE,
   OVERLAY=(81:C'000000'))
/*

Best regards.
Max

Il giorno mar 30 ago 2022 alle ore 09:32 Mario Bezzi <
subscriptions.mario.be...@gmail.com> ha scritto:

> Hello list,
>
> say I have a file with goods, dates, and available quantities, not
> necessarily sorted. I want to sort it and calculate daily deltas.
>
> For example using the following input :
>
> Product,Date,Availability
> Sugar,2022/08/01,100
> Sugar,2022/08/02,97
> Sugar,2022/08/03,93
>
> I need to get to this:
>
> Product,Date,Sold
> Sugar,2022/08/01,N/A  (No daily delta for the first record)
> Sugar,2022/08/02,3    (100 - 97)
> Sugar,2022/08/03,4    (97 - 93)
>
> May I use bultin DFSORT functions to calculate deltas from the previous
> record and the current one?
>
> I had a look at the OUTREC statement in the Application Programming
> Manual, but as far as I can see arithmetic expressions can only use input
> fields from the current record or decimal constants.
>
> It believe I can achieve the above result using an E35 exit, just wanted
> to be sure that's the only way.
>
> Thanks!
> mario
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to