Submitted by Niels Liisberg on Thu, 04/04/2013 - 15:13
Forums

 

Q:
How can i in IceBreak produce a stream file on the IFS directly?
 
Jeppe C.B.
 
A: 
Hi Jeppe
 
Here is an example how to write a ASCII stream file on the IFS with icebreak   
 
<%
/* ---------------------------------------------------------------------------
 * Sample: This program shows how to produce a stream file directly on the IFS
 *
 * --------------------------------------------------------------------------- */
 /include qasphdr,ifs 
 var i    like(int)
 var ok   like(int)
 var f    like(int)
 var buf  like(string)
 
 /free
  *inlr = *ON;
 
  // Look in the qasphdr,IFS for the OpenFlags:
  // This file is output only, data is replaced if it exists
  // You simply add parameters togeter: O_WRONLY + O_CREAT gives: write only AND Create if it does not exists 
  f = open('/www/testfile.log' : O_WRONLY + O_CREAT );
  
  for i = 1 to 1000;
    // Need to produce the data in ascii: windows-1252 is a good candidate
    buf = XlateStr (
          %char(i) 
          + ' This is a test ' 
          + %char(%timestamp) : 0 : 1252
        ) + x'0d0a'; // Newline in ascii   
  
    // Note: we skip the length int ( hench the + 2 ) to get the buffer data
    // %len contains the actual length of the varchar 
    ok = write(f: %addr(buf) + 2  : %len(buf) );
  endfor;
  ok = close(f);