title: How to encode a STRING variable into a given code page
body: <p>I've got a string variable containing a text that I need to encode and write to a file, in <code>UTF-16LE</code> code page.</p>
  
  <p>Currently the following code generates a <code>UTF-8</code> file and I don't see any option in the statement <code>OPEN DATASET</code> to generate the file in <code>UTF-16LE</code>.</p>
  
  <pre><code>REPORT zmyprogram.
  
  DATA(filename) = `/tmp/myfile`.
  
  OPEN DATASET filename IN TEXT MODE ENCODING DEFAULT FOR OUTPUT.
  
  TRANSFER 'HELLO WORLD' TO filename.
  
  CLOSE DATASET filename.
  </code></pre>
  
  <p>I guess one solution is to first encode the string in memory, then write the encoded bytes to the file.</p>
  
  <p>Generally speaking, how to encode a string of characters into a given code page, in memory?</p>