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 trailing spaces

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Wed Aug 18, 2010 12:20 am    Post subject: Removing trailing spaces
Reply with quote

Hi,

I have a delimited file as my input and I need to remove trailing spaces from the fields in this file. Eg for input and required output is given below :

Input:
Code:
36750 |      I am     a  happy   child         |   Thanks very much    |23

Required Output:
Code:
36750|      I am     a  happy   child|   Thanks very much|23


Pls note that the preceeding and middle spaces are intact.
Back to top
View user's profile Send private message

superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Wed Aug 18, 2010 12:34 am    Post subject: Reply to: Removing trailing spaces
Reply with quote

Like your Avatar! - Kevin
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: Wed Aug 18, 2010 1:02 am    Post subject:
Reply with quote

Arien,

Is each delimiter (|) always in the same position in each record, or can they be in different positions in different records. Please show an example with more than one record for input and expected output so we can get a better idea of what they can look like.

Also, give the RECFM and LRECL of the input file and output file, and the starting position, length and format of all relevant fields.
Back to top
View user's profile Send private message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Wed Aug 18, 2010 1:57 am    Post subject:
Reply with quote

Hi Frank:

As per the example given here RECFM=FB, LRECL=80

Delimiters occur at specific positions in input file: 7, 48 and 72


I have actually unloaded a table here and delimited fields with a pipe in this output file. The field definition of the table is as below:

char(6)
char(40)
char(23)
char(8)


The output file example records :
Code:
36750 |      I am     a  happy   child         |   Thanks very much    |23     
12189 |This is another row                     |  Just an       example|   78
10000 |Hi                                      |Another example        | 42     


and expected output:
Code:
36750|      I am     a  happy   child|   Thanks very much|23
12189|This is another row|  Just an       example|   78
10000|Hi|Another example| 42


Pls note that the preceeding and middle spaces are intact.
Back to top
View user's profile Send private message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Wed Aug 18, 2010 1:58 am    Post subject:
Reply with quote

@ Kevin... thank you icon_smile.gif
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Aug 18, 2010 3:29 am    Post subject: Reply to: Removing trailing spaces
Reply with quote

arien,

Couldn't think of an easier way to do this, so here is a brute force method to squeeze out the trailing blanks. The max value you need to squeeze is 40 blanks.

Code:

//STEP0100 EXEC PGM=SORT                                                       
//SYSOUT   DD SYSOUT=*                                                         
//SORTIN   DD DSN=Your input FB 80 byte input file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                                         
//SYSIN    DD *                                           
  SORT FIELDS=COPY                                                 
  OUTREC FINDREP=(IN=(C'                                        |',
                      C'                                       |',   
                      C'                                      |',   
                      C'                                     |',   
                      C'                                    |',     
                      C'                                   |',     
                      C'                                  |',       
                      C'                                 |',       
                      C'                                |',         
                      C'                               |',         
                      C'                              |',           
                      C'                             |',           
                      C'                            |',             
                      C'                           |',             
                      C'                          |',               
                      C'                         |',               
                      C'                        |',                 
                      C'                       |',                 
                      C'                      |',                   
                      C'                     |',                   
                      C'                    |',                     
                      C'                   |',                     
                      C'                  |',                       
                      C'                 |',                       
                      C'                |',                         
                      C'               |',                         
                      C'              |',                           
                      C'             |',                           
                      C'            |',                             
                      C'           |',                             
                      C'          |',                               
                      C'         |',                               
                      C'        |',                                 
                      C'       |',                                 
                      C'      |',                                   
                      C'     |',                                   
                      C'    |',                                     
                      C'   |',                                     
                      C'  |',             
                      C' |'),OUT=C'|')   
//*
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Wed Aug 18, 2010 3:33 am    Post subject:
Reply with quote

arien,
Is this related to http://ibmmainframes.com/viewtopic.php?t=50698

Just curious why couldn't you handle this in DB2 unload itself?

Code:
 
SELECT CONCAT(RTRIM(COL1),CHAR('|')),   
       CONCAT(RTRIM(COL2),CHAR('|')),   
       CONCAT(RTRIM(COL3),CHAR('|')),   
       CONCAT(RTRIM(COL4),CHAR('|'))     
  FROM  TBL                           


Thanks,
Back to top
View user's profile Send private message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Wed Aug 18, 2010 8:33 pm    Post subject:
Reply with quote

Hi sqlcode1,

Yes, this is the next step of my requirement. I unloaded a table into a delimited file using DSNUPROC and then I need to rtrim the fields..

I tried your example.. it did wonders. Just that I had to use DSNUTILA instead of DSNUPROC in my JCL for executing the above SELECT query.

Only thing is if you could help me with left-justifying the columns in the output. The starting position of each column in the output is still the same, and I don't want to miss the starting spaces in the columns and hence can't use LTRIM.

My DSNUPROC output file:
Code:
36750 |      I am     a  happy   child         |   Thanks very much    |23     
12189 |This is another row                     |  Just an       example|   78
10000 |Hi                                      |Another example        | 42     


Current output using RTRIM in DSNUTILA:
Code:
36750|       I am     a  happy   child|            Thanks very much|    23     
12189| This is another row|                       Just an       example|   78
10000| Hi|                                      Another example|         42


Expected output :
Code:
36750|      I am     a  happy   child|   Thanks very much|23
12189|This is another row|  Just an       example|   78
10000|Hi|Another example| 42
Back to top
View user's profile Send private message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Wed Aug 18, 2010 8:35 pm    Post subject:
Reply with quote

@Skolusu : My Original file contains uto 200 blanks before the | delimiter.. it would be too crude an approach to do so... icon_sad.gif thanks anyway icon_smile.gif
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Wed Aug 18, 2010 9:59 pm    Post subject:
Reply with quote

arien,
You are probably in the wrong section of forum.
See if this works for you.

Code:
SELECT CAST (RTRIM(COL1) || '|'             
          || RTRIM(COL2) || '|'             
          || RTRIM(COL3) || '|'             
          || RTRIM(COL4) || AS CHAR (80))   
FROM  TBL                               


Thanks,
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Aug 18, 2010 10:09 pm    Post subject: Reply to: Removing trailing spaces
Reply with quote

arien,

There are ways to handle this is in SQL itself.


SQLCODE1,

Are you aware that RTRIM function actually creates a VARCHAR output string?
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 578
Location: USA

PostPosted: Wed Aug 18, 2010 10:15 pm    Post subject:
Reply with quote

Skolusu,
Yes, RTRIM creates VARCHAR and that is the reason I am casting the entire output with CHAR(80).

Thanks,
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 -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Removing the MODETAB field in a VTAM ... rcwing All Other Mainframe Topics 1 Fri Feb 19, 2016 7:11 pm
No new posts Remove intermediate spaces Pallavi Vishwanath SYNCSORT 1 Fri Jan 15, 2016 2:45 am
No new posts Syncsort to remove the leading spaces V S Amarendra Reddy SYNCSORT 5 Fri Jan 08, 2016 9:47 pm


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