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
 

 

How to perform STRIP Function in COBOL

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

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Fri Jul 18, 2008 10:08 pm    Post subject: How to perform STRIP Function in COBOL
Reply with quote

I need to perform String function strip in COBOL,

Please suggest a simple method to perform this ..

Example:
Input
' INPUT '

Output Should be :
'INPUT'

Thanks
Ram
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: Fri Jul 18, 2008 10:17 pm    Post subject:
Reply with quote

Hello,

You could code a loop and only move the bytes/values you want in the "output" string.
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Fri Jul 18, 2008 11:44 pm    Post subject:
Reply with quote

Thanks Dick for ur quick response,

But i would be difficult because I need to increment two counter , One for input field and other for Output field,

Is there any other possible solution ..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Jul 18, 2008 11:54 pm    Post subject:
Reply with quote

COBOL really doesn't lend itself to string manipulation like other languages. If you can't use a loop as Dick suggested, you're probably going to have to write a subroutine in another language to perform the function.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Fri Jul 18, 2008 11:58 pm    Post subject:
Reply with quote

Hi

If you want to remove only the leading SPACES then you can use many method like UNSTRING or INSPECT or using Reference Modification Move statement etc.

Please try the below one.

Declare 2 Working Storage variable

01 WS-SPACES
01 WS-INPUT

UNSTRING Input Delimited by SPACES INTO
WS-SPACES, WS-INPUT
END-UNSTRING.
Back to top
View user's profile Send private message
sonalsa

New User


Joined: 13 Sep 2007
Posts: 4
Location: charlotte

PostPosted: Sat Jul 19, 2008 1:32 am    Post subject: Reply to: How to perform STRIP Function in COBOL
Reply with quote

Hello ,

I have a similar scenario to be coded, where I need to remove special characters or spaces from a string.

Ex:
Say I have an input string as "~123Ab ^ erb &! erf *()_ ".
My desired output is "123Aberberf".

Could any one please help me how to get this coded in cobol.
Back to top
View user's profile Send private message
Suresh Ponnusamy

Active User


Joined: 22 Feb 2008
Posts: 107
Location: New York

PostPosted: Sat Jul 19, 2008 1:57 am    Post subject:
Reply with quote

Please refer the below given post.

http://ibmmainframes.com/viewtopic.php?t=32505

Here instead of Alphabet, you can define the list of Special Characters in the Working Storage Section and eliminate the same using Inspect Clause or through a Perform until loop.
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: Sat Jul 19, 2008 3:02 am    Post subject: Re: How to perform STRIP Function in COBOL
Reply with quote

This will remove all unwanted characters from a given STRING value and left-justify this value, padded with low-order spaces. The length of these example STRINGS are 256-Bytes.

Code:

CBL TRUNC(OPT)                                                           
           03  WS-XLATE-FROM-TBL   PIC  X(256).                           
           03  WS-XLATE-TO-TBL     PIC  X(256).                           
           03  WS-STRING           PIC  X(256).                           
           03  WS-WORK-STRING      PIC  X(256).                           
           03  WS-SUB              PIC  9(008)     BINARY.               
           03  WS-SUB-X            REDEFINES WS-SUB                       
                                   PIC  X(004).                           
      *                                                                   
           MOVE '~123Ab ^ erb &! erf *()_'                               
                                       TO WS-STRING.                     
           MOVE SPACES                 TO WS-XLATE-TO-TBL.               
           MOVE ZERO                   TO WS-SUB.                         
           MOVE 1                      TO TALLY.                         
      *                                                                   
      **** LOAD THE 'FROM-TBL' WITH ALL 256 POSSIBLE VALUES OF X'00'     
      **** THRU X'FF'.                                                   
      *                                                                   
           PERFORM UNTIL TALLY > LENGTH OF WS-XLATE-FROM-TBL             
               MOVE WS-SUB-X (4:)      TO WS-XLATE-FROM-TBL (TALLY:1)     
               ADD  1                  TO TALLY                           
               ADD  1                  TO WS-SUB                         
           END-PERFORM.                                                       
      *                                                                   
      **** NOW, TRANSFER THE BYTES YOU WOULD LIKE TO RETAIN FROM THE     
      **** 'FROM-TBL' TO THE 'TO-TBL'. NOTE THAT THE 'TO-TBL' HAS BEEN   
      **** INITIALIZED TO SPACES BEFOREHAND. IN THIS EXAMPLE, WE ARE     
      **** ONLY RETAINING LOWER-CASE LETTERS, UPPER-CASE LETTERS AND     
      **** NUMERICS 0-9.                                                 
      *                                                                   
           MOVE WS-XLATE-FROM-TBL (130:)                                 
                                       TO WS-XLATE-TO-TBL (130:9).       
           MOVE WS-XLATE-FROM-TBL (146:)                                 
                                       TO WS-XLATE-TO-TBL (146:9).       
           MOVE WS-XLATE-FROM-TBL (163:)                                 
                                       TO WS-XLATE-TO-TBL (163:8).       
           MOVE WS-XLATE-FROM-TBL (194:)                                 
                                       TO WS-XLATE-TO-TBL (194:9).       
           MOVE WS-XLATE-FROM-TBL (210:)                                 
                                       TO WS-XLATE-TO-TBL (210:9).       
           MOVE WS-XLATE-FROM-TBL (227:)                                 
                                       TO WS-XLATE-TO-TBL (227:8).       
           MOVE WS-XLATE-FROM-TBL (241:)                                 
                                       TO WS-XLATE-TO-TBL (241:10).       
      *                                                                   
      **** OK, WE'VE BUILT OUR TRANSLATE-TBLS, SO WE'LL KEEP THE LOWER   
      **** AND UPPER CASE LETTERS AS WELL AS NUMERICS 0-9 AND CONVERT     
      **** ALL OTHER BYTE-VALUES TO SPACE. AFTER THE 'INSPECT' THE       
      **** STRING WILL CONTAIN ' 123Ab   erb    erf     ', INTERSPERSED   
      **** WITH SPACES.                                                   
      *                                                                   
           INSPECT WS-STRING           CONVERTING WS-XLATE-FROM-TBL       
                                       TO WS-XLATE-TO-TBL.               
      *                                                                   
      **** MOVE THE CONVERTED STRING VALUE TO A WORK-STRING AND RESET     
      **** THE STRING TO SPACES. THEN, RE-POPULATE THE STRING AS A       
      **** LEFT-JUSTIFIED VALUE, IGNORING ALL SPACES.                     
      *                                                                   
           MOVE WS-STRING              TO WS-WORK-STRING.                 
           MOVE SPACES                 TO WS-STRING.                     
           MOVE ZERO                   TO WS-SUB.                         
           MOVE 1                      TO TALLY.                         
      *                                                                   
           PERFORM UNTIL TALLY > LENGTH OF WS-WORK-STRING                 
               IF  WS-WORK-STRING (TALLY:1) NOT = SPACE                   
                   ADD  1              TO WS-SUB                         
                   MOVE WS-WORK-STRING (TALLY:1)                         
                                       TO WS-STRING (WS-SUB:1)           
               END-IF                                                     
               ADD  1                  TO TALLY                           
           END-PERFORM.                                                   
      *                                                                   
   


Regards,

Bill
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: Sat Jul 19, 2008 8:24 am    Post subject:
Reply with quote

Hello,

Quote:
But i would be difficult because I need to increment two counter , One for input field and other for Output field,
Then it is probably time to learn and get comfortable with such code. Once you have done just a bit, you will no longer find it difficult and intimidating icon_smile.gif
Back to top
View user's profile Send private message
sonalsa

New User


Joined: 13 Sep 2007
Posts: 4
Location: charlotte

PostPosted: Mon Jul 21, 2008 6:39 pm    Post subject: Thanks
Reply with quote

Thanks Bill...

Your soltion was a perfect fit for my situation ....thanks again for helping me ..
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
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


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