View previous topic :: View next topic
|
Author |
Message |
BAJJI
New User
Joined: 15 Jul 2005 Posts: 47
|
|
|
|
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 |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
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 |
|
|
BAJJI
New User
Joined: 15 Jul 2005 Posts: 47
|
|
|
|
yes.
i want exactly that.
can you please send me the logic towards that... ASAP.
thanks,
Kiran. |
|
Back to top |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
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 |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
What do you 'get' if input is 'Z' ? |
|
Back to top |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
Correction:
Function ORD returns a EBCIDC Colleteral Sequence number..Not the ASCII. |
|
Back to top |
|
|
creator.abhishek
New User
Joined: 07 May 2006 Posts: 32 Location: Pune
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
IQofaGerbil
Active User
Joined: 05 May 2006 Posts: 183 Location: Scotland
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
IQofaGerbil with the INSPECT command definitively has the best suggestion! |
|
Back to top |
|
|
|