<% Option Explicit %>
<html>
<head>
<title>Importdatatotextfile</title>
</head>
<body>
<%
Dim conn, fs, objFile, objFileTextStream, i, strSQL
Dim strLine, strLinePart, strFirstName
Dim Posting,Document_Header_Text,Material,Material_Description
Dim Qty_in_Un_Of_Entry,Unit_of_Entry,Batch,Cost_Center,Movement_Type
Dim Storage_Location,Material_Document,Special_Stock,Vendor
Dim Amount_in_LC,GL_Account
Dim mySmartUpload
'*** Upload By aspSmartUpload ***'
'*** Create Object ***'
Set mySmartUpload = Server.CreateObject("Upload.SmartUpload")
'*** Upload Files ***'
mySmartUpload.Upload
'** Getfile Name ***'
sFileName = mySmartUpload.Files("file1").FileName
If sFileName <> "" Then
'*** Upload **'
mySmartUpload.Files("file1").SaveAs(Server.MapPath("txt/"&sFileName))
OpenFile = "txt/"&sFileName
'*** Create Object ***'
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*** Check Exist Files ***'
If Not objFSO.FileExists(Server.MapPath(sFileName)) Then
Else
'*** Open Files ***'
Set oInStream = objFSO.OpenTextFile(Server.MapPath(sFileName),1,False)
SET CONN = SERVER.CREATEOBJECT("ADODB.CONNECTION")
CONN.OPEN "Provider=SQLOLEDB.1;Data Source=192.1.10.58;Initial Catalog=SAP_MM;User ID=nok;Pwd=nok"
Set fs = Server.CreateObject("Scripting.FileSystemObject")
'Set objFile = fs.GetFile("C:\SAP_GI_1.txt")
'Set objFile = fs.GetFile(Server.MapPath(openFile))
Set objFileTextStream = objFile.OpenAsTextStream(1)
objFileTextStream.skipLine
Do While objFileTextStream.AtEndOfStream <> True
strLine = objFileTextStream.ReadLine
strLinePart = split(strLine," ")
for i = 0 TO UBound(strLinePart)
If i = 0 Then
Posting = Trim(strLinePart(i))
ElseIf i = 1 Then
Document_Header_Text = Trim(strLinePart(i))
ElseIf i = 2 Then
Material = Trim(strLinePart(i))
ElseIF i = 3 Then
Material_Description = Trim(strLinePart(i))
ElseIF i = 4 Then
Qty_in_Un_Of_Entry = Trim(strLinePart(i))
ElseIF i = 5 Then
Unit_of_Entry = Trim(strLinePart(i))
ElseIF i = 6 Then
Batch = Trim(strLinePart(i))
ElseIF i = 7 Then
Cost_Center = Trim(strLinePart(i))
ElseIF i = 8 Then
Movement_Type = Trim(strLinePart(i))
ElseIF i = 9 Then
Storage_Location = Trim(strLinePart(i))
ElseIF i = 10 Then
Material_Document = Trim(strLinePart(i))
ElseIF i = 11 Then
Special_Stock = Trim(strLinePart(i))
ElseIF i = 12 Then
Vendor = Trim(strLinePart(i))
ElseIF i = 13 Then
Amount_in_LC = Trim(strLinePart(i))
ElseIF i = 14 Then
GL_Account = Trim(strLinePart(i))
End If
Next
'intPosting_Date = Trim(intPosting_Date)
strSQL = "INSERT INTO SAP_GI ([Posting_Date],[Document_Header_Text],[Material],[Material_Description],[Qty_in_Un_Of_Entry],[Unit_of_Entry],[Batch],[Cost_Center],[Movement_Type],[Storage_Location],[Material_Document],[Special_Stock],[Vendor],[Amount_in_LC],[GL_Account]) "
strSQL = strSQL &" VALUES "
strSQL = strSQL &" ('"&Posting&"','"&Document_Header_Text&"','"&Material&"','"&Material_Description&"','"&Qty_in_Un_Of_Entry &"'"
strSQL = strSQL &" ,'"& Unit_of_Entry &"','" &Batch&"','"&Cost_Center&"','"&Movement_Type&"'"
strSQL = strSQL &" ,'"& Storage_Location &"','"&Material_Document&"','"&Special_Stock&"','"&Vendor&"'"
strSQL = strSQL &" ,'"& Amount_in_LC&"','"&GL_Account&"')"
'response.write(strSQL)
conn.Execute strSQL
Loop
objFileTextStream.Close: Set objFileTextStream = Nothing
Set fs = Nothing
conn.Close: Set conn = Nothing
%>