View previous topic :: View next topic |
Author |
Message |
rekuth123 Beginner
Joined: 12 Jul 2005 Posts: 7 Topics: 2
|
Posted: Mon Jul 18, 2005 9:43 am Post subject: Question on INSPECT |
|
|
I have an alphanumeric field defined as PIX x(40) and it's value is '0 to 4.99 Grams'.
After doing the UNSTRING on this input value I want to retrieve 0 and 4.99
and I'm moving it to a WS-TEST-FIELD
I'm doing the INSPECT on 0 and 4.99 (WS-TEST-FIELD) by using
INSPECT WS-TEST-FIELD TALLYING WS-TEMP-COUNT
FOR '0' '1' '2' '3' '4' '5' '6' '7' '8' '9'
but it's not allowing me saying that 0 is not allowed
and I tried using IF WS-TEST-FIELD NUMERIC but if use that I'm not able to retrieve 4.99 as it is not numeric.
Could you please tell me how to overcome this problem? |
|
Back to top |
|
 |
rekuth123 Beginner
Joined: 12 Jul 2005 Posts: 7 Topics: 2
|
Posted: Mon Jul 18, 2005 11:23 am Post subject: |
|
|
Can some one help me with this problem ASAP. Thanks in advance. |
|
Back to top |
|
 |
info_seeker Beginner
Joined: 31 Jan 2005 Posts: 27 Topics: 9
|
Posted: Mon Jul 18, 2005 3:43 pm Post subject: |
|
|
Hi,
You missed the "ALL" phrase in the code.
INSPECT WS-TEST-FLD TALLYING WS-TEMP-COUNT
FOR ALL '0' '1' '2' '3' '4' '5' '6' '7' '8' '9'.
This will give the count as 4. In b/w why are you using counting function (tallying) to extract the numeric values. Am I missing something here ( ??
-Seeker!!! |
|
Back to top |
|
 |
rekuth123 Beginner
Joined: 12 Jul 2005 Posts: 7 Topics: 2
|
Posted: Mon Jul 18, 2005 5:49 pm Post subject: |
|
|
Hi Seeker,
Thanks for your response.
My input case: ws-chr-vl-typ-nm - PIC X(40)
1. 0 to 4.99 Milligrams
Retrieve 0 and move it to ws-chr-mnm-vl - 9(04)v9(3)
and move 4.99 to ws-chr-mxm-vl - 9(04)v9(3)
2. 30 Grams
Retrieve 30 and move it to both ws-chr-mnm-vl and ws-chr-mxm-vl
The following is the code
05 WS-CHR-VL-TYP-NM PIC X(40).
05 WS-PTR PIC S9(4).
05 WS-SUB PIC S9(4).
05 WS-TEST-FIELD PIC X(40).
05 WS-HOLD-FIELD PIC X(40) JUST RIGHT.
05 HOLD-ARRAY OCCURS 2 TIMES.
10 WS-HOLD-VALUE PIC X(09) JUST RIGHT.
05 WS-TEMP-MNM.
10 WS-TEMP-MNM1 PIC X(09) JUST RIGHT.
10 WS-TEMP-MNM2 REDEFINES WS-TEMP-MNM1.
15 WS-CHR-MNM-VL PIC 9(05)V9(03).
05 WS-TEMP-MXM.
10 WS-TEMP-MXM1 PIC X(09) JUST RIGHT.
10 WS-TEMP-MXM2 REDEFINES WS-TEMP-MXM1.
15 WS-CHR-MXM-VL PIC 9(05)V9(03).
Code is:
MOVE +1 TO WS-PTR.
MOVE 'X' TO WS-HOLD-FIELD.
MOVE +1 TO WS-SUB.
PERFORM UNTIL WS-PTR > +40
OR WS-HOLD-FIELD = ' '
INITIALIZE HOLD-ARRAY(WS-SUB)
UNSTRING WS-CHR-VL-TYP-NM DELIMITED BY ' '
INTO WS-HOLD-FIELD POINTER WS-PTR
IF WS-HOLD-FIELD NOT = ' '
MOVE WS-HOLD-FIELD TO WS-TEST-FIELD
INSPECT WS-TEST-FIELD REPLACING ALL ' ' BY '0'
INSPECT WS-TEST-FIELD REPLACING ALL '.' BY '0'
IF WS-TEST-FIELD NUMERIC
INSPECT WS-HOLD-FIELD REPLACING ALL ' ' BY '0'
MOVE WS-HOLD-FIELD TO WS-HOLD-VALUE(WS-SUB)
ADD +1 TO WS-SUB
END-IF
END-IF
END-PERFORM.
MOVE WS-HOLD-VALUE(1) TO WS-TEMP-MNM1
IF WS-HOLD-VALUE(2) > SPACES
MOVE WS-HOLD-VALUE(2) TO WS-TEMP-MXM1
ELSE
MOVE WS-TEMP-MNM1 TO WS-TEMP-MXM1
END-IF
When I execute the above code
I have the following values
ws-chr-mnm-vl - 00000.000 which is what I want
ws-chr-mxm-vl - says it's an invalide decimal and I assume I was not able to move the value 00004.99 to this field and I need 4.990 to be moved.
For my second input case I'm getting
ws-chr-mnm-vl - 00000.003 which is wrong and I should have got as 30.000 only
Could you please let me know how could I achieve this? Thanks in advance |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sun Jul 24, 2005 10:22 pm Post subject: |
|
|
Rekuth,
You STILL haven't defined your problem so that we can provide a reasonable answer.
How do the parameters in your input vary? Can the next occurance of "0 to 4.99 milligrams" be "10.046 to 425.659 grams", etc. Can "30 Grams" be 1,486 Lbs?
Please define the input GENERALLY so that we can understand its variability.
A solution for the case you present may or may not be an adequate solution for ALL the I/P possibilities.
As I mentioned in another forum NUMVAL and/or NUMVAL-C may contain the solution ou're looking for. But before that can be determined you have to fully present all the problem's aspects.
Here's a way to use NUMVAL:
Define ws-comp-fld the way you would like the data in ws-hold to be.
compute ws-comp-fld = function numval (ws-hold-fld)
On thhe other hand you wanted to use the value in ws-hold in a calculation, you could also do this:
compute ws-total = (function numval (ws-hold-fld) * ws-x) / ws-y etc. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
|
|