View previous topic :: View next topic
|
Author |
Message |
Prayag P V
New User
Joined: 03 Dec 2015 Posts: 6 Location: India
|
|
|
|
I have a requirment.
Read a record, and find a 5 byte string starting with 'Q' (eg: Q$A12), and delete the string from record.
This 5 digit string can be present anywhere in the record.The string starting with 'Q' and rest of the 4 bytes can be vary. My record length is 15 bytes.
I have to do this in JCL.
Example:
Input:
ABCDEFG123QABC2
HAIQ&A12ACMATLK
Output:
ABCDEFG123
HAIACMATLK
Thanks in advance |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
PARSE and BUILD. Is there always a Q? Will it always be followed by four characters? |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Cannot be done "in JCL". Maybe using your sort product - moving topic.
Please learn how to use the code tags for the presentation of code and data. You found out how to use the BOLD tags so the code tags should be easy! |
|
Back to top |
|
|
Prayag P V
New User
Joined: 03 Dec 2015 Posts: 6 Location: India
|
|
|
|
Bill Woodger wrote: |
PARSE and BUILD. Is there always a Q? Will it always be followed by four characters? |
Yes.. Always it start with 'Q', and it will be always followed by four characters. |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Quote: |
Yes.. Always it start with 'Q', and it will be always followed by four characters. |
The question is whether all the records will have 'Q****' ?
What do you want to do if there is No 'Q****' ?
I believe you would also need to use IFTHEN=(WHEN and OVERLAY after PARSE and BUILD (inrec) to get your desired result as the output.
. |
|
Back to top |
|
|
Prayag P V
New User
Joined: 03 Dec 2015 Posts: 6 Location: India
|
|
|
|
RahulG31 wrote: |
The question is whether all the records will have 'Q****' ?
What do you want to do if there is No 'Q****' ?
I believe you would also need to use IFTHEN=(WHEN and OVERLAY after PARSE and BUILD (inrec) to get your desired result as the output.
. |
If the record have 'Q****', then delete that string or replace with ' '(spaces).
If there is no 'Q****' in the record, then no need to do anything.(write the actual data to output)
Thanks in advance |
|
Back to top |
|
|
boyti ko
New User
Joined: 03 Nov 2014 Posts: 78 Location: Malaysia
|
|
|
|
you can try this on command line while editing/viewing the file if you need it quick for a few records.
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Editing yes, viewing not.
will insert a space.
will remove the text[/quote] |
|
Back to top |
|
|
boyti ko
New User
Joined: 03 Nov 2014 Posts: 78 Location: Malaysia
|
|
|
|
Actually I tried it in VIEW mode..
Code: |
VIEW XXXXXXXX.XXXXXXXX.BOYTI(TEST) - 01.04 Columns 00001 00072
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001 ABCDEFG123QABC2
000002 HAIQ&A12ACMATLK
****** **************************** Bottom of Data **************************** |
then did this command:
Code: |
VIEW XXXXXXXX.XXXXXXXX.BOYTI(TEST) - 01.04 CHARS 'Q====' changed
Command ===> Scroll ===> CSR
****** ***************************** Top of Data ******************************
==CHG> ABCDEFG123
==CHG> HAI ACMATLK
****** **************************** Bottom of Data **************************** |
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Quote: |
Actually I tried it in VIEW mode.. |
Yes - but that is only temporary. If you do a simple F3 out of view any changes are not saved. You have to issue a REPLACE or CREATE command |
|
Back to top |
|
|
boyti ko
New User
Joined: 03 Nov 2014 Posts: 78 Location: Malaysia
|
|
|
|
Ohh I see, so that's what you meant, because in our shop, we got VS or VSAVE shop-specific command to do SAVE in case we are on VIEW mode. That's why I had taken the habit of viewing only the files.
Anyways, Just what the others told to use PARSE and BUILD, Im thinking that maybe this can be resolve by doing something like this.
%00 - PARSE the string before Q.
%01 - PARSE the string with Q and 4 characters
%02 - PARSE the remaining
Then BUILD %00 and %02.. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
That's essentially it, but it will need a SQZ as well (all PARSEd fields have a FIXLEN). Discovered later that data can contain blanks as well, so those need to be protected. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Noting that despite the samples provided, the input can contain blanks.
Nothing that Q followed by fewer than four should not occurs, but dealing with that possibility.
Code: |
OPTION COPY
INREC IFOUTLEN=15,
IFTHEN=(WHEN=INIT,
FINDREP=(IN=C' ',
OUT=X'FE')),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=C'Q',
OUT=X'FD',
STARTPOS=12)),
IFTHEN=(WHEN=INIT,
PARSE=(%00=(ENDBEFR=C'Q',
FIXLEN=15),
%01=(SUBPOS=1,
STARTAT=C'Q',
FIXLEN=5),
%02=(FIXLEN=10)),
BUILD=(%00,
X'FEFEFEFEFE',
%02)),
IFTHEN=(WHEN=INIT,
OVERLAY=(1,30,
SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=X'FE',
OUT=C' ')),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=X'FD',
OUT=C'Q'))
|
The above will chance Qxxxx to five blanks. To remove (shift subsequent bytes (if any) left and right-pad with space (if necessary), simply deleted the line with X'FEFEFEFEFE', and change 30 to 25 in the OVERLAY.
Ensure the output is 15 bytes. Change original blanks to a non-display value. Change Q at or after position 12 to a diffetrent non-display value. PARSE to a maximum of three fields (prior to Q, five from Q, residue). BUILD a new record (30 bytes) and use OVERLAY with SQZ to get rid of blanks. Change blank-value back to blank, and Q-value back to Q.
%00 will be all blank (when Q is at position one) up to 15 bytes (when there is no Q). When Q is present but not at position one, %00 will contain all the bytes up to the Q and will be space-padded to a total length of 15.
%01 will be space when there is no Q in the first 11 positions of the input, otherwise will be bytes of length five.
%02 will be space when there is no Q in the first 11 positions of the input, and space when the Q is in position 11, otherwise it will contain the residue after the five characters including Q have been recognized. |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Bill, I am not sure why we are changing C'Q' to X'FD' and using a X'FEFEFEFEFE' in BUILD ?
I am using below mentioned and I think it works fine. Any comments?
Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
FINDREP=(IN=C' ',
OUT=X'FE')),
IFTHEN=(WHEN=INIT,
PARSE=(%00=(ENDBEFR=C'Q',FIXLEN=15),
%01=(ADDPOS=4,FIXLEN=15))),
IFTHEN=(WHEN=INIT,
OVERLAY=(%00,%01,1:1,30,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=X'FE',
OUT=C' ')) |
. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
For the first it is to ensure that Qxxx and Qxx and Qx and Q don't get changed (since only Qxxxx is supposed to be changed).
For the second, TS/OP is not totally clear as to whether the located text is to be "deleted" or replaced by space.
The OVERLAY in place of BUILD is OK. There is no chance that any data will be "left over" from the original record. The two PARSE fields instead of three is good, you can use FIXLEN=10 on the second and then the 1,30 can be 1,25.
The "space" version should fit in with this as well (just add the constant, and put the 1,25 back to 1,30). |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Thanks for making it clear to me. |
|
Back to top |
|
|
Prayag P V
New User
Joined: 03 Dec 2015 Posts: 6 Location: India
|
|
|
|
Thanks all..
Especially Bill Woodger and RahulG31
Yours code working fine |
|
Back to top |
|
|
|