Form S_202RMO

LANSA

Form S_202RMO
* ===================================================================;
*;
* Component : S_202RMO;
* Type : Reusable Part;
* Ancestor : PRIM_OBJT (Primitive Form);
*;
* Description : Product "Model";
*;
* This reusable component represents the "model" of a "Product" for;
* this simple MVC example.;
*;
* Disclaimer : The following material is supplied as example material;
* only. No warranty concerning this material or its use;
* in any way whatsoever is expressed or implied.;
*;
* ===================================================================;
Function Options(*DIRECT);
Begin_Com Defaultpty(Name);
;
Define Field(#SpaceName) Reffld(#Std_obj) Default(*Component);
Define Field(#BRetCode) Type(*char) Length(2);
Def_Cond Name(*RetOkay) Cond('#BRetCode = ok');
Def_Cond Name(*RetNOkay) Cond('#BRetCode *ne ok');
;
* ===================================================================;
* Define the events that this model signals to all observers;
* ===================================================================;
;
Define_Evt Name(ProductFound);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*input) Class(#s_202des) Name(#Description);
Define_Map For(*input) Class(#s_202prc) Name(#Price);
Define_Map For(*input) Class(#s_202qty) Name(#Available);
Define_Map For(*input) Class(#std_Obj) Name(#RequestedBy);
;
Define_Evt Name(ProductCreated);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*input) Class(#s_202des) Name(#Description);
Define_Map For(*input) Class(#s_202prc) Name(#Price);
Define_Map For(*input) Class(#s_202qty) Name(#Available);
;
Define_Evt Name(ProductUpdated);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*input) Class(#s_202des) Name(#Description);
Define_Map For(*input) Class(#s_202prc) Name(#Price);
Define_Map For(*input) Class(#s_202qty) Name(#Available);
;
Define_Evt Name(ProductDestroyed);
Define_Map For(*input) Class(#s_202num) Name(#Number);
;
* ===================================================================;
* Create the details of a new product;
* ===================================================================;
;
Mthroutine Name(Create);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*input) Class(#s_202des) Name(#Description);
Define_Map For(*input) Class(#s_202prc) Name(#Price);
Define_Map For(*input) Class(#s_202qty) Name(#Available);
Define_Map For(*output) Class(#s_retcda2) Name(#ReturnCode) Mandatory(' ');
;
Change Field(#S_202NUM) To(#Number.Value);
Change Field(#S_202DES) To(#Description.Value);
Change Field(#S_202PRC) To(#Price.Value);
Change Field(#S_202QTY) To(#Available.Value);
;
Use Builtin(Fetch_In_Space) With_Args(#SpaceName #S_202NUM) To_Get(#BRetCode);
;
If Cond(*RetOkay);
Set Com(#ReturnCode) Value(ER);
Else;
Set Com(#ReturnCode) Value(OK);
Use Builtin(Insert_in_Space) With_Args(#SpaceName #S_202NUM #S_202DES #S_202PRC #S_202QTY);
Signal Event(ProductCreated) Number(#S_202NUM) Description(#S_202DES) Price(#S_202PRC) Available(#S_202QTY);
Endif;
;
Endroutine;
;
* ===================================================================;
* Update the details of an existing product;
* ===================================================================;
;
Mthroutine Name(Update);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*input) Class(#s_202des) Name(#Description);
Define_Map For(*input) Class(#s_202prc) Name(#Price);
Define_Map For(*input) Class(#s_202qty) Name(#Available);
Define_Map For(*output) Class(#s_retcda2) Name(#ReturnCode) Mandatory(' ');
;
Change Field(#S_202NUM) To(#Number.Value);
Change Field(#S_202DES) To(#Description.Value);
Change Field(#S_202PRC) To(#Price.Value);
Change Field(#S_202QTY) To(#Available.Value);
;
Use Builtin(Fetch_In_Space) With_Args(#SpaceName #S_202NUM) To_Get(#BRetCode);
;
If Cond(*RetOkay);
Set Com(#ReturnCode) Value(OK);
Use Builtin(Update_in_Space) With_Args(#SpaceName #S_202NUM #S_202DES #S_202PRC #S_202QTY);
Signal Event(ProductUpdated) Number(#S_202NUM) Description(#S_202DES) Price(#S_202PRC) Available(#S_202QTY);
Else;
Set Com(#ReturnCode) Value(ER);
Endif;
;
Endroutine;
;
* ===================================================================;
* Get the details of an existing product;
* ===================================================================;
;
Mthroutine Name(Get);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*output) Class(#s_retcda2) Name(#ReturnCode) Mandatory(' ');
Define_Map For(*input) Class(#std_Obj) Name(#RequestedBy);
;
Change Field(#S_202NUM) To(#Number.Value);
;
Use Builtin(Fetch_In_Space) With_Args(#SpaceName #S_202NUM) To_Get(#BRetCode #S_202NUM #S_202DES #S_202PRC #S_202QTY);
;
If Cond(*RetOkay);
Set Com(#ReturnCode) Value(OK);
Signal Event(ProductFound) Number(#S_202NUM) Description(#S_202DES) Price(#S_202PRC) Available(#S_202QTY) Requestedby(#RequestedBy);
Else;
Set Com(#ReturnCode) Value(ER);
Endif;
;
Endroutine;
;
* ===================================================================;
* Destroy the details of an existing product;
* ===================================================================;
;
Mthroutine Name(Destroy);
Define_Map For(*input) Class(#s_202num) Name(#Number);
Define_Map For(*output) Class(#s_retcda2) Name(#ReturnCode) Mandatory(' ');
;
Change Field(#S_202NUM) To(#Number.Value);
;
Use Builtin(Fetch_In_Space) With_Args(#SpaceName #S_202NUM) To_Get(#BRetCode #S_202NUM #S_202DES #S_202PRC #S_202QTY);
;
If Cond(*RetOkay);
Set Com(#ReturnCode) Value(OK);
Use Builtin(Delete_In_Space) With_Args(#SpaceName #S_202NUM);
Signal Event(ProductDestroyed) Number(#S_202NUM);
Else;
Set Com(#ReturnCode) Value(ER);
Endif;
;
Endroutine;
;
* ===================================================================;
* Enumerate the details of all existing products;
* ===================================================================;
;
Mthroutine Name(Enumerate);
Define_Map For(*input) Class(#std_Obj) Name(#RequestedBy);
;
Use Builtin(Select_in_Space) With_Args(#SpaceName) To_Get(#BRetCode #S_202NUM #S_202DES #S_202PRC #S_202QTY);
Dowhile Cond(*RetOkay);
Signal Event(ProductFound) Number(#S_202NUM) Description(#S_202DES) Price(#S_202PRC) Available(#S_202QTY) Requestedby(#RequestedBy);
Use Builtin(SelectNext_in_Space) With_Args(#SpaceName) To_Get(#BRetCode #S_202NUM #S_202DES #S_202PRC #S_202QTY);
Endwhile;
;
Endroutine;
;
* ===================================================================;
* Create a space to handle the storage of the product objects;
* and then prefill the space with 5 "sample" products;
* ===================================================================;
;
Evtroutine Handling(#Com_Owner.CreateInstance);
;
Use Builtin(Create_Space) With_Args(#SpaceName);
Use Builtin(Define_Space_Cell) With_Args(#SpaceName S_202NUM KEY);
Use Builtin(Define_Space_Cell) With_Args(#SpaceName S_202DES);
Use Builtin(Define_Space_Cell) With_Args(#SpaceName S_202PRC);
Use Builtin(Define_Space_Cell) With_Args(#SpaceName S_202QTY);
;
Invoke Method(#COM_Owner.Create) Number(12) Description('Hammer') Price(21.45) Available(1348);
Invoke Method(#COM_Owner.Create) Number(34) Description('Chisel') Price(14.95) Available(437);
Invoke Method(#COM_Owner.Create) Number(56) Description('Saw') Price(51.99) Available(596);
Invoke Method(#COM_Owner.Create) Number(78) Description('Screwdriver') Price(3.45) Available(5866);
Invoke Method(#COM_Owner.Create) Number(90) Description('Pliers') Price(11.98) Available(475);
;
Endroutine;
;
* ===================================================================;
* Destroy the space used to store the product objects;
* ===================================================================;
;
Evtroutine Handling(#Com_Owner.DestroyInstance);
;
Use Builtin(Destroy_Space) With_Args(#SpaceName);
;
Endroutine;
;
End_Com