Changing Keys

whwar9739

Member
I am looking for some help on make changes to key fields within a record.

Essentially I have a key similar to the following:

int1 format "9"
int2 format "zzz9"
date format "99/99/9999"
cha1 format "x(4)"
int3 format "zzzz9"
cha2 format "x"

I am looking to change all records with int2 = 2 to int2 = 4 along with this i need to ensure that a sequence (int3) is increased if there is already a record with int2 = 4 and int3's equal.

Thanks for any help.
 

accent

New Member
If you're using a sequence to determine int3, your code should look something like this (not guaranteed to be error-free):
Code:
define buffer b-table for table.

for each table where table.int2 = 2 exclusive:
   find b-table where b-table.int2 = 4 and b-table.int3 = table.int3 no-lock no-error.

   assign table.int2 = 4.

   if avail b-table then
      assign table.int3 = next-value(<sequence-name>).
end.
Where "table" should, offcourse, be replaced with the name of the table you want to change.

If you're NOT using a sequence to assign int3, simply look for the last record, sorting by int3, store that value in a variable, and add 1 each time "b-table" is available.

Hope I understood it right...
 

whwar9739

Member
I think you have the understanding correct the issue I end up with doing something similar to your example is that it gives me an error on the key saying it already exists.

Here is the stripped down version of the code I currently have:

Code:
DEF VAR l-seq        LIKE table.int3                                       NO-UNDO.
DEF BUFFER xtable FOR table.
REPEAT PRESELECT EACH table EXCLUSIVE-LOCK WHERE table.int2 = 4:
   FIND NEXT table.
   FIND LAST xtable NO-LOCK
      WHERE xtable.int1    = 2
        AND xtable.date  = ddt.date
        AND xtable.int1  = ddt.int1
        AND xtable.cha2      = ddt.cha2
        AND xtable.cha1       = ddt.cha1     NO-ERROR.
   IF AVAIL xtable THEN l-seq = xddt.int3 + 1.
                 ELSE l-seq = 0.
   ASSIGN
      table.int3    = l-seq
      table.int2 = 4
   .
END.
 

whwar9739

Member
Sadly after posting my last reply I found the issue in my code. In my assign I had the wrong number for int2. Thanks for the help.
 
Top