midrange.com code scratchpad
Name:
Replace All & Write to Stream File
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/13/2009 07:16:51 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1.      // Invocation
  2.                string = formatString(itemNumber) + ','
  3.                + formatString(vendorItem.vivnno) + ','
  4.                + %char(qtyAvail) + ','
  5.                + formatString(%trim(warehouse(i).info.address1) + ' '
  6.                     + %trim(warehouse(i).info.address2)) + ','
  7.                + formatString(warehouse(i).info.city) + ','
  8.                + formatString(warehouse(i).info.stateCode) + ','
  9.                + formatString(warehouse(i).info.postalCode) + ','
  10.                + formatString(warehouse(i).info.phone);
  11.            Stmf_writeln(fd : %addr(string) : %len(%trim(string)));
  12.  
  13.  
  14.       **************************************************************************
  15.       * Write Line
  16.       **************************************************************************
  17.      P Stmf_writeln    B                   export
  18.      D Stmf_writeln    PI            10i 0
  19.      D  fd                           10i 0 value
  20.      D  string                         *   value
  21.      D  len                          10i 0 value
  22.       *
  23.      D eol             s              2a
  24.      D rc              s             10i 0
  25.       *
  26.       /free
  27.        // check the length
  28.        if (len > 0);
  29.          rc = writef(fd : string : len);
  30.          if (rc < 1);
  31.            // Set the error message if an error occured
  32.            if (fd < 0);
  33.              error.message = %str(strerror(errno));
  34.              error.number = errno;
  35.            endif;
  36.            return rc;
  37.          endif;
  38.        endif;
  39.  
  40.        // write the end of line charaters
  41.        eol = newline;
  42.        rc = writef(fd : %addr(eol) : %len(eol));
  43.        return rc;
  44.       /end-free
  45.       *
  46.      P Stmf_writeln    E    
  47.  
  48.  
  49.      P String_replace  B                   Export
  50.      D String_replace  PI         65535a   varying
  51.      D  string                         *   value options(*string)
  52.      D  oldChars                   1024a   const varying options(*varsize)
  53.      D  newChars                   1024a   const varying options(*varsize)
  54.       *
  55.      D oldLen          s             10i 0
  56.      D newLen          s             10i 0
  57.      D pos             s             10i 0
  58.      D returnString    s          65535a   varying
  59.       /free
  60.        returnString = %str(string);
  61.        oldLen = %len(oldChars);
  62.        newLen = %len(newChars);
  63.        if (newLen = 0);
  64.          newLen = 1;
  65.        endif;
  66.  
  67.        pos = %scan(oldChars : returnString);
  68.        dou (pos = 0);
  69.          if (pos > 0);
  70.            returnString = %replace(newChars : returnString : pos : oldLen);
  71.            if ((pos + newLen) > %len(string));
  72.              leave;
  73.            else;
  74.              pos = %scan(oldChars : returnString : (pos + newLen));
  75.            endif;
  76.          endif;
  77.        enddo;
  78.  
  79.        return returnString;
  80.       /end-free
  81.       *
  82.      P String_replace  E                
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css