home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 15a / convdb2.zip / CONFIELD.CMD next >
OS/2 REXX Batch file  |  1987-02-14  |  7KB  |  188 lines

  1. ************************************************************
  2. ************************************************************
  3. *****              File Converter  (c) COPYRIGHT 1983  *****
  4. *****  confield.cmd                Data Based Advisor  *****
  5. *****                                                  *****
  6. *****  AUTHOR: Larry Eitel                             *****
  7. *****  DATE: October 29, 1983                          *****
  8. *****                                                  *****
  9. *****  called from con.cmd                             *****
  10. *****                                                  *****
  11. *****  PURPOSE:                                        *****
  12. *****  Get a valid field name to recieve converted     *****
  13. *****  information and valid field list from the       *****
  14. *****  (SECONDARY) from file.  Then generate REPLACE   *****
  15. *****  statements which can be used to generate a      *****
  16. *****  command file to accomplish the convertion.      *****
  17. *****                                                  *****
  18. *****  DISCLAIMER:                                     *****
  19. *****  The author makes or implies no warranties       *****
  20. *****  regarding the operation or usefulness of this   *****
  21. *****  program.  It is recommended the user make       *****
  22. *****  backups of any valuable files.                  *****
  23. ************************************************************
  24. ************************************************************
  25. DO WHILE t
  26.   ERASE
  27.   ? header
  28.   @ 3,0 SAY 'Convert the contents in the file ' +;
  29.   trim(fromck)+' and add to the file ' +trim(tock)+ '.' 
  30.   ***** Loop to get a valid field to append to
  31.   STORE t TO check
  32.   DO WHILE check
  33.     SELECT PRIMARY
  34.     ***** Initialize tofield which will contain name of 
  35.     ***** the field in the to file.
  36.     STORE '          ' TO tofield
  37.     ***** Get the name of the tofield.  If the name of the
  38.     ***** tofield in the PRIMARY use area is the same as 
  39.     ***** the name of a field in the SECONDARY use area,
  40.     ***** preface the field name with p.<fieldname>.
  41.     @ 05,00 SAY 'Enter the field to convert to, '+;
  42.     '(?)isplay fields, <RET> if  Done. ' GET tofield
  43.     @ 10,00 SAY ' ' 
  44.     ***** Display last REPLACE statement generated
  45.     IF 0#test(line&lnumber)
  46.       ? line&lnumber
  47.     ENDIF 0#test(line&lnumber) 
  48.     READ
  49.     ***** Display structure of the to file
  50.     IF !(tofield)= '?' 
  51.       @ 11,00
  52.       @ 06,00 SAY ' ' 
  53.       DISPLAY STRUCTURE
  54.       ?
  55.       ? 'Press any key to continue.' 
  56.       WAIT
  57.       ERASE
  58.       ? header
  59.       @ 3,0 SAY 'Convert the contents in the file ' +;
  60.       trim(fromck)+' and add to the file ' +trim(tock)+ '.' 
  61.       LOOP
  62.     ENDIF !(tofield)= 'D' 
  63.     IF tofield= ' ' 
  64.       ERASE
  65.       RETURN
  66.     ENDIF tofield= ' ' 
  67.     ***** Test for valid field in the to file
  68.     IF 0=test(&tofield=&tofield)
  69.       ?? chr(7)
  70.       SET inte OFF
  71.       @ 23,00 SAY 'INVALID FIELD NAME' 
  72.       SET inte ON
  73.     ELSE
  74.       STORE f TO check
  75.     ENDIF 0=test(&tofield=&tofield)
  76.   ENDDO WHILE check
  77.   ***** This loop will get the field list of the from file
  78.   ***** that will be appended to the to file into the 
  79.   ***** tofield
  80.   ***** Initialize fromfiel which will contain the field
  81.   ***** list to append to new field
  82.   STORE $(str(0,79),1,78) TO fromfiel
  83.   STORE t TO check
  84.   DO WHILE check
  85.     ***** Get the field list from the SECONDARY file. If a  
  86.     ***** field name in the field list is the same as a  
  87.     ***** field in the (PRIMARY) tofile, preface the field        
  88.     ***** name with s.<fieldname>.
  89.     @ 06,00 SAY 'Enter contents to transfer to the '+;
  90.     'above field.' 
  91.     @ 07,00 SAY '?>Display fields, <BLANK> to Return.' 
  92.     @ 08,00 GET fromfiel
  93.     READ
  94.     ***** Display structure of the from file
  95.     IF fromfiel=' '
  96.       @ 22,00
  97.       STORE f TO check
  98.       LOOP
  99.     ENDIF
  100.     IF '?' $fromfiel
  101.       SELECT secondary
  102.       @ 11,00
  103.       @ 22,00
  104.       @ 09,00 SAY ' ' 
  105.       DISPLAY STRUCTURE
  106.       ? 
  107.       ? 'Press any key to continue.' 
  108.       WAIT
  109.       ERASE
  110.       ? header
  111.       @ 3,0 SAY 'Convert the contents in the file ' +;
  112.       trim(fromck)+' and add to the file ' +trim(tock)+ '.' 
  113.       @ 05,00 SAY 'Enter the field to convert to, '+;
  114.       '(D)isplay fields, <RET> to Exit. :         :' 
  115.       SET inte OFF
  116.       @ 05,65 SAY tofield
  117.       SET inte ON
  118.       LOOP
  119.     ENDIF '?' $fromfiel 
  120.     ***** The following is a series of tests on the fromfiel
  121.     ***** entry.  There doesn't seem to be a more graceful
  122.     ***** of testing this entry.  What I do is tell the user
  123.     ***** if the message at the bottom of the screen remains
  124.     ***** there, to press any key and correct the entry.
  125.     ***** It has to pass two different tests. One is a test
  126.     ***** to see if it is a valid field list. The other is a
  127.     ***** test to verify if the field list can be REPLACED
  128.     ***** into the field chosen.  In other words you will
  129.     ***** not be able to put a character string into a 
  130.     ***** numeric field.
  131.     SET inte OFF
  132.     @ 22,00 SAY 'If this prompt remains on the screen, '+;
  133.     'press any key and correct your entry.' 
  134.     SET inte ON
  135.     ***** Prevent a possible dBASE II error message from
  136.     ***** being displayed on the screen by SETting CONSOL
  137.     ***** OFF.
  138.     SET cons OFF
  139.     RELEASE fromstrg
  140.     STORE &fromfiel TO fromstrg
  141.     SET cons ON
  142.     ***** If the above STORE command failed because 
  143.     ***** fromfiel did not contain a valid field list,
  144.     ***** memory variable fromstrg will not have a value.
  145.     IF 0=test(fromstrg)
  146.       LOOP
  147.     ENDIF 0=test(fromstrg) 
  148.     ***** Prevent a possible dBASE II error message from
  149.     ***** being displayed on the screen by SETting CONSOL
  150.     ***** OFF.
  151.     SET cons OFF
  152.     SELECT seco
  153.     REPLACE &tofield WITH fromstrg
  154.     SET cons ON
  155.     SELECT PRIMARY
  156.     ***** If the above REPLACE command failed because 
  157.     ***** tofield cannot be REPLACEd with fromstrg. Probably
  158.     ***** due to one being numeric and the other a character
  159.     ***** string.
  160.     IF 0=test(&tofield=fromstrg)
  161.       @ 22,00
  162.       LOOP
  163.     ELSE
  164.       STORE f TO check
  165.     ENDIF 0=test(&tofield=fromstrg) 
  166.     ***** If the entry passed the above tests, STORE a 
  167.     ***** REPLACE statement to a new memory variable. To do
  168.     ***** this, I used the memory variable phrase "line"
  169.     ***** and added a sequential apha-numeric string to the
  170.     ***** end of it.  The result is for every valid REPLACE 
  171.     ***** statement created, there will a different memory
  172.     ***** variable created e.,g., line1, line2, line3, etc.
  173.     IF number<10
  174.       STORE str(number,1) TO lnumber
  175.     ELSE
  176.       STORE str(number,2) TO lnumber
  177.     ENDIF number<10 
  178.     ***** STORE a REPLACE statement to a memory variable.
  179.     ***** Note that if lnumber=1, using the macro function,
  180.     ***** you can STORE the following string to line1. Next
  181.     ***** time around it will be STOREd to line2.
  182.     STORE 'REPLACE ' +trim(tofield)+ ' WITH ' +;
  183.     trim(fromfiel) TO line&lnumber
  184.     STORE number+1 TO number
  185.   ENDDO WHILE check 
  186. ENDDO WHILE t 
  187. RETURN
  188.