2014-06-19 141 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.