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

Regarding to find whether lower case or higher case is prese


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

New User


Joined: 24 Dec 2007
Posts: 3
Location: chennai

PostPosted: Wed Oct 08, 2008 5:51 pm
Reply with quote

Hi all,
I have a scenario like this.

I have a variable declaration like this.

01 ws-var1 pic x(30) value 'aaaaaAAAAA vvvvvv'.

I have to find out the number of lowercase letters present in this variable.

Is it possible to do it in cobol?

Thanks,
Dhilip
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 08, 2008 6:12 pm
Reply with quote

Code:
           05  IN-VAR                  PIC X(30)
               VALUE 'abcde ABCDE fghij FGHIJKLMNOPQ'.
           05  WS-LC-COUNT             PIC 9(04) VALUE ZERO.
           05  WS-IN-LOC               PIC 9(02).
           05  WS-VAR-LOC              PIC 9(02).
           05  WS-LC-VARS              PIC X(26)
               VALUE 'abcdefghijklmnopqrstuvwxyz' .

           PERFORM
              VARYING WS-IN-LOC
                  FROM 1 BY 1
                  UNTIL WS-IN-LOC > 30
              PERFORM
                  VARYING WS-VAR-LOC
                      FROM 1 BY 1
                      UNTIL WS-VAR-LOC > 26
                  IF  IN-VAR (WS-IN-LOC : 1) =
                      WS-LC-VARS (WS-VAR-LOC : 1)
                      ADD 1            TO  WS-LC-COUNT
                  END-IF
              END-PERFORM
           END-PERFORM
               .
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Wed Oct 08, 2008 6:43 pm
Reply with quote

Dhilip,
You can try this aswell -
Code:

 Z= 0
 K= 0
 PERFORM UNTIL Z = (LENGTH OF D)                   
    COMPUTE Z = Z + 1                             
    IF FUNCTION UPPER-CASE (D(Z:1))  NOT EQUAL D(Z:1) 
      COMPUTE K = K + 1     
    END-IF
 END-PERFORM     

The value of K will have the number of lower case elements encountered.
Hope this helps.

Cris
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 08, 2008 6:44 pm
Reply with quote

You can achieve this by using intrinsic function ORD
below is the code
Code:

*DD

01 MYVAR.                                       
   02 UL  PIC X(30) VALUE 'aaaaaAAAAA vvvvvv'.   
   02 UL1 REDEFINES UL PIC X OCCURS 30 TIMES.   
01 LOWERCNT PIC 99 VALUE 0.                     
01 LCNT PIC 99 VALUE 1.                       

*PD

PERFORM CNTLOWER 30 TIMES.               
DISPLAY "LOWER CASE CNT:" LOWERCNT.       
STOP RUN.

CNTLOWER.                                               
    IF FUNCTION ORD(UL1(LCNT)) >= FUNCTION ORD('a') AND 
       FUNCTION ORD(UL1(LCNT)) <= FUNCTION ORD('z') THEN
    COMPUTE LOWERCNT = LOWERCNT + 1.                     
    COMPUTE LCNT = LCNT + 1.                             
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 08, 2008 7:09 pm
Reply with quote

Sambhaji: try your code on a string with a tilde (~) in it. Since the EBCDIC collating sequence is not contiguous for the lower case alphabet, your code can pick up spurious lower case values, such as a tilde. To do what the origianl poster wnated, you need three separate comparisons for the range 'a' to 'i', 'j' to 'r', and 's' to 'z' or your count may be off.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Oct 08, 2008 7:11 pm
Reply with quote

Quote:

I have to find out the number of lowercase letters present in this variable.


Robert Sample's solution works.

Cris, you managed to count the non-uppercase; not the lowercase.

Sambhaji, if you were to check out the ebcdic chart
you will find that there are values between i and j and r and s that are not lowercase.

here is a link: www.lookuptables.com/ebcdic_scancodes.php
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 08, 2008 7:13 pm
Reply with quote

Thanks, Dick -- I tested that code before posting it.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Oct 08, 2008 7:43 pm
Reply with quote

Robert,
that is the difference between a profi and a chair-weight,
of which you have proven many times over,
that you are a member of the first group.

learned a lot following your posts.
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Wed Oct 08, 2008 7:44 pm
Reply with quote

Dick,will this code suit the requirement icon_smile.gif
Code:

 Z= 0
 K= 0
 PERFORM UNTIL Z = (LENGTH OF D)                   
    COMPUTE Z = Z + 1                             
    IF FUNCTION LOWER-CASE (D(Z:1))  EQUAL D(Z:1) 
      COMPUTE K = K + 1     
    END-IF
 END-PERFORM


Cris
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 Oct 08, 2008 10:48 pm
Reply with quote

Hi Cris,

The only aspect of using FUNCTION LOWER-CASE, UPPER-CASE or what have you, is that (under the covers) a BALR is issued to a run-time routine.

IMHO, Robert's solution is all in-line and you never leave the caller.

Regards,

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

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Oct 09, 2008 12:02 pm
Reply with quote

Quote:
Sambhaji: try your code on a string with a tilde (~) in it. Since the EBCDIC collating sequence is not contiguous for the lower case alphabet, your code can pick up spurious lower case values, such as a tilde


Thanks Robert for pointing out this, I have missed it icon_sad.gif icon_sad.gif icon_sad.gif
Amendments are done here icon_smile.gif icon_smile.gif icon_smile.gif
Code:

CNTLOWER.                                                 
    IF ( FUNCTION ORD(UL1(LCNT)) >= FUNCTION ORD('a') AND
       FUNCTION ORD(UL1(LCNT)) <= FUNCTION ORD('i')) OR   
       ( FUNCTION ORD(UL1(LCNT)) >= FUNCTION ORD('j') AND
       FUNCTION ORD(UL1(LCNT)) <= FUNCTION ORD('r')) OR   
       ( FUNCTION ORD(UL1(LCNT)) >= FUNCTION ORD('s') AND
       FUNCTION ORD(UL1(LCNT)) <= FUNCTION ORD('z')) THEN     
    COMPUTE LOWERCNT = LOWERCNT + 1.                     
    COMPUTE LCNT = LCNT + 1.                             
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu Oct 09, 2008 12:19 pm
Reply with quote

what about using the SPECIAL NAMES? for example:

Code:

ENVIRONMENT DIVISION.   
CONFIGURATION SECTION.   
SPECIAL-NAMES.                                                   
      CLASS lowercase   IS 'abcdefghijklmnopqrstuvwxyz'         
.....
PROCEDURE DIVISION.
move 'a' to w-char                     
IF W-CHAR IS lowercase                 
   DISPLAY W-CHAR  'lowercase-YES'     
ELSE                                   
   DISPLAY W-CHAR  'lowercase-NO'     
END-IF   
...


so no need to loop around WS-LC-VARS.
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: Thu Oct 09, 2008 12:39 pm
Reply with quote

acevedo wrote:
what about using the SPECIAL NAMES?
My thought, exactly...
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Oct 09, 2008 9:10 pm
Reply with quote

Or the level 88. . .

Code:
01  THE-CHARACTER             PIC X.                 
    88 LC-LETTER  VALUES ARE 'a' THRU 'i',
                             'j' THRU 'r',
                             's' THRU 'z'.       


d
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Oct 13, 2008 11:47 am
Reply with quote

How about this one more way...

Code:

CNTLOWER.
 if UL1(LCNT) is alphabetic-lower and   
    UL1(LCNT) not =  space then         
   COMPUTE LOWERCNT = LOWERCNT + 1.
   COMPUTE LCNT = LCNT + 1.
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 sort to find out the char which repea... Mainframe Interview Questions 10
No new posts Compare 2 alphabets in a REXX and fin... CLIST & REXX 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
Search our Forums:

Back to Top