a.omz
a.omz

Reputation: 17

Update data field in progress 4gl

Can someone please help me?

All I want to do is update a field in a table, lets say for example membership number if it meets certain conditions.

For example: I have a list of membership numbers. IF the numbers on the list match the membership number in the table - we don't do anything.

If it doesn't match - then we change the membership number to another number that is stored in my input CSV. (i know this sounds back to front, but this is just an analogy)

So in essence I am asking - how do you update a field in a database table? This doesn't seem to be working:

def stream inputStream.
def stream outStream.

def var abcData           as char extent 4 no-undo.

def var vl-XYZ# as integer.
def var vl-link# as integer.
def var vl-orig-ABC# as char.
def var vl-new-ABC# as char.
/* def var vl-error as char. */
def var vl-match as char.
def var vl-status as char.

def buffer bMembers for  members.

input stream inputStream from "/home/abc.csv".

output stream outStream to "/home/xyz.csv".

export stream outStream delimiter "'" "ABCID" "Match".
 
repeat:   
   
    assign
    abcData = "".
        
    import stream inputStream delimiter "'" abcData.

    assign
    vl-link# = integer(abcdata[1])
    vl-XYZ# = integer(abcData[2])
    vl-orig-ABC# = string(abcData[3])
    vl-new-ABC# = string(abcData[4])   .           

 
   for each account no-lock  where account.link# = vl-link#,
    First members no-lock where  members.XYZ# = vl-XYZ#:

        if members.abc# = vl-orig-ABC# then
            assign
                vl-status = "Needs amending".
        
        if members.abc# <> vl-orig-ABC# then
            assign
                vl-status = "No action needed"
                members.abc# = vl-new-ABC#.
    

 
export stream outStream delimiter "'" vl-link# vl-XYZ# vl-orig-ABC# members.abc# vl-status

]

Upvotes: 1

Views: 1294

Answers (1)

Mike Fechner
Mike Fechner

Reputation: 7192

The problem with updating the members records will be in the FOR EACH. You need to use EXCLUSIVE-LOCK with the members table to be able to update records.

   for each account no-lock  where account.link# = vl-link#,
    First members EXCLUSIVE-LOCK where  members.XYZ# = vl-XYZ#:

The selection criteria for the members table does also not seem to be right, in a joined FOR EACH statement, the second table should depend on the first one like

   for each account no-lock  where account.link# = vl-link#,
    First members EXCLUSIVE-LOCK where members.<somefield of members> = account.<matchine ield in account> 
                                   AND members.XYZ# = vl-XYZ#:

Upvotes: 1

Related Questions