View previous topic :: View next topic
|
Author |
Message |
Munish Singla
New User
Joined: 18 Jul 2007 Posts: 21 Location: kolkata
|
|
|
|
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 |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
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 |
|
|
Munish Singla
New User
Joined: 18 Jul 2007 Posts: 21 Location: kolkata
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Munish,
Try using COBOL STRING verb. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Munish Singla
New User
Joined: 18 Jul 2007 Posts: 21 Location: kolkata
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Munish Singla
New User
Joined: 18 Jul 2007 Posts: 21 Location: kolkata
|
|
|
|
Thanks a lot.
But how we use pointers in COBOL. I have never used them.
Please explain it. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
Back to top |
|
|
Varun Singh
New User
Joined: 01 Aug 2007 Posts: 25 Location: Delhi
|
|
|
|
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.... |
|
Back to top |
|
|
|