7.119.2 SRVROUTINE Examples

Example 1 – Returning a record

Example 2 – Returning a list of data

Example 3 – Returning a response object

Example 4 -Using *HTTP

Example 5 - Using *RESOURCE

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

Example 4 -Using *HTTP

Srvroutine Name(Status) Response(*HTTP #http)

Define Field(#contentstring) Type(*CHAR) Length(256) Decimals(0)

#contentstring := '{"JOBID":"' + *JOBNBR + '","ServerStatus":"OK",' + '"CPUTYPE":"' + *CPUTYPE + '",' + '"LANSAPGMLIB":"' + *LANSAPGMLIB + '"}'

#http.Response.ContentString := #contentstring

Endroutine

 

Example 5 - Using *RESOURCE

Srvroutine Name(GetFile) Response(*RESOURCE #MyFile) Session(*REQUIRED)

Field_Map For(*INPUT) Field(#lemlstr) Parameter_Name(Path)

Field_Map For(*INPUT) Field(#Filename)

 

Define Field(#tempFile) Reffld(#lemlstr)

 

#TempFile := #lemlstr + #filename.substring( 1 (#filename.lastpositionof( '.' ) - 1) ) + '_temp.txt'

 

Use Builtin(OV_FILE_SERVICE) With_Args(COPY_FILE (#lemlstr + #filename) #TempFile) To_Get(#retcode #ErrorNumber)

 

If (#retcode = OK)

 

#myfile.ContentFile := #TempFile

#myfile.RemoveFile := true

 

Endif

Endroutine