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

To get alphabet count in variable


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

New User


Joined: 05 Oct 2010
Posts: 9
Location: Chandigarh

PostPosted: Wed Nov 27, 2013 8:31 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Nov 27, 2013 8:36 pm
Reply with quote

What do you expect

when

Code:
"0BCD123456"
" BCD123456"
"A 123456"
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 27, 2013 9:03 pm
Reply with quote

Hello,

Is there some particular reason to use INSPECT?
Back to top
View user's profile Send private message
rupeshgullu

New User


Joined: 05 Oct 2010
Posts: 9
Location: Chandigarh

PostPosted: Wed Nov 27, 2013 9:24 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Nov 27, 2013 9:26 pm
Reply with quote

Ok so the count would be atleast 3 and max of 4?
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: Wed Nov 27, 2013 10:07 pm
Reply with quote

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
View user's profile Send private message
rupeshgullu

New User


Joined: 05 Oct 2010
Posts: 9
Location: Chandigarh

PostPosted: Wed Nov 27, 2013 10:30 pm
Reply with quote

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
View user's profile Send private message
rupeshgullu

New User


Joined: 05 Oct 2010
Posts: 9
Location: Chandigarh

PostPosted: Thu Nov 28, 2013 12:30 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Nov 28, 2013 2:05 pm
Reply with quote

So why not adjust the code? You did take the time to understand what the code is doing, didn't you?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Nov 28, 2013 3:30 pm
Reply with quote

that is even not what you asked :
rupeshgullu wrote:
... 'ABC1D67892' ... should give me '3'
... 'ABCD123456' ... should give me '4'
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Nov 28, 2013 3:47 pm
Reply with quote

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
View user's profile Send private message
rupeshgullu

New User


Joined: 05 Oct 2010
Posts: 9
Location: Chandigarh

PostPosted: Thu Nov 28, 2013 4:14 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Nov 28, 2013 4:44 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Nov 29, 2013 2:10 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 02, 2013 5:51 am
Reply with quote

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
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top