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: 6966
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
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm


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