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 find the count and divide by that many zeros

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

New User


Joined: 02 May 2008
Posts: 72
Location: chennai

PostPosted: Tue Aug 19, 2008 10:19 am    Post subject: how to find the count and divide by that many zeros
Reply with quote

hi,

i have an variable decared as

03 WS-SAFECRT PIC 9(4).

the values can be like WS-SAFECRT = 1234, WS-SAFECRT = 0102,
WS-SAFECRT=0045

i need to take the valid values of the variable (i.e) remove the leading zeros and take the length of the vaibable and divide by 1000,1000,100 corresponding to the original length of the variable

if WS-SAFECRT = 1234 then RESULT = WS-SAFECRT/10000 (since lenght of 1234 is 4 hence dividing by 10000)
WS-SAFECRT = 0102 then RESULT = WS-SAFECRT/1000 (since lenght of 0102 is 3 hence dividing by 1000)
WS-SAFECRT = 0045 then RESULT = WS-SAFECRT/100 (since lenght of 0045 is 2 hence dividing by 100)

how can this be done in cobol
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: Tue Aug 19, 2008 11:03 am    Post subject:
Reply with quote

Hello,

Code:
IF WS-SAFECRT > 999 COMPUTE THE-RESULT = WS-SAFECRT / 10000
and so on . . .
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Aug 19, 2008 3:05 pm    Post subject:
Reply with quote

Hi Vidya,

below is the logic am giving to you
on that line you can build code


divvalue=1
temp=yourno

do until temp > = 1
{
divvalue=divvalue*10
temp=yourno/10

yourno=temp
}

eg if yourno is 1234 then divvalue will be 10000
if yourno is 0123 then divvalue will be 1000
if yourno is 0 then divvalue will be 1 ie no zeros ( icon_smile.gif )
Back to top
View user's profile Send private message
mytags

New User


Joined: 28 Apr 2008
Posts: 63
Location: US

PostPosted: Tue Aug 19, 2008 4:23 pm    Post subject:
Reply with quote

Hi
Using if condition is the easiest ways.As Dick said.
Thanks
Mytags
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Aug 19, 2008 4:30 pm    Post subject:
Reply with quote

but then it will be hard coded and only work for number for which if is coded

above is generic logic works for any no of digits icon_smile.gif
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: Tue Aug 19, 2008 9:48 pm    Post subject:
Reply with quote

Hello,

Quote:
but then it will be hard coded and only work for number for which if is coded
I believe you misunderstand. There will be only 1 value hard-coded for each 999, 99, and 9. This will run much more efficiently than the loop which will use many cpu cycles unnecessarily.

"Any number of digits" should not be an issue as the field only holds 4 digits.

The loop would not be obvious to many who read the code. It is best to implement code that is correct, easily maintainable, and does not use more system resource than needed.
Back to top
View user's profile Send private message
vidyaa

New User


Joined: 02 May 2008
Posts: 72
Location: chennai

PostPosted: Wed Aug 20, 2008 3:02 pm    Post subject:
Reply with quote

Hi Dick,

Thank you so much and it works great.
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: Wed Aug 20, 2008 9:01 pm    Post subject: Reply to: how to find the count and divide by that many zero
Reply with quote

Hi Vidya,

You're welcome icon_smile.gif

Thank you for letting us know it is working.

d
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 CICS Transaction attach count of supp... lind sh CICS 1 Wed Jun 21, 2017 1:33 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am


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