Cust# Address Zip
"1997","123 South Ave ","12345"
"1998","1276 North Ave ","65455"
And i want the file to look like this:
"1997","123 South Ave","12345"
"1998","1276 North Ave","65455"
This would no doubt turn the file into a varible
length record, but isint there a keyword or
something to do this kinda like rtrim in oracle??
Any help would be greatly appreciated. Thanks!
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Cust# Address Zip
"3534","123 So Ave ","53436"
"6235","4321 Sesame St ","84674"
And i want it to look like this:
"3534","123 So Ave","53436"
"6235","4321 Sesame St","84674"
This would no doubt change this to a varible length record, but i can't
seem to find out anything on this in any of my books. Isint there a
keyword i can use like in Oracle you would use 'RTRIM(field)' and that
would get rid of the spaces. Is there anything i can do like that in
COBOL. Any help would be greatly appreciated. Thanks!
raide...@my-deja.com wrote:
>
> Can someone tell me how to get rid of trailing
> spaces in cobol. I can't seem to find any answers
> in any of my books. Let say i have a file that
> the fields are enclosed by "" and each field is
> comma delimited. It looks like this:
>
> Cust# Address Zip
>
> "1997","123 South Ave ","12345"
> "1998","1276 North Ave ","65455"
>
> And i want the file to look like this:
>
> "1997","123 South Ave","12345"
> "1998","1276 North Ave","65455"
>
> This would no doubt turn the file into a varible
> length record, but isint there a keyword or
> something to do this kinda like rtrim in oracle??
If your file already exists in the space-filled format then a simple move of
each field to the output file would suffice. Using the STRING command or
reference modification for the variable fields. Typically COBOL does not
input comma separated files, although STRING will help with this if there is
no other way.
The long way:
Set up each field as a varible field in WS.
move fields from fixed to variable
determine individual lengths and set appropriate ODO length indicator
STRING delimited by size into V length output record
set output record length
write record
In other words, do your homework.
This will NOT remove blanks from embedded fields. Neither is it
platform independent. COBOL allows us to write reasonably tight code that
will achieve both.
(The following is ALMOST platform independent; you would need to change the
file definition from LINE SEQUENTIAL to SEQUENTIAL (and specify variable
format through JCL) if you were to run it on a mainframe...Across the PC
spectrum I believe it will run on any COBOL supported platform.)
IDENTIFICATION DIVISION.
PROGRAM-ID. 'STRTEST'.
*AUTHOR. Peter E. C. Dashwood.
* This program demonstrates the use of COBOL to remove trailing
* blanks.
*DATE_WRITTEN. September,1999.
ENVIRONMENT DIVISION.
configuration section.
source-computer. IBM-PC.
object-computer. IBM-PC.
input-output section.
file-control.
select INFILE assign "input.csv"
organization is line sequential
access mode is sequential.
select OUTFILE assign "output.csv"
organization is line sequential
access mode is sequential.
*------------------------ DATA DIVISION ---------------------
DATA DIVISION.
file section.
FD INFILE
LABEL RECORDS STANDARD
DATA RECORD is INPUT-RECORD.
01 INPUT-RECORD pic x(255).
FD OUTFILE
LABEL RECORDS STANDARD
DATA RECORD is OUTPUT-RECORD.
01 OUTPUT-RECORD pic x(100).
WORKING-STORAGE SECTION.
01 field-1 pic x(7).
01 field-2 pic x(50).
01 field-3 pic x(8).
01 record-counts.
12 in-count pic s9(9) comp-5.
12 out-count pic s9(9) comp-5.
12 display-count pic 9(9).
01 end-flag pic x.
88 not-finished value zero.
88 finished value '1'.
PROCEDURE DIVISION.
MAIN SECTION.
a000.
perform startup-housekeeping
perform main-logic until finished
perform close-down
.
a999.
stop run.
*-----------------------------------------------------------
STARTUP-HOUSEKEEPING section.
sh000.
open input INFILE
output OUTFILE
initialize record-counts
set not-finished to TRUE
.
sh999.
exit.
*-----------------------------------------------------------
MAIN-LOGIC section.
ml000.
read INFILE
at end
set finished to TRUE
go to ml999
end-read
add 1 to in-count
*
* Remove the trailing blanks with COBOL string functions...
*
move spaces to field-1
field-2
field-3
unstring input-record
delimited by ','
into field-1
field-2
field-3
end-unstring
*
* Unfortunately, there is a special case where field
* 2 may terminate with a single space. This will NOT
* be removed by delimiting with a double space (which is
* the easy option). If it is absolutely necessary to remove
* ALL trailing spaces (even when there is only one), then
* we can handle it with the following inspect..
*
inspect field-2
replacing all ' "' by ' '
*
* ...this will convert the final space/quote to double space
* which will then be handled by the standard stringing.
*
move spaces to output-record
string
field-1
delimited by space
','
delimited by size
field-2
delimited by ' '
'",'
delimited by size
field-3
delimited by space
into output-record
end-string
write output-record
add 1 to out-count
.
ml999.
exit.
*----------------------------------------------------------
CLOSE-DOWN section.
cd000.
close INFILE
OUTFILE
move in-count to display-count
display "Records read =" display-count
move out-count to display-count
display "Records written =" display-count
display space
display "END OF RUN"
.
cd999.
exit.
*---------------- END OF PROGRAM 'STRTEST' ----------------
raide...@my-deja.com wrote in message <7qhcc2$60a$1...@nnrp1.deja.com>...
>Can someone help me get rid of trailing spaces in COBOL. I have a file
>that the fields are enclosed in quotes and is comma delimited. And
>example is as follows:
>
>
>Cust# Address Zip
>
>"3534","123 So Ave ","53436"
>"6235","4321 Sesame St ","84674"
>
>And i want it to look like this:
>
>"3534","123 So Ave","53436"
>"6235","4321 Sesame St","84674"
>
>
>This would no doubt change this to a varible length record, but i can't
>seem to find out anything on this in any of my books. Isint there a
>keyword i can use like in Oracle you would use 'RTRIM(field)' and that
>would get rid of the spaces. Is there anything i can do like that in
>COBOL. Any help would be greatly appreciated. Thanks!
For the task at hand, I would take another approach.
read the input record back to front on a character by character basis using
reference modification,
skipping the trailing spaces, and the spaces after (=before) ending quotes,
moving all other characters
to a ws-field. Then write the output record from the ws-field backward
again.
This would require only two perform varying... loops and require no
knowledge of the fields and their
contents. Only the maximum record size. And the program becomes
multi-purpose.
For a real nice job, I would make the output file a byte-stream to eliminate
trailing spaces at record level in the outfile.
Would you agree ?
> -----Original Message-----
> From: peter dashwood [SMTP:dash...@freewebaccess.co.uk]
> Sent: Friday, September 03, 1999 4:24 AM
> To: comp.la...@list.deja.com
> Subject: Re: Getting rid of trailing spaces
>
> Message from the Deja.com forum:
> comp.lang.cobol
> Your subscription is set to individual email delivery
> _____________________________________________________________
> Deja.com: Share what you know. Learn what you don't.
> http://www.deja.com/
> * To modify or remove your subscription, go to
> http://www.deja.com/edit_sub.xp?group=comp.lang.cobol
> * Read this thread at
> http://www.deja.com/thread/%3C37cf3155%40eeyore.callnetuk.com%3E
This will NOT remove blanks from embedded fields. Neither is it
platform independent. COBOL allows us to write reasonably tight code that
will achieve both.
(The following is ALMOST platform independent; you would need to change the
file definition from LINE SEQUENTIAL to SEQUENTIAL (and specify variable
format through JCL) if you were to run it on a mainframe...Across the PC
spectrum I believe it will run on any COBOL supported platform.)
IDENTIFICATION DIVISION.
PROGRAM-ID. 'STRTEST'.
*AUTHOR. Peter E. C. Dashwood.
* This program demonstrates the use of COBOL to remove trailing
* blanks.
*DATE-WRITTEN. September,1999.
ENVIRONMENT DIVISION.
configuration section.
source-computer. IBM-PC.
object-computer. IBM-PC.
input-output section.
file-control.
select INFILE assign "input.csv"
organization is line sequential
access mode is sequential.
select OUTFILE assign "output.csv"
organization is line sequential
access mode is sequential.
*------------------------ DATA DIVISION ---------------------
DATA DIVISION.
file section.
FD INFILE
LABEL RECORDS STANDARD
DATA RECORD is INPUT-RECORD.
01 INPUT-RECORD pic x(255).
FD OUTFILE
LABEL RECORDS STANDARD
DATA RECORD is OUTPUT-RECORD.
01 OUTPUT-RECORD pic x(255).
WORKING-STORAGE SECTION.
* The 3 work fields are all max size + 1 to enable a space
* delimiter for unstringing.
01 field-1 pic x(7).
01 field-2 pic x(53).
01 field-3 pic x(8).
raide...@my-deja.com wrote in message <7qhc00$5k6$1...@nnrp1.deja.com>...
>Can someone tell me how to get rid of trailing
>spaces in cobol. I can't seem to find any answers
>in any of my books. Let say i have a file that
>the fields are enclosed by "" and each field is
>comma delimited. It looks like this:
>
>Cust# Address Zip
>
>"1997","123 South Ave ","12345"
>"1998","1276 North Ave ","65455"
>
>And i want the file to look like this:
>
>"1997","123 South Ave","12345"
>"1998","1276 North Ave","65455"
>
>This would no doubt turn the file into a varible
>length record, but isint there a keyword or
>something to do this kinda like rtrim in oracle??
In article <7qhc00$5k6$1...@nnrp1.deja.com>,
raide...@my-deja.com wrote:
> Can someone tell me how to get rid of trailing
> spaces in cobol. I can't seem to find any answers
> in any of my books. Let say i have a file that
> the fields are enclosed by "" and each field is
> comma delimited. It looks like this:
>
> Cust# Address Zip
>
> "1997","123 South Ave ","12345"
> "1998","1276 North Ave ","65455"
>
> And i want the file to look like this:
>
> "1997","123 South Ave","12345"
> "1998","1276 North Ave","65455"
>
> This would no doubt turn the file into a varible
> length record, but isint there a keyword or
> something to do this kinda like rtrim in oracle??
> Any help would be greatly appreciated. Thanks!
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>
--
In the beginning there was 1 switch...
Doing it the way you suggest is a bit more complex than you may believe. In
fact, it is likely to be more than one perform varying, with variable
reference modification, especially if you are to handle the special case
noted in my code sample. Furthermore, all this really does is make visible
the code being generated from the COBOL string functions (the object code
would be almost identical (hopefully :-) ) but the compiler has the
advantage of using its own workfields and avoiding arithmetic conversions
which it will certainly have to do with the method you are suggesting.)
Don't get me wrong; I love nested performs (and varying) and I consider
reference modification to be an extremely powerful and useful function
(although I try and limit it to fixed modifiers, so it can be resolved at
compile time rather than at run time).
My real objection is that in this case, this is NOT simple, especially for
someone learning COBOL. Reference modification with variable modifiers has
lead many maintenance programmers in the middle of the night to call down
curses on the author...we should hesitate to recommend it as desirable
coding practice...especially for people just starting.
Of course, all of the above is a matter of opinion and yours is every bit as
valuable (or otherwise) as mine is. If you really think it is so easy, why
not knock up a code sample of a working program to do it and post it
here...? The one I posted took 20 minutes (I modified an existing skeleton)
to write, and another 15 to compile, create test data, find the problem with
the single trailing space, and get a final successful test. (Fortunately, I
had a very rare slow day, and became intrigued by what appeared to be a
positively trivial problem...it ain't.) It was fun and made some light
relief from "real" problems...
Regards,
Pete.
trblshtr wrote in message <7qr8jv$8ac$1...@nnrp1.deja.com>...
Alain Reymond
here is a q&d example. i'm not sure why you think it is not simple.
77 SUB1 PIC 99 VALUE ZERO.
01 PARSER.
03 P-WHOL PIC X(80).
03 P-EACH REDEFINES P-WHOL OCCURS 80 PIC X.
01 SOME-RIGHT PIC X(??) JUST.
01 SOME-LEFT PIC X(??).
.
.
MOVE SOME-LEFT TO P-WHOL.
PERFORM VARYING SUB1 FROM 80 BY -1
UNTIL P-EACH(SUB1) <> SPACE OR
SUB1 = ZERO
CONTINUE
END-PERFORM.
COMPUTE SUB1 = SUB1 + 1.
MOVE P-WHOL(1:SUB1) TO SOME-RIGHT.
In article <37d1...@eeyore.callnetuk.com>,
> > raide...@my-deja.com wrote:
> >> Can someone tell me how to get rid of trailing
> >> spaces in cobol. I can't seem to find any answers
> >> in any of my books. Let say i have a file that
> >> the fields are enclosed by "" and each field is
> >> comma delimited. It looks like this:
> >>
> >> Cust# Address Zip
> >>
> >> "1997","123 South Ave ","12345"
> >> "1998","1276 North Ave ","65455"
> >>
> >> And i want the file to look like this:
> >>
> >> "1997","123 South Ave","12345"
> >> "1998","1276 North Ave","65455"
> >>
> >> This would no doubt turn the file into a varible
> >> length record, but isint there a keyword or
> >> something to do this kinda like rtrim in oracle??
> >> Any help would be greatly appreciated. Thanks!
> >>
> >> Sent via Deja.com http://www.deja.com/
> >> Share what you know. Learn what you don't.
> >>
> >
> >--
> >In the beginning there was 1 switch...
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Share what you know. Learn what you don't.
>
>
--
In the beginning there was 1 switch...
unless SOME-RIGHT is defined as an ODO, it will just pad with
spaces...
Bob
----------------------------------------------------------------------
Bob Berman - West Hartford, CT
mailto:bbe...@netbox.com website: http://www.ntplx.net/~bberman
THE TRUE TERRORISTS IN AMERICA ARE
THE PEOPLE WHO DEMAND TO SEE THE STORE MANAGER !
----+----+----+----+----+----+----+----+----+----+----+----+----+----+
>> IF SUB1 > ZERO
>> MOVE P-WHOL(1:SUB1) TO SOME-RIGHT.
It is more complicated than you think. ;-) The above perform will
inevitably bomb if SOME-LEFT is all spaces: when SUB1 becomes zero,
the "P-EACH(SUB1) <> SPACE" condition will be evaluated and get an
invalid subscript error. Beyond that, when SOME-LEFT is all spaces,
SOME-RIGHT is not changed, leaving in whatever garbage was already
in SOME-RIGHT.
>Shouldn't have posted the first 1 - was distracted by news of an
>unexpected death in the family. presume you can do the housekeeping.
>added the 'just' for similar thread. will be gone for a bit.
We had a long thread on this issue just a few months ago. Turns out,
at least on the compilers we tested it on, loops with reference
modification were *significantly* faster than STRING/UNSTRING and
FUNCTION REVERSE, and even faster than subscripts or indexes. The
speed difference was more than 100:1 in some cases!
--
Judson McClendon judm...@bellsouth.net (remove numbers)
Sun Valley Systems http://personal.bhm.bellsouth.net/~judmc
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."