home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXHLAPI.ZIP / REXTEST3.CMD < prev   
OS/2 REXX Batch file  |  1991-03-20  |  8KB  |  208 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*  REXHLAPI.DLL Test Procrdure                                       */
  4. /*                                                                    */
  5. /*  Author:   W. David Ashley                                         */
  6. /*  Date:     03/20/91                                                */
  7. /*  Version:  1.0                                                     */
  8. /*  Release:  1                                                       */
  9. /*                                                                    */
  10. /*  Notes:                                                            */
  11. /*    1. Requires OS/2 Extended Edition 1.2 REXX interpreter.         */
  12. /*    2. Requires REXHLAPI.DLL in the LIBPATH.                        */
  13. /*    3. Communications Manager should be running before beginning    */
  14. /*       this procedure.                                              */
  15. /*    4. Be sure to change the USERID and PASSWORD variables before   */
  16. /*       attempting to run this cmd. The host data set name should    */
  17. /*       also be modified (see main processing loop).                 */
  18. /*                                                                    */
  19. /*  Log:                                                              */
  20. /*    03/20/91 - Original issue.                                      */
  21. /*                                                                    */
  22. /**********************************************************************/
  23.  
  24. /* load REXHLAPI.DLL external function if not already loaded */
  25. if rxfuncquery('REXHLLAPI') then ,
  26.  call rxfuncadd 'REXHLLAPI','REXHLAPI', 'REXHLLAPI'
  27.  
  28. /* Setup */
  29. say 'Starting process.'
  30. userid = 'zzzzz'
  31. password = 'xxxxxx'
  32.  
  33. /* get Comm. Mgr. short session names */
  34. session_info = REXHLLAPI('Query_sessions')
  35. if length(session_info) < 13 then do
  36.   say 'No Comm. Mgr. sessions are active, canceling execution.'
  37.   exit
  38.   end
  39. j = 1
  40. session.0 = 0
  41. do i = 13 by 12 for (length(session_info) / 12) - 1
  42.   if i > length(session_info) then leave
  43.   session.j = substr(session_info, i, 1)
  44.   j = j + 1
  45.   session.0 = session.0 + 1
  46.   end
  47.  
  48. /* main processing */
  49. call logon
  50. say 'Started download.'
  51. dnldretc = 1
  52. do while dnldretc \= 0
  53.   dnldretc = downloadfile('c:\testfile.txt ' || mysession ||,
  54.    /* your dsn goes here */
  55.    ":'xxxxx.xxx.xxx(xxxxxx)' ascii crlf")
  56.   call waitforready
  57.   say 'Receive File Return Code =' dnldretc '.'
  58.   if dnldretc = 11 then do
  59.     say 'Host connection lost during file transfer.'
  60.     call logon
  61.     end
  62.   if dnldretc = 17 then do
  63.     say 'Host file does not exist.'
  64.     dnldretc = 0
  65.     end
  66.   end
  67. call logoff
  68.  
  69. /* Exit */
  70. say 'Finished all processing.'
  71. exit
  72.  
  73. /**********************************************************************/
  74. /**********************************************************************/
  75. /******************** REXX Functions are below ************************/
  76. /**********************************************************************/
  77. /**********************************************************************/
  78.  
  79. /**********************************************************************/
  80. /* Log on to TSO procedure                                            */
  81. /**********************************************************************/
  82.  
  83. logon:
  84.   do while tsologon() \= 0
  85.     say 'Logon failure, will try again.'
  86.     end
  87.   return
  88.  
  89. /**********************************************************************/
  90. /* TSO logon from VTAM procedure                                      */
  91. /**********************************************************************/
  92.  
  93. tsologon:
  94.   /* Find an unused session */
  95.   call tryconnect
  96.   do while mysession = -1
  97.     say 'All sessions active, will try again later.'
  98.     call REXHLLAPI 'Pause', 60
  99.     call tryconnect
  100.     end
  101.   say 'Connected to host.'
  102.   /* Set up the default session parameters */
  103.   call REXHLLAPI 'Set_Session_parms', 'SRCHFROM'
  104.   /* Send logon string to host */
  105.   call REXHLLAPI 'Sendkey', 'tso1 'userid',s3279m2'
  106.   call REXHLLAPI 'Sendkey', '@E' /* Enter */
  107.   call REXHLLAPI 'Pause', 20
  108.   if REXHLLAPI('Search_ps', '-OIDCARD', 1820) \= 0 then do
  109.     /* RACF screen now visible */
  110.     call REXHLLAPI 'Sendkey', password
  111.     call REXHLLAPI 'Sendkey', '@E' /* Enter */
  112.     readystatus = 0
  113.     do while readystatus = 0
  114.       call REXHLLAPI 'Pause', 10
  115.       if REXHLLAPI('Search_ps', 'ACF/VTAM DOMAIN', 1) \= 0 then do
  116.         say 'TSO session cancelled unexpectedly.'
  117.         return 1
  118.         end
  119.       if REXHLLAPI('Search_ps', 'READY', 1) \= 0 then readystatus = 1
  120.       if REXHLLAPI('Search_ps', ' *** ', 1840) \= 0 then do
  121.         if REXHLLAPI('Search_ps', 'READY', 1760) \= 0 then readystatus = 1
  122.         call REXHLLAPI 'Sendkey', '@E' /* Enter */
  123.         end
  124.       if REXHLLAPI('Search_ps', '-OIDCARD', 1820) \= 0 then do
  125.         say 'Your password has expired.'
  126.         exit
  127.         end
  128.       end
  129.     call REXHLLAPI 'Sendkey', '@C' /* Clear */
  130.     call REXHLLAPI 'Sendkey', 'term nobreak'
  131.     call REXHLLAPI 'Sendkey', '@E' /* Enter */
  132.     call waitforready
  133.     call REXHLLAPI 'Pause', 2
  134.     say 'Logged on to TSO.'
  135.     return 0
  136.     end
  137.   return 1
  138.  
  139. /**********************************************************************/
  140. /* Try Session Connect procedure                                      */
  141. /**********************************************************************/
  142.  
  143. tryconnect:
  144.   /* disconnect from ps so we don't stack connections */
  145.   disconretc = REXHLLAPI('Disconnect_ps')
  146.   if session.0 > 0 then do j = 1 to session.0
  147.     mysession = session.j
  148.     conretc = REXHLLAPI('Connect_ps', mysession)
  149.     if conretc = 0 then do
  150.       if REXHLLAPI('Search_ps', 'ACF/VTAM DOMAIN', 1) \= 0 then do
  151.          return
  152.          end
  153.       end
  154.     else disconretc = REXHLLAPI('Disconnect_ps')
  155.     end
  156.   mysession = -1
  157.   return
  158.  
  159. /**********************************************************************/
  160. /* Logoff of tso                                                      */
  161. /**********************************************************************/
  162.  
  163. logoff: procedure
  164.   call REXHLLAPI 'Sendkey', 'logoff'
  165.   call REXHLLAPI 'Sendkey', '@E' /* Enter */
  166.   say 'Logged off of TSO.'
  167.   disconretc = REXHLLAPI('Disconnect_ps')
  168.   call REXHLLAPI 'Pause', 20
  169.   return
  170.  
  171. /**********************************************************************/
  172. /*  Wait for READY procedure                                          */
  173. /**********************************************************************/
  174.  
  175. waitforready:
  176.   do while 1
  177.     if REXHLLAPI('Search_ps', 'ACF/VTAM DOMAIN', 1) \= 0 then call error
  178.     if REXHLLAPI('Search_ps', 'UNSUPPORTED FUNCTION', 1) \= 0 then call error
  179.     if REXHLLAPI('Search_ps', ' *** ', 1) \= 0 then do
  180.       call REXHLLAPI 'Sendkey', '@E' /* Enter */
  181.       call REXHLLAPI 'Pause', 10
  182.       end
  183.     if REXHLLAPI('Search_ps', 'READY', 1) \= 0 then return
  184.     call REXHLLAPI 'Pause', 4
  185.     end
  186.   end
  187.  
  188. /**********************************************************************/
  189. /*  Download a file procedure                                         */
  190. /**********************************************************************/
  191.  
  192. downloadfile:
  193.   arg dnldparm
  194.   call REXHLLAPI 'Disconnect_ps'
  195.   dretc = REXHLLAPI('Receive_File', dnldparm)
  196.   if dretc = 3 | dretc = 4 | dretc = 27 then dretc = 0
  197.   call REXHLLAPI 'Connect_ps', mysession
  198.   return dretc
  199.  
  200. /**********************************************************************/
  201. /*  Error procedure                                                   */
  202. /**********************************************************************/
  203.  
  204. error:
  205.   say 'TSO session cancelled unexpectedly.'
  206.   call logon
  207.   return
  208.