formatting a numeric field in input file

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
BANUREKHAB
Member
Posts: 6
Joined: Thu Nov 08, 2012 12:56 am

formatting a numeric field in input file

Post by BANUREKHAB » Fri Sep 02, 2016 12:17 am

Hi,

we get a input file from a different appilcation in the below format, X(18 byte

-131.1
290.05
265.07
251.52
252.37
281.78
304.78
421.37
418.1
354.66
361.05
254.33
277.33
68.64
125


My requirement is to convert this in to s9(16)v9(2) format. Is this possible. Please help.

magesh_j
Member
Posts: 16
Joined: Wed Aug 31, 2016 8:32 am

Post by magesh_j » Fri Sep 02, 2016 7:36 am

Assuming LRECL=80, use the below code

Code: Select all

OPTION COPY                                                          
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'-'),                                 
              PARSE=(%00=(ENDBEFR=C'.',ENDBEFR=C' ',FIXLEN=16,PAIR=QUOTE),        
                     %01=(FIXLEN=2)),                                
              BUILD=(%00,UFF,ZD,LENGTH=16,                           
                     %01,81:C'-')),                                  
                                                                     
       IFTHEN=(WHEN=NONE,                                            
               PARSE=(%02=(ENDBEFR=C'.',ENDBEFR=C' ',FIXLEN=16,PAIR=QUOTE),       
                      %03=(FIXLEN=2)),                               
               BUILD=(%02,UFF,ZD,LENGTH=16,                          
                      %03,81:C' '))                                  
                                                                     
OUTREC IFTHEN=(WHEN=(17,2,CH,EQ,C' '),OVERLAY=(17:C'00'),HIT=NEXT),  
                                                                     
       IFTHEN=(WHEN=(18,1,CH,EQ,C' '),OVERLAY=(18:C'0'),HIT=NEXT),   
                                                                     
       IFTHEN=(WHEN=(81,1,CH,EQ,C'-'),                               
               OVERLAY=(1,18,ZD,MUL,-1,ZD,LENGTH=18)),               
       IFOUTLEN=80                                                                                        
Thanks
Magesh

magesh_j
Member
Posts: 16
Joined: Wed Aug 31, 2016 8:32 am

Post by magesh_j » Sat Sep 03, 2016 5:39 am

BANUREKHAB,
Also let us know if you need

Code: Select all

418.1 to be 418.10

or

418.1 to be 418.01

I assumed to be

Code: Select all

418.1 to be 418.10
Regards,
Magesh

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Sep 05, 2016 10:22 am

For reversing the sign of a value, subtracting from zero is more efficient than multiply by minus one.

magesh_j
Member
Posts: 16
Joined: Wed Aug 31, 2016 8:32 am

Post by magesh_j » Mon Sep 05, 2016 7:38 pm

Also we can move the values and decimal and symbol seperately in 81:%00,%01,c'+1'

IFThen=(when=(1,16,ss,eq,c'-'),overlay=(99:c'-'))

Then read 81,19,sff,zd,length=18 will make more easy.

We haven't got anything from op. Left as is.

Thanks
Magesh

BANUREKHAB
Member
Posts: 6
Joined: Thu Nov 08, 2012 12:56 am

Post by BANUREKHAB » Tue Sep 06, 2016 8:48 pm

Thank you very much and very sorry for the late reply. This is exactly what i needed.

My input file,

100402.24
1006961.9
103761.05
-100.31
170855.35
183
-159711.81
155213.69
152236.93
161383.16

After using the sort provided,

SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'-'),
PARSE=(%00=(ENDBEFR=C'.',ENDBEFR=C' ',FIXLEN=16,PAIR=QUOTE),
%01=(FIXLEN=2)),
BUILD=(%00,UFF,ZD,LENGTH=16,%01,81:C'-')),
IFTHEN=(WHEN=NONE,
PARSE=(%02=(ENDBEFR=C'.',ENDBEFR=C' ',FIXLEN=16,PAIR=QUOTE),
%03=(FIXLEN=2)),
BUILD=(%02,UFF,ZD,LENGTH=16,%03,81:C' '))
OUTREC IFTHEN=(WHEN=(17,2,CH,EQ,C' '),OVERLAY=(17:C'00'),HIT=NEXT),
IFTHEN=(WHEN=(18,1,CH,EQ,C' '),OVERLAY=(18:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(81,1,CH,EQ,C'-'),
OVERLAY=(1,18,ZD,SUB,-0,ZD,LENGTH=18 )),
IFOUTLEN=400

Output:
000000000010040224
000000000100696190
000000000010376105
00000000000001003J
000000000017085535
000000000000018300
00000000001597118J
000000000015521369
000000000015223693
000000000016138316


Thank you again. I will modify it for subtract from zero instead of multiplying by -1.

magesh_j
Member
Posts: 16
Joined: Wed Aug 31, 2016 8:32 am

Post by magesh_j » Tue Sep 06, 2016 9:22 pm

BANUREKHAB,

Start using code tags. which will help people to read it better.

Code: Select all

[ code ] ur code [ / code ]

Regards,
Magesh

magesh_j
Member
Posts: 16
Joined: Wed Aug 31, 2016 8:32 am

Post by magesh_j » Tue Sep 06, 2016 9:22 pm

BANUREKHAB,

Start using code tags. which will help people to read it better.

Code: Select all

[ code ] ur code [ / code ]

Regards,
Magesh

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others