Convert Char to Numeric



Unicenter CA-Easytrieve Plus Report Generator: CA's information retrieval and data management tool

Convert Char to Numeric

Postby pbc3199 » Thu Jun 17, 2010 7:46 am

Dear all,
I'm Easytrieve beginner. COuld you please show mw the sample coding how to convert char to numeric?
pbc3199
 
Posts: 6
Joined: Thu Jun 17, 2010 7:43 am
Has thanked: 0 time
Been thanked: 0 time

Re: Convert Char to Numeric

Postby dick scherrer » Thu Jun 17, 2010 8:10 am

Hello and welcome to the forum,

Post the cobol picture of the input and the output fields you want to convert. Show some sample input values.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Convert Char to Numeric

Postby pbc3199 » Thu Jun 17, 2010 1:54 pm

My input file have WS-SERIAL 5 N.
I want to set to WS-SERIAL-NO 5 A
pbc3199
 
Posts: 6
Joined: Thu Jun 17, 2010 7:43 am
Has thanked: 0 time
Been thanked: 0 time

Re: Convert Char to Numeric

Postby dick scherrer » Fri Jun 18, 2010 2:13 am

Hello,

You will do better in the future if you provide what is requested rather than something else you choose to post. . . This time - no problem, but often there are delays when people do not provide requested info.

This:
DEFINE WS-SERIAL    W 5 N VALUE 234   
DEFINE WS-SERIAL-NO W 5 A         
WS-SERIAL-NO = WS-SERIAL                       
DISPLAY 'WS-SERIAL-NO AFTER NOVE ' WS-SERIAL-NO


Gives:
WS-SERIAL-NO AFTER NOVE 00234
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Convert Char to Numeric

Postby NicC » Fri Oct 01, 2010 3:11 pm

raj1984 wrote:It's a very simple program.

First, determine the amount of numbers entered. Then convert each char number into an integer. So, let's say you have 3 numbers - 1, 2, and 3. Declare an integer multiplier variable and set it equal to 1. Declare a float sum and set it equal to 0. Then do this algorithm:

Multiply the last number by multiplier and add it to a sum.
Multiply the multiplier by 10.
Repeat with the next number.

So with 1, 2, and 3 the algorithm will look like - 3 + 20 + 100, which in the end will give you the float sum that equals to 123.


Why do all that when a simple assignment will do as shown by Dick?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Convert Char to Numeric

Postby NicC » Fri Oct 01, 2010 3:11 pm

Oh - I see. You are spamming.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Convert Char to Numeric

Postby kramana9999 » Fri Oct 01, 2010 8:56 pm

use function numval(char dataitem)
kramana9999
 
Posts: 1
Joined: Fri Sep 24, 2010 10:42 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Convert Char to Numeric

Postby dick scherrer » Fri Oct 01, 2010 11:54 pm

Hello and welcome to the forum,

use function numval(char dataitem)
Have you tested this in Easytrieve to be sure it works. . .

Please do not post untested "solutions".
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Convert Char to Numeric

Postby Scott Lippincott » Fri Oct 15, 2010 11:28 am

In Dick's code sample there is no difference in the contents of WS-SERIAL and WS-SERIAL-NO after the assignment. The difference in the way they are displayed is due to the application of a default edit mask.
DEFINE WS-SERIAL W 5 N VALUE 234
DEFINE WS-SERIAL-NO W 5 A
WS-SERIAL-NO = WS-SERIAL
DISPLAY 'WS-SERIAL-NO AFTER NOVE ' WS-SERIAL-NO
In fact, the two fields could redefine the same storage; making the assignment unnecessary.
DEFINE WS-SERIAL W 5 N VALUE 234
DEFINE WS-SERIAL-NO WS-SERIAL 5 A
DISPLAY 'WS-SERIAL = ' WS-SERIAL
DISPLAY 'WS-SERIAL-NO = ' WS-SERIAL-NO
Results in the following:
WS-SERIAL = 234
WS-SERIAL-NO = 00234
The difference is that the default edit mask is applied to the numeric definition. (WS-SERIAL)
DEFINE WS-SERIAL W 5 N VALUE 234 MASK('99999')
DISPLAY 'WS-SERIAL = ' WS-SERIAL
Results in the following:
WS-SERIAL = 00234

Some useful Easytrieve notes:
Numeric data (N or P) defined without a number of decimal places coded is always stored as a positive integer using a sign nibble of x'F'
DEFINE WS-NUM W 6 N VALUE 100 contains hex 'F0F0F0F1F0F0'
DEFINE WS-NUM W 4 P VALUE 100 contains hex '0000100F'

Numeric data (N or P) defined with a number of decimal places coded is stored as above, but the field is signed. Positive numbers are stored as above, and negative numbers are stored with a sign nibble of x'D'.
DEFINE WS-NUM W 6 N 0 VALUE -100 contains hex 'F0F0F0F1F0D0'
DEFINE WS-NUM W 4 P 0 VALUE -100 contains hex '0000100D'

Just one thing that the manual doesn't tell you. Numeric data specified without indicating the number of decimal places is treated as character data in reports. (it does not get accumulated into control total lines) If you want integer totals in report control totals, you must code the number of decimal positions as 0 (zero)
Scott Lippincott
 
Posts: 5
Joined: Wed Jul 28, 2010 7:30 am
Has thanked: 0 time
Been thanked: 1 time


Return to CA-Easytrieve

 


  • Related topics
    Replies
    Views
    Last post