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

How to seperate numeric field from an alphanumeric field Dyn


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
royalchm

New User


Joined: 15 Nov 2007
Posts: 29
Location: Bangalore

PostPosted: Mon Mar 05, 2012 5:30 pm
Reply with quote

Hi,
I have a 6-byte alphanumeric field, need to get the numeric value from this field. But the values will come like 123 ABC, 123ABC,1ABCDE,1234AB... etc. I have used NUMVAL function in the program it's not working and saying "Invalid character O was found in column 4 in argument-1 for function NUNUMVAL-C in program at displacement X'0EF8' ".
Could you please give me any solution for this.
Thanks in Advance....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Mar 05, 2012 5:37 pm
Reply with quote

as long as the numerics are in front (left side)
and the alpha is in end the (right side)
try with INSPECT CONVERTING a thru z to spaces then try the NUMVAL.

alternatively, bump an index thru the 6 bytes, and compare for 0 thru 9 otherwise convert to spaces.
if you use reference modification
use 1:1, 2:1, 3:1 == literals
if you use a variable for the postiion, you will end up with code resembling the inspect.

if you have values like '124ab2' you what would you expect as a result?
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: Mon Mar 05, 2012 6:02 pm
Reply with quote

Subject to the answer to dbz's last question, you can do it by only finding the first non-numeric. That would give you the length of the numeric part. Handles non-alphas in there, if that is a possibility, that way.

Use most common local method for handling parts of fields (occurs depending on, reference-modification, UNSTRING, indexes, subscripts, blind faith).

You might like to check this one.

Since you have a simple numeric, you don't "need" NUMVAL. Doesn't matter much, but the NUMVAL in the linked example is 5+ times slower than the straight code. You'd still have to do "a lot" of them to notice, however :-)
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: Mon Mar 05, 2012 6:10 pm
Reply with quote

An alternative -

Define a PIC 9(17) field and initialize it to zeros.

Then define PIC 9(08) COMP fields, SUB1 and SUB2, initializing SUB1 to the LENGTH OF STRING and SUB2 to the LENGTH of the PIC 9(17) field.

Then, starting at the last byte of the STRING (SUB1), using reference modification in an in-line PERFORM, test for NUMERICS and move each numeric-byte from STRING to the current-byte of the PIC 9(17) field (then subtract 1 from SUB2). Regardless, always subtract 1 from SUB1.

When SUB1 is less than 1, then your done and the PIC 9(17) field will contain the numerics, right-justified, with high-order zeros.

Mr. Bill
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top