2014-06-19 181 views
0
input from cust.txt. 
define temp-table tt-cust field name like customer.name 
         field custnum like customer.custnum. 
repeat: 
    create ttcust. 
    import delimiter "," tt-cust.name tt-cust.custnum. 
end. 
input close. 
for each customer where customer.country = "usa" exclusive-lock: 
    assign customer.name = tt-cust.name 
      customer.custnum = tt-cust.custnum. 
end. 

如果輸入文件中的數據錯誤,我想在日誌文件中寫入錯誤。例如,如果在custnum字段中有一個字符而不是數字。如何寫入日誌文件?

回答

0

使用流同時處理輸入和輸出。

DEFINE STREAM inStream. 
DEFINE STREAM outStream. 

DEFINE VARIABLE iTestInt AS INT64  NO-UNDO. 

INPUT STREAM inStream FROM cust.txt. 

/* Add error log */ 
OUTPUT STREAM outStream TO c:\temp\errlog.txt. 
DEFINE TEMP-TABLE tt-cust 
    FIELD name LIKE customer.name 
    FIELD custnum LIKE customer.custnum. 
REPEAT: 
    CREATE tt-cust. 
    IMPORT STREAM inStream DELIMITER "," tt-cust.name tt-cust.custnum. 

    /* Test if custnum is a number */ 
    iTestInt = INT64(TT-CUST.custnum) NO-ERROR. 
    IF iTestInt = ? THEN DO: 
     PUT STREAM outStream UNFORMATTED "Strange custnum: " + tt-cust.custnum SKIP. 
     NEXT. 
    END. 

END. 
INPUT STREAM inStream CLOSE. 
OUTPUT STREAM outStream CLOSE.