You can call Rebuild from your COBOL program as follows:
call "callrb" using commands status
|A PIC X(600) item containing the Rebuild command line. This item must be 600 bytes in length because Rebuild scans the command line backwards from offset 599.
|A PIC XX COMP-X item containing the returned file status. This item shows the result of the call to Rebuild.
When called from within a program, Rebuild does not display any of its usual messages.
If an error occurs or the rebuild is unsuccessful, RETURN-CODE contains a non-zero value and status contains the returned file status. You should always check RETURN-CODE and status after a call to Rebuild.
The possible values of RETURN-CODE are shown below.
|Rebuild executed successfully
|An error occurred on the input file such as file not found or invalid file format - check status parameter
|An error occurred on the output file - check status parameter
|Error in sort
|File is corrupt
|Attempt to do a /k:a:exists
|Attempt to do a /k:r:onprime
|Attempt to do a /k:r:dontexist
|Too many duplicates on out
|The parameter list contained an error such as an invalid option or an invalid combination of options
|Rebuild has run out of memory
If an error occurs, execute Rebuild from the command line on the same file with a set of identical options. The screen output should give a more precise indication as to the cause of the error.
The following example shows Rebuild being called from within a COBOL program.
01 parameters pic x(600). 01 status pic xx comp-x. ... move "infile.dat,outfile.dat -s:lii -c:d1" to parameters call "callrb" using parameters,status end-call