IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Removing Leading and Trailing spaces in a Line


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
spradeepece

New User


Joined: 25 Jun 2008
Posts: 19
Location: Chennai

PostPosted: Fri Apr 30, 2010 7:46 pm
Reply with quote

Hi,

I have a file (FB - RECL - 72), with first 3 fields of 22 bytes each and last with 6 bytes. First 3 fields have data (alphanumeric) which may/may not start from first position. The message can be of any length (from 0 to 22, 0 since Field 1 and 3 can be non-empty where 2 can be empty)

I need to strip off the extra spaces before and after the actual message, so that I can have the message in a single line without leading and trailing spaces. But the intermediate space characters should be preserved. Fourth field should not be affected, and retained in same position as in input.

I need 1 blank space between the messages in the output file.

Input File :-
Code:
----------------------  ----------------------  -----------------------  ------
HI EVERYBODY.             THIS IS A   SAMPLE    DATA TO FIND             AAAAAA
IF WE  CAN              JUSTIFY  A RECORD,      WITHOUT SQUEEZE          BBB   



Output File :-

Code:
-------------------------------------------------------------------------
HI EVERYBODY. THIS IS A   SAMPLE DATA TO FIND                      AAAAAA
IF WE  CAN JUSTIFY  A RECORD, WITHOUT SQUEEZE                      BBB   


I tried Squeeze Option, where the intermediate spaces were removed. Please suggest.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Apr 30, 2010 11:20 pm
Reply with quote

Assuming that the first field starts in position 1, the second field starts in position 23, the third field starts in position 45 and the fourth field starts in position 67, here's a DFSORT job that will do what I think you're asking for. (I also assumed there aren't any apostrophes in your messages.)

Code:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (FB/72)
//SORTOUT DD DSN=...  output file (FB/72)
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
    BUILD=(1,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,
       23,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,
       45,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,
       67,6)),
    IFTHEN=(WHEN=INIT,
      OVERLAY=(1,75,SQZ=(SHIFT=LEFT,MID=C' ',PAIR=APOST))),
    IFTHEN=(WHEN=INIT,
      FINDREP=(STARTPOS=1,ENDPOS=75,IN=C'''',OUT=C'')),
    IFTHEN=(WHEN=INIT,
      BUILD=(1,66,67:70,6))
/*
Back to top
View user's profile Send private message
spradeepece

New User


Joined: 25 Jun 2008
Posts: 19
Location: Chennai

PostPosted: Tue May 04, 2010 9:58 am
Reply with quote

Thanks Frank..

But sorry, I should have said that my data contains all forms of special characters.. including Single/Double quotes.. (My data contains addresses, where we cannot restrict the special characters). I went for an option of X'0505' instead of C''''.. Not sure if it is advisable..

Code:
OPTION COPY                                                           
INREC IFTHEN=(WHEN=INIT,                                             
 BUILD=(1,22,JFY=(SHIFT=LEFT,LEAD=X'0505',TRAIL=X'0505',LENGTH=24),X,
   23,22,JFY=(SHIFT=LEFT,LEAD=X'0505',TRAIL=X'0505',LENGTH=24),X,     
   45,22,JFY=(SHIFT=LEFT,LEAD=X'0505',TRAIL=X'0505',LENGTH=24),X,     
    67,6)),                                                           
  IFTHEN=(WHEN=INIT,                                                 
    OVERLAY=(1,75,SQZ=(SHIFT=LEFT,MID=C' ',PAIR=APOST))),             
  IFTHEN=(WHEN=INIT,                                                 
    FINDREP=(STARTPOS=1,ENDPOS=75,IN=X'0505',OUT=C'')),               
  IFTHEN=(WHEN=INIT,                                                 
    BUILD=(1,66,67:70,6))                                             


But in this case, the intermediate (or valid) spaces were trimmed too.

Expected :
Code:
HI EVERYBODY. THIS IS A   SAMPLE DATA TO FIND                     AAAAAA
IF WE  CAN JUSTIFY  A RECORD, WITHOUT SQUEEZE                     BBB   


Actual Outcome :
Code:
HI EVERYBODY. THIS IS A SAMPLE DATA TO FIND                    AAA     
IF WE CAN JUSTIFY A RECORD, WITHOUT SQUEEZE                    BBB     
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue May 04, 2010 10:52 pm
Reply with quote

Quote:
I should have said that my data contains all forms of special characters.. including Single/Double quotes


The technique I used requires the use of PAIR=APOST (for apostrophes) or PAIR=QUOTE (for double quotes). So apostrophe or double quote are the only characters that will work as the leading and trailing characters with this technique. If your data can contain both apostrophes and double quotes as well as embedded blanks, then I don't see any way of doing what you want with IFTHEN.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 04, 2010 11:09 pm
Reply with quote

Hello,

Most likely not what you are looking for, but this is a trivial bit of COBOL code. . .
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue May 04, 2010 11:20 pm
Reply with quote

It can also be done with DFSORT using an E15 exit in Assembler or COBOL with the appropriate code.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed May 05, 2010 12:49 am
Reply with quote

I should have been more specific. . . icon_redface.gif

Yup, this bit of code could be well served as an exit (rather than a standalone process).

d
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed May 05, 2010 12:54 am
Reply with quote

spradeepece wrote:
Thanks Frank..

But sorry, I should have said that my data contains all forms of special characters.. including Single/Double quotes..


What about x'00' or x'FF'?
Back to top
View user's profile Send private message
spradeepece

New User


Joined: 25 Jun 2008
Posts: 19
Location: Chennai

PostPosted: Fri May 07, 2010 12:00 pm
Reply with quote

Craq,

X'00' is there in my data.. But i could not find X'FF'.. Is there a way X'FF' is useful..

Thanks everybody.. I have done it using REXX (STRIP) option.. But still a bit curious to know about X'FF'..
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Fri May 07, 2010 10:44 pm
Reply with quote

spradeepece,

Use the following DFSORT control cards

Code:

//SYSIN    DD *                                                         
  OPTION COPY                                                           
  INREC IFTHEN=(WHEN=INIT,FINDREP=(IN=X'7D',OUT=X'FF')),               
  IFTHEN=(WHEN=INIT,                                                   
    BUILD=(1,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,   
       23,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,       
       45,22,JFY=(SHIFT=LEFT,LEAD=C'''',TRAIL=C'''',LENGTH=24),X,       
       67,6)),                                                         
    IFTHEN=(WHEN=INIT,                                                 
      OVERLAY=(1,75,SQZ=(SHIFT=LEFT,MID=C' ',PAIR=APOST))),             
    IFTHEN=(WHEN=INIT,                                                 
      FINDREP=(STARTPOS=1,ENDPOS=75,IN=C'''',OUT=C'')),                 
    IFTHEN=(WHEN=INIT,                                                 
      FINDREP=(STARTPOS=1,ENDPOS=75,IN=X'FF',OUT=X'7D')),               
    IFTHEN=(WHEN=INIT,                                                 
      BUILD=(1,66,67:70,6))                                             
//*
Back to top
View user's profile Send private message
spradeepece

New User


Joined: 25 Jun 2008
Posts: 19
Location: Chennai

PostPosted: Mon May 10, 2010 4:05 pm
Reply with quote

Good catch icon_smile.gif

Thanks Kolusu..
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Reading dataset in Python - New Line ... All Other Mainframe Topics 22
Search our Forums:

Back to Top