#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include
#include
#include
#include
#define MAX_LENGTH 500
char Output[MAX_LENGTH];
char *Mid(char *str, int start, int length);
void main(void)
{
FILE *infile;
char inword[MAX_LENGTH];
char command[MAX_LENGTH];
//Oracle Field Names
char tBUYER_NUMBER[4];
char tEDI[3];
char tINV_BY[2];
char tMESSAGE[61];
char tPURCHASE_ORDER_NUMBER[7];
char tPO_TYPE[2];
char tSTS_CANCEL_STATUS[2];
char tSPEC[2];
char tPO_STATUS_CODE[4];
char tSTORE_NUMBER[4];
char tDISCOUNTS[9];
char tTERMS[9];
char tTICKET_FLAG[2];
char tVENDOR_NUMBER[6];
char tSHIP_TO_NUMBER[4];
char tEXP_STORE[5];
char tMMS_PO[2];
char tMMS_RECEIPT[2];
char tORDER_OTB_FLAG[5];
char tPO_STATUS[2];
// Flat file to be read in
if ((infile = fopen("c:\\Pomd15a.txt", "rt")) == NULL)
{
printf("Cannot open input file - %s\n", "c:\\Pomd15a.txt");
exit(1);
}
CoInitialize(NULL);
try
{
// Connection
_ConnectionPtr pCn("ADODB.Connection");
// Connection String
_bstr_t strCnn("Provider=MSDAORA.1;Password=
// Open Connection
pCn->Open(strCnn, "", "", adConnectUnspecified);
// delete all data from table
pCn->Execute("delete from
printf("Importing Data...Please Wait.\n");
fseek(infile, 0L, SEEK_SET);
while(fgets(inword, MAX_LENGTH, infile)!=NULL)
{
strcpy(tBUYER_NUMBER,Mid(inword,27,2));
strcpy(tEDI,Mid(inword,122,2));
strcpy(tINV_BY,Mid(inword,166,1));
strcpy(tMESSAGE,Mid(inword,168,60));
strcpy(tPURCHASE_ORDER_NUMBER,Mid(inword,305,6));
strcpy(tPO_TYPE,Mid(inword,312,1));
strcpy(tSTS_CANCEL_STATUS,Mid(inword,331,1));
strcpy(tSPEC,Mid(inword,362,1));
strcpy(tPO_STATUS_CODE,Mid(inword,365,3));
strcpy(tSTORE_NUMBER,Mid(inword,370,3));
strcpy(tDISCOUNTS,Mid(inword,374,8));
strcpy(tTERMS,Mid(inword,383,8));
strcpy(tTICKET_FLAG,Mid(inword,392,1));
strcpy(tVENDOR_NUMBER,Mid(inword,428,5));
strcpy(tSHIP_TO_NUMBER,Mid(inword,435,3));
strcpy(tEXP_STORE,Mid(inword,439,4));
strcpy(tMMS_PO,Mid(inword,444,1));
strcpy(tMMS_RECEIPT,Mid(inword,446,1));
strcpy(tORDER_OTB_FLAG,Mid(inword,448,4));
strcpy(tPO_STATUS,"U");
command[0]='\0';
sprintf(command,"INSERT INTO
pCn->Execute(command, NULL, adCmdText);
}
// Close the Infile
fclose(infile);
pCn->Close();
}
// Report Error
catch (_com_error &e)
{
cout<<(char*) e.Description();
}
::CoUninitialize();
}
char *Mid(char *str, int start, int length)
{
strncpy(Output, str + (start-1), length);
Output[length]='\0';
return (Output);
}