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
 

 

Regarding to find whether lower case or higher case is prese

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Regarding to find whether lower case or higher case is prese
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: 7912
Location: Bellevue, IA

PostPosted: Wed Oct 08, 2008 6:12 pm    Post subject:
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    Post subject: Reply to: Regarding to find whether lower case or higher cas
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    Post subject:
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: 7912
Location: Bellevue, IA

PostPosted: Wed Oct 08, 2008 7:09 pm    Post subject:
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    Post subject:
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: http://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: 7912
Location: Bellevue, IA

PostPosted: Wed Oct 08, 2008 7:13 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Regarding to find whether lower case or higher cas
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Oct 08, 2008 10:48 pm    Post subject: RE: Reply to: Regarding to find whether lower case or higher
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    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Thu Oct 09, 2008 12:39 pm    Post subject:
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

Site Director


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

PostPosted: Thu Oct 09, 2008 9:10 pm    Post subject: Reply to: Regarding to find whether lower case or higher cas
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    Post subject:
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    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 How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 pm
No new posts How to find a CICS resource used in C... Arunkumar Chandrasekaran CICS 8 Thu Sep 29, 2016 1:45 pm
No new posts how to find clist's or view library Andrew Hsia CLIST & REXX 4 Tue Jun 28, 2016 6:07 pm
No new posts How to find jobs that are in schedule... anilkumar922 All Other Mainframe Topics 5 Tue Jun 28, 2016 10:01 am


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