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

How to RTRIM in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Munish Singla

New User


Joined: 18 Jul 2007
Posts: 21
Location: kolkata

PostPosted: Sat Nov 03, 2007 3:20 am
Reply with quote

Hi all,

I have a requirement where i have to remove the spaces at the end of a ws-variable. Suppose the length of variable is PIC x(100). It occupies only 50 bytes. Now i need to remove the last 50 bytes from th variable. After that i need to write it in to file. Now problem is record length of file conatins n number of such variables. So when i move these variables to file, reocrd of file conatins lots of spaces due to empty apces in the variables.

Can anybody plese suggest me?
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Sat Nov 03, 2007 4:07 am
Reply with quote

Will this file have variable length records or fixed length length records? If there are more than 1 of these variable length fields in the record how would you find the start and end of each field? If there is only 1 variable length field and it is the last field this is doable, in a VB file. If there are more than 1 variable length fields in the record this becomes much more difficult.
Back to top
View user's profile Send private message
Munish Singla

New User


Joined: 18 Jul 2007
Posts: 21
Location: kolkata

PostPosted: Sat Nov 03, 2007 5:04 am
Reply with quote

File will have variable length records,
but there are more than one variable length fields

take a example suppose there r three variables

a pic x(30)
b pic x(30)
c pic x(30)

and there three needs to be written in the file..
now 1 contains only 10 bytes of actual data, b contains only 15 , c 20

so when these will be written to file
record will contain apces between a,b and c ..
like 1-10 of a then 20 spaces , 1-15 of b then 15 spaces , 1-20 of c then 10 spaces.

Now i want to have only 1 space between a,b and c

hope it clarifies the problem.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Sat Nov 03, 2007 6:26 am
Reply with quote

Munish,

Try using COBOL STRING verb.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Sat Nov 03, 2007 3:42 pm
Reply with quote

and if you want to find the fields again, put a delimiter between each field during your string operation.

This kind of thing becomes very difficult on the mainframe. if you were writing in c, you can use null dilimited strings. but, this is cobol and cobol was designed to have discrete fields.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Nov 04, 2007 10:13 am
Reply with quote

Hello,

If you want to remove trailing spaces and create a "new" record with only one space (or other delimiter), you can do this with a bit of code that uses reference modification and/or string.

Will these fields have multiple consecutive embedded spaces or will the only places multiple spaces occur be at the end of the field?

When you write the "new" record, you will want to create a field with the total byte count of the new record to use with a "depending on" to define the variable length to take advantage of the shorter new records.
Back to top
View user's profile Send private message
Munish Singla

New User


Joined: 18 Jul 2007
Posts: 21
Location: kolkata

PostPosted: Tue Nov 06, 2007 7:16 am
Reply with quote

Hi Dick,

The spaces will occur onlt at the end of each field.

Could you please explian in little detail how we can do it.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Nov 06, 2007 8:57 am
Reply with quote

Hello,

One way would be to individually unstring the a, b, and c variables (delimited by a double-space) into some work field, capturing the length of each using POINTER.

When you have the 3 pointers, you could then string the original values (using reference modification to "trim" the trailing spaces) interleaved with the single space you want.
Back to top
View user's profile Send private message
Munish Singla

New User


Joined: 18 Jul 2007
Posts: 21
Location: kolkata

PostPosted: Wed Nov 07, 2007 12:42 am
Reply with quote

Thanks a lot.

But how we use pointers in COBOL. I have never used them.
Please explain it.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 07, 2007 12:49 am
Reply with quote

Hello,

Here's the link for POINTER info:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3lr10/6.2.39.3?ACTION=MATCHES&REQUEST=unstring+pointer&TYPE=FUZZY&SHELF=&DT=20020920180651&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

Other UNSTRING info is in the same manual (which can be accessed via "Manuals" at the top of the page).
Back to top
View user's profile Send private message
Varun Singh

New User


Joined: 01 Aug 2007
Posts: 25
Location: Delhi

PostPosted: Wed Nov 07, 2007 2:15 pm
Reply with quote

01 WS-SUB PIC 9(02) VALUE 01.
01 WS-ARRAY-COUNT PIC 9(02) VALUE 01.
01 WS-POINTER PIC S9(04) COMP.
01 DOUBLE-SPACE PIC X(02) VALUE ' '.
PERFORM VARYING WS-SUB FROM 1 BY 1
UNTIL WS-SUB > WS-ARRAY-COUNT
UNSTRING STR
DELIMITED BY DOUBLE-SPACE
INTO A(WS-SUB)
WITH POINTER WS-POINTER
END-UNSTRING
END-PERFORM

I think this might help.... icon_biggrin.gif
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 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
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
Search our Forums:

Back to Top