mask the middle number using the JCL - dfsort

i have requrement like this. could you please help any one help me?
i have 16 digit length fileld in my input file. if more than 13 digit length then first 4 digit as it is and last 4 digits as it is and mask the remaining the number
if less than 13 then keep the number as it is.
example
IP file
0000359681243354
0000359681243354
810176733
OP
00003̶5̶9̶6̶8̶1̶2̶4̶3354
00003̶5̶9̶6̶8̶1̶2̶4̶3354
810176733

Edit 1:
As per #NicC's suggestions in the Comments section of this answer, you may try the following code:
INREC IFTHEN=(WHEN=INIT,BUILD=(1,16)),
IFTHEN=(WHEN=(13,1,CH,NE,X'40',AND,13,1,CH,NE,X'00'),OVERLAY=(5:8C'-'))
SORT FIELDS=COPY
Alternatively, you may also try the following code.
Firstly, we use OUTFIL with FTOV,VLTRIM=C' ' to convert the input records to VB with an RDW. This is helpful because we can access the RDW to get the length of data upto first nonblank character. But, how to access the RDW? See next step.
Secondly, we build a record in T2 file, with actual data, followed by the length of the data (RDW is in 1,2,BI. Subtract 4 from 1,2,BI to get the length of data).
Lastly, use INREC IFTHEN to check if the length of the data is GE 13 or not. Format data as required.
Note: Following code needs to be changed for DD names, position of the 16 digit length field and other input fields in the record.
//STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file (FB)
//TEMP1 DD DSN=&&TEMP1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//TEMP2 DD DSN=&&TEMP2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=... output file (FB)
//TOOLIN DD *
COPY FROM(IN) USING(CTL1)
COPY FROM(TEMP1) TO(TEMP2) USING(CTL2)
COPY FROM(TEMP2) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=TEMP1,FTOV,VLTRIM=C' '
/*
//CTL2CNTL DD *
OUTFIL FNAMES=TEMP2,VTOF,
BUILD=(5,16,X,1,2,BI,SUB,+4,TO=ZD,LENGTH=2)
/*
//CTL3CNTL DD *
INREC IFTHEN=(WHEN=(18,2,ZD,GE,13),BUILD=(1:1,4,5:8C'-',13:13,4),
IFTHEN=(WHEN=(18,2,ZD,LT,13),BUILD=(1:1,6))
SORT FIELDS=COPY

Related

If else in sort JCL

I have a two requirements:
I must concatenate some fields from a file in a Cobol program. The way i must concatenate is based on one of the aforementioned field. The concatenated fields must be outputted in a new file.
I must then sort this new file with a sort utility invoked by JCL.
The Issue
I need to sort same file for 2 conditions. I have tried with ifthen outrec build. How can I sort it in one pass?
Here is a source-code example :
ID DIVISION.
PROGRAM-ID. FOO.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
Select Infil assign to inp001.
Select Outfil assign to out001.
DATA DIVISION.
FILE SECTION.
FD Infil.
01 Main.
03 A.
05 ws-Pc. Pic x(1).
05 filler Pic x(5).
03 B. Pic x(4).
03 C. Pic x(4).
03 D. Pic 9(13)V99.
03 E. Pic x(13).
FD Outfil.
01 Temp Pic x(42).
WORKING-STORAGE SECTION.
01 file-flag Pic x(01).
88 file-end value 'Y'.
88 not-file-end value 'N'.
PROCEDURE DIVISION.
Open input Infil
Open output Outfil
read Infil
at end
set file-end to true
not at end
set not-file-end to true
end-read
Perform until file-end
If ws-Pc = 3
String A B C Delimited by size
into Temp
End-String
Else
String A B C E Delimited by size
into Temp
End-String
End-if
Write Temp
read Infil
at end
Set file-end to true
end-read
end-Perform.
end program foo.
Here is the logic I need for the sort utility :
If ws-Pc=3
Sort(fieldA,fieldB)
Else
Sort(fieldA,fieldB,fieldE)
End-if.
I can propose you three variations :
If you are sure that your last 13 characters are the same (spaces for instance) in the case without a field E (ws-pc equal to three) you can just have this sysin:
SORT FIELDS=(1,6,CH,A,7,4,CH,A),EQUALS
Indeed, thanks to the equals all your inputs will keep their relative order once sorted. For the case ws-pc=3 it will be sorted according to field A and B. Field E plays no importance because it is the same for all.
If you are not sure that the last 13 characters are the same you can do it yourself:
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),BUILD=(1,14,13X))
SORT FIELDS=(1,6,CH,A,7,4,CH,A),EQUALS
This will force your last characters to be spaces.
If you don't want to use the "EQUALS" you can create your own ordering by appending a line number in the field E when it is unused. You then have to remove it.
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),BUILD=(1,14,SEQNUM,13,ZD))
SORT FIELDS=(1,6,CH,A,7,4,CH,A)
OUTREC IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),BUILD=(1,14,13X))

JCL SORT SQZ shift left using build

I have 2 input files. I merged them using JOINKEY. The first input file countains a record count (lenght of 10 with leading zeroes).
The second file, is just comma separated fields between double quote (ex ''xxxx'',''yyyy'',etc).
The problem I got is I want to get rid of the leading zeroes from the records count of the first input file.
My count is 0000000012, I will like to have 12.
I don't understand how to handle it with SQZ function since it will be a variable lenght. How can we handle it in the OUTREC BUILD since it will not be a fix length of 10 anymore but a variable length if I use SQZ function?
Thanks for your help.
Here is the JCL:
//SORT100 EXEC PGM=SORT
//*
//SORTJNF1 DD *
Counter written records: 0000000012
//SORTJNF2 DD
DSN=INPUT.WITHOUT.COUNT,DISP=SHR
//SORTOUT DD DSN=OUTPUT.WITH.COUNT,
// DISP=
(,CATLG),RECFM=FB,LRECL=130,DATACLAS=DCPRXTP
//SYSIN DD *
SORT FIELDS=COPY
JOINKEYS FILE=F1,FIELDS=(131,8,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(131,8,A),SORTED,NOSEQCK
REFORMAT FIELDS=(F2:1,80,F1:30,10)
OUTREC BUILD=(1,80,81,10,C'," "',36X)
//JNF1CNTL DD *
INREC OVERLAY=(131:SEQNUM,8,ZD)
//JNF2CNTL DD *
INREC OVERLAY=(131:SEQNUM,8,ZD)
//*
//SYSOUT DD SYSOUT=*
//

Reading in dates using informats in SAS when raw data is messy

I am essentially trying to read messy data into SAS using informats and having problems. I have column of data of the following form in a raw txt file, say:
RegDate
0
0
16/10/2002
20/11/2003
0
For RegDate, 0 = missing, otherwise the date is present. I would like to read this data into SAS, giving 'NA' for the zeros and the date for the date, and output into a dataset.
If all dates were present, I could use the code
data test;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "&pathlocation" delimiter='09'x
MISSOVER DSD firstobs=2 ;
informat RegDate ddmmyy10. ;
format RegDate ddmmyy10. ;
input
RegDate;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
However I cannot read the above text file doing this as it does not take into account the zeros, as the informat is set to read in dates.
If using a proc import statement
proc import datafile="&pathlocation" out=test dbms=tab replace;
run;
it tries to use a best32. informat, as there is a zero in the first row. The dates cannot then be read in.
So I need to create a custom format of some sort. I can do this for a numeric informat alone or a character informat alone, or a picture informat (which is needed for the dates?). I cannot figure out how to combine multiple formats for one variable. I'm sure the solution is very simple however I cannot find it online so I apologise if this is obvious. Is there either a way to a) put some IF-THEN statement into the format so that it does different things depending on the input b) read the data in purely as text so that the formats need to be used.
NA's are text and not valid in SAS - they're used in R. To indicate that the value is missing for a numeric variable SAS uses a period (.). Reading the data in with your code assigns the 0 to missing which would be an appropriate read of the data.
If you want NA you'll need to read or convert the data to text, but then your dates will be text and you'll be limited in what you can do with them, for example no date calculations.
If you really want you could display it that way using a nested format.
proc format;
value na_date_fmt
low-high = [ddmmyy10.]
. = "NA";
run;
data have;
infile cards dsd;
informat regDate ddmmyy10.;
format regDate ddmmyy10.;
format newDate na_date_fmt.;
input regdate;
newDate=regdate;
cards;
0
0
16/10/2002
20/11/2003
0
;
run;
proc print data=have;
run;
You can add an IF statement to the DATA step, like this:
data test;
infile "&pathlocation" delimiter='09'x
MISSOVER DSD firstobs=2 ;
informat RegDate ddmmyy10. ;
format RegDate ddmmyy10. ;
input
RegDate;
if RegDate = 0 then RegDate = .;
run;
The output is
RegDate
.
.
16/10/2012
20/11/2003
.

JOINKEYS REFORMAT field for a VB file for F2 is not working

I am trying to right and left outer join these two RECFM VB files but
I don't get anything from the F2 file.
//STEP2000 EXEC PGM=SORT
//* JOIN
//*
//SYSOUT DD SYSOUT=*
//*
//SORTJNF1 DD DSN=YXX122.TEMP.EXPORT.TYPEN,
// DISP=SHR
//*
//SORTJNF2 DD DSN=YXX122.TEMP.EXPORT.TYPEC,
// DISP=SHR
//*
//SORTOUT DD DSN=YXX122.DYXX122.EXPORT.XSUM,
// DISP=(NEW,CATLG,DELETE),
// UNIT=(DEV,2),
// SPACE=(CYL,(150,20),RLSE),
// DCB=(RECFM=VB,LRECL=304,BLKSIZE=0)
//*
//SYSIN DD *
SORT FIELDS=COPY
JOINKEYS FILES=F1,
FIELDS=(13,4,A,18,5,A,17,1,A,23,1,A,33,8,A,41,4,A)
JOINKEYS FILES=F2,
FIELDS=(13,4,A,18,5,A,17,1,A,23,1,A,33,8,A,41,4,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:5,300)
OUTFIL FTOV
//
The problem is I can't find how the REFORMAT FIELDS the F2 file.
I tried with REFORMAT FIELDS=(F1:5,300,F2:5,300) but the outfile was with a length of 600.
I will like to know how to have both file F1 and F2 in my SORTOUT file with a VB length 304.
Any idea on how to fix this problem?
It turns out you have DFSORT, not SyncSORT which makes things simpler, as you can definitely use the Match Marker ? in the REFORMAT statement. Up-to-date SyncSORT may have the Match Marker as an undocumented feature.
Putting all the unmatched records on one OUTFIL may be confusing (you won't know which input they have come from).
This conceptualises your join (where the Output is the joined data, and b represents blank).
F1
A
C
E
F2
B
C
F
Output
Ab
bB
Eb
bF
So if you want B and F you need to specify some data from F2. You also need to identify the "blanks" so that you know which part of the REFORMAT record currently has data in (DFSORT has a Match Marker for this, SyncSORT does not).
For that you need to identify one byte which can never be blank in the record. If that is not possible, one byte which can never be another given value (which you specify on FILL= on the REFORMAT). Failing that, two or more bytes with the same characteristics. As a final fail-safe you can check the entire part of the REFORMAT record from one file or the other for blank.
Since you want V-type output, you could make your REFORMAT record variable:
REFORMAT FIELDS=(F1:1,4,?,F1:5,300,F2:5)
And use VLTRIM on OUTFIL.
Or fixed:
REFORMAT FIELDS=(F1:5,300,F2:5,300)
And use FTOV with VLTRIM on OUTFIL.
Then you need some code, which tests the byte/bytes/partofdata you have chosen for being space/thevalueyouhavechosen and uses BUILD to create a record which contains the data you want (plus trailing blanks/values which will be killed by the VLTRIM).
IFTHEN=(WHEN=(logicalexpression),
BUILD=(1,4,5,300)),
IFTHEN=(WHEN=NONE,
BUILD=(1,4,305,300))
Or
IFTHEN=(WHEN=(logicalexpression),
BUILD=(1,300)),
IFTHEN=(WHEN=NONE,
BUILD=(301,300))
Here's some code which does what you want. Probably. I can't test it with SyncSORT.
Data:
F1
A 11111111111111111111111111111111111
C 2222222222222222222222
E 3
F2
B 4444444444444444
C 55555555555555555555555555
F 6666666666666
Code:
OPTION COPY
JOINKEYS F1=INA,FIELDS=(5,1,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(5,1,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1,F2,ONLY
REFORMAT FIELDS=(F1:1,4,F1:5,76,F2:5)
OUTFIL FNAMES=EXT,VLTRIM=C' ',
IFTHEN=(WHEN=(81,1,CH,EQ,C'2'),
BUILD=(1,4,82)),
IFTHEN=(WHEN=NONE,
BUILD=(1,4,5,76))
The Match Marker, ?, will be set to 1 for unmatched F2, 2 for unmatched F2 and B for matched records (which you won't get, because of the ONLY on the JOIN statement).
This presumes your data is already in sequence. Remove the SORTED,NOSEQCK for data which is not in sequence.
I've used an LRECL of 80 and a simple key and some simple data.
Output:
For EXT:
A 11111111111111111111111111111111111
B 4444444444444444
E 3
F 6666666666666
SORTOUT would show the unchanged REFORMAT record. That is for you to see how it works. You can remove the FNAMES=EXT or remove the SORTOUT from the JCL when you understand everything.
The F1:1,4 ensures that the REFORMAT record is variable-length. The 5,300 should use blank-padding for shorter records. That's why you need the VLTRIM later. The F2:5 says "file two, position five, to the end of the file two record".
If your data can have genuine trailing blanks, you'll have to use FILL= and VLTRIM= for the same character.
IFTHEN=(WHEN=(logicalexpression) processing finishes when an IFTHEN is true. So the combination in the code is effectively an IF/ELSE.
See also this, Compare two files and write it to "match" and "nomatch" files and Sync sort, Unpaired records of File1 have spaces for no records in F2 file. Can we replace those specific column's spaces by ZEROS? for further examples.

Append data at end of existing data with SORT

I want the below code to work for variable length data also in input. So, that I can append double quote at its end. I don't want to use COBOL. Is it possible?
ZZZZ.VVVV.FILE.CORR1 contains following records:-
ABCDEFG_AAAAAA_BBB0001.csv
ABCDEFG_AAAAAA_BBB0002.csv
ABCDEFG_AAAAAA_BBB0003.csv
Output records in file ZZZZ.VVVV.FILE.CORR2 by following code is:
r_file1="ABCDEFG_AAAAAA_BBB0001.csv"
r_file2="ABCDEFG_AAAAAA_BBB0002.csv"
r_file3="ABCDEFG_AAAAAA_BBB0003.csv"
JCL code is:
//STEPSRT5 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=ZZZZ.VVVV.FILE.CORR1, <ID>
// DISP=SHR
//SORTOUT DD DSN=ZZZZ.VVVV.FILE.CORR2, <OD>
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0),
// SPACE=(27920,(29,6),RLSE),
// DISP=(NEW,CATLG,DELETE)
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1:C'r_file',7:SEQNUM,1,ZD,8:C'="',10:1,26,36:C'"',44X)
/*
SORT FIELDS=COPY
INREC BUILD=(C'r_file',SEQNUM,1,ZD,C'="',5,44,80:X)
OUTREC FINDREP=(STARTPOS=14,IN=C' ',OUT=C'"',DO=1)
This is not JCL by the way, They are SORT Control Cards. You find all the details in the manual for your site's SORT product.
INREC/OUTREC/OUTFIL can contain one only of BUILD, OVERLAY, IFTHEN or one or more IFTHENs. Two ways to do it since you want two functions used unconditionally is like the above, or with two IFTHEN=(WHEN=NONE with the function-use part of the IFTHEN.
Your records are not variable. They are fixed-length (or your existing code would not work) likely 80 bytes (if not 80, change the 80:X appropriately).
Bear in mind that you will get duplicate sequence-numbers with more than 10 input records (and the tenth is going to give you r_file0).
You could also look at SQZ (squeeze) since you have no embedded blanks in your data.
Try the following:
//STEP01 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC BUILD=(C'r_file',SEQNUM,3,CSF,C'="',1,68,C'"')
OUTREC BUILD=(1,80,SQZ=(SHIFT=LEFT))
/*
//SORTIN DD *
ABCDEFG_AAAAAA_BBB0001.csv
ABCDEFG_AAAAAA_BBB0002.csv
ABCDEFG_AAAAAA_BBB0003.csv
ABCDEFG_AAAAAA_0702.csv
ABCDEFG_AAAAAA_AAAYZ0702.csv
ABCDEFG_AAAAAA_BBB.csv
ABCDEFG_AAAAAA_XXXXXXXAMY0702.csv
ABCDEFG_AAAAAA_YZ0702.csv
ABCDEFG_AAAAAA_C0702.csv
ABCDEFG_AAAAAA_0702.csv
ABCDEFG_AAAAAA_702.csv
ABCDEFG_AAAAAA_02.csv
ABCDEFG_AAAAAA_2.csv
/*
//SORTMSG DD SYSOUT=*
//
SORTOUT will contain:
r_file1="ABCDEFG_AAAAAA_BBB0001.csv"
r_file2="ABCDEFG_AAAAAA_BBB0002.csv"
r_file3="ABCDEFG_AAAAAA_BBB0003.csv"
r_file4="ABCDEFG_AAAAAA_0702.csv"
r_file5="ABCDEFG_AAAAAA_AAAYZ0702.csv"
r_file6="ABCDEFG_AAAAAA_BBB.csv"
r_file7="ABCDEFG_AAAAAA_XXXXXXXAMY0702.csv"
r_file8="ABCDEFG_AAAAAA_YZ0702.csv"
r_file9="ABCDEFG_AAAAAA_C0702.csv"
r_file10="ABCDEFG_AAAAAA_0702.csv"
r_file11="ABCDEFG_AAAAAA_702.csv"
r_file12="ABCDEFG_AAAAAA_02.csv"
r_file13="ABCDEFG_AAAAAA_2.csv"
INREC builds a record something like:
r_file 10="ABCDEFG_AAAAAA_0702.csv "
The trick is to use CFS for the sequence number so that they are created with leading spaces, that way we do not get messed up trying to trim leading zeros as would required with ZD (SQZ with PREBLANK=C'0' to get rid of leading zeros just doesn't work - it gets rid of all zeros, including imbeded and trailing)
Next OUTREC squeezes the spaces out of the record leaving the file name as you require it to be presented.
Note: This solution assumes that your file names do not contain imbedded spaces. If they do, there is more tinkering to be done.

Resources