|
|
| Author |
Message |
ponnu116
New User
Joined: 12 Sep 2007 Posts: 17 Location: chennai
|
|
|
|
| We are facing a data exception error in a PL/1 program, when a non numeric value is being checked for zeros in an IF statement. We are facing this issue when the program is compiled in Enterprise PL/i and not in earlier compilers. It will be greatful, if someone can help me with how to resolve this issue and let us know how to check a variable's type in PLI so that we can check whether it is numeric or not before the IF Condition. |
|
| Back to top |
|
 |
References
|
Posted: Thu Apr 17, 2008 12:00 pm Post subject: Re: How to check a PLI variable is numeric or not |
 |
|
|
 |
Bill O'Boyle
Active User
Joined: 14 Jan 2008 Posts: 227 Location: Orlando, FL, USA
|
|
|
|
What is the format of the numeric field? Display-Numeric or Packed-Decimal?
Regards,
Bill |
|
| Back to top |
|
 |
ponnu116
New User
Joined: 12 Sep 2007 Posts: 17 Location: chennai
|
|
|
|
| it is a packed decimal.can we verify whether it is numeric or not |
|
| Back to top |
|
 |
Bill O'Boyle
Active User
Joined: 14 Jan 2008 Posts: 227 Location: Orlando, FL, USA
|
|
|
|
My PL/I is rather rusty (haven't touched it over 20 years) and the only one I remember is for Display Numeric, using the IF VERIFY.
Perhaps someone else has the answer?
Regards,
Bill |
|
| Back to top |
|
 |
Bill O'Boyle
Active User
Joined: 14 Jan 2008 Posts: 227 Location: Orlando, FL, USA
|
|
| Back to top |
|
 |
Bill O'Boyle
Active User
Joined: 14 Jan 2008 Posts: 227 Location: Orlando, FL, USA
|
|
|
|
Below is an Assembler sub-program which can be called from PL/I to validate decimal-data. It uses the "TEST PACK" instruction, which is a somewhat fairly new instruction. However, you need to contact your System's folks and verify that you have "THE EXTENDED-TRANSLATION FACILITY 2" installed. Example syntax (from COBOL) is given in the source, so you'll just have to access it via the proper PL/I syntax.
| Code: |
***********************************************************************
*---------------------------------------------------------------------*
* *
* THE EXTENDED-TRANSLATION FACILITY 2 MUST BE INSTALLED IN *
* ORDER FOR THE 'TP' (TEST PACK) INSTRUCTION TO WORK. *
* *
* EXAMPLE 'CALL' FROM COBOL: *
* *
* 03 WS-PARM-LGTH PIC 9(04) BINARY. *
* 03 WS-PARM-DATA PIC X(16). *
* 03 WS-TESTPKD PIC X(08) VALUE 'TESTPKD'. *
* 03 WS-DECIMAL-X PIC X(05). *
* *
* MOVE X'123456789C' TO WS-DECIMAL-X. *
* MOVE WS-DECIMAL-X TO WS-PARM-DATA. *
* MOVE LENGTH OF WS-DECIMAL-X TO WS-PARM-LGTH. *
* *
* CALL WS-TESTPKD USING WS-PARM-LGTH, *
* WS-PARM-DATA. *
* *
* UPON RETURN, THE 'RETURN-CODE' SPECIAL-REGISTER (R15) WILL *
* EQUAL ZERO (VALID PACKED-DECIMAL DATA), 08 (INVALID DATA) OR *
* 16 (INVALID DATA LENGTH). *
* *
* AFTER ISSUING THE OBLIGATORY 'BCTR,0', AN 'SLL,4' IS ISSUED *
* AGAINST R7. THIS IS NECESSARY FOR THE 'EX' TO 'OR' THE *
* ADJUSTED-LGTH INTO BITS 8-15 OF THE 'TP' INSTRUCTION. *
* *
* SO FOR EXAMPLE, IF THE ADJUSTED R7 = X'00000005', IT WILL *
* CONTAIN X'00000050' AFTER THE SHIFT. *
* *
*---------------------------------------------------------------------*
***********************************************************************
TESTPKD CSECT
USING *,R3 INFORM ASSEMBLER
SAVE (14,12) SAVE REGISTERS
LA R3,0(,R15) R3 IS BASE-REGISTER
L R7,0(,R1) POINT TO HWORD-LGTH
LH R7,0(,R7) LOAD AS HWORD
LA R15,16 SET RETURN-CODE
CHI R7,1 ZERO OR NEGATIVE LGTH?
BL RTN2CLLR YES, RETURN TO CALLER
CHI R7,16 EXCEEDS MAXIMUM-LGTH?
BH RTN2CLLR YES, RETURN TO CALLER
BCTR R7,0 REDUCE BY ONE
SLL R7,4 SHIFT-LEFT 4-BITS FOR 'EX'
L R9,4(,R1) POINT TO DATA-PARM
LA R9,0(,R9) CLEAR TOP-BIT
LA R15,8 SET RETURN-CODE
EX R7,VALIDATE VALID DECIMAL-DATA?
BNZ RTN2CLLR NO, RETURN TO CALLER
SLR R15,R15 ALL IS WELL
RTN2CLLR EQU *
*
RETURN (14,12),RC=(15) RETURN TO THE CALLER
*
VALIDATE TP 0(00,R9) EXECUTED 'TP' (LGTH IN R7)
*
LTORG , LITERAL-ORG
*
TESTPKD AMODE 31
TESTPKD RMODE ANY
*
YREGS REGISTER-EQUATE MACRO
*
END , END 'TESTPKD'
|
HTH....
Regards,
Bill |
|
| Back to top |
|
 |
soundarr
New User
Joined: 17 Jan 2008 Posts: 9 Location: Chennai
|
|
|
|
Hi ponnu,
You can use UNSPEC BUILTIN function for this. Let me know if you need more info on this and if my reply isnt too late..;-)
Regards,
Soundarr |
|
| Back to top |
|
 |
k_vikram07
New User
Joined: 23 Nov 2005 Posts: 35
|
|
|
|
HI
Use HEX function to get the hex char of the field and then use VERIFY to verify if all the hex digits are acceptable.
regards
Vik[/code] |
|
| Back to top |
|
 |
letmeknow
New User
Joined: 10 Dec 2005 Posts: 5 Location: chennai
|
|
|
|
Srini,
As vikram said you can use VERIFY to verify whether the variable is numeric or not.
DCL A DEC FIXED(5,0) INIT(0);
DCL B PIC'99999' INIT('');
DCL C BIN FIXED(15) INIT(0);
A=1234;
B=A;
C = VERIFY(B,'0123456789');
C will be 0, since it is numeric.
Ex: A = 123A;
C will be 4. --> gives the position of the non numeric.
------
If A is decimal value, define appropriate pic variable, in verify string add . (decimal point).
Regards,
Krishna |
|
| Back to top |
|
 |
|
|
|