LegacyJ CICS and COBOL technology for the J2EE Enterprise Environment

Products     Services     Support     Sales     News     Partners

  

Academic
Programs

Customer
Information

News &
Information

Technical
Information

White
Papers

About Us

LegacyJ FAQ

Calls between COBOL and Java

Question: "We would like more information about implementing CALLS between the PERCobol compiled programs and our own hand crafted Java.  The issue concerns how we should code the inclusion of a packed decimal number in a parameter string. Our Cobol programs send parameters in a single block - this is constructed and de-constructed into individual fields within each program.  These fields have datatypes of their own right such as string, zoned and packed".

Passing numerics between COBOL and Java with  PERCobol:

Here is some information on how VS Cobol II (AIX/ASCII) stores numbers:

http://www-3.ibm.com/software/awdtools/cobol/library/booksghi/Igya1mst.pdf
Go to page 29 ( pdf page 55 )

This pdf and others are available at:
http://www-3.ibm.com/software/awdtools/cobol/aix/library/

Also, attached is a snippet of code that may help you get started.

The attached snippet is for storing a string into a byte[] and int offset.  You'll need to understand the variable into which it's being placed, its picture (PIC S999V99 for instance, stripped to 99999 for even/odd purposes here), its sign (the implicit SIGN TRAILING, SIGN LEADING, etc.), and its size in bytes (itemSize, the number of bytes the packed-decimal uses; the listing file will have this information if you don't know it.  In general, number of 9's plus one for sign, divided by two and rounded up if necessary).  (The Cobol programmers will be well aware of these concepts.)

This takes care of a number of cases, so if a case is known never to occur, it may be stripped away; the sign leading and trailing are done in separate areas, for instance.

Additional Tips

An easy method for passing data back and forth from Java to COBOL is by using the GET-PROPERTY, SET-PROPERTY feature:

WORKING-STORAGE SECTION.

01 my-outer-array occurs 3 times.
     05 my-array occurs 5 times pic x(10) is get-property
            set-property.

Then use:

cobolObj.setMyArray(1,1,"Hello");

or

String result=cobolObj.getMyArray(1,1);

For arrays in the LINKAGE SECTION, as long as the USING item is a 01/77 group item, it'll be fine for calling.  The getElements will work when calling from COBOL to Java.  To have Java call COBOL with it, it'll have to fill a byte[] with the data image (there's no extra magic for dealing with Integer arrays, for instance).  

PERCobol

Home         About Us         Privacy        Legal        
© Copyright LegacyJ Corp. 1998, 2008
All Rights Reserved.

All trademarks are the properties of their respective owners or licensers.