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

Inspect Tally always coming as zero


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

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Fri May 23, 2008 6:36 pm
Reply with quote

i tried this:

INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.

to trim initialy spaces of a string. but my cntr value is always coming as zero. Am i missing something?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri May 23, 2008 7:13 pm
Reply with quote

i think your variable INPUT-R is missing leading spaces ...
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Fri May 23, 2008 7:29 pm
Reply with quote

Darakshan,

Quote:
to trim initialy spaces of a string


Post few more details as to how u r input field, CNTR looks and all.

Your statement is syntatically correct.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri May 23, 2008 7:31 pm
Reply with quote

You might also try initing CNTR to 0 (or 1 if you want the ptr to the 1st non blank char in the field.
Back to top
View user's profile Send private message
anjankumar_r

New User


Joined: 22 May 2008
Posts: 7
Location: India

PostPosted: Mon May 26, 2008 3:37 pm
Reply with quote

Put display of INPUT-R variable and find out whether it actually contains any spaces.

If not working, provide us declaration of the INPUT-R, CNTR and the value of INPUT-R.
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Mon May 26, 2008 6:17 pm
Reply with quote

the input-r variable is declared as

Code:
01 ws-input.                           
   49 input-LEN      PIC S9(5) COMP.
   49 input-r          PIC X(32000).   

01 CNTR                    PIC 9(3).

input-r has this
Code:
  01|qwf,0223,987,;


i tried the following:

INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.

i displayed the cntr value and i got the value as 000
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon May 26, 2008 7:01 pm
Reply with quote

What was the value of CNTR before the INSPECT?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Mon May 26, 2008 7:08 pm
Reply with quote

Are you sure those a spaces or are they some other nodisplayable characters?
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: Mon May 26, 2008 7:43 pm
Reply with quote

You need to define CNTR (at a minimum) as PIC 9(05) and ensure that you initialize it to ZERO before any INSPECT TALLYING.

What would happen if the number of leading spaces in "input-r" is greater than 999? Yep, you'll have an overflow condition and CNTR will be reset back to 000 and you'll start the counting process again.

Why don't you use use the TALLY SPECIAL REGISTER or define CNTR as PIC 9(08) COMP/COMP-4/BINARY/COMP-5, etc and again, ensure that you initialize it first.

FWIW, I don't particularly like INSPECT TALLYING because it causes a CALL to a COBOL run-time routine, which ultimately, searches the target field for leading spaces anyway. So, why not just keep it in-line?

With that, a PERFORM UNTIL would be more efficient and you're in more control -

Code:

03  CNTR PIC 9(08) BINARY.
*
MOVE 1 TO CNTR.
MOVE ZERO TO TALLY.
*
PERFORM UNTIL CNTR > LENGTH OF INPUT-R
    IF  INPUT-R (CNTR:1) > SPACE
        MOVE CNTR TO TALLY
        MOVE LENGTH OF INPUT-R TO CNTR
    ELSE
        MOVE SPACE TO INPUT-R (CNTR:1)
    END-IF
    ADD 1 TO CNTR
END-PERFORM.

Once the PERFORM is complete, if TALLY is non-zero, it will contain the position in INPUT-R that contains the first byte that exceeds a SPACE.

As a precaution, whenever a byte-value is found that is not greater than a SPACE, then it is populated with a SPACE, to ensure that it didn't contain a value which was less than a SPACE (which covers byte-values from X'00' through X'3F').

Later,

Bill
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Tue May 27, 2008 6:52 am
Reply with quote

Code:
PERFORM UNTIL CNTR > LENGTH OF INPUT-R
    IF  INPUT-R (CNTR:1) > SPACE
        MOVE CNTR TO TALLY
        MOVE LENGTH OF INPUT-R TO CNTR
    ELSE
        MOVE SPACE TO INPUT-R (CNTR:1)
    END-IF
    ADD 1 TO CNTR
END-PERFORM.

Thanks for the code to get rid of those characters whose byte-value is lower than space.
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 No sysout coming in spool JCL & VSAM 4
No new posts Expected data is not coming up on Fir... CICS 2
No new posts Inspect in Assemebler PL/I & Assembler 10
No new posts Help needed with INSPECT COBOL Programming 3
No new posts Inspect statement COBOL Programming 5
Search our Forums:

Back to Top