View previous topic :: View next topic
|
Author |
Message |
rupeshgullu
New User
Joined: 05 Oct 2010 Posts: 9 Location: Chandigarh
|
|
|
|
Hi ,
I have one variable WS-TEST PIC X(10) VALUE 'ABC1D67892'
I want to get the count of leading alphabets i.e it should give me '3' in above case or if it is 'ABCD123456' it should give me count as '4'
how can i use Inspect verbin this case |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
What do you expect
when
Code: |
"0BCD123456"
" BCD123456"
"A 123456" |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Is there some particular reason to use INSPECT? |
|
Back to top |
|
|
rupeshgullu
New User
Joined: 05 Oct 2010 Posts: 9 Location: Chandigarh
|
|
|
|
Actually I have verified that data will be like 'ABCD123456' or 'ABC1D56789' it won't be as specified.
I want to use the count which comes while inspecting for processing down the line in program . That's why I want to use inspect |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Ok so the count would be atleast 3 and max of 4? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Give this a try (Only desk checked) -
Code: |
03 WS-TEST PIC X(10) VALUE 'ABC1D67892'.
03 WS-ALPHA-KTR PIC 9(08) COMP.
*
MOVE ZERO TO WS-ALPHA-KTR.
MOVE ZERO TO TALLY.
*
PERFORM UNTIL TALLY > LENGTH OF WS-TEST
IF (WS-TEST (TALLY:1) ALPHABETIC
AND WS-TEST (TALLY:1) NOT = SPACE)
ADD 1 TO WS-ALPHA-KTR
END-IF
ADD 1 TO TALLY
END-PERFORM.
|
Once the PERFORM completes, WS-ALPHA-KTR will equal 4.
HTH.... |
|
Back to top |
|
|
rupeshgullu
New User
Joined: 05 Oct 2010 Posts: 9 Location: Chandigarh
|
|
|
|
Sure will try and let u know.. count will be max upto 5 but i need to confirm... will post the result shortly |
|
Back to top |
|
|
rupeshgullu
New User
Joined: 05 Oct 2010 Posts: 9 Location: Chandigarh
|
|
|
|
It has given count of num of alphabets. what I want is that if I have alphanumeric values upto 5 bytes then it should give me count as 5
so that i can get all numeric values after 5 digits |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
So why not adjust the code? You did take the time to understand what the code is doing, didn't you? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
that is even not what you asked :
rupeshgullu wrote: |
... 'ABC1D67892' ... should give me '3'
... 'ABCD123456' ... should give me '4'
|
|
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
If I wanted the trailing numeric value of a field , this is how I would do it
(also not compiled on this end):
Code: |
03 ws-input pic x(10) value 'ABC1D67892'.
03 ws-numX.
05 ws-num9 pic 9(10).
move ws-input to ws-numX
PERFORM varying Ix from 10 by -1
until ix < 1
or WS-numX(Ix:1) ALPHABETIC
continue
END-PERFORM
if ix > 0
move all '0' to WS-numX (1:ix)
end-if |
|
|
Back to top |
|
|
rupeshgullu
New User
Joined: 05 Oct 2010 Posts: 9 Location: Chandigarh
|
|
|
|
I have modified the code as below:
Code: |
MOVE ZEROS TO WS-SPACE-COUNTER3.
MOVE ZEROS TO WS-SPACE-COUNTER4.
MOVE ZEROS TO TALLY.
PERFORM UNTIL TALLY > LENGTH OF WS-ORDER-NO-REV
ADD 1 TO WS-SPACE-COUNTER3
IF (WS-ORDER-NO-REV (TALLY:1) IS ALPHABETIC
AND WS-ORDER-NO-REV (TALLY:1) NOT = SPACES)
MOVE WS-SPACE-COUNTER3 TO WS-SPACE-COUNTER4
END-IF
ADD 1 TO TALLY
END-PERFORM. |
Code'd |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
rupeshgullu,
Why do you not use the code tags to present your code in a readable manner with proper indentation as other people have done? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
rupeshgullu,
You have to bear in mind that we don't know what you want, but you do.
You have told us, with some contradictions, how you want to do what you want, but we don't know what you are trying to achieve.
Have you tested your solution with A1B2C12345?
With Bill's solution, why don't you just stop after looking at five bytes or when you find a numeric?
With GuyC's, just start from five and wind down.
If you are going to attempt to use what you end up with for some calculation, please check it for NUMERIC first.
Rather than ALPHABETIC or SPACE, why not NOT NUMERIC? It'll be less of a strain on the old CPU and more directly describe what you are doing - perhaps, because we don't know. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
It appears that there may not be an actual requirement. Just some wonder about "what if I have . . . ".
Suggest rupeshgullu explain what kind of data this would support. |
|
Back to top |
|
|
|