How to Compile and Run an AS/400 COBOL ILE/Inquiry Screen/
Database Retrieval/Display Screen program, EMPMSTINQ. (Rev. 08)

The purpose of this COBOL ILE program is to:

a. Write an Inquiry screen to a user workstation, requesting a database key.
b. Read an Inquiry screen from a user workstation, containing a database key.
c. Retrieve the corresponding database record from a relational database.
d. Display the requested database record back to the user workstation.
e. Repeat steps a. through d. - until the user presses function key F3.

Note: This documentation file is at www.patmoss.com/as400/howcobinq.htm.

See the actual COBOL and DDS source files, data records, and display screens at:

 1. COBOL source program  www.patmoss.com/as400/progs/empmstinq.cbl
 2. Database definition           www.patmoss.com/as400/progs/empmstp.dds
 3. Database data records     www.patmoss.com/as400/progs/empmstp.dta
 4. Display screens layout     www.patmoss.com/as400/progs/empinq.dsp
 5. Display screens tests        www.patmoss.com/as400/progs/empinq.scn

Three source files are needed:

a. the source COBOL program EMPMSTINQ,
    which displays an inquiry screen, EMPPMT,
    retrieves a database record from EMPMSTP,
    and displays a database screen EMPFLDS
b. the source database file, EMPMSTP
c. the source display file, EMPINQ
     which contains the two display screens
     EMPPMT and EMPFLDS

And there are three corresponding object
files, EMPMSTINQ, EMPMSTP, and EMPINQ,
which are actually used to execute the
program, store the database records,
and display the two workstation screens.

The detailed program steps are as follows:

a. Display an inquiry screen on the user workstation,
    (via object display file EMPINQ, format EMPPMT)
    prompting for an Employee Number (5 digit number).
b. When the user enters an Employee Number and presses Enter,
    the program retrieves from a database (EMPMSTP)
    a record with the corresponding Employee Number.
c. If the record is found in the database, the program
    displays two lines (via object display file EMPINQ,
    format EMPFLDS): Employee Name and Employee Salary.
d. If the record is not found in the database, the program
    displays an error message line "EMPL NUMBER NOT FOUND".
e. After either c. or d., the program waits for input
    from screen a. (which is still displayed at the top
    of the screen display).
f. After any screen, if the user presses function key F3
    (instead of pressing the Enter key), program execution
    ends and control is returned to the AS/400 oper system.

A. The AS/400 files needed
     The actual files on the AS/400 for EMPMSTINQ are as follows:

1a. COBOL source program member EMPMSTINQ
      Directory QSYS/AS580, file QCBLSRC, member EMPMSTINQ, type CBLLE.

      All of my COBOL source programs are stored, as members of
      the physical file QSYS/AS580/QCBLSRC. So, this COBOL source
      program will be stored as member QSYS/AS580/QCBLSRC(EMPMSTINQ).
  
      The CL command to create/edit/view member names in this file is
      "WRKMBRPDM AS580/QCBLSRC". This means "Work with Members
      using the Program Development Manager".
 
      For full onscreen prompting, key in "WRKMBRPDM" and press F4.
 
      When PDM is running and its initial screen is displayed:

      Initially, to create the new member, press function key F6.
      Then enter the program name "EMPMSTINQ", the file type
      "CBLLE", and press the Enter key.
  
      All member names are displayed on the screen. Scroll down
      to the member name "EMPMSTINQ". Then key in "2" to edit
      this member, or "5" to display this member.
 
      To scroll to the bottom of the file, key in "*BOT" and press Enter.
      To scroll back to the top of file,     key in "*TOP" and press Enter.
 
      When you are done - press function key F3 to return to the Main menu.
 
      Notes: "CBLLE" means "COBOL Integrated Language Environment".
                    "CL" means "an AS/400 Command Language" command.
 
1b. COBOL object program file EMPMSTINQ
      Directory QSYS/AS580, file EMPMSTINQ, type *PGM, attribute CBLLE.
 
      When a COBOL source program is compiled with no errors,
      the AS/400 creates an equivalent object program file,
      in a different directory, with the same name.
 
      All of my object program files are stored in root directory
      QSYS/AS580. So, the object program file for source program
      EMPMSTINQ will be stored as QSYS/AS580/EMPMSTINQ.
 
      To view all object file names in this root directory, key 
      in the CL command "DSPLIB AS580". One of the object names
      displayed will be EMPMSTINQ, with type *PGM and attrib CBLLE.
  
      To execute this object program, key in the CL command
      "CALL AS580/EMPMSTINQ". See step 7. below.

2a. Physical database definition file EMPMSTP
      Directory QSYS/AS580, file QDDSSRC, member EMPMSTP, type PF.

      All of my Physical and Logical database definition files
      are stored, as members of the physical file QSYS/AS580/QDDSSRC.
      So, this Physical database definition file will be stored as
      QSYS/AS580/QDDSSRC(EMPMSTP).
 
      The CL command to create/edit/view member names in this file
      is "WRKMBRPDM AS580/QDDSSRC".
 
      For full onscreen prompting, key in "WRKMBRPDM" and press F4.
 
      When PDM is running and its initial screen is displayed:
 
      Initially, to create the new member, press function key F6.
      Then enter the file name "EMPMSTP", the file type "PF", and
      press the Enter key.
 
      All member names are displayed on the screen. Scroll down
      to the member name "EMPMSTP". Then key in "2" to edit
      this member, or "5" to display this member.
 
      To scroll to the bottom of the file, key in "*BOT" and press Enter.
      To scroll back to the top of file,     key in "*TOP" and press Enter.
 
      When you are done - press function key F3 to return to the Main menu.
 
2b. Object database file EMPMSTP (database schema only)
      Directory QSYS/AS580, file EMPMSTP, type *FILE, attribute PF.

      When a DDS source database definition member is compiled with
      no errors, the AS/400 creates an equivalent object database file
      (schema), in a different directory, with the same name.
 
      All of my object database files are stored in the root directory
      QSYS/AS580. So, the object database file for source database
      definition member EMPMSTP will be stored as QSYS/AS580/EMPMSTP.
 
      To view all object names in this root directory, key in
      the CL command "DSPLIB AS580". One of the object names
      displayed will be EMPMSTP, with type *FILE and attrib PF.
 
      To view file field definitions, key in "DSPFFD AS580/EMPMSTP".

2c. Object database file EMPMSTP (database data records only)
      Directory QSYS/AS580, file EMPMSTP, type *FILE, attribute PF.

      Once an object database file has been created, we can add
      data records to the corresponding data portion of this
      database object.
 
      To add data records, we use the "Data File Utility", DFU.
 
      The CL command to view/add/change/delete data records in 
      an object database file is "STRDFU". 
      
      Then choose option "5. Update data using temporary program".
 
      Next, follow the prompts to enter the data fields for each
      new data record. Repeat to enter as many data records as
      you wish.
 
      When you are done - press function key F3 to return to the Main menu.

      To view the database data records, key in "DSPPFM AS580/EMPMSTP".

3a. Source display definition file EMPINQ
      Directory QSYS/AS580, file QDDSSRC, member EMPINQ, type DSPF.

      All of my display definition files are stored, as members of the
      physical file QSYS/AS580/QDDSSRC. So, this display definition file
      will be stored as QSYS/AS580/QDDSSRC(EMPINQ).
 
      The CL command to create/edit/view member names in this file
      is "WRKMBRPDM AS580/QDDSSRC".
 
      For full onscreen prompting, key in "WRKMBRPDM" and press F4.
 
      When PDM is running and its initial screen is displayed:
 
      Initially, to create the new member, press function key F6.
      Then enter the file name "EMPINQ", the file type "DSPF", and
      press the Enter key.
  
      All member names are displayed on the screen. Scroll down
      to the member name "EMPINQ". Then key in "2" to edit this
      member, or "5" to display this member.

      To scroll to the bottom of the file, key in "*BOT" and press Enter.
      To scroll back to the top of file,     key in "*TOP" and press Enter.

      There are two records (i.e., screens) defined for the display
      definition file EMPINQ, as follows:

      o "EMPPMT"  -- the Employee Number Inquiry screen
      o "EMPFLDS" -- the Employee Fields Display screen

      When you are done - press function key F3 to return to the Main menu.
 
3b. Object display file EMPINQ (schema)
      Directory QSYS/AS580, file EMPINQ, type *FILE, attribute DSPF.

      When a DDS source display definition member is compiled with
      no errors, the AS/400 creates an equivalent object display file
      (schema), in a different directory, with the same name.
 
      All of my object display files are stored in the root directory
      QSYS/AS580. So, the object display file for source display
      definition member EMPINQ will be stored as QSYS/AS580/EMPINQ.
 
      To view all object names in this root directory, key in
      the CL command "DSPLIB AS580". One of the object names
      displayed will be EMPINQ, with type *FILE and attrib DSPF.
  
      To view file field definitions, key in "DSPFFD AS580/EMPINQ".

3c. Object display file EMPINQ (display file screen)
      Directory QSYS/AS580, file EMPINQ, type *FILE, attribute PF.
 
      The CL command to view/test display screens for an object
      display file is "STRSDA". 
      
      Then choose option "3. Test display files".
 
      Next, choose "Record to be tested" = "EMPPMT" and press Enter key.
      You will see the Employee Number Inquiry screen.
      When you are done - press function key F3.
 
      Next, choose "Record to be tested" = "EMPFLDS" and press Enter key.
      You will see the Employee Fields Display screen.
      When you are done - press function key F3.

4. Output queue
    Directory QSYS/AS580, file PATOUTQ, type *OUTQ

    All of my compilation output reports and execution output
    reports are stored in the output queue QSYS/AS580/PATOUTQ.

    To view all file names in this output queue, key in
    the CL command "WRKOUTQ AS580/PATOUTQ".

    The oldest queued files will be at the top of the list.
    And the newest queued files will be at the bottom (i.e.,
    at the end) of the list.

    For full onscreen prompting, key in "WRKOUTQ" and press F4.

    This output queue contains:
    
    o the compilation output report for source program EMPMSTINQ
       (see steps 5./6.)
    o the compilation output report for source database file EMPMSTP
       (see steps 8./9.)
    o the compilation output report for source display file EMPINQ
       (see steps 10./11.)

B. The AS/400 commands needed
     The actual AS/400 instructions to compile and run EMPMSTINQ are:

5. To compile the source program EMPMSTINQ
    Directory QSYS/AS580, file QCBLSRC, member EMPMSTINQ, type CBLLE.

    Key in "WRKMBRSRC AS580/QCBLSRC" and press Enter.

    All member names in QSYS/AS580/QCBLSRC are displayed
    on the screen.

    Scroll down in the list to the source program name EMPMSTINQ.

    To compile this source member, key in "14" on the left side 
    and press Enter.

    Then press function key F3 - to return to the Main menu.

    Note: After a successful compilation, the AS/400 will create
               a compilation output report in the output queue
               QSYS/AS580/PATOUTQ, and the object program file 
               QSYS/AS580/EMPMSTINQ in the directory QSYS/AS580.

6. To view the output report from the compilation from 5.
    Key in "WRKOUTQ AS580/PATOUTQ" and press Enter.

    All output queue member names in PATOUTQ are displayed
    on the screen.

    Scroll down in the list to EMPMSTINQ (the last item in the list).

    Note: If the batch compilation is still in process, press
                function key F5 to Refresh the screen display. Repeat
                this operation until the Status changes from "OPN" to
                "RDY".

    To view this compilation output report, key in "5" on the left
    side and press Enter.

    To scroll to the bottom of the file, key in "*BOT" and press Enter.
    To scroll back to the top of file,     key in "*TOP" and press Enter.

    When you are done - press function key F3 to return to the Main menu.

7. To execute the object program QSYS/AS580/EMPMSTINQ
    Key in "CALL AS580/EMPMSTINQ" and press Enter.

    This will display an initial screen DSPFMT of EMPINQ
    on your screen.

    Enter a five-digit Employee Number and press the Enter key.

    This will display the EMPFLDS screen of EMPINQ
    on your screen.

    Note: There are nine valid test Employee Numbers to choose
                from, 11111 through 99999.

    When you are done - press function key F3 to return to the Main menu.

    Note: Be sure to compile the database file and enter test
               data (see steps 8./9. below), and be sure to compile
               the display file (see steps 10./11. below) - before
               executing the object program EMPMSTINQ in step 7.

8. To compile the source database definition file EMPMSTP
    Directory QSYS/AS580, file QDDSSRC, member EMPMSTP, type PF.

    Key in "WRKMBRSRC AS580/QDDSSRC" and press Enter.

    All member names in QSYS/AS580/QDDSSRC are displayed
    on the screen.

    Scroll down in the list to the source program name EMPMSTP.

    To compile this source member, key in "14" on the left side 
    and press Enter.

    Then press function key F3 - to return to the Main menu.

    Note: After a successful compilation, the AS/400 will create
               a compilation output report in the output queue
               QSYS/AS580/PATOUTQ, and the object database file 
               QSYS/AS580/EMPMSTP in the directory QSYS/AS580.

9. To view the output report from the compilation from 8.
    Key in "WRKOUTQ AS580/PATOUTQ" and press Enter.

    All output queue member names in PATOUTQ are displayed
    on the screen.

    Scroll down in the list to EMPMSTP (the last item in the list).

    Note: If the batch compilation is still in process, press
                function key F5 to Refresh the screen display. Repeat
                this operation until the Status changes from "OPN" to
                "RDY".

    To view this compilation output report, key in "5" on the left
    side and press Enter.

    To scroll to the bottom of the file, key in "*BOT" and press Enter.
    To scroll back to the top of file,     key in "*TOP" and press Enter.

    When you are done - press function key F3 to return to the Main menu.

10. To compile the source display definition file EMPINQ
      Directory QSYS/AS580, file QDDSSRC, member EMPINQ, type DSPF.

      Key in "WRKMBRSRC AS580/QDDSSRC" and press Enter.

      All member names in QSYS/AS580/QDDSSRC are displayed
      on the screen.

      Scroll down in the list to the source display file name EMPINQ.

      To compile this source member, key in "14" on the left side 
      and press Enter.

      Then press function key F3 - to return to the Main menu.

      Note: After a successful compilation, the AS/400 will create
                 a compilation output report in the output queue
                 QSYS/AS580/PATOUTQ, and the object display file 
                 QSYS/AS580/EMPINQ in the directory QSYS/AS580.

11. To view the output report from the compilation from 10.
      Key in "WRKOUTQ AS580/PATOUTQ" and press Enter.

      All output queue member names in PATOUTQ are displayed
      on the screen.

      Scroll down in the list to EMPINQ (the last item in the list).

      Note: If the batch compilation is still in process, press
                  function key F5 to Refresh the screen display. Repeat
                  this operation until the Status changes from "OPN" to
                  "RDY".

      To view this compilation output report, key in "5" on the left
      side and press Enter.

      To scroll to the bottom of the file, key in "*BOT" and press Enter.
      To scroll back to the top of file,     key in "*TOP" and press Enter.

      When you are done - press function key F3 to return to the Main menu.

12. To sign off the AS/400, key in "90" and press Enter.

Isn't using the AS/400 fun? :)