Hello World!

This document contains the following exercises:


Creating a Program

You will now write your first short program which displays "Hello World!". It will be stored in the library you have created previously.

Start of instruction setTo create a new program

  1. Make sure that you have logged on to the library named TUTORIAL.

  2. Invoke the Direct Command window and enter one of the following:

    EDIT PROGRAM
    E P

    System commands may be abbreviated. E P is the abbreviated form of EDIT PROGRAM.

    The program editor appears. It is currently empty.

    >> -----------Columns 001 072 <<  Program          Lines         User SAG      
    Command ===>                                       Mode   Struct Lib  TUTORIAL 
    ****** ****************************** top of data *****************************
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ''''''                                                                         
    ****** **************************** bottom of data ****************************
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          Help  Save  Exit  Run   Rfind Stow  -     +     Check Home  Undo  Canc

    Caution:
    Do not press ENTER now. When you press ENTER, you leave insert mode. To enter code, you then have to return to insert mode as follows: enter the line command I at the beginning of the line which contains the words "top of data" and press ENTER.

  3. Enter the following code in the program editor:

    * The "Hello world!" example in Natural.
    *
    DISPLAY "Hello world!"
    END /* End of program

    When you press ENTER twice after the last line of code has been added, insert mode is switched off.

    Comment lines start with an asterisk (*) followed by at least one blank or a second asterisk. When you forget to enter the blank or second asterisk, Natural assumes that you have specified a system variable; this will result in an error.

    If you want to insert empty lines in your program, you should define them as comment lines. This is helpful, if you want to access your program from different platforms (Windows, mainframe or Linux and Cloud). With the mainframe version of Natural, for example, the default is that empty lines are automatically deleted when you press ENTER.

    You can also insert comments at the end of a statement line. In this case, the comment starts with a slash followed by an asterisk (/*).

    The text that is to be shown in the output is defined with the DISPLAY statement. It is enclosed in quotation marks.

    The END statement is used to mark the physical end of a Natural program. Each program must end with END.

    When you press ENTER, it may happen that all of your lower-case characters are translated to upper-case characters. This behavior is defined in the editor profile (which is explained later).

Running a Program

The system command RUN automatically invokes the system command CHECK which checks the program code for errors. If no error is found, the program is compiled on the fly and then executed.

Notes:

  1. CHECK is also available as a separate command.
  2. Natural also provides the system command EXECUTE which uses the stowed version of your program (stowing a program is explained later in this tutorial). In contrast to this, the RUN command always uses your latest modifications to the program.

Start of instruction setTo run a program

  1. In the program editor's command line, enter one of the following:

    RUN
    R

    Note:
    In the program editor, you can press PF10 (Home) to place the cursor in the command line.

    When your code is syntactically correct, the output contains the text you have defined.

    MORE
    Page      1                                                  13-05-16  13:27:42
    
    
    Hello world!
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  2. Press ENTER to return to the program editor.

Correcting Program Errors

You will now create an error in your Hello World program and then run the program once more.

Start of instruction setTo correct an error

  1. Delete the second quotation mark in the line containing the DISPLAY statement.

  2. Run the program once more as described above.

    When the error is found, an error message is displayed.

    >> -----------Columns 001 072 <<  Program          Lines  4      User SAG
    Command ===> run                                   Mode   Struct Lib  TUTORIAL
    ****** ****************************** top of data ***************************** 
    000010 * The "Hello world!" example in Natural.                                 
    000020 *                                                                        
    000030 DISPLAY "Hello world!                                                    
    000040 END /* End of program                                                    
    +-------------------------- Error in File:          ---------------------------+
    ¦NAT0305 Text string must begin and end on the same line.                      ¦
    ¦             VVVVVVVVVVVVVVV                                                  ¦
    ¦0030 DISPLAY "Hello world!                                                    ¦
    +------------------------------------------------------------------------------+
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--- 
          Help  Save  Exit  Run   Rfind Stow  -     +     Check Home  Undo  Canc
  3. Correct the error in the window which displays the error message, that is: insert the missing quotation mark at the end of the line.

  4. Press ENTER to find the next error.

    In this case, no more errors are found and the output is shown.

  5. Press ENTER to return to the program editor.

Stowing a Program

When you stow a program, it is compiled and both source code and a generated program are stored in the Natural system file.

Like the RUN command, the system command STOW automatically invokes the CHECK command. A program is only stowed when it is syntactically correct.

Note:
If you want to save the changes to your program, even if the program contains a syntactical error (for example, if you want to suspend your work until the next day), you can use the system command SAVE. When a program is saved for the first time, you also have to specify a name. For example: SAVE HELLO.

Start of instruction setTo stow a program

  • In the program editor's command line, enter the following:

    STOW HELLO

    where "HELLO" is the name with which your program is to be stored.

    Note:
    When a program has already been given a name, it is sufficient to enter STOW in the command line (without a program name) or to press PF6.

Displaying Information about a Program

The LIST command is useful to find out whether only the source code or both source code and a generated program are available for an object.

Start of instruction setTo display information about a program

  1. In the program editor's command line, enter one of the following:

    LIST DIR HELLO
    L DIR HELLO

    The following screen appears. The information provided with Cataloged on is only available when the object has been stowed.

    >> -----------Columns 001 072 <<  Program HELLO    Lines  4      User SAG
    Command ===> list dir hello                        Mode   Struct Lib  TUTORIAL
    ****** ****************************** top of data ***************************** 
    +---------------------------- List Directory HELLO ----------------------------+
    ¦ Directory of Program HELLO                  Saved on ... 2009-06-30 16:37:00 ¦
    ¦ ---------------------------------------------------------------------------- ¦
    ¦ Library .... TUTORIAL   User-ID ...... SAG       Mode .. Structured          ¦
    ¦ OP-System .. SUN_SOLA                                                        ¦
    ¦ NAT-Ver .... V 6.3.7                                                         ¦
    ¦ Size ................................. 108 Bytes                             ¦
    ¦                                                                              ¦
    ¦ Directory of Program HELLO                  Cataloged on 2009-06-30 16:37:00 ¦
    ¦ ---------------------------------------------------------------------------- ¦
    ¦ Library .... TUTORIAL   User-ID ...... SAG       Mode .. Structured          ¦
    ¦ OP-System .. SunOS                           OP-Version ..5.8Generic_10852   ¦
    ¦ NAT-Ver .... V 6.3.7                                                         ¦
    ¦ Size ................................. 330 Bytes                             ¦
    ¦ Endian mode: Big                                                             ¦
    ¦                                                            ENTER to continue ¦
    +------------------------------------------------------------------------------+
                                                                                    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--- 
          Help  Save  Exit  Run   Rfind Stow  -     +     Check Home  Undo  Canc
  2. Press ENTER to return to the program editor.

Displaying the Content of the Current Library

The LIST command can also be used to display a list of all Natural objects in the current library. This is helpful, for example, if you decide at some point during this tutorial that you want to delete one or more of your Natural objects in order to start again from the very beginning.

Start of instruction setTo display a list of Natural objects

  1. In the program editor's command line, enter one of the following:

    LIST *
    L *

    The following window appears. It lists the program you have just created.

    >> -----------Columns 001 072 <<  Program HELLO    Lines  4      User SAG
    Command ===> l *                                   Mode   Struct Lib  TUTORIAL
    ****** ****************************** top of data *****************************
    000010 * The "Hello world!" example in Natural.                                
    000020 *                                                                       
    000030 DISPLAY "Hello world!"                                                  
    0+--------------------------------- List * * ---------------------------------+ 
    *¦ Cmd Name     Type        SM S/C Userid   SRC Date         GP Date          ¦ 
     ¦ --- -------- ----------- -- --- -------- ---------------- ---------------- ¦ 
     ¦ <DIRECT COMMAND>                                                           ¦ 
     ¦     HELLO    Program     S  S/C SAG      16:37 2009-06-30 16:37 2009-06-30 ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
     ¦                                                                            ¦ 
    E¦                                                                            ¦ 
     +----------------------------------------------------------------------------+
  2. To find out which commands are available, enter a question mark (?) in the Cmd column next to your program.

    The following window appears.

    +---------------------------+ 
    ¦ C Check                   ¦ 
    ¦ D Read                    ¦
    ¦ E Edit                    ¦ 
    ¦ L List                    ¦ 
    ¦ I List Dir                ¦ 
    ¦ H Hardcopy                ¦ 
    ¦ R Run                     ¦ 
    ¦ X Execute                 ¦ 
    ¦ S Stow                    ¦ 
    ¦ U Scratch                 ¦ 
    ¦ . End                     ¦ 
    +---------------------------+

    Note:
    Scratch is used to delete an object.

  3. Do not apply any changes right now. Press ESC to close the window without selecting any command.

  4. Press ESC once more to return to the program editor.

Setting the Editor Profile Options

When working with the Natural program editor, an editor profile can be defined per user. This tutorial uses the default settings of the editor profile named SYSTEM. Some important settings are mentioned below.

Start of instruction setTo check the editor profile options

  1. In the program editor's command line, enter the following:

    PROFILE

    The main menu of the editor profile appears.

    13:57:44         **** Program Editor Profile ****                    09.06.30  
                                Main Menu                                          
                                                                                   
      Profile Name ... SYSTEM                                                      
                                                                                   
                                                                                   
           _  Save                                                                 
                                                                                   
           _  Modify                                                               
                                                                                   
           _  Read                                                                 
                                                                                   
           _  Technical Info                                                       
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
    Command ===>                                                                   
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          Help        Exit  Modi  Save  Read  Tech                          Canc

    When a user-specific editor profile does not exist, the default profile SYSTEM is displayed. This default profile can be used to create a user-specific profile. When a user-specific profile exists already, it is displayed instead of the SYSTEM profile.

  2. Mark the option Modify and press ENTER.

    Or:
    Press PF4.

    The following screen appears.

    14:05:36          **** Program Editor Profile ****                   09.06.30  
                             Modify Defaults                                       
                                                                                   
      User ID ........ SYSTEM                                                      
                                                                                   
                                                                                   
           _  PA/PF-Keys                                                           
                                                                                   
           _  Commands                                                             
                                                                                   
           _  Find                                                                 
                                                                                   
           _  General                                                              
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
    Command ===>                                                                   
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          Help  Keys  Exit        Ctrl        Find  Genl                    Canc
  3. Mark the option Commands and press ENTER.

    The following screen appears.

    14:04:39             **** Program Editor Profile ****                09.06.30  
                              Modify Editor Defaults                               
                                                                                   
    User ID ....... SYSTEM                                                         
                                                                                   
                                                                                   
    aorder .............. OFF            hex ................. OFF                 
    autosave ............ OFF            justify ............. LEFT                
    caps ................ OFF            limit ............... OFF                 
    cols ................ OFF            log ................. OFF                 
    decimal character ... .              mask line ........... OFF                 
    empty ............... OFF            message line ........ ON                  
    escape .............. OFF            mso ................. ON                  
    escape character .... .              scroll mode ......... PAGE                
    fix ................. OFF            tabs ................ OFF                 
    fixlen .............. 48             tabulator character . ^                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
    Command ===>                                                                   
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          Help        Exit                                                  Canc

    Check the setting of the following options:

    • caps
      Specifies whether data are to be translated into upper case.

    • empty
      Specifies whether lines containing only space characters are to be deleted automatically.

    • escape
      Specifies whether the escape character is to be used to precede line commands.

    This tutorial assumes that the above options are set to "OFF".

  4. If "ON" is currently defined for any of the above options, overwrite it with "OFF".

  5. Press PF3 or enter EXIT in the command line.

  6. Press PF3 repeatedly until the main menu of the editor profile is shown again.

  7. When a user-specific profile has not yet been created, overwrite the profile name SYSTEM with your user ID.

    When a user-specific profile exists already, proceed with the next step.

  8. Mark the option Save and press ENTER.

    Or:
    Press PF5.

  9. Press PF3.

    Or:
    Enter EXIT in the command line.

    The program editor is shown again. Any new settings will now be used in the program editor.

You can now proceed with the next exercises: Database Access.