IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Validate NUMERIC DATA from Input


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Aug 15, 2013 11:46 pm
Reply with quote

Code:

03  WS-INPUT-ITEM PIC  9(10).
03  WS-SUB PIC  9(08) COMP-5 VALUE 1.
03  WS-MAX-SUB PIC  9(08) COMP-5.
03  WS-STRING PIC  X(300).
03  WS-POS PIC  9(08) COMP-5 VALUE ZERO.
03  WS-ERROR-SUB PIC  9(02) VALUE ZERO.

COMPUTE WS-MAX-SUB = (LENGTH OF WS-STRING / LENGTH OF WS-INPUT-ITEM).

PERFORM UNTIL WS-SUB > WS-MAX-SUB
     ADD  1 TO WS-POS
     MOVE WS-STRING (WS-POS:LENGTH OF WS-INPUT-ITEM) TO WS-INPUT-ITEM (1:)
     IF  WS-INPUT-ITEM NOT NUMERIC
          MOVE WS-SUB TO WS-ERROR-SUB
          MOVE WS-MAX-SUB TO WS-SUB
     END-IF
     ADD  1 TO WS-SUB
     ADD LENGTH OF WS-INPUT-ITEM TO WS-POS
END-PERFORM.

IF  WS-ERROR-SUB > ZERO
     DISPLAY 'SUB-STRING = ', WS-ERROR-SUB, ' IS NOT NUMERIC'
     DISPLAY 'PLEASE REVIEW THIS DATA - VALIDATION PREMATURELY TERMINATED'
END-IF.

In this code, WS-MAX-SUB resolves as 30. The first '~' appears in WS-STRING at position 11 and subsequently at the "current' position plus 11. In between each '~', you'll find 10-bytes of data (a single sub-string).

This is based upon each sub-string being 10-bytes, which is the LENGTH OF WS-INPUT-ITEM.

WS-ERROR-SUB is set to the current value in WS-SUB when the current sub-string (found in WS-INPUT-ITEM) is NOT NUMERIC. When the PERFORM is completed, it's checked for a non-zero value. The PERFORM will be exited prematurely when the first NON NUMERIC sub-string is found.

I've only desk-checked this, so give it a try....
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Fri Aug 16, 2013 9:29 am
Reply with quote

Bill O'Boyle : As I mentioned earlier, I've some other input data in between numeric data like date, time & texts. So I can't follow your code. More are less it is checking each and every byte, which I've already used.


Bill Woodger:
1. I'm agreeing with your for replace NUMVAL with normal MOVE statement.
2. Anything <= SPACES will be non-process-able values(some times low-values). So I thought it is better to validate > SPACES.
3. If I follow UNSTRING with COUNT option,
    a. I've to declare and process 30 more variables for COUNT
    b. If there is SPACE in the input it will COUNT that as well. so I can't able to populate ZERO based on count.

for example: input = ' 1254', then count will be 6, so I'll populate 4 zeroes in front. So the values will be '0000 1254', which is incorrect.
Same goes for input = ' ' (all spaces), then count will be 10.
If I use INSPECT then it will replace all leading spaces into zeroes.
Am I missing anything ?

As for understand coding: We have number of programs coding and will have same structure as this, no need to go back and check what is the initial 'VALUE' for the TEMP variables as we follow 'SPACES' and 'ZEROES' for all TEMP variables we are using in whole program.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Aug 16, 2013 10:04 am
Reply with quote

One tip; If you're going to check each byte to be NUMERIC, check for NOT LESS THAN ZERO (X'F0') and NOT GREATER THAN '9' (X'F9'). This will generate two Assembler CLI (Compare Logical Immediate) instructions, which is far cheaper than a straight away NUMERIC check, which generates the far more expensive Assembler TRT (Translate and Test) instruction, utilizing a 256-byte translate-table built by the compiler and uses this byte-value as a displacement into the table (relative to zero), where the calculated table-address (when valid) will contain a X'00'.

Having attempted to understand your parsing/validation dilemma was a struggle, but apparently, there are hidden anomalies, which were not well documented, so my suggestions are over and good luck.

HTH....
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Aug 16, 2013 1:31 pm
Reply with quote

If checking byte-for-byte, do as Mr Bill says. The advanntage of IF ... NUMERIC for multiple bytes is that the instruction "stops" as soon as it finds a non-numeric. For one byte, this is not an advantage.

For the rest, if you're happy, we're happy.

The code will be tested.

I don't think an individual user will notice difference in response time.

I think if we really knew what you wanted, the provider of the message could have done more for you.

Let's let you get on with it, and stop pointing out stuff which you already know or are uninterested in.

You know all the details. We don't. Means we spend more time that necessary, only to get things patted away by you.

Next time, give us all the information up front, please.

Good luck.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top