sams_teach_yourself_cobol_in_24_hours_-_hour_24_the_graphical_user_interface

Sams Teach Yourself COBOL in 24 Hours - Hour 24 The Graphical User Interface

Return to Teach Yourself COBOL in 24 Hours, COBOL bibliography, COBOL, COBOL DevOps, Awesome COBOL, Awesome IBM Mainframe, IBM Mainframe development, IBM Mainframe bibliography, Fortran

“ (TYCb24H 1998)

Hour 24 The Graphical User Interface

Most modern computer users are very familiar with the graphical user interface, or GUI. This method of interfacing with the user is very different from the historical approach of the text mode screen. Some argue that the GUI is not well suited to the tasks of business, and there may be some truth to that criticism. Business demands streamlined, fast, accurate, and simple-to-operate applications to minimize training costs and ease user operation.

Unlike a text mode screen, where every field is displayed, the GUI relies on user action to open specific areas of the application. Text mode applications guide the user through the process, but the GUI allows the user to control the process. This type of process is often referred to as event driven. Event-driven logic, relating to a GUI, can be very difficult to handle and code. However, COBOL is more than adequate to handle the business logic required behind the scenes in a GUI type of application.

In this hour, you learn about the GUI, concentrating on such items as

• Different methods of achieving a GUI in COBOL

• Using COBOL sp2 to generate a complete GUI program

• What a panel is, and how to define one using sp2

• Using the COBOL Call interface to communicate with the GUI

Different Methods of Achieving the Graphical User Interface The Graphical User Interface (GUI) has been used on multiple platforms, from UNIX to the PC. COBOL itself has no built-in GUI. The multiple platforms and operating systems that support COBOL make a standard GUI nearly impossible. However, each compiler vendor supports some form of GUI.

One way to produce a GUI for your application is to use one of these vendor-provided solutions. However, they may not be portable to another vendor’s compiler and may not be available on all platforms.

Many of these products use a special scripting language to control the user interface, requiring the programmer to learn another set of rules and language elements to create the desired user interface. Some use enhanced Accept and Display statements to actually create a GUI. Still others use COBOL statements to handle the manipulation of data from the GUI.

One method that has some following is using a language other than COBOL to create the interface. Languages such as Visual Basic and Visual C++ handle the user interface, making calls to COBOL programs to carry out the file access and business processing.

Another method that is very popular is to use a third-party tool designed to work with COBOL for the user interface. These tools support multiple compilers and platforms. If at some point you require a different COBOL compiler or are running on a different platform, you do not need to change your COBOL programs. Simply change the version of the third-party tool in use.

One such third-party tool that supports virtually every COBOL compiler available on the PC is COBOL sp2 from Flexus International.

In this hour, you use the COBOL sp2 product to create a GUI program.

Using sp2 to Create a Graphical User Interface sp2 uses panels to represent each window displayed to the user. Call statements are issued in your COBOL program to manipulate these panels. sp2 creates a Copybook, containing all of data fields that are passed to and from the panel for the user to modify, for use with your program. Additionally, sp2 generates a skeleton COBOL program for you to use with your application. For the demonstration in this hour, you create a GUI interface for the Chapt15d program in Listing 15.3. The program covers dynamic access to an Indexed file.

The first step is to install the COBOL sp2 evaluation version onto your PC. The file is located on the CD-ROM that came with this book. To install the Windows 95, 98, and NT version, run the following, where D: is the drive letter of your CD-ROM drive: D:\3rdparty\SPFJ3224.EXE. Follow the prompts to install the programs. To install the Windows 3.1 version, run D:\3rdparty\SPFJ1624.EXE. If you are using a compiler other than the provided Fujitsu compiler, you may download the version of sp2 that works with your compiler from the Flexus Web site at http://www.flexus.com.

After installing the software, you should become familiar with the sp2 panel editor. Start the editor by clicking Start, Programs, Fujitsu 32 Bit Version-COBOL sp2, and COBOL sp2 60 Day Evaluation. The window shown in Figure 24.1 should be displayed.

Familiarize yourself with the icons available on the toolbar. Their descriptions are shown in the figure. These buttons are used throughout this hour.

Designing Your Panel The first step in designing the panel for your GUI is to title the panel and choose a window border style. To do so, select the Panel menu option and click Display. The display shown in Figure 24.2 appears.

For the title, type Tenant Display Program and enter the same for the description. Select the radio button next to Main to use a Main Window style display. Click the OK button to accept the selections.

The next step is to add the various fields to the screen display. The first field to add is the dealer number. Some text should be added to describe the field. Click the Text button on the sp2 toolbar. Next, position your mouse at the location on the screen where you want this text to appear. Start near the upper-left corner of the screen but leave some room at the edges. Click the location you desire, and the word Text appears.

Figure 24.1 The COBOL sp2 panel editor.

Image

In the second field of the Field Control Ribbon, you will see the word Text. This field is where you modify the text being displayed on the panel. Click on the field, change the text to Number:, and press Enter. The text in the panel changes from the word Text to the word Number:.

Next, you need to add the field for entering the dealer number. Select the System Default Entry Field icon from the sp2 toolbar. Position the mouse so that the pointer is immediately after the text added for Number: and click to position the field. If you do not like the position of the field, double-click the field to select it, drag the field to a new location, and click to accept the position.

Figure 24.2 Selecting panel display options.

Image

The new field is not long enough to display the entire number, so you need to extend the field to the right. Double-click the field to select it, position the mouse over the right border, and drag the edge of the field to the right. This step expands the displayed size of the input field. Make the field approximately the size shown in Figure 24.3.

Figure 24.3 Adding a system default entry field.

Image

The size of the data to be placed in the field is defined by entering a Picture clause definition into the third field of the Field Control Ribbon. Select the field again by double-clicking it. The dealer number is a Pic X(8) field, so in the third field of the Field Control Ribbon, where the default value of X(10) is displayed, type X(8) and press Enter.

The field must have a name attached to it for use in the Copybook generated by sp2. In addition, your program uses that name to fill in the panel with data. To name the Number field, type the name Number into the first field of the Field Control Ribbon.

Follow the same steps to set up the other entry fields on the screen. These fields are for the dealer name (Last, First, and Middle). The panel should now resemble Figure 24.4. Remember that Last name is 25 characters, First is 15, and Middle is 10.

1. Click the Text icon and position the field description on the panel.

2. Change the text displayed by modifying the second field of the Field Control Ribbon.

3. Click the System Default Entry Field icon and position the field where desired, clicking to place the field.

4. Expand the field to a reasonable length by double-clicking to select it and then dragging the mouse from the right border of the field.

5. Set the length of the field by selecting it and then changing the value as appropriate in the third field of the Field Control Ribbon.

6. Name the field by selecting it and then enter the name of the field in the first field of the Field Control Ribbon.

Figure 24.4 Panel editor after adding the first few fields.

Image

The next set of fields is for display only, and no data may be keyed into them. These fields are added to the screen in the same manner as those described earlier except now you must set a field attribute to indicate that the data is display only. This setting prevents the user from keying any data into the field. The field names and lengths follow:

Address-Line-1 X(50) Address-Line-2 X(50) City X(40) State-Or-Country X(20) Postal-Code X(15) Home-Phone X(20) Work-Phone X(20) Other-Phone X(20) Add the fields to the panel as described in the earlier steps. After specifying the name of each field, click the Protection Type icon. The fourth field of the field control ribbon is a drop-down box. Select the down arrow in the field and then choose the Display Only option for the field. You do not want users to tab into or key anything in these fields. Your panel should now resemble Figure 24.5.

Figure 24.5 Panel editor after adding display-only fields.

Image

Scroll the display window down a bit so that you can add the remaining display fields. The three date fields are next. Add them in the manner described above. sp2 knows about date fields and date formatting. Place MM/DD/YYYYY where the Picture clause would normally go, in the third field of the Field Control Ribbon. Click the Input Type icon and use the fourth field of the Field Control Ribbon to select Date as the field type.

Name the fields as follows: Start-Date, Last-Rent-Paid-Date, and Next-Rent-Due-Date. Don’t neglect to set the protection type on these fields to Display Only. The panel should now resemble Figure 24.6.

The final two display-only entry fields to add are the Rent-Amount and Consignment-Percent fields. Use the same method to add these two fields. However, in the Picture field for the Rent-Amount, enter Z,ZZZ.99, and for Consignment-Percent enter ZZ9. Click the Input Type icon and select Numeric as the input type. The panel should now resemble Figure 24.7. Don’t forget to enter the field names.

Figure 24.6 Panel editor after adding dates.

Image

Figure 24.7 Panel editor—panel nearly complete.

Image

Finally, it is time to add some push buttons. This program can perform several operations: Read Random Number, Read Random Name, Read Next Number, and Read Next Name. In addition, Clear or Exit are valid operations. Rather than add a button for each read function, add a drop-down box that allows the user to select the desired function.

Scroll the panel down a little so that you can add a drop-down box. Follow these steps to add the field.

1. Click the Combination Box icon.

2. Position the field immediately under Rent: by clicking once to place the field.

3. Type in the field name Operation-Type in the first field of the Field Control Ribbon.

4. Change the Picture clause to X(18).

5. The second field of the Field Control Ribbon contains the text that is to appear in the drop-down list. Use a comma to separate the items. The first item is repeated because it is to appear by default, and the following items are all of the items that may appear. Change the text to read as follows: Read Random Number, Read Random Number, Read Random Name, Read Next Number, Read Next Name.

Image

You must be very careful in your spelling. If an entry is not spelled properly, it may not show up in the display. Also, make sure you change the Picture clause to X(18) before entering the text; otherwise, it will be truncated.

Your panel now should resemble Figure 24.8.

Figure 24.8 Panel editor after adding the drop-down list.

Image

To complete the panel definition, you need to add three push buttons to the panel. One is Read, the next is Clear, and the final one is Exit. Follow these steps to add the buttons to your panel. You complete panel should resemble Figure 24.9.

1. Click the Push Button icon.

2. Place the button next to the drop-down box that you just added by positioning the mouse and clicking.

3. Change the text that appears on the button by typing Read in the second field of the Field Control Ribbon, where OK appears by default. Press Enter to accept the change.

4. sp2 detects push buttons as if they were function keys or other special keys. To assign a value to a button that can be detected in your program, click in the third field of the Field Control Ribbon. Then press F2 to activate a feature called Easy Key. The code for the next keystroke you make is entered into the field for you. When you press the F3 key, 317 appears in the field.

5. Change the name of the push button to Read, by typing Read into the first field of the Field Control Ribbon.

6. Repeat these steps to add push buttons for Clear and Exit to the right of the Read button. Use the F4 key as the Easy Key value for Clear and F5 for Exit. Name the buttons Clear and Exit.

Figure 24.9 Panel editor—completed panel.

Image

To save your work, select File and then Save. Panels are saved into panel files that may contain more than one panel. When you click Save, you are prompted for a filename. Enter Chapt24.Pan for the panel filename. Then click Open. (Under Windows 3.1, click OK.) Choose Yes when asked whether you want to create the file. Type in Chapt24a as the panel name and then click OK.

COBOL sp2 needs to generate a Copybook for use in your program and, in fact, generates a skeleton program for your use as a starting point. This skeleton contains the bare basics required for the interface with sp2 to function. This program is generated in the directory where sp2 was installed, which is SPFJ3224 under Windows 95, 98, and NT and SPFJ1624 under Windows 3.1.

To generate these files, select File and then click Generate.

You may now close the sp2 panel editor window. When asked whether you want to save your work, click Yes.

Modifying the Generated Program Before changing the program, become familiar with it. The generated program has a file extension of CBL rather than COB. The Fujitsu COBOL compiler recognizes either extension as a COBOL source file. Review Listing 24.1.

Listing 24.1 SP2 Generated Program

000001 IDENTIFICATION DIVISION. 000002 PROGRAM-ID. chapt24a. 000003 000004* TITLE - Tenant Display Program 000005* DESCRIPTION - Tenant Display Program 000006 000007 ENVIRONMENT DIVISION. 000008 CONFIGURATION SECTION. 000009 SOURCE-COMPUTER. IBM-PC. 000010 OBJECT-COMPUTER. IBM-PC. 000011 000012 DATA DIVISION. 000013 WORKING-STORAGE SECTION. 000014 000015 COPY “sp2.cpy”. 000016 000017 COPY “chapt24a.cpy”. 000018 000019 PROCEDURE DIVISION. 000020 MAINLINE. 000021****************** 000022* MAINLINE LOGIC * 000023****************** 000024 PERFORM PROC-OPEN-FILE 000025 MOVE LOW-VALUES TO chapt24a-DATA 000026 MOVE “chapt24a” TO chapt24a-NEXT-PANEL 000027 MOVE “y” TO chapt24a-NEW-WINDOW 000028 MOVE LOW-VALUES TO chapt24a-FIELDS 000029 MOVE LOW-VALUES TO chapt24a-COLRS 000030 MOVE LOW-VALUES TO chapt24a-TYPES 000031 PERFORM PROC-CON-chapt24a 000032 PERFORM PROC-CLOSE-WINDOW 000033 PERFORM PROC-CLOSE-FILE 000034 PERFORM PROC-END-SESSION 000035 STOP RUN 000036 . 000037 000038 PROC-OPEN-FILE. 000039****************

000040* OPEN SP2 FILE * 000041****************

000042 MOVE LOW-VALUES TO SP2-FI-DATA 000043 MOVE “C:\SPFJ3224\chapt24.pan” TO SP2-FI-NAME 000044 CALL “SP2” USING SP2-OPEN-FILE SP2-FILE-DEF 000045 . 000046 000047 PROC-CON-chapt24a. 000048****************** 000049* CONVERSE PANEL * 000050****************** 000051 CALL “SP2” USING SP2-CONVERSE-PANEL chapt24a-CONVERSE-DATA 000052 MOVE LOW-VALUE TO chapt24a-NEW-WINDOW 000053 . 000054 000055 PROC-CLOSE-WINDOW. 000056************************ 000057* CLOSE CURRENT WINDOW * 000058************************ 000059 CALL “SP2” USING SP2-CLOSE-WINDOW SP2-NULL-PARM 000060 . 000061 000062 PROC-CLOSE-FILE. 000063********************** 000064* CLOSE CURRENT FILE * 000065********************** 000066 CALL “SP2” USING SP2-CLOSE-FILE SP2-NULL-PARM 000067 . 000068 000069 PROC-END-SESSION. 000070******************

000071* END SP2 SESSION * 000072******************

000073 CALL “SP2” USING SP2-END-SESSION SP2-NULL-PARM 000074 . Image

The case (upper versus lower) used for the COBOL statements and variable names in the generated code is not quite what you are used to seeing in these lessons. Remember that for the COBOL statements themselves, COBOL is not case sensitive, and it does not matter whether the letters are in upper-or lowercase.

The Proc-Open-File Paragraph makes a call to sp2 to open the panel file that is used by the program.

Proc-Con-Chapt24a is used to “converse” with the panel and thus the user. When the Converse-Panel call is made to sp2, sp2 handles the interaction between the user and the panel. When the user clicks one of the buttons or closes the window, control returns to your program. Based on the values of the fields returned, the program can take appropriate action.

The first time a panel is conversed, it must be displayed in a new window. Use the following code:

000027 MOVE “y” TO chapt24a-NEW-WINDOW The value “y” is lowercase and is case sensitive when passed to sp2. Notice in line 52 that Low-Values is moved to this field. This step prevents a new window from being created the next time the panel is displayed.

When exiting the program, sp2 must be called for three purposes: first to close the window that is currently open, handled by the PROC-CLOSE-WINDOW Paragraph; second to close the panel file, handled by the PROC-CLOSE-FILE Paragraph; and last to perform any necessary housekeeping and unload the sp2 program from memory, handled by the PROC-END-SESSION Paragraph.

Working-Storage contains two Copybooks. The first, sp2.Cpy, holds fields and values that sp2 uses. The second is generated by sp2 (Listing 24.2) and includes data to manipulate the fields that your panel uses.

Image

The sp2 generated Copybook contains many items that are used internally by sp2, but are not directly referenced in the program. The Copybook in Listing 24.2 is an abbreviated version showing only fields with which you are concerned.

Listing 24.2 SP2 Generated Copybook

000001******************************** 000002* parameter for CONVERSE-PANEL * 000003* parameter for GET-INPUT * 000004******************************** 000005 01 chapt24a-CONVERSE-DATA. 000006 05 chapt24a-RET-CODE 000007 PIC S9(4) COMP-5. 000029 05 chapt24a-DATA. 000030******** chapt24a-IP-NUM-DATA ******** 000031 10 chapt24a-KEY 000032 PIC S9(4) COMP-5. 000033 88 chapt24a-Read-HIT 000034 VALUE 317. 000035 88 chapt24a-Clear-HIT 000036 VALUE 318. 000037 88 chapt24a-Exit-HIT 000038 VALUE 319.

000114******** chapt24a-OP-VAR-DATA ******** 000115 05 chapt24a-FIELDS. 000116 10 chapt24a-Number 000117 PIC X(0008). 000118 10 chapt24a-Last 000119 PIC X(0025). 000120 10 chapt24a-First 000121 PIC X(0015). 000122 10 chapt24a-Middle 000123 PIC X(0010). 000124 10 chapt24a-Address-Line-1 000125 PIC X(0050). 000126 10 chapt24a-Address-Line-2 000127 PIC X(0050). 000128 10 chapt24a-City 000129 PIC X(0040). 000130 10 chapt24a-State-Or-Country 000131 PIC X(0020). 000132 10 chapt24a-Postal-Code 000133 PIC X(0015). 000134 10 chapt24a-Home-Phone 000135 PIC X(0020). 000136 10 chapt24a-Work-Phone 000137 PIC X(0020). 000138 10 chapt24a-Other-Phone 000139 PIC X(0020). 000140 10 chapt24a-Start-Date 000141 PIC 9(0008). 000142 10 chapt24a-Last-Rent-Paid-Date 000143 PIC 9(0008). 000144 10 chapt24a-Next-Rent-Due-Date 000145 PIC 9(0008). 000146 10 chapt24a-Rent-Amount 000147 PIC 9(04)V9(02). 000148 10 chapt24a-Consignment-Percent 000149 PIC 9(003). 000150 10 chapt24a-Operation-Type 000151 PIC X(0018). When you examine this listing, start by noticing the 88 levels defined in lines 33 through 38. The program checks these conditional fields to determine which button the user selected.

The second set of important fields starts at line 115. These fields display the user data and are the fields by which you communicate with the user.

The next step in creating your program is to add the specific logic you need to perform the functions. Start by adding the Select and FD for the dealer file. In the Select, because the program is not in the \TYCOBOL directory, specify the full filename of the dealer file. Add Select, FD, Open, and Close statements for the file.

When you open the file \SPFJ3224\Chapt24a.Cbl with Programming Staff, you receive a warning message about line numbers being invalid. This message appears because the generated code has no line numbers. Answer Yes to the question and let the COBOL editor assign the line numbers in the program.

Make sure to specify the whole path to the dealer file in the Select statement. Because the program does not run from the \Tycobol directory, you need to provide the full path information.

000013 Select Dealer-File Assign to “\Tycobol\Dealer.Dat” 000014 Organization Indexed 000015 Access Dynamic 000016 Record Key Dealer-Number 000017 Alternate Record Key Dealer-Name 000018 File Status Dealer-Status. When inserting the code for the file access, you will find several places where error messages should be displayed. You should not use the Display statement within a GUI program. Instead, use the facility provided to display a message box. COBOL sp2 accomplishes this by using a special Call to display the message box:

000064 MOVE LOW-VALUES TO SP2-MS-DATA 000065 MOVE “b” TO SP2-MS-ICON 000066 MOVE “File Error” TO SP2-MS-TITLE 000067 MOVE “o” TO SP2-MS-BUTTON 000068 MOVE 1 TO SP2-MS-LINE-CNT 000069 String “Error Opening Dealer File” 000070 Dealer-Status 000071 Delimited by Size 000072 Into Sp2-Ms-Text 000073 End-String 000074 Call “SP2” Using Sp2-Display-Message Sp2-Message-Data The SP2-MS-ICON field contains a value that corresponds to the value of the icon to appear in the message box. Valid values are “b” for bang, (the Exclamation point), “s” for the Stop sign, “i” for Information, and “q” for Question. The SP2-MS-TITLE field contains the title for the message box. SP2-MS-BUTTON indicates the type of push button or buttons to be displayed for termination of the message box. “o” is OK, “y” is Yes/No, “n” is No/Yes, and “r” is Retry. The SP2-MS-LINE-CNT is the number of lines into which your message is split. For the purposes of this book, you always use 1. SP2-MS-TEXT is the error message text. The Call to sp2 using the parameters shown will display a message box, warning the user of the error.

After inserting the Select, FD, file Open, and file Close statements, it’s time to code the steps necessary to perform the functions. You need to set up a repeating processing loop. This loop will converse the panel, return to the program, and take appropriate action based on the values returned by sp2. Then the loop is repeated. Two conditions terminate the loop. First, the user clicks the Exit button. Second, the user selects the Close option by clicking the X in the upper-right corner under Windows 95/98 or NT, or the user double-clicks in the upper-left corner under Windows 3.1. One of these conditions is checked by testing the conditional item, Chapt24a-Exit-Hit. This condition is coded under a data value named Chapt24a-Key. This field has the value associated with the reason that sp2 returned to your program. The SP2.Cpy Copybook includes a set of fields that assist you in detecting which key or activity occurred that caused sp2 to return to your program. The key value associated with closing the window is SP2-KEY-CLOSE.

The main logic in the program revolves around the Proc-Con-Chapt24a Paragraph. It is the one modified to handle the testing and performing of the various conditions. Walk through the entire program, examining each area and the steps required to perform the operations. The full listing of the program is shown in Listing 24.3.

Listing 24.3 Final Dealer Display Program

000001 @OPTIONS MAIN,TEST 000002 IDENTIFICATION DIVISION. 000003 PROGRAM-ID. chapt24a. 000004 000005* TITLE - Tenant Display Program 000006* DESCRIPTION - Tenant Display Program 000007 000008 ENVIRONMENT DIVISION. 000009 CONFIGURATION SECTION. 000010 SOURCE-COMPUTER. IBM-PC. 000011 OBJECT-COMPUTER. IBM-PC. 000012 Input-Output Section. 000013 File-Control. 000014 Select Dealer-File Assign to “\Tycobol\Dealer.Dat” 000015 Organization Indexed 000016 Access Dynamic 000017 Record Key Dealer-Number 000018 Alternate Record Key Dealer-Name 000019 File Status Dealer-Status. Notice the use of the full path to the Dealer.Dat file. Because this program will not be executed from that directory, specifying the full path allows the program to find the data file.

000020 DATA DIVISION. 000021 File Section. 000022 FD Dealer-File. 000023 01 Dealer-Record. 000024 03 Dealer-Number Pic X(8). 000025 03 Dealer-Name. 000026 05 Last-Name Pic X(25). 000027 05 First-Name Pic X(15). 000028 05 Middle-Name Pic X(10). 000029 03 Address-Line-1 Pic X(50). 000030 03 Address-Line-2 Pic X(50). 000031 03 City Pic X(40). 000032 03 State-or-Country Pic X(20). 000033 03 Postal-Code Pic X(15). 000034 03 Home-Phone Pic X(20). 000035 03 Work-Phone Pic X(20). 000036 03 Other-Phone Pic X(20). 000037 03 Start-Date Pic 9(8). 000038 03 Last-Rent-Paid-Date Pic 9(8). 000039 03 Next-Rent-Due-Date Pic 9(8). 000040 03 Rent-Amount Pic 9(4)V99. 000041 03 Consignment-Percent Pic 9(3). 000042 03 Filler Pic X(50). 000043 WORKING-STORAGE SECTION. 000044 01 Dealer-Status Pic X(2) Value Spaces. 000045 88 Dealer-Success Value “00” Thru “09”. 000046 01 Error-Message Pic X(60) Value Spaces. 000047 COPY “sp2.cpy”. 000048 000049 COPY “chapt24a.cpy”. 000050 01 Date-Reverse-Area. 000051 03 Date-YYYYMMDD Pic 9(8). 000052 03 Date-YYYYMMDD-X Redefines Date-YYYYMMDD. 000053 05 Date-YYYY Pic 9(4). 000054 05 Date-MM Pic 9(2). 000055 05 Date-DD Pic 9(2). 000056 03 Date-MMDDYYYY Pic 9(8). 000057 03 Date-MMDDYYYY-X Redefines Date-MMDDYYYY. 000058 05 Date-MM Pic 9(2). 000059 05 Date-DD Pic 9(2). 000060 05 Date-YYYY Pic 9(4). 000061 PROCEDURE DIVISION. 000062 MAINLINE. 000063****************** 000064* MAINLINE LOGIC * 000065****************** 000066 PERFORM PROC-OPEN-FILE 000067 MOVE LOW-VALUES TO chapt24a-DATA 000068 MOVE “chapt24a” TO chapt24a-NEXT-PANEL 000069 MOVE “y” TO chapt24a-NEW-WINDOW 000070 MOVE LOW-VALUES TO chapt24a-FIELDS 000071 MOVE LOW-VALUES TO chapt24a-COLRS 000072 MOVE LOW-VALUES TO chapt24a-TYPES 000073 Perform Open-File 000074 If not Dealer-Success 000075* message box display! 000076 MOVE LOW-VALUES TO SP2-MS-DATA 000077 MOVE “b” TO SP2-MS-ICON 000078 MOVE “File Error” TO SP2-MS-TITLE 000079 MOVE “o” TO SP2-MS-BUTTON 000080 MOVE 1 TO SP2-MS-LINE-CNT 000081 String “Error Opening Dealer File ” 000082 Dealer-Status 000083 Delimited by Size 000084 Into Sp2-Ms-Text 000085 End-String 000086 Call “SP2” Using Sp2-Display-Message Sp2-Message-Data A message box is shown instead of a Display statement.

000087 Else 000088* there is no reason to perform these if the open fails 000089 PERFORM PROC-CON-chapt24a 000090 PERFORM PROC-CLOSE-WINDOW 000091 Perform Close-File 000092 End-if 000093 PERFORM PROC-CLOSE-FILE 000094 PERFORM PROC-END-SESSION 000095 STOP RUN 000096 . 000097 Open-File. 000098 Open Input Dealer-File 000099 . 000100 Close-File. 000101 Close Dealer-File 000102 . 000103 PROC-OPEN-FILE. 000104****************

000105* OPEN SP2 FILE * 000106****************

000107 MOVE LOW-VALUES TO SP2-FI-DATA 000108 MOVE “C:\SPFJ3224\chapt24.pan” TO SP2-FI-NAME 000109 CALL “SP2” USING SP2-OPEN-FILE SP2-FILE-DEF 000110 . 000111 000112 PROC-CON-chapt24a. 000113****************** 000114* CONVERSE PANEL * 000115****************** 000116 Perform With Test After Until 000117 Chapt24a-Key = Sp2-Key-Close or 000118 Chapt24a-Exit-Hit 000119 CALL “SP2” USING SP2-CONVERSE-PANEL chapt24a-CONVERSE-DATA 000120 MOVE LOW-VALUE TO chapt24a-NEW-WINDOW 000121 Perform Determine-Action 000122 End-Perform 000123 . The Determine-Action Paragraph checks the return fields from the Call to sp2 and performs the appropriate action based on those values.

000124 Determine-Action. 000125 Evaluate True 000126 When Chapt24a-Exit-Hit 000127 When Chapt24a-Key = Sp2-Key-Close 000128 Continue The Continue coded here works because the Perform statement is checking for these values after performing this routine. These two conditions cause the processing loop to terminate.

000129 When Chapt24a-Read-Hit 000130 Evaluate Chapt24a-Operation-Type 000131 When “Read Random Number” 000132 Perform Read-Random-Number 000133 When “Read Random Name” 000134 Perform Read-Random-Name 000135 When “Read Next Number” 000136 Perform Read-Next-Number 000137 When “Read Next Name” 000138 Perform Read-Next-Name 000139 End-Evaluate If the user presses the Read button, the program evaluates the value selected in the drop-down list box to determine which type of Read is desired. The appropriate action is performed based on the value of the field.

000140 When Chapt24a-Clear-Hit 000141 Initialize Chapt24a-Fields 000142 Move “Read Random Number” To Chapt24a-Operation-Type The Clear button causes the fields controlled by sp2 to be initialized. The reason for moving Read Random Number back into the Chapt24a-Operation-Type is that the act of initializing the field erases its value and prevents the field from functioning properly.

000143 When Other 000144 Continue 000145 End-Evaluate 000146 . 000147 Read-Random-Number. 000148 Move Chapt24a-Number to Dealer-Number 000149 Read Dealer-File 000150 Invalid Key 000151 String “Error on Random Read Number ” 000152 Dealer-Status 000153 Delimited by Size 000154 Into Error-Message 000155 End-String 000156 Perform Show-Error-Message Show-Error-Message is a common routine that displays the text in Error-Message in a Windows message box.

000157 Not Invalid Key 000158 Perform Fill-Panel-Data 000159 End-Read 000160 . 000161 Read-Random-Name. 000162 Move Chapt24a-Last To Last-Name 000163 Move Chapt24a-First To First-Name 000164 Move Chapt24a-Middle To Middle-Name 000165 Read Dealer-File Key Dealer-Name 000166 Invalid Key 000167 String “Error on Random Read Name ” 000168 Dealer-Status 000169 Delimited by Size 000170 Into Sp2-Ms-Text 000171 End-String 000172 Perform Show-Error-Message 000173 Not Invalid Key 000174 Perform Fill-Panel-Data 000175 End-Read 000176 . 000177 Read-Next-Number. 000178 Move Chapt24a-Number to Dealer-Number 000179 Start Dealer-File Key > Dealer-Number 000180 Invalid Key 000181 String “Start Error Number ” 000182 Dealer-Status 000183 Delimited by Size 000184 Into Error-Message 000185 End-String 000186 Perform Show-Error-Message 000187 End-Start 000188 If Dealer-Success 000189 Read Dealer-File Next 000190 At End 000191 Move “End of File, Read by Number” To Error-Message 000192 Perform Show-Error-Message 000193 Not At End 000194 Perform Fill-Panel-Data 000195 End-Read 000196 End-if 000197 . 000198 Read-Next-Name. 000199 Move Chapt24a-Last To Last-Name 000200 Move Chapt24a-First To First-Name 000201 Move Chapt24a-Middle To Middle-Name 000202 Start Dealer-File Key > Dealer-Name 000203 Invalid Key 000204 String “Start Error Name ” 000205 Dealer-Status 000206 Delimited by Size 000207 Into Error-Message 000208 End-String 000209 Perform Show-Error-Message 000210 End-Start 000211 If Dealer-Success 000212 Read Dealer-File Next 000213 At End 000214 Move “End of File, Read by Name” To Error-Message 000215 Perform Show-Error-Message 000216 Not At End 000217 Perform Fill-Panel-Data 000218 End-Read 000219 End-if 000220 . Fill-Panel-Data moves the data from the record that was just retrieved to the fields that are passed to sp2 for displaying the data on the panel.

000221 Fill-Panel-Data. 000222 Move Dealer-Number To Chapt24a-Number 000223 Move Last-Name To Chapt24a-Last 000224 Move First-Name To Chapt24a-First 000225 Move Middle-Name To Chapt24a-Middle 000226 Move Address-Line-1 To Chapt24a-Address-Line-1 000227 Move Address-Line-2 To Chapt24a-Address-Line-2 000228 Move City To Chapt24a-City 000229 Move State-or-Country To Chapt24a-State-or-Country 000230 Move Postal-Code To Chapt24a-Postal-Code 000231 Move Home-Phone To Chapt24a-Home-Phone 000232 Move Work-Phone To Chapt24a-Work-Phone 000233 Move Other-Phone To Chapt24a-Other-Phone 000234 Move Start-Date To Date-MMDDYYYY 000235 Move Corresponding Date-MMDDYYYY-X To Date-YYYYMMDD-X 000236 Move Date-YYYYMMDD To Chapt24a-Start-Date 000237 Move Last-Rent-Paid-Date To Date-MMDDYYYY 000238 Move Corresponding Date-MMDDYYYY-X To Date-YYYYMMDD-X 000239 Move Date-YYYYMMDD To Chapt24a-Last-Rent-Paid-Date 000240 Move Next-Rent-Due-Date To Date-MMDDYYYY 000241 Move Corresponding Date-MMDDYYYY-X To Date-YYYYMMDD-X 000242 Move Date-YYYYMMDD To Chapt24a-Next-Rent-Due-Date When a field is defined to sp2 as a date field, the assumed format is YYYYMMDD, or Year, Month, Day. Because the data in the Dealer.Dat file is stored in MMDDYYYY format, the date must be rearranged before being moved to the display fields.

000243 Move Rent-Amount To Chapt24a-Rent-Amount 000244 Move Consignment-Percent To Chapt24a-Consignment-Percent 000245 . 000246 Show-Error-Message. 000247 MOVE LOW-VALUES TO SP2-MS-DATA 000248 MOVE “b” TO SP2-MS-ICON 000249 MOVE “File Error” TO SP2-MS-TITLE 000250 MOVE “o” TO SP2-MS-BUTTON 000251 MOVE 1 TO SP2-MS-LINE-CNT 000252 Move Error-Message To Sp2-Ms-Text 000253 Move Spaces To Error-Message 000254* Spaces Are Moved into Error-Message is preparation of the next 000255* String statement that will occur using the field. 000256 Call “SP2” Using Sp2-Display-Message Sp2-Message-Data 000257 . 000258 PROC-CLOSE-WINDOW. 000259************************ 000260* CLOSE CURRENT WINDOW * 000261************************ 000262 CALL “SP2” USING SP2-CLOSE-WINDOW SP2-NULL-PARM 000263 . 000264 000265 PROC-CLOSE-FILE. 000266********************** 000267* CLOSE CURRENT FILE * 000268********************** 000269 CALL “SP2” USING SP2-CLOSE-FILE SP2-NULL-PARM 000270 . 000271 000272 PROC-END-SESSION. 000273******************

000274* END SP2 SESSION * 000275******************

000276 CALL “SP2” USING SP2-END-SESSION SP2-NULL-PARM 000277 . The program compiles normally. However, to link the program you need to include the Sp2.Lib file provided with COBOL sp2. Perform the following steps to link Chapt24a.

1. In the WINLINK window, for the first link file enter \SPFJ3224\Chapt24a.Obj. (Under Windows 3.1, use \SPFJ1624\Chapt24a.Obj). Click Add.

2. Then for the next link file, in the same place that you just entered the program object name, enter \SPFJ3224\SP2.Lib. (Use the appropriate directory if using Windows 3.1.) Click Add.

3. Then click OK to link the program. Under Windows 3.1, click Build.

When you run the program, it should display a window that looks like Figure 24.10. Experiment with the operation of the program.

Figure 24.10 Chapt24a—display when the program is run.

Image

This small demonstration only begins to touch on the features of COBOL sp2 and a GUI with COBOL. If you are interested in further GUI programming, please read the help file—COBOL sp2 Online Users Guide—that comes with COBOL sp2. It is the complete user’s manual.

The Future of COBOL COBOL has a vibrant present and a bright future. The COBOL standards committee is actively working on the next version of COBOL. This new version promises to build on the present strengths of COBOL to make the language that has been used since the dawn of business computing, robust, stable, and useable well into the twenty-first century.

One expected feature is built-in validations using a new verb, Validate, which will simplify the coding of date validations and the like. Another new feature will specify a standard for COBOL program recursion. File and record locking, used in multiuser environments, are being standardized. Currently, COBOL vendors provide different methods of handling these situations. Numeric fields are being expanded from 18 digits to 31 digits, which should eliminate any need to use imprecise floating-point math.

One of COBOL’s strengths has always been its capability to accurately handle financial transactions without relying on the inaccuracies inherent in floating-point arithmetic.

Several changes in the COBOL language will yield even greater portability. Some complex mathematical operations produce different results on different compilers. In the next COBOL standard, the programmer will be able to specify the use of a set of arithmetic rules that will provide predictable and identical results across the different compilers. The capability to read backward through an Indexed or Relative file is being standardized. Most compiler vendors already have a method to accomplish the read, but each differs slightly from the others.

One of the largest changes evident in the next COBOL standard is object orientation. The new COBOL standard will provide COBOL with this very powerful programming method, designed to support easy reuse of code. The COBOL version of object-oriented programming promises to be a very clean and reliable implementation.

Although it may be several years yet before the standard is approved and implemented by the different COBOL compiler vendors, the language remains in wide use today with a rich feature set that makes development a joy. COBOL has been and continues to be a strong performer in business-related programming.

What should your next COBOL programming book be? For a more advanced view of COBOL, try COBOL: Unleashed! (ISBN: 0-672-31254-9; Jon Wessler et al.).

Summary I would like to thank you for taking the time and energy to work your way through Sams Teach Yourself COBOL in 24 Hours. I hope that you join me in finding COBOL to be a strong, rich, and interesting programming language. No matter what your interest in COBOL, I sincerely hope that this book is your first step in a strong relationship with this historically colorful language and its very bright future. Welcome to the world of computer programming, fellow COBOL programmer!

Fair Use Sources

COBOL: COBOL Fundamentals, COBOL Inventor - COBOL Language Designer: 1959 by Howard Bromberg, Norman Discount, Vernon Reeves, Jean E. Sammet, William Selden, Gertrude Tierney, with indirect influence from Grace Hopper, CODASYL, ANSI COBOL, ISO/IEC COBOL; Modern COBOL - Legacy COBOL, IBM COBOL, COBOL keywords, COBOL data structures - COBOL algorithms, COBOL syntax, Visual COBOL, COBOL on Windows, COBOL on Linux, COBOL on UNIX, COBOL on macOS, Mainframe COBOL, IBM i COBOL, IBM Mainframe DevOps, COBOL Standards, COBOL Paradigms (Imperative COBOL, Procedural COBOL, Object-Oriented COBOL - COBOL OOP, Functional COBOL), COBOL syntax, COBOL installation, COBOL containerization, COBOL configuration, COBOL compilers, COBOL IDEs, COBOL development tools, COBOL DevOps - COBOL SRE, COBOL data science - COBOL DataOps, COBOL machine learning, COBOL deep learning, COBOL concurrency, COBOL history, COBOL bibliography, COBOL glossary, COBOL topics, COBOL courses, COBOL Standard Library, COBOL libraries, COBOL frameworks, COBOL research, Grace Hopper, COBOL GitHub, Written in COBOL, COBOL popularity, COBOL Awesome list, COBOL Versions. (navbar_cobol)


Cloud Monk is Retired (for now). Buddha with you. © 2005 - 2024 Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


sams_teach_yourself_cobol_in_24_hours_-_hour_24_the_graphical_user_interface.txt · Last modified: 2022/05/16 03:27 by 127.0.0.1