Java mapping for COBOL comp and comp-3 fields
I am calling a DB2 stored procedure created using COBOL from my java application.
input macro (type varchar
):
01 SP1-INPUTS.
05 FIELD-1 PIC X(03).
05 FIELD-2 PIC S9(09) COMP.
05 FIELD-3 PIC S9(15)V9(02) COMP-3.
05 FIELD-3X REDEFINES FIELD-3 PIC X(09)
To test a stored procedure, I only know the value for FIELD-1
. For other fields, to fill in the packed parts, how many zeros do you need to put in? Please see the code I wrote and got confused about passing dummy values.
String field1="abc";
String field2="000000000"; // 9 zeroes, correct?
String field3="00...0" // should I give 18 zeroes or 9 zeroes?
How many characters are there in total for an input macro?
source to share
COBOL has no strings, it has fixed-length fields without terminators.
So for FIELD-1, you have three "symbols". PICture of X can resolve any of 256 possible bit values, but will usually contain human-readable values.
FIELD-2 is a binary field. You can think of this as a four-byte integer.
However, as it is defined there, COMP, with S, it has a maximum value of 999.999.999 positive and a minimum value of 999.999.999 negative.
If it was specified as COMP-5, it can contain the full range for all bits in those four bytes. Note that the TRUNC (BIN) compiler option will change the behavior of COMP to COMP-5 anyway, so you need to check on the Mainframe side which compilation option is used for TRUNC (other values are STD and OPT).
The IBM mainframe has its own binary field - Big Endian. On your local machine, the binary value will be Little Endian. For example, the value 16906090 will be stored as X'01020304 '.
FIELD-3 packed-decimal. It is nine bytes long, but each byte contains two decimal digits, with the exception of the least significant (least significant) byte which contains one digit followed by a sign specifier (PICture uses S, so the sign must be C for positives and D for negative , base-16). There is an implied decimal point ( V
) and two decimal places.
FIELD-3X is another X field. It can again contain any pattern bit in each of the bytes. You need to know what was meant to be used in this field (there is not the slightest clue from the names, like the others, which does not work well).
The design is wrong. All nuts are sending binary and packed decimal fields from the Mainframe to another location or vice versa. If all , the fields were defined as X or 9 without USING the (implied) COMP or COMP-3, then you will be very easy to ride.
The final definition requires the desired full stop / period, but this is more of a pastor.
01 SP1J-INPUTS.
05 a-meaningful-name PIC X(03).
05 another-meaningful-name PIC S9(09)
SIGN LEADING SEPARATE.
05 a-third-meaningful-name PIC +9(15).9(02).
05 yet-annother-meaningful-name
REDEFINES a-third-meaningful-name
PIC X(19).
This shows two ways to handle a sign, either with a SIGN clause or with numeric editing. .
in a numeric editable definition is the actual decimal point, not the implied one, with V.
All data is now "text" or "character" data that you can easily deal with. EBCDIC (IBM mainframe encoding) to ASCII (your local machine encoding most likely) is easy and can be done at the data level rather than at the field level.
For your back-and-forth connection, the above will be much easier for you, the more error prone and more easily verifiable. Internally, the COBOL program can easily convert to / from it for its own internal use.
If you don't force them to change their interface to "character" then you have all sorts of additional coding and testing, with no advantage.
And an example of this layout with ABC, 123456789 (negative) and 123456789012345.67 (positive) would be
ABC-123456789+123456789012345.67
Note that in addition to the lack of field delimiters, there are also no data and record delimiters. No "null" s.
There is an alternative to the actual decimal point that should provide a scaling factor. Alternatively, you can hard-code the scaling in your program.
I assume the above data will be easy for you to both accept and create. Try to change your interface. If they refuse, inform your boss about the impact on the extra code, and the extra code is just to "understand" the data before you even think about using it. Which is stupid.
To create simple format data for you, the COBOL program should do this:
MOVE FIELD-1 TO a-meaningful-name
MOVE FIELD-2 TO another-meaningful-name
MOVE FIELD-3 TO a-third-meaningful-name
To get the data from you in light format, the COBOL program should do this:
MOVE a-meaningful-name TO FIELD-1
MOVE another-meaningful-name TO FIELD-2
MOVE a-third-meaningful-name TO FIELD-3
If REDEFINES has a purpose, it would require specific code for the fourth field, but it's hard for me to guess, but not hard to code once the real need is known.
There is nothing cumbersome or much more straightforward than something you need to code differently.
source to share