Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
vina2010

New User

Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

 Posted: Mon Sep 06, 2010 5:45 pm    Post subject: Separating Alphanumeric string with Decimal values 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.

Binop B

Active User

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

 Posted: Mon Sep 06, 2010 5:51 pm    Post subject: 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....
vina2010

New User

Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

Posted: Mon Sep 06, 2010 6:29 pm    Post subject:

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?
tomehta

New User

Joined: 18 Aug 2008
Posts: 98
Location: India

Posted: Mon Sep 06, 2010 6:32 pm    Post subject: Reply to: Separating Alphanumeric string with Decimal values

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..
dbzTHEdinosauer

Global Moderator

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

Posted: Mon Sep 06, 2010 6:33 pm    Post subject:

 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
Binop B

Active User

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

Posted: Mon Sep 06, 2010 6:35 pm    Post subject:

 Quote: could you please guide me how I can use an INSPECT to separate the values.
I sincerely apologize... ... I had UNSTRING in mind when i suggested INSPECT... Apologize sincerely if I have made you loose your time...
vina2010

New User

Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

 Posted: Tue Sep 07, 2010 11:52 am    Post subject: 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. Really Thanks for the code.
dbzTHEdinosauer

Global Moderator

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

Posted: Tue Sep 07, 2010 2:26 pm    Post subject:

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

PeterHolland

Global Moderator

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

 Posted: Tue Sep 07, 2010 2:58 pm    Post subject: How about using real decimal point picture fields to UNSTRING into ? 01 Var1 PIC X(6). 01 Var1Num REDEFINES Var1 PIC 9(3).99
vina2010

New User

Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

 Posted: Tue Sep 07, 2010 3:53 pm    Post subject: 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.
dbzTHEdinosauer

Global Moderator

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

Posted: Tue Sep 07, 2010 4:01 pm    Post subject:

 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.
PeterHolland

Global Moderator

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

 Posted: Tue Sep 07, 2010 4:09 pm    Post subject: 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!
vina2010

New User

Joined: 06 Sep 2010
Posts: 19
Location: Bangalore

 Posted: Tue Sep 07, 2010 4:24 pm    Post subject: Ya Peter,to my bad luck it is a operand.
Keanehelp

New User

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

 Posted: Tue Sep 07, 2010 5:15 pm    Post subject: 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
dbzTHEdinosauer

Global Moderator

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

 Posted: Tue Sep 07, 2010 5:19 pm    Post subject: 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.
Keanehelp

New User

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

 Posted: Tue Sep 07, 2010 5:31 pm    Post subject: Hi Dick, I apologize, didn't read between the lines. Thanks
dbzTHEdinosauer

Global Moderator

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

 Posted: Tue Sep 07, 2010 5:39 pm    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics JDBC Driver -Default Values yogi.47eie DB2 0 Mon May 18, 2020 7:27 pm Get next 5 numeric from a string of '... maxsubrat COBOL Programming 7 Fri Apr 24, 2020 2:30 pm Convert a packed decimal value to zon... Dinesh Mani DB2 6 Mon Mar 16, 2020 6:02 pm Not able to view the values of variab... sattar_engg CA Products 1 Thu Jan 23, 2020 12:32 pm Finding a string and concatinating mu... ArunkumarGanesan DFSORT/ICETOOL 11 Thu Jan 09, 2020 5:59 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us