IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Why TALLYING field increments when there is no matching char


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 22, 2009 11:36 pm
Reply with quote

Hi,

I am declaring 2 varibles

01 W-TIME-3 PIC X(8).
01 W-TALLY-1 PIC 9.
w-time-3 may contains values 31:40:8 ---> beore 3 there is one space.
or it may conain 10:00:53

iam Inspecting the w-time-3 for leading space.

INSPECT W-TIME-3 TTALLYING W-TALLY-1 FOR LEADING SPACE.

if the W-TIME-3 contains 31:40:8 the W-TALLY-1=1 but
for W-TIME-3 contains 10:00:53 the W-TALLY-1=1

i am not getting why W-TALLY-1 is also 1 for 2nd one even there is no leading space.

Could any one help on this.

Regards
Suneel
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 22, 2009 11:45 pm
Reply with quote

From the COBOL Language Reference:
Quote:
identifier-2
Is the count field, and must be an elementary integer item defined without the symbol P in its PICTURE character-string.

Identifier-2 cannot be an external floating-point item.

You must initialize identifier-2 before execution of the INSPECT statement begins.
so where do you initialize W-TALLY-1 before each inspect statement?
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 22, 2009 11:56 pm
Reply with quote

Hi,

I have initialized the W-TALLY-1 before the inspect statement as

01 W-TALLY-1 PIC 9 VALUE ZERO.

Regards
suneel
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jan 23, 2009 12:08 am
Reply with quote

Are you initializing w-tally-1 before the second inspect?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 23, 2009 12:08 am
Reply with quote

Are you doing the two INSPECT statements in two separate program runs, or is there one program run with execution of both INSPECT statements? If the second, you need to move zero back to W-TALLY-1 before the second INSPECT statement.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 23, 2009 12:15 am
Reply with quote

hi,

I am using one Inspect staement in one program by reading each record in the sequential file till end.

if there is any record which has leading space for the w-time-3,i am doing some operation on the particular record

Regards
Suneel
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Fri Jan 23, 2009 12:29 am
Reply with quote

You need to move zero to W-TALLY-1 before each time the inspect statement is executed.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jan 23, 2009 12:36 am
Reply with quote

Hello,

Quote:
I have initialized the W-TALLY-1 before the inspect statement as
01 W-TALLY-1 PIC 9 VALUE ZERO.
This provides an initial value at program execution, but not "before the inspect statement". As mentioned above, you need to reset tally every time thru the code.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 23, 2009 12:39 am
Reply with quote

Quote:

i am not getting why W-TALLY-1 is also 1 for 2nd one even there is no leading space.
Because you failed to move zero to W-TALLY-1, and there were no leading spaces in the second field, W-TALLY-1 retained its initialized value. What is the initialized value? The value of 1 you set the variable to the LAST time through the code. Without clearing the value each time, the next INSPECT statement will start with the value from the last INSPECT statement.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 23, 2009 12:48 am
Reply with quote

Hi,

i have initialized the w-tally-1 each time before executing the INSPECT statement.

Its working fine.

Thanks for all your help.

Regards
Suneel
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 23, 2009 8:46 am
Reply with quote

Why don't you use the TALLY Special Register and initialize it every time to ZERO. It's implicitly defined as PIC 9(05) COMP.

A one-byte display-numeric Tally field certainly has its limitations, especially if the target-field length exceeds 9-Bytes.

You won't know the true value because overflow may have occurred. icon_redface.gif

Just use the TALLY Special Register and you'll save yourself much grief. icon_wink.gif

Regards,

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top