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

  1. /**************************************************************************/
  2. /* This REXX command file contains examples of I/O on a fixed, EBCDIC     */
  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. /*         EBCFIXED.DAT, which is an EBCDIC, 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\EBCFIXED.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 = 'EBCFIXED.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_EBCFIXED_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_EBCFIXED_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_EBCFIXED_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.     key = left('', 100)
  268.     ComArea = '10'VSAMFileName'F'key'Y'
  269.     VSAMRecord = left('', 80)
  270.  
  271.     do while ReturnCode = 0
  272.         call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  273.  
  274.         ReturnCode = substr(ComArea, 2, 1)
  275.         if ReturnCode = 0 then
  276.             say strip(VSAMRecord)
  277.     end
  278. L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE_EXIT:
  279.     RETURN
  280.  
  281. L3_READ_A_RECORD_FROM_VSAM_FILE:
  282.     key = left('Taunya', 100)
  283.     ComArea = '20'VSAMFileName'F'key'Y'
  284.     VSAMRecord = left('', 80)
  285.  
  286.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  287.     ReturnCode = substr(ComArea, 2, 1)
  288.     if ReturnCode = 0 then
  289.         say strip(VSAMRecord)
  290. L3_READ_A_RECORD_FROM_VSAM_FILE_EXIT:
  291.     RETURN
  292.  
  293. L3_CLOSE_FILE:
  294.     ComArea = '90'VSAMFileName'F'
  295.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  296.  
  297.     ReturnCode = substr(ComArea, 2, 1)
  298.  
  299.     if ReturnCode <> 0 then do
  300.         SAY 'There was an error closing' strip(VSAMFileName)'.  Aborting...'
  301.         exit 9
  302.     end
  303. L3_CLOSE_FILE_EXIT:
  304.     RETURN
  305.  
  306. L3_DISPLAY_POSITION_AND_READ_MESSAGE:
  307.     say
  308.     say 'Hit enter to read' strip(VSAMFileName) 'sequentially, starting with John.'
  309.  
  310.     parse pull junk
  311. L3_DISPLAY_POSITION_AND_READ_MESSAGE_EXIT:
  312.     RETURN
  313.  
  314. L3_POSITION_ON_JOHN:
  315.     key = left('John', 100)
  316.     ComArea = 'P0'VSAMFileName'F'key'Y'
  317.     VSAMRecord = left('', 80)
  318.  
  319.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  320.     ReturnCode = substr(ComArea, 2, 1)
  321.     if ReturnCode = 0 then
  322.         say strip(VSAMRecord)
  323. L3_POSITION_ON_JOHN_EXIT:
  324.     RETURN
  325.  
  326. L3_DISPLAY_WRITE_MESSAGE:
  327.     say
  328.     say 'Hit enter to add Taunya to' strip(VSAMFileName)
  329.  
  330.     parse pull junk
  331. L3_DISPLAY_WRITE_MESSAGE_EXIT:
  332.     RETURN
  333.  
  334. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT:
  335.     ComArea = 'Q0'VSAMFileName'F'
  336.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  337.  
  338.     ReturnCode = substr(ComArea, 2, 1)
  339.     if ReturnCode <> 0 then do
  340.         say 'There was an error opening' strip(VSAMFileName)'.  Aborting...'
  341.         exit 9
  342.     end
  343. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT_EXIT:
  344.     RETURN
  345.  
  346. L3_WRITE_A_RECORD_TO_VSAM_FILE:
  347.     key = left('Taunya', 100)
  348.     ComArea = '40'VSAMFileName'F'key'Y'
  349.     VSAMRecord = left('Taunya  9876 3rd St.    Dallas      TX', 80)
  350.  
  351.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  352.     ReturnCode = substr(ComArea, 2, 1)
  353.     if ReturnCode = 0 then
  354.         say 'Taunya was successfully added to' strip(VSAMFileName)
  355.     else do
  356.         say 'There was an error writing to' VSAMFile'.  Aborting...'
  357.         exit 9
  358.     end
  359. L3_WRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  360.     RETURN
  361.  
  362. L3_DISPLAY_READ_RANDOM_MESSAGE:
  363.     say
  364.     say 'Hit enter to read the record for Taunya from' strip(VSAMFileName)
  365.  
  366.     parse pull junk
  367. L3_DISPLAY_READ_RANDOM_MESSAGE_EXIT:
  368.     RETURN
  369.  
  370. L3_DISPLAY_REWRITE_MESSAGE:
  371.     say
  372.     say 'Hit enter to update Taunya in' strip(VSAMFileName)
  373.  
  374.     parse pull junk
  375. L3_DISPLAY_REWRITE_MESSAGE_EXIT:
  376.     RETURN
  377.  
  378. L3_REWRITE_A_RECORD_TO_VSAM_FILE:
  379.     key = left('Taunya', 100)
  380.     ComArea = '50'VSAMFileName'F'key'Y'
  381.     VSAMRecord = left('Taunya  1234 Rosemont   Baltimore   MD', 80)
  382.  
  383.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  384.     ReturnCode = substr(ComArea, 2, 1)
  385.     if ReturnCode = 0 then
  386.         say 'Taunya was successfully updated in' strip(VSAMFileName)
  387.     else do
  388.         say 'There was an error rewriting to' strip(VSAMFile)'.  Aborting...'
  389.         exit 9
  390.     end
  391. L3_REWRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  392.     RETURN
  393.  
  394. L3_DISPLAY_ERASE_RANDOM_MESSAGE:
  395.     say
  396.     say 'Hit enter to erase the record for Taunya from' strip(VSAMFileName)
  397.  
  398.     parse pull junk
  399. L3_DISPLAY_ERASE_RANDOM_MESSAGE_EXIT:
  400.     RETURN
  401.  
  402. L3_ERASE_A_RECORD_FROM_VSAM_FILE:
  403.     key = left('Taunya', 100)
  404.     ComArea = 'E0'VSAMFileName'F'key'Y'
  405.     VSAMRecord = left('', 80)
  406.  
  407.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  408.     ReturnCode = substr(ComArea, 2, 1)
  409.     if ReturnCode = 0 then
  410.         say 'Taunya was successfully erased from' strip(VSAMFileName)
  411.     else do
  412.         say 'There was an error erasing Taunya from' strip(VSAMFile)'.  Aborting...'
  413.         exit 9
  414.     end
  415. L3_ERASE_A_RECORD_FROM_VSAM_FILE_EXIT:
  416.     RETURN
  417.  
  418.  
  419.