a.omz
a.omz

Reputation: 17

Reading file compare with table and need output

Hi can someone please help me with something. Sorry I am new to this.

I have a file "dntData", with 9 numbers in a column. 6 are numbers in a database table, 3 are made up numbers.

All i want to do is for the program to read the input, look for the numbers in the table and return whether those numbers exist in the table or not.

For some reason, my program only returns numbers that it can find and nothing for the ones it cant - which is not useful to my purpose. i need an output to tell me "number not found" along with the number that was looked for.

This is the code i wrote:

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.

Upvotes: 0

Views: 85

Answers (1)

Stefan Drissen
Stefan Drissen

Reputation: 3379

When FIND cannot find a record it will throw an error, so you will need to add NO-ERROR to your find statement.

See simple example on 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.

The input file is:

1'one
2'two
3'three

A few remarks:

  • if you are finding records on key, then you should use find instead of find first
  • if you are not interested in the contents of the record but just need to know if it exists, use the can-find function (which returns true / false and does not require no-error)

Upvotes: 2

Related Questions