|
Thanks Vern.
I did indeed have things reversed. Barbara set me straight. I should have been using cvthc() rather than cvtch().
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vernon Hamberg
Sent: Friday, September 21, 2012 2:56 PM
To: RPG programming on the IBM i / System i
Subject: Re: Converting an into to hex to char
Hi Gary
Your hexvalue and charvalue in the prototype need to be switched. First parameter is the output and needs to be double the length of the second one.
Of course, when you're working with less than max length, it should work, by accident, maybe.
It might be that the second parameter should not be const - can't remember. I know it seems it is not modified, but I've seen places where that doesn't matter - still can't be const.
Annother thought - when you display charvalue in STRDBG with :x, put a length after it - say, 256 - see what else is out there.
HTH
Vern
On 9/21/2012 4:03 PM, Monnier, Gary wrote:
Hi Vern and Robert,--
As you said Vern "sometimes a piercing glance at the obvious is what's needed."
My piercing glance doesn't seem to be too sharp today.
Here's the pertinent code...
D CEEISEC PR EXTProc('CEEISEC') OPDESC
D yeartocheck 10U 0
D mthtocheck 10U 0
D daytocheck 10U 0
D hourtocheck 10U 0
D minutetocheck 10U 0
D secondtocheck 10U 0
D msecondtochk 10U 0
D rtnseconds 8F
D errorcode like(fc)
D yeartocheck S 10U 0
D mthtocheck S 10U 0
D daytocheck S 10U 0
D hourtocheck S 10U 0
D minutetocheck S 10U 0
D secondtocheck S 10U 0
D msecondtocheck S 10U 0
D rtnseconds S 8F
D fc DS
D fc_Severity 5I 0
D fc_msgNbr 5I 0
D fc_msgNbrHex 2A overlay(fc_msgNbr:1)
D fc_bits 1
D fc_Facility 3
D fc_I_S_Info 10I 0
//------------------------------------------------
// Convert Hex value to Character value (cvtch)
//
//------------------------------------------------
D cvtHexToChar PR ExtProc('cvtch')
D charvalue 32767A options(*varsize)
D hexvalue 65534A options(*varsize) const
D charlen 10I 0 value
D charvalue S 4A
/free
yeartocheck = 2011;
mthtocheck = 9;
daytocheck = 21;
hourtocheck = 59;
minutetocheck = 59;
secondtocheck = 59;
msecondtocheck = 1;
clear rtnseconds;
clear fc;
//----------------------------
// Convert the date to seconds
//----------------------------
callP(E) CEEISEC(yeartocheck:mthtocheck:daytocheck:hourtocheck:
minutetocheck:secondtocheck:msecondtocheck:
rtnseconds:fc);
if (fc_msgNbr <> 0);
callP(E) cvtHexToChar(charvalue:fc_msgNbrHex:%len(fc_msgNbrHex));
rtnErrMsgID = 'CPF9897';
rtnErrMsgFile = 'QCPFMSG';
rtnErrMsgLib = '*LIBL';
rtnErrData = 'Invalid date supplied - ' + dateToCheck + '.';
rtnErrDtaLen = %len(%trimr(rtnErrData));
rc = 1;
endif;
return rc;
/end-free
The above code throws C2M3001, charvalue is x'00404040', fc_msgNbrHex = x'2510' and I assume %len(fc_msgNbrHex) is 2.
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Vernon Hamberg
Sent: Friday, September 21, 2012 1:31 PM
To: RPG programming on the IBM i / System i
Subject: Re: Converting an into to hex to char
Hi Gary
You don't convert the number to hex - you convert the hex value of either msgnbr or msgnbrchar to its hex nybbles - so the result is a 4-character string - the first parameter of cvtch, right?
Can you show us your call to cvtch?
The 3rd parameter is the length of the 2nd parameter - so that should have a value of 2. It should be a 10i 0. First parameter is a 4-character variable, 2nd parameter can be the 5i 0 integer or its 2-character overlaid variable.
I know I'm stating the obvious. But sometimes a piercing glance at the obvious is what's needed.
Here's a prototype I have for cvtch - actually converts bytes to nybbles, once might say - these always get me a little turned around!
d convertCharacterToHex...
d pr extproc('cvtch')
d toString 512
d fromString 256
d fromStringLength...
d 10i 0 value
HTH
Vern
On 9/21/2012 2:54 PM, Monnier, Gary wrote:
All,--
I've gone a bit brain dead today it seems and I'm hoping someone can help me reignite the ol' synapses.
I have a program using the Convert Integers to Seconds (CEEISEC) API. This API uses the CEE feedback structure to return error information.
D feedback DS
D severity 5I 0
D msgnbr 5I 0
D msgnbrchar 2A overlay(msgnbr:1)
D bits 1
D facility 3
D i_s_info 10I 0
When I force invalid data in debug I have a msgnbr and a facility of CEE returned. This is as expected. Trouble is msgnbr does not relate to any CEExxxx message unless I display msgnbr in hex.
For example when in debug if I supply an invalid hour and press (F11) on variable msgnbr I see 9488 for a value. There is no error message CEE9488 that I can find.
But if I display msgnbr in hex (eval msgnbr:x) I see 2510. Error message CEE2510 (The value for hour is not valid.) does exist and is in fact the error I forced.
Using msgnbr or msgnbrchar with cvtch() throws C2M3001 so I know I have to convert msgnbr to a hex value.
My quandary is how in the world do I convert integer 9488 to hex value x'2510' so I can use cvtch() to convert x'2510' to character value '2510'?
I want to build the CEExxxx message number by concatenating facility and the converted msgnbr.
Thanks,
Gary Monnier
This is the RPG programming on the IBM i / System i (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 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 on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.