This document provides information on how to use an operation to create data for a child data class from a different data class (not necessarily its parent class).
The process described below demonstrates how to add data to the child class (MYCLASS1.CL1) of a data class (MYCLASS1) from a different data class (MYCLASS2). This is done by adding a script that will create an operation on (MYCLASS1), called from (MYCLASS2):
$Structure MYCLASS1
##########################################
# METHODS #
##########################################
$METHODS
Case CURPTH
When ""
Case ACTION
When "MYMETHOD" Gosub MYMETHOD # Update MYPROP1 method
Endcase
Endcase
Return
# Update MYPROP1 using MYPRAM1 which is passed
# KEY1 and MYPARAM1 are passed and used in this operation
$MYMETHOD
Local Integer NEWLINE
# Use standard method CRUD to read MYCLASS1
ASTATUS=fmet this.AREAD(MYCLASS1)
If ASTATUS<>[V]CST_AOK
ARET_VALUE= CST_AFALSE
Return
Else
ARET_VALUE= CST_ATRUE
# create a new line for MYCLASS1.CL1 at last position
NEWLINE=fmet this.ADDLINE("CL1",[V]CST_ALASTPOS)
If NEWLINE=[V]CST_ANOTDEFINED # check status after creating line
ARET_VALUE = CST_AFALSE
Endif
If ARET_VALUE = CST_ATRUE
# update CL1 with values passed
this.CL1(NEWLINE).MYPROP1 = MYPARAM1
ASTATUS=fmet this.AUPDATE
If ASTATUS<>[V]CST_AOK
ARET_VALUE= CST_AFALSE
Endif
Endif
Endif
Return##############################################
# Data Class - MYCLASS2 #
##############################################
##############################################
# METHODS #
##############################################
$METHODS
Case CURPRO
When ""
Case ACTION
When "AINSERT_AFTER" : Gosub AINSERT_AFTER
Endcase
Endcase
Return
# Action After insert
$AINSERT_AFTER
# Declaration new instance of MYCLASS2 data class
Local Instance MYCLASS Using C_MYCLASS2
MYCLASS = NewInstance C_MYCLASS2 AllocGroup Null
ASTATUS=fmet MYCLASS.MYMETHOD(KEYID,MYPARM1)
If ASTATUS<>[V]CST_ATRUE
ASTATUS = fmet THIS.ASETERROR ("", "Not updated.", [V]CST_AERROR)
Endif
# Free instances
FreeGroup MYCLASS
Return