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

Author Message
BAJJI

New User

Joined: 15 Jul 2005
Posts: 47

 Posted: Mon Jun 26, 2006 7:58 pm    Post subject: Logic to get the next alphabet hi, can any one provide me with the logic to get the next alphabet. eg. if already K is given then i should get L. if already C is given then i should get D. etc. please provide me with the logic ASAP. thanks, Kiran.

IQofaGerbil

Active User

Joined: 05 May 2006
Posts: 183
Location: Scotland

 Posted: Mon Jun 26, 2006 8:34 pm    Post subject: Re: To get the next alphabet. erm... IF field = 'A' then 'get B' else IF field = 'B' then 'get C' else IF field = 'C' then ...........etc etc is this what you want ?
BAJJI

New User

Joined: 15 Jul 2005
Posts: 47

 Posted: Mon Jun 26, 2006 8:41 pm    Post subject: Re: To get the next alphabet. yes. i want exactly that. can you please send me the logic towards that... ASAP. thanks, Kiran.
shreevamsi

Active User

Joined: 23 Feb 2006
Posts: 305

 Posted: Tue Jun 27, 2006 3:50 pm    Post subject: Hi, There is an a FUNTION 'ORD' which returns a ASCII value for a particular CHar. EG: FUNCTION ORD('A') will return 193. SO add 1 to 193 and convert into CHAR. The Function that converts back from Integer to ASCII...I couldn't recollet :-) Any body know the Function to Convert ASCII Value to CHar?? There is another way to handle Char Envertion. It worked for MICROSOFT Cobol WORKING-STORAGE SECTION. 01 CHR PIC X. 01 ASC PIC 99 COMP-X REDEFINES CHR. PROCEDURE DIVISION. 000-MAIN. **** equivalent to ASC("X") MOVE "X" TO CHR. DISPLAY "ASCII VALUE OF X:". DISPLAY ASC. **** equivalent to CHR(89) MOVE 89 TO ASC. DISPLAY "CHAR FOR ASCII 89:". DISPLAY CHR. This may also work for MFs ~Vamsi
IQofaGerbil

Active User

Joined: 05 May 2006
Posts: 183
Location: Scotland

 Posted: Tue Jun 27, 2006 3:58 pm    Post subject: Re: To get the next alphabet. What do you 'get' if input is 'Z' ?
shreevamsi

Active User

Joined: 23 Feb 2006
Posts: 305

 Posted: Tue Jun 27, 2006 4:27 pm    Post subject: Correction: Function ORD returns a EBCIDC Colleteral Sequence number..Not the ASCII.
creator.abhishek

New User

Joined: 07 May 2006
Posts: 32
Location: Pune

 Posted: Tue Jun 27, 2006 4:41 pm    Post subject: Whatever it may be, I know it is not going to be easy. What you have to do is to icrement the value of a char by 1, if it is any of the alphabet except I,R,Z. You have to increment by 8 if it is I. You have to increment by 9 if it is R, and finally you have to decrease the value by 40 if it is Z.(if it is assumed that A should come after Z) You understand everything of it once you look into the following EBCDIC Character Code Reference. http://nemesis.lonestar.org/reference/telecom/codes/ebcdic.html
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1274
Location: Israel

Posted: Tue Jun 27, 2006 6:19 pm    Post subject:

Hello,

Because there are "holes" in the EBCDIC values, the method proposed by Vamsi will not work (in EBCDIC, alphabet goes from x'C1' (A) to x'C9' (I) then x'D1' (J) to x'D9' (R) then x'E2' (S) to x'E9' (Z). Adding 1 will lead to errors).

Using a table can be interesting:
 Code: 01  ALPHA-IX        PIC S9(4)      COMP.  01  ALPHA-TABLE     PIC X(26)      VALUE 'ABCDEFG.....VWXYZ'.  01  FILLER                         REDEFINES ALPHA-TABLE.      03 ALPHA-CHAR   PIC X          OCCURS 26. * loop until character found in table or end of table  PERFORM VARYING ALPHA-IX FROM 1 BY 1      UNTIL (ALPHA-IX > 26) OR      (ALPHA-CHAR (ALPHA-IX) = )  END-PERFORM  IF ALPHA-IX > 26 THEN * if end of table reached, was not alpha      DISPLAY 'not an alpha character'  ELSE * if char found, get next char (note: if Z, loop to A)      ADD 1 TO ALPHA-IX      IF ALPHA-IX > 26 THEN MOVE 1 TO ALPHA-IX      MOVE ALPHA-CHAR (ALPHA-IX) TO  END-IF
IQofaGerbil

Active User

Joined: 05 May 2006
Posts: 183
Location: Scotland

 Posted: Tue Jun 27, 2006 6:57 pm    Post subject: Re: To get the next alphabet. Am I missing the point here? Do we need to complicate things? If the specification says for a given input A thru Z get the next in alphabetical sequence then is here anything wrong with just doing a large nested IF statement ? ie IF field = 'A' then 'get B' else IF field = 'B' then 'get C' else IF field = 'C' Just need to know what to 'get' if field = 'Z' maybe loop back to 'A' ?
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1274
Location: Israel

Posted: Tue Jun 27, 2006 8:26 pm    Post subject:

While we are on the subject, let's try (just for the fun):
 Code: EVALUATE   WHEN 'A' MOVE 'B' TO NEW-CHAR   WHEN 'B' MOVE 'C' TO NEW-CHAR   WHEN 'Y' MOVE 'Z' TO NEW-CHAR   WHEN 'Z' MOVE 'A' TO NEW-CHAR   WHEN OTHER DISPLAY 'not alpha char' END-EVALUATE
IQofaGerbil

Active User

Joined: 05 May 2006
Posts: 183
Location: Scotland

 Posted: Tue Jun 27, 2006 8:46 pm    Post subject: Re: To get the next alphabet. Your specification is not clear, no explanation of what 'get' means, however if you just want to simply convert the 'A' to 'B' and 'B' to 'C' etc then this will work INSPECT your-field CONVERTING ”ZABCDEFGHIJKLMNOPQRSTUVWXY“ TO ”ABCDEFGHIJKLMNOPQRSTUVWXYZ“
mmwife

Super Moderator

Joined: 30 May 2003
Posts: 1592

Posted: Wed Jun 28, 2006 11:47 pm    Post subject: Re: To get the next alphabet.

Hi Rajj1,

Sorry, Rajj, previous code had errors. You can try this:
 Code: 05  wrk-fld.   10  filler     pic  x(001) value X?00?.   10  wrk-alpha  pic  x(001). 05  wrk-binary   redefines     wrk-fld      pic s9(004). move alpha-in to wrk-alphaa evaluate alpha-in when 'I' thru 'Q' when 'i' thru 'q' add +7 to wrk-binary when 'R' thru 'Y' when 'r' thru 'y' add +8 to wrk-binary end-evaluate if alpha-in = 'Z' or 'z'    move alpha-in to wrk-fld    perform Z-stuff else    add +1 to wrk-binary end-if

There are gaps between "I/i" & "J/j", "Q/q" & "R/r", so the need to add 7/8.
wrk-fld contains the new alpha.
Marso

REXX Moderator

Joined: 13 Mar 2006
Posts: 1274
Location: Israel

 Posted: Thu Jun 29, 2006 1:46 am    Post subject: IQofaGerbil with the INSPECT command definitively has the best suggestion!
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Logic to skip Maximum time-stamp and ... vickey_dw DB2 2 Thu Feb 01, 2018 11:15 pm Is CICS BMS logic on z/OS different ... Andi1982 CICS 2 Fri Dec 01, 2017 1:56 pm Need help in building a logic Benchwarmer All Other Mainframe Topics 4 Wed Feb 22, 2017 2:49 am Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm Sort Logic to extract data scorp_rahul23 DFSORT/ICETOOL 13 Tue Mar 01, 2016 1:22 am

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