Search code examples
openedgeprogress-4gl

<Table> already exists with Record ID 0. (132) - PROGRESS 4GL


I have written below query to create a record in table but its throwing error - " already exists with Record ID 0. (132)". I queried the table but record is not available. I am not sure why am getting this error.

Kindly help on the same.

define temp-table ttbudget no-undo like BudgetGroup.
define buffer b_BudgetGroup for BudgetGroup.

create ttbudget.
assign
ttbudget.BudgetGroupCode        = "kepa"
ttbudget.BudgetGroupDescription = "kepa"
ttbudget.BudgetGroupIsActive    = YES
.

create b_BudgetGroup.
buffer-copy ttbudget to b_BudgetGroup.

Flags Index Name                       Cnt Field Name
pu    Prim                               1 + BudgetGroup_ID
u     UniqueIdx                          2 + BudgetGroupCode
                                           + BudgetGroupCategory

Solution

  • Your actual code is probably doing this in a loop. And the error message probably actually says: "** ttbudget already exists with BudgetGroup_ID 0 (132)" or "** b_BudgetGroup already exists with BudgetGroup_ID 0 (132)" not "Record ID 0. (132)".

    When you create ttbudget you are not assigning a value to ttbudget.BudgetGroup_ID so it gets a value of zero.

    You then buffer-copy that TT to the real table.

    You have a unique index on that field so there cannot be more than one such record.

    When the 2nd iteration of the loop runs it tries to create another record and you see the error message.

    If the sample code is close to the real code (sans the missing loop) your transaction is scoped to the entire procedure and so the b_BudgetGroup record creation will be undone. Making it so that your query to find a record with BudgetGroup_ID = 0 fails.

    To fix this you need to assign a unique value to ttbudget.BudgetGroup_ID. Ideally you would do that with a SEQUENCE. Something like:

    assign
      ttbudget.BudgetGroup_ID         = next-value( sequenceName )
      ttbudget.BudgetGroupCode        = "kepa"
      ttbudget.BudgetGroupDescription = "kepa"
      ttbudget.BudgetGroupIsActive    = YES
    .
    

    (The sequence would need to be created in the database schema before you use it.)

    According to the index definitions that you shared, the combination of BudgetGroupCode and BudgetGroupCategory also needs to be unique (regardless of BudgetGroup_ID) and you are always assigning "kepa" and "" (blank) to those fields so you will need to do something about that as well.