Multiple records

42 views
Skip to first unread message

Bernd Stoltefuss

unread,
Nov 27, 2014, 6:08:57 AM11/27/14
to legsta...@googlegroups.com
Hi,

i do not quiet understand how to convert files that contain multiple records of the same type.
Let say i have a copybook like:

 01  ACCOUNT.
           03  NR                 PIC S9(10) USAGE COMP-3.
           03  ID                   PIC S9(10) USAGE COMP-3.

and i have a mainframe file with several records of this type.

When i generate the xsd and call a AccountTransformers.toXml(bytes,writer), where bytes is the whole input file, i will get an Xml only including the first record.
What is the supposed standard way of transforming a file with multiple records to XML? 

Regards,

 Frank

Fady

unread,
Nov 27, 2014, 7:27:34 AM11/27/14
to legsta...@googlegroups.com
Hello Bernd,

This is a jUnit example for you:

    public void testAccount() throws Exception {
       
       
byte[] hostData = HostData.toByteArray("00000001024c00000000256c00000002048c00000000512c");
       
int offset = 0;
       
       
HostTransformStatus status = new HostTransformStatus();
       
AccountXmlTransformers tf = new AccountXmlTransformers();


       
StringWriter writer = new StringWriter();
        tf
.getHostToXml().transform(hostData, offset, writer, status);
       
System.out.println(writer.toString());
        offset
+= status.getHostBytesProcessed();
       
        writer
= new StringWriter();
        tf
.getHostToXml().transform(hostData, offset, writer, status);
       
System.out.println(writer.toString());
        offset
+= status.getHostBytesProcessed();
       
        assertEquals
(8, offset);


   
}



Let me know if you need more explanations.

Fady

Bernd Stoltefuss

unread,
Nov 27, 2014, 9:18:42 AM11/27/14
to legsta...@googlegroups.com
Works like a charm. I was not aware of "getHostBytesProcessed()". Thanks!

Chethan h.s

unread,
Feb 14, 2015, 7:12:19 PM2/14/15
to legsta...@googlegroups.com
Hi Fady 

I have similar problem 

My cb looks like below 
 03   RECORD-KEY.
               05   CLIENT-NO           PIC  X(3).
               05   CLIENT-SUFFIX       PIC  X.
               05   LOAN-NO.
                   07   OUR-NO          PIC  X(6).
                   07   CK-DIG          PIC  X.
               05   REC-CODE            PIC  X.
               05   REC-NUMBER          PIC  999.

and Java code looks like this 

InputStream inputstream = new FileInputStream(path);
byte[] data  = new byte[4000];
int  bytesRead = inputstream.read(data);
System.out.println("bytesRead :: "+bytesRead);
int offset = 0;
while(bytesRead != -1) {
bytesRead = inputstream.read(data);
HostTransformStatus status = new HostTransformStatus();
RecordKeyHostToJavaTransformer recordKeyHostToJavaTransformer = new RecordKeyHostToJavaTransformer();
RecordKey recordKey = (RecordKey)recordKeyHostToJavaTransformer.transform(data,offset,"Cp037");
offset += status.getHostBytesProcessed();
//LoanNo loanNum = (LoanNo) (new LoanNoHostToJavaTransformer().transform(data, "IBM037"));
if(recordKey.getRecCode().equalsIgnoreCase("P")){
System.out.println("data:"+data);
System.out.println(recordKey.toString());
}
But I am not getting loan number transformed to ascii

Record [clientNo=384, clientSuffix=1, loanNo=   ì/", recCode=P, recNumber=1]
Reply all
Reply to author
Forward
0 new messages