PreviousInstalling Sample Session with Dialog SystemNext

Chapter 3: Sample Session

This tutorial session will help you become familiar with using the components of Server Express. Using the sample program Tictac (a Tic-Tac-Toe game, also known as Noughts and Crosses), you will learn the basic steps to edit, compile, animate, and run or link a program.

All the features covered are described in detail in the manuals.

Dialog System is covered in a separate tutorial, in the chapter Sample Session with Dialog System.


Note: Remember to consult the appendix UNIX Key Usage Chart to find out how the keys shown in this chapter map onto those you must use.


3.1 Preparing and Using a Program

This sample session illustrates all the essential steps in preparing an application for use in Server Express:

You do all these steps within the Server Express Development Environment.

See the section Packaging for details on how to prepare a program to run outside the Server Express system so you can deliver it to your users.

3.1.1 Entering Server Express

Use the Infomgr tool to locate the tictac.cbl demonstration program. Infomgr is described in the chapter Infomgr in your Utilities Handbook.

Before you use a demonstration program, we recommend you copy it to your own work directory to avoid the danger of other users working with it at the same time.

  1. Copy the source file tictac.cbl from its directory into a work directory using Infomgr, and make that directory your current working directory.

  2. Enter:
    sde

The Server Express Development Environment is loaded. It displays its main screen, as shown in Figure 3-1.



Figure 3-1: The Server Express Development Environment Screen

This screen consists of four parts:

The text area means the main body of the screen.

The menu, at the bottom of the screen, shows the functions available at this point. Each function has a function key (shown as Fnn=) associated with it; pressing the key activates the function. Many of the menus in the system have more functions than there is room for on the screen. On these menus, pressing Alt displays more functions (the Alt menu) and Ctrl displays yet more (the Ctrl menu).

Above the menu is the third part of the screen, the information line. This line contains a mixture of fixed and variable information. For example, the information line can contain the menu name, the name of the program you are working with, the status of the Insert, Caps, Num Lock and Scroll Lock keys, and toggle settings. A toggle is a key that selects between options.

The message/input area is below the menu, on the bottom line of your display. This is where the system displays messages and you enter information such as filenames.

At this point the text area contains the Server Express banner, which displays information about the new features in this release.

This format of screen is used in most of the Server Express tools. A function key can serve one of three purposes:

The Escape key on a menu usually leaves the menu and takes you back up to the one you invoked it from.

3.1.2 Getting Help

You can get Help on every menu by pressing F1=help.

  1. Press F1=help

    The text area is replaced by text. There is more information than fits on one screen, and if you press F1 again the next page appears. The information presented is relevant to the menu from which you start Help; here you see general information about Server Express and the main functions because you pressed F1 on the main menu.

  2. Press Space (or F1 if you are on the last page of help) to return to the main menu.

3.1.3 Editing

You're now going to start the COBOL Editor. This editor is designed especially for COBOL programs, although it can be used for any type of source file.

  1. Press F2=edit

    The work area clears and a new menu appears, shown in Figure 3-2.



    Figure 3-2: The COBOL Editor Main Menu

    The COBOL Editor enables you either to type in COBOL source, or to load in a file created previously. If you were creating a new program you would type it now. However, the source of Tictac is supplied on disk for you. You simply load it into the COBOL Editor, as described in the next step.

    Accessible from the main menu are two more menus - the Alternate menu and the Control menu - which you get to by pressing Alt and Ctrl. See the appendix UNIX Key Usage Chart for details on actual keystrokes required for these keys.

  2. Press F3=load file on the Alternate menu.

    The Load File menu appears. It includes a line on which to type the name of the file to load. The directory you are in is already displayed on this line.

  3. Enter:
    tictac

    You need not specify the extension .cbl; the COBOL Editor assumes .cbl if no extension is specified.

The source code is displayed with the cursor positioned under the first statement on line 1. The main menu of the COBOL Editor returns.

3.1.4 Compiling

You might have noticed that the Server Express main menu has keys for the Compile and Animate functions. However, you can also access these functions from within the COBOL Editor, and we will do it this way in this tutorial.

  1. From the COBOL Editor's main menu, press F2=COBOL once. Do not hold it down, as this would make it repeat.

    The COBOL menu appears.

  2. Press F2= compl /animate once.

    On this menu, F2 is a toggle selecting whether you will compile, animate, or both. Its setting is shown on the information line, and changes each time you press.

  3. Press F2= compl /anim until its setting is "Cmp+Anim".

  4. Press Enter to begin compiling.

    The COBOL Editor screen disappears. The Compiler checks the program for syntax errors and produces intermediate code.

The Compiler creates the intermediate code in a file with extension .int and produces extra information needed by the Animator in a .idy file. When it has finished the Animator screen appears.

Intermediate code can also be run without further preparation, using the Run option as described in the section Running.

3.1.5 Animating

The Animator screen is shown in Figure 3-3. You use Animator to watch the source code executing.



Figure 3-3: The Animator Screen

The Animate main menu appears at the bottom of the screen. It displays an information line containing the program name Tictac, and level, speed, Ins, Caps, Num and Scroll indicators. The next two lines contain the function and letter key options you use to control the way the program is animated.

You can execute your program in one of three modes: Step, Go and Zoom. When you execute your program in Step mode, you manually control the execution of each statement. In Go mode, you initially set the speed of execution, then watch as each statement is automatically executed. Zoom mode executes the entire program without displaying the source until it reaches the end of the program. You can interrupt it, or set a breakpoint where it will stop.

3.1.5.1 Stepping Through the Program

The source code is initially displayed with the cursor positioned under the first executable statement:

perform with test after

One of the letter commands on the Animate menu is Step.

  1. Press S to begin stepping through your program.

    The cursor is now positioned under the next executable statement:

    call clear-screen 
  2. Press Step.

    This executes the CALL statement, and leaves the cursor on the next statement.

  3. Press Step.

    This executes the DISPLAY statement, and leaves the cursor on the next statement.

  4. Press F2=view.

    The user screen is the screen displayed by the program itself, that is, the screen that would be seen by the user if you were running the program without Animator. The screen showing the source is called the Animator screen.

    The CALL statement executed a library routine that cleared the user screen, and the DISPLAY statement then displayed some text. You can now see the user screen with that text:

    To select a square type a number between 1 and 9

    You can use the view facility to view the user screen at any time during animation.

  5. Press any key to return to the Animator screen.

  6. Now execute the next three statements in the program by pressing Step three times.

    Each time you press Step another statement is executed, and you can see what is actually happening in the program.

3.1.5.2 Executing in Go Mode

In Go mode, your program is automatically executed at the speed you select, and you can watch exactly what is happening in the program.

  1. To start Go mode, press G.

    The Go menu shown in Figure 3-4 appears at the bottom of the screen as execution begins. The program is currently executing at a speed of 5, the default setting.



    Figure 3-4: The Go Menu

    The speed is displayed on the information line. You can set execution speed from either the Animate main menu or the Go menu. The range of speeds is from 0 to 9, with 0 the slowest speed. You can change this speed at any time during execution (except during an ACCEPT statement) by pressing a key between 0 and 9.

    Execution halts when an ACCEPT statement is reached. The system now pauses on the user screen after executing the ACCEPT statement on line 114. It is prompting you to enter data.

  2. Respond by typing N to indicate that you will be the one to start the game.

    The system continues animation in Go mode and pauses after the next ACCEPT, displaying the user screen and prompting again for data.

  3. Select square 9 by pressing 9 on your keyboard.

    This places an "X" in square 9 and resumes program execution in Go mode. Remember, you can press F2=view at any time to see the user screen.

  4. Experiment with pressing keys between 6 and 9 to make the program execute faster.

    Execution stops again when you are prompted to select another square. Notice that the system has placed a 0 in square 5.

  5. Press 8 to select the square and to resume execution.

  6. Press Escape.

    You can temporarily halt execution at any time except while the program is executing an ACCEPT statement. The message:

    Keyboard interrupt

    appears at the bottom of the screen. The cursor is positioned on the next executable statement.

3.1.5.3 Executing in Zoom Mode

  1. Press Z to begin execution in Zoom mode.

    The program resumes execution at full speed and displays only the user screen. Continue playing until the game is complete. Then the message:

    Play again?

    appears.

  2. Respond by typing N (No).

    The source code returns to the screen with the cursor positioned under STOP RUN, indicating that the program has completed execution.

3.1.5.4 Exiting Animator

To exit from Animator:

  1. Press Escape to terminate your Animator session.

    The message:

    Exit from animator? Y/N

    appears at the bottom of the screen.

  2. Press Y (Yes) to return to the COBOL Editor's main menu.

    The source listing again appears in the text area, ready for further editing should it be required.

  3. Press Escape to exit from the COBOL Editor.

    This returns you to the main menu of Server Express .

3.1.6 Generating Native Code

You can use the Generate option on the Server Express main menu to create a file with extension .gnt containing native machine code, which executes faster than intermediate code. The .gnt file can be run using the Run option as described in the section Running below.

To create tictac.gnt:

  1. Press F6=generate on the Server Express main menu.

    A menu appears enabling you to specify the program to compile. Because you have just been working with tictac, its name is already set there as default; and the default settings of the menu are what we want. So you do not type anything on this menu.

  2. Press Enter

    The system displays a banner identifying the Generator and some directives that Server Express has automatically set. The function finishes after just a few seconds.

You are then returned to the Server Express main menu .

3.1.7 Generating Callable Shared Objects

You can use the CSO option on the Server Express main menu to create a callable shared object file with the extension .so; this contains native machine code, which executes faster than intermediate code. Callable shared objects can be run using the Run option as described in the section Running below. Unlike .int and .gnt files, however, callable shared object can contain more than one COBOL program and can also contain other language programs, such as C and C++. Callable shared objects can also be linked with third party object files or shared libraries. This behavior is similar to system executables and shared libraries but differs from .int files and .gnt files, where each file corresponds to a single COBOL program.

To create tictac.so:

  1. Create the object file tictac.o as shown in the section Using the Linker.

  2. Press F7=CSO on the Server Express main menu.

    A menu appears enabling you to specify the program to compile. Because you have just been working with tictac, its name is already set there as default; and the default settings of the menu are what we want. So you do not type anything on this menu.

  3. Press Enter

    The system displays a banner identifying the Generator and some directives that Server Express has automatically set. The function finishes after just a few seconds.

You are then returned to the Server Express main menu .

3.1.8 Running

You run a program in the same way whether you are running intermediate code, generated code or callable shared objects.

To run a program:

  1. Press F6=run

    A menu appears enabling you to specify the program to be run and giving you access to various functions and options useful at this point. However, because you have just been working with tictac, its name is already set there as default; and the default settings of the menu are what we want. So you do not enter anything on this menu.

  2. Press Enter

    The system runs the program, which starts off by displaying the first message of the game on your screen. Have fun playing it; it can be beaten!

    At the end of the game, Tictac displays the message:

    Play again? 
  3. Press N for "No".

You are returned to the Server Express main menu .

3.1.9 Leaving Server Express

If you do not want to go on to the next part of the tutorial at the moment, exit from Server Express:

  1. Press Escape to leave the Server Express Development Environment

    Server Express displays a message asking you to confirm that you want to leave.

  2. Press Y for "Yes".

Server Express exits, and you are returned to the operating system.

3.2 Using the Linker

When your application is working you might want to make it independent of the Server Express system so you can distribute it for use on other binary-compatible machines. To do this you use the UNIX system linker, which can be accessed from the Server Express main menu.


Notes:


If you have left the Server Express Development Environment, load it by using the sde command as before. To link a tictac:

  1. Press F6=generate.

    The Generator menu appears as before. This time you use the Generator to produce an .o file instead of a .gnt file.

  2. If you closed the Server Express Development Environment and have just re-entered it, type:
    tictac

    but do not press Enter yet. If you remained in Server Express since the previous part of this sample session, the word tictac is already there.

  3. Press F6=gnt/object so that the word "object" appears on the status line.

  4. Press Enter.

    The program is generated, but this time an .o file is produced.

  5. Press F8=link.

    A menu appears enabling you to specify the program to be linked and giving you access to various functions and options useful at this point. Because you have just been working with tictac its name is already set there, with the extension .o assumed; and the default settings of the menu are what we want. So you do not enter anything on this menu.

  6. Press Enter.

    The command line that Server Express will pass to the system linker is displayed, and then linking begins. A list headed "Entry points defined in module: tictac.o" is displayed, after which there might be a pause before the linking finishes and you are returned to the Server Express main menu.

  7. Now exit from Server Express to the operating system, as above.

3.2.1 Running the Linked Program

To run the linked program, enter:

./tictac

The program now runs independently of the COBOL system and you can play the Tic-Tac-Toe game.

3.3 Some More Features

You have now learned how to perform the main task which Server Express facilitates - create, test, and run a program.

This part of the sample session examines some other commonly used features of Server Express which will improve your productivity.

3.3.1 Compiler Directives

Compiler directives enable you to control the way in which your source code is compiled.

The following example shows you how to use Compiler directives to change the syntax allowed by the Compiler, and the output it produces.

Load the Server Express Development Environment by using the sde command, and load the file tictac.cbl into the COBOL Editor as before.

To set the Compiler directives:

  1. Press F2=COBOL.

  2. Press F2=compl/animate.

  3. Ensure that "Compile" appears on the information line. If it doesn't, press F2=compl/anim until it does.

  4. Press F4=list until "List-Con" appears on the information line.

    This causes the source code to be listed on the screen, with any error messages.

  5. Press F10=directives

  6. Type the following directives at the prompt:
    osvs flag(osvs) list()

    Ensure that the bottom part of your display looks like Figure 3-5.

  7. You have entered three directives. The first two describe the language you want to test for: the OSVS directive means you want the OSVS reserved word list used, and the FLAG(OSVS) directive means you want any syntax that is not OSVS compatible to be indicated.

    The final directive, LIST, means you want the source listing that the Compiler produces sent to a file. The parentheses mean you want to use the default name, which is your program name with an extension of .lst, so this creates tictac.lst.



    Figure 3-5: The Directives Menu

  8. Press Enter to accept the directives and return to the COBOL menu.

  9. Press F9=directives to enable the directives you have just entered.

  10. Press Enter to start compiling the program.

Some messages are displayed, too quickly for you to read. With this indication that there could be something wrong, you can load the listing file you have created (tictac.lst) into the COBOL Editor at some future time to see what they are. In fact, the messages are indicating the lines of code that do not conform to OSVS syntax. These are not errors that prevent the creation of usable code, so you can go on to use Animator with the code again.

There are many different directives available, and this is just one way of setting them. See your Server Express User's Guide for more information about setting directives.

3.4 Other Features

This Sample Session chapter has introduced you to the most essential features of Server Express. There are many other useful tools and features described in your Server Express User's Guide and Utilities Handbook.


Copyright © 2000 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.

PreviousInstalling Sample Session with Dialog SystemNext