-- $Source: /commtar/monoBANK/CICS_INTF/demo.ada,v $ -- $Revision: 1.24 $ $Date: 88/06/04 13:55:02 $ $Author: chris $ with Demo_Utilities; with CICS_Terminal_Control; with CICS_Task_Control; with CICS_Exceptions; with CICS_Exec_Interface_Block; use CICS_Exec_Interface_Block; -- for "=" with Host_Character_Pkg; with RTS_CICS_Exceptions; procedure demo is package DU renames Demo_Utilities; package TC renames CICS_Terminal_Control; package TSK renames CICS_Task_Control; package HC renames Host_Character_Pkg; package EIB renames CICS_Exec_Interface_Block; package CommA renames DU.Comm; use CommA; -- for "=" package Emap renames DU.Emap; package Dmap renames DU.Dmap; package DF renames DU.DFile; package CEX renames CICS_Exceptions; package RCE renames RTS_CICS_Exceptions; Comm_Ptr : CommA.Communication_Area_Pointer; Local_Comm : DU.Comm_Record; DData : Dmap.Terminal_Data; EData : Emap.Terminal_Data; Choice : String(1..1); Data_Rec : DU.Data_Record; Trans_Name : constant string := "DEMO"; Emap_Name : constant string := "MENU"; Dmap_Name : constant string := "DATA"; Data_File_Name : constant string := "ADDRFILE"; PremodA: constant TC.Attribute_Character := ( TC.Unprotected_Alphanumeric, TC.Bright_Pen_Detectable, True); PremodN: constant TC.Attribute_Character := ( TC.Unprotected_Numeric, TC.Bright_Pen_Detectable, True); begin Comm_Ptr := CommA.Comm_Area; if Comm_Ptr = null then -- this is the first time into the program Emap.Send_Map(Emap_Name, Source=>TC.Map_Only, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; case Comm_Ptr.state is when DU.Read_Choice => Emap.Receive_Map(Emap_Name, Into=>EData); Choice := Emap.Field(EData, DU.Action); if Choice = "A" then Dmap.Send_Map(Dmap_Name, Source=>TC.Map_Only, Erase=>TC.Screen); Local_Comm.State := DU.Add_Data; Local_Comm.Action := 'A'; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; if Choice = "D" then declare Match : constant String := EMap.Field(EData,DU.Name); Input : DU.Data_Record; Gen_Key : Boolean := False; Found : Boolean := True; Data : Dmap.Terminal_Data; Match_Len : Natural := Match'Length; begin if Match_Len = 0 then Emap.Set_Field(DU.Msg, string'("No Name Entered, Please try again")); Emap.Send_Map(Emap_Name); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; for i in 1..Match'Length loop if Match(i) = '*' then Gen_Key := True; Match_Len := i-1; exit; end if; end loop; begin DF.Read(Data_File_Name, Input, HC.To_Host_String(Match(1..Match_Len)), Gen_Key); exception when RCE.NOTFND => Found := False; end; if Found then Dmap.Set_Field(Data, DU.Lname, HC.To_String(Input.lname)); Dmap.Set_Field(Data, DU.Fname, HC.To_String(Input.fname)); Dmap.Set_Field(Data, DU.Company, HC.To_String(Input.company)); Dmap.Set_Field(Data, DU.Street, HC.To_String(Input.street)); Dmap.Set_Field(Data, DU.City, HC.To_String(Input.city)); Dmap.Set_Field(Data, DU.State, HC.To_String(Input.state)); Dmap.Set_Field(Data, DU.Zip, HC.To_String(Input.zip)); Dmap.Set_Field(Data, DU.Phone, HC.To_String(Input.phone)); Dmap.Set_Field(Data, DU.Comments, HC.To_String(Input.comments)); Dmap.Set_Field(Data, DU.Error, String'( "Press Clear to Exit, Enter to return to MENU")); Dmap.Set_Attribute(Data, DU.Lname, (TC.Protected_AutoSkip, TC.Bright_Pen_Detectable, True)); Dmap.Set_Attribute(Data, DU.Error, (TC.Protected_AutoSkip, TC.Bright_Pen_Detectable, False)); -- pre-modify all fields so we get the old -- data back if no new data is entered Dmap.Set_Attribute (Data, DU.Fname, PremodA); Dmap.Set_Attribute (Data, DU.Company, PremodA); Dmap.Set_Attribute (Data, DU.Street, PremodA); Dmap.Set_Attribute (Data, DU.City, PremodA); Dmap.Set_Attribute (Data, DU.State, PremodA); Dmap.Set_Attribute (Data, DU.Zip, PremodN); Dmap.Set_Attribute (Data, DU.Phone, PremodA); Dmap.Set_Attribute (Data, DU.Comments, PremodA); Dmap.Send_Map(Dmap_Name, From =>Data, Cursor=>Dmap.Field_Position(DU.Fname), Erase=>TC.Screen); Local_Comm.state := DU.update_data; Local_Comm.Action := 'D'; CommA.Setup_Return(Trans_Name, Local_Comm); return; else Emap.Set_Field(DU.Msg, String'("Name not found - try again")); Emap.Send_Map(Emap_Name, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; end; else Emap.Set_Field(DU.Msg, String'("Invalid Menu Choice please enter 'A' or 'D'")); Emap.Send_Map(Emap_Name, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; when DU.Add_Data => Dmap.Receive_Map(Dmap_Name, Into=>DData); DU.Read_Data(DData, Data_Rec); begin DF.Write(Data_File_Name, Data_Rec, Data_Rec.Lname); exception when CEX.Duplicate_Record => Dmap.Set_Field(DData, DU.Error, String'("Last Name is already in the Database")); Dmap.Send_Map(Dmap_Name, From=>DData); Local_Comm.State := DU.Add_Data; Local_Comm.Action := 'A'; CommA.Setup_Return(Trans_Name, Local_Comm); return; end; Emap.Send_Map(Emap_Name, Source=>TC.Map_Only, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; when DU.Update_Data => Dmap.Receive_Map(Dmap_Name, Into=>DData); DU.Read_Data(DData, Data_Rec); DF.Read(Data_File_Name, Data_Rec, HC.To_Padded_Host_String( Dmap.Field(DData, DU.Lname), Dmap.Length(DU.Lname)), Update=>True); DU.Read_Data(DData, Data_Rec); DF.Rewrite(Data_File_Name, Data_Rec); Emap.Send_Map(Emap_Name, Source=>TC.Map_Only, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end case; exception when CEX.MapFail => if EIB.EIB_AID = EIB.Clear then -- user cleared the screen before a receive TC.Send_Text("DEMO - SESSION ENDED", Erase=>TC.Screen); return; elsif EIB.EIB_AID = EIB.PA1 then Emap.Send_Map(Emap_Name, Source=>TC.Map_Only, Erase=>TC.Screen); Local_Comm.state := DU.Read_Choice; Local_Comm.Action := ' '; CommA.Setup_Return(Trans_Name, Local_Comm); return; end if; when RCE.EOC => TC.Send_Text("EOC exception"); return; when RCE.EODS => TC.Send_Text("EODS exception"); return; when RCE.INVMPSZ => TC.Send_Text("INVMPSZ exception"); -- when others => -- -- don't just die -- TC.Send_Text("DEMO - SESSION ENDED : Unexpected Exception", -- Erase=>TC.Screen); -- return; end Demo; -- $Cprt start$ -- -- Copyright (C) 1988 by Intermetrics, Inc. -- -- This material may be used duplicated or disclosed by or for the -- U.S. Government pursuant to the copyright license under DAR clause -- 7-104.9(a) (May 1981). -- -- This project was spnsored by the STARS Foundation -- Naval Research Laboratory, Washington DC -- -- $Cprt end$