home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 11 / CDACTUAL11.iso / cdactual / demobin / share / os2 / VPREVAL / DATAPROC._ / FINDCUST < prev    next >
Encoding:
Text File  |  1994-01-13  |  1.8 KB  |  72 lines

  1. /*******************************/
  2. /* Find a customer information */
  3. /*******************************/
  4. Arg window
  5. ret=0
  6.  
  7. call sqldbs 'START USING DATABASE dbsample IN SHARED MODE';
  8. if (SQLCA.SQLCODE <> 0) then do
  9.     response=VpMessageBox(window,TITLE,'START USING DATABASE Error :  SQLCODE = ' SQLCA.SQLCODE)
  10.     return SQLCA.SQLCODE
  11. end
  12.  
  13. /* Create The SQL Select Statement  */
  14. prep_string = "SELECT ",
  15.    "CUST_CUSTOMER_ID, ",
  16.    "CUST_NAME, ",
  17.    "CUST_COMPANY, ",
  18.    "CUST_ADDRESS, ",
  19.    "CUST_CITY, ",
  20.    "CUST_STATE, ",
  21.    "CUST_ZIP, ",
  22.    "CUST_COUNTRY, ",
  23.    "CUST_PHONE  ",
  24.    "FROM userid.customer ",
  25.    " WHERE CUST_CUSTOMER_ID = " || cust.customer_id;
  26.  
  27. /* Get cursor ready to access data */
  28. call sqlexec 'DECLARE c1 CURSOR FOR s1';
  29.  
  30. call sqlexec 'PREPARE s1 FROM :prep_string';
  31. if ( SQLCA.SQLCODE <> 0) then do
  32.    response=VpMessageBox(window,TITLE,'PREPARE STATEMENT Error.'SQLCA.SQLMSG)
  33.    ret = 1
  34. end
  35. else do
  36.    call sqlexec 'OPEN c1';
  37.  
  38.    /* Retrieve Data From The Cursor And Display It  */
  39.    if (SQLCA.SQLCODE = 0) then do
  40.  
  41.       cmd_string = "FETCH c1 INTO ",
  42.          ":cust.customer_id, ",
  43.          ":cust.name, ",
  44.          ":cust.company, ",
  45.          ":cust.address, ",
  46.          ":cust.city, ",
  47.          ":cust.state, ",
  48.          ":cust.zip, ",
  49.          ":cust.country, ",
  50.          ":cust.phone"
  51.  
  52.       call sqlexec cmd_string;
  53.  
  54.       if ( SQLCA.SQLCODE <> 0) then do
  55.          ret = 1
  56.          response=VpMessageBox(window,TITLE,'Error finding customer.'SQLCA.SQLMSG)
  57.       end
  58.    end
  59.  
  60. end
  61.  
  62. /* close the cursor */
  63. call sqlexec 'CLOSE c1';
  64.  
  65. call sqldbs 'STOP USING DATABASE';
  66. if (SQLCA.SQLCODE <> 0) then do
  67.     response=VpMessageBox(window,TITLE,'STOP USING DATABASE Error :  SQLCODE = ' SQLCA.SQLCODE)
  68.     return SQLCA.SQLCODE
  69. end
  70.  
  71. return ret
  72.