Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Removing Leading and Trailing spaces in a Line

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
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    Post subject: Removing Leading and Trailing spaces in a Line
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 Moderator


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

PostPosted: Fri Apr 30, 2010 11:20 pm    Post subject:
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    Post subject:
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 Moderator


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

PostPosted: Tue May 04, 2010 10:52 pm    Post subject:
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

Site Director


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

PostPosted: Tue May 04, 2010 11:09 pm    Post subject:
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 Moderator


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

PostPosted: Tue May 04, 2010 11:20 pm    Post subject:
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

Site Director


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

PostPosted: Wed May 05, 2010 12:49 am    Post subject: Reply to: Removing Leading and Trailing spaces in a Line
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Removing Leading and Trailing spaces in a Line
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us