MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Removing opening and closing bracket '[' & ']' using sor

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
srihemz
Beginner


Joined: 22 Nov 2016
Posts: 6
Topics: 1
Location: Chennai

PostPosted: Fri Dec 16, 2016 9:21 am    Post subject: Removing opening and closing bracket '[' & ']' using sor Reply with quote

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.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Fri Dec 16, 2016 10:41 am    Post subject: Reply with quote

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             

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
srihemz
Beginner


Joined: 22 Nov 2016
Posts: 6
Topics: 1
Location: Chennai

PostPosted: Fri Dec 16, 2016 1:00 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Fri Dec 16, 2016 3:02 pm    Post subject: Reply with quote

If I've understood you correctly, you are saying:

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

Is that correct?
Back to top
View user's profile Send private message
srihemz
Beginner


Joined: 22 Nov 2016
Posts: 6
Topics: 1
Location: Chennai

PostPosted: Mon Dec 19, 2016 6:45 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12358
Topics: 75
Location: San Jose

PostPosted: Mon Dec 19, 2016 10:19 am    Post subject: Reply with quote

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''))   
//*                                                       

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
srihemz
Beginner


Joined: 22 Nov 2016
Posts: 6
Topics: 1
Location: Chennai

PostPosted: Tue Dec 20, 2016 12:28 am    Post subject: Reply with quote

Wow! Thanks for the optimized control card, Kolusu Smile
Thank You
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group