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

Subtract the ZD fields to provide negative sign in output


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Balaryan
Warnings : 2

New User


Joined: 20 Nov 2009
Posts: 27
Location: chennai

PostPosted: Wed Oct 11, 2017 10:51 pm
Reply with quote

Hi All,

I am trying to perform an arithmetic operation using two decimal fields in records to have the desired result. but somehow, its not working for me. I am not sure what mistake I am doing.

My requirement is to match two files based on two fields. if it matches, then i should perform subtraction of decimal field for first record (for e.g : 0003.0493) from file1 and decimal field (for eg : 0000.9589) to have the result 0002.0904 in output file.

Code:

Input file 1:

INPUT  |0001|0000000001_001|0000000001|0003.0493|0003.0493|
INPUT  |0001|0000000002_001|0000000002|0002.7800|0002.7800|
INPUT  |0001|0000000003_001|0000000003|0001.4200|0001.4200|
INPUT  |0001|0000000004_001|0000000004|0001.3600|0001.3600|
INPUT  |0001|0000000005_001|0000000005|0001.7800|0001.7800|
INPUT  |0001|0000000006_001|0000000006|0004.7200|0004.7200|

Input file 2:

0001|0000000001|10/10/2017|00000.9589
0001|0000000002|10/10/2017|00000.1054
0001|0000000003|10/10/2017|00000.2042
0001|0000000004|10/10/2017|00001.5800
0001|0000000005|10/10/2017|00000.0400

output file:
------------

INPUT  |0001|0000000001_001|0000000001| 0002.0904|0003.0493|0000.9589
INPUT  |0001|0000000002_001|0000000002| 0002.6746|0002.7800|0000.1054
INPUT  |0001|0000000003_001|0000000003| 0001.2158|0001.4200|0000.2042
INPUT  |0001|0000000004_001|0000000004|-0000.2200|0001.3600|0001.5800
INPUT  |0001|0000000005_001|0000000005| 0001.7400|0001.7800|0000.0400

JCL:
====

//STEP002  EXEC PGM=SORT                                           
//SORTJNF1 DD DISP=SHR,DSN=input file 1
//SORTJNF2 DD DISP=SHR,DSN=input file 2
//*                                                               
//SORTOUT  DD DSN=ouput file,
//            DISP=(,CATLG,DELETE),UNIT=STOR,                     
//            DCB=(BLKSIZE=0,LRECL=069,RECFM=FB),                 
//            SPACE=(CYL,(900,300),RLSE)                           
//*                                                               
//SYSOUT   DD SYSOUT=*                                             
//SYSPRINT DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  SORT FIELDS=(09,04,CH,A,29,10,CH,A)                             
  JOINKEYS FILE=F1,FIELDS=(29,10,A,09,04,A)                       
  JOINKEYS FILE=F2,FIELDS=(06,10,A,01,04,A)                       
  JOIN UNPAIRED,F1,F2                                             
  REFORMAT FIELDS=(F1:1,59,F2:29,09,?)                             
  INREC  IFTHEN=(WHEN=(69,01,CH,EQ,C'1'),                         
    BUILD=(01:01,59,C'0000.0000')),                               
    IFTHEN=(WHEN=(69,01,CH,EQ,C'B'),                               
    BUILD=(01:01,39,40:(50,09,ZD,SUB,60,09,ZD),                   
           EDIT=(STTTT.TTTT),LENGTH=10,50:39,20)),                   
  IFOUTLEN=69
//*                                                               



Also, for the fourth record, it should display the negative value by subtracting 0001.3600 - 0001.5800. But When i executed this piece of code, i am getting S0C7 abend.

Appreciate your time.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 11, 2017 11:48 pm
Reply with quote

The DFSORT Application Programming Guide manual, in the Data format descriptions paragraph, tells you EXACTLY why you got the ABEND (emphasis added by me):
Quote:
ZD (zoned decimal, signed). Each digit of the decimal number is converted into its 8-bit EBCDIC representation. The sign indicator replaces the first four bits of the low order byte of the number.

Example: -247 becomes
2 4 - 7 Decimal
F2 F4 D7 Hexadecimal
11110010 11110100 11010111 Binary
The number +247 becomes
F2 F4 C7
11110010 11110100 11000111
Note:

The following are treated as positive sign indicators: F, E, C, A, 8, 6, 4, 2, 0.
The following are treated as negative sign indicators: D, B, 9, 7, 5, 3, 1.
For SUM processing, 0 through 9 for the sign or A through F for a digit results in a data exception (0C7 ABEND). For example, a ZD value such as 3.5 (X'F34BF5') results in an 0C7 because B is treated as an invalid digit. ICETOOL's DISPLAY or VERIFY operator can be used to identify ZD values with invalid digits. ICETOOL's VERIFY operator can be used to identify ZD values with invalid signs.
The first four bits of the last digit is the sign indicator. The first four bits of each other digit is ignored. Thus the EBCDIC strings '0025' and ' 25' are both treated as 25 because a leading blank (X'40') is equivalent to a 0 digit (X'F0').
Try using SFF instead of ZD.
Back to top
View user's profile Send private message
Balaryan
Warnings : 2

New User


Joined: 20 Nov 2009
Posts: 27
Location: chennai

PostPosted: Thu Oct 12, 2017 12:47 am
Reply with quote

Thanks, Robert. That serves the purpose. My bad, I didn't take an effort to go through the documentation. Appreciate your time and information. It really worked.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Thu Oct 12, 2017 2:54 am
Reply with quote

1) You can ignore characters like '.' (but handle '+', and '-') when specifying format SFF instead of ZD. You also may need to practice with correct assumed position of decimal point.

2) Syntax error: must be EDIT=(ITTTT.TTTT); and also parameter SIGNS=... is needed to mark negatives with minus

3) Case WHEN=(69,01,CH,EQ,C'2') is not handled

4) For debugging purposes you can temporary add converted field values (before subtraction) into your output:
Code:
BUILD=(01,39,                         
       50,09,SFF,                     
       60,09,SFF,                     
       (50,09,SFF,SUB,60,09,SFF),     
          EDIT=(ITTTT.TTTT),SIGNS=(,-,,),LENGTH=10,
       39,20)),                       
     .......


Please, complete testing, and debugging.
Back to top
View user's profile Send private message
Balaryan
Warnings : 2

New User


Joined: 20 Nov 2009
Posts: 27
Location: chennai

PostPosted: Thu Oct 12, 2017 3:03 am
Reply with quote

Yes Sergeyken. Agree with you completely. Also, I had used the below code to achieve the result to handle negative

EDIT=(STTTT.TTTT),SIGNS=(' ',-),LENGTH=10
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
No new posts XL C Trace Preprocessor Output All Other Mainframe Topics 3
Search our Forums:

Back to Top