View previous topic :: View next topic
|
Author |
Message |
Sudhanshu Shekhar
New User
Joined: 23 Jul 2008 Posts: 27 Location: City of Joy
|
|
|
|
HI,
i have a record with several amount fields.
I want to check if any of these fields contain any alphabet.
I want to write it to an exception file in that case.
I am using inspect but dont want to inspect the code 26 times with each alphabet. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
IF AMT1 NOT NUMERIC
it's an error
END-IF. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Your requirement is not at all clear. If these fields are USAGE DISPLAY, and AMT1 has the value +10.75, it will be stored as 00000000000107E -- so how do you distinguish the legitimate, valid sign overlays from invalid alphabetic characters? If the fields are not USAGE DISPLAY, the problem is worse since both COMP-3 and COMP variables can have valid data fields that appear to be alphabetic characters (for example, -97994 stored as a PIC S9(05) COMP-3 value is 'pr(').
There is a link to the manuals at the top of this page. Click on it, find the COBOL Language Reference and Programming Guide manuals and read up in them on how COBOL stores data internally. Once you have done this, and can reformulate your question in a way that actually makes sense, we should be able to help you. |
|
Back to top |
|
|
Sudhanshu Shekhar
New User
Joined: 23 Jul 2008 Posts: 27 Location: City of Joy
|
|
|
|
Yesh i guess the requirement was not put corretly.
AMT1 is PIC X(10).
I Use the AMT = FUNCTION NUMVAL(AMT1) to extract the numeric value.
But if AMT1 contains any alphabet/non numeric chars the job abends, so i want to have a check before going to the intrinsic function and write those records(containing alphabets or special chars) to an exception file instead of performing the NUMVAL.
Sincere apologies .... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
A PIC X(10) and PIC S9(13)V99 have a different number of digits -- so you're still not explaining yourself very well.
Why not just say
Code: |
IF AMT1 NUMERIC
COMPUTE AMT = FUNCTION NUMVAL(AMT1) |
|
|
Back to top |
|
|
Sudhanshu Shekhar
New User
Joined: 23 Jul 2008 Posts: 27 Location: City of Joy
|
|
|
|
@ Robert,
If AMT is say '9999fff763'
Will the above still work? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Is it so hard for you to test? Code:
Code: |
01 WS-VARIABLES.
10 AMT1 PIC X(10) VALUE '9999FFF763'.
10 AMT2 PIC S9(13)V99.
LINKAGE SECTION.
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
IF AMT1 NUMERIC
COMPUTE AMT2 = FUNCTION NUMVAL (AMT1)
DISPLAY 'AMT2 OK -- ' AMT2
ELSE
DISPLAY 'AMT1 FAILED NUMERIC TEST'
END-IF.
MOVE '1234567890' TO AMT1.
IF AMT1 NUMERIC
COMPUTE AMT2 = FUNCTION NUMVAL (AMT1)
DISPLAY 'AMT2 OK -- ' AMT2
ELSE
DISPLAY 'AMT1 FAILED NUMERIC TEST'
END-IF.
GOBACK. |
produces output of
Code: |
AMT1 FAILED NUMERIC TEST
AMT2 OK -- 00012345678900{ |
|
|
Back to top |
|
|
|