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
 

 

Trimming Strings in COBOL

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

Specialist


Joined: 12 Sep 2003
Posts: 19

PostPosted: Mon Jun 14, 2004 12:54 pm    Post subject: Trimming Strings in COBOL
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Trimming Strings in COBOL
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Fri Oct 29, 2010 7:54 am    Post subject:
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    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. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Occurrence of various strings within ... TS70363 JCL & VSAM 1 Thu Apr 27, 2017 8:18 pm
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm


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