Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
trgdhilip

New User

Joined: 24 Dec 2007
Posts: 3
Location: chennai

 Posted: Wed Oct 08, 2008 5:51 pm    Post subject: Regarding to find whether lower case or higher case is prese 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

Robert Sample

Global Moderator

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

Posted: Wed Oct 08, 2008 6:12 pm    Post subject:

 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                .
Cristopher

New User

Joined: 31 Jul 2008
Posts: 53
Location: NY

Posted: Wed Oct 08, 2008 6:43 pm    Post subject: Reply to: Regarding to find whether lower case or higher cas

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
Escapa

Senior Member

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

Posted: Wed Oct 08, 2008 6:44 pm    Post subject:

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.
Robert Sample

Global Moderator

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

 Posted: Wed Oct 08, 2008 7:09 pm    Post subject: 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.
dbzTHEdinosauer

Global Moderator

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

Posted: Wed Oct 08, 2008 7:11 pm    Post subject:

 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.

Robert Sample

Global Moderator

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

 Posted: Wed Oct 08, 2008 7:13 pm    Post subject: Thanks, Dick -- I tested that code before posting it.
dbzTHEdinosauer

Global Moderator

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

 Posted: Wed Oct 08, 2008 7:43 pm    Post subject: 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.
Cristopher

New User

Joined: 31 Jul 2008
Posts: 53
Location: NY

Posted: Wed Oct 08, 2008 7:44 pm    Post subject: Reply to: Regarding to find whether lower case or higher cas

Dick,will this code suit the requirement
 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
Bill O'Boyle

CICS Moderator

Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

 Posted: Wed Oct 08, 2008 10:48 pm    Post subject: RE: Reply to: Regarding to find whether lower case or higher 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
Escapa

Senior Member

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

Posted: Thu Oct 09, 2008 12:02 pm    Post subject:

 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
Amendments are done here
 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.
acevedo

Active User

Joined: 11 May 2005
Posts: 344
Location: Spain

Posted: Thu Oct 09, 2008 12:19 pm    Post subject:

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.
CICS Guy

Senior Member

Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

Posted: Thu Oct 09, 2008 12:39 pm    Post subject:

 acevedo wrote: what about using the SPECIAL NAMES?
My thought, exactly...
dick scherrer

Site Director

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

Posted: Thu Oct 09, 2008 9:10 pm    Post subject: Reply to: Regarding to find whether lower case or higher cas

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
Escapa

Senior Member

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

Posted: Mon Oct 13, 2008 11:47 am    Post subject:

 Code: CNTLOWER.  if UL1(LCNT) is alphabetic-lower and        UL1(LCNT) not =  space then             COMPUTE LOWERCNT = LOWERCNT + 1.    COMPUTE LCNT = LCNT + 1.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Rexx code to find greater then symobl... Bharath Vikraman CLIST & REXX 8 Tue May 29, 2018 9:40 am Find & Replace string in CA-SORT mrgnndhmk CA Products 1 Fri Mar 30, 2018 12:58 am Find a string in PS file opened in br... mukkas CLIST & REXX 3 Sat Feb 24, 2018 2:15 pm Command to find TMEMBER name for a TPIPE Siva NKK Kothamasu IMS DB/DC 0 Wed Aug 16, 2017 6:08 pm RFE: DB2 support for mixed case names. Pedro DB2 0 Tue Jul 04, 2017 1:32 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us