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

Conversion of Assembler to COBOL code 2


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Fri Dec 16, 2011 8:49 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Dec 16, 2011 9:30 pm
Reply with quote

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
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Fri Dec 16, 2011 9:53 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Dec 16, 2011 10:26 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Dec 16, 2011 11:08 pm
Reply with quote

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 icon_wink.gif
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Dec 16, 2011 11:16 pm
Reply with quote

Enrico,

NP, I was relying on my memory, which has recently suffered a page fault. icon_wink.gif

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sat Dec 17, 2011 12:29 am
Reply with quote

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.... icon_wink.gif

Mr. Bill
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 17, 2011 12:52 am
Reply with quote

icon_redface.gif
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Sat Dec 17, 2011 1:12 am
Reply with quote

enrico thats only because us old dogs do have have a brain fart from time to time.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 17, 2011 1:43 am
Reply with quote

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 icon_wink.gif

(*) but what else could anybody expect from COBOL
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sat Dec 17, 2011 3:58 am
Reply with quote

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. icon_wink.gif

Mr. Bill
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Dec 17, 2011 4:43 am
Reply with quote

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 icon_wink.gif

(*) 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
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Sat Dec 17, 2011 2:23 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Dec 17, 2011 4:14 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Sat Dec 17, 2011 4:22 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sat Dec 17, 2011 7:03 pm
Reply with quote

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.

icon_redface.gif icon_redface.gif icon_redface.gif

Slowly wiping egg from face....

Mr. Bill
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Sun Dec 18, 2011 9:05 am
Reply with quote

Many thanks Bill & Bill Woodger for going through this in detail.
Thanks you Peter..icon_smile.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun Dec 18, 2011 9:39 am
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Sun Dec 18, 2011 9:40 am
Reply with quote

You are welcome.
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 -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compile rexx code with jcl CLIST & REXX 6
Search our Forums:

Back to Top