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

TRIM operation in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
Reply with quote

See this thread:

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
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
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: 128
Location: Guntur

PostPosted: Tue Jul 31, 2007 6:32 pm
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
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
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: 6966
Location: porcelain throne

PostPosted: Wed Aug 01, 2007 7:57 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
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
Search our Forums:

Back to Top