I recently came across with a requirement in which, file has account number. Requiremnet was to mask alternate charcters with "X".If any space encountered in between, masking need to reset and start again.For example
Eg 1:-
I/p:-
12345 678
O/p:-
1X3X5X 6X8--After "5" we have a blank so masking rest and started again.
Eg 2:-
12345678
1X3X5X7X
Eg 3:-
A1234
O/p
AX2X3X.
I know if we have fixed size we can harcode using OUTREC FIELDS=(1:1,...). But size of field can vary from 5 to 15 Bytes max. Meaning one time it will be 5 bytes next time it will be 10 bytes and so on. Can we do it using DFSORT?
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Quote:
Requiremnet was to mask alternate charcters with "X".If any
space encountered in between, masking need to reset and start again.
Your description of the rules is subject to some questions.
Can there only be one blank between groups of characters or can there be more than one blank? If more than one blank between groups, should all the blanks be kept or only one?
Can the size of each group of characters vary from 5 to 15 bytes, or can the total number of characters vary from 5 to 15 bytes?
Could you have something like:
Code:
1 2 3 4
so that no masking would be needed?
What is the RECFM and LRECL of the input file?
It would help if you would show a better example of input and expected output for all possible cases you have to handle and use ubb code tags so we can see where the spaces are.
Thanks for reply. Please find below for the questions asked.
Quote:
Q)Can there only be one blank between groups of characters or can there be more than one blank? If more than one blank between groups, should all the blanks be kept or only one?
A) Yes there can be multiple blanks between Group(s).If multiple spaces found single space need to be retained and rest of spaces need to be masked.Pls see Example 3.
LRECL/RECFM 80/FB
I/P- Example with three Groups(Group1- 1234,Group2 -A5678,Group3-B4567. Only one space with be there between the groups.If multiple spaces found then First Space with treated as space and rest will be treated as characters for masking. Pls see example 3.
Note:- At a single point of time there can be max of 10 Records with combinations mentioned in below examples.Meaning Records with single group or records with multiple groups or records with mix of single or mutliple records.
Code:
Ex:1
1234 A5678 B4567
O/P
1X3X AX6X8 BX5X7
EX 2 i/p- Single Group with 15 Characters
Code:
ABC123456789045
o/p
AXCX2X4X6X8X0X5.
EX 3- Groups with multiple spaces in between.
Code:
A123 B1234 C1-123
O/P
AX2X XBX2X3 CX-X2X---> Two spaces found between group1 and group2 but first space is treated as itself and masking started from second space considering, space as a character.Its kind of string delimited by first occurance of space.
q)Can the size of each group of characters vary from 5 to 15 bytes, or can the total number of characters vary from 5 to 15 bytes?
a) No Not groups. Only the characters vary from 5 to 15 Bytes.Meaning 5- 15 charactesr can be in single group or in multiple group.But max characters will be 15.
Yes requirement was completed thru COBOL. But was curious to know how would it have been done in DFSORT,if we have single spaces in between Group(s).Could you please share your views.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
jsk wrote:
EX 3- Groups with multiple spaces in between.
Code:
A123 B1234 C1-123
O/P
AX2X XBX2X3 CX-X2X---> Two spaces found between group1 and group2 but first space is treated as itself and masking started from second space considering, space as a character.Its kind of string delimited by first occurance of space.
Did you have a typo in the above example? Shouldn't the second part be XBX2X4 instead of XBX2X3 . Also there are 2 spaces between the 2nd and 3rd word shouldn't it be XCX-X2X as explained in example 4?
OUTREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'XXXXXXXXXXXXXX',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X X X X X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X X X X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X X X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'X X',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'@$',C' '))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'$ ',C' '))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'$ ',C' '))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'@',C'X'))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C' X ',C''))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C' ',C' ')))
//*
Step1:- Identify groups with single space and multiple space and mask it with " @" for double space and "$" for single space using Find and Replace function.
Step2:-Build the reformated record with " @" and "$" so that making can be done based on " @" and "$".
Strep3:- Mask Alternate Char with "X" based on condition.
Step4:- Reformat the records by removing unwanted masking done at end of records.
Belive I am in right track. Skolusu can put more views on this.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
Frank Yaeger wrote:
The student long ago surpassed the teacher.
But at least the teacher was smart enough to hire the student.
Thank you Frank. The student is still wet behind the ears and has a very long way to go to even be compared with the master.
sqlcode1 wrote:
Excellent!!!!
Escapa wrote:
Good one Kolusu
Thank you
gylbharat wrote:
Wow... Excellent..Skolusu, Can you please also explain the logic of the above solution?
I think JSK has pretty much covered it. The only trick in that solution is to identify the double space and retain the first space as a seperate character. The first FINDREP does that. The second FINDREP takes care of single space records. Once we get that then it is easy to split the records into words delimited by space. Then a bunch of ifthen statements are used to mask out even or odd numbered characters checking if the first character is a space or not. once the masking is completed we now try to squeeze everything back to as it is with another set of FINDREPs and replace the double space and single space characters to their original format.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
glypharat wrote:
Thanks Skolusu...
But i have not understood why we are testing on Fixed positions like 1,17,33 etc for '@' ?
The best way to understand the job is to run the job with 1 IFTHEN statement and check the results of it. Run these 3 jobs and check the output after each run. The output from the 3rd job will make u understand as to why I am checking on fixed positions.