8 6 3 DEFINE_MAP in MTHROUTINE

LANSA Technical

8.6.3 DEFINE_MAP in MTHROUTINE

When you create a custom-defined method using the MTHROUTINE command, you can optionally specify that the method can receive input values and return output values using a DEFINE_MAP statement.

Example 1

You could define a method to fetch details for an employee on the form. The method accepts the employee number (#curemp) as input and returns a transaction number (#trnno):

mthroutine name(GetInfo)
   define_map for(*input) class(#empno) name(#curemp)
   define_map for(*output) class(#STD_NUM) name(#trnno)
   change #empno #curemp.value
   fetch fields(#detflds) from_file(pslmst) with_key(#empno)
   change #STD_NUM '#STD_NUM + 1'
   set com(#trnno) value(#STD_NUM)
endroutine  
 

An owner form of this form can now ask it to execute this method. It passes the current value of the #empno field and receives the transaction number. The value of the transaction number is assigned to a field #TRANSA on the owner form.

EVTROUTINE HANDLING(#MOVETO.Click)
   invoke #frmdetail.GetInfo curemp(#empno) trnno(#transa)
ENDROUTINE
 

Example 2

In this example form the Click event of the push button invokes the method LoadForm, passing the name of a form to be displayed and returning a reference to the created form instance.

Try copying and pasting this source code to a form component and compile it. Execute the form and use it to create and display instances of other forms by specifying the name of the form to be displayed and clicking the Load button. The form name entered must be the name of a previously created form.

BEGIN_COM HEIGHT(123) LEFT(296) TOP(120) WIDTH(209)
DEFINE_COM CLASS(#STD_OBJ.Visual) NAME(#STD_OBJ) CAPTION('Form to Load:') DISPLAYPOSITION(1) HEIGHT(19) LABELTYPE(Caption) LEFT(8) MARGINLEFT(80) PARENT(#COM_OWNER) TABPOSITION(1) TOP(8) WIDTH(161)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_1) CAPTION('Load') DISPLAYPOSITION(2) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(2) TOP(45)
 
* form collection counter and form collection
define #FormTot Reffld(#STD_NUM) default(0)
DEFINE_COM CLASS(#PRIM_KCOL) NAME(#FORMS) COLLECTS(#PRIM_FORM) KEYEDBY(#STD_NUM) STYLE(Collection)
 
define #Position Reffld(#STD_NUM) default(1)
 
EVTROUTINE HANDLING(#PHBN_1.Click)
Change #FormTot '#FormTot + 1'
* call the LoadForm method, pass it the name of the form to be instantiated and return a reference to it.
Invoke #COM_OWNER.LoadForm FormName(#Std_Obj) FormReference(#Forms<#FormTot>)
ENDROUTINE
 
Mthroutine LoadForm
* receive the name of the form and return a reference of the form instance which has been created
Define_map *input  #Std_Obj    #FormName
Define_map *output #prim_form  #FormReference pass(*by_Reference)
 
*Create an instance of the named form and set reference to it
Set_Ref #FormReference (*Create_from #FormName.Value)
 
Set #FormReference Left(#Position) Top(#Position)
Change #Position '#Position + 10'
 
Invoke #FormReference.ShowForm
Endroutine
END_COM