View previous topic :: View next topic
|
Author |
Message |
sungang77
New User
Joined: 03 Nov 2005 Posts: 46 Location: Shanghai, China
|
|
|
|
If BMS map has a field, length is 8.
We don't know what the user will input.
Then we get the variable of this field in CICS program.
for example: the variable we input is(b stand for blank, s stand for space): "b76bs85s", we want check if we can convert it to '7685'.
What's the best way to judge if it's a legal numeric and convert it to a numeric?
Great thanks!!!!! |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
You can try this code:
Code: |
WORKING-STORAGE SECTION.
01 WS-INPUT PIC X(8).
01 WS-NBR PIC 9(8).
01 SUB1 PIC S9(5) COMP-3.
01 SUB2 PIC S9(5) COMP-3.
01 LEN2 PIC S9(5) COMP-3.
PROCEDURE DIVISION.
MOVE LENGTH OF WS-NBR TO LEN2.
MOVE 0 TO WS-NBR.
MOVE ' 76 85 ' TO WS-INPUT.
PERFORM P2000-CONVERT THRU P2000-EXIT.
MOVE 0 TO WS-NBR.
MOVE 'S76 85 ' TO WS-INPUT.
PERFORM P2000-CONVERT THRU P2000-EXIT.
GOBACK.
P2000-CONVERT.
DISPLAY 'WS-INPUT >' WS-INPUT '<'.
MOVE LEN2 TO SUB2.
PERFORM
VARYING SUB1 FROM LENGTH OF WS-INPUT BY -1
UNTIL SUB1 < 1
IF WS-INPUT(SUB1:1) NUMERIC
THEN
MOVE WS-INPUT(SUB1:1) TO WS-NBR(SUB2:1)
SUBTRACT 1 FROM SUB2
ELSE
IF WS-INPUT(SUB1:1) = ' '
THEN
CONTINUE
ELSE
DISPLAY 'WS-INPUT >' WS-INPUT '< NON NUMERIC'
END-IF
END-IF
END-PERFORM.
DISPLAY 'WS-NBR >' WS-NBR '< FROM WS-INPUT >' WS-INPUT '<'.
DISPLAY ' '.
P2000-EXIT.
EXIT.
|
results of the execution of this program
Code: |
WS-INPUT > 76 85 <
WS-NBR >00007685< FROM WS-INPUT > 76 85 <
WS-INPUT >S76 85 <
WS-INPUT >S76 85 < NON NUMERIC
WS-NBR >00007685< FROM WS-INPUT >S76 85 <
|
Dave |
|
Back to top |
|
|
mainframemouli
New User
Joined: 01 Mar 2005 Posts: 52 Location: Mysore
|
|
|
|
david ,
your answer is specific to the example the author has given .
I think the author needs generalized solution.
All your cics programs should have the normalization step to handle this situation.
try checking out NUMVAL and NUMVAL-C functions of cobol...i am not sure. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
NUMVAL and NUMVAL-C both abend if the input value is not numeric.
My intention was not to code sungang77's program for him. My assumption is that he's intelligent enough to use the code example as a base, though I?m not sure what input condition will not work.
Dave |
|
Back to top |
|
|
sungang77
New User
Joined: 03 Nov 2005 Posts: 46 Location: Shanghai, China
|
|
|
|
Thanks, Dave, and others.
I am sorry I do not see your answer until today because I am busy these days.
I know what you mean. It must work.
I forgot to tell you about y assumption is user can input anything.
If there's none numeric(not include space) in user's input, the repeat part should break as soon as program detect it, how can we improve the code?
Another thing, can we delete the space before we perform the repeat part?
P.S: I haven't use 'inspect' in cobol before, can it used in such situation? |
|
Back to top |
|
|
vivek_mvs
New User
Joined: 25 Apr 2006 Posts: 2 Location: United States
|
|
|
|
Hi,
I think you can try this is CICS
Code: |
EXEC CICS BIF DEEDIT
FIELD(CONTG)
LENGTH(9)
END-EXEC |
Results
CONTG before execution CONTG after execution
Original value Returned value
14-6704/B 00146704B
$25.68 000002568
It extracts all the numer values and put it back in the variable
This removes all characters other than digits from CONTG, a 9-byte field, and returns the edited result in that field to the application program.Note that a decimal point is an EBCDIC special character and as such is removed.
Thanks
Vivek |
|
Back to top |
|
|
sungang77
New User
Joined: 03 Nov 2005 Posts: 46 Location: Shanghai, China
|
|
|
|
Thanks so much, Vivek.
I have a question. As you refered, "This removes all characters other than digits from CONTG", why in the first example, the character "B" is still in the returned value? |
|
Back to top |
|
|
|