現在地: LANSA テクニカル リファレンスガイド > 7. RDML コマンド > 7.119 SRVROUTINE > 7.119.2 SRVROUTINE の使用例

7.119.2 SRVROUTINE の使用例

例 1 – レコードを戻す

例 2 – データのリストを戻す

例 3 – 応答レコードを戻す

例 4 - *HTTP の使用

例 5 - *RESOURCE の使用

例 1 – レコードを戻す

以下は、識別子を受け取って、レコードを表すフィールドのグループを返す簡単なルーチンです。

呼び出し元によって FETCH の成否が決定できるように、#IO$STS を戻す追加の出力マップがあることに注意してください。

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
 

例 2 – データのリストを戻す

以下は、ファイル内のすべてのレコードを含むリストを戻す簡単なルーチンです。

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

 

例 3 – 応答レコードを戻す

次はイメージをダウンロードする際の一般的なルーチンです。この例では、イメージはデータベース・テーブルから読み込まれます。そして、応答オブジェクトにイメージ・データが入れられ、ファイル名が設定されます。

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

 

例 4 - *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

 

例 5 - *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