HP3000-L Archives

September 2015, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Robert W.Mills" <[log in to unmask]>
Reply To:
Robert W.Mills
Date:
Tue, 8 Sep 2015 13:40:54 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (157 lines)
This macro makes is easier to create a CSV record.

*> *************************************************************************
*> %AppendCsv(Field#,CsvRecord#)
*> -------------------------------------------------------------------------
*> Append Field to CsvRecord. If Field contains a comma (,) then Field is
*> quoted (") before being added. Quotes (") within Field will be replaced
*> with single-quotes (').
*> *************************************************************************

01 AppendCsv-macro.
05 AppendCsv-comma-count pic s9(04) comp value zero.
05 AppendCsv-field pic x(512) value spaces.
05 AppendCsv-field-length pic s9(04) comp value zero.
05 AppendCsv-index pic s9(04) comp value zero.
05 AppendCsv-pointer pic s9(04) comp value zero.

$define %AppendCsv=
initialize AppendCsv-macro
move function trim(!1) to AppendCsv-field
move length(function trim(AppendCsv-field)) to AppendCsv-field-length
move length(function trim(!2, trailing)) to AppendCsv-pointer
if AppendCsv-pointer > 1 then
move "," to !2(!3:1)
add 1 to AppendCsv-pointer end-add
end-if
perform
varying AppendCsv-index from 1 by 1
until AppendCsv-index > AppendCsv-field-length
if AppendCsv-field(AppendCsv-index:1) = "," then
add 1 to AppendCsv-comma-count end-add
end-if
if AppendCsv-field(AppendCsv-index:1) = quote then
move "'" to AppendCsv-field(AppendCsv-index:1)
end-if
end-perform
if AppendCsv-field-length > zero then
if AppendCsv-comma-count > zero then
string
quote, function trim(AppendCsv-field), quote delimited by size
into !2 with pointer AppendCsv-pointer
end-string
else
string
function trim(AppendCsv-field) delimited by size
into !2 with pointer AppendCsv-pointer
end-string
end-if
end-if#

Regards,
Robert W.Mills


> On 7 Sep 2015, at 21:40, Tony Summers <[log in to unmask]> wrote:
> 
> Worth putting a final comma at the end of the line, otherwise some versions of excel can make the last column very wide.
> 
> From: Walter J. Murray [mailto:[log in to unmask]]
> Sent: Monday, September 07, 2015 09:28 PM
> To: [log in to unmask] <[log in to unmask]>
> Subject: Re: [HP3000-L] Fun with COBOL
> 
> I'm a little late to the party, but here's my solution. Yes, the STRING
> statement is helpful. I don't advocate using an apostrophe to delimit
> nonnumeric literals, preferring to stick with standard COBOL. And yes,
> QUOTE is a figurative constant guaranteed to give you a quotation mark.
> 
> Here's a sample program:
> 
> 000100 IDENTIFICATION DIVISION.
> 000200 PROGRAM-ID. COBTEST.
> 000610 DATA DIVISION.
> 000620 WORKING-STORAGE SECTION.
> 000630 77 ONE-COMMA PIC X VALUE ",".
> 000640 01 1ST-ITEM PIC X(6) VALUE "ITEM 1".
> 000650 01 2ND-ITEM PIC X(6) VALUE "ITEM 2".
> 000660 01 3RD-ITEM PIC X(6) VALUE "ITEM 3".
> 000670 01 MY-RECORD PIC X(72).
> 000700 PROCEDURE DIVISION.
> 000800 1000-START.
> 000900 INITIALIZE MY-RECORD
> 001000 STRING QUOTE 1ST-ITEM QUOTE ONE-COMMA
> 001010 QUOTE 2ND-ITEM QUOTE ONE-COMMA
> 001011 QUOTE QUOTE ONE-COMMA
> 001012 QUOTE QUOTE ONE-COMMA
> 001013 QUOTE 3RD-ITEM QUOTE
> 001014 DELIMITED SIZE
> 001015 INTO MY-RECORD
> 001016 DISPLAY MY-RECORD
> 001020 STOP RUN.
> 001100 END PROGRAM COBTEST.
> 
> Here's the output:
> 
> "ITEM 1","ITEM 2","","","ITEM 3"
> 
> Walter
> 
> 
> -----Original Message-----
> From: HP-3000 Systems Discussion [mailto:[log in to unmask]] On
> Behalf Of Newton, Ernie
> Sent: Thursday, September 03, 2015 10:47 AM
> To: [log in to unmask]
> Subject: [HP3000-L] Fun with COBOL
> 
> 
> Greetings,
> 
> It's been a long time since I wrote COBOL, and I have an elementary
> question about creating a comma-delimited file.
> 
> If I want...
> 
> "item one", "item two","","","item three"
> 
> How do I create the "," between item one and item two? Is it simply PIC
> "","" (quote comma quote inside double quotes?)
> 
> And the ","",""," would it be the same? Just put that inside double
> quotes?
> 
> Something tells me that there is an escape sequence, but the mind is not
> cooperating.
> 
> Thanks,
> 
> Ernie
> 
> ________________________________
> 
> This message, including any attachments, is intended solely for the use
> of the named recipient(s) and may contain confidential and/or privileged
> information. Any unauthorized review, use, disclosure or distribution of
> this communication(s) is expressly prohibited. If you are not the
> intended recipient, please contact the sender by reply e-mail and
> destroy any and all copies of the original message.
> 
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html<http://raven.utc.edu/archives/hp3000-l.html> *
> 
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html<http://raven.utc.edu/archives/hp3000-l.html> *
> 
> The contents of this email are confidential to the intended recipient and may not be disclosed. Although it is believed that this email and any attachments are virus free, it is the responsibility of the recipient to confirm this.
> 
> Details of Smith & Williamson group companies and Nexia Smith & Williamson Audit Limited and their regulators (where applicable), can be found at this URL
> 
> http://www.smith.williamson.co.uk/disclosure
> 
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2