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
 

 

Inspect Tally always coming as zero

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject:
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    Post subject:
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: 1288
Location: Chennai, India

PostPosted: Fri May 23, 2008 7:29 pm    Post subject: Reply to: Inspect Tally always coming as zero
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    Post subject:
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    Post subject: Reply to: Inspect Tally always coming as zero
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Mon May 26, 2008 7:01 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon May 26, 2008 7:43 pm    Post subject: Re: Inspect Tally always coming as zero
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    Post subject:
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    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 Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm
No new posts Using Inspect in cobol Ajay Dwivedi COBOL Programming 8 Sat Sep 26, 2015 11:33 pm
No new posts EQUIVALENT OF COBOL INSPECT IN REXX pshongal CLIST & REXX 2 Fri Nov 22, 2013 10:44 am
No new posts Find the occurrence of keywords using... suraaj COBOL Programming 15 Fri Aug 30, 2013 8:27 pm
No new posts Inspect using replace dharmaraok COBOL Programming 9 Fri Aug 16, 2013 10:28 pm


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