home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
clarion
/
clar2asc.zip
/
CLAR2ASC.CLA
next >
Wrap
Text File
|
1992-06-17
|
5KB
|
113 lines
OMIT('** **')
┌───────────────────────────────────────────────────────────────────────┐
│ │
│Clarion Technical Staff │
│June 15, 1992 │
│Sample program to convert Clarion data files to ASCII fixed length │
│records. (fixed lenght fields and fixed lenght records) │
│ │
│ This program will read the accompanying Clarion data file │
│ and convert it to a ASCII data file. │
│ To use this program, change the field, file and key names to your │
│ respective names. │
│ │
└───────────────────────────────────────────────────────────────────────┘
╔═══════════════════════════════════════════════════════════════╗
║ Note: This program will make use of the DOS file declaration. ║
║ One might think that to convert Clarion records to ASCII flat ║
║ files, the ASCII attribute should be used. This of course ║
║ would work, but it can create some problems. For a Clarion ║
║ "ASCII" file, the add statement writes data from the record ║
║ with trailing spaces clipped. If the last file is a string ║
║ of 10 and it has the data 'MARY' in this field then this ║
║ record will be 6 characters shorter than the "fixed" length. ║
║ For this reason we have used the DOS binary file type and ║
║ have added our own CR/LF at the end of each record. ║
║ ║
╚═══════════════════════════════════════════════════════════════╝
** **
! ┌────────────── change this to the name
clar2asc PROGRAM ! │ of your ascii file on disk.
!
DOS_FIL DOS,PRE(DOS),NAME('NAME.ASC') ! ascii file declaration
RECORD RECORD ! see sample ascii file attached
LNAME STRING(20) ! you will need to determine the lenghts
FNAME STRING(10) ! of all of your fields -
ADDRESS1 STRING(30) ! when reading a flat ascii file, all
ADDRESS2 STRING(30) ! fields in the dos file declaration
CITY STRING(10) ! will be strings
ST STRING(2)
ZIP STRING(5)
DATE STRING(8) !ascii date looks like 12/22/92
DATE2 STRING(6) !ascii date looks like 122292
CR BYTE(13) !Carrage return ascii code 13
LF BYTE(10) !Line feed ascii code 10
. .
! ┌──────── change this to the name
! │ of your clarion file on disk.
!
CLAR_FIL FILE,PRE(CLA),CREATE,NAME('NAME.DAT')
LNAME_KEY KEY(CLA:LNAME),DUP
RECORD RECORD
LNAME STRING(20) !change to your field and key names
FNAME STRING(10)
ADDRESS1 STRING(30)
ADDRESS2 STRING(30)
CITY STRING(10)
ST STRING(2)
ZIP STRING(5)
DATE LONG
DATE2 LONG
. .
SCREEN SCREEN HUE(15,1),PRE(SCR)
ROW(13,23) STRING('CONVERTING RECORD NUMBER:')
REC_NO COL(49) STRING(@N10)
.
CODE
OPEN(SCREEN)
OPEN(CLAR_FIL)
IF ERROR() THEN STOP(ERROR()).
CREATE(DOS_FIL) ! **** note this will wipe out
! a existing dos file
IF ERROR() THEN STOP(ERROR()).
SET(CLAR_FIL) ! set the file to process sequentially
LOOP UNTIL EOF(CLAR_FIL) ! start loop
NEXT(CLAR_FIL) ! read record
SCR:REC_NO += 1 !increment counter
!******* equate each field in ascii file to corresponding field in
! Clarion file. Change these names to your field names
DOS:LNAME = CLA:LNAME
DOS:FNAME = CLA:FNAME
DOS:ADDRESS1 = CLA:ADDRESS1
DOS:ADDRESS2 = CLA:ADDRESS2
DOS:CITY = CLA:CITY
DOS:ST = CLA:ST
DOS:ZIP = CLA:ZIP
!****************** convert ascii dates to clarion dates-2 examples
!first example ascii date will look like 12/22/92
DOS:DATE = FORMAT(CLA:DATE,@D1)
! second example ascii date will look like 122292 or 092292
DOS:DATE2 = RIGHT(DEFORMAT(FORMAT(CLA:DATE,@D1),@p##/##/##p))
ADD(DOS_FIL)
IF ERROR() THEN STOP(ERROR()).
.