SUBROUTINE ACCUTERM.FILE.TRANSFER.SUB(DOSDIR,DOSITEM,MODE,MSG,PICKFILE,PICKITEM) ! * 03-09-06 smt get DOS file(s), write to PICK file item(s) or vice versa * Using AccuTerm FT or FTD facility * the FT creates a 1 to 1 PICK to DOS and DOS to PICK * the FTD facility moves multiple PICK items to a single DOS item and vice versa * Note: the EXPORTFTD does a SSELECT on the PICKFILE, so setup the PICKFILE item ids accordingly * for example: if I'm exporting to an EXCEL spreadsheet, I'll create the PICKFILE item ids * as a numeric sequential number, then "R%6" the item id before writing to the PICKFILE * So a SSELECT of that file will naturally have all the lines in a specific order. * I typical create a header row with that PICKFILE item id being '000000' (six zeros) * Again, the natural SSELECT will occur naturally and the header row becomes line 1 of the * EXCEL spreadsheet * The IMPORTFTD (which I seldom use) brings DOS directory items in their natural sequence ! * variables: * DOSDIR - example: c: or c:\temp * DOSITEM - example: testing.txt or '*' for ALL items (this program will prefix with '\') * MODE - 'IMPORTFT' or 'IMPORTFTD' from DOS or 'EXPORTFT' or 'EXPORTFTD' to DOS * MSG - literal error message if any occurs * PICKFILE - example: SYSTEM,SYSPROG,SYSPROG-BP (SYSTEM,ACCOUNT-NAME,FILE-NAME format - the literal file - this program will open it) * PICKITEM id - example: RECALCULATE-FILE-SIZES or '*' for ALL items (the item id - this program will read it) * * Note: the PICKFILE example above works on the mvBASE multi-value environment * D3 would be: ACCOUNT-NAME,FILE-NAME, * QM would be: ACCOUNT-NAME:FILE-NAME (if config rule is set as such) ! *** for QM $CATALOGUE GLOBAL *** ! MSG = '' GET.TRANSFER.STATUS = CHAR(27):CHAR(2):\S\ *** Not really doing anything with this - here for documentation purposes if you'd like to * ESC STX S * returns status of the last file transfer. Status message is: * Status: s files f bytes b * where f is the number of files transferred, b is the number of bytes transferred, and s is the tranfer status: * 0 = transfer successful * 1 = unable to open file * 2 = transfer aborted by operator * 3 = file already exists * 4 = terminated due to timeout * 5 = terminated due to corrupted data * 6 = invalid packet type * 7 = terminated by remote program * 8 = 8 data bits required for protocol * 9 = software flow control not allowed for protocol * 10 = destination file is write protected STATUSES = '' STATUSES<1> = \transfer successful\ STATUSES<2> = \unable to open file\ STATUSES<3> = \transfer aborted by operator\ STATUSES<4> = \file already exists\ STATUSES<5> = \terminated due to timeout\ STATUSES<6> = \terminated due to corrupted data\ STATUSES<7> = \invalid packet type\ STATUSES<8> = \terminated by remote program\ STATUSES<9> = \8 data bits required for protocol\ STATUSES<10> = \software flow control not allowed for protocol\ STATUSES<11> = \destination file is write protected\ ! OPEN PICKFILE TO THEFILE ELSE MSG = \Sorry - Can't open PICK file \:PICKFILE:\ . ABORT.\ GOTO 20000 END * LG.DOS.DIR = LEN(DOSDIR) BEGIN CASE CASE DOSDIR[LG.DOS.DIR,1] = \:\ ; DOSDIR = DOSDIR:"\" CASE DOSDIR[LG.DOS.DIR,1] = "\" ; DOSDIR = DOSDIR[1,(LG.DOS.DIR - 1)] END CASE * BEGIN CASE CASE MODE = \EXPORTFT\ GOSUB 18000 IF MSG = '' THEN GOSUB 19100 CASE MODE = \IMPORTFT\ GOSUB 18250 IF MSG = '' THEN GOSUB 19100 CASE MODE = \EXPORTFTD\ GOSUB 18500 IF MSG = '' THEN GOSUB 19100 CASE MODE = \IMPORTFTD\ GOSUB 18750 IF MSG = '' THEN GOSUB 19100 CASE 1 MSG = \Invalid MODE. Must be: EXPORTFT, EXPORTFTD, IMPORTFT, or IMPORTFTD.\ END CASE GOTO 20000 ! 18000 * EXPORT to DOS (one to one relationship) ! VERB = \SSELECT \:PICKFILE IF PICKITEM # \*\ THEN VERB = VERB:\ "\:PICKITEM:\"\ END * CRT VERB EXECUTE VERB CAPTURING RESULTS RETURNING ERRINFO IF ERRINFO < 1 THEN MSG = \Performing \:VERB:\ resulted in: \:RESULTS RETURN END * DONE = 0 LOOP READNEXT PICKID ELSE DONE = 1 UNTIL DONE = 1 DO READ THEREC FROM THEFILE,PICKID ELSE THEREC = '' IF THEREC # '' THEN DOSID = PICKID IF DOSITEM # '' THEN IF PICKITEM # \*\ THEN DOSID = DOSITEM ; * allows you to name the DOS item differently END END CRT \export MULTI-VALUE \:PICKFILE:\ \:PICKID CRT \ to DOS \:DOSDIR:"\":DOSID VERB = \FT\ DATA \S\ DATA \K\ DATA PICKFILE DATA PICKID DATA DOSDIR DATA DOSID EXECUTE VERB END REPEAT RETURN ! 18250 * IMPORT from DOS (one to one relationship) ****** Note: DOSITEM could be an '*' to get ALL items from the DOSDIR ! CRT \import DOS \:DOSDIR:"\":DOSITEM CRT \ to MULTI-VALUE \:PICKFILE:\ \:PICKITEM * VERB = \FT\ DATA \R\ DATA \K\ DATA DOSDIR DATA DOSITEM DATA PICKFILE DATA PICKITEM EXECUTE VERB RETURN ! 18500 * EXPORT all items from a MULTI-VALUE file to a single DOS file ! DOSPATH = DOSDIR:"\":DOSITEM CRT \export MULTI-VALUE \:PICKFILE:\ \:PICKITEM CRT \ to DOS \:DOSPATH VERB = \SSELECT \:PICKFILE DATA \FTD\ DATA \S\ DATA \K\ DATA PICKFILE DATA '' DATA DOSPATH DATA "*" DATA "N" EXECUTE VERB RETURN ! 18750 * IMPORT all items from a DOS directory to a single MULTI-VALUE item ! DOSPATH = DOSDIR:"\":DOSITEM CRT \import DOS \:DOSPATH CRT \ to MULTI-VALUE \:PICKFILE:\ \:PICKITEM DATA \FTD\ DATA \R\ DATA \K\ DATA DOSPATH DATA \N\ DATA \*\ DATA '' DATA \N\ DATA PICKFILE EXECUTE VERB RETURN ! 19100 * get last transfer status ! PRINT GET.TRANSFER.STATUS:;INPUT STATS RESULT.CODE = OCONV(STATS,"G1 1") LAST.TRANSFER.RESULT = STATUSES FILES.CODE = OCONV(STATS,"G3 1") BYTES.CODE = OCONV(STATS,"G5 1") IF RESULT.CODE # 0 THEN MSG = LAST.TRANSFER.RESULT END RETURN ! 20000 * end of program ! RETURN END