Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to RTRIM in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to RTRIM in COBOL
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    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Sat Nov 03, 2007 6:26 am    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Sat Nov 03, 2007 3:42 pm    Post subject:
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

Site Director


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

PostPosted: Sun Nov 04, 2007 10:13 am    Post subject:
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    Post subject: Reply to: How to RTRIM in COBOL
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

Site Director


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

PostPosted: Tue Nov 06, 2007 8:57 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Nov 07, 2007 12:49 am    Post subject:
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    Post subject:
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    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 IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us