Thanks Aaron - I hadn’t spotted that.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 13, 2015, at 12:07 PM, Aaron Albertson <albertaa@xxxxxxxxxx> wrote:

I want to point out that while the MI reference has not been available as a
PDF for quite some time, the html documentation still exists in the IBM i
knowledge center and is updated with each release of IBM i. For the most
current version of MI reference documentation you need to go to the IBM i
knowledge center for your release and then select 'Programming->Application
programming interfaces->Machine interface programming' (6.1 & 7.1) or
'Programming->Application programming interfaces->IBM i Machine
Interface' (7.2).


Aaron Albertson


"C400-L" <c400-l-bounces@xxxxxxxxxxxx> wrote on 01/10/2015 10:52:02 AM:

From: Jon Paris <jon.paris@xxxxxxxxxxxxxx>
To: "C400-L@Midrange. Com" <c400-l@xxxxxxxxxxxx>
Date: 01/10/2015 10:52 AM
Subject: Re: [C400-L] Converting packed decimal to a char array
Sent by: "C400-L" <c400-l-bounces@xxxxxxxxxxxx>

You can use the functions you have found but it is more work that
you need I suspect. In some cases sprintf might be enough since the
additional formatting option D(n,p) is available. The MI built-ins
can also provide alternative approaches for some of these functions.
For example EDIT_PACKED does a high speed conversion of a packed
source to an external character form.

These are all listed in the MI reference http://www-01.ibm.com/
support/knowledgecenter/api/content/nl/en-us/ssw_i5_54/books/sc092418.pdf
- this seems to be the latest version but not sure. Each of the
definitions includes an example of calling the function from C.

Sorry I don’t understand your comment at the end regarding the
returned structures. Do you have an RPG definition of them we could
look at - it would make it easier to see what you are trying to do.
For example you said "The input and outputs are both data buffers
that are effectively packed structures” but for us the word “packed”
has meaning as referencing a type of numeric field. I’m thinking
that when you say “packed” you mean struct with not separators
between the fields?

An RPG definition of a struct (known as a DS) incorporating a packed
numeric might look like this:

d results ds
d char 10a // 10 character char array
d pkd1 9p 2 // 7.2 packed decimal -
occupies 5 bytes
// sign is in rightmost
nyble
d zoned1 9s 2 // 7.2 zoned numeric -
occupies 10 bytes
// sign is high order
bit settings in rightmost byte

If you can show us the structure you are dealing with it would be a
lot easier to help you. I’m not a C programmer - I know just enough
to be really dangerous - but I know RPG!


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 10, 2015, at 5:56 AM, Jevgeni Astanovski <jevgeniast@xxxxxxxxx>
wrote:

Thanks, Jon.

Well, by now I found these editing function and got the following:

decimal (15,0) A = 125678D ;
char szTemp[256], szOutput[256], EditMask[256], ZeroFill[1] ;
int n, m, MaskLen, RcvLen ;
Qus_EC_t error_code ;

n = digitsof(A) ;
m = precisionof(A) ;

QECCVTEC(EditMask, &MaskLen, &RcvLen, ZeroFill, "P", " ", n, m,
&error_code) ;

QECEDT(szTemp, RcvLen, &A, "*PACKED ", n, EditMask, MaskLen, "0",
&error_code) ;
memcpy(szOutput, szTemp, RcvLen) ;
szOutput[RcvLen] = 0x00 ;
printf("After conversion A: !%s!\n", szOutput) ;


It produces the following:
After conversion A: ! 125678!
What I expected is a number padded with zeros in the left.
I have to check if the receiver program will accept the changed
input...

Is it what you meant in your advise?

You asked what for do I need it.
I have a big set of API-s on iSeries that are called via RPC from PC
environment. The input and outputs are both data buffers that are
effectively packed structures - that is data fields without any
separators with known widths. This is as infrastructure and I cannot
change it. Packed numbers are always returned as char arrays - and it
is also part of the infrastructure....



On Fri, Jan 9, 2015 at 5:47 PM, Jon Paris <jon.paris@xxxxxxxxxxxxxx>
wrote:
It would help to know why you are trying to do this (editing the
number for example?).

Have you looked at the various editing and conversion
capabilities available in the surfaced MI functions (https://
publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0924180.pdf) as
well as the C/C++ library extensions? (http://www-01.ibm.com/
support/knowledgecenter/#!/ssw_ibm_i_72/rtref/rtrefmain.htm).

Everything you could need is there.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 9, 2015, at 4:00 AM, Jevgeni Astanovski
<jevgeniast@xxxxxxxxx> wrote:

Hi all,

spend a lot of time and feeling like I run into a dead cycle with a
problem, that looks trivial.

I have packed decimals in my C programs that I need to convert to a
char array, representing the number (not zero terminated string).

For example:

decimal (15,9) A ;
char szTemp[32], sField[16] ;

sprintf(szTemp, "%016D(15,9)", A) ;
memcpy(sField, szTemp, 16) ;

What I want to achieve is get a function, that receives A and
returns sField.
Of course it must support any types of decimal - not only decimal
(15,9) but others like decimal(11,7), decimal (15,0), decimal (5,0)
and so on. And, of course, decimal can be positive or negative...


Any ideas?

Jevgeni.
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries)
(C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.


--
This is the Bare Metal Programming IBM i (AS/400 and iSeries)
(C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

--
This is the Bare Metal Programming IBM i (AS/400 and iSeries)
(C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.


--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-
L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.



This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2019 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 here. If you have questions about this, please contact [javascript protected email address].