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
 

 

Converting multiple spaces in to none

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Priyesh Tewari

New User


Joined: 24 Jun 2008
Posts: 7
Location: Pune

PostPosted: Thu Jan 14, 2010 6:50 pm    Post subject: Converting multiple spaces in to none
Reply with quote

Hi,
Can some bdy tell me an answer to this. I have a string 'X Y Z A'. There are spaces in between al the alphabets. Now I want to remove all the spaces and just have the output string as XYZA. How can I do it? Please help...

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

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7931
Location: Bellevue, IA

PostPosted: Thu Jan 14, 2010 6:54 pm    Post subject:
Reply with quote

Is the variable DBCS? UTF-8?

Assuming it is a "normal" (i.e., not DBCS nor UTF) variable, reference modification will do this -- see the COBOL Language Reference manual (link at the top of the page) for details on how to code it.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jan 14, 2010 7:19 pm    Post subject:
Reply with quote

Code:

01  input-string-size          pic s9(4) comp.
01  input-string               pic x(10).  (or however large it is)
01  input-table     
    redefines
    input string.
    05  input-item             pic x(01)
                               occurs 10 times    (or however large input-string is)
                               indexed by input-index.
        88  input-is-space     value space.
*
01  output-string              pic x(10).  (or however large input-string is)
    88  output-string-to-space value spaces.
01  output-table     
    redefines
    output string.
    05  output-item            pic x(01)
                               occurs 10 times    (or however large input-string is)
                               indexed by output-index.
*

Code:

   move length of input-string to input-string-size.
   set  output-index           to 1   
        set  output-string-to-space true
   perform varying input-index
           from    1
           by      1
           until   input-index > input-string-size         
      if input-is-space(input-index)
      then
         continue
      else
         move input-item  (input-index)
         to   output-item (output-index)       
         set  output-index
              up by 1
      end-if
   end-perform 


I would think, IMUO that advice to a novice should be to use/learn indexing first, since it is much more effecient than reference modification, especially since he could not figure out how to accomplish this task.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 14, 2010 7:25 pm    Post subject: Reply to: Converting multiple spaces in to none
Reply with quote

The following post maybe helpful (or maybe not), if you apply the logic in a reverse manner or extract some of the logic as needed:

http://www.ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Bill
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Jan 15, 2010 4:00 pm    Post subject:
Reply with quote

Robert Sample wrote:
Assuming it is a "normal"
icon_smile.gif, you're now habitual of this forum, Robert.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Fri Jan 15, 2010 4:27 pm    Post subject: Reply to: Converting multiple spaces in to none
Reply with quote

but it' s much more fun with ... ABnormal <thingies>
as in Frankestein junior
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
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 Converting multiple VB files to FB fi... Viswanath Reddy JCL & VSAM 6 Mon Aug 08, 2016 11:49 pm
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm


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