aws-samples / mainframe-data-utilities

Python scripts to convert and unpack mainframe EBCDIC data on the cloud or any ASCII environment.
Apache License 2.0
34 stars 11 forks source link

Zoned decimal not adding the decimal point. #11

Open clintiepoo opened 4 months ago

clintiepoo commented 4 months ago

Hi,

I’ve got some data that is in ZD format with a decimal point. Example: PIC 9(2)V9(2). This would be a 4 byte zoned decimal with 2 decimal places.

I think your script is treating ZD similar to CH, and thus not adding the decimal marker. See line 40 in src/core/edcdic.py.

Example data: 1035 Expected output: 10.35 Actual output: 1035

If I’m missing something, please let me know. Thanks!

luisdant commented 4 months ago

Hello! You're totally right.

I'll fix it soon.

Please, let me know if you have a proposed fix.

clintiepoo commented 4 months ago

Hello! You're totally right.

I'll fix it soon.

Please, let me know if you have a proposed fix.

Hello,

I don’t have a fully written fix but pseudo code would look like:

I think this would minimize adding decimal points to only where they’re needed.

—-

Edit: it looks like it’s actually as simple as splitting out zd into its own elif block and wrapping the ch returned value with the AddDecPlaces function.

clintiepoo commented 4 months ago

@luisdant I'm not great at github and creating pull requests etc. I think this would do it.

    if type.lower() == "ch":
        return bytes.decode('cp037').replace('\x00', '').rstrip() if rem_lv == True else bytes.decode('cp037')

    elif type.lower() == "zd":
        return AddDecPlaces(bytes.decode('cp037').replace('\x00', '').rstrip() if rem_lv == True else bytes.decode('cp037'), dec_places)
luisdant commented 1 month ago

That's done!

I'm sorry for the late response and THANK YOU for your contribution!

Please let me know if I can close the issue.