7.119.2 SRVROUTINE Examples

Example 1 – Returning a record

Example 2 – Returning a list of data

Example 3 – Returning a response object

Example 1 – Returning a record

This simple routine receives an identifier and returns the group of fields representing the record.

Note the additional output map returning the #IO$STS field so that the success of the FETCH can be determined by the caller.

Group_By Name(#Employee) Fields(#Empno #Surname #Givename #Address1 #Address2 #Address3 #Postcode #Phonehme #Phonebus #Deptment #Section #Salary #Startdte #Termdate)

Srvroutine Name(GetEmployee)

Field_Map For(*Input) Field(#Empno)

Group_Map For(*output) Group(#Employee)

Field_Map For(*output) Field(#io$sts) Parameter_Name(Status)

Fetch Fields(#Employee) From_File(pslmst) With_Key(#Empno)

Endroutine

Example 2 – Returning a list of data

This simple routine returns a list containing all the records in the file.

Def_List Name(#Employees) Fields(#Empno #Surname #Givename #Address1 #Address2 #Address3 #Postcode #Phonehme #Phonebus #Deptment #Section #Salary #Startdte #Termdate) Type(*working) Entrys(999)

Srvroutine Name(GetEmployees)

List_Map For(*Output) List(#Employees)

Select Fields(#Employees) From_File(pslmst)

Add_Entry To_List(#Employees)

Endselect

Endroutine

Example 3 – Returning a response object

This is a typical image download routine. In this example the image is read from a database table. The response object is then populated with the image and the file name is set.

Srvroutine Name(DownloadImage) Response(#Response)

Field_Map For(*Input) Field(#Empno)

Fetch Fields(#GiveName #Surname) From_File(pslmst) With_Key(#empno)

If_Status Is(*okay)

Fetch Fields(#empimg) From_File(pslimg) With_Key(#empno)

If_Status Is(*okay)

#Response.ContentFile := #Empimg.Filename

#Response.AttachmentFileName := #Surname + #GiveName + #Empno

Endif

Endif

Endroutine