home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / clar2asc.zip / CLAR2ASC.CLA next >
Text File  |  1992-06-17  |  5KB  |  113 lines

  1.  
  2.     OMIT('** **')
  3.  
  4. ┌───────────────────────────────────────────────────────────────────────┐
  5. │                                                                       │
  6. │Clarion Technical Staff                                                │
  7. │June 15, 1992                                                          │
  8. │Sample program to convert Clarion data files to ASCII fixed length     │
  9. │records. (fixed lenght fields and fixed lenght records)                │
  10. │                                                                       │
  11. │ This program will read the accompanying Clarion data file             │
  12. │ and convert it to a ASCII data file.                                  │
  13. │ To use this program, change the field, file and key names to your     │
  14. │ respective names.                                                     │
  15. │                                                                       │
  16. └───────────────────────────────────────────────────────────────────────┘
  17.    ╔═══════════════════════════════════════════════════════════════╗
  18.    ║ Note: This program will make use of the DOS file declaration. ║
  19.    ║ One might think that to convert Clarion records to ASCII flat ║
  20.    ║ files, the ASCII attribute should be used.  This of course    ║
  21.    ║ would work, but it can create some problems.  For a Clarion   ║
  22.    ║ "ASCII" file, the add statement writes data from the record   ║
  23.    ║ with trailing spaces clipped.  If the last file is a string   ║
  24.    ║ of 10 and it has the data 'MARY' in this field then this      ║
  25.    ║ record will be 6 characters shorter than the "fixed" length.  ║
  26.    ║ For this reason we have used the DOS binary file type and     ║
  27.    ║ have added our own CR/LF at the end of each record.           ║
  28.    ║                                                               ║
  29.    ╚═══════════════════════════════════════════════════════════════╝
  30.  
  31.  
  32.   ** **
  33.  
  34.                                 !   ┌────────────── change this to the name
  35. clar2asc     PROGRAM            !   │               of your ascii file on disk.
  36.                                 !   
  37. DOS_FIL   DOS,PRE(DOS),NAME('NAME.ASC') ! ascii file declaration
  38. RECORD      RECORD                ! see sample ascii file attached
  39. LNAME     STRING(20)              ! you will need to determine the lenghts
  40. FNAME     STRING(10)              ! of all of your fields -
  41. ADDRESS1  STRING(30)              ! when reading a flat ascii file, all
  42. ADDRESS2  STRING(30)              ! fields in the dos file declaration
  43. CITY      STRING(10)              ! will be strings
  44. ST        STRING(2)
  45. ZIP       STRING(5)
  46. DATE      STRING(8)         !ascii date looks like 12/22/92
  47. DATE2     STRING(6)         !ascii date looks like 122292
  48. CR        BYTE(13)          !Carrage return ascii code 13
  49. LF        BYTE(10)          !Line feed ascii code 10
  50.           . .
  51.  
  52.  
  53.                                      !   ┌──────── change this to the name
  54.                                      !   │         of your clarion file on disk.
  55.                                      !   
  56. CLAR_FIL   FILE,PRE(CLA),CREATE,NAME('NAME.DAT')
  57. LNAME_KEY   KEY(CLA:LNAME),DUP
  58. RECORD        RECORD
  59. LNAME     STRING(20)                       !change to your field and key names
  60. FNAME     STRING(10)
  61. ADDRESS1  STRING(30)
  62. ADDRESS2  STRING(30)
  63. CITY      STRING(10)
  64. ST        STRING(2)
  65. ZIP       STRING(5)
  66. DATE      LONG
  67. DATE2     LONG
  68.            .  .
  69.  
  70.  
  71.  
  72. SCREEN   SCREEN       HUE(15,1),PRE(SCR)
  73.            ROW(13,23) STRING('CONVERTING RECORD NUMBER:')
  74. REC_NO       COL(49)  STRING(@N10)
  75.          .
  76.  
  77.  
  78.          CODE
  79.     OPEN(SCREEN)
  80.     OPEN(CLAR_FIL)
  81.     IF ERROR() THEN STOP(ERROR()).
  82.     CREATE(DOS_FIL)                     ! **** note this will wipe out
  83.                                         ! a existing dos file
  84.     IF ERROR() THEN STOP(ERROR()).
  85.  
  86.     SET(CLAR_FIL)                     ! set the file to process sequentially
  87.     LOOP UNTIL EOF(CLAR_FIL)          ! start loop
  88.       NEXT(CLAR_FIL)                  ! read record
  89.       SCR:REC_NO += 1                !increment counter
  90.  
  91.        !******* equate each field in ascii file to corresponding field in
  92.               ! Clarion file. Change these names to your field names
  93.  
  94.        DOS:LNAME    =   CLA:LNAME
  95.        DOS:FNAME    =   CLA:FNAME
  96.        DOS:ADDRESS1 =   CLA:ADDRESS1
  97.        DOS:ADDRESS2 =   CLA:ADDRESS2
  98.        DOS:CITY     =   CLA:CITY
  99.        DOS:ST       =   CLA:ST
  100.        DOS:ZIP      =   CLA:ZIP
  101.  
  102.          !******************    convert ascii dates to clarion dates-2 examples
  103.          !first example   ascii date will look like 12/22/92
  104.  
  105.       DOS:DATE = FORMAT(CLA:DATE,@D1)
  106.  
  107.           ! second example  ascii date will look like 122292 or 092292
  108.       DOS:DATE2 = RIGHT(DEFORMAT(FORMAT(CLA:DATE,@D1),@p##/##/##p))
  109.       ADD(DOS_FIL)
  110.       IF ERROR() THEN STOP(ERROR()).
  111.     .
  112.  
  113.