|
Random thought . . . You write an RPG4 program to receive the packed/char and return the numeric. You could make it flexible by passing in the length to substring out and unpack. Once in the RPG, it is straight-forward. >>> vhamberg@centerfieldtechnology.com 02/03/03 02:09PM >>> This didn't work, Jim - data type mismatch.&CHAR has to be a string representation of a number, not a hex value. But something close can be done with %BIN. This becomes the same problem as displaying the hex-equivalent of a string, which has been solved before. Don't know if my solution is the same. Negative numbers are not covered here - need to check for value of last nybble of last byte. And number of decimals needs to be known ahead of time. =========================================================== PGM /* */ /* --------- Define program file(s) and variable(s). --------------- */ /* */ DCL VAR(&CHAR) TYPE(*CHAR) LEN(8) + VALUE(X'123456789012345F') /*---------this is your incoming */ DCL VAR(&NUM155) TYPE(*DEC) LEN(15 5) DCL VAR(&NUMBER) TYPE(*CHAR) LEN(17) DCL VAR(&COUNTER1) TYPE(*DEC) LEN(3 0) VALUE(1) DCL VAR(&COUNTER2) TYPE(*DEC) LEN(3 0) VALUE(1) DCL VAR(&BYTES2) TYPE(*CHAR) LEN(2) VALUE(X'0000') DCL VAR(&CHAR1) TYPE(*CHAR) LEN(1) DCL VAR(&DEC1) TYPE(*DEC) LEN(1 0) DCL VAR(&DEC3) TYPE(*DEC) LEN(3 0) /* */ /* --------- Change character value to a 15,5 and then to 7,2 ------ */ /* */ LOOP1: /* Binary value of packed byte */ CHGVAR VAR(%SST(&BYTES2 2 1)) VALUE(%SST(&CHAR + &COUNTER1 1)) CHGVAR VAR(&DEC3) VALUE(%BIN(&BYTES2)) /* 1st digit */ CHGVAR VAR(&DEC1) VALUE(&DEC3 / 16) CHGVAR VAR(&CHAR1) VALUE(&DEC1) CHGVAR VAR(%SST(&NUMBER &COUNTER2 1)) VALUE(&CHAR1) CHGVAR VAR(&COUNTER2) VALUE(&COUNTER2 + 1) /* 2nd digit */ IF COND(&COUNTER2 < 16) THEN(DO) CHGVAR VAR(&DEC1) VALUE(&DEC3 - (&DEC1 * 16)) CHGVAR VAR(&CHAR1) VALUE(&DEC1) CHGVAR VAR(%SST(&NUMBER &COUNTER2 1)) VALUE(&CHAR1) ENDDO CHGVAR VAR(&COUNTER1) VALUE(&COUNTER1 + 1) IF COND(&COUNTER1 <= 8) THEN(DO) CHGVAR VAR(&COUNTER2) VALUE(&COUNTER2 + 1) GOTO CMDLBL(LOOP1) ENDDO CHGVAR VAR(&NUMBER) VALUE(' ' *CAT %SST(&NUMBER 1 + 10) *CAT '.' *CAT %SST(&NUMBER 11 5)) CHGVAR VAR(&NUM155) VALUE(&NUMBER) ENDPGM ====================================================== If you debug this and set a breakpoint at the last statement, &NUM155 will be 1234567890.12345 Vern At 01:30 PM 2/3/2003 -0600, you wrote: >Bill, > >You can try this in your CL, I believe it will work.....unless I am not >understanding what you are trying to do. > >/* */ >/* --------- Define program file(s) and variable(s). --------------- */ >/* */ > DCL VAR(&CHAR ) TYPE(*CHAR) LEN( 11) ><----------this is your incoming > DCL VAR(&NUM155 ) TYPE(*DEC ) LEN(15 5) > DCL VAR(&NUMBER ) TYPE(*DEC ) LEN( 7 2) >/* */ >/* --------- Change character value to a 15,5 and then to 7,2 ------ */ >/* */ > CHGVAR VAR(&NUM155 ) VALUE(&CHAR ) > CHGVAR VAR(&NUMBER ) VALUE(&NUM155) > >Jim > > >-----Original Message----- >From: bill.reger@convergys.com [mailto:bill.reger@convergys.com] >Sent: Monday, February 03, 2003 12:18 PM >To: Midrange-L@midrange.com >Subject: Packed (*CHAR) to Numeric (*DEC) in CLP > > >Can anyone tell me how (in a CLP) to convert a *CHAR declared variable >containing a packed numeric value into a *DEC declared variable? > >Bill _______________________________________________ This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/midrange-l or email: MIDRANGE-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l. THIS MESSAGE IS INTENDED ONLY FOR THE USE OF THE INDIVIDUAL OR ENTITY TO WHICH IT IS ADDRESSED AND MAY CONTAIN INFORMATION THAT IS PRIVILEGED, CONFIDENTIAL AND EXEMPT FROM DISCLOSURE UNDER APPLICABLE LAW. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, downloading, storing or forwarding of this communication is prohibited. If you have received this communication in error, please notify us immediately via email and delete the message from your computer files and/or data base. Thank you.
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.