View previous topic :: View next topic
|
Author |
Message |
feellikeneo
New User
Joined: 19 Mar 2007 Posts: 73 Location: Chennai
|
|
|
|
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 |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
Back to top |
|
|
feellikeneo
New User
Joined: 19 Mar 2007 Posts: 73 Location: Chennai
|
|
|
|
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 |
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
See the end of the thread I posted then. The solution is given |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
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 [/code] |
|
Back to top |
|
|
feellikeneo
New User
Joined: 19 Mar 2007 Posts: 73 Location: Chennai
|
|
|
|
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 |
|
Back to top |
|
|
kgumraj2
New User
Joined: 01 Aug 2007 Posts: 42 Location: Hyderabad
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
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 |
|
|
|