readblock

The readblock function reads a block of data (segment or record) from the input file and places it into the argument of a string variable.

The readblock and writeblock functions are used in conjunction with each other to pass a block of data from the input file to the output file without compliance checking or testing for proper EDI syntax. Together these functions provide a more efficient alternative of using "wildcard" segments, which are typically implemented in build and break maps.

The readblock and writeblock functions are also used in conjunction with the Document Extraction service to specify the beginning and end of each document in a batch of documents, so that each document can be extracted individually. See the Example 2, below.

The readblock function returns a zero value if it does not read any data. However, if readblock returns a zero value, you should not assume the translator has reached the end of the file. If the data file has a number of new lines embedded in it, the readblock function returns a zero for each new line. If you want to know for certain when the end of the file is reached, use the eof function.

Notes:
  • Readblock, writeblock, and unreadblock are supported only for positional and EDI files.
  • You may not use an ActiveX property as the first parameter of the readblock function because the length of the property is unknown prior to compilation.
  • See the IBM® Sterling Gentran:Server® for Microsoft Windows XML User Guide for special considerations when using this function with XML data.

Syntax

readblock(string_variable);

Examples

Example 1

String[1024] buffer;

readblock(buffer);
writeblock(buffer);

while readblock(buffer) do
begin
   if left(buffer,3) = "HDR" then
       begin
          unreadblock();
             break;
        end
   writeblock(buffer);
end 
//Read a block from the input file and place it in buffer. Look for 
//a "HDR" record tag. If found, reset the file pointer to where it was
//before the "HDR" record was found. Write contents of the buffer to
//the output file. 

Example 2

string[250] buffer; 
string[3] match; 
integer match_len; 
integer eofInput; 
// set these next two variables 
match = "SUM";  // the tag of the last record in the document 
match_len = 3;  // the length of the tag 
// read the block we're on and write it 
readblock(buffer); 
writeblock(buffer); 
eofInput = eof(0); // check if we are at the end of the input document 
// keep reading and writing records until the end of the document 
while !eofInput do 
begin 
  if readblock(buffer) then 
  begin 
    writeblock(buffer); 
    if left(buffer, match_len) = match then  
//write the document, not new lines and continues to process documents 
       begin 
         break; 
       end 
  end 
  eofInput = eof(0); 
// check if we are at the end of the input document 
end