Hello,
I am trying to import an ASCII file to an Alpha table.
I am trying to get the data into the following fields.
Invoice_Number Yes Character 7
Date Yes Date 8
Customer Yes Character 30
Plant Yes Character 20
Ship_Date Yes Date 8
Rep Yes Character 4
Price Yes Numeric 7 2
Customer_Requested_Date Yes Date 8
Customer_Order Yes Character 16
Here is the sample of the code the import genie created.
temporary_import_table = file.temp_path_get()+ "tblsalesorders_temp_table.dbf"
import_destination_table = "m:\alpha database\tblsalesorders.dbf"
import_filename = filename_decode("m:\exports\sales order.csv")
if file.exists(import_filename) = .f. then
ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
end
end if
import.type = 0
import.names = "none"
import.file = import_filename
import.db = temporary_import_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = ","
import.record_sep = ""
import.text_qualifier = "\""
import.record_len = 125
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 9
import.field1 = "invoice_number,c,0,7,0"
import.field2 = "date,d,1,8,0"
import.field3 = "customer,c,2,30,0"
import.field4 = "plant,c,3,20,0"
import.field5 = "ship_date,d,4,8,0"
import.field6 = "rep,c,5,4,0"
import.field7 = "price,n,6,7,2"
import.field8 = "customer_requested_date,d,7,8,0"
import.field9 = "customer_order,c,8,16,0"
import()
'Prompt for confirmation before appending the records that were imported into the temporary table.......
dim rec_count as n
rec_count = a5_get_records_in_query(temporary_import_table, ".t.")
message_text = "" + rec_count + " record(s) will be imported into '"+import_destination_table+"'."+crlf(2)+ "OK to proceed?"
operation_result=ui_msg_box("Import Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
If operation_result ui_ok_selected then
end
end if
a_tbl = table.open(import_destination_table)
append.t_db = temporary_import_table
append.m_key = ""
append.t_key = ""
append.m_filter = ""
append.t_filter = ""
append.type = "All"
append.m_count = 9
append.m_field1 = "INVOICE_NUMBER"
append.m_exp1 = "@tblsalesorders_temp_table->INVOICE_NUMBER"
append.m_field2 = "CUSTOMER"
append.m_exp2 = "@tblsalesorders_temp_table->CUSTOMER"
append.m_field3 = "DATE"
append.m_exp3 = "@tblsalesorders_temp_table->DATE"
append.m_field4 = "PLANT"
append.m_exp4 = "@tblsalesorders_temp_table->PLANT"
append.m_field5 = "CUSTOMER_ORDER"
append.m_exp5 = "@tblsalesorders_temp_table->CUSTOMER_ORDER"
append.m_field6 = "PRICE"
append.m_exp6 = "@tblsalesorders_temp_table->PRICE"
append.m_field7 = "REP"
append.m_exp7 = "@tblsalesorders_temp_table->REP"
append.m_field8 = "SHIP_DATE"
append.m_exp8 = "@tblsalesorders_temp_table->SHIP_DATE"
append.m_field9 = "CUSTOMER_REQUESTED_DATE"
append.m_exp9 = "@tblsalesorders_temp_table->CUSTOMER_REQUESTED_DATE"
append.t_count = 0
a_tbl.append()
a_tbl.close()
a5_imp_append_op_result(a_records_processed,a_records_total,a_records_violated,import_destination_table)
'In case the destination table is not already in the Database, add it...
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
When I run the operation, I get a mismatch error, and the records will not import.
I am including a copy of the import file and the database also.
I am trying to import an ASCII file to an Alpha table.
I am trying to get the data into the following fields.
Invoice_Number Yes Character 7
Date Yes Date 8
Customer Yes Character 30
Plant Yes Character 20
Ship_Date Yes Date 8
Rep Yes Character 4
Price Yes Numeric 7 2
Customer_Requested_Date Yes Date 8
Customer_Order Yes Character 16
Here is the sample of the code the import genie created.
temporary_import_table = file.temp_path_get()+ "tblsalesorders_temp_table.dbf"
import_destination_table = "m:\alpha database\tblsalesorders.dbf"
import_filename = filename_decode("m:\exports\sales order.csv")
if file.exists(import_filename) = .f. then
ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
end
end if
import.type = 0
import.names = "none"
import.file = import_filename
import.db = temporary_import_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = ","
import.record_sep = ""
import.text_qualifier = "\""
import.record_len = 125
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 9
import.field1 = "invoice_number,c,0,7,0"
import.field2 = "date,d,1,8,0"
import.field3 = "customer,c,2,30,0"
import.field4 = "plant,c,3,20,0"
import.field5 = "ship_date,d,4,8,0"
import.field6 = "rep,c,5,4,0"
import.field7 = "price,n,6,7,2"
import.field8 = "customer_requested_date,d,7,8,0"
import.field9 = "customer_order,c,8,16,0"
import()
'Prompt for confirmation before appending the records that were imported into the temporary table.......
dim rec_count as n
rec_count = a5_get_records_in_query(temporary_import_table, ".t.")
message_text = "" + rec_count + " record(s) will be imported into '"+import_destination_table+"'."+crlf(2)+ "OK to proceed?"
operation_result=ui_msg_box("Import Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
If operation_result ui_ok_selected then
end
end if
a_tbl = table.open(import_destination_table)
append.t_db = temporary_import_table
append.m_key = ""
append.t_key = ""
append.m_filter = ""
append.t_filter = ""
append.type = "All"
append.m_count = 9
append.m_field1 = "INVOICE_NUMBER"
append.m_exp1 = "@tblsalesorders_temp_table->INVOICE_NUMBER"
append.m_field2 = "CUSTOMER"
append.m_exp2 = "@tblsalesorders_temp_table->CUSTOMER"
append.m_field3 = "DATE"
append.m_exp3 = "@tblsalesorders_temp_table->DATE"
append.m_field4 = "PLANT"
append.m_exp4 = "@tblsalesorders_temp_table->PLANT"
append.m_field5 = "CUSTOMER_ORDER"
append.m_exp5 = "@tblsalesorders_temp_table->CUSTOMER_ORDER"
append.m_field6 = "PRICE"
append.m_exp6 = "@tblsalesorders_temp_table->PRICE"
append.m_field7 = "REP"
append.m_exp7 = "@tblsalesorders_temp_table->REP"
append.m_field8 = "SHIP_DATE"
append.m_exp8 = "@tblsalesorders_temp_table->SHIP_DATE"
append.m_field9 = "CUSTOMER_REQUESTED_DATE"
append.m_exp9 = "@tblsalesorders_temp_table->CUSTOMER_REQUESTED_DATE"
append.t_count = 0
a_tbl.append()
a_tbl.close()
a5_imp_append_op_result(a_records_processed,a_records_total,a_records_violated,import_destination_table)
'In case the destination table is not already in the Database, add it...
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
When I run the operation, I get a mismatch error, and the records will not import.
I am including a copy of the import file and the database also.
Comment