A code I could not understand.

Customer Information Control System. Middleware and MQ Series.
Post Reply
Sunil Hyderbad
Registered Member
Posts: 22
Joined: Thu Jan 30, 2014 9:58 am

A code I could not understand.

Post by Sunil Hyderbad »

Hi,

I see this code in one of the programs and I'm not sure what it does:

Code: Select all

1 XML-DECODE.
	2 RTN COMP 	PIC 9(2).
	2 RSN COMP-5  PIC 9(4).

1 HV PIC X(16) VALUE '0123456789ABCDEF'.

DISPLAY ' RC=' RTN ',REASON=X '''
 HV(FUNCTION MOD(RSN/4096 16) +1:1)
	 HV(FUNCTION MOD(RSN/256 16) +1:1)
	 HV(FUNCTION MOD(RSN/16  16) +1:1)
	 HV(FUNCTION MOD(RSN/1   16) +1:1)  ''''	

specially what 1:1 is doing? Can someone please guide.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: A code I could not understand.

Post by Robert Sample »

Assuming this is COBOL code, the :1 is using reference modification to specify the length being used -- the variable is HV; the FUNCTION ... +1 is specifying the starting byte of the HV variable. Basically the hex value of RSN is being displayed with this code.
Sunil Hyderbad
Registered Member
Posts: 22
Joined: Thu Jan 30, 2014 9:58 am

Re: A code I could not understand.

Post by Sunil Hyderbad »

Thanks Robert. But can we use HV as it is used here HV(FUNCTION MOD(RSN/4096 16) +1:1) ?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: A code I could not understand.

Post by Robert Sample »

RSN is divided by 4096; this result is then modulo 16 to come up with a value between 0 and 15; add 1 to get the starting position of HV that will be displayed; the : 1 says to only display the one byte.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: A code I could not understand.

Post by William Collins »

It looks like it was written by someone unused to having people understand their programs :-)

OK, it is interpreting the code returned from an XML-parsing failure, and that is given as a decimal number represented in a binary field, so always needs to be converted to hex, which is what the code is doing.

The COMP PIC 9(2) field will define a two-byte binary (which can hold four decimal digits) but the two digits are used to mimic the message code when you look it up. A nice touch.

The COMP-5 is necessary, because the binary code can utilise all the bits of the two bytes of storage defined. In this instance it doesn't matter which value, one through four, is used for the PIC.

The code is only going to execute once, so the fact that this is a very heavy-handed way to do it does not matter.

Still, it happens when there is an error, and someone is going to be looking at that code and... wondering what it is doing. It is doing as Robert has outlined.

It could be made more easy to understand.

Code: Select all

1 XML-DECODE.
   2 RTN COMP    PIC 9(2).
   2 RSN COMP-5  PIC 9(4).

1 HV PIC X(16) VALUE '0123456789ABCDEF'.

DISPLAY " RC=" RTN 
        ",REASON=X'"
              HV ( ( FUNCTION MOD ( ( RSN / 4096 ) 16 ) + 1 ) : 1 )
              HV ( ( FUNCTION MOD ( ( RSN /  256 ) 16 ) + 1 ) : 1 )
              HV ( ( FUNCTION MOD ( ( RSN /   16 ) 16 ) + 1 ) : 1 )
              HV ( ( FUNCTION MOD (   RSN          16 ) + 1 ) : 1 )  
        "'" 
Or even:

Code: Select all

DISPLAY " RC=" RTN 
        ",REASON=X'"
              HV ( 
                   ( FUNCTION MOD ( ( RSN / 4096 ) 16 ) 
                      + 1 )
                         : 1 )
              HV ( 
                   ( FUNCTION MOD ( ( RSN /  256 ) 16 ) 
                      + 1 )
                         : 1 )
              HV ( 
                   ( FUNCTION MOD ( ( RSN /   16 ) 16 ) 
                      + 1 )
                         : 1 )
              HV ( 
                   ( FUNCTION MOD (  RSN           16 ) 
                      + 1 )
                         : 1 )
        "'"
I'd not even do that, but work out four separate values, and DISPLAY those. When there is a problem, I'd not want people looking at the diagnosis-aid code first to understand that before they get to even start looking at the problem. That's a terrible thing to do to someone.

There's no disadvantage in doing it in more than one statement, and plenty of disadvantages often in doing it in one statement.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “CICS, Middleware and MQ Series.”