View previous topic :: View next topic
|
Author |
Message |
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
Hi,
I am new to Assembler and i have a task to analyse Assembler code and provide a COBOL version of it. I have a problem with TRT statement which is given below
Code: |
TRT WSNSRNM, ALPHATAB
BRANCH STMT upon some condition
MVC WSN1ST, 0(R1)
ALPHATAB DC 256X X'00'
ORG ALPHATAB+C'A'
DC 9X X'FF'
ORG ALPHATAB+C'J'
DC 9X X'FF'
ORG ALPHATAB+C'S'
|
WSNSRNM is of CL20 format and contains a Surname. WSN1ST is of format CL1. As per my understanding i think they are checking if the first character in WSNSRNM is equal to either A or J or S. If am wrong please help me. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
I believe you can subsitute the TRT with -
IF WSN1ST ALPHABETIC-UPPER AND NOT = SPACE
The Translate-Table is first initialized to X'00's then has X'FF's inserted into the upper-case alphabetic-letters slots. So, when an alphabetic-letter is found during the TRT, R1 will contain the address.
Internally, COBOL will probably issue a TRT to validate this as an upper-case letter as well and ensure it is not a SPACE.
Give it a try....
Mr. Bill |
|
Back to top |
|
|
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
Hi Bill,
You mean to say IF WSSRNM ALPHABETIC-UPPER AND NOT SPACE.
That means you are trying to move the first Upper Alphabetic letter in WSSRNM into WSN1ST... |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Actually no movement is done, just validation that this one-byte contains an alphabetic-upper letter and it's not a space, because a valid character for the alphabetic-upper test includes a space.
Mr. Bill |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
sorry to be picky ( or maybe I have a brain check )
Code: |
IF WSN1ST ALPHABETIC-UPPER AND NOT = SPACE |
isn' t the AND part useless... if the WSN1NT is ALPHA-UPPER then automatically is not a space |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Enrico,
NP, I was relying on my memory, which has recently suffered a page fault.
But I think COBOL does a TRT and builds a Translate-Table which includes a SPACE as a valid character as well as upper-case A-Z.
Mr. Bill |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Enrico,
Just verified that class conditions ALPHABETIC (Upper and Lower case letters), ALPHABETIC-LOWER (Lower case letters) and ALPHABETIC-UPPER (Upper case letters) also include a SPACE as a valid character.
I'm glad I wasn't having another CRS moment....
Mr. Bill |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
Back to top |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
enrico thats only because us old dogs do have have a brain fart from time to time. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
as a partial excuse I find COBOL assumption a bit illogic ... (*)
might concede the space for generic ALPHABETIC,
but for ALPHA-UPPER and ALPHA-LOWER nahhh
(*) but what else could anybody expect from COBOL |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Looking at the Assembler TRT again, I misread it because the TRT is going against the 20-byte label WSNSRNM.
After the TRT completes, a BZ indicates no upper-case letters were found because X'FF''s are inserted in the upper-case letter slots, which (when the first upper-case letter was found), would raise a CC of BNZ and zero-off R1 would contain the address of the first letter found in the Translate-Table.
With that, then perhaps the IF ALPHABETIC-UPPER test is not what you want. So, review the following. The PERFORM loop will terminate early or rummage through all the bytes. But, after coming out of the loop, if WS-LOCTN is non-zero, then this is the location of the first upper-case letter in WS-WSNSRNM.
Code: |
03 WS-WSNSRNM PIC X(20).
03 WS-WSN1ST PIC X(01).
03 WS-LETTER PIC X(01).
03 WS-SUB PIC 9(08) COMP.
03 WS-LOCTN PIC 9(08) COMP.
*
MOVE 1 TO WS-SUB.
MOVE ZERO TO WS-LOCTN.
*
PERFORM UNTIL WS-SUB > LENGTH OF WS-WSNSRNM
MOVE WS-WSNSRNM (WS-SUB:1)
TO WS-LETTER
IF (WS-LETTER ALPHABETIC-UPPER AND
WS-LETTER NOT = SPACE)
MOVE WS-SUB TO WS-LOCTN
MOVE LENGTH OF WS-WSNSRNM
TO WS-SUB
END-IF
ADD 1 TO WS-SUB
END-PERFORM.
*
IF WS-LOCTN > ZERO
MOVE WS-LETTER TO WS-WSN1ST
ELSE
MOVE SPACE TO WS-WSN1ST
END-IF.
|
Maybe this can be accomplished in some wild INSPECT, but I'll leave that alone for now.
Mr. Bill |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
enrico-sorichetti wrote: |
as a partial excuse I find COBOL assumption a bit illogic ... (*)
might concede the space for generic ALPHABETIC,
but for ALPHA-UPPER and ALPHA-LOWER nahhh
(*) but what else could anybody expect from COBOL |
A "PICTURE A" field allows letters and spaces. This is an "ALPHABETIC" field, and the ALPHABETIC test allows for upper, lower and space. ALPHABETIC-UPPER and ALPHABETIC-LOWER are subsets of ALPHABETIC, with the space being common to both subsets.
With no real strings, no real string functions, we'd be a bit stuffed if an alphabetic field didn't allow a space as a valid "character", and the "Class Test" has to follow the definition of the field.
Now, if we had a function like WORD, it would obviously make sense not to include the space, sort of, except no, because we'd not have much of a string to store it in and would still have a barrel of trailing spaces storing it in our usual PIC X(30). :-) Yes, X, I have never bothered with PIC X myself, and never seen one anywhere in a living program either. It's not like you'd get an abend if you put numeric data in it, so what'd be the point? That's just begging for a "well, I do that all the time..." |
|
Back to top |
|
|
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
Hi Bill,
Thanks for the help. However i still don't understand the presence of letters A or J or S in the ALPHATAB. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Probably the wrong "Bill", but if you look at the EBCDIC codes for letters you'll see that they are not contiguous. C1-C9, D1-D9, E2-E9. Two groups of nine and one group of eight. The groups start with the letters A, J and S. The table you have has an initial value of binary zeros, At position "A" (displacement x'C1') 9 x x'FF' will be set, at "J" (displacement x'D1') 9 x x'FF' and, presumably, at position "S" (displacement x'E2') 8 x x'FF', although you do not show that.
With the Cobol code that the other Bill has shown, you won't need a similar sort of set-up in the Cobol program. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
ALPHATAB is set to x'00', except for the characters A-I,J-R and S. Those characters are represented by x'FF'. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Quoting myself -
Quote: |
CC of BNZ and zero-off R1 would contain the address of the first letter found in the Translate-Table. |
Whereas, it should be -
CC of BNZ and zero-off R1 would contain the address of the first valid upper-case letter found in the 20-Byte label WSNSRNM.
Slowly wiping egg from face....
Mr. Bill |
|
Back to top |
|
|
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
Many thanks Bill & Bill Woodger for going through this in detail.
Thanks you Peter.. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No problem, glad it helped.
Bill Woodger wrote: |
[...] I have never bothered with PIC X myself, |
This should of course have been "I have never bothered with PIC A myself". PIC X I've used quite a bit :-) |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
You are welcome. |
|
Back to top |
|
|
|