Best Practices - Updating an Existing Object

The purpose of this document is to provide best practices to update an existing object.

The recommended method is the following:

  1. Create a NewInstance.
  2. Read the instance to be updated.

Example:

# In a given class, two properties (MYKEY, MYSTRING) have to be created in MYTABLE if they don't exist# Otherwise, update MYSTRING propertyLocal File MYTABLELocal Instance MY_TABLE Using C_MYTABLEMY_TABLE = NewInstance C_MYTABLE AllocGroup null[L]ASTATUS = fmet MY_TABLE.AREAD(this.MYKEY)If [L]ASTATUS = [V]CST_AOKMY_TABLE.MYSTRING = this.MYSTRING[L]ASTATUS = fmet MY_TABLE.AUPDATE()If [L]ASTATUS<>[V]CST_AOK[L]ASTATUS = fmet this.ASETERROR("MYSTRING","Error updating record"-this.MYKEY,[V]CST_AERROR)EndifElse# Initialize InstanceFreeGroup MY_TABLE : # Remove error on readMY_TABLE = NewInstance C_MYTABLE AllocGroup null : # create new instance[L]ASTATUS = fmet MY_TABLE.AINIT()If [L]ASTATUS=[V]CST_AOKMY_TABLE.MYKEY = this.MYKEYMY_TABLE.MYSTRING = this.MYKEY[L]ASTATUS = fmet MY_TABLE.AINSERT()If [L]ASTATUS<>[V]CST_AOK[L]ASTATUS = fmet this.ASETERROR("MYKEY","Error creating record"-this.MYKEY,[V]CST_AERROR)EndifElse# Error upon table initialization[L]ASTATUS = fmet this.ASETERROR("MYKEY","Error upon initialization of"-this.MYKEY,[V]CST_AERROR)EndifEndifFreeGroup MY_TABLE