JCL to replace negative values with zeros

We can replace the negative values in input file with zeros. There are so many ways which we can do this. The following example explains the how SORT utility can be used to replace the negative values with zeros.

Assume that we have a following records in the input file.

Input file contents

Product Name
Stock available
Product1
+200
Product2
+100
Product3
-500
Product4
-250
Product5
+50
Input file contents

We can see that above file is having negative stocks for the products product3 and product4. Now our requirement is to replace these negative values with zeros. The desired outcome should be as shown below

Note: Header columns Product Name and Stock Available are not part of input file contents. These are added for illustration purpose only

Output file contents

Product Name
Stock available
Product1
+200
Product2
+100
Product3
+00000
Product4
+00000
Product5
+50
File contents after replace of negative values is done

JCL Code to replace negative values with zeros

//REPNGVAL JOB (X,XX,XXX),'MAIL ATT'MSGCLASS=F,CLASS=D, REGION=M

//STEP001 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=input file
//SORTOUT DD DSN=output file
//SYSIN DD *
SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=(11,1,CH,EQ,C'-'),
OVERLAY=(11:C'+00000')
/*
//********** END OF JOB**************************************

Assume that Product name in the input file is starting at position 1 with length 10 and Stock available is starting at position 11 with length 6.

Out of 6 bytes, which occupied by Stock available field first byte holds the + or - sign and the remaining 5 bytes holds the value of the stock available field.

More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working