Your finished code for form iiiMaintDept should appear something like the following:
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(484) Clientheight(219) Componentversion(2) Left(484) Top(214) Layoutmanager(#Layout1)
Define_Com Class(#PRIM_TBLO) Name(#Layout1)
Define_Com Class(#PRIM_TBLO.Column) Name(#Column1) Displayposition(1) Parent(#Layout1) Width(1.54)
Define_Com Class(#PRIM_TBLO.Column) Name(#Column2) Displayposition(2) Parent(#Layout1) Width(0.46)
Define_Com Class(#PRIM_TBLO.Row) Name(#Row1) Displayposition(1) Parent(#Layout1) Height(1.66)
Define_Com Class(#PRIM_TBLO.Row) Name(#Row2) Displayposition(2) Parent(#Layout1) Height(0.34)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem1) Alignment(TopLeft) Column(#Column1) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Down) Margintop(10) Marginleft(20)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem2) Alignment(TopLeft) Column(#Column1) Manage(#xDepartmentDescription) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Down) Margintop(10) Marginleft(20)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem3) Alignment(BottomCenter) Column(#Column2) Manage(#FETCH) Parent(#Layout1) Row(#Row1) Sizing(None) Marginbottom(10) Flow(Up)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem4) Alignment(TopLeft) Column(#Column1) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Down) Marginleft(20) Margintop(10)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem5) Alignment(TopLeft) Column(#Column1) Manage(#xDepartmentCode) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Down) Margintop(10) Marginleft(20)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem6) Alignment(TopLeft) Column(#Column1) Manage(#STD_NUM) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Down) Marginleft(20) Margintop(10)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem7) Alignment(BottomCenter) Column(#Column2) Manage(#INSERT) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Up) Marginbottom(10)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem8) Alignment(BottomCenter) Column(#Column2) Manage(#UPDATE) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Up) Marginbottom(10)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem9) Alignment(BottomCenter) Column(#Column2) Manage(#DELETE) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Up) Marginbottom(10)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem10) Alignment(BottomCenter) Column(#Column2) Manage(#CLEAR) Parent(#Layout1) Row(#Row1) Sizing(None) Flow(Up) Marginbottom(10)
Define_Com Class(#xDepartmentCode.Visual) Name(#xDepartmentCode) Displayposition(1) Parent(#COM_OWNER) Tabposition(1) Height(21) Top(10) Left(20)
Define_Com Class(#xDepartmentDescription.Visual) Name(#xDepartmentDescription) Displayposition(2) Parent(#COM_OWNER) Tabposition(2) Width(294) Top(41) Left(20)
Define_Com Class(#PRIM_STBR) Name(#StatusBar1) Displayposition(3) Height(25) Left(0) Messageposition(1) Parent(#COM_OWNER) Tabposition(4) Tabstop(False) Top(194) Width(484)
Define_Com Class(#PRIM_PHBN) Name(#FETCH) Caption('Fetch') Displayposition(4) Left(388) Parent(#COM_OWNER) Tabposition(5) Top(147)
Define_Com Class(#STD_NUM.Visual) Name(#STD_NUM) Componentversion(1) Displayposition(5) Height(21) Parent(#COM_OWNER) Tabposition(3) Usepicklist(False) Width(241) Top(72) Left(20)
Define_Com Class(#PRIM_PHBN) Name(#INSERT) Displayposition(6) Left(388) Parent(#COM_OWNER) Tabposition(6) Top(112) Caption('Insert')
Define_Com Class(#PRIM_PHBN) Name(#UPDATE) Displayposition(7) Left(388) Parent(#COM_OWNER) Tabposition(7) Top(77) Caption('Update')
Define_Com Class(#PRIM_PHBN) Name(#DELETE) Caption('Delete') Displayposition(8) Left(388) Parent(#COM_OWNER) Tabposition(8) Top(42)
Define_Com Class(#PRIM_PHBN) Name(#CLEAR) Displayposition(9) Left(388) Parent(#COM_OWNER) Tabposition(9) Top(7) Caption('Clear')
Group_By Name(#formdata) Fields(#xDepartmentCode #xDepartmentDescription #STD_NUM)
Define Field(#answer) Type(*char) Length(6)
Evtroutine Handling(#com_owner.CreateInstance)
Set Com(#com_owner) Caption(*component_desc)
Execute Subroutine(InitForm)
Endroutine
Evtroutine Handling(#FETCH.Click)
Fetch Fields(#xDepartmentCode #xDepartmentDescription) From_File(xDepartments) With_Key(#xDepartmentCode)
If_Status Is_Not(*OKAY)
Message Msgtxt('Error retrieving Department')
Else
#xDepartmentCode.ReadOnly := True
#FETCH.Enabled #INSERT.Enabled := False
#UPDATE.Enabled #DELETE.Enabled := True
Endif
Endroutine
Evtroutine Handling(#INSERT.Click)
Begincheck
Condcheck Field(#xDepartmentCode) Cond(#xDepartmentCode.Contains( ' ' )) If_True(*ERROR) If_False(*NEXT) Msgtxt('Code cannot contain embedded blanks.')
If Cond(#xDepartmentCode = #xDepartmentDescription)
Set_Error For_Field(#xDepartmentCode #xDepartmentDescription) Msgtxt('Department Code cannot be the same as Department Description')
Endif
Rangecheck Field(#STD_NUM) Range((1 10)) Msgtxt('Must be in the range 1 to 10')
#xDepartmentDescription := #xDepartmentDescription.UpperCase
Valuecheck Field(#xDepartmentDescription) With_List(NONE END LAST) In_List(*error) Not_Inlist(*next) Msgtxt('This descriptiuon is reserved')
Filecheck Field(#xDepartmentCode) Using_File(xDepartments) Using_Key(#xDepartmentCode) Found(*ERROR) Not_Found(*NEXT) Msgtxt('Department Code already exists')
Endcheck
Insert Fields(#formdata) To_File(xDepartments)
If_Status Is(*OKAY)
Message Msgtxt('Department inserted successfully')
Execute Subroutine(InitForm)
Else
If_Status Is(*ERROR)
Message Msgtxt('Error inserting department')
Endif
Endif
Endroutine
Evtroutine Handling(#UPDATE.Click)
Update Fields(#formdata) In_File(xDepartments) Val_Error(*next)
If_Status Is(*OKAY)
Message Msgtxt('Departmenmt successfully updated')
Execute Subroutine(InitForm)
Else
If_Status Is(*NORECORD)
Message Msgtxt('Department not found')
Else
If_Status Is(*ERROR)
Message Msgtxt('Error updating department')
Endif
Endif
Endif
Endroutine
Evtroutine Handling(#DELETE.Click)
Use Builtin(MESSAGE_BOX_SHOW) With_Args(YESNOCANCEL NO QUESTION 'Confirm Delete' 'Are you sure you want to delete?') To_Get(#answer)
If Cond(#answer = YES)
Delete From_File(xDepartments) Val_Error(*NEXT)
Case Of_Field(#IO$STS)
When Value_Is(= OK)
Message Msgtxt('Department deleted successfully')
Execute Subroutine(InitForm)
When (= NR)
Message Msgtxt('Department not found')
When (= ER)
Message Msgtxt('Error deleting department')
Endcase
Endif
Endroutine
Evtroutine Handling(#CLEAR.Click)
Execute Subroutine(InitForm)
Endroutine
Subroutine Name(InitForm)
#formdata := *default
#UPDATE.enabled #DELETE.Enabled := False
#xDepartmentCode.ReadOnly := False
#FETCH.enabled #INSERT.enabled := true
Endroutine
End_Com