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

Separating Alphanumeric string with Decimal values


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

New User


Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

PostPosted: Mon Sep 06, 2010 5:45 pm
Reply with quote

Hi

I have a string of length 80 which has decimal values separated by commas(,).There will be 5 decimal values(valid values 1.00 to 100.00) separated by commas and remaining fields filled with spaces.I need to parse the string and store the values into a decimal variables(VAR1,VAR2,....,VAR5).VAR1 TO VAR5 need to be decimal values as I need to do some calculation using these values.

Sample :
Input String : 10.00,15.23,14.00,100.00,23.00
VAR1=10.00,VAR2=15.23,VAR3=14.00,VAR4=100.00,VAR5=23.00

I am need a help on the below 2 problems

1> COBOL code to separate the values
2> Storing decimal values from a alphanumeric field to decimal.I am facing a SOC7 abend because of invalid move.I can't use Function NUMVAL or NUMVAL-C to do the conversion as I am using a older version of COBOL.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Mon Sep 06, 2010 5:51 pm
Reply with quote

Hi Vina,

Please post what you have done so far and then we would feel like guiding you ...

For a starter - look into the INSPECT command....
Back to top
View user's profile Send private message
vina2010

New User


Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

PostPosted: Mon Sep 06, 2010 6:29 pm
Reply with quote

I have tried with PERFORM,could you please guide me how I can use an INSPECT to separate the values.
Code:

PERFORM VARYING X3 FROM 1 BY 1 UNTIL X3 > 80   
    IF INPUT(X3:1) = ',' OR                     
       (INPUT(X3:1) = SPACES AND COUNTER = 4)
       ADD 1 TO COUNTER                         
       COMPUTE X4 = X3 - X1                     
       INITIALIZE HR-NUM-VAL(X5)               
       MOVE INPUT(X1:X4) TO HR-NUM-VAL(X5)     
       COMPUTE X5 = X5 + 1                     
       COMPUTE X1 = X3 + 1                     
    END-IF                                     
END-PERFORM           


Its abending when I am doing a MOVE here.I know as I can't move alphanumeric to decimal.Do i need to break decimal into two parts and then store the value?
Back to top
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Mon Sep 06, 2010 6:32 pm
Reply with quote

Hi
Regarding the first part, you can use UNSTRING WITH POINTER
try some thing like below,

Code:
UNSTRING WS-STRING                     
  DELIMITED BY ','                     
  INTO   Arr-decimal(i)     
         Arr-decimal(i+1)     
  WITH POINTER WS-POS           
END-UNSTRING                             
.

hope it helps..
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Sep 06, 2010 6:33 pm
Reply with quote

Quote:
as I am using a older version of COBOL


you can use UNSTRING to parse the fields.

Then comes the fun.

since you have decimal points (.), you can not use a simple move.

best would be ref mod.

Code:

05  ws-var-01    pic x(16).
05  ws-num-01    pic 9(16).
05  ws-num-00-dp pic 9(16)v
    redefines
    ws-num-01.
05  ws-num-01-dp pic 9(15)v9(01)
    redefines
    ws-num-01.
05  ws-num-02-dp pic 9(14)v9(02)
    redefines
    ws-num-01.
05  ws-num-var-01 pic 9(14)v9(02).
05  ws-dec.pos   pic 9(2).
05  ws-sub-01    pic s9(4) comp.
05  ws-sub-02    pic s9(4) comp.

move zero to ws-num-01,
             ws-dec-pos
move 16   to ws-sub-02
UNSTRING input
    delimited by ','
    INTO ws-var-01
       , ws-var-02
       , ws-var-03
       , ws-var-04
       , ws-var-05
 END-UNSTRING

PERFORM VARYING WS-SUB-01
           FROM 16
             BY -1
          UNTIL WS-SUB-01 = 0
  IF ws-var-01(ws-sub-01:1) => 0
    and
     ws-var-01(ws-sub-01:1) <= 9
  then
     move ws-var-01(ws-sub-01:01) to ws-num-01(ws-sub-02:1)
     substract 1 from ws-sub-02
  end-if
  IF ws-var-01(ws-sub-01:01) = '.'
  then
     compute ws-dec-pos = 16 - ws-sub-01
  end-if
end-perform

evaluate true
    when ws-dec-pos = 0
         move ws-num-00-dp to ws-num-var-01
    when ws-dec-pos = 1
         move ws-num-01-dp to ws-num-var-01
    when ws-dec-pos = 2
         move ws-num-02-dp to ws-num-var-01
end-evaluate

add more code for ws-var-02 thru ws-var-05
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Mon Sep 06, 2010 6:35 pm
Reply with quote

Quote:
could you please guide me how I can use an INSPECT to separate the values.
I sincerely apologize... icon_redface.gif ... I had UNSTRING in mind when i suggested INSPECT... Apologize sincerely if I have made you loose your time...
Back to top
View user's profile Send private message
vina2010

New User


Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

PostPosted: Tue Sep 07, 2010 11:52 am
Reply with quote

Binop, not a problem.

dbz , Thanks.This code is working.But when i googled there were suggestions to redefine the alphanumeric into decimal though they were not confident enough.So I was curious if receving variable could be redefined to avoid such a big logic.I tried redefining the variables but no success.Any ideas in doing this in a simpler way. icon_question.gif
Really Thanks for the code.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Sep 07, 2010 2:26 pm
Reply with quote

if you know for certain, the input fields will always contain 2 decimal,
you could extract the values using a compute.

compute ws-num-var-2-dp = char-on-left-of-dp + (2-char-on-right-of-dp / 100) end-compute

Quote:
Any ideas in doing this in a simpler way


not for free.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Sep 07, 2010 2:58 pm
Reply with quote

How about using real decimal point picture fields to UNSTRING into ?


01 Var1 PIC X(6).
01 Var1Num REDEFINES Var1 PIC 9(3).99
Back to top
View user's profile Send private message
vina2010

New User


Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

PostPosted: Tue Sep 07, 2010 3:53 pm
Reply with quote

Hi Peter,I tried with redefines you had mentioned.

But it failed in compilation pointing where I am using the redefined variable(Var1Num) for calculation.

'WS-LR-NUM (NUMERIC-EDITED)' was not numeric, but was a sender in an arithmetic expression. The statement discarded.'

I tried with 9(3)V99 its abending here with SOC7. icon_rolleyes.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Sep 07, 2010 4:01 pm
Reply with quote

Quote:
I tried with 9(3)V99 its abending here with SOC7


because you have the '.' within the numeric field.

you will have to remove the '.' from the extracted fields before you can use the values in an arithmetic statement.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Sep 07, 2010 4:09 pm
Reply with quote

Vina,

it was a wild guess i made, im sorry it didnt work.
But you mention calculation, what kind of calculation did you do?

You can MOVE into an numeric editing field. You can COMPUTE into it. You can even ADD into it, if it is the destination field and not one of the operands. However, it cannot be one of the operands of a computation because it really doesn't contain numeric data!
Back to top
View user's profile Send private message
vina2010

New User


Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

PostPosted: Tue Sep 07, 2010 4:24 pm
Reply with quote

Ya Peter,to my bad luck it is a operand. icon_sad.gif
Back to top
View user's profile Send private message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Tue Sep 07, 2010 5:15 pm
Reply with quote

Hi,

Try this

Unstring in a Pic(X) variable
Use Numval function to get numeric equivalent. For ex

WorkingStorage.
05 WS-var1 PIC S9(3)V9(9) COMP-3.
05 WS-var1-disp PIC -9(3).9(9).
05 WS-var PIC X(12)

Procedure

Unstring ..... INTO WS-VAR

Compute WS-var1 = FUNCTION NUMVAL(WS-VAR)

***If you want to display it then

Move WS-VAR1 TO WS-VAR-DISP

Hope this helps.

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Sep 07, 2010 5:19 pm
Reply with quote

vina2010,

one of your problems is using 30 year-old-unsupported COBOL.
But there is nothing anyone can do about that.

The UNSTRING you only have to PERFORM once.

the PERFORM VARYING can be an isolated routine, which uses common fields, and have 5 evaluates to move the common-extracted field to the destination.

your basic code would be:

UNSTRING

move field-1 to common-field
PERFORM determine-dp
EVALUATE
move field-2 to common-field
PERFORM determine-dp
EVALUATE
...

that would reduce your code.
if you really wanted to be slick, define your UNSTRING receivers as COBOL internal table items,
and your final numeric fields as COBOL internal table items.
then you would perform 5 times
move to common field
perform determine dp
evaluate

Keanehelp,
it would help if you read the TS first post and understand his restrictions.
Back to top
View user's profile Send private message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Tue Sep 07, 2010 5:31 pm
Reply with quote

Hi Dick,

I apologize, didn't read between the lines.

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Sep 07, 2010 5:39 pm
Reply with quote

Nitin,
don't apologize to me, you have not wasted my time,
but your post indicated that you did not bother to read the TS's post,
and show him the respect of a valid response.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top