Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling static EBCDIC hex in NetRPG #34

Open
worksofliam opened this issue Sep 16, 2019 · 0 comments
Open

Handling static EBCDIC hex in NetRPG #34

worksofliam opened this issue Sep 16, 2019 · 0 comments

Comments

@worksofliam
Copy link
Owner

This is a fun post to write about, right? Everyone in the IBM i world loves to deal with EBCDIC problems. Of course, when porting RPGLE to another platform you have to handle edge cases of when hexadecimal can be used.

Firstly, you can read about hexadecimal literals here in the RPGLE manual.

Let's use this RPG example:

**FREE

Dcl-S MyStr Char(12);

MyStr = x'C88593939640A6969993845B';

Dsply MyStr;

That static hexadecimal string is Hello world$ in EBCDIC. Now, we must not forget that there are multiple versions of EBCDIC. If we were running this under a job of CCSID (or codepage) 37, then the value is Hello world$. If we were running this under CCSID 285, it would be ``Hello world£`.

Luckily, for NetRPG, .NET Core has some support for these encodings (and others too!). The parser is keeping an eye out for these hexadecimal literals.

case "x":
    token = new RPGToken(RPGLex.Type.STRING_LITERAL, EBCDIC.ConvertHex(EBCDIC.GetEncoding(int.Parse(Configurations["CCSID"])), tokens[i + 1].Value));

Using System.Encoding we can convert a string of bytes from EBCDIC to a regular C# string. and we created a ConvertHex function to make this easier long term. We also have a function to convert an IBM i CCSID to the equivalent .NET Core encoding name. You can see those here.

Meaning, when the hexadecimal literal is found in the RPG code, the tokens are replaced with the converted string. Because .NET Core supports multiple different CCSIDs, it means we can support them too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant