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

Converting multiple spaces in to none


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 14, 2010 6:54 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 14, 2010 7:25 pm
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:

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

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

Superior Member


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

PostPosted: Fri Jan 15, 2010 4:00 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jan 15, 2010 4:27 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
Search our Forums:

Back to Top