I have an APP that loads in data files. I use to only get one file per day. Now I get more than one on some days. Instead of repeating the code, I want to create a loop that will ask the user if he has another file to load. The bad part about this is that I have 7 bank files. All of them are different structures so I a have 7 different parts to my code to get them and parse them and then put them into a holding file. If I have a loop of some sort, that would take care of the more than one file situation but it will cause a problem when time to load the holding file unless I right after I parse the data file. Here is the code I am using. I am sure there is a better way to do this. Please feel free to jump in and change it all! :-)
CLOSE DATABASES ALL
SET CENTURY ON
m.dSettDate = {//}
*!* gc_mainpath = "\\Svrpc-stlmnt01\e\Return-Items\"
*!* gc_systempath = "\\Svrpc-stlmnt01\e\Return-Items\sysdata\"
*!* gc_datapath = "\\Svrpc-stlmnt01\e\Return-Items\data\"
*!* gc_dailyreportspath = "\\Svrpc-stlmnt01\e\Return-Items\Daily-Reports\"
*!* gc_prtscrnpath = "H:\settlement\prt_scrn\"
*!* gc_amsouthpath = "H:\settlement\prt_scrn\amsouth-returns"
*!* gc_elanpath = "H:\settlement\prt_scrn\elan-returns"
*!* gc_fnbopath = "H:\settlement\prt_scrn\fnbo-returns"
*!* gc_funbpath = "H:\settlement\prt_scrn\funb-returns"
*!* gc_imperialpath = "H:\settlement\prt_scrn\imperial-returns"
*!* gc_keypath = "H:\settlement\prt_scrn\key-returns"
*!* gc_regionspath = "H:\settlement\prt_scrn\regions-returns"
*SET DEFA TO \\Svrpc-stlmnt01\e\RETURN-Items\DATA
IF WEXIST("makechoice")
HIDE WINDOW "makechoice"
ENDIF
******************************************************************************************************
***********************************************************************************************
***** FUNB
oIE = CREATEOBJECT("InternetExplorer.Application")
oIE.VISIBLE = .T.
oIE.Navigate("
ftp://funb:funb@198.203.192.131/outbox")
CHDIR (gc_prtscrnpath)
txt_file=GETFILE("?????????????","FUNB File")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "funb.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "funbtemp.prj")
ObjMonarch.ExportTable(gc_datapath + "funbtemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
CHDIR (gc_datapath)
USE funbtemp IN 0
SELECT funbtemp
m.dSettDate = funbtemp.settdate
USE IN funbtemp
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_funbpath)
COPY FILE (gc_datapath + "funb.txt") TO ("funb-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("funb.txt")
DELETE FILE funb.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No FUNB Bank File Found, Please Download File. ")
*RETURN
ENDIF
*************************************************************************************************
***** AMSouth Bank file 1
CHDIR (gc_prtscrnpath)
*CHDIR (gc_amsouthpath)
txt_file=GETFILE("MBX","AmSouth 1")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "asouth.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "asouthtemp.prj")
ObjMonarch.ExportTable(gc_datapath + "asouthtmp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* CHDIR (gc_datapath)
*!* USE asouthtmp IN 0
*!* SELECT asouthtmp
*!* m.dSettDate = asouthtmp.settdate
*!* USE IN asouthtmp
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_amsouthpath)
COPY FILE (gc_datapath + "asouth.txt") TO ("amsouth-returns-" + STRTRAN(DTOC(m.dSettDate),"/") + "-" + SUBSTR(JUSTFNAME((txt_file)),1,8) + ".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("asouth.txt")
DELETE FILE asouth.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No AmSouth Bank File Found, Please Download File. ")
*RETURN
ENDIF
*************************************************************************************************
***** AMSouth Bank file 2
CHDIR (gc_prtscrnpath)
*CHDIR (gc_amsouthpath)
txt_file=GETFILE("MBX","AmSouth 2")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "asouth.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "asouthtemp.prj")
ObjMonarch.ExportTable(gc_datapath + "asouthtm2.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* CHDIR (gc_datapath)
*!* USE asouthtmp IN 0
*!* SELECT asouthtmp
*!* m.dSettDate = asouthtmp.settdate
*!* USE IN asouthtmp
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_amsouthpath)
COPY FILE (gc_datapath + "asouth.txt") TO ("amsouth-returns-" + STRTRAN(DTOC(m.dSettDate),"/") + "-" + SUBSTR(JUSTFNAME((txt_file)),1,8) + ".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("asouth.txt")
DELETE FILE asouth.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No AmSouth Bank File Found, Please Download File. ")
*RETURN
ENDIF
*********************************************************************************************
*********************************************************************************************
**** ELAN
CHDIR (gc_elanpath)
txt_file=GETFILE("","ELAN File")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "elan.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "elantemp.prj")
ObjMonarch.ExportTable(gc_datapath + "elantemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_elanpath)
COPY FILE (gc_datapath + "elan.txt") TO ("elan-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_elanpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("elan.txt")
DELETE FILE elan.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No Elan Bank File Found, Please Download File. ")
*RETURN
ENDIF
***********************************************************************************************
******* FNBO
CHDIR (gc_prtscrnpath)
txt_file=GETFILE("TXT","FNBO File")
*!* ?txt_file
IF NOT EMPTY(txt_file)
SET DEFA TO (gc_datapath)
USE tempdata IN 0 EXCLU
SELECT tempdata
ZAP
APPEND FROM (txt_file) TYPE SDF
SCAN
SCATTER MEMVAR
REPLACE FILE WITH ALLTRIM(SUBSTR(m.file,2))
ENDSCAN
COPY TO fnbo.txt TYPE SDF
USE IN tempdata
*!* This section creates the fnbotemp.dbf
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "fnbotemp.prj")
ObjMonarch.ExportTable(gc_datapath + "fnbotemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_fnbopath)
COPY FILE (gc_datapath + "fnbo.txt") TO ("fnbo-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("fnbo.txt")
DELETE FILE fnbo.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" FNBO Files Not Found, Please Download File. ")
*RETURN
ENDIF
*!* ***********************************************************************************************
******************************************************************************************************
**** IMPERIAL
CHDIR (gc_prtscrnpath)
txt_file=GETFILE("DAT","Imperial File")
IF NOT EMPTY(txt_file)
CHDIR (gc_datapath)
COPY FILE (txt_file) TO (gc_datapath + "imperial.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "ibtemp2.prj")
ObjMonarch.ExportTable(gc_datapath + "ibtemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_imperialpath)
COPY FILE (gc_datapath + "imperial.txt") TO ("imperial-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("imperial.txt")
DELETE FILE imperial.txt
ENDIF
ELSE
SET DEFA TO \\Svrpc-stlmnt01\e\RETURN-Items\
MESSAGEBOX(" No Imperial Bank File Found, Please Download File. ")
*RETURN
ENDIF
***********************************************************************************************
***** KEY
CHDIR (gc_prtscrnpath)
txt_file=GETFILE("MBX","Key File")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "key.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "keytemp.prj")
ObjMonarch.ExportTable(gc_datapath + "keytemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_keypath)
COPY FILE (gc_datapath + "key.txt") TO ("key-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("key.txt")
DELETE FILE KEY.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No KEY Bank File Found, Please Download File. ")
*RETURN
ENDIF
***********************************************************************************************
**** REGIONS
CHDIR (gc_prtscrnpath)
txt_file=GETFILE("???","Regions File")
IF NOT EMPTY(txt_file)
CHDIR (gc_datapath)
COPY FILE (txt_file) TO "regions.txt"
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "regionstemp.prj")
ObjMonarch.ExportTable(gc_datapath + "regtemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
CHDIR (gc_datapath)
USE regtemp IN 0
SELECT regtemp
REPLACE ALL settdate WITH m.dSettDate
USE IN regtemp
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_regionspath)
COPY FILE (gc_datapath + "regions.txt") TO ("regions-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("regions.txt")
DELETE FILE regions.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No Regions Bank File Found, Please Download File. ")
*RETURN
ENDIF
***********************************************************************************************
******************************************************************************************************
***********************************************************************************************
***** BOW
CHDIR (gc_bowpath)
txt_file=GETFILE("TXT","BOW File")
IF NOT EMPTY(txt_file)
COPY FILE (txt_file) TO (gc_datapath + "bow.txt")
ObjMonarch= CREATEOBJECT("Monarch32")
ObjMonarch.VISIBLE=.F.
OpenProj = ObjMonarch.SetProjectFile(gc_datapath + "bowtemp.prj")
ObjMonarch.ExportTable(gc_datapath + "bowtemp.dbf")
ObjMonarch.CloseAllDocuments
ObjMonarch.EXIT
CHDIR (gc_datapath)
USE bowtemp IN 0
SELECT bowtemp
REPLACE ALL settdate WITH m.dSettDate
USE IN bowtemp
*!* ****************************************************************************************
*!* Copy the file to a name we can recognize since they come in with funny names
CHDIR (gc_bowpath)
COPY FILE (gc_datapath + "bow.txt") TO ("bow-returns-" + STRTRAN(DTOC(m.dSettDate),"/")+".txt")
CHDIR (gc_prtscrnpath)
DELETE FILE (txt_file)
CHDIR (gc_datapath)
IF FILE("bow.txt")
DELETE FILE bow.txt
ENDIF
ELSE
CHDIR (gc_mainpath)
MESSAGEBOX(" No BOW Bank File Found, Please Download File. ")
*RETURN
ENDIF
**********************************************************************************************
IF WEXIST("makechoice")
HIDE WINDOW "makechoice"
ENDIF
***********************************************************************************************
CHDIR (gc_datapath)
CLOSE DATA ALL
USE risdata_temp2 IN 0 EXCLUSIVE
SELECT risdata_temp2
ZAP
IF FILE('asouthtmp.dbf')
APPEND FROM asouthtmp
ENDIF
IF FILE('asouthtm2.dbf')
APPEND FROM asouthtm2
ENDIF
IF FILE('elantemp.dbf')
APPEND FROM elantemp
ENDIF
IF FILE('fnbotemp.dbf')
APPEND FROM fnbotemp
ENDIF
IF FILE('funbtemp.dbf')
APPEND FROM funbtemp
ENDIF
IF FILE('ibtemp.dbf')
APPEND FROM ibtemp
ENDIF
IF FILE('keytemp.dbf')
APPEND FROM keytemp
ENDIF
IF FILE('regtemp.dbf')
APPEND FROM regtemp
ENDIF
IF FILE('bowemp.dbf')
APPEND FROM bowtemp
ENDIF
USE IN risdata_temp2
*!* USE risdata_temp2 IN 0 EXCLUSIVE
*!* SELECT risdata_temp2
*!* REPLACE ALL risdata_temp2.settdate WITH m.dSettDate
*!* USE IN risdata_temp2
SELECT risdata_temp2.*, Banks.portfolio, Banks.DESCRIP, Banks.bank ;
FROM risdata_temp2 LEFT OUTER JOIN returnitems!Banks ;
ON (ALLTRIM(risdata_temp2.bankname) == ALLTRIM(Banks.bank)) ;
ORDER BY risdata_temp2.bankname ;
INTO TABLE risdata_temp3
USE IN risdata_temp2
USE IN Banks
USE IN risdata_temp3
USE ris_format EXCLUSIVE
ZAP
APPEND FROM risdata_temp3
USE IN ris_format
USE ris_format IN 0 SHARED
SELECT ris_format
CHDIR \\Svrpc-stlmnt01\e\ris-DATA\
COPY TO "risdata1_" + STRTRAN(DTOC(m.dSettDate),"/") + ".txt" DELIMITED WITH TAB
*!* GO TOP
*!* CHDIR \\Svrpc-stlmnt01\e\RETURN-Items\daily-reports\
*!* COPY TO "risdata1_" + STRTRAN(DTOC(m.dSettDate),"/") + ".txt" DELIMITED WITH TAB
USE IN ris_format
CHDIR (gc_datapath)
IF FILE('asouthtmp.dbf')
DELETE FILE asouthtmp.DBF
ENDIF
IF FILE('asouthtm2.dbf')
DELETE FILE asouthtm2.DBF
ENDIF
IF FILE('elantemp.dbf')
DELETE FILE elantemp.DBF
ENDIF
IF FILE('fnbotemp.dbf')
DELETE FILE fnbotemp.DBF
ENDIF
IF FILE('funbtemp.dbf')
DELETE FILE funbtemp.DBF
ENDIF
IF FILE('ibtemp.dbf')
DELETE FILE ibtemp.DBF
ENDIF
IF FILE('keytemp.dbf')
DELETE FILE keytemp.DBF
ENDIF
IF FILE('regtemp.dbf')
DELETE FILE regtemp.DBF
ENDIF
SET DEFAULT TO (gc_mainpath)
IF WEXIST("makechoice")
SHOW WINDOW "makechoice"
ELSE
DO FORM makechoice
ENDIF
CLOSE DATA ALL
SET DEFAULT TO (gc_mainpath)
Thanks in advance for your help! :-)
Randall L. Johnson