View previous topic :: View next topic
|
Author |
Message |
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
You could code a loop and only move the bytes/values you want in the "output" string. |
|
Back to top |
|
|
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Suresh Ponnusamy
Active User
Joined: 22 Feb 2008 Posts: 107 Location: New York
|
|
|
|
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 |
|
|
sonalsa
New User
Joined: 13 Sep 2007 Posts: 4 Location: charlotte
|
|
|
|
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 |
|
|
Suresh Ponnusamy
Active User
Joined: 22 Feb 2008 Posts: 107 Location: New York
|
|
|
|
Please refer the below given post.
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
sonalsa
New User
Joined: 13 Sep 2007 Posts: 4 Location: charlotte
|
|
|
|
Thanks Bill...
Your soltion was a perfect fit for my situation ....thanks again for helping me .. |
|
Back to top |
|
|
|