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

Trimming Strings in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Johore

Specialist


Joined: 12 Sep 2003
Posts: 19

PostPosted: Mon Jun 14, 2004 12:54 pm
Reply with quote

Hi team,

How do we Trim the Trailing blanks from a sentence using STRING function. Is there an easy way , using another function also ??

Quote:
ex ... INPUT - PIC X(80) = "THE QUICK BROWN FOX. "

output - "THE QUICK BROWN FOX."


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

Specialist


Joined: 12 Sep 2003
Posts: 19

PostPosted: Thu Jun 17, 2004 5:36 pm
Reply with quote

Hi ..

One of the simplest way i could think of is using a STRING function

Code:
SRTING INPUT   DELIMITED BY "  " ( two spaces)
             INTO   OUTPUT

Is there any simpler way

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

New User


Joined: 12 May 2004
Posts: 33

PostPosted: Thu Jun 17, 2004 11:58 pm
Reply with quote

Johore

Couple of ways to trim the trailing spaces.

1. using instrinc function REVERSE
MOVE FUNCTION REVERSE(INPUT) TO INPUT-R.
INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.
COMPUTE INP-LEN = LENGTH OF INPUT-R - CNTR.
INPUT-TRIM = MOVE INPUT(1:INP-LEN)

2.
MOVE LENGTH OF INPUT TO STR-LEN.
PERFORM VARYING SUB FROM STR-LEN BY -1
UNTIL INPUT(SUB:1) NOT = SPACE
END-PERFORM
MOVE INPUT(1:SUB) TO INPUT-TRIM.
Back to top
View user's profile Send private message
princess

New User


Joined: 14 Jan 2007
Posts: 1
Location: chennai

PostPosted: Fri Oct 29, 2010 7:16 am
Reply with quote

Hi,

I just want to know if how can I perform the validation of the trim string like this.
What should be done to compare the trim string into another variable.

example:

the trim string i got is OUTPUT-STR = 'fox'
and i want to compare if the OUTPUT-STR = 'fox' exist in TXT-FIELD.
If TXT-FIELD = 'The quick brown fox jumps over the lazy dog'

Please let me know the answer.
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: Fri Oct 29, 2010 7:54 am
Reply with quote

There is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference manual, and read up on the INSPECT statement.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top