AsciiToEbcdic (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (found the X sting function)
m (re-match syntax diagram to revised template; fix tags. Still some link targets thatneed to be writtend / defined / found.)
Line 7: Line 7:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%string</th>
<tr><th>%outString</th>
<td>A string variable to receive the method object string translated to EBCDIC.</td></tr>
<td>A string variable to receive the method object <var class="term">string</var> translated to EBCDIC.</td></tr>
<tr><th><var class="term">string</var></th>
<tr><th>string</th>
<td>A string that is presumed to consist of ASCII characters.</td></tr>
<td>The input string, which is presumed to consist of ASCII characters.</td></tr>
<tr><th>CharacterEncode</th>
<tr><th>CharacterEncode</th>
<td>The optional, but <var>[[Methods#Named parameters|NameRequired]]</var>, argument <var class="term">CharacterEncode</var> argument is a <var>[[Boolean enumeration]]</var>; if you specify a value, the parameter name <var class="term">CharacterEncode</var> is required.<ul><li>If its value is <code>False</code>, the default, an exception is thrown if the input <var class="term">string</var> contains any ASCII character not translatable to EBCDIC.<li>If its value is <code>True</code>, any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with <code>'&'</code>.<li>For instance, the six characters <code>'&amp;#x90;'</code> replace the ASCII <i>"Device Control String"</i> character (X'90').  A similar example is shown below.</ul></td></tr>
<td>The optional, but <var>[[Methods#Named parameters|NameRequired]]</var>, argument <var class="term">CharacterEncode</var> argument is a <var>[[Boolean enumeration]]</var>.  If its value is:<ul><li><code>False</code>, the default, an exception is thrown if the input <var class="term">string</var> contains any ASCII character not translatable to EBCDIC.<li><code>True</code>, any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with <code>'&'</code>.<li>For instance, the six characters <code>'&amp;#x90;'</code> replace the ASCII <i>"Device Control String"</i> character (X'90').  A similar example is shown below.</ul></td></tr>
</table>
</table>



Revision as of 02:04, 2 February 2011

Convert ASCII string to EBCDIC (String class)


AsciiToEbcdic is an intrinsic function to convert an ASCII (ISO-8859-1) string to EBCDIC using the current Unicode tables. Optionally, untranslatable characters are represented with character references.

Syntax

%outString = string:AsciiToEbcdic[( [CharacterEncode= boolean])] Throws CharacterTranslationException

Syntax terms

%outString A string variable to receive the method object string translated to EBCDIC.
string The input string, which is presumed to consist of ASCII characters.
CharacterEncode The optional, but NameRequired, argument CharacterEncode argument is a Boolean enumeration. If its value is:
  • False, the default, an exception is thrown if the input string contains any ASCII character not translatable to EBCDIC.
  • True, any ASCII character not translatable to EBCDIC is replaced with the XML style hexadecimal character reference of the character, and the ampersand character is replaced with '&'.
  • For instance, the six characters '&#x90;' replace the ASCII "Device Control String" character (X'90'). A similar example is shown below.

Exceptions

AsciiToEbcdic can throw the following exception:

CharacterTranslationException
If the method encounters a translation problem, properties of the exception object may indicate the location and type of problem.

Usage notes

  • More information is available about the Unicode tables.
  • The AsciiToEbcdic function is available as of Sirius Mods version 7.3.

Examples

  1. The following fragment shows calls of AsciiToEbcdic against strings with and without non-translatable characters. The X constant function is used in the example.

    %a String Len 20 %a = '31':X Print %a:AsciiToEbcdic %a = '318132':X Print %a:AsciiToEbcdic(CharacterEncode=True) Print %a:AsciiToEbcdic

    The result is:

    1 1&#x81;2 CANCELLING REQUEST: MSIR.0751: Class STRING, function ASCIITOEBCDIC: CHARACTER TRANSLATIONEXCEPTION exception: ASCII character X'81' without valid translation to EBCDIC at byte position 1 ...

See also