Skip to content

CCSID conversion issue in SequentialFile #280

@rgala

Description

@rgala

It looks like during reading/writing records from source physical files using SequentialFile class, the CCSID of field is ignored and data is interpreted in job's CCSID. In my case, after connecting to AS400.RECORDACCESS service, the job QRWTSRVR that is handling the connection has CCSID set to 278 (I have CCSID 278 set on my profile). The source file has CCSID of 37. Variant characters are incorrectly converted.

Steps to reproduce:

  1. Temporarily set your profiles CCSID to 278 by running CHGPRF CCSID(278)
  2. CRTSRCPF FILE(SOMELIB/TEST)
  3. CHGPF FILE(SOMELIB/TEST) CCSID(37)
  4. ADDPFM FILE(SOMELIB/TEST) MBR(TEST) SRCTYPE(RPGLE)
  5. Put some variant characters to a member, like [^]\, for example.
  6. Read records in Java with something like below:
AS400 as400 = new AS400();
as400.connectService(AS400.RECORDACCESS);
SequentialFile sf = new SequentialFile(as400, "/QSYS.LIB/SOMELIB.LIB/TEST.FILE/TEST.MBR");
sf.setRecordFormat();
Record[] records = sff.readAll();
for (Record record : recordss) {
    System.out.println(record.getField(2));
}

What will be printed is §¬¤É instead of [^]\

When debugging, the as400Data_ field of record variable contains 0xB5 0x5F 0X9F 0x71 (starting from index 12) which are 278 equivalents of [^]\, in CCSID 37 it's §¬¤É and this is what is converted to a Java string.

I tried to set CCSID to 37 on AS400 class object (as400.setCcsid(37)) before connecting, but it did not help. The workaround I found was to alter record format and force CCSID 278 on SRCDTA field, but I don't like this solution at all.

RecordFormat rf = sf.getRecordFormat();
AS400Text textField = new AS400Text(rf.getFieldDescriptions()[2].getLength(), 278);
RecordFormat format = new RecordFormat(rf.getName());
format.addFieldDescription(rf.getFieldDescription(0));
format.addFieldDescription(rf.getFieldDescription(1));
format.addFieldDescription(new CharacterFieldDescription(textField, rf.getFieldDescriptions()[2].getFieldName()));
sf.setRecordFormat(format);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions