com.microfocus.cobol.lang で定義されている CustomRecord インターフェイスを使用すると、cobCall() や cobrcall() で呼び出したレガシー COBOL プログラムにグループ項目を渡すことができます。
CustomRecord インターフェイスの定義を次に示します。
package com.microfocus.cobol.lang;
public interface CustomRecord
{
public Object[] getParameters();
public void setParameters(Object[] parms);
}
データ項目 customerDetails は、次のように定義できます。
01 customerDetails.
03 customerName pic x(30).
03 customerAddress pic x(30).
03 customerRef pic 9(6).
Java の実装例を次に示します。
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;
}
}
Java プログラム内では、次のようなコードで COBOL プログラムを呼び出します。
cobcall("RecordDemo",new ParameterList().add(
new RecordData(myname, myaddress, myref)));