You are on page 1of 3

Function Filename_check_ACC() &POS = Find("PSVOUCHER", &Filename_error); &POS1 = Find(".", &Filename_error); &ErrorFILE_NAME = Substring(&Filename_error, &POS, (&POS1 - 1)); TC_V_AET.

SQL_STATEMENT = &ErrorFILE_NAME | ","; &STR_FILENAME = &ErrorFILE_NAME; End-Function; Function Move_files() If TC_V_AET.ERROR_COUNT > 0 Then try &COMMAND_STRING = GetEnv("COMSPEC") | " /c " | " MOVE /Y " | &In_P ath | &STR_FILENAME | " " | &Error_Path | &STR_FILENAME | "_" | %Datetime; &execErr = Exec(&COMMAND_STRING, %Exec_Asynchronous + %FilePath_Absolute); catch Exception &ex1 Exit (1); end-try; End-If; If TC_V_AET.ERROR_COUNT = 0 Then try &COMMAND_STRING_PROCESSED = GetEnv("COMSPEC") | " /c " | " MO VE /Y " | &In_Path | &STR_FILENAME | " " | &Success_Path | &STR_FILENAME | "_" | %Datetime; &Processed_ex = Exec(&COMMAND_STRING_PROCESSED, %Exec_Asynchronous + %F ilePath_Absolute); catch Exception &ex2 Exit (1); end-try; End-If; End-Function; Function EditRecord(&REC As Record) Returns boolean; Local integer &E; &REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_Tran slateTable + %Edit_PromptTable + %Edit_OneZero); REM &REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_ OneZero); If &REC.IsEditError Then For &E = 1 To &REC.FieldCount &MYFIELD = &REC.GetField(&E); If &MYFIELD.EditError Then &MSGNUM = &MYFIELD.MessageNumber; &MSGSET = &MYFIELD.MessageSetNumber; &LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD .Name); &LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, "")); End-If; End-For; Return False; Else Return True; End-If; End-Function; Function ImportSegment(&RS2 As Rowset, &bExecute As boolean) Returns boolean; Local Rowset &RS1, &RSP; Local string &RecordName;

Local Record &REC2; Local SQL &SQL1; Local integer &I, &L; &SQL1 = CreateSQL("%Insert(:1)"); &RecordName = "RECORD." | &RS2.DBRecordName; &REC2 = CreateRecord(@(&RecordName)); For &I = 1 To &RS2.ActiveRowCount &RS2(&I).GetRecord(1).CopyFieldsTo(&REC2); If (EditRecord(&REC2)) Then If (&bExecute = True) Then &REC2.PROCESS_INSTANCE.Value = &Total_Count; /*Process instance is u sed to store the no.of files sucessfully loaded */ &SQL1.Execute(&REC2); End-If; For &L = 1 To &RS2.GetRow(&I).ChildCount &RS1 = &RS2.GetRow(&I).GetRowset(&L); If (&RS1 <> Null) Then If (ImportSegment(&RS1, &bExecute) = False) Then Return False; End-If; End-If; End-For; Else Return False; End-If; End-For; Return True; End-Function; /*** Read and Load the data from XML into Temporary Tables. ***/ Local Local Local Local Local Local Local File &FILE1; Record &REC1; SQL &SQL1; Rowset &RS1, &RS2; integer &M; array of string &FNAMES; string &FPath;

&In_Path = GetURL(URL.AP_TC); &LogFilePath = GetURL(URL.AP_TC_LOG); &ErrFilePath = GetURL(URL.AP_TC_ERR); &PrcsdFilePath = GetURL(URL.AP_TC_PRCS); &filename = GetURL(URL.AP_TC_FLNAME); &Log_Path = GetURL(URL.AP_TC_LOG); TC_V_AET.SQL_STATEMENT = &LogFilePath; &Error_file = &LogFilePath | "\TradeCard" | %Datetime | ".log"; &FNAMES_PSS = FindFiles(&In_Path | "PSVOUCHER*.XML", %FilePath_Absolute); /*Open the erred data file */ &ErrFileName = "TradeCard_" | %Datetime | ".csv"; &ErrFilePath1 = &ErrFilePath | &ErrFileName; &Errfile = GetFile(&ErrFilePath1, "W", %FilePath_Absolute); If &Errfile.IsOpen Then &Errfile.WriteLine(%Datetime | ": " | "Begin: error TradeCard report"); Else Exit; End-If; &LOGFILE = GetFile(&Error_file, "W", %FilePath_Absolute);

&filecount = 0; &Success_file_count = 0; &Error_file_count = 0; /*** For Processing XML files***/ While &FNAMES_PSS.Len > 0 &FILE1 = GetFile(&FNAMES_PSS.Shift(), "R", "a", %FilePath_Absolute); &FILE1.SetFileLayout(FileLayout.TC_VCH); &LOGFILE.SetFileLayout(FileLayout.TC_VCH); &Filename_error = Upper(&FILE1.Name); &RS1 = &FILE1.CreateRowset(); &RS = CreateRowset(Record.V_HDR_XML_S, CreateRowset(Record.V_LIN_XML_S, Creat eRowset(Record.V_DIS_XML_S))); &SQL1 = CreateSQL("%Insert(:1)"); &RS1 = &FILE1.ReadRowset(); While &RS1 <> Null; &filecount = &filecount + 1; &Total_Count = &Total_Count + 1; &rc = ImportSegment(&RS1, False); If (&rc = True) Then &rc = ImportSegment(&RS1, True); &Success_file_count = &Success_file_count + 1; Filename_check_ACC(); Else &Error_file_count = &Error_file_count + 1; Filename_check_ACC(); End-If; &RS1 = &FILE1.ReadRowset(); End-While; &FILE1.Close(); If TC_V_AET.ERROR_COUNT > 0 Then Move_files(); &Error_Comment = "****Correct the error in the following path" | &Error_Pa th | &ErrorFILE_NAME | ", place the corrected file in the root folder(" | &In_Pa th | ") for reprocessing. Make sure the Root folder should have file name with . XML Extension*****"; &LOGFILE.WriteLine(&Error_Comment); &LOGFILE.WriteRowset(&RS1); End-If; If TC_V_AET.ERROR_COUNT = 0 Then Move_files(); &Error_Comment = "****Following file successfully loaded in Staging table " | &In_Path | &ErrorFILE_NAME | "***********"; &LOGFILE.WriteLine(&Error_Comment); End-If; End-While; TC_V_AET.ERROR_COUNT = &Error_file_count; TC_V_AET.SUCCESS_COUNT = &Success_file_count; &LOGFILE.Close();

You might also like