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

Logic to get the next alphabet


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

New User


Joined: 15 Jul 2005
Posts: 47

PostPosted: Mon Jun 26, 2006 7:58 pm
Reply with quote

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.
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Mon Jun 26, 2006 8:34 pm
Reply with quote

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 ?
Back to top
View user's profile Send private message
BAJJI

New User


Joined: 15 Jul 2005
Posts: 47

PostPosted: Mon Jun 26, 2006 8:41 pm
Reply with quote

yes.

i want exactly that.

can you please send me the logic towards that... ASAP.

thanks,
Kiran.
Back to top
View user's profile Send private message
shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Tue Jun 27, 2006 3:50 pm
Reply with quote

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
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Tue Jun 27, 2006 3:58 pm
Reply with quote

What do you 'get' if input is 'Z' ?
Back to top
View user's profile Send private message
shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Tue Jun 27, 2006 4:27 pm
Reply with quote

Correction:

Function ORD returns a EBCIDC Colleteral Sequence number..Not the ASCII.
Back to top
View user's profile Send private message
creator.abhishek

New User


Joined: 07 May 2006
Posts: 32
Location: Pune

PostPosted: Tue Jun 27, 2006 4:41 pm
Reply with quote

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.

nemesis.lonestar.org/reference/telecom/codes/ebcdic.html
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Jun 27, 2006 6:19 pm
Reply with quote

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) = <your character>)
 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 <new character area>
 END-IF
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Tue Jun 27, 2006 6:57 pm
Reply with quote

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' ?
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Jun 27, 2006 8:26 pm
Reply with quote

While we are on the subject, let's try (just for the fun):
Code:
EVALUATE <my character>
  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
Back to top
View user's profile Send private message
IQofaGerbil

Active User


Joined: 05 May 2006
Posts: 183
Location: Scotland

PostPosted: Tue Jun 27, 2006 8:46 pm
Reply with quote

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“
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Jun 28, 2006 11:47 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Jun 29, 2006 1:46 am
Reply with quote

IQofaGerbil with the INSPECT command definitively has the best suggestion!
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 Finding faulty logic Subscript out of... COBOL Programming 5
This topic is locked: you cannot edit posts or make replies. Need assistance in job scheduling logic. Mainframe Interview Questions 2
No new posts Rexx Logic error while adding seperat... CLIST & REXX 3
No new posts PL/1 Callback address logic in z/OS C... PL/I & Assembler 1
No new posts Sync logic between VSAM files and DB2... COBOL Programming 9
Search our Forums:

Back to Top