【问题标题】:Reading file compare with table and need output读取文件与表比较需要输出
【发布时间】:2021-03-06 07:44:56
【问题描述】:

嗨,有人可以帮我做点什么吗?抱歉,我是新手。

我有一个文件“dntData”,每列有 9 个数字。 6 是数据库表中的数字,3 是组成的数字。

我要做的就是让程序读取输入,查找表中的数字并返回这些数字是否存在于表中。

出于某种原因,我的程序只返回它可以找到的数字,而对于它不能找到的数字则一无所获——这对我的目的没有用。我需要一个输出来告诉我“找不到号码”以及正在寻找的号码。

这是我写的代码:

def stream inputStream.
def stream outStream.

def var dntData           as char extent 1 no-undo.

def var vl-CIN# as integer.

def var vl-error as char.
def var vl-match as char.


input stream inputStream from "/home/xxx/xxx/xxx/xxx/FirstInput.csv".

output stream outStream to "/home/xxx/xxx/xxx/xxx/FirstOutput.csv".

export stream outStream delimiter "'" "CustomerID" "Match" "Error".
 
Repeat:   
   
    assign
    dntData = "".
        
    import stream inputStream delimiter "'" dntData.

    assign
    vl-CIN# = integer(dntnData[1]).

 
   

   find first members where cin# = vl-CIN#.
       
           if not available(members) then
             assign
               vl-error = "Could Not Find".
           if available(members) then
             assign
                vl-match = "Account Exists".
 

    

export stream outStream delimiter "'" vl-CIN# vl-match vl-error.

【问题讨论】:

    标签: openedge progress-4gl


    【解决方案1】:

    FIND 找不到记录时会抛出错误,因此您需要将NO-ERROR 添加到您的查找语句中。

    查看ABLdojo上的简单示例:

    define temp-table tt
       field id as int
       .
    
    create tt. tt.id = 1.
    // create tt. tt.id = 2.
    create tt. tt.id = 3.
    
    def var cc as char extent 1.
    def var id as int.
    
    input from "input.csv".
     
    repeat:
       
       cc = ''.
       import delimiter "'" cc.
    
       id = integer( cc[1] ).
    
       find first tt where tt.id = id no-error.       
       if not available tt then 
          message 'not found' id.
       else
          message 'found' tt.id.
    
    end.
    
    input close.
    

    输入文件是:

    1'one
    2'two
    3'three
    

    几点说明:

    • 如果您在 key 上查找记录,那么您应该使用 find 而不是 find first
    • 如果你对记录的内容不感兴趣,只需要知道它是否存在,使用can-find函数(返回真/假,不需要no-error

    【讨论】:

    • 谢谢斯特凡。完美的。无错误位是让我绊倒的原因。也感谢您在评论中也采取了额外的步骤。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2013-10-14
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多