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

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