home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / calldll.zip / ASCFIXED.CMD next >
OS/2 REXX Batch file  |  1996-02-04  |  16KB  |  418 lines

  1. /**************************************************************************/
  2. /* This REXX command file contains examples of I/O on a fixed, ASCII      */
  3. /* Micro Focus indexed (VSAM) file.  It does several different types of   */
  4. /* I/O, including:                                                        */
  5. /*                                                                        */
  6. /*     1.  Open for input                                                 */
  7. /*         Read sequentially through a file                               */
  8. /*         Close                                                          */
  9. /*                                                                        */
  10. /*     2.  Open for input                                                 */
  11. /*         Position on a record                                           */
  12. /*         Read sequentially through the remainder of the file            */
  13. /*         Close                                                          */
  14. /*                                                                        */
  15. /*     3.  Open for I/O                                                   */
  16. /*         Write a new record                                             */
  17. /*         Close                                                          */
  18. /*                                                                        */
  19. /*     4.  Open for input                                                 */
  20. /*         Do a random read                                               */
  21. /*         Close                                                          */
  22. /*                                                                        */
  23. /*     5.  Open for I/O                                                   */
  24. /*         Rewrite an existing record                                     */
  25. /*         Close                                                          */
  26. /*                                                                        */
  27. /*     6.  Open for input                                                 */
  28. /*         Do a random read                                               */
  29. /*         Close                                                          */
  30. /*                                                                        */
  31. /*     7.  Open for I/O                                                   */
  32. /*         Delete an existing record                                      */
  33. /*         Close                                                          */
  34. /*                                                                        */
  35. /* Notes:  This command file is ready to run.  It does I/O on             */
  36. /*         ASCFIXED.DAT, which is an ASCII, fixed block, Micro Focus      */
  37. /*         indexed file.  This file is included in the INDEXIO.ZIP file.  */
  38. /*         If this file is not in the current directory, change the       */
  39. /*         VSAMFileName variable below to include the path.  For example: */
  40. /*                                                                        */
  41. /*             VSAMFileName = 'C:\FILES\ASCFIXED.DAT'                     */
  42. /*                                                                        */
  43. /*         This program opens the file, does the I/O, then closes the     */
  44. /*         file for each example.  This is done for illustrative purposes */
  45. /*         only.  Normally, you would open the file once, do all of the   */
  46. /*         I/O, then close the file.  Opening the file once would be much */
  47. /*         faster since the open operation takes a lot longer than any of */
  48. /*         the other I/O operations.                                      */
  49. /*                                                                        */
  50. /*         The examples in this command file set the ComArea prior to     */
  51. /*         performing I/O.  The ComArea tells the I/O program what type   */
  52. /*         of I/O you want to perform (open, read sequential, read        */
  53. /*         random, etc).  Here is an explanation of the ComArea fields:   */
  54. /*                                                                        */
  55. /*             Byte 1 - Call Code                                         */
  56. /*               0 - Open for input                                       */
  57. /*               Q - Open for I/O                                         */
  58. /*               2 - Random read                                          */
  59. /*               4 - Write or Rewrite                                     */
  60. /*               5 - Rewrite or Write                                     */
  61. /*               E - Erase                                                */
  62. /*               P - Position (greater than or equal to key)              */
  63. /*               1 - Read sequential (from beginning of file or last pos) */
  64. /*               9 - Close                                                */
  65. /*                                                                        */
  66. /*             Byte 2 - Return Code                                       */
  67. /*               0 - Request successfully processed                       */
  68. /*               9 - Attempting to read past end of file on seq read      */
  69. /*               B - Key definition block for the file is too big         */
  70. /*               F - File name not found                                  */
  71. /*               G - Error reading file header                            */
  72. /*               I - Invalid info passed in the ComArea                   */
  73. /*               N - Record not found on random read or erase             */
  74. /*               O - Error opening file name                              */
  75. /*               E - Other error                                          */
  76. /*                                                                        */
  77. /*             Bytes 3 through 102 (100 bytes total) - File Name          */
  78. /*                                                                        */
  79. /*             Byte 103 - F for fixed, or V for variable                  */
  80. /*                                                                        */
  81. /*             Bytes 104 through 203 (100 bytes total) - Record Key       */
  82. /*                                                                        */
  83. /*             Byte 204 - Y for EBCDIC file, anything else is ASCII file  */
  84. /*                                                                        */
  85. /*         The 4 call code (write new) and 5 (rewrite) are almost         */
  86. /*         interchangeable.  You can use either one to write a new record */
  87. /*         or to rewrite a record.  The 4 call code will first try to     */
  88. /*         write a new record.  If it fails, it will rewrite the record.  */
  89. /*         The 5 call code will first try to rewrite the record.  If it   */
  90. /*         fails, it will write a new record.  So you can use either      */
  91. /*         call code to write or rewrite, however, performance will be    */
  92. /*         a little better if you know whether the record already exists  */
  93. /*         and use the appropriate call code.                             */
  94. /*                                                                        */
  95. /*         The P call code positions on the record that is greater than   */
  96. /*         or equal to the key that you pass in.  Not only does it        */
  97. /*         position on the record, it also returns the record.  A         */
  98. /*         position changes the sequential pointer within the file.       */
  99. /*         After doing a position, sequential reads return the records    */
  100. /*         that come after the record that was positioned on.             */
  101. /**************************************************************************/
  102.  
  103. '@ECHO OFF'
  104.  
  105. VSAMFileName = 'ASCFIXED.DAT'
  106. VSAMFileName = LEFT(VSAMFileName, 100)
  107.  
  108. CALL L2_INIT_AND_LOAD_CALLDLL
  109.  
  110. CALL L2_READ_SEQUENTIAL
  111.  
  112. CALL L2_POSITION_AND_READ_SEQUENTIAL
  113.  
  114. CALL L2_WRITE
  115.  
  116. CALL L2_READ_RANDOM
  117.  
  118. CALL L2_REWRITE
  119.  
  120. CALL L2_READ_RANDOM
  121.  
  122. CALL L2_ERASE
  123.  
  124. CALL L2_UNLOAD_CALLDLL
  125.  
  126. EXIT 0
  127.  
  128. /********************************LEVEL 2 CODE********************************/
  129.  
  130. L2_INIT_AND_LOAD_CALLDLL:
  131.     CALL L3_LOAD_REXXUTIL
  132.  
  133.     CALL L3_CHECK_IF_ASCFIXED_FILE_EXISTS
  134.  
  135.     CALL L3_LOAD_CALLDLL
  136. L2_INIT_AND_LOAD_CALLDLL_EXIT:
  137.     RETURN
  138.  
  139. L2_READ_SEQUENTIAL:
  140.     CALL L3_DISPLAY_READ_SEQUENTIAL_MESSAGE
  141.  
  142.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  143.  
  144.     CALL L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE
  145.  
  146.     CALL L3_CLOSE_FILE
  147. L2_READ_SEQUENTIAL_EXIT:
  148.     RETURN
  149.  
  150. L2_POSITION_AND_READ_SEQUENTIAL:
  151.     CALL L3_DISPLAY_POSITION_AND_READ_MESSAGE
  152.  
  153.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  154.  
  155.     CALL L3_POSITION_ON_JOHN
  156.  
  157.     CALL L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE
  158.  
  159.     CALL L3_CLOSE_FILE
  160. L2_POSITION_AND_READ_SEQUENTIAL_EXIT:
  161.     RETURN
  162.  
  163. L2_WRITE:
  164.     CALL L3_DISPLAY_WRITE_MESSAGE
  165.  
  166.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  167.  
  168.     CALL L3_WRITE_A_RECORD_TO_VSAM_FILE
  169.  
  170.     CALL L3_CLOSE_FILE
  171. L2_WRITE_EXIT:
  172.     RETURN
  173.  
  174. L2_READ_RANDOM:
  175.     CALL L3_DISPLAY_READ_RANDOM_MESSAGE
  176.  
  177.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  178.  
  179.     CALL L3_READ_A_RECORD_FROM_VSAM_FILE
  180.  
  181.     CALL L3_CLOSE_FILE
  182. L2_READ_RANDOM_EXIT:
  183.     RETURN
  184.  
  185. L2_REWRITE:
  186.     CALL L3_DISPLAY_REWRITE_MESSAGE
  187.  
  188.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  189.  
  190.     CALL L3_REWRITE_A_RECORD_TO_VSAM_FILE
  191.  
  192.     CALL L3_CLOSE_FILE
  193. L2_REWRITE_EXIT:
  194.     RETURN
  195.  
  196. L2_ERASE:
  197.     CALL L3_DISPLAY_ERASE_RANDOM_MESSAGE
  198.  
  199.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  200.  
  201.     CALL L3_ERASE_A_RECORD_FROM_VSAM_FILE
  202.  
  203.     CALL L3_CLOSE_FILE
  204. L2_ERASE_EXIT:
  205.     RETURN
  206.  
  207. L2_UNLOAD_CALLDLL:
  208.     call CallDLLDropFuncs
  209. L2_UNLOAD_CALLDLL_EXIT:
  210.     RETURN
  211.  
  212. /********************************LEVEL 3 CODE********************************/
  213.  
  214. L3_LOAD_REXXUTIL:
  215.     IF RXFUNCQUERY('SYSLOADFUNCS') THEN DO
  216.         CALL RXFUNCADD 'SYSLOADFUNCS', 'REXXUTIL', 'SYSLOADFUNCS'
  217.         CALL SYSLOADFUNCS
  218.     END
  219. L3_LOAD_REXXUTIL_EXIT:
  220.     RETURN
  221.  
  222. L3_CHECK_IF_ASCFIXED_FILE_EXISTS:
  223.     call sysfiletree VSAMFileName,'file','f'
  224.     if file.0 = 0 then do
  225.         say
  226.         say strip(VSAMFileName) 'does not exits.  This file is included in'
  227.         say 'INDEXIO.ZIP.' strip(VSAMFileName) 'must be in the current directory,'
  228.         say 'or you can change the "VSAMFileName" variable in this command'
  229.         say 'file to include the path where' strip(VSAMFileName) 'resides.  For'
  230.         say 'example:'
  231.         say
  232.         say '    VSAMFileName = C:\FILES\ASCFILXED.DAT'
  233.         exit 9
  234.     end
  235. L3_CHECK_IF_ASCFIXED_FILE_EXISTS_EXIT:
  236.     RETURN
  237.  
  238. L3_LOAD_CALLDLL:
  239.     if RXFUNCQUERY('CallDLLLoadFuncs') then do
  240.         call RXFUNCADD 'CallDLLLoadFuncs', 'CALLDLL', 'CallDLLLoadFuncs'
  241.         call CallDLLLoadFuncs
  242.     end
  243. L3_LOAD_CALLDLL_EXIT:
  244.     RETURN
  245.  
  246. L3_DISPLAY_READ_SEQUENTIAL_MESSAGE:
  247.     say
  248.     say 'Hit enter to read' strip(VSAMFileName) 'sequentially.'
  249.  
  250.     parse pull junk
  251. L3_DISPLAY_READ_SEQUENTIAL_MESSAGE_EXIT:
  252.     RETURN
  253.  
  254. L3_OPEN_VSAM_FILE_FOR_INPUT:
  255.     ComArea = '00'VSAMFileName'F'
  256.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  257.  
  258.     ReturnCode = substr(ComArea, 2, 1)
  259.     if ReturnCode <> 0 then do
  260.         say 'There was an error opening' strip(VSAMFileName)'.  Aborting...'
  261.         exit 9
  262.     end
  263. L3_OPEN_VSAM_FILE_FOR_INPUT_EXIT:
  264.     RETURN
  265.  
  266. L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE:
  267.     ComArea = '10'VSAMFileName'F'
  268.     VSAMRecord = left('', 80)
  269.  
  270.     do while ReturnCode = 0
  271.         call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  272.  
  273.         ReturnCode = substr(ComArea, 2, 1)
  274.         if ReturnCode = 0 then
  275.             say strip(VSAMRecord)
  276.     end
  277. L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE_EXIT:
  278.     RETURN
  279.  
  280. L3_READ_A_RECORD_FROM_VSAM_FILE:
  281.     key = left('Taunya', 100)
  282.     ComArea = '20'VSAMFileName'F'key
  283.     VSAMRecord = left('', 80)
  284.  
  285.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  286.     ReturnCode = substr(ComArea, 2, 1)
  287.     if ReturnCode = 0 then
  288.         say strip(VSAMRecord)
  289. L3_READ_A_RECORD_FROM_VSAM_FILE_EXIT:
  290.     RETURN
  291.  
  292. L3_CLOSE_FILE:
  293.     ComArea = '90'VSAMFileName'F'
  294.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  295.  
  296.     ReturnCode = substr(ComArea, 2, 1)
  297.  
  298.     if ReturnCode <> 0 then do
  299.         SAY 'There was an error closing' strip(VSAMFileName)'.  Aborting...'
  300.         exit 9
  301.     end
  302. L3_CLOSE_FILE_EXIT:
  303.     RETURN
  304.  
  305. L3_DISPLAY_POSITION_AND_READ_MESSAGE:
  306.     say
  307.     say 'Hit enter to read' strip(VSAMFileName) 'sequentially, starting with John.'
  308.  
  309.     parse pull junk
  310. L3_DISPLAY_POSITION_AND_READ_MESSAGE_EXIT:
  311.     RETURN
  312.  
  313. L3_POSITION_ON_JOHN:
  314.     key = left('John', 100)
  315.     ComArea = 'P0'VSAMFileName'F'key
  316.     VSAMRecord = left('', 80)
  317.  
  318.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  319.     ReturnCode = substr(ComArea, 2, 1)
  320.     if ReturnCode = 0 then
  321.         say strip(VSAMRecord)
  322. L3_POSITION_ON_JOHN_EXIT:
  323.     RETURN
  324.  
  325. L3_DISPLAY_WRITE_MESSAGE:
  326.     say
  327.     say 'Hit enter to add Taunya to' strip(VSAMFileName)
  328.  
  329.     parse pull junk
  330. L3_DISPLAY_WRITE_MESSAGE_EXIT:
  331.     RETURN
  332.  
  333. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT:
  334.     ComArea = 'Q0'VSAMFileName'F'
  335.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  336.  
  337.     ReturnCode = substr(ComArea, 2, 1)
  338.     if ReturnCode <> 0 then do
  339.         say 'There was an error opening' strip(VSAMFileName)'.  Aborting...'
  340.         exit 9
  341.     end
  342. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT_EXIT:
  343.     RETURN
  344.  
  345. L3_WRITE_A_RECORD_TO_VSAM_FILE:
  346.     key = left('Taunya', 100)
  347.     ComArea = '40'VSAMFileName'F'key
  348.     VSAMRecord = left('Taunya  9876 3rd St.    Dallas      TX', 80)
  349.  
  350.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  351.     ReturnCode = substr(ComArea, 2, 1)
  352.     if ReturnCode = 0 then
  353.         say 'Taunya was successfully added to' strip(VSAMFileName)
  354.     else do
  355.         say 'There was an error writing to' VSAMFile'.  Aborting...'
  356.         exit 9
  357.     end
  358. L3_WRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  359.     RETURN
  360.  
  361. L3_DISPLAY_READ_RANDOM_MESSAGE:
  362.     say
  363.     say 'Hit enter to read the record for Taunya from' strip(VSAMFileName)
  364.  
  365.     parse pull junk
  366. L3_DISPLAY_READ_RANDOM_MESSAGE_EXIT:
  367.     RETURN
  368.  
  369. L3_DISPLAY_REWRITE_MESSAGE:
  370.     say
  371.     say 'Hit enter to update Taunya in' strip(VSAMFileName)
  372.  
  373.     parse pull junk
  374. L3_DISPLAY_REWRITE_MESSAGE_EXIT:
  375.     RETURN
  376.  
  377. L3_REWRITE_A_RECORD_TO_VSAM_FILE:
  378.     key = left('Taunya', 100)
  379.     ComArea = '50'VSAMFileName'F'key
  380.     VSAMRecord = left('Taunya  1234 Rosemont   Baltimore   MD', 80)
  381.  
  382.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  383.     ReturnCode = substr(ComArea, 2, 1)
  384.     if ReturnCode = 0 then
  385.         say 'Taunya was successfully updated in' strip(VSAMFileName)
  386.     else do
  387.         say 'There was an error rewriting to' strip(VSAMFile)'.  Aborting...'
  388.         exit 9
  389.     end
  390. L3_REWRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  391.     RETURN
  392.  
  393. L3_DISPLAY_ERASE_RANDOM_MESSAGE:
  394.     say
  395.     say 'Hit enter to erase the record for Taunya from' strip(VSAMFileName)
  396.  
  397.     parse pull junk
  398. L3_DISPLAY_ERASE_RANDOM_MESSAGE_EXIT:
  399.     RETURN
  400.  
  401. L3_ERASE_A_RECORD_FROM_VSAM_FILE:
  402.     key = left('Taunya', 100)
  403.     ComArea = 'E0'VSAMFileName'F'key
  404.     VSAMRecord = left('', 80)
  405.  
  406.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  407.     ReturnCode = substr(ComArea, 2, 1)
  408.     if ReturnCode = 0 then
  409.         say 'Taunya was successfully erased from' strip(VSAMFileName)
  410.     else do
  411.         say 'There was an error erasing Taunya from' strip(VSAMFile)'.  Aborting...'
  412.         exit 9
  413.     end
  414. L3_ERASE_A_RECORD_FROM_VSAM_FILE_EXIT:
  415.     RETURN
  416.  
  417.  
  418.