HP3000-L Archives

March 2007, Week 1

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:
"Dave Powell, MMfab" <[log in to unmask]>
Reply To:
Dave Powell, MMfab
Date:
Wed, 7 Mar 2007 11:55:42 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (118 lines)
You can get into trouble using "string" and "delimited by spaces" if any of
your fields have spaces in the middle, like a company-name might.

A better approach (for those without Supertool) is to write a routine that
sets pointers to the 1st and last characters of the field, and then adds to
the first / left pointer until it finds a non-blank character, then subtracts
from the last / right pointer untill it finds a non-blank character or
collides with the first pointer.  Along the way you should also check for
commas in each field and enclose the (non-blank) part of the field in quotes
if there are any commas.  And start by moving all numeric fields to something
with zero-suppressing picture clauses.  If you don't feel like hard-wiring the
max field lengths, you can get them with the Cobol 'length' function or HP's
old ".len." pseudo-intrinsic.

Below is a Cobol macro from one of my pgms that does most of the work.  Its
parms are the data-field and a numeric field whose value is the data-field
length.  The output record is called "incomplete-rec".

To use it, first, in your startup
MOVE   1        TO    RPTR        (the output pointer)
COMPUTE CUST-PO-LEN = FUNCTION LENGTH (CUST-PO-C40)
and repeat for other fields,
then
%APPENDFIELD(SORT-CUST-PO#,CUST-PO-LEN#).
%APPENDFIELD(ANY-OTHER-ITEM#,ANY-OTHER-ITEM-LEN#).
and repeat for other fields.

 01  CSV-FIELDS.
     05  CUST-PO-LEN         PIC S9(09)  COMP.
     05  JUNK                          PIC S9(09)  COMP.
     05  COMMA-CNT           PIC S9(09)  COMP.
     05  RPTR            PIC S9(09)  COMP.
     05  FLEN            PIC S9(09)  COMP.
     05  START-PTR               PIC S9(09)  COMP.
     05  END-PTR                 PIC S9(09)  COMP.
     05  CSV-REC-LEN             PIC S9(09)  COMP.
     05  QUOTE-CHAR              PIC X(01)  VALUE  """".
     05  COMMA-CHAR      PIC  X(01)  VALUE  ",".
     05  FORCE-QUOTE-SWITCH      PIC  X(01).
       88  FORCE-QUOTE               VALUE  "Y".
       88  DONT-FORCE-QUOTE          VALUE  "N".

$DEFINE  %APPENDFIELD=
$CONTROL  LOCOFF
         MOVE  0                 TO  COMMA-CNT
         IF  RPTR            >   1
             MOVE  COMMA-CHAR    TO  INCOMPLETE-REC(RPTR:1)
             ADD  1          TO  RPTR
         END-IF
         MOVE  !2                TO  END-PTR
         PERFORM     UNTIL   ( END-PTR   <=  1 )
                     OR  ( !1(END-PTR:1) <>  SPACES )
             SUBTRACT  1         FROM  END-PTR
         END-PERFORM
         MOVE  1                 TO  START-PTR
         PERFORM     UNTIL   ( START-PTR     >=  !2 )
                     OR      ( START-PTR     >   END-PTR )
                     OR      ( !1(START-PTR:1)   <>  SPACES )
             ADD  1              TO  START-PTR
         END-PERFORM
         COMPUTE  FLEN       =   END-PTR - START-PTR + 1
         PERFORM     VARYING     JUNK    FROM  START-PTR  BY  1
                     UNTIL       JUNK        >   END-PTR
             IF  ( !1(JUNK:1)    =    COMMA-CHAR )
                 ADD  1          TO  COMMA-CNT
             END-IF
             IF  ( !1(JUNK:1)    =    QUOTE-CHAR )
                 MOVE  SPACES    TO  !1(JUNK:1)
             END-IF
         END-PERFORM
         IF  FLEN        >   0
             IF  COMMA-CNT       >   0
             OR  ( FORCE-QUOTE )
                 STRING  QUOTE-CHAR,  !1(START-PTR:FLEN)
                         QUOTE-CHAR
                         DELIMITED BY SIZE   INTO  INCOMPLETE-REC
                     WITH POINTER        RPTR
             ELSE
                 STRING  !1(START-PTR:FLEN)
                         DELIMITED BY SIZE   INTO  INCOMPLETE-REC
                     WITH POINTER        RPTR
             END-IF
         END-IF
$CONTROL  LOCON
         #


----- Original Message ----- 
From: "kellie Jones" <[log in to unmask]>
To: <[log in to unmask]>
Sent: Wednesday, March 07, 2007 09:53
Subject: [HP3000-L] Create a CSV file


I've read the archives - and the only info I can find on CSV files is
converting
to fixed from a csv file.

I was wondering if there was a way to create a *real* csv file on the 3000.

I don't have many resources - I can create a csv file with COBOL or with
QUIZ. What they really are is a fixed length file with commas in between the
fields. Problem is, if you open the file up in excel - there are extra spaces,
and
it doesn't handle it correctly (you can see the data fine - but if you need to
load it into a database or do a lookup - it includes the trailing spaces). I'd
have to do a trim in excel and re-save the file to get rid of the spaces.

Is there a way to do this in COBOL or even just from the OS?

tia

* 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