View previous topic :: View next topic
|
Author |
Message |
suneelv
New User
Joined: 26 Aug 2008 Posts: 52 Location: inida
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
suneelv
New User
Joined: 26 Aug 2008 Posts: 52 Location: inida
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Are you initializing w-tally-1 before the second inspect? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
suneelv
New User
Joined: 26 Aug 2008 Posts: 52 Location: inida
|
|
|
|
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 |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
You need to move zero to W-TALLY-1 before each time the inspect statement is executed. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
suneelv
New User
Joined: 26 Aug 2008 Posts: 52 Location: inida
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
Just use the TALLY Special Register and you'll save yourself much grief.
Regards,
Bill |
|
Back to top |
|
|
|