HP 3000 Manuals

Preparing and Using a Program [ COBOL/HP-UX Getting Started for the Series 700 and 800 ] MPE/iX 5.0 Documentation


COBOL/HP-UX Getting Started for the Series 700 and 800

Preparing and Using a Program 

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

   *   compiling - checking its syntax and producing intermediate code

   *   animating - testing and debugging it

   *   generating - producing an object program in native machine code

   *   running it

   *   linking - producing a single executable file containing the object
       program, plus the support modules it needs from the Micro Focus
       Run-Time Environment

Compiling 

   1.  Copy the source file tictac.cbl into one of your work directories.
       You will find this file in the directory containing the tutorial
       programs supplied with the COBOL system.  They are in subdirectory
       "demo" within the directory pointed to by the $COBDIR environment
       variable.

   2.  Enter the following command:

            cob -av tictac.cbl

       The explanation of this command line is:

       cob                   tells the system to check the syntax and
                             compile your source code.

       -                     indicates the start of the flags that you
                             set to control compilation.

       a                     is a flag that tells cob that you will be
                             using Animator to test the program.

       v                     is a flag that sets "verbose" mode, in which
                             cob displays messages to show progress.

       tictac.cbl            is the name of the program source file to
                             compile.  The Compiler looks for the file
                             tictac with the extension .cbl or .cob.

       You could in fact omit the "a" flag, as it is the default; we have
       included it here for clarity.

       The Compiler banner appears, including the version number of the
       COBOL system.  The Compiler then checks the source code for syntax
       errors and creates intermediate code, displaying a number of
       messages indicating its progress.  The system then outputs the
       intermediate code in the .int file, and extra information needed
       by the Animator in a .idy file.  When compiling is complete, the
       following message appears:

            Data=xxxxxxxxx Code=yyyyyyyyy

       This means the compilation produced an object program needing
       xxxxxxxxx bytes of data storage and yyyyyyyyy bytes of storage for
       Procedure Division code.

       You could run the .int program now, using cobrun.  However, there
       is a very powerful tool available for testing and debugging the
       logic of your program, and it's a good idea to use this tool next.

Animating 

Now use Animator to watch the source code executing.

Note:    Animator animates .int files; if it finds a .gnt file, it runs
         it without animation.  If you run through this sample session a
         second time, make sure you have no tictac.gnt file left from the
         previous time.

3.  Enter:

     anim tictac

The system displays the Animator banner, including the version number 
and copyright information, and then displays the Animator main menu
screen, shown in Figure 3-1  

	       Click here to view figure.
          Figure 3-1.  The Animator Screen 

This screen consists of four parts:

   *   the text area

   *   the information line

   *   the menu

   *   the message area

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.

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 area is below the menu, on the bottom line of your display,
and is where messages are usually displayed.

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

     perform with test after

The Animate main menu appears at the bottom of the screen.  It displays
an information line containing the program name Tictac, together with
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.

Controlling the Speed.   

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).  These modes of execution are described in the
following sections.

Stepping Through the Program.   

The first letter command on the Animate menu is Step.

4.  Press S to begin stepping through your program.

    The cursor is now positioned under the next executable statement:

         call clear-screen

5.  Press Step again twice.

    This positions the cursor on the DISPLAY statement and then executes
    the statement.

    This causes a brief display of the user screen in its current state.
    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 user screen briefly appears each time you
    execute a DISPLAY statement.

    The cursor then moves to the beginning of the statement:

         perform init

6.  Now press F2=view.

    The user screen appears showing the text displayed by the executed
    DISPLAY statement:

         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.

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

8.  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.

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.

9.   To start Go mode, press G.

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

10.  Press 7 to increase the speed.

	       Click here to view figure.
          Figure 3-2.  The Go Menu 

     This change in 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 by pressing a
     key between 0 and 9.

     Program execution halts when an ACCEPT statement is encountered.
     The system now pauses on the user screen after executing the ACCEPT
     statement on line 114 anticipating data entry.

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

     The system continues animation in Go mode at a speed of 7 and pauses
     after the next ACCEPT, displaying the user screen and prompting
     again for data entry.

12.  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
     program's screen.

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

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

     You can temporarily halt execution at any time.

14.  Press Escape.

     The message:

          Keyboard interrupt

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

Executing in Zoom Mode.   

15.  Now 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.

16.  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.
     The message:

          STOP RUN encountered with RETURN-CODE=+00000: use Escape to
          terminate

     appears at the bottom of the screen.

Exiting Animator.   

17.  Press Escape to terminate your Animator session.

     The message:

          Exit from animator? Y/N

     appears at the bottom of the screen.

18.  Press Y (Yes) to return to the operating system.

Generating Native Code 

Having animated the program, you will now want to convert it to optimized
native code in a .gnt file.

   1.  Enter:

            cob -uv tictac.cbl

       In this command line, all is as before, except:

       u       is a flag that tells cob to process the program through to
               producing dynamically loadable generated code.

               This time, cob invokes the Compiler and the Generator.
               The last message displayed comes from the Generator, and
               is similar to the Compiler's message giving data and code
               sizes, but also shows space taken by literals.

               Since you had already produced a tictac.int in your
               previous call of cob (see the section "Compiling" ,
               above), you could have omitted the Compiler step by
               specifying .int instead of .cbl.

Running 

2.  To run Tictac, enter:

         cobrun tictac

    You need not specify an extension, as cobrun will automatically look
    for the .gnt file.

    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!

    You could run the intermediate code instead by specifying an
    extension of .int (also, if cobrun does not find a .gnt file it will
    run the .int file).  The above call of cob to produce generated code
    would then be unnecessary.  However, although the difference is not
    apparent in a small program such as Tictac, generated code runs much
    faster than intermediate code.

Linking 

As an alternative to using cobrun, you can create an optimized .o file
and link it to form an executable file.

Note:    You can link your program only if you have a "C"/Operating
         System Development System installed on your machine.  This
         provides the system tools that cob needs, like ld, the system
         linker.

   1.  Enter:

            cob -xv tictac.cbl

       In this command line, all is as before, except:

       x       is a flag that tells cob to process the program all the
               way through to producing an executable file.

               This time cob invokes the Compiler, Generator, and UNIX
               system linker, one after the other.  The last thing
               displayed is a list headed "Entry points defined in
               module:  tictac.o", after which there may be a long pause
               before the operating system prompt appears.

               Since you had already produced a tictac.int in your
               previous call of cob (see the section "Compiling" ,
               above), you could have omitted the Compiler step here; if
               you had specified .int instead of .cbl, cob would have
               used the existing .int file and just invoked the Generator
               and Linker.  The end effect would have been the same.

Running the Linked Program 

2.  To run Tictac, simply enter:

         ./tictac

    The system runs the program.



MPE/iX 5.0 Documentation