In this step you will execute the Find srvroutine in the Department Server Module, which uses the FETCH command to retrieve a single record from the database. If you examine the code generated for the xDepartments Server Module, you will notice that there are no OPEN or CLOSE statements required for the table. Table opening and closing is handled automatically by LANSA.
1. Switch to the server module iiixDepartmentsDataServer in the editor and locate the Find srvroutine.
Hint: Use the Go To tab.
Field_Map For(*Input) Field(#xDepartmentCode)
Group_Map For(*Output) Group(#xDepartments)
Field_Map For(*Output) Field(#io$sts) Parameter_Name(Status)
* Return all data for the keys provided
Fetch Fields(#xDepartments) From_File(xDepartments) With_Key(#xDepartmentCode)
Note that the Fetch command retrieves fields defined by the Group_By xDepartments, using the key xDepartmentCode.
Your web page executes the Find srvroutine passing field xDepartmentCode. The srvroutine returns the fields in the Group_by xDepartments and the I/O Status field IO$STS.
2. Copy the Group_by, xDepartments to the Windows clipboard.
3. Switch to your web page, iiiMaintDepartment. Paste the Group_By, into your web page before the routines.
4. Create a method routine, Fetch:
5. As you learnt in exercise WBF025, this routine should have this standard structure:
Define the Server Module.Find srvroutine as component FindDepartment.
Execute FindDepartment asynchronously, passing parameters to be sent / received.
Within an event routine for FindDepartment.Completed handle any required processing when srvroutine completes.
Your code should look like the following:
Define_Com Class(#iiixDepartmentsDataServer.Find) Name(#FindDepartment)
#FindDepartment.ExecuteAsync( #xDepartmentCode #xDepartments #io$sts )
If (#IO$STS = OK)
Further logic will be added in later steps.
Note: If you select #iiixDepartmentsDataServer.Find in your source and press F2, you will see the following on the Features tab:
This shows that you can call the Server Module's srvroutines, synchronously (Execute) or asynchronously (ExecuteAsync). The required input and output parameters are also shown.
6. Invoke the Fetch method from the Fetch button Click event:
7. Compile your web page. Execute the web page in the browser. Department code is a 4 long, Alphanumeric field, containing a number code. Enter a department code such as 100, 200, 1000 or 1100 and click the Fetch button. The department description should be displayed.