momi sabag:
Thank you for the comment. I am not sure how to determine which way is the AS400 database set up - I do not know whether the text fields are varchar or char. What is the best way to find out?
Main Topics
Browse All TopicsThe problem is that the target field on AS400 DB2 is a text field with some portion consisting of packed decimal data. I can use AS400PackedDecimal from the AS400 toolkit to pack the fields in Java, but writing it (using setBinaryStream method withing prepared statement), but the store will still scramble the results.
Is there method where I can suppress the ASCII to EBCDIC conversion?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
A few ideas come to mind. Haven't tested any, though:
Write to a file containing the correct layout (packed field defined as it's own column), and then use the CPYF FMTOPT(*NOCHK). This only works if the packed data appears in a fixed position.
If the data is in an unpredictable location, you can still use the intermediate file idea, but declare the entire record as binary fields per momi_sabaq's suggestion , and handle your own packing and ASCII(Unicode)/EBCDIC conversion, then copy from the intermediate file using CPYF *NOCHK
Another alternative would be to create an AS/400 stored procedure to build the combined field for you. Trivial to do in a C or RPG stored proc, for example.
- Gary Patterson
Check out y EE profile: http://www.experts-exchang
Gary_The_IT_Pro:
Thank you for your comment.
The CPYF option would not work too well as I access the database from an interactive application using JDBC and Java on Apache/Tomcat. The packed fields are on the same location so that would not be a problem.
I am creating and using stored SQL procedures but do not know how to write packed field from SQL - to the use of stored procedure calling another language may actually work. I will try that.
Thanks again!
MPK1:
I can't be certain from what's posted so far. But, are you simply trying to execute INSERT and/or UPDATE statements against a table on the AS/400? You should be able to handle the packed field just like any other numeric type. No ASCII/EBCDIC conversion should be involved as far as the data goes.
I'm obviously missing something due to insufficient Monday morning coffee...
Tom
@Gary:
Ah. Well, that would indeed be an issue. And the pseudo-packed/character field isn't CCSID 65535? (Or all character fields are 65535 which makes handling the exception field difficult...)
Yes, now after re-reading the opening statement, it makes sense. That is, the problem makes sense -- the field definition doesn't.
By handling as 65535, the non-packed portion could be ASCII/EBCDIC converted before the packed/hex characters are concatenated in. The entire field might then be transmitted without conversion.
Maybe.
Also, a stored proc does seem reasonable. The true character portion and the numeric portion could be passed in separately. The SP would assemble the packed bytes and concatenate them on.
That's about all I have to add. Looks like the question's being handled as well as the design allows.
Tom
@Tom and @Gary:
Gentlemen:
The packed field is defined in a text field (CHAR) and I cannot change that characteristic. I tried various schemes to bypass the ASCII - EBCDIC conversion, but I failed in all. The problem is that I have a packed date: 2091005 that should end up in EBCDIC packed as "20", "91", "00", and "5F" (speaking of hex presenatation).
The packing in ASCII is performed using AS400PackedDecimal java class that generates the above hexadecimal values. The problem is that when I store it in the database, it ends up scrambled.
I am right now trying to approach it using overriding DDS (PF with LF) and should see if that works.
I really appreciate your comments!
Regards,
Mark
Mark:
Although the packed characters are in a text field, the problem seemed to be that the field included other non-packed characters. E.g., the first four bytes might contain the letters "DATE" and the last four bytes would contain the four packed values. The total field length would therefore be eight bytes. This impression comes from your initial description "...a text field with some portion consisting of packed decimal data." The portion containing packed bytes would be the final bytes in my example.
Is that accurate? The field has mixed character representation?
Also, what date is represented by "2091005"? I would normally expect "20091005" or something similar. When packed, those bytes would be '02', '00', '91', '00' and '5F' -- five bytes in length. But maybe your date representation is custom or it was a simple typo.
Tom
Tom:
You are correct, the field is a mixture of text and packed data.
The field is in a COBOL Presentation
01 combined_field.
05 field1 pic x(2).
05 field2 pic s9(7) COMP-3.
05 field3 pic s9(3) COMP-3
05 field4 pic s9(3) COMP-3.
Presentation of date is CYYMMDD (C=2 for 2000s, =1 for 1000s ). So starting on position 3 of the text field, the packed 2091005 will show up as 20, 91,00,5F (note that F means positive). Similarly, the first text positions are "01" represented by "F0", "F1" in the EBCDIC. Total length of the field is 10 characters.
As far as I can tell, the machine uses Cp037 codepage and I am on a normal ASCII - standard Java (or POJO).
This problem is quite a challenge. Thanks for any thought and input!
Mark
It is custom and that is my problem.
Mark:
You can _probably_ get things to work either by a pretty ugly concatenation of characters in your Java (which you started out trying) or by way of a SP to do the work on the server. You appear to have no choice but to keep the very unfortunate definition of the compound field.
However, given that the field is compound with packed subfields and that the system runs under Cp037 (CCSID 37), then the CCSID atribute of that specific column probably shouldn't be CCSID 37. IMO, that column ought to be CCSID 65535. That more correctly identifies the characteristics of the data values held in the column.
If there is an administrator, a DBA or anyone responsible for the table, it seems possible that a ALTER TABLE... ALTER COLUMN... CCSID 65535... statement should set the column definition without actually changing anything. Changing the column CCSID to 65535 essentially tells DB2 "This is binary data. Don't do things like ASCII/EBCDIC conversions." The data themselves in all of the rows won't change. And programs that work now should continue to work as always. Exceptions would be other ODBC/JDBC kinds of apps that were previously written to do what you're trying to do.
I suspect that a SP will be the eventually chosen resolution and I understand why. Just adding a potential resolution to keep in mind.
Tom
Tom:
Your last comment is very interesting. I do not know if DBA would do this for me, but I can build the same table in different library and set the column to CCSID of choice. Once I deposit record to that table, I can simply copy it to the main database using SP. Once tested, I should be able to go to the DBA with the request.
I will let you know.
Thanks!
Mark
Mark,
That's essentially what I was suggesting in comment 25495679 above. Create a table with the correct attributes (personally, I'd not make it a binary column, I'd define each of the subfields as a distinct column with the correct data type, then just insert into my new properly-defined table, then do a binary copy [CPYF *NOCHK] to the target table with the combined field. You could call the system supplied stored procedure QCMDEXC to execute the CPYF command.
I have an even easier idea that you can quickly try, though:
I ran the following SQL statement from Run SQL Scripts on a V5R4 machine, and it inserted the untranslated hex value that I specified into a 10-byte character column.
Note that as of V5R3, the JDBC connection property "translate hex" is used to select the data type used by hex constants in SQL expressions. "Binary" indicates that hex contants will use the BINARY data type. "Character" indicates that hex contants will use the CHARACTER FOR BIT DATA data type. The default setting is character.
This only works with "translate hex=character" (the default).
In your program, you just build a dynamic SQL statement containing the hex literal you want to write to the underlying file. Granted, this means a little work to construct the hex literal, but it eliminates the need to create a stored proc or the overhead of creating a duplicate table and copying records.
- Gary Patterson
Check out my EE profile: http://www.experts-exchang
Mark:
Gary's comment...
> ...personally, I'd not make it a binary column, I'd define each of the subfields as a distinct column with the correct data type,...
I expect that you realize that that's technically the "correct" answer overall. A correctly defined database makes this stuff go away. I imagine that it wasn't as important when this was designed. But when remote clients get involved or even the files are merely accessed via a 'structured database language (SQL)', the assumption becomes that it's 'properly structured' at the start.
And also, if you're unfamiliar with the suggestion about [CPYF *NOCHK], it might be worthwhile to become familiar. It's a useful tool in tricky situations when quick recoveries are needed.
Tom
Gary & Tom:
I fully agree with your assessment of what should be an architecturally correct solution. This approach has been developed in mid 80's by yours truly and it sounded as a good idea at the time. The disk space considerations played quite a role back then especially for the multi-million record files. The application hit over 9Mil records in one table in some installations.
The solution is now fully implemented and encapsulated so that no sensibilities are offended.
I used the CPYF in the past but it was not appropriate for this approach - this processing occurs interactively and waking up the AS400 utility would probably cost me some response time.
Thanks for your help.
Business Accounts
Answer for Membership
by: momi_sabagPosted on 2009-10-05 at 01:02:10ID: 25493183
you can try working with binary values and then no ascii to ebcdic conversion should take place
try to define the column in the AS400 database as varchar for bit data