Removing opening and closing bracket '[' & ']' using sor
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Utilities

#1: Removing opening and closing bracket '[' & ']' using sor Author: srihemzLocation: Chennai PostPosted: Fri Dec 16, 2016 9:21 am
    —
Hi All,

I have a requirement to strip opening and closing bracket of a field whose length is variable. Required field starts at position 5.

Sample Input (LRECL - 80)
Code:

1236 HI HI   HI
1236 OP QRS   TREND                 
4997 T UVW                   
4997 HI HOW ARE YOU     
1111 I'M FINE           
4991 COME[ON ] ]   
4998 [COME[ON ] ]       
4999 [AAB  CCDD [EEFF]  GGG IIIAREWAY]   
4955 [AAB  CCDD [EEFF  GGG IIIAREWAY]
4955 [AAB  CCDD EEFF]  GGG IIIAREWAY]
4955 [AAB  CCDD EEFF  GGG IIIAREWAY]

Output: (LRECL - 80)
Code:

1236 HI HI   HI
1236 OP QRS   TREND                 
4997 T UVW                   
4997 HI HOW ARE YOU     
1111 I'M FINE           
4991 COME[ON ] ]   
4998 COME[ON ]       
4999 AAB  CCDD [EEFF]  GGG IIIAREWAY   
4955 AAB  CCDD [EEFF  GGG IIIAREWAY
4955 AAB  CCDD EEFF]  GGG IIIAREWAY
4955 AAB  CCDD EEFF  GGG IIIAREWAY

For which, I am trying to generate control card as below.
Code:
//STEP01 EXEC PGM=SORT                       
//SYSOUT   DD SYSOUT=*                         
//SORTIN   DD *                                 
IFTHEN                                         
BUILD                                           
//SORTOUT  DD DSN=XXXX.CTLCARD.FILE,DISP=SHR
//SYSIN    DD *                                 
  OPTION COPY                                                       
  OUTFIL REPEAT=80,IFOUTLEN=80,                                   
  IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,3,ZD,START=1,RESTART=(1,6))),   
  IFTHEN=(WHEN=(1,6,CH,EQ,C'IFTHEN'),                                 
  OVERLAY=(10:C'IFTHEN=(WHEN=(1,2,BI,EQ,',81,3,                       
             C',AND,5,1,CH,EQ',C'''',C'[',C'''',C'),',                 
             85:SEQNUM,3,ZD,START=1,INCR=2,89:C'IF')),                 
  IFTHEN=(WHEN=(1,6,CH,EQ,C'BUILD '),                                 
  OVERLAY=(10:C'OVERLAY=(',81,3,C':',C'C',C'''',C' ',C'''',C')),',     
             85:SEQNUM,3,ZD,START=2,INCR=2,89:C'BU')),                 
  IFTHEN=(WHEN=(81,3,ZD,EQ,001,AND,89,2,CH,EQ,C'IF'),                 
  OVERLAY=(001:C'  OUTFIL')),                                         
  IFTHEN=(WHEN=(81,3,ZD,NE,001,AND,89,2,CH,NE,C'IF'),                 
  OVERLAY=(001:C'        '))                                           

Query 1:
Hi Koulsu, I have referred your solution in other topics and trying to code according to my requirement. I have not yet coded to write complete sort card. I'm adding ITHEN statement one by one so that I can find where the problem is.
Now, Last two IFTHEN statements to overlay 1st 8 bytes to OUTFIL for first line and space for other lines are not working. Could you please suggest any idea whether the last 2 statements are ignored or coded wrongly
Later I'm planning to add missing sort card lines like "OPTION COPY" using HEADER statement

Query 2:

In next step, I need to sort the output control card based on position (85,3) so that IFTHEN and OVERLAY statements come as a pair. Please give me any hint if I can achieve in first step itself.

#2:  Author: kolusuLocation: San Jose PostPosted: Fri Dec 16, 2016 10:41 am
    —
srihemz,

There are some inconsistencies in your output. You say you need to remove the leading and trailing [ and ] , but this record

Code:

4991 COME[ON ] ]   


should have been

Code:


4991 COMEON ] 


But you wanted
Code:

4991 COME[ON ] ]


which does not fit the requirement.

Assuming that the above record is a typo here is a JCL which will remove the leading and trailing brackets in one go

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                   
1236 HI HI   HI                                                   
1236 OP QRS   TREND                                               
4997 T UVW                                                       
4997 HI HOW ARE YOU                                               
1111 I'M FINE                                                     
4991 COME[ON ] ]                                                 
4998 [COME[ON ] ]                                                 
4999 [AAB  CCDD [EEFF]  GGG IIIAREWAY]                           
4955 [AAB  CCDD [EEFF  GGG IIIAREWAY]                             
4955 [AAB  CCDD EEFF]  GGG IIIAREWAY]                             
4955 [AAB  CCDD EEFF  GGG IIIAREWAY]                             
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  INREC IFTHEN=(WHEN=INIT,FINDREP=(DO=1,INOUT=(C'[',C''))),       
        IFTHEN=(WHEN=INIT,BUILD=(1,80,JFY=(SHIFT=RIGHT))),       
        IFTHEN=(WHEN=INIT,                                       
        OVERLAY=(80:80,1,CHANGE=(1,C']',C' '),NOMATCH=(80,1),     
                 01:01,80,JFY=(SHIFT=LEFT)))                     
//*


The output from this is

Code:

1236 HI HI   HI                               
1236 OP QRS   TREND                           
4997 T UVW                                     
4997 HI HOW ARE YOU                           
1111 I'M FINE                                 
4991 COMEON ]                                 
4998 COME[ON ]                                 
4999 AAB  CCDD [EEFF]  GGG IIIAREWAY           
4955 AAB  CCDD [EEFF  GGG IIIAREWAY           
4955 AAB  CCDD EEFF]  GGG IIIAREWAY           
4955 AAB  CCDD EEFF  GGG IIIAREWAY             

#3:  Author: srihemzLocation: Chennai PostPosted: Fri Dec 16, 2016 1:00 pm
    —
Thanks a lot for your response kolusu. Sorry that my requirement was not mentioned clearly. Code you provided will perfectly suit my requirement. But in the very least cases input file may not come with both leading and trailing brackets. Sometimes few records will have onlyleading or only trailing. To say in detail, opening bracket that is present only at position 5 (start of the field) should be removed when its corresponding closing bracket appears only at the end of field or even when its corresponding closing bracket not present at all but should not be removed if it has closing bracket before the end of the field. Closing bracket that is present at end of field should be removed when its corresponding opening bracket removed at the start of the field or no opening bracket at all. Words in between the field can have the brackets which neednot be removed. It is not necessary for every open brackets to have closing bracket and viceversa. Please let me know if i confused more. When i go to office on monday i will try to incorporate your code and alter according to my requirement if i could

#4:  Author: William Collins PostPosted: Fri Dec 16, 2016 3:02 pm
    —
If I've understood you correctly, you are saying:

"If position five is '[', remove it any any trailing ']'"

Is that correct?

#5:  Author: srihemzLocation: Chennai PostPosted: Mon Dec 19, 2016 6:45 am
    —
Hi Kolusu & William,

At my work place, I was asked to change the requirement to remove '[' and ']' present anywhere. So my work became quite simple. I used Kolusu's logic given above and modified slightly as per the changed requirement. Thanks a lot for both of your response and help Smile

My final control card:
Code:
  OPTION COPY                                                       
  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'[',C'',C']',C''))),                   
        IFTHEN=(WHEN=INIT,BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C' '))), 
        IFTHEN=(WHEN=(6,1,CH,EQ,C'-'),                             
        OVERLAY=(6:6,1,CHANGE=(1,C'-',C' '),NOMATCH=(6,1),         
                 06:06,74,JFY=(SHIFT=LEFT)))         


Sample Input:
Code:

2335 Xxxxx Yyyyy [Size Small / Medium / Large]                         
1236 Aa Bbb   Ccccc                                                     
[6193] - [Dddddd - Eeeeeee Rrrr]                                       
2499 Ellllllt & Caaaaa - Oaaaaane Pllll - [Store Size Small / Medium / Large]
[4562] - [Leeee - Roooo Paaa Rooo]                                     
6509 Beeeeeeee Kiiii Rooo  - Store Size Small                           
[1509] - [Beeeeeeee Kiiii Rooo PFS]                                     
2331 Suuuuu - [Store Size Large]                                       
 [3366] - [Suuuun JSR]                                                 
6492] - [Biiiiiiiii - Rawwwwd Way]                                     
2335 Leee - [Store Size Small / Medium / Large] 
6197 Beehhhe - [Store Size Small]           
4999 [AAB] CCDD [EEFF]  GGG IIIAREWAY]       
4955 [AAB  CCDD [EEFF  GGG IIIAREWAY]       
4955 [AAB  CCDD EEFF]  GGG IIIAREWAY]       
4955 [AAB  CCDD EEFF  GGG IIIAREWAY]                               

Sample Output:
Code:

2335 Xxxxx Yyyyy Size Small / Medium / Large                           
1236 Aa Bbb Ccccc                                                       
6193 Dddddd - Eeeeeee Rrrr                                             
2499 Ellllllt & Caaaaa - Oaaaaane Pllll - Store Size Small / Medium / Large
4562 Leeee - Roooo Paaa Rooo                                           
6509 Beeeeeeee Kiiii Rooo - Store Size Small                           
1509 Beeeeeeee Kiiii Rooo PFS                                           
2331 Suuuuu - Store Size Large                                         
3366 Suuuun JSR                                                         
6492 Biiiiiiiii - Rawwwwd Way                                           
2335 Leee - Store Size Small / Medium / Large                           
6197 Beehhhe - Store Size Small                                         
4999 AAB CCDD EEFF GGG IIIAREWAY                                       
4955 AAB CCDD EEFF GGG IIIAREWAY                                       
4955 AAB CCDD EEFF GGG IIIAREWAY                                       
4955 AAB CCDD EEFF GGG IIIAREWAY

#6:  Author: kolusuLocation: San Jose PostPosted: Mon Dec 19, 2016 10:19 am
    —
srihemz,

You can avoid the extra Justify if you use FINDREP once again. Use the following control cards

Code:

//SYSIN    DD *                                           
  OPTION COPY                                             
  INREC IFTHEN=(WHEN=INIT,                               
       FINDREP=(IN=(C'[',C']'),OUT=C'')),                 
        IFTHEN=(WHEN=INIT,                               
       OVERLAY=(01,80,SQZ=(SHIFT=LEFT,MID=C' '))),       
        IFTHEN=(WHEN=INIT,                               
       FINDREP=(ENDPOS=7,DO=1,IN=(C'- ',C'-'),OUT=C''))   
//*                                                       

#7:  Author: srihemzLocation: Chennai PostPosted: Tue Dec 20, 2016 12:28 am
    —
Wow! Thanks for the optimized control card, Kolusu Smile
Thank You



MVSFORUMS.com -> Utilities


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group