Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert non numeric fields to Numeric fields in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Wed Nov 22, 2006 7:14 pm    Post subject: Convert non numeric fields to Numeric fields in COBOL
Reply with quote

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
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Wed Nov 22, 2006 7:30 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Wed Nov 22, 2006 7:47 pm    Post subject: Re: Need to convert non numeric fields to Numeric fields
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Nov 23, 2006 6:18 am    Post subject:
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Thu Nov 23, 2006 9:39 am    Post subject: Re: Need to convert non numeric fields to Numeric fields
Reply with quote

Thanks for correcting me.I was not sure if any arithmetic stmts are using this NUM.
Back to top
View user's profile Send private message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Thu Nov 23, 2006 2:14 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Thu Nov 23, 2006 2:17 pm    Post subject:
Reply with quote

sorry how to convert these into numeric
Back to top
View user's profile Send private message
surya_pathaus

Active User


Joined: 28 Aug 2006
Posts: 110

PostPosted: Thu Nov 23, 2006 2:43 pm    Post subject: Re: Need to convert non numeric fields to Numeric fields
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Thu Nov 23, 2006 4:24 pm    Post subject: Re: Need to convert non numeric fields to Numeric fields
Reply with quote

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
View user's profile Send private message
surya_pathaus

Active User


Joined: 28 Aug 2006
Posts: 110

PostPosted: Thu Nov 23, 2006 4:39 pm    Post subject: Re: Need to convert non numeric fields to Numeric fields
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Thu Nov 23, 2006 4:48 pm    Post subject:
Reply with quote

Ya...its working fine.

Thanks
Arun
Back to top
View user's profile Send private message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Fri Nov 24, 2006 4:50 pm    Post subject:
Reply with quote

Hi arcvns

What should the value of I be .... shld move the the value of K to I ?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Fri Nov 24, 2006 5:47 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Mon Nov 27, 2006 10:29 am    Post subject:
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Mon Nov 27, 2006 11:33 am    Post subject:
Reply with quote

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
View user's profile Send private message
Abi

New User


Joined: 27 Jul 2005
Posts: 35
Location: Chennai

PostPosted: Wed Nov 29, 2006 6:53 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Wed Nov 29, 2006 7:04 pm    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Sum Fields ballaswaroop DFSORT/ICETOOL 4 Tue May 02, 2017 11:07 am
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us