現在地: Visual LANSA 開発者ガイド > 2. グラフィカル・ユーザーインターフェース・アプリケーションの作成 > 2.9 リスト、ツリー・ビュー、グリッド、グラフ > 2.9.8.15 グリッド/リストでのエラー処理
2.9.8.15 グリッド/リストでのエラー処理

次の例では、コレクションを使用して、ユーザーが複数のレコードを一度に更新する可能性のあるグリッドのエラー・チェックを行う方法を示しています。また、ネストされたBEGINCHECK/ENDCHECKブロックを正しく使用して、妥当性検査に失敗したフィールドに対する視覚的なフィードバックを表示する方法も示します。

ネストされたBEGINCHECK/ENDCHECKブロックを使用する理由は、この方法でグリッドを更新することで、IBM i上でブラウズ・リストを介して複数の詳細入力を検証することと同様になるからです。

* COMPONENT:STD_FORM

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(221) Clientwidth(492) Height(255) Left(335) Top(106)
Define_Com Class(#PRIM_GRID) Name(#GRID_1) Captionnoblanklines(True) Columnbuttonheight(29) Columnscroll(False) Componentversion(1) Displayposition(1) Height(193) Left(0) Parent(#COM_OWNER) Showbuttonselection(True) Showselection(True) Showselectionhilight(False) Showsortarrow(True) Tabposition(1) Top(0) Visualstyle(#VS_NORM) Width(401)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_1) Caption('Empno') Captiontype(Caption) Displayposition(1) Parent(#GRID_1) Source(#EMPNO) Width(15)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_2) Caption('Surname') Captiontype(Caption) Displayposition(2) Parent(#GRID_1) Source(#SURNAME) Width(29)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_3) Caption('Zip') Captiontype(Caption) Columnalign(Right) Displayposition(3) Parent(#GRID_1) Readonly(False) Source(#POSTCODE) Width(14)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_4) Columnalign(Right) Displayposition(4) Parent(#GRID_1) Source(#SALARY) Widthtype(Remainder)
Define_Com Class(#PRIM_PHBN) Name(#PHBN_1) Caption('&Refresh ') Displayposition(2) Left(408) Parent(#COM_OWNER) Tabposition(2) Top(8)
Define_Com Class(#PRIM_STBR) Name(#STBR_1) Displayposition(3) Height(24) Left(0) Messageposition(1) Parent(#COM_OWNER) Tabposition(3) Tabstop(False) Top(197) Width(492)
Define_Com Class(#PRIM_PHBN) Name(#PHBN_upd) Caption('&Update ') Displayposition(4) Left(408) Parent(#COM_OWNER) Tabposition(4) Top(40)

Define_Com Class(#prim_kcol<#postcode #empno>) Name(#postcodes)
Define_Com Class(#prim_kcol<#salary #empno>) Name(#salaries)

Evtroutine Handling(#PHBN_1.Click)
* Clear Collections as well as grid
#postcodes.RemoveAll
#salaries.RemoveAll
Clr_List Named(#grid_1)
Select Fields(#grid_1) From_File(pslmst)
#postcodes<#empno> := #postcode
#salaries<#empno> := #salary
Add_Entry To_List(#grid_1)
Endselect
Endroutine

Evtroutine Handling(#PHBN_upd.Click)
* Check the input data
Begincheck
Selectlist Named(#GRID_1)
Continue If(#Com_owner.HasNotChanged)
Begincheck
Update Fields(#salary #postcode) In_File(pslmst) With_Key(#empno) Io_Error(*NEXT) Val_Error(*NEXT) Check_Only(*yes)
If_Status Is_Not(*okay)
#grid_1.currentitem.Visualstyle <= #vs_emph
Else
#grid_1.currentitem.Visualstyle <= #vs_norm
Endif
Upd_Entry In_List(#GRID_1)
Endcheck If_Error(*next)
Endselect
Endcheck

* Now do the updates (now that every field is validated and correct)
Selectlist Named(#Grid_1)
Continue If(#Com_owner.HasNotChanged)
Update Fields(#salary #postcode) In_File(pslmst) With_Key(#empno) Io_Error(*NEXT) Val_Error(*NEXT)
Endselect
Endroutine

* Method Routine to check for changes
Mthroutine Name(HasNotChanged)
Define_Map For(*result) Class(#prim_boln) Name(#Result)
If ((#postcode = #postcodes<#Empno>) And (#salary = #salaries<#Empno>))
#Result := True
Endif
Endroutine
End_Com

 

「内側」のBEGINCHECK/ENDCHECKループでは、ユーザーが更新した各グリッド行項目が処理されます。また、IF_ERROR(*NEXT) パラメータにより、SELECTLIST ループですべてのグリッド項目の処理が継続され、エラーの初回検出時にこのループが停止しなくなります。

妥当性検査エラーが検出された場合、「外側」の BEGINCHECK/ENDCHECK コマンドでは、デフォルトの IF_ERROR(*LASTDIS) 設定を使用するため、データベースにレコードが書き込まれずに更新イベント・ルーチンが強制終了します。

妥当性検査エラーは、1つ以上のグリッド行でエラーが見つかったときに検出されます。これは、「内側」の妥当性検査ブロックでのエラーにより「外側」の妥当性検査ブロックでエラーがトリガーされるためです。