Previous Topic Next topic Print topic


Creating Custom Records using com.microfocus.cobol.lang.CustomRecord Interface

Restriction: This applies to native code only.

Custom records are useful for passing group items to existing COBOL programs. You use then in conjunction with the .cobcall mechanism.

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

and

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