The following example shows how to use the CREATE, DISPLAY, MODIFY, and INQUIRE statements to create and interact with the .NET control once its COPY file has been included in your COBOL program. First, you'll find a sample COPY file. Then you'll find a sample COBOL program, with comments, in bold.
NETDEFGEN COPY File
----- Generated by NetDefGen ----- OBJECT @ASSEMBLY NAME "@My.Assembly" VERSION "1.0.0.0" CULTURE "neutral" STRONG "3f6e8fa90dc2951b" NAMESPACE "My.Test.Namespace" CLASS "MyClass " CONSTRUCTOR, 0, @CONSTRUCTOR1 * printIteration PROPERTY_GET, 0, @printIteration RETURNING, "int", TYPE 3 * printIteration PROPERTY_PUT, 0, @printIteration "int (Property Value)", TYPE 3 * Int32 ToLog(System.String, Int32, System.String) METHOD, 0, "@ToLog" "BSTR" @StringIn, TYPE 8 "int" @someNumber, TYPE 3 "BSTR" @anotherString, TYPE 8 RETURNING "int", TYPE 3 * Public fields FIELD, 0, @lastName RETURNING, "BSTR", TYPE 8 NAMESPACE "My.Test.Namespace" CLASS "MyGUIClass" VISUAL CONSTRUCTOR, 0, @CONSTRUCTOR1 * LogRecordRead (Int32) EVENT, -709034780, @MyGUIClasss_LogRecordRead * LogRecordWritten (Int32, System.String) EVENT, -1411090252, @MyGUIClass_LogRecordWritten NAMESPACE "My.Test.Namespace" CLASS "UserControl1" VISUAL CONSTRUCTOR, 0, @CONSTRUCTOR1 CONSTRUCTOR, 0, @CONSTRUCTOR2 "BSTR" @userStuff, TYPE 8 "int" @intData, TYPE 3 "unsigned int" @uintData, TYPE 19 "single" @floatData, TYPE 4 "double" @doubleData, TYPE 5 "short" @shortintData, TYPE 2 "unsigned short" @ushortintData, TYPE 18 ----- End Generated NetDefGen Code -----
COBOL Program
* Handles can be associated with a specific * Assembly.NameSpace.Class * Use this form when the COBOL statement, MODIFY - INQUIRE, etc., * uses the handle before a CREATE or DISPLAY statement occurs * in the program. 77 MY-NONGUI-HANDLE USAGE IS HANDLE OF "@My.Assembly.My.Test.Namespace.MyClass". 77 MY-GUI-HANDLE USAGE IS HANDLE. 77 NUMBRPRINTS USAGE IS SIGNED-INT VALUE 3. 77 QPRINTS USAGE IS SIGNED-INT. 77 PARAM1 USAGE IS SIGNED-INT. 77 PARAM2 PIC x(128). 77 LAST-NAME PIC x(32). 77 PARM1 pic x(12) VALUE "HELLO WORLD". 77 PARM2 USAGE IS SIGNED-INT VALUE 1111. 77 PARM3 USAGE IS UNSIGNED-INT VALUE 2222. 77 PARM4 USAGE IS FLOAT VALUE 0.3333. 77 PARM5 USAGE IS DOUBLE VALUE 123456.55. 77 PARM6 USAGE IS SIGNED-SHORT VALUE 4444. 77 PARM7 USAGE IS UNSIGNED-SHORT VALUE 5555. *CREATE - instantiate a NON-GUI CLASS. CREATE "@My.Assembly" NAMESPACE IS "My.Test.Namespace" CLASS-NAME IS "MyClass" EVENT PROCEDURE IS EVENT-PROC HANDLE IS MY-NONGUI-HANDLE. *DISPLAY - instantiate a GUI CLASS. GUI classes have a keyword *VISUAL in the COPY file after the CLASS keyword. DISPLAY "@My.Assembly" NAMESPACE IS "My.Test.Namespace" CLASS-NAME IS "MyGUIClass" EVENT PROCEDURE IS MY-EVENT-PROCEDURE HANDLE IS MY-GUI-HANDLE. *INQUIRE - retrieve the value of a PROPERTY OR FIELD. INQUIRE MY-NONGUI-HANDLE printIteration IN QPRINTS. INQUIRE MY-NONGUI-HANDLE lastName IN LAST-NAME. *MODIFY - execute a method. Methods are case sensitive. They *must match the COPY file case and be enclosed in quotes. MODIFY MY-NONGUI-HANDLE "ToLog"("Hello From COBOL", 99, "It's a Good Thing"). *MODIFY - set the value of a PROPERTY OR FIELD. MODIFY MY-NONGUI-HANDLE printIteration = NUMBRPRINTS. MODIFY MY-NONGUI-HANDLE lastName = LAST-NAME. *Capture events and retrieve event data - Use EVENT-DATA-2 or the *COPY file event name. *EVENT-DATA-2 and the COPY file event name are an event ID. The *runtime tries to locate the last event thrown by matching the *event ID. If you use CONTROL-HANDLE or HANDLE IS from the CREATE *and DISPLAY statements, the runtime tries to locate the last *event thrown by matching the .NET Interface for the control. *Using a CONTROL-HANDLE or COPY file event name/numeric ID makes *a difference when event procedures cause another event before *collecting the first event's DATA. If the events are different, *use the COPY file event name to retrieve the desired event data. *If you use CONTROL-HANDLE, the most recent event, that is, the *Last In First Out (LIFO), received by the runtime for a .NET *interface is returned to a COBOL program possibly resulting in *incorrect event data. MY-EVENT-PROCEDURE. EVALUATE EVENT-TYPE WHEN MSG-NET-EVENT EVALUATE EVENT-DATA-2 WHEN @MyGUIClass_LogRecordWritten CALL "C$GETNETEVENTDATA" USING @MyGUIClass_LogRecordWritten PARAM1 PARAM2 WHEN @MyGUIClass_LogRecordRead CALL "C$GETNETEVENTDATA" USING EVENT-DATA-2 PARAM1 END-EVALUATE END-EVALUATE. *Screen section .NET Control with a Constructor screen section. 01 screen-1. 03 SOME-NETCONTROL, "@My.Assembly", LINE 1, COL 2, NAMESPACE IS "My.Test.Namespace", CLASS-NAME IS "UserControl1", CONSTRUCTOR IS CONSTRUCTOR2(PARM1, PARM2, PARM3, PARM4, PARM5, PARM6, PARM7), EVENT PROCEDURE IS USERCONTROL-EVENTS. *Coding exceptions. NameSpace is optional in C# and VB NET and *therefore may not appear in a COPY file. However, DISPLAY, *CREATE, and Screen Section COBOL statements require a NameSpace *entry. When a COPY file is missing a NameSpace keyword, use the *class name as the NameSpace value on DISPLAY, CREATE, and Screen *Section statements.