home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / db22re.zip / DISPTB.CMD < prev    next >
OS/2 REXX Batch file  |  1993-03-10  |  3KB  |  91 lines

  1. /*
  2.  ┌──────────────────────────────────────────────────────────────────┐
  3.  │  Name       : disptb.cmd                                         │
  4.  │  Purpose    : display the "sample staff" table                   │
  5.  │  Platform   : DB2/2                                              │
  6.  │  Author     : Jeff Fisher                                        │
  7.  │               IBM Toronto Development Lab                        │
  8.  │  Disclaimer : This "sample" code is for demonstrations only, no  │
  9.  │               warrenties are made or implied as to correct       │
  10.  │               function. You should carefully test this code in   │
  11.  │               your own environment before using it.              │
  12.  │                                                                  │
  13.  └──────────────────────────────────────────────────────────────────┘
  14. */
  15.  
  16.  
  17. Main:
  18.     call Start_Using
  19.  
  20.     stmtbuf = 'select * from staff order by id'
  21.     call SQLEXEC 'PREPARE s1 FROM :stmtbuf'
  22.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  23.  
  24.     call SQLEXEC 'DECLARE c1 CURSOR FOR s1'
  25.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  26.  
  27.     call SQLEXEC 'OPEN c1'
  28.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  29.  
  30.     do until SQLCA.SQLCODE \=0
  31.         call SQLEXEC 'FETCH c1 INTO :id,',
  32.                                    ':name    :n_name,',
  33.                                    ':dept    :n_dept,',
  34.                                    ':job     :n_job,',
  35.                                    ':years   :n_years,',
  36.                                    ':salary  :n_salary,',
  37.                                    ':comm    :n_comm'
  38.         if SQLCA.SQLCODE = +100 then leave
  39.         if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  40.  
  41.         if n_name   <0 then name   = ' '
  42.         if n_dept   <0 then dept   = ' '
  43.         if n_job    <0 then job    = ' '
  44.         if n_years  <0 then years  = ' '
  45.         if n_salary <0 then salary = ' '
  46.         if n_comm   <0 then comm   = ' '
  47.  
  48.         say '****************************'
  49.         say 'Identification: ' id
  50.         say '          Name: ' name
  51.         say '    Department: ' dept
  52.         say '           Job: ' job
  53.         say '         Years: ' years
  54.         say '        Salary: ' salary
  55.         say '    Commission: ' comm
  56.         say '****************************'
  57.         pause
  58.     end
  59.  
  60.  
  61. EndProg:
  62.     call SQLEXEC 'CLOSE c1'
  63.  
  64.     call Stop_Using
  65.  
  66.     exit
  67.  
  68.  
  69. ErrorSQL:
  70.     call beep 220,1000
  71.     say
  72.     say '        >>>  SQL has returned a fatal condition code'
  73.     say '             SQLCODE       = ' SQLCA.SQLCODE
  74.     say '             MSG           = ' SQLMSG
  75.     say
  76.     pause
  77.     signal EndProg
  78.  
  79.  
  80. Start_Using:
  81.     call SQLEXEC 'CONNECT TO SAMPLE IN SHARED MODE'
  82.     if SQLCA.SQLCODE \=0 then signal ErrorSQL
  83.     return
  84.  
  85.  
  86. Stop_Using:
  87.     call SQLEXEC 'CONNECT RESET'
  88.     if SQLCA.SQLCODE \=0 then signal ErrorSQL
  89.     return
  90.  
  91.