× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Fri, 05 Aug 2011 17:09:48 +0530, Eric Lee wrote:

Hi,



I'm trying to call an RPG program with a Data structure as a program
parameter, but the data doesn't come in formatted as I have defined
them.

When I debug the RPG, the 70 long datastructure isn't formatted as I
expected.


I think there's a datastructure class in jt400 these days, but I had a
similar issue before it was available, so I wrote the following class:

import java.beans.PropertyVetoException;
import java.io.CharConversionException;
import java.io.UnsupportedEncodingException;

import com.ibm.as400.access.*;

public class DataStructure extends Record {
/**
* <h1>DataStructure</h1>
* <p>Provide a interface object which can provide
* a data structure argument for program calls</p>
*/
private static final long serialVersionUID = 1L;
private RecordFormat recordFormat;
private String recordFormatName = "";
/**
* <h1>DataStructure Constructor</h1>
* <p><code>public DataStructure(String recordFormatName) throws
PropertyVetoException</code></p>
* <p>Constructs a DataStructure object</p>
* @param recordFormatName
* @throws PropertyVetoException
*/
public DataStructure(String recordFormatName) throws
PropertyVetoException {
super();
this.recordFormatName = recordFormatName;
recordFormat = new RecordFormat(recordFormatName);
}
/**
* <h1>addField</h1>
* <p><code>public void addField(int dataType, String fieldName,
int fieldLength, int numDecimalPositions)
throws PropertyVetoException</code></p>
* <p>Add a new field to the end of the data structure</p>
* <h2>Valid dataType values:</h2>
* <ul><li>AS400DataType.<i>TYPE_PACKED</i></li>
* <li>AS400DataType.<i>TYPE_ZONED</i></li></ul>
* @param dataType
* @param fieldName
* @param fieldLength - this is the number of numeric digits for
numeric fields, same as DDS.
* @param numDecimalPositions
* @throws PropertyVetoException
*/
public void addField(int dataType, String fieldName,
int fieldLength, int numDecimalPositions) throws
PropertyVetoException {
switch (dataType) {
case AS400DataType.TYPE_PACKED:
recordFormat.addFieldDescription(
new PackedDecimalFieldDescription(
new
AS400PackedDecimal(

fieldLength, numDecimalPositions), fieldName));
case AS400DataType.TYPE_ZONED:
recordFormat.addFieldDescription(
new ZonedDecimalFieldDescription(
new
AS400ZonedDecimal(

fieldLength, numDecimalPositions), fieldName));
}
}
/**
* <h1>addField</h1>
* <p><code>public void addField(int dataType, String fieldName,
int fieldLength)
* throws PropertyVetoException</code></p>
* <p>Add a new field to the end of the data structure</p>
* <h2>Valid dataType values:</h2>
* <ul><li>AS400DataType.<i>TYPE_TEXT</i></li></ul>
* @param dataType
* @param fieldName
* @param fieldLength
* @throws PropertyVetoException
*/
public void addField(int dataType, String fieldName, int
fieldLength) throws PropertyVetoException{
if (dataType == AS400DataType.TYPE_TEXT) {
recordFormat.addFieldDescription(
new CharacterFieldDescription(
new AS400Text(

fieldLength), fieldName));
}
}
/**
* <h1>setContents</h1>
* <p><code>public void setContents()
* throws UnsupportedEncodingException,
* CharConversionException</code></p>
* <p>Transfers the record format fields to the data
structure<br />
* This method should always be executed after all fields have
been added</p>
* @throws PropertyVetoException
* @throws UnsupportedEncodingException
* @throws CharConversionException
*/
public void setContents() throws PropertyVetoException,
UnsupportedEncodingException, CharConversionException {
super.setRecordFormat(recordFormat);
super.setContents(recordFormat.getNewRecord
(recordFormatName).getContents());
}

}

There's also an externally defined datastructure class that does
something similar if you have a physical file as the interface definition:

import com.ibm.as400.access.*;
import com.ibm.as400.data.*;

public class ExternalDataStructure extends Record {
/**
* Constructs a data structure based on a physical file (table)
* Extends com.ibm.as400.access.Record
*/
private static final long serialVersionUID = 1L;
RecordFormatDocument recordFormatDocument = null;
/**
* @param iHost - the remote IBM i host
* @param baseTablePath - the namefmt 1 path to the based-on
table
* @param recordFormatName - the name of the record format. Must
be the only record.
* @throws Exception
*/
public ExternalDataStructure(
AS400 iHost,
String baseTablePath,
String recordFormatName) throws Exception {
super();
AS400FileRecordDescription interfaceTable =
new AS400FileRecordDescription(iHost,
baseTablePath);
recordFormatDocument =
new RecordFormatDocument(

interfaceTable.retrieveRecordFormat()[0]);
RecordFormat recordFormat =
recordFormatDocument.toRecordFormat
(recordFormatName);
super.setRecordFormat(recordFormat);
super.setContents(
recordFormat.getNewRecord
(recordFormatName).getContents());
}

}

hth


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.