The CustomRecord interface in com.microfocus.cobol.lang enables you to pass group items to a legacy COBOL program, when using cobCall() and cobrcall().
The CustomRecord interface is:
package com.microfocus.cobol.lang; public interface CustomRecord { public Object[] getParameters(); public void setParameters(Object[] parms); }
The data item customerDetails can be defined as follows:
01 customerDetails. 03 customerName pic x(30). 03 customerAddress pic x(30). 03 customerRef pic 9(6).
A Java implementation could be:
import com.microfocus.cobol.lang.*; import java.text.*; public class RecordData implements com.microfocus.cobol.lang.CustomRecord { private String customerName; private StringBuffer customerAddress; private int customerRef; RecordData(String name, String address, int ref) { customerName = name; customerAddress = new StringBuffer(address); customerRef = ref; } public String getCustomerName() { return this.customerName; } public String getCustomerAddress() { return this.customerAddress.toString(); } public int getCustomerRef() { return this.customerRef; } public Object[] getParameters() { String strCustomerRef = Integer.toString(this.customerRef); while(strCustomerRef.length() < 6) { strCustomerRef = "0"+strCustomerRef; } customerAddress.setLength(30); /* must ensure length is right! */ customerAddress.ensureCapacity(30); return new ParameterList() .add(new Pointer(this.customerName,30)) .add(this.customerAddress) .add(strCustomerRef.getBytes()) .getArguments(); } public void setParameters(Object[] parms) { Pointer ptr = (Pointer)parms[0]; this.customerName = ptr.toString(); this.customerAddress = (StringBuffer)parms[1]; byte[] byteCustomerRef = (byte[])parms[2]; this.customerRef = Integer.parseInt(new String(byteCustomerRef)); } public String toString() { return "Customer Name : "+this.customerName+"\n"+ "Customer Address : "+this.customerAddress+"\n"+ "Customer Ref : "+this.customerRef; } }
The Java program could call the COBOL program as follows:
cobcall("RecordDemo",new ParameterList().add( new RecordData(myname, myaddress, myref)));