View previous topic :: View next topic
|
Author |
Message |
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
One of the filed has values like
111-222-333
111/222/333
111 222 333
111-222/333
I need convert all these values to 11122233.I need to remove all these dashes,slashes and spaces .. and need to convert into a numeric char.
How can i do it ? can i do it by INSPECT verb.Can anybody let me know the syntax
Thanks |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi Abi
You can use rerference modification to achieve this.
Code: |
WORKING-STORAGE SECTION.
01 ALPHANUM PIC X(11).
01 NUM.
02 N1 PIC 999.
02 N2 PIC 999.
02 N3 PIC 999.
PROCEDURE DIVISION.
MOVE ALPHANUM(1:3) TO N1.
MOVE ALPHANUM(5:3) TO N2.
MOVE ALPHANUM(9:3) TO N3.
DISPLAY NUM.
STOP RUN.
|
|
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Or you can use the STRING verb also.Here is the syntax.
Code: |
WORKING-STORAGE SECTION.
01 ALPHANUM PIC X(11) VALUE '123 456/789'.
01 NUM.
02 N1 PIC 999.
02 N2 PIC 999.
02 N3 PIC 999.
PROCEDURE DIVISION.
MAIN.
UNSTRING ALPHANUM DELIMITED BY '/' OR '-' OR ' '
INTO N1, N2, N3
DISPLAY NUM
STOP RUN.
|
Thanks
Arun |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi arcvns,
You need one missing piece to complete your 2 ans:
Code: |
01 NUM-NUM REDEFINES NUM PIC S9(9). |
As previously written NUM cannot be used in an arith stmt. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Thanks for correcting me.I was not sure if any arithmetic stmts are using this NUM. |
|
Back to top |
|
|
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
Thanks for the replies... I also have datas like
/188-160 4/
026 375 3/
028-625 7
how to convert these into non-numeric |
|
Back to top |
|
|
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
sorry how to convert these into numeric |
|
Back to top |
|
|
surya_pathaus
Active User
Joined: 28 Aug 2006 Posts: 110
|
|
|
|
Hi,
This can work for you for all types of strings which you mentioned...
Code: |
MOVE LENGTH OF SOURCE-STRING TO K
MOVE LENGTH OF TARGET-STRING TO J
PERFORM VARYING I FROM K DOWN BY 1 UNTIL K < I
IF IS NUMERIC(I : 1)
MOVE SOURCE-STRING(I : 1) TO TARGET-STRING(J : 1)
SUBTRACT 1 FROM J
END-IF
END-PERFORM
|
|
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi surya
I tried to execute your code and ended up with some compile-time errors.
I think it should be like this
Code: |
PERFORM VARYING I FROM K BY -1 UNTIL I < 1
IF ALPHANUM(I : 1) IS NUMERIC
MOVE ALPHANUM(I : 1) TO RESULT(J : 1)
SUBTRACT 1 FROM J
END-IF
END-PERFORM
|
Correct me if I am wrong
Thanks
Arun |
|
Back to top |
|
|
surya_pathaus
Active User
Joined: 28 Aug 2006 Posts: 110
|
|
|
|
Hi Arun,
Ya. That code is not tested. I gave it as algorithm. Just to give the idea about the logic.
Thanks. Tested the code and corrected.
Is it giving proper results as required? |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Ya...its working fine.
Thanks
Arun |
|
Back to top |
|
|
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
Hi arcvns
What should the value of I be .... shld move the the value of K to I ? |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi Abi
You dont need to move any particular value to I.You need to move only the lengths of source and target strings to K and J respectively.
Thanks
Arun |
|
Back to top |
|
|
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
Hi
I treid to execute the above code .Non-numeric fields were eliminated.But got one problem.
when i converted the value 188-160 4/
in the traget string i got the value as " 1881604" .I ogt additional 3 spaces in the front.How to remove that space. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi Abi
In the above code the result will get stored in a numeric variable(right justified with leading zeros) as the target variable I have defined is
01 RESULT PIC S9(18) VALUE 0.
When I tried with your input I am getting 000000000001881604.Is nt that matching with your expected result?
Please correct me if wrong
Thanks
Arun |
|
Back to top |
|
|
Abi
New User
Joined: 27 Jul 2005 Posts: 35 Location: Chennai
|
|
|
|
Hi,
I tried this below code & it i got the expected values.
MOVE LENGTH OF SOURCE-STRING TO K
MOVE 1 TO J
PERFORM VARYING I FROM 1 BY 1 UNTIL I > K
IF ALPHANUM(I : 1) IS NUMERIC
MOVE ALPHANUM(I : 1) TO RESULT(J : 1)
ADD 1 TO J
END-IF
END-PERFORM
Thanks for your suggestions. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi Abi
Please let me know hw did u define your destination variable.is it PIC X or PIC 9?
Thnks
Arun |
|
Back to top |
|
|
|