Page 1 of 2

Sum an alphanumeric fields

PostPosted: Thu Jul 03, 2014 2:10 am
by danylele74
Hi everybody, I have this problem: I have to sum alphanumeric fields using JCL but I can not find the solution.

Input file

KEY        VALUE 
----+----1----+----1----+----1----+----1
0000000100 +0000000500,34
0000000100 +0000023344,00
0000000200 +0000002200,99
0000000200 -0000001500,99
0000000300 -0000000100,00



Output file

KEY        VALUE   
----+----1----+----1----+----1----+----1
0000000100 +0000023844,34
0000000200 +0000000700,00
0000000300 -0000000100,00

Can you help me?

Thanks.

Re: Sum an alphanumeric fields

PostPosted: Thu Jul 03, 2014 4:38 am
by BillyBoyo
Presuming that your data is already in sequence, you should look at the OUTFIL reporting functions.

You'll need OUTFIL with REMOVECC,NODETAIL, SECTIONS for your key, and TRAILER2 with TOT, where you can use SFF for the field type, where the signn should be taken into account automatically, and the comma ignored. You can use EDIT to format the total into the same manner of display as your source.

Re: Sum an alphanumeric fields

PostPosted: Thu Jul 03, 2014 10:06 am
by danylele74
Thanks.
Can you show me an example about OUTFIL and REMOVECC, TRAILER2, etc. ??

the KEY field is numeric.

Re: Sum an alphanumeric fields

PostPosted: Fri Jul 04, 2014 2:57 am
by NicC
Cannot be done in JCL. JCL is not for this sort of problem. Moving to DFSort section. If you are using Syncsort then say so and it will be moved again.

Re: Sum an alphanumeric fields

PostPosted: Sat Jul 05, 2014 6:33 pm
by Magesh23586
Here is the code for you
//STEP01 EXEC PGM=SORT                               
//SORTIN DD *                                         
0000000100 +0000000500.34                             
0000000100 +0000023344.00                             
0000000200 +0000002200.99                             
0000000200 -0000001500.99                             
0000000300 -0000000100.00                             
//SORTOUT DD SYSOUT=*                                 
//SYSOUT DD SYSOUT=*                                 
//SYSIN DD *                                         
  SORT FIELDS=COPY                                   
  OUTFIL FNAMES=SORTOUT,REMOVECC,NODETAIL,           
  SECTIONS=(1,10,SKIP=P,                             
  TRAILER3=(1:1,10,X,TOT=(12,14,                     
         SFF,EDIT=(STTTTTTTTTT.TT),SIGNS=(+,-))))     
/*                                                   


You may refer following link, as you are beginner
http://ibmmainframes.com/post-7535.html

Hope this helps,

Thanks
Magesh

Re: Sum an alphanumeric fields

PostPosted: Mon Jul 07, 2014 5:01 am
by BillyBoyo
Magesh23586, that should be about right. I'd only query the SKIP=P. With the REMOVECC it may not matter, but better not to include it, I think.

Re: Sum an alphanumeric fields

PostPosted: Mon Jul 07, 2014 10:16 pm
by BillyBoyo
It seems this doesn't give you all your data. However, we had no way to know.

If you are a beginner, it is best to stay in this forum. The other where you posted is for those with more experience.

Modify the following for your exact positions and lengths (an any typos I've made).

     TRAILER3=(1,10,
               11,4000,
               TOT=(4011,14,                     
                     SFF,EDIT=(STTTTTTTTTT.TT),SIGNS=(+,-),
               4015,6000)))


I've spread the code out as it is always easier to read, understand, and change, that way.

Remember, we only know what you show us. You showed us a short record, so Magesh23586 provided you with code for a short record.

Also note, that with something working, you can search for other examples of TRAILER3 and get a better idea of how it works, and also consult the manuals. You will learn more and faster if you do the work from guidance, rather than just copy and paste.

Re: Sum an alphanumeric fields

PostPosted: Tue Jul 08, 2014 3:27 pm
by danylele74
Unfortunately in the output file (at the bottom right of the record) I find the range containing the calculated sum.

Is it possible to remove it without losing the data contained in the input file ?

This is my JCL


//STEP060  EXEC PGM=SORT,REGION=0M,COND=(0,NE)                     
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD DISP=SHR,DSN=XSE005.IMP000.IM1IM71.DATAPLUS.SORT3   
//SORTOUT  DD DISP=OLD,DSN=XSE005.IMP000.IM1IM71.DATAPLUS.SORT4   
//SYSIN    DD *                                                   
    SORT FIELDS=(13,9,CH,A),FORMAT=BI                             
    OUTFIL REMOVECC,NODETAIL,                                     
    SECTIONS=(13,9,                                               
    TRAILER3=(1:1,9980,X,                                         
         TOT=(3674,19,SFF,EDIT=(STTTTTTTTTTTTTTT.TT),SIGNS=(+,-))))



Thank you

p.s.
Input and output files have lenght 10000.

Re: Sum an alphanumeric fields

PostPosted: Tue Jul 08, 2014 5:12 pm
by BillyBoyo
Still not clear what you want. You have an alpha-numeric value you want "summed". Do you want the result of the summing to be in the original location? Let's assume Yes for now.

    TRAILER3=(1:1,3673,X,                                         
         TOT=(3674,19,SFF,EDIT=(STTTTTTTTTTTTTTT.TT),SIGNS=(+,-)),
               3693,xxxx))

Re: Sum an alphanumeric fields

PostPosted: Tue Jul 08, 2014 7:58 pm
by danylele74
yes, I want the result of the summing to be in the original location (position 3674,19)