This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read mainframe file (in .txt) and assign values to variables.  RSS feed

 
Siva Pratap Reddy Gangireddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am from Mainframe background and working on Java (Beginner) . we need to read mainframe file which is having data in Packed decimal and s(4)V99 formats.

we found few topics but we are not sure how to convert data to 0x## format. Those examples passed the value in 0x## format ( example {0x19, 0x2C} is for 192 value)

But we are not seeing data like this in file (FTPed from Mainframe with both text and binary modes). Also program is getting while training to read the file. Not able to attached the files in (txt, zip or doc formats. Hence coping directly here.

Data in file with BINARY Mode FTP:
=======================
òðñõðøòÉ@Nòðñõðøòù@#Eo@ñòóôõö@#El@Nñòóôõö@ñòóôõö÷øñÂ@Nñòóôõö÷øKñò@4Vx<@Nñòóôõö÷øKñòó@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Data in file with TEXT Mode FTP:
=======================
2015082I +20150829 Ù ? 123456 Ù % +123456 123456781B +12345678.12 »ŒÞ +12345678.123



Can anyone help how to read the mainframe file by step by step?

We also need who to write the file from Java with data in Packed decimal and s(4)V99 formats to Mainframe.





 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I shall see whether I can add code tags to your post. Always use the tags. If I can add them you will see how much better it looks

That looks too hard for “beginning”, so I shall move the discussion.
We shall need more information: How old is the file? What sort of mainframe was it? Is it really a text file? If it is text, what sort of encoding was applied to it? Is it in ASCII or UTF-8 or ISO8859-1 or even (IBM machines only?) EBCDIC?
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at this thread which may help you.
Also please supply details of the packed decimal and s(4)V99 formats.
 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot use text mode FTP to transfer files with binary (COMP, COMP-3) numbers in them. The character translation will damage the binary fields. You must use binary-mode FTP or something similar. Then read the file as a bytestream, and convert the text and binary fields on a field-by-field basis.

You can do it all yourself, or use an off-the-shelf solution. I use the Pentaho DI (Kettle) utility myself. Since it's a general-purpose ETL (Extract, Transform, Load) utility, it can do things like do the FTP connection to the mainframe, convert the fields, and load them directory into a database. Or into fixed character fields, CSV files or whatever I need. It can also handle going the other direction.

The other advantage of a utility like this is that it can be used by non-programmers, since the processing steps and field declarations are all managed by definitions stored in XML files (or a database) and can be edited using a simple drag and drop GUI with dialogs. That makes it easy to adapt to changes in data formats and to add additional files to the conversion process later.
 
Siva Pratap Reddy Gangireddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ALL for replay.

Please find input file layout as below. All COMP-3 fields are packed decimal (PD), fields with V99 are Zoned decimal (ZD).

Fields which are ending with -D, are display format which java can read directly.

Data:
WS-EFF-DATE = +20150829
WS-NUMBER-C1 = 123456
WS-NUMBER-C2 = +123456
WS-AMOUNT-1 = +12345678.12
WS-AMOUNT-2 = +12345678.123




Please find field starting, ending and length for above layout.



I am not sure about encoding. Mostly it uses EBCDIC. The encoding value Cp1047 is suitable for binary mode transferred data as it matched with text mode transfer. we used to FTP the data in .TXT format on desktop.



 
Siva Pratap Reddy Gangireddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried below code for just one filed/variable WS-NUMBER-C1 which is starting at position 20th. i am getting value [63, -31, 63, 32] at variable pd. The original value is 123456 in display format. I expected the value in format [0x01 0x23 0x45 0x6F] at variable pd. Almost all posts are representing data in 0x## format.

Data is represented in HEX format below for field WS-NUMBER-C1.


Code:
 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zoned Decimal is also encoded with cp1047 (EBCDIC). As long as you have separate signs defined, you can directly convert the text to Unicode and thence (if desired) to a binary (int or float) value.

In the case on embedded signs (default), the sign will be overlaid on the last character (byte) of the original EBCDIC text. It will be a nybble whose hex value is 'C" or 'F' for positive numbers and 'D' for negative numbers. To properly handle such values, you need to extract the high nybble from the rightmost character and save it for the sign value, then bitwise-OR an 0xF0 over that byte to convert it to a properm cp1047 digit value.
 
Siva Pratap Reddy Gangireddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gave display format values for cross reference only. it is a test file. My main focus is on Packed decimal and Zoned decimal values. I provided actual data how mainframe looks like. Hence we can't see data in format 0X##. All examples are having input in the format of 0X##. Here only i am feeling that i am missing some part as original data will not have this format.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!