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
 

 

TRIM operation in COBOL

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

New User


Joined: 19 Mar 2007
Posts: 73
Location: Chennai

PostPosted: Tue Jul 31, 2007 6:04 pm    Post subject: TRIM operation in COBOL
Reply with quote

Hello everybody,

Is there any ways to perform the trim operation in COBOL.
Say I have a variable as "IBM MAINFRAMES (spaces)"

I need to truncate the spaces at the end.
Is there any possible ways to do that in COBOL. If there is something please post it here.. Please also post if you have examples.

Thanks in advance,


Cheers,
Neo icon_smile.gif
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Jul 31, 2007 6:18 pm    Post subject: Re: TRIM operation in COBOL
Reply with quote

feellikeneo wrote:
Hello everybody,

Is there any ways to perform the trim operation in COBOL.
Say I have a variable as "IBM MAINFRAMES (spaces)"

I need to truncate the spaces at the end.
Is there any possible ways to do that in COBOL. If there is something please post it here.. Please also post if you have examples.

Thanks in advance,


Cheers,
Neo icon_smile.gif


If you have a pic x(20) with 'IBM MAINFRAMES' in the first 14 positions and spaces in the last 6 positions, when you TRIM what are you going to replace the spaces with? Why not just move the pic x(20) field to a pic x(14) that would truncate it. With MAINFRAME COBOL you need to think of fixed length fields not strings.[/b]
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jul 31, 2007 6:21 pm    Post subject:
Reply with quote

See this thread:

http://ibmmainframes.com/viewtopic.php?t=22726&highlight=
Back to top
View user's profile Send private message
feellikeneo

New User


Joined: 19 Mar 2007
Posts: 73
Location: Chennai

PostPosted: Tue Jul 31, 2007 6:22 pm    Post subject: Re: TRIM operation in COBOL
Reply with quote

Craq Giegerich wrote:
feellikeneo wrote:
Hello everybody,

Is there any ways to perform the trim operation in COBOL.
Say I have a variable as "IBM MAINFRAMES (spaces)"

I need to truncate the spaces at the end.
Is there any possible ways to do that in COBOL. If there is something please post it here.. Please also post if you have examples.

Thanks in advance,


Cheers,
Neo icon_smile.gif


If you have a pic x(20) with 'IBM MAINFRAMES' in the first 14 positions and spaces in the last 6 positions, when you TRIM what are you going to replace the spaces with? Why not just move the pic x(20) field to a pic x(14) that would truncate it. With MAINFRAME COBOL you need to think of fixed length fields not strings.[/b]



Hi,
Actually what my scenario is I read a DATASET name from a file in the COBOL. Initially the DSN name I have given length as 44.
This does not mean, all my DSN name must have length 44. So I need to truncate any spaces if any at the trail.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Jul 31, 2007 6:25 pm    Post subject:
Reply with quote

See the end of the thread I posted then. The solution is given
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 130
Location: Guntur

PostPosted: Tue Jul 31, 2007 6:32 pm    Post subject: TRIM operation in COBOL
Reply with quote

Hi feellikeneo,

if you want to use that variable for any purpose without spaces we can do it using reference modification.


if you have any issue, then specify in which way you want to use it

then it will be easy to give you equalent code for that.


please correct me if i am wrong icon_neutral.gif [/code]
Back to top
View user's profile Send private message
feellikeneo

New User


Joined: 19 Mar 2007
Posts: 73
Location: Chennai

PostPosted: Wed Aug 01, 2007 6:25 pm    Post subject:
Reply with quote

Hi All,

I found a way to solve my requirement using INSPECT command.
I used the following code,

Code:

INSPECT WS-DSN
  REPLACING FIRST SPACES BY ','


This helped me to put a "," at the inspection of first space, which solved my problem.

Thanks for everyone who helped me

Cheers,
Neo icon_smile.gif
Back to top
View user's profile Send private message
kgumraj2

New User


Joined: 01 Aug 2007
Posts: 42
Location: Hyderabad

PostPosted: Wed Aug 01, 2007 7:22 pm    Post subject:
Reply with quote

Hi,

Please check below logic,

My input variable has "IBMMAINFRAMES NAME "

1. You will be knowing the length of the variable,
2. So search from last byte ( Increasing a counter).
3. When you encounter an alphabet , move (total length - counter) to length field
4. Use Partial Move concept and move to taget variable.

I feel you can go ahead. Thanks.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Wed Aug 01, 2007 7:57 pm    Post subject:
Reply with quote

instead of
Quote:

1. You will be knowing the length of the variable,

1b. set counter to zero.
Quote:
2. So search from last byte ( Increasing a counter).
3. When you encounter an alphabet , move (total length - counter) to length field
4. Use Partial Move concept and move to taget variable.

[code]
1. set counter to length of variable
2. search using the counter as subscript . decrease counter
3. move variable (1:counter)
[code]
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Aug 01, 2007 8:00 pm    Post subject:
Reply with quote

Here is a question:

Does the programmer setting variables and looping through a string outperform the COBOL function of INSPECT?

My gut reaction is no. The INSPECT is most likely far more efficient than any code we would write.
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 Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


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