Convert ISO Message to BCD

1,013 views
Skip to first unread message

macaruchi

unread,
Apr 4, 2012, 7:01:05 PM4/4/12
to jPOS Users
Hi!
I am a newbie using this llibrary. I used to use this lib to generate
ISO messages in Ascii mode but now my provider tell me that they need
this message but BCD encode.

I dont know how to encode the whole message to BCD. I am seeing a few
methods and I try this...

<code>
public class MyISOMSG {

public static void main(String[] args) throws IOException,
ISOException {
// Create Packager based on XML that contain DE type
GenericPackager Packager = new GenericPackager("mybasic.xml");

// Create ISO Message
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(Packager);

// ISO Message
isoMsg.setPackager(Packager);
isoMsg.setMTI("0200");
isoMsg.set(2, "4916971200540380");
isoMsg.set(3, "003000");
isoMsg.set(4, "125.00");
isoMsg.set(11, "000081");
isoMsg.set(14, "1109");
isoMsg.set(18, "5411");
isoMsg.set(22, "012");
isoMsg.set(24, "006");
isoMsg.set(25, "08");
isoMsg.set(41, "12776859");
isoMsg.set(42, "349000000000");
isoMsg.set(49, "214");
isoMsg.set(62, "000001");
// print the DE list
logISOMsg(isoMsg);

// Get and print the output result
byte[] data = isoMsg.pack();

System.out.println("RESULTADO BCD:"+ISOUtil.hexString(data)); //
*****Conversion that I do *****
System.out.println("RESULT : " + new String(data));
}

private static void logISOMsg(ISOMsg msg) {
System.out.println("----ISO MESSAGE-----");
try {
System.out.println(" MTI : " + msg.getMTI());
for (int i=1;i<=msg.getMaxField();i++) {
if (msg.hasField(i)) {
System.out.println(" Field-"+i+" : "+msg.getString(i));
}
}
} catch (ISOException e) {
e.printStackTrace();
} finally {
System.out.println("--------------------");
}

}

}

</code>

Alejandro Revilla

unread,
Apr 4, 2012, 8:22:56 PM4/4/12
to jpos-...@googlegroups.com
Instead of ' GenericPackager Packager = new GenericPackager("mybasic.xml");' use something like iso87binary.xml as the configuration.

You can find it in the jpos/src/main/resources/cfg/packager directory.

--
@apr




--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage.
Please support jPOS, contact: sa...@jpos.org

You received this message because you are subscribed to the  "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users

macaruchi

unread,
Apr 5, 2012, 10:15:23 PM4/5/12
to jPOS Users
So to pack the message can I use the same method
byte[] data = isoMsg.pack() or must use other method for BCD ?




i changed the XML file ....

On 4 abr, 20:22, Alejandro Revilla <a...@jpos.org> wrote:
> Instead of ' GenericPackager Packager = new GenericPackager("mybasic.xml");'
> use something like iso87binary.xml as the configuration.
>
> You can find it in the jpos/src/main/resources/cfg/packager directory.
>
> --
> @apr <http://twitter.com/apr>
> > Please seehttp://jpos.org/wiki/JPOS_Mailing_List_Readme_first

chi...@gmail.com

unread,
Apr 5, 2012, 11:51:34 PM4/5/12
to jpos-...@googlegroups.com
The method remains the same though the packing of the individual fields changes based on the packages contents. Compare the 2 xml files and understand the differences.

-chhil
Sent from BlackBerry® on Airtel
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first

Alejandro Revilla

unread,
Apr 6, 2012, 8:59:44 AM4/6/12
to jpos-...@googlegroups.com
Same method, ISOMsg.pack(), provided you've previously set the appropriate packager in that ISOMsg object by calling its setPackager method.

--
@apr

md...@yahoo.com

unread,
Apr 15, 2012, 12:48:00 AM4/15/12
to jPOS Users
Hi All,
Finally I found the topics: I myself trying to figure out how to
convert the asii to BCD, Thanks For all information above.

Before I read this thread, I tried to use BCDInterpreter :

public class BCDInterpreter
extends Object
implements Interpreter
Implements BCD Interpreter. Numeric Strings (consisting of chars
'0'..'9' are converted to and from BCD bytes. Thus, "1234" is
converted into 2 bytes: 0x12, 0x34.

But I couldn't find example code to show how to use it , so I tried
something like below :
isoMsg.set(11, "123456");
logISOMsg(isoMsg);
byte[] data2 = isoMsg.getBytes(11) ;
System.out.println("RESULT 11 in ASCII : " + new String(data2)); //
will show "123456"
BCDInterpreter.LEFT_PADDED.interpret( new String(data2), data2,
0); // not like what i have ecpected , only show : "36w456"
System.out.println("RESULT 11 in BCD : "+ new String(data2) );

So could someone tell me how to use BCDInterpreter correctly ?

Best Regards
PS : I am new to JPOS and not really familiar with Java, but I have
experienced building iso-8583 applications with delphi

On Apr 6, 7:59 pm, Alejandro Revilla <a...@jpos.org> wrote:
> Same method, ISOMsg.pack(), provided you've previously set the appropriate
> packager in that ISOMsg object by calling its setPackager method.
>
> --
> @apr <http://twitter.com/apr>

Mark Salter

unread,
Apr 15, 2012, 4:14:49 AM4/15/12
to jpos-...@googlegroups.com
On 15/04/2012 05:48, md...@yahoo.com wrote:
> So could someone tell me how to use BCDInterpreter correctly ?
>
You are missing a *major* point of jPOS...

... being that you don't really need to use the BCDInterpreter yourself
(unless you *really* want to).

What you need to do is pick or set-up your Packager to have it's field
types as BCD.

take a visual look at :-

/jpos6/build/modules/jpos/cfg/packager/iso87ascii.xml

and

/jpos6/build/modules/jpos/cfg/packager/iso87binary.xml

to see the differences and the use iso87binary.xml as your starting
point and adjust that to match your message specification.

(Just as Alejandro said in the first reply). Don't worry though your
efforts will not be wasted, you are now probably quite familiar with the
internal works, but I do hope the above information is a pleasant surprise!

> PS : I am new to JPOS and not really familiar with Java, but I have

We can tell :-)

> experienced building iso-8583 applications with delphi

Ok, so in ISO8583 terms, you need to use the right field types to get
the right result.

Just pick your Packager wisely and all the 'hard' work is done for you.

--
Mark

Mark Salter

unread,
Apr 15, 2012, 7:35:36 AM4/15/12
to jpos-...@googlegroups.com
On 15/04/2012 09:14, Mark Salter wrote:
> On 15/04/2012 05:48, md...@yahoo.com wrote:
>> So could someone tell me how to use BCDInterpreter correctly ?
>>
> You are missing a *major* point of jPOS...

Unless you are not the OP, in which case...

I there are tests for BCDInterpreter in :-

jpos/src/test/java/org/jpos/iso/BCD*

and I evolved some test for BCD* from Ascii* *before I realised that my
local copy was very outdated.

BCDInterpreter inter = BCDInterpreter.LEFT_PADDED_F; // Pick type
byte[] b = new byte[3]; // somewhere for the result
inter.interpret("12345", b, 0); // convert


b holds x'F12345'

--
Mark

Reply all
Reply to author
Forward
0 new messages