home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / a / db2mm.lbr / DB2MM.CZD / DB2MM.CMD
Encoding:
Text File  |  1993-10-26  |  4.8 KB  |  187 lines

  1. ***************************************************************
  2. ** DBASE-MM.PRG - JOHN SCHNELL - 1983                 **
  3. ** program to convert dBASE.DBF files to MAILMERGE.TXT files **
  4. **                                 **
  5. **  datafile needed: TEMPLATE.DBF (zero records)         **
  6. **    one fieldname: CONCAT,C,100 (increase size up to 254   **
  7. **             characters, to equal maxlength field)   **
  8. ***************************************************************
  9.  
  10. ERASE
  11. SET TALK OFF
  12. SET ECHO OFF
  13. SET BELL OFF
  14. SET CONFIRM ON
  15. SET DEFAULT TO B:
  16. CLEAR
  17. STORE 100 TO maxlength
  18.  
  19. *******************************
  20. * get name of file to convert *
  21. *******************************
  22. STORE F TO ok
  23. DO WHILE .NOT. ok
  24.   STORE '        ' TO filename
  25.   @ 01,05 SAY 'Enter name of dBASE file to convert to MAILMERGE file';
  26.  
  27.   GET filename
  28.   READ
  29.   ERASE
  30.   @ 01,05 SAY 'Insert diskette with .DBF file into drive B:, push any key'
  31.   SET CONSOLE OFF
  32.   WAIT
  33.   SET CONSOLE ON
  34.   IF    FILE('&filename')
  35.     STORE T TO ok
  36.   ELSE
  37.     ERASE
  38.     ? CHR(7)
  39.     @ 01,00 SAY '!!Sorry, only these .DBF files are on this disk,';
  40.       +'please try again !!'
  41.     ?
  42.     LIST FILES LIKE *.dbf
  43.     STORE 100 TO delay
  44.     DO WHILE delay > 0
  45.       STORE delay-1 TO delay
  46.     ENDDO    delay > 0
  47.     ERASE
  48.   ENDIF FILE('&filename')
  49. ENDDO     .NOT. ok
  50.  
  51. *************************************************
  52. * read file structure and get fields to convert *
  53. *************************************************
  54. ERASE
  55. SET CONFIRM OFF
  56. ? '=== Retrieving database record structure ==='
  57. USE &filename
  58.   COPY STRUCTURE EXTENDED TO tempstru                        USE tempstru
  59. STORE F TO ok
  60. DO WHILE .NOT. ok
  61.   STORE 0 TO count
  62.   STORE 2 TO offset
  63.   STORE 0 TO length
  64.   GOTO TOP
  65.   ERASE
  66.   @ 01,01 SAY '   FIELDNAME / TYPE / LENGTH  ';
  67.     +'- Please identify fields you wish to convert.'
  68.   DO WHILE .NOT. eof
  69.     STORE 'N' TO include
  70.     @ #+(offset),01 SAY str(#,2)+'. '+field:name+'   '+field:type+' ';
  71.       +STR(field:len,3)+'    -- Include in MailMerge file (Y/N)   ';
  72.     GET include
  73.     READ
  74.     IF      !(include) = 'Y'
  75.       IF    field:type = 'C'
  76.     STORE 'var'+STR(count+10,2) TO variable
  77.     STORE field:name TO &variable
  78.     STORE length+field:len TO length
  79.     STORE count+1 to count
  80.       ENDIF field:type = 'C'
  81.       IF    field:type = 'N'
  82.     STORE 'var'+STR(count+10,2) TO variable
  83.     STORE 'STR('+field:name;
  84.           +','+STR(field:len,2);
  85.           +','+STR(field:dec,2)+')' TO &variable
  86.     STORE length+field:len TO length
  87.     STORE count+1 TO count
  88.       ENDIF field:type = 'N'
  89.     ENDIF !(include) = 'Y'
  90.     SKIP
  91.     IF      # = 20
  92.       ERASE
  93.       STORE -19 TO offset
  94.     ENDIF # = 20
  95.   ENDDO    .NOT. eof
  96.   @ 24,10 SAY 'Is the above correct ???';
  97.   GET ok
  98.   READ
  99.   IF    length > maxlength
  100.     STORE F TO ok
  101.     ERASE
  102.     ? CHR(7)
  103.     ? 'Concatenated string too long, ';
  104.       +'eliminate'+STR(length - maxlength,3);
  105.       +' characters from selected fields'
  106.     STORE 100 TO delay
  107.     DO WHILE delay > 0
  108.       STORE delay-1 TO delay
  109.     ENDDO    delay > 0
  110.     ERASE
  111.   ENDIF length > maxlength
  112.  
  113. ENDDO     .NOT. ok
  114. USE
  115. DELETE FILE tempstru
  116.  
  117. ********************************************************
  118. * convert fields to one concatenated field in tempfile *
  119. ********************************************************
  120. ERASE
  121. ? '=== Creating tempfile ===== '
  122. ?
  123. USE template
  124. COPY STRUCTURE TO tempfile
  125. USE
  126. ERASE
  127. ? '=== Creating concatenated records ====='
  128. ?
  129. SELECT PRIMARY
  130. USE &filename
  131. SELECT SECONDARY
  132. USE tempfile
  133. SELECT PRIMARY
  134. GOTO TOP
  135. DO WHILE .NOT. eof .AND. count > 0
  136.   STORE '"' TO m:concat
  137.   STORE 0 TO loop
  138.   DO WHILE count > loop
  139.     STORE 'var'+STR(loop+10,2) TO variable
  140.     STORE &variable TO variable
  141.     STORE m:concat-&variable TO m:concat
  142.     STORE loop+1 TO loop
  143.     IF      count > loop
  144.       STORE m:concat-'","' TO m:concat
  145.     ELSE
  146.       STORE m:concat-'"' TO m:concat
  147.     ENDIF count > loop
  148.   ENDDO    count > loop
  149.   SELECT SECONDARY
  150.   APPEND BLANK
  151.   REPLACE concat WITH m:concat
  152.   ? m:concat
  153.   SELECT PRIMARY
  154.   SKIP
  155. ENDDO     .NOT. eof .AND count > 0
  156. SELECT PRIMARY
  157. USE
  158.  
  159. ************************************************
  160. * copy concatenated .DBF file to .SDF/.MM file *
  161. ************************************************
  162. STORE F TO ok
  163. DO WHILE .NOT. ok
  164.   ERASE
  165.   STORE "        " TO mmfilename
  166.   SET CONFIRM ON
  167.   @ 01,05 SAY 'What name do you want for the MailMerge .TXT file ? ';
  168.   GET mmfilename
  169.  
  170.   READ
  171.   SET CONFIRM OFF
  172.   @ 03,05 SAY 'Is '+!(mmfilename)-'.TXT  correct (Y/N) '; GET ok
  173.   READ
  174. ENDDO     .NOT. ok
  175. ERASE
  176. @ 01,05 SAY !(mmfilename)-'.TXT file now being created, please stand-by'
  177. SELECT SECONDARY
  178. COPY TO &mmfilename SDF delimited with ,
  179. USE
  180. DELETE FILE tempfile
  181. ERASE
  182. @05,05 SAY 'dBASE to MailMerge file conversion is complete'
  183. SET INTENSITY OFF
  184. CLEAR
  185. RELEASE ALL
  186. LETE FILE tempfile
  187. ERAS