IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SUM FIELDS - To add a byte if sign field is there


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Jul 16, 2010 12:26 am
Reply with quote

Hi,

I have an input file of 160 bytes (Fixed Byte) and I need to sum the amount field for same Type code field
Type code - X(5) - starting at 42nd byte, length - 5 bytes
Amount field S9(4)V99 - starting at 77th byte, length - 6 bytes

When I did SUM FIELDS, it seems the data got overflow and got incorrect results.

Code:
SORT FIELDS=(42,5,CH,A)
SUM FIELDS=(77,6,ZD)


I thought of using INREC to pad zeroes before 77th byte however since sign is there, I am not sure how to add additional 2 bytes and then do SUM

Please help.

Thanks
Vinu
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jul 16, 2010 12:45 am
Reply with quote

Hello,

Post some sample input records and the output you want from these input records.

Mention the dsorg and lrecl of the files. Post any "rules" for getting form the input to the output.

Post the jcl and sort control statements ysed and the informational output from this run (including the message id's).
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Jul 16, 2010 12:54 am
Reply with quote

Hi,

Please find the sample input and output and JCL used.

Type Code is at 42nd byte X(5).
Amount is at 77th byte - S9(4)V99

Input data
Code:
Type Cd   Amount   
10000    +200.01
10000    -100.01
10000     +50.02
20000    +1500.50
20000    -2000.50
Output
Code:
10000     +150.02
20000     -500


Code:
//STEP01  EXEC PGM=SORT                                     
//SYSOUT    DD SYSOUT=*                                     
//SYSPRINT  DD SYSOUT=*                                     
//SORTIN    DD DSN=<Input file>,DISP=SHR   
//SORTOUT   DD DSN=<Output file>,     
//             DISP=(,CATLG,DELETE),                       
//             UNIT=DISK,                                   
//             SPACE=(CYL,(1,1),RLSE),                   
//             DCB=(RECFM=FB,LRECL=160,BLKSIZE=0)           
//SYSIN     DD *                                           
   SORT FIELDS=(42,5,CH,A)   
   SUM FIELDS=(77,6,ZD)
/* 


Thanks
Vinu
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Jul 16, 2010 1:12 am
Reply with quote

Since you need to convert the signed numeric to a valid ZD format, you will need an INREC converting the CSF/SFF to ZD before summing.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Jul 16, 2010 1:18 am
Reply with quote

Hi CICS guy,

Is it mandatory to convert the signed field to ZD before doing summing ?

Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Jul 16, 2010 1:21 am
Reply with quote

Vinu,

That amount is NOT a ZD value - it's an SFF value. SFF cannot be used in SUM. Here's a DFSORT job that will do what you asked for. I assumed the amount was actually in positions 77-84 (8 bytes), and that you only wanted the Type code and amount in the output records as shown in your example.

Code:

//S1 EXEC PGM=SORT                                         
//SYSOUT DD SYSOUT=*                                       
//SORTIN DD DSN=...  input file                       
//SORTOUT DD DSN=...  output file                               
//SYSIN DD *                                               
  SORT FIELDS=(42,5,CH,A)                                 
  OUTFIL REMOVECC,NODETAIL,                               
    SECTIONS=(42,5,                                       
      TRAILER3=(42:42,5,                                   
        77:TOT=(77,8,SFF,EDIT=(SIIIT.TT),SIGNS=(+,-))))   
/*
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Jul 16, 2010 1:34 am
Reply with quote

Hi Frank,

Thanks for the code.
My Amount field is S9(4)V99 - 6 bytes.

So I have changed EDIT=(SIIIT.TT) to EDIT=(SIT.TT)
This truncated the output values.

Another example where the output can go past 6 bytes
For ex
Code:
Input
11111   +9000.99
11111   +8000.99

Output
11111   +17001.98


Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Jul 16, 2010 2:05 am
Reply with quote

Hmm ... I think we're getting a bit mixed up here with the internal representation of the value vs the external representation. Based on your example, and this statement:

Quote:
I thought of using INREC to pad zeroes before 77th byte however since sign is there, I am not sure how to add additional 2 bytes and then do SUM


I assumed your values looked like this in the input records.

sdddd.dd

But if they're really 6-byte ZD values, then the sign is in the last byte, not in the first byte. That is, the ZD values look like this in hex:

FdFdFdFdFdsd

where s is the sign.

So you can pad with zeros (F0) on the left and not affect the sign.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Jul 16, 2010 2:12 am
Reply with quote

Hi Frank,

My values look like those mentioned in input records.

Amt can be +100.00, +2000.99 ie., it is S9(4)V99. (6 bytes).
While summing it overflows the 4 bytes. As you have mentioned, we can't do summing if Signed byte is there.
The code you have mentioned worked fine. Only problem is the length of bytes in it. Here ZD is not there.
My reqt is just to have the sum of amount for the similar Type codes.

Thanks
Vinu
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Jul 16, 2010 3:15 am
Reply with quote

You are absolutely making NO SENSE. You keep contradicting yourself as to what the values look like and how many bytes they occupy.

+2000.99 (X'4EF2F0F0F04BF9F9') would occupy 8 bytes and would be SFF format. 200099 (X'F2F0F0F0F9F9') would occupy 6 bytes and would be ZD format.

Then you say "it overflows the 4 bytes". 4, 6, 8? Eeeek.

I can't figure out what your data really looks like or what you want to do since you keep making confusing statements about it.

Please show what the +100.00 and +2000.99 values look like in HEXADECIMAL ... that will clear up once and for all what type of values you have.

Quote:
Only problem is the length of bytes in it. Here ZD is not there.


I have NO IDEA what you mean by this.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Jul 16, 2010 3:42 am
Reply with quote

Quote:
My Amount field is S9(4)V99 - 6 bytes.

So I have changed EDIT=(SIIIT.TT) to EDIT=(SIT.TT)

This truncated the output values.


If S9(4)V99 is 6 bytes, it's ZD with 6 digits, so if you change the EDIT mask to have 4 digits (IT.TT) instead of 6 digits (IIIT.TT), of course it will truncate the digits. You need SIIIT.TT for 6 digits. You would need SIIIIIT.TT to add two leading zeros to prevent overflow.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Sat Jul 17, 2010 2:58 am
Reply with quote

Hi Frank,

Thanks for the information.
Eventhough with IT.TT itself, it didnt give the desired results.
I have the Type code 1000C,1012A, 1012D, 1115A etc in input however it gave me the truncated result for 1012D,1115A. Not sure whether it combines all other Type codes.

When I tried using IIIT.TT, got error stating that the Input and Output LRECL is mismatching.

Thanks
Chidam
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Sat Jul 17, 2010 3:38 am
Reply with quote

We were talking about the amount field. So why are you saying what the Type Code field looks like? What does the amount field look like? Isn't the amount field the field you're trying to add?

Quote:
Eventhough with IT.TT itself, it didnt give the desired results.


No, it wouldn't as I explained in my previous post.

Quote:
When I tried using IIIT.TT, got error stating that the Input and Output LRECL is mismatching.


Well, that means you tried to increase the length of the output records, but your output data set has a different LRECL. Remove the LRECL for the output data set if you're specifying it. If you're using an OLD data set that already has an LRECL, switch to using a new data set without an LRECL, so sort can set the correct LRECL.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Tue Jul 20, 2010 2:09 am
Reply with quote

Thanks Frank.
I was trying to increase the Amount field. I tried increasing IIIT and it worked fine.

Thanks
Vinu
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:

Back to Top