View previous topic :: View next topic
|
Author |
Message |
darakhshan
New User
Joined: 03 Mar 2008 Posts: 32 Location: India
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
i think your variable INPUT-R is missing leading spaces ... |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
anjankumar_r
New User
Joined: 22 May 2008 Posts: 7 Location: India
|
|
|
|
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 |
|
|
darakhshan
New User
Joined: 03 Mar 2008 Posts: 32 Location: India
|
|
|
|
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
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
What was the value of CNTR before the INSPECT? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Are you sure those a spaces or are they some other nodisplayable characters? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
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 |
|
|
|