com.microfocus.COBOL.lang.CustomRecord インターフェイスを使用したカスタム レコードの作成

制約事項: 次の説明はネイティブ コードのみに該当します。

カスタムレコードは、既存の COBOL プログラムにグループ項目を渡すのに実用的です。.cobcall 機能とともに使用します。

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 による CustomRecord インターフェイスの実装例を次に示します。

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;
    }
}

および

package com.microfocus.cobol.lang;
public interface CustomRecord
{
   public Object[] getParameters();
   public void setParameters(Object[] parms);
}