读取文件与表比较,需要输出



嗨,有人能帮我个忙吗?对不起,我是新手。

我有一个文件"dntData",在一列中有9个数字。其中6个是数据库表中的数字,3个是编出来的数字。

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

由于某种原因,我的程序只返回它能找到的数字,而不返回它不能找到的数字——这对我的目的没有帮助。我需要一个输出告诉我&;number not found&;以及要查找的数字

这是我写的代码:
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.

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

注释:

  • 如果你在键上找到记录,那么你应该使用find而不是find first
  • 如果您对记录的内容不感兴趣,但只是需要知道它是否存在,请使用can-find函数(该函数返回true/false并且不需要no-error)

最新更新