I have a file with each record of length 4 characters.
• All the records are left justified
• The record can be a string or a whole number or a decimal number
• There is no sign, the numbers are always positive
This file needs to sorted such that
The records with value string are at the top
followed by numerical values sorted in ascending order.
There is no option in SORT to automatically recognize free-text decimal fractioned values, or left-aligned numeric values in the manner TS wants it. Formats like UFF etc. do not recognize decimal points, and ignore them. Formats like CH do consider numeric values as simple characters. Formats like ZD do not accept anything except digits '0'-'9'.
Some time ago I've posted a related example: how to parse unaligned decimal fractioned values using SORT tools.
But I suggest the TS to try something by himself using given hints, before giving him a ready-to-use solution.
Looks like the most part of topic starters here are not interested neither in learning, nor in trying something by themselves, isn't it?
They are waiting for a ready-to-use solution OF THEIR JOB to be presented to them FREE OF CHARGE?
Code:
//*==================================================================
//* PROCESS FREE TEXT
//*==================================================================
//FREETEXT EXEC PGM=SYNCSORT
//*
//SYSOUT DD SYSOUT=*
//*
//SORTIN DD *
8999
bbbb
299
abcc
92 <===
0.1
5.7 <===
9999
cefd
1
1.9
//*
//SORTOUT DD SYSOUT=*
//*
//SYSIN DD *
* Add control fields based on three categories of input records
* CASE 1: no digits; consider simple string
INREC IFTHEN=(WHEN=(1,4,SS,NE,L(C'0', |
C'1', | none
C'2', |
C'3', | of any digit
C'4', |
C'5', | present?
C'6', |
C'7', |
C'8', |
C'9')), |
BUILD=(1,80, original record
4X, blank whole digit part
4X, blank fractional part
1,4)), non-digit, character value
* CASE 2: some digits, and decimal point: consider non-whole number
IFTHEN=(WHEN=(1,4,SS,EQ,C'.'), decimal point present?
PARSE=(%1=(ENDBEFR=C'.',FIXLEN=4), whole part
%2=(ENDBEFR=BLANKS,FIXLEN=4)), fraction part
BUILD=(1,80, original record
%1,JFY=(SHIFT=RIGHT), right-aligned whole part
%2,JFY=(SHIFT=LEFT), left-aligned fraction part
4X)), blank character value
* CASE 3: some digits, no decimal point: consider whole number
IFTHEN=(WHEN=NONE, otherwise: whole number
BUILD=(1,80, original record
1,4,JFY=(SHIFT=RIGHT), right-alighned whole part
4X, blank fraction part
4X)) blank character value
*
* re-order on created control fields
SORT FIELDS=(81,4,CH,A, whole number, if present
85,4,CH,A, fractional part, if present
89,4,CH,A) character part, if non-numeric
*
OUTREC BUILD=(1,80) restore original record
*
END
//*
Code:
********************************* TOP OF DATA *********
abcc
bbbb
cefd
0.1
1
1.9
5.7 <===
92 <===
299
8999
9999
******************************** BOTTOM OF DATA *******
It is not recommended to code the statements (in any language) in this "compacted" style.
If you do so to save 5 minutes today, then hard time in the future is guaranteed.
TS requirements in the very first post states this clearly, so what you said will not be a possible option and even if it is possible then TS can add SQZ=(SHIFT=LEFT) as first INREC statement and I assumed it to be Dec(3,2).
Quote:
• All the records are left justified
This will take care of that but not need if they are already LEFT justified.