View previous topic :: View next topic
|
Author |
Message |
rekuth123
New User
Joined: 16 Jul 2005 Posts: 3
|
|
|
|
Hi,
I have an input field declared as PIC X(40).
The following are the possible values for this input field
1. 3 Grams
2. 30 to 200 Milligrams
3. SPF 50
I have two output fields output-1 and output-2, both declared as PIC S9(4)V9(3) COMP-3.
For the input '3 Grams' I need to move 3 to both output-1 and output-2 as 3 is the only one number available in the input string.
For the input '30 to 200 Milligrams' I need to move 30 to output-1 and 200 to output-2.
For the input 'SPF 50' I need to move 50 to both output-1 and output-2.
Can you please let me know how can I achieve this in cobol.
I can do this using UNSTRING but when I tried to move the value to COMP-3 I'm getting SOC7. Could you please provide me the logic to achieve this? Thanks in advance. |
|
Back to top |
|
|
rekuth123
New User
Joined: 16 Jul 2005 Posts: 3
|
|
|
|
One more input case is 0.99 to 1 Milligram and 0.99 should be moved to output-1 and 1 should b emoved to output-2 |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi,
Why don't you show us the code (including the data defs) and where you're having the problem. It sure beats guessing.
A picture is worth a 1000 words. |
|
Back to top |
|
|
rekuth123
New User
Joined: 16 Jul 2005 Posts: 3
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
I would approach it something like this:
Unstring into pic x fields
Test the 2nd field to determine which of the 3 cases you described this one is. E.g., if fld 2 begins w/"G" it's case 1; if "t" it's case 2. If fld 1 is SPF it's case 3. Granted, I may be over simplifying but that's the general idea. Again you didn't indicate how many variations you're dealing with. I assumed 3.
From that you can determine where the numeric fields are are.
Take a look at NUMVAL or NUMVAL-C to convert the dec pts and spaces in the fields that contain the numerics. |
|
Back to top |
|
|
|