home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rickact.zip / RickACT.cmd
OS/2 REXX Batch file  |  1995-11-16  |  5KB  |  144 lines

  1. /* rexx
  2.  *
  3.  * name:      RickACT.cmd
  4.  *
  5.  * date:      July 20, 1995
  6.  *
  7.  * Author:    Rick Kruer for OS/2 Magazine
  8.  *            <rick@computer-miracles.com>
  9.  *
  10.  * Function:  This Rexx program will read a Symantec Act! for Windows
  11.  *            database (dbf) in comma delimted format, extracting
  12.  *            name and address data to produce VisPro/Reports labels.
  13.  *
  14.  *            This program as written will extract ALL records from
  15.  *            the Act! database, modify to suit your needs.
  16.  *
  17.  * Status:    This program is freeware and may be distributed for free.
  18.  *
  19.  */
  20.  
  21. namestem.          = ''
  22. keepstem.          = ''
  23. exclude.           = ''
  24. exclude.COUNTRY    = 1                    /* Exclude this Act! field */
  25. exclude.MANAGER    = 1                    /* Exclude this Act! field */
  26. exclude.OWNERRY    = 1                    /* Exclude this Act! field */
  27. exclude.SALUTATION = 1                    /* Exclude this Act! field */
  28. namestem.0         = 0
  29. keepstem.0         = 0
  30. exclude.0          = 0
  31. incount            = 0
  32. outcount           = 0
  33. infile             = 'd:\actwin2\database\miracles.txt'
  34. outfile            = 'y:\work\vpreport.txt'
  35. limit_infile       = ''                       /* limit count or null */
  36.  
  37. say
  38. say "Welcome to Rick's Act! database reformat for VisPro/Reports"
  39. say
  40. say "Input comma delimited database text file:" infile
  41. say "Output VisPro/Report text formatted file:" outfile
  42. say
  43. say "Note: this may take many minutes depending on file size"
  44. say "W o r k i n g . . ."
  45. say
  46. /*
  47.  *---------------------------------------------------------------------
  48.  *   Register Rexx Utility functions
  49.  *---------------------------------------------------------------------
  50.  */
  51. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  52. call SysLoadFuncs
  53.  
  54. /*
  55.  *---------------------------------------------------------------------
  56.  *   Delete output file if it exists
  57.  *---------------------------------------------------------------------
  58.  */
  59. rc = stream(outfile, 'C', 'QUERY EXISTS')
  60. if rc <> '' then do
  61.    rc = stream(outfile, 'C', 'CLOSE')
  62.    rc = SysFileDelete(outfile)
  63.    say 'file' outfile 'deleted'
  64.    end
  65.  
  66. /*
  67.  *---------------------------------------------------------------------
  68.  *   Open files
  69.  *---------------------------------------------------------------------
  70.  */
  71. rc = stream(infile, 'C', 'OPEN READ')
  72. if rc \= 'READY:' then do
  73.    say 'Error doing stream open read'
  74.    say 'rc=' rc
  75.    end
  76.  
  77. rc = stream(outfile, 'C', 'OPEN WRITE')
  78. if rc \= 'READY:' then do
  79.    say 'Error doing stream open write'
  80.    say 'rc=' rc
  81.    end
  82.  
  83. /*
  84.  *---------------------------------------------------------------------
  85.  *   Read Act! comma delimited database, created reformatted data
  86.  *   Write out formatted file for use in VisPro/Reports
  87.  *---------------------------------------------------------------------
  88.  */
  89. line = linein(infile)
  90. first = 1
  91. incount = 1
  92. do while lines(infile) <> 0
  93.  
  94.    i = 0
  95.    do i=i+1
  96.       k = pos('",',line)
  97.       if k = 0 then leave
  98.       name = substr(line,1,k)
  99.       name = strip(name,'B','"')
  100.       line = substr(line,k+2)
  101.  
  102.       if first = 1 then do             /* Special procesing for     */
  103.          keepstem.0 = keepstem.0 + 1   /* first record includes     */
  104.          keepstem.i = name             /* saving database field     */
  105.          end                           /* names (such as 'Name',    */
  106.       else do                          /* 'Address', 'Phone', etc.) */
  107.          namestem.0 = namestem.0 + 1
  108.          namestem.i = name
  109.          end
  110.       end
  111.  
  112. /*
  113.  *---------------------------------------------------------------------
  114.  *   Process each database field for this record
  115.  *---------------------------------------------------------------------
  116.  */
  117.    first = 0
  118.    do i = 1 to namestem.0
  119.       if namestem.i = '' then iterate
  120.       name = keepstem.i
  121.       if exclude.name = 1 then iterate
  122.       out = 'Data.'incount'.'left(keepstem.i,12,' ') '=' '"'namestem.i'"'
  123.       rc = lineout(outfile,out)
  124.       outcount = outcount + 1
  125.       end
  126.  
  127.    out = 'Comment' '=' '"----------------------------------------------------------------"'
  128.    rc = lineout(outfile,out)
  129.    line = linein(infile)
  130.    incount = incount + 1
  131.    end
  132.  
  133. /*
  134.  *---------------------------------------------------------------------
  135.  *   Close up shop
  136.  *---------------------------------------------------------------------
  137.  */
  138. rc = stream(infile, 'C', 'CLOSE')
  139. rc = stream(outfile, 'C', 'CLOSE')
  140.  
  141. say 'Input record count.........................' right(incount,9)
  142. say 'Output record count........................' right(outcount,9)
  143. exit 0
  144.