2014-06-19 2 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. 
관련 문제