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
 

 

how to remove zeroes from numeric field
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Fri Nov 14, 2008 7:05 pm    Post subject: how to remove zeroes from numeric field
Reply with quote

SUPPOSE I HAVE A NUMERIC FIELD OF LEGTH 6

w-num pic 9(06)

its value may be 000009 or 000099 or 000999.

i just want to move 9 0r 99 or 999 depending on the value of input.
i just want to remove the leading zeroes part and move the remaining field to other field. no of zeroes may vary from situation to situation.


is there any shorter solution other than comparing field by field
Back to top
View user's profile Send private message

Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Nov 14, 2008 7:25 pm    Post subject:
Reply with quote

Read this Link. It can help you.

I would say google is the best friend of a programmer. Try surfing once before you post. icon_cool.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Nov 14, 2008 7:32 pm    Post subject:
Reply with quote

Use reference modification:
Code:
          PERFORM
             VARYING I FROM 1 BY 1
                 UNTIL I > 6
             IF  W-NUM (I : 1) > '0'
                 MOVE W-NUM  (I : )  TO  WS-B
                 MOVE 7              TO  I
             END-IF
          END-PERFORM.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Nov 15, 2008 2:31 am    Post subject:
Reply with quote

Hello,

Quote:
I would say google is the best friend of a programmer. Try surfing once before you post.
Yup, google has zillions of "hits".

Before going to google, i'd suggest using our forum SEARCH. The hits here will be more directed to what you are looking for.

Quote:
i just want to remove the leading zeroes part and move the remaining field to other field.

Do you want the result right- or left-justified? If you want the result right-justified, you might just move the pic 9(6) field to an edited field ZZZZZ9?
Back to top
View user's profile Send private message
nelson.pandian

Active User


Joined: 09 Apr 2008
Posts: 133
Location: Phoenix, AZ

PostPosted: Sat Nov 15, 2008 11:55 pm    Post subject:
Reply with quote

Ajit,

Quote:
I just want to move 9 0r 99 or 999 depending on the value of input

If you move only the values to an other PIC 9(06) variable and try to display it or write into an file you will get the same output with leading zeros.
So i would like to suggest you to use the edited fields ZZZZZ9.
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Mon Nov 17, 2008 2:47 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

thanks all of you for help.

my program requirement is to use two digits out of the six digits if only two have values.

if only digit have value other than zero than just pick one digit out of six.
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Mon Nov 17, 2008 3:42 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

Hi,I am finding your posts little confusing ,In the beginning your requirement was some thing like
Quote:
its value may be 000009 or 000099 or 000999.
i just want to move 9 0r 99 or 999 depending on the value of input.

And now you desire to pick only two digits
Quote:
my program requirement is to use two digits out of the six digits if only two have values.
So is it right-justified or left-justified, I reckon it should right. Still,if the input value is 000109 , then what you believe your output should be.Please let us know.

Cris
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Mon Nov 17, 2008 3:48 pm    Post subject:
Reply with quote

if i input is 000109 i just want to pick 109

if input is 000010 i just want to pick 10

if input is 000111 i just want to pick 111
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Mon Nov 17, 2008 4:17 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

Thanks Ajit,
the solutions already posted i.e. use of edited fields ZZZZZ9 should suffice your requirement(Is this field used/displayed in report generation?). My fault got little confused after reading your penultimate post icon_smile.gif.
Cris
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Mon Nov 17, 2008 4:21 pm    Post subject:
Reply with quote

using zzz wil only supress zeroes
i just want to neglect leading zeroes and take the remaining digits out
and this length may be variable

and in my cobol substring doesn't work
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Nov 17, 2008 4:35 pm    Post subject:
Reply with quote

what is the definition of your final destination for this data?

are you having left/right justification problems?

what cobol substring (no such thing)? There is reference modification.

do you want to move only digits following a non-zero digit to another field?
provide the definition of the sending field and the receiving field.

you know what you want, but we do not.
you have half explained the first part:
Quote:
i just want to neglect leading zeroes and take the remaining digits

now, explain the second part: what is the definition of your final destination?
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Mon Nov 17, 2008 4:40 pm    Post subject:
Reply with quote

I have to string three fields for example as below

1st field w-A pic x(6) value abcdef
2nd field w-B pic 9(6) value 000024
3rd field w-C pic 9(6) value 000111


now at last i want output as abcdef/24/111
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Nov 17, 2008 5:05 pm    Post subject:
Reply with quote

Ajit007_cool,
excellent! you will now receive some clever suggestions from our forum friends.

the process would be to determine the number of characters (and location within the field) that would be strung together with W-A.

Code:

Move spaces to receiving-field

STRING w-A
          delimited by size
       w-B(<position of first non-zero/space char>:<remaining length of w-B to move>)
          delimited by size
       w-C(<position of first non-zero/space char>:<remaining length of w-C to move>)
          delimite by size
  into  Receiving-field
END-STRING
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Nov 17, 2008 9:25 pm    Post subject:
Reply with quote

Hello,

Quote:
I have to string three fields for example as below

1st field w-A pic x(6) value abcdef
2nd field w-B pic 9(6) value 000024
3rd field w-C pic 9(6) value 000111

now at last i want output as abcdef/24/111
Please reflect on what you have finally posted versus how you began the topic.

You will get useful answers much more quickly if you post your actual requirement right away rather than some incomplete, misleading question. All this does is waste everyone's time (including yours).
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Tue Nov 18, 2008 12:55 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

Ajit007_cool,
You can try this piece of code
Code:
01 A PIC X(06)  VALUE SPACES.
01 B PIC 9(06) VALUE ZEROES.
01 C PIC 9(06) VALUE ZEROES.
01 WS-TEMP PIC X(18) VALUE SPACES.
01 M PIC 9(02)  VALUE ZEROES.
01 I PIC 9(02)  VALUE ZEROES.
01 K PIC 9(02) VALUE ZEROES.
01 PTR1 PIC 99 VALUE 1.

UNSTRING A DELIMITED BY SPACE INTO WS-TEMP 
POINTER PTR1
COMPUTE PTR1 = PTR1 - 1
MOVE '/' TO WS-TEMP(PTR1:1)
PERFORM                                   
    VARYING I FROM 1 BY 1                 
        UNTIL I > 6                       
    IF  B(I : 1) > '0'                     
     COMPUTE   K = 7 - I                   
        MOVE B (I : )  TO  WS-TEMP(PTR1: K)
        MOVE 7              TO  I         
    END-IF                                 
END-PERFORM                               
COMPUTE PTR1 = PTR1 + K                     
MOVE '/' TO WS-TEMP(PTR1:1)                 
COMPUTE PTR1 = PTR1 + 1                     
PERFORM                                     
    VARYING I FROM 1 BY 1                   
        UNTIL I > 6                         
    IF  C(I : 1) > '0'                     
    COMPUTE     K = 7 - I                   
        MOVE C(I : )  TO  WS-TEMP(PTR1: K) 
        MOVE 7              TO  I           
     END-IF                                 
END-PERFORM


This would fail if variable A has spaces in between e.g. A = "abc de" or "ab de " .If you believe such a scenario can occur then u need to read the string A till the end and to check for spaces. Surely reference modification can be one good option to try for this as well.
Cris
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Tue Nov 18, 2008 1:06 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

Hi, I just checked my code ..the variable definition of field A should be taken as PIC X(7) value spaces.

Cris
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Tue Nov 18, 2008 1:57 pm    Post subject: Reply to: how to remove zeroes from numeric field
Reply with quote

Hi,For the string A you can use the following code if you dont wish to use
unstring option
Code:
A pic x(06) value spaces
MOVE 6 TO I
PERFORM  UNTIL I = 0
    IF  A(I : 1) <> SPACES
        MOVE A (1 :I )  TO  WS-TEMP(1: I)
        MOVE 0              TO  I         
    END-IF
     COMPUTE I = I - 1                               
END-PERFORM

Cris
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Wed Nov 19, 2008 9:44 pm    Post subject:
Reply with quote

problem is in my cobol sustring doesnt work so i cant use some thing like this

WS-TEMP(PTR1:1)

so if can anbody tell me

if i have field A pic Z(6) value ' 6'

so can i move this field B pic X(6) and it can appear like this '6 '
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Nov 19, 2008 10:07 pm    Post subject:
Reply with quote

Please tell me you're kidding about no reference modification -- it's been in the language for a long time (as in since the late 80's or early 90's -- even VS COBOL II had it)!

If you truly don't have reference modification, you can do a batch of redefines on A to isolate the right 5, 4, 3, 2, and 1 characters. Your move would be like
Code:
IF  A >= 100000
    MOVE A TO B
    ELSE IF A >= 10000
            MOVE A-5-CHAR TO B
...
Back to top
View user's profile Send private message
ajit007_cool

New User


Joined: 08 Sep 2008
Posts: 14
Location: basel

PostPosted: Wed Nov 19, 2008 10:16 pm    Post subject:
Reply with quote

can i supress leading spaces in a field and move the reamining value to some other field

delimited by leading spaces is there any command for this
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


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