[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading numeric fields from XML files



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


Question:  A numeric field, say, order number, is 10 long.  However, only
the significant digits are sent and received, so order number 0000055555 is
returned as 55555.  Is there an  "elegant" way to put 55555 into a numeric
variable?

If you're on V5R2 or later, you can use %DEC, as follows:


D CharData        s            100A
D Numeric         s             10P 0

/free

    CharData = '55555';
    Numeric = %dec(CharData: 10: 0);

Keep in mind that the parms to the %dec() BIF are the size of the numeric field, not the character field.

I suppose the vendor can return all 10 digits. And yes, MOVE will work, if the field is zero-filled first. (I even tried to fool the system and use %DEC, to no avail.)

In V5R1 (and earlier) they hadn't added this functionality to %DEC yet. If you don't need decimal places, one easy solution is to use atoll() from the ILE C runtime library:


H DFTACTGRP(*NO) BNDDIR('QC2LE')

D atoll           PR            20I 0 extproc('atoll')
D   string                        *   value options(*String)

D CharData        s            100A
D Numeric         s             10P 0

/free

    CharData = '55555';
    Numeric = atoll(CharData);
    dsply Numeric;
    *inlr = *on;

/end-free


If you do need decimal positions on V5R1 or earlier, the best idea (IMHO) is to use Barbara Morris' GETNUM subprocedure. You can download it from the following link:


http://faq.midrange.com/index.pl?file=52

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------