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

Get equivalent hex string value for the given alphanumeric


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Wed Feb 29, 2012 3:31 pm
Reply with quote

Good morning & happy day

We use SUPRA SQL and COBOL program, the key for the table is " BLIND_KEY" CHAR (8) BYTE KEY
Suppose the blind-key value is ‘ ¯X*’ we have to input the hex value ‘0000000015bce75c’ to get the info from table. So please guide me how to achieve this programmatically to get hex value for given alphanumeric

¯X* -> 0000000015bce75c (required output)
00001BE5
00005C7C

I am doing this manually, I feel quite difficult when I get huge date.
Thanks in advance for all your time and help.

Have a good day
Thanks.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 29, 2012 3:54 pm
Reply with quote

is not SUPRA on a server and not a mainframe??? which would be ascii

but you have ¯X*
which is ebcdic
¯
X==x'e7'
*== x'5c'

for what is the x'15'
and why the binary zeroes in a char column. is that unique to supra?
need a little more info.

if the need is just to have a displayable 5C for an asterisk
then create a cobol internal table
each item consisting of the 2 char (5c in this case)
and move you single numeric to a x type field, which is redefined as binary and use it for a subscript.
Back to top
View user's profile Send private message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Wed Feb 29, 2012 4:19 pm
Reply with quote

Code:
Command ===>                                                  Scroll ===> CSR 
****** ***************************** Top of Data ******************************
000001      ¯X*                                                               
       00001BE54444444444444444444444444444444444444444444444444444444444444444
       00005C7C0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************


the input field would contain the value ' ¯X*', the equal hexa value is 0000000015bce75c'. Please help me to get this value programatically or by other way
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 29, 2012 4:41 pm
Reply with quote

since you are to obstinate to answer any questions or provide any meaningful information,

i will ask again:
1. where does your program do?
does it have an input file that it reads, and you are expected to select rows based on the input values?

2. even though the column is char(8),
it appears that there are binary numbers contained in the column.

unfortunately for you
Quote:
the input field would contain the value ' ¯X*', the equal hexa value is 0000000015bce75c'

the above statement is BfS.

the three (3) characters ¯X* in ebcdic are x'BCE75C'

the x'0000000015' is the values of the first 5 byes of this 8 char field.

show us some of your db2 column values displayed in hex.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Wed Feb 29, 2012 5:31 pm
Reply with quote

what do You want to do ...

given the hex string
Code:
****** ***************************** Top of Data ******************************
000001      ¯X*                                                               
       00001BE54444444444444444444444444444444444444444444444444444444444444444
       00005C7C0000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
****** **************************** Bottom of Data ****************************

display it as
Code:
0000000015bce75c


or the other way around ...
read,accept,whatever <input construct You like> a string like

Code:
0123456789ABCDEF


and store in a variable as

Code:
 
****** ***************************** Top of Data ******************************
 000001                                                               
        02468ACE4444444444444444444444444444444444444444444444444444444444444444
        13579BDF0000000000000000000000000000000000000000000000000000000000000000
 ------------------------------------------------------------------------------

Back to top
View user's profile Send private message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Wed Feb 29, 2012 5:50 pm
Reply with quote

Thanks for reply and help

Quote:
1. where does your program do?
does it have an input file that it reads, and you are expected to select rows based on the input values?


The input file have aphanumeric value, I need to read the value and convert to hex string, next I have to provide this as input to the table to select the column. Please find the input file below (the file is in hex on mode). The first 1-8 characters are input values.

Code:
****** **********
000001      2ck |
       00000F8944
       0000F2320F
-----------------
000002       m  |
       0000029144
       0000BA410F
-----------------
000003      Ä ý |
       0000060844
       0000E3DD0F
-----------------
000004        i |
       0000033844
       0000BD190F
-----------------


Quote:
2. even though the column is char(8),
it appears that there are binary numbers contained in the column.


yes, this is what i got in input field, please see below for table info


Code:
EASY  2.8     RESULT       TABLE:  XXX                                              Page 1
-------------------------- SQL 2800 -- PROD SYSTEM  ---------------------------
                                                                               
     1      blind_key....:   000000000FF28392                                 
     2 fiel2.....:   7,030,386                                         
     3 field3...........:   OUIMC 100497                                     
     4 field4.........:   3                                                 
     5 field 5:   N                                                 
.
.
.                                             
|   12 field12..........:                                                     
|   13 field13....:   -                                                 
|   14 field14..:   -                                                 
V   15 field15......:   0                                                 
-------------------------------------------------------------------------------
             1=HELP 3=LAST-SEL 4=PRINT 6=REPORT 8=DOWN 12=SPLTLINE             
                                                                               
                                                                  single result
                                                                               
Table: ...........................                         Function: .........


Is there chance to break (read) a byte into 4 bits & 4 bits.
Please let me know if anything required furthermore. Thanks.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Wed Feb 29, 2012 5:56 pm
Reply with quote

instead of posting garbage, would not have been simper reply 1 / 2 to my questions

when You ask for help You should post what WE ( the people helping ) think is useful to help You
not what You think useful
You just complicated things with no reason
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 29, 2012 5:58 pm
Reply with quote

Code:
1      blind_key....:   000000000FF28392


that is a hex representation of 8 bytes.

enrico,
you tend to have a more polished tone to your tutorials,
(and is seems that the tutorial must start at
What are computers and how do they work)
so i am going to drop out of this thread.
Back to top
View user's profile Send private message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Wed Feb 29, 2012 6:04 pm
Reply with quote

If something incorrect please I am sorry, I apology for the inconvenience caused.
Back to top
View user's profile Send private message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Wed Feb 29, 2012 6:10 pm
Reply with quote

Dick Brenholtz
Yes, the blind key in table needs to be hex representation of the input alphanumeric value. I need to convert 8 byte alphanumeric value to 16 digit hex string. Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 29, 2012 6:11 pm
Reply with quote

you don't have to convert anything.

move the first 8 char of your record to your host variable
and do the select...................................
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Wed Feb 29, 2012 6:24 pm
Reply with quote

the data you showed with the HEX on are not alphanumeric data amen
8 bytes of hex data which shows up as <garbage> on the screen can be decoded to 16 <thing> in the range 0-9a-f

conversely if you want to obtain an arbitrary 8 bytes things Yoyu need to enter 16 <thing> in the beforesaid range and <pack> them as 8 bytes

the process is more complicated that it seems

because 0-9 ==> f0 - f9
and A-F ==> C1 - C6

if You cannot understand the basics of data representation You are leading to a windy road

why not ask those who designed the application about it ?
Back to top
View user's profile Send private message
sprasannapathy

New User


Joined: 04 Jan 2008
Posts: 42
Location: india

PostPosted: Mon Mar 12, 2012 1:08 pm
Reply with quote

This program will convert aplhanumeric value x'15' (one byte -WS-LK-ONEBYTE-AN) into 2 byte hex value 15 (WS-LK-HEXASTRING).

Code:

main program

00105  01  WS-LK-PGMNAME               PIC X(8) VALUE 'PRSMSP08'
00106  01  WS-LK-ONEBYTE-AN            PIC X VALUE X'15'.
00107  01  WS-LK-HEXASTRING            PIC X(2).         
00108  01  WS-LK-HEXSTRING-ERR-FLG     PIC X.                 
00109      88  WS-LK-HEXSTRING-ERR-FLGN      VALUE 'N'.       
00110      88  WS-LK-HEXSTRING-ERR-FLGY      VALUE 'Y'.       
00111  PROCEDURE DIVISION.                                     
00112                                                         
00113  0000-MAIN.                                             
00114      CALL WS-LK-PGMNAME USING WS-LK-ONEBYTE-AN, WS-LK-HEX
00115                            WS-LK-HEXSTRING-ERR-FLG       
00116      IF WS-LK-HEXSTRING-ERR-FLGN
00117      DISPLAY WS-LK-ONEBYTE-AN, ' ', WS-LK-HEXASTRING, ' '
00118                         WS-LK-HEXSTRING-ERR-FLG   
00119      ELSE
00120      DISPLY 'ERROR IN INPUT'


SUBPROGRAM

Code:

00002  IDENTIFICATION DIVISION.                                         PRSMSP08
00003  PROGRAM-ID.    PRSMSP08.                                            LV137
00004 ****************************************************************     CL182
00005 * ADD SET OF NEW FORMPROD PRODUCTS TO GROUP OF CUSTOMERS       *     CL253
00006 ****************************************************************     CL182
00007 *INCLUDE++ ENVIR                                                     CL182
00001  ENVIRONMENT DIVISION.                                            05/07/84
00002  CONFIGURATION SECTION.                                           ENVIR
00003  SOURCE-COMPUTER. IBM-370.                                           LV001
00004  OBJECT-COMPUTER. IBM-370.
00005  INPUT-OUTPUT SECTION.
00006  FILE-CONTROL.
      *END INCLUDE++
00008                                                                      CL182
00009  DATA DIVISION.                                                      CL182
00010                                                                      CL*50
00011  WORKING-STORAGE SECTION.                                            CL182
00012 *                                                                    CL*45
00013  01  WS-PACK-FORMATT-CONVERSION  PIC X(1) VALUE X'15'.               CL*99
00014  01  WS-PARA-NAME                PIC X(80).                          CL111
00015  LINKAGE SECTION.                                                    CL111
00016  01 LK-ONEBYTE-AN                PIC X(1).                           CL111
00017  01 LK-HEXASTRING                PIC X(2).                           CL111
00018  01 LK-HEXSTRING-ERR-FLG         PIC X(1).                           CL128
00019                                                                      CL111
00020  PROCEDURE DIVISION USING LK-ONEBYTE-AN, LK-HEXASTRING,              CL125
00021                           LK-HEXSTRING-ERR-FLG.                      CL131
00022  0000-MAIN.                                                          CL182
00023      MOVE 'MAIN -PRSMSP08 '      TO WS-PARA-NAME                     CL111
00024      EVALUATE   LK-ONEBYTE-AN                                        CL111
00025        WHEN X'00'        MOVE '00' TO LK-HEXASTRING                  CL111
00026        WHEN X'01'        MOVE '01' TO LK-HEXASTRING                  CL111
00027        WHEN X'02'        MOVE '02' TO LK-HEXASTRING                  CL111
00028        WHEN X'03'        MOVE '03' TO LK-HEXASTRING                  CL111
00029        WHEN X'04'        MOVE '04' TO LK-HEXASTRING                  CL111
00030        WHEN X'05'        MOVE '05' TO LK-HEXASTRING                  CL111
00031        WHEN X'06'        MOVE '06' TO LK-HEXASTRING                  CL111
00032        WHEN X'07'        MOVE '07' TO LK-HEXASTRING                  CL111
00033        WHEN X'08'        MOVE '08' TO LK-HEXASTRING                  CL111
00034        WHEN X'09'        MOVE '09' TO LK-HEXASTRING                  CL111
00035        WHEN X'0A'        MOVE '0A' TO LK-HEXASTRING                  CL111
00036        WHEN X'0B'        MOVE '0B' TO LK-HEXASTRING                  CL111
00037        WHEN X'0C'        MOVE '0C' TO LK-HEXASTRING                  CL111
00038        WHEN X'0D'        MOVE '0D' TO LK-HEXASTRING                  CL111
00039        WHEN X'0E'        MOVE '0E' TO LK-HEXASTRING                  CL111
00040        WHEN X'0F'        MOVE '0F' TO LK-HEXASTRING                  CL111
00041        WHEN X'10'        MOVE '10' TO LK-HEXASTRING                  CL112
00042        WHEN X'11'        MOVE '11' TO LK-HEXASTRING                  CL112
00043        WHEN X'12'        MOVE '12' TO LK-HEXASTRING                  CL112
00044        WHEN X'13'        MOVE '13' TO LK-HEXASTRING                  CL112
00045        WHEN X'14'        MOVE '14' TO LK-HEXASTRING                  CL112
00046        WHEN X'15'        MOVE '15' TO LK-HEXASTRING                  CL112
00047        WHEN X'16'        MOVE '16' TO LK-HEXASTRING                  CL112
00048        WHEN X'17'        MOVE '17' TO LK-HEXASTRING                  CL112
00049        WHEN X'18'        MOVE '18' TO LK-HEXASTRING                  CL112
00050        WHEN X'19'        MOVE '19' TO LK-HEXASTRING                  CL112
00051        WHEN X'1A'        MOVE '1A' TO LK-HEXASTRING                  CL112
00052        WHEN X'1B'        MOVE '1B' TO LK-HEXASTRING                  CL112
00053        WHEN X'1C'        MOVE '1C' TO LK-HEXASTRING                  CL112
00054        WHEN X'1D'        MOVE '1D' TO LK-HEXASTRING                  CL112
00055        WHEN X'1E'        MOVE '1E' TO LK-HEXASTRING                  CL112
00056        WHEN X'1F'        MOVE '1F' TO LK-HEXASTRING                  CL112
00057        WHEN X'20'        MOVE '20' TO LK-HEXASTRING                  CL113
00058        WHEN X'21'        MOVE '21' TO LK-HEXASTRING                  CL113
00059        WHEN X'22'        MOVE '22' TO LK-HEXASTRING                  CL113
00060        WHEN X'23'        MOVE '23' TO LK-HEXASTRING                  CL113
00061        WHEN X'24'        MOVE '24' TO LK-HEXASTRING                  CL113
00062        WHEN X'25'        MOVE '25' TO LK-HEXASTRING                  CL113
00063        WHEN X'26'        MOVE '26' TO LK-HEXASTRING                  CL113
00064        WHEN X'27'        MOVE '27' TO LK-HEXASTRING                  CL113
00065        WHEN X'28'        MOVE '28' TO LK-HEXASTRING                  CL113
00066        WHEN X'29'        MOVE '29' TO LK-HEXASTRING                  CL113
00067        WHEN X'2A'        MOVE '2A' TO LK-HEXASTRING                  CL113
00068        WHEN X'2B'        MOVE '2B' TO LK-HEXASTRING                  CL113
00069        WHEN X'2C'        MOVE '2C' TO LK-HEXASTRING                  CL113
00070        WHEN X'2D'        MOVE '2D' TO LK-HEXASTRING                  CL113
00071        WHEN X'2E'        MOVE '2E' TO LK-HEXASTRING                  CL113
00072        WHEN X'2F'        MOVE '2F' TO LK-HEXASTRING                  CL113
00073        WHEN X'30'        MOVE '30' TO LK-HEXASTRING                  CL113
00074        WHEN X'31'        MOVE '31' TO LK-HEXASTRING                  CL113
00075        WHEN X'32'        MOVE '32' TO LK-HEXASTRING                  CL113
00076        WHEN X'33'        MOVE '33' TO LK-HEXASTRING                  CL113
00077        WHEN X'34'        MOVE '34' TO LK-HEXASTRING                  CL113
00078        WHEN X'35'        MOVE '35' TO LK-HEXASTRING                  CL113
00079        WHEN X'36'        MOVE '36' TO LK-HEXASTRING                  CL113
00080        WHEN X'37'        MOVE '37' TO LK-HEXASTRING                  CL113
00081        WHEN X'38'        MOVE '38' TO LK-HEXASTRING                  CL113
00082        WHEN X'39'        MOVE '39' TO LK-HEXASTRING                  CL113
00083        WHEN X'3A'        MOVE '3A' TO LK-HEXASTRING                  CL113
00084        WHEN X'3B'        MOVE '3B' TO LK-HEXASTRING                  CL113
00085        WHEN X'3C'        MOVE '3C' TO LK-HEXASTRING                  CL113
00086        WHEN X'3D'        MOVE '3D' TO LK-HEXASTRING                  CL113
00087        WHEN X'3E'        MOVE '3E' TO LK-HEXASTRING                  CL113
00088        WHEN X'3F'        MOVE '3F' TO LK-HEXASTRING                  CL113
00089        WHEN X'40'        MOVE '40' TO LK-HEXASTRING                  CL113
00090        WHEN X'41'        MOVE '41' TO LK-HEXASTRING                  CL113
00091        WHEN X'42'        MOVE '42' TO LK-HEXASTRING                  CL113
00092        WHEN X'43'        MOVE '43' TO LK-HEXASTRING                  CL113
00093        WHEN X'44'        MOVE '44' TO LK-HEXASTRING                  CL113
00094        WHEN X'45'        MOVE '45' TO LK-HEXASTRING                  CL113
00095        WHEN X'46'        MOVE '46' TO LK-HEXASTRING                  CL113
00096        WHEN X'47'        MOVE '47' TO LK-HEXASTRING                  CL113
00097        WHEN X'48'        MOVE '48' TO LK-HEXASTRING                  CL113
00098        WHEN X'49'        MOVE '49' TO LK-HEXASTRING                  CL113
00099        WHEN X'4A'        MOVE '4A' TO LK-HEXASTRING                  CL113
00100        WHEN X'4B'        MOVE '4B' TO LK-HEXASTRING                  CL113
00101        WHEN X'4C'        MOVE '4C' TO LK-HEXASTRING                  CL113
00102        WHEN X'4D'        MOVE '4D' TO LK-HEXASTRING                  CL113
00103        WHEN X'4E'        MOVE '4E' TO LK-HEXASTRING                  CL113
00104        WHEN X'4F'        MOVE '4F' TO LK-HEXASTRING                  CL113
00105        WHEN X'50'        MOVE '50' TO LK-HEXASTRING                  CL114
00106        WHEN X'51'        MOVE '51' TO LK-HEXASTRING                  CL114
00107        WHEN X'52'        MOVE '52' TO LK-HEXASTRING                  CL114
00108        WHEN X'53'        MOVE '53' TO LK-HEXASTRING                  CL114
00109        WHEN X'54'        MOVE '54' TO LK-HEXASTRING                  CL114
00110        WHEN X'55'        MOVE '55' TO LK-HEXASTRING                  CL114
00111        WHEN X'56'        MOVE '56' TO LK-HEXASTRING                  CL114
00112        WHEN X'57'        MOVE '57' TO LK-HEXASTRING                  CL114
00113        WHEN X'58'        MOVE '58' TO LK-HEXASTRING                  CL114
00114        WHEN X'59'        MOVE '59' TO LK-HEXASTRING                  CL114
00115        WHEN X'5A'        MOVE '5A' TO LK-HEXASTRING                  CL114
00116        WHEN X'5B'        MOVE '5B' TO LK-HEXASTRING                  CL114
00117        WHEN X'5C'        MOVE '5C' TO LK-HEXASTRING                  CL114
00118        WHEN X'5D'        MOVE '5D' TO LK-HEXASTRING                  CL114
00119        WHEN X'5E'        MOVE '5E' TO LK-HEXASTRING                  CL114
00120        WHEN X'5F'        MOVE '5F' TO LK-HEXASTRING                  CL114
00121        WHEN X'60'        MOVE '60' TO LK-HEXASTRING                  CL115
00122        WHEN X'61'        MOVE '61' TO LK-HEXASTRING                  CL115
00123        WHEN X'62'        MOVE '62' TO LK-HEXASTRING                  CL115
00124        WHEN X'63'        MOVE '63' TO LK-HEXASTRING                  CL115
00125        WHEN X'64'        MOVE '64' TO LK-HEXASTRING                  CL115
00126        WHEN X'65'        MOVE '65' TO LK-HEXASTRING                  CL115
00127        WHEN X'66'        MOVE '66' TO LK-HEXASTRING                  CL115
00128        WHEN X'67'        MOVE '67' TO LK-HEXASTRING                  CL115
00129        WHEN X'68'        MOVE '68' TO LK-HEXASTRING                  CL115
00130        WHEN X'69'        MOVE '69' TO LK-HEXASTRING                  CL115
00131        WHEN X'6A'        MOVE '6A' TO LK-HEXASTRING                  CL115
00132        WHEN X'6B'        MOVE '6B' TO LK-HEXASTRING                  CL115
00133        WHEN X'6C'        MOVE '6C' TO LK-HEXASTRING                  CL115
00134        WHEN X'6D'        MOVE '6D' TO LK-HEXASTRING                  CL115
00135        WHEN X'6E'        MOVE '6E' TO LK-HEXASTRING                  CL115
00136        WHEN X'6F'        MOVE '6F' TO LK-HEXASTRING                  CL115
00137        WHEN X'70'        MOVE '70' TO LK-HEXASTRING                  CL116
00138        WHEN X'71'        MOVE '71' TO LK-HEXASTRING                  CL116
00139        WHEN X'72'        MOVE '72' TO LK-HEXASTRING                  CL116
00140        WHEN X'73'        MOVE '73' TO LK-HEXASTRING                  CL116
00141        WHEN X'74'        MOVE '74' TO LK-HEXASTRING                  CL116
00142        WHEN X'75'        MOVE '75' TO LK-HEXASTRING                  CL116
00143        WHEN X'76'        MOVE '76' TO LK-HEXASTRING                  CL116
00144        WHEN X'77'        MOVE '77' TO LK-HEXASTRING                  CL116
00145        WHEN X'78'        MOVE '78' TO LK-HEXASTRING                  CL116
00146        WHEN X'79'        MOVE '79' TO LK-HEXASTRING                  CL116
00147        WHEN X'7A'        MOVE '7A' TO LK-HEXASTRING                  CL116
00148        WHEN X'7B'        MOVE '7B' TO LK-HEXASTRING                  CL116
00149        WHEN X'7C'        MOVE '7C' TO LK-HEXASTRING                  CL116
00150        WHEN X'7D'        MOVE '7D' TO LK-HEXASTRING                  CL116
00151        WHEN X'7E'        MOVE '7E' TO LK-HEXASTRING                  CL116
00152        WHEN X'7F'        MOVE '7F' TO LK-HEXASTRING                  CL116
00153        WHEN X'80'        MOVE '80' TO LK-HEXASTRING                  CL117
00154        WHEN X'81'        MOVE '81' TO LK-HEXASTRING                  CL117
00155        WHEN X'82'        MOVE '82' TO LK-HEXASTRING                  CL117
00156        WHEN X'83'        MOVE '83' TO LK-HEXASTRING                  CL117
00157        WHEN X'84'        MOVE '84' TO LK-HEXASTRING                  CL117
00158        WHEN X'85'        MOVE '85' TO LK-HEXASTRING                  CL117
00159        WHEN X'86'        MOVE '86' TO LK-HEXASTRING                  CL117
00160        WHEN X'87'        MOVE '87' TO LK-HEXASTRING                  CL117
00161        WHEN X'88'        MOVE '88' TO LK-HEXASTRING                  CL117
00162        WHEN X'89'        MOVE '89' TO LK-HEXASTRING                  CL117
00163        WHEN X'8A'        MOVE '8A' TO LK-HEXASTRING                  CL117
00164        WHEN X'8B'        MOVE '8B' TO LK-HEXASTRING                  CL117
00165        WHEN X'8C'        MOVE '8C' TO LK-HEXASTRING                  CL117
00166        WHEN X'8D'        MOVE '8D' TO LK-HEXASTRING                  CL117
00167        WHEN X'8E'        MOVE '8E' TO LK-HEXASTRING                  CL117
00168        WHEN X'8F'        MOVE '8F' TO LK-HEXASTRING                  CL117
00169        WHEN X'90'        MOVE '90' TO LK-HEXASTRING                  CL118
00170        WHEN X'91'        MOVE '91' TO LK-HEXASTRING                  CL118
00171        WHEN X'92'        MOVE '92' TO LK-HEXASTRING                  CL118
00172        WHEN X'93'        MOVE '93' TO LK-HEXASTRING                  CL118
00173        WHEN X'94'        MOVE '94' TO LK-HEXASTRING                  CL118
00174        WHEN X'95'        MOVE '95' TO LK-HEXASTRING                  CL118
00175        WHEN X'96'        MOVE '96' TO LK-HEXASTRING                  CL118
00176        WHEN X'97'        MOVE '97' TO LK-HEXASTRING                  CL118
00177        WHEN X'98'        MOVE '98' TO LK-HEXASTRING                  CL118
00178        WHEN X'99'        MOVE '99' TO LK-HEXASTRING                  CL118
00179        WHEN X'9A'        MOVE '9A' TO LK-HEXASTRING                  CL118
00180        WHEN X'9B'        MOVE '9B' TO LK-HEXASTRING                  CL118
00181        WHEN X'9C'        MOVE '9C' TO LK-HEXASTRING                  CL118
00182        WHEN X'9D'        MOVE '9D' TO LK-HEXASTRING                  CL118
00183        WHEN X'9E'        MOVE '9E' TO LK-HEXASTRING                  CL118
00184        WHEN X'9F'        MOVE '9F' TO LK-HEXASTRING                  CL118
00185        WHEN OTHER        MOVE 'C'  TO LK-HEXSTRING-ERR-FLG           CL137
00186      END-EVALUATE                                                    CL131
00187      IF LK-HEXSTRING-ERR-FLG = 'C'                                   CL137
00188      MOVE 'N' TO LK-HEXSTRING-ERR-FLG                                CL133
00189      EVALUATE   LK-ONEBYTE-AN                                        CL131
00190        WHEN X'A0'        MOVE 'A0' TO LK-HEXASTRING                  CL119
00191        WHEN X'A1'        MOVE 'A1' TO LK-HEXASTRING                  CL119
00192        WHEN X'A2'        MOVE 'A2' TO LK-HEXASTRING                  CL119
00193        WHEN X'A3'        MOVE 'A3' TO LK-HEXASTRING                  CL119
00194        WHEN X'A4'        MOVE 'A4' TO LK-HEXASTRING                  CL119
00195        WHEN X'A5'        MOVE 'A5' TO LK-HEXASTRING                  CL119
00196        WHEN X'A6'        MOVE 'A6' TO LK-HEXASTRING                  CL119
00197        WHEN X'A7'        MOVE 'A7' TO LK-HEXASTRING                  CL119
00198        WHEN X'A8'        MOVE 'A8' TO LK-HEXASTRING                  CL119
00199        WHEN X'A9'        MOVE 'A9' TO LK-HEXASTRING                  CL119
00200        WHEN X'AA'        MOVE 'AA' TO LK-HEXASTRING                  CL119
00201        WHEN X'AB'        MOVE 'AB' TO LK-HEXASTRING                  CL119
00202        WHEN X'AC'        MOVE 'AC' TO LK-HEXASTRING                  CL119
00203        WHEN X'AD'        MOVE 'AD' TO LK-HEXASTRING                  CL119
00204        WHEN X'AE'        MOVE 'AE' TO LK-HEXASTRING                  CL119
00205        WHEN X'AF'        MOVE 'AF' TO LK-HEXASTRING                  CL119
00206        WHEN X'B0'        MOVE 'B0' TO LK-HEXASTRING                  CL120
00207        WHEN X'B1'        MOVE 'B1' TO LK-HEXASTRING                  CL120
00208        WHEN X'B2'        MOVE 'B2' TO LK-HEXASTRING                  CL120
00209        WHEN X'B3'        MOVE 'B3' TO LK-HEXASTRING                  CL120
00210        WHEN X'B4'        MOVE 'B4' TO LK-HEXASTRING                  CL120
00211        WHEN X'B5'        MOVE 'B5' TO LK-HEXASTRING                  CL120
00212        WHEN X'B6'        MOVE 'B6' TO LK-HEXASTRING                  CL120
00213        WHEN X'B7'        MOVE 'B7' TO LK-HEXASTRING                  CL120
00214        WHEN X'B8'        MOVE 'B8' TO LK-HEXASTRING                  CL120
00215        WHEN X'B9'        MOVE 'B9' TO LK-HEXASTRING                  CL120
00216        WHEN X'BA'        MOVE 'BA' TO LK-HEXASTRING                  CL120
00217        WHEN X'BB'        MOVE 'BB' TO LK-HEXASTRING                  CL120
00218        WHEN X'BC'        MOVE 'BC' TO LK-HEXASTRING                  CL120
00219        WHEN X'BD'        MOVE 'BD' TO LK-HEXASTRING                  CL120
00220        WHEN X'BE'        MOVE 'BE' TO LK-HEXASTRING                  CL120
00221        WHEN X'BF'        MOVE 'BF' TO LK-HEXASTRING                  CL120
00222        WHEN X'C0'        MOVE 'C0' TO LK-HEXASTRING                  CL121
00223        WHEN X'C1'        MOVE 'C1' TO LK-HEXASTRING                  CL121
00224        WHEN X'C2'        MOVE 'C2' TO LK-HEXASTRING                  CL121
00225        WHEN X'C3'        MOVE 'C3' TO LK-HEXASTRING                  CL121
00226        WHEN X'C4'        MOVE 'C4' TO LK-HEXASTRING                  CL121
00227        WHEN X'C5'        MOVE 'C5' TO LK-HEXASTRING                  CL121
00228        WHEN X'C6'        MOVE 'C6' TO LK-HEXASTRING                  CL121
00229        WHEN X'C7'        MOVE 'C7' TO LK-HEXASTRING                  CL121
00230        WHEN X'C8'        MOVE 'C8' TO LK-HEXASTRING                  CL121
00231        WHEN X'C9'        MOVE 'C9' TO LK-HEXASTRING                  CL121
00232        WHEN X'CA'        MOVE 'CA' TO LK-HEXASTRING                  CL121
00233        WHEN X'CB'        MOVE 'CB' TO LK-HEXASTRING                  CL121
00234        WHEN X'CC'        MOVE 'CC' TO LK-HEXASTRING                  CL121
00235        WHEN X'CD'        MOVE 'CD' TO LK-HEXASTRING                  CL121
00236        WHEN X'CE'        MOVE 'CE' TO LK-HEXASTRING                  CL121
00237        WHEN X'CF'        MOVE 'CF' TO LK-HEXASTRING                  CL121
00238        WHEN X'D0'        MOVE 'D0' TO LK-HEXASTRING                  CL122
00239        WHEN X'D1'        MOVE 'D1' TO LK-HEXASTRING                  CL122
00240        WHEN X'D2'        MOVE 'D2' TO LK-HEXASTRING                  CL122
00241        WHEN X'D3'        MOVE 'D3' TO LK-HEXASTRING                  CL122
00242        WHEN X'D4'        MOVE 'D4' TO LK-HEXASTRING                  CL122
00243        WHEN X'D5'        MOVE 'D5' TO LK-HEXASTRING                  CL122
00244        WHEN X'D6'        MOVE 'D6' TO LK-HEXASTRING                  CL122
00245        WHEN X'D7'        MOVE 'D7' TO LK-HEXASTRING                  CL122
00246        WHEN X'D8'        MOVE 'D8' TO LK-HEXASTRING                  CL122
00247        WHEN X'D9'        MOVE 'D9' TO LK-HEXASTRING                  CL122
00248        WHEN X'DA'        MOVE 'DA' TO LK-HEXASTRING                  CL122
00249        WHEN X'DB'        MOVE 'DB' TO LK-HEXASTRING                  CL122
00250        WHEN X'DC'        MOVE 'DC' TO LK-HEXASTRING                  CL122
00251        WHEN X'DD'        MOVE 'DD' TO LK-HEXASTRING                  CL122
00252        WHEN X'DE'        MOVE 'DE' TO LK-HEXASTRING                  CL122
00253        WHEN X'DF'        MOVE 'DF' TO LK-HEXASTRING                  CL122
00254        WHEN X'E0'        MOVE 'E0' TO LK-HEXASTRING                  CL123
00255        WHEN X'E1'        MOVE 'E1' TO LK-HEXASTRING                  CL123
00256        WHEN X'E2'        MOVE 'E2' TO LK-HEXASTRING                  CL123
00257        WHEN X'E3'        MOVE 'E3' TO LK-HEXASTRING                  CL123
00258        WHEN X'E4'        MOVE 'E4' TO LK-HEXASTRING                  CL123
00259        WHEN X'E5'        MOVE 'E5' TO LK-HEXASTRING                  CL123
00260        WHEN X'E6'        MOVE 'E6' TO LK-HEXASTRING                  CL123
00261        WHEN X'E7'        MOVE 'E7' TO LK-HEXASTRING                  CL123
00262        WHEN X'E8'        MOVE 'E8' TO LK-HEXASTRING                  CL123
00263        WHEN X'E9'        MOVE 'E9' TO LK-HEXASTRING                  CL123
00264        WHEN X'EA'        MOVE 'EA' TO LK-HEXASTRING                  CL123
00265        WHEN X'EB'        MOVE 'EB' TO LK-HEXASTRING                  CL123
00266        WHEN X'EC'        MOVE 'EC' TO LK-HEXASTRING                  CL123
00267        WHEN X'ED'        MOVE 'ED' TO LK-HEXASTRING                  CL123
00268        WHEN X'EE'        MOVE 'EE' TO LK-HEXASTRING                  CL123
00269        WHEN X'EF'        MOVE 'EF' TO LK-HEXASTRING                  CL123
00270        WHEN X'F0'        MOVE 'F0' TO LK-HEXASTRING                  CL124
00271        WHEN X'F1'        MOVE 'F1' TO LK-HEXASTRING                  CL124
00272        WHEN X'F2'        MOVE 'F2' TO LK-HEXASTRING                  CL124
00273        WHEN X'F3'        MOVE 'F3' TO LK-HEXASTRING                  CL124
00274        WHEN X'F4'        MOVE 'F4' TO LK-HEXASTRING                  CL124
00275        WHEN X'F5'        MOVE 'F5' TO LK-HEXASTRING                  CL124
00276        WHEN X'F6'        MOVE 'F6' TO LK-HEXASTRING                  CL124
00277        WHEN X'F7'        MOVE 'F7' TO LK-HEXASTRING                  CL124
00278        WHEN X'F8'        MOVE 'F8' TO LK-HEXASTRING                  CL124
00279        WHEN X'F9'        MOVE 'F9' TO LK-HEXASTRING                  CL124
00280        WHEN X'FA'        MOVE 'FA' TO LK-HEXASTRING                  CL124
00281        WHEN X'FB'        MOVE 'FB' TO LK-HEXASTRING                  CL124
00282        WHEN X'FC'        MOVE 'FC' TO LK-HEXASTRING                  CL124
00283        WHEN X'FD'        MOVE 'FD' TO LK-HEXASTRING                  CL124
00284        WHEN X'FE'        MOVE 'FE' TO LK-HEXASTRING                  CL124
00285        WHEN X'FF'        MOVE 'FF' TO LK-HEXASTRING                  CL124
00286        WHEN OTHER        MOVE 'Y'  TO LK-HEXSTRING-ERR-FLG           CL128
00287      END-EVALUATE                                                    CL105
00288      END-IF                                                          CL136
00289      GOBACK                                                          CL182
00290      .                                                               CL182
00291  0000-EXIT.   EXIT.                                                  CL182
00292                                                                      CL182

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: Mon Mar 12, 2012 1:23 pm
Reply with quote

OK, not really the question, was it?

Does it work? The snippet with the call won't compile.

"N" is only set to your flag if byte is greater than x'9f'.

I don't know when the OTHER could ever possibly occur. Why are you moving the paragraph name to working-storage? I'd have thought it obvious which para it was in?

Generally when we think of these programs, we try to do it in a reasonable amount of code and a reasonable amount of time. This will average 128 tests to establish the display value, and is the longest in terms of code that I've seen, by many-a-mile.
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: Mon Mar 12, 2012 4:28 pm
Reply with quote

Maybe this is what you need?

www.ibmmainframes.com/viewtopic.php?p=115071&highlight=#115071
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: Mon Mar 12, 2012 6:40 pm
Reply with quote

Or this, which is shorter than yours, sprasannapathy , but does a bit more.

Or this one.
Back to top
View user's profile Send private message
Dexter Morgan

New User


Joined: 11 Jan 2012
Posts: 3
Location: United States

PostPosted: Tue Apr 03, 2012 10:25 am
Reply with quote

Just noticed this old thread, which is a little hard to follow. If problem is truly to produce zone-digit character representation of hexadecimal, I would like to offer an alternative solution that, I think, is more straightforward and user-friendly. This solution involves simple calculation (COBOL divide) to derive hex characters. It requires 2 copybooks (1 working-storage, 1 procedure division).
Code:
*****************************************************************
      *           CONVERSION CHARACTER-TO-HEX WORKING STORAGE
      *    AREAS TO USE AND HOLD DATA FOR CONVERSION. CAN BE MADE A
      *    STATIC COPYBOOK WITH OVERRIDE FOR INPUT SIZE.
      *    Example: COPY cpybook-name REPLACING ==MAXINPTSZ==
      *                                      BY ==10==.
      ******************************************************************
       01  CHAR-TO-HEX-ZD-AREA.

           05  WHLD-DIVISION-FIELDS.
               10  WHLD-DIVIDEND       PIC S9(03)    COMP VALUE +0.
               10  WHLD-DIVISOR        PIC S9(02)    COMP VALUE +16.
               10  WHLD-QUOTIENT       PIC S9(02)    COMP VALUE +0.
               10  WHLD-REMAINDER      PIC S9(02)    COMP VALUE +0.
               10  WHLD-DIV-LENGTH     PIC S9(06)V99 COMP VALUE +0.

           05  WHLD-HEX-ZD-VAL-ARRAY.
               10  FILLER              PIC  X(16) VALUE
                   '0123456789ABCDEF'.
           05  FILLER              REDEFINES
               WHLD-HEX-ZD-VAL-ARRAY.
               10  WTBL-HEX-ZD-VAL-ENTRY   OCCURS 16 TIMES.
                   15  WTBL-HEX-ZD-VALUE     PIC  X(01).

           05  WHLD-CHAR-X-AREA.
               10  WHLD-CHAR-BINARY-H1 PIC  X(01) VALUE X'00'.
               10  WHLD-CHAR-BINARY-H2 PIC  X(01).
           05  FILLER              REDEFINES
               WHLD-CHAR-X-AREA.
               10  WHLD-CHAR-BINARY-HW  PIC S9(03) COMP.

           05  WCNT-CHAR-CALCED-MAX    PIC S9(06) COMP VALUE +0.
           05  WLNG-HEX-OUTPUT-MAX     PIC S9(08) COMP VALUE +0.
           05  WLNG-CHAR-INPUT-MAX     PIC S9(08) COMP VALUE +0.
           05  WSUB-CHAR               PIC S9(08) COMP VALUE +0.
           05  WHLD-CHAR-AREA.
               10  WTBL-CHAR-POS-ENTRY OCCURS ==MAXINPTSZ== TIMES.
                   15  WTBL-CHAR-POS   PIC  X(01).

           05  WHLD-HEX-ZD-AREA.
               10  WTBL-HEX-ZD-ENTRY   OCCURS ==MAXINPTSZ== TIMES.
                   15  WTBL-HEX-ZD-ZONE   PIC  X(01).
                   15  WTBL-HEX-ZD-DIGIT  PIC  X(01).
      /****************************************************************
      *                   COMMON CONVERSION ROUTINE
      * CONVERT 1 CHARACTER BYTE TO 2 HEXADECIMAL ZONE-DIGIT CHAR
      * BYTES UNTIL ALL INPUT PROCESSED. (LEAVE AS IS; MAKE COPYBOOK?)
      ****************************************************************
       CONVERT-CHAR-TO-HEX-ZONE-DIGIT.

           MOVE SPACES                 TO WHLD-HEX-ZD-AREA
           MOVE LENGTH OF WHLD-HEX-ZD-VAL-ARRAY TO WHLD-DIVISOR

           PERFORM
           VARYING WSUB-CHAR           FROM 1 BY 1
             UNTIL WSUB-CHAR           > WLNG-CHAR-INPUT-MAX
                   MOVE ZEROES
                     TO WHLD-CHAR-BINARY-HW
                   MOVE WTBL-CHAR-POS (WSUB-CHAR)
                     TO WHLD-CHAR-BINARY-H2
                   MOVE WHLD-CHAR-BINARY-HW
                     TO WHLD-DIVIDEND
                   DIVIDE WHLD-DIVIDEND
                                       BY        WHLD-DIVISOR
                                       GIVING    WHLD-QUOTIENT
                                       REMAINDER WHLD-REMAINDER
                   END-DIVIDE
                   MOVE WTBL-HEX-ZD-VALUE  (WHLD-QUOTIENT  + 1)
                     TO WTBL-HEX-ZD-ZONE   (WSUB-CHAR)
                   MOVE WTBL-HEX-ZD-VALUE  (WHLD-REMAINDER + 1)
                     TO WTBL-HEX-ZD-DIGIT  (WSUB-CHAR)
           END-PERFORM
           .
       CONVERT-CTHZD-EXIT.
           EXIT.
      /****************************************************************
      *                   COMMON EDIT ROUTINE
      * NOT REALLY REQUIRED IF YOU ARE CAREFUL AND CHECK LENGTHS
      * MANUALLY. (LEAVE AS IS: MAKE COPYBOOK WITH ABOVE PARAGRAPH?)
      ****************************************************************
       EDIT-CHAR-TO-HEX-ZONE-DIGIT.

           EVALUATE TRUE
           WHEN WLNG-CHAR-INPUT-MAX     = ZEROES
                DISPLAY 'INVALID WLNG-CHAR-INPUT-MAX, VALUE = ZEROES'
                abort process
           END-EVALUATE

           COMPUTE WHLD-DIV-LENGTH =
              WLNG-HEX-OUTPUT-MAX /
              WLNG-CHAR-INPUT-MAX

           EVALUATE TRUE
           WHEN WHLD-DIV-LENGTH         >= 2.00
                CONTINUE
           WHEN OTHER
                DISPLAY 'ERROR. RATIO='
                        WHLD-DIV-LENGTH
                        ' OF HEX-ZD-FIELD LENGTH='
                        WLNG-HEX-OUTPUT-MAX
                        ' MUST BE 2 OR MORE TIMES CHAR LENGTH='
                        WLNG-CHAR-INPUT-MAX
                abort process
           END-EVALUATE

           COMPUTE WCNT-CHAR-CALCED-MAX =
               LENGTH OF WHLD-CHAR-AREA /
               LENGTH OF WTBL-CHAR-POS-ENTRY

           EVALUATE TRUE
           WHEN WLNG-CHAR-INPUT-MAX    > WCNT-CHAR-CALCED-MAX
                DISPLAY 'ERROR. INPUT LENGTH='
                        WLNG-CHAR-INPUT-MAX
                        ' GREATER THAN AVAILABLE LENGTH='
                        WCNT-CHAR-CALCED-MAX
                abort process
           END-EVALUATE
           .
       EDIT-CTHZD-EXIT.
           EXIT.


Only other source code is for each input field supplied by programmer to perform character hex zone-digit routines.
Code:
/***************************************************************
      *    THIS EXAMPLE CONVERTS your-data 10-CHAR TO 20-CHAR HEX
      *    ZONE-DIGIT DISPLAY. THIS IS ONLY NON-STATIC ROUTINE.
      *    (SUPPLY YOUR DATA HERE, EDIT AND PERFORM CONVERSION HERE)
      ****************************************************************
       CONVERT-10-CHAR-TO-20-HEX.
           MOVE LENGTH OF your-char-input
                                       TO WLNG-CHAR-INPUT-MAX

      **** VALIDATION TO NEXT FULL COMMENT CAN BE REMOVED WHEN *******
      **** ASSURED LENGTHS ARE CORRECT! ******************************
           MOVE LENGTH OF your-hex-ZD-output
                                       TO WLNG-HEX-OUTPUT-MAX
           PERFORM EDIT-CHAR-TO-HEX-ZONE-DIGIT
              THRU EDIT-CTHZD-EXIT
      ****************************************************************

           MOVE your-char-input (1:WLNG-CHAR-INPUT-MAX)
                                       TO WHLD-CHAR-AREA
           PERFORM CONVERT-CHAR-TO-HEX-ZONE-DIGIT
              THRU CONVERT-CTHZD-EXIT

           MOVE WHLD-HEX-ZD-AREA (1:WLNG-CHAR-INPUT-MAX * 2)
                                       TO your-hex-ZD-output
           .
       CONVERT-1CT2H-EXIT.
           EXIT.

There are several benefits: main one, being you set the size of the input that you want to convert. Input can be 1 input hex character to 99,999 or whatever. Secondly, you are using mostly copybooks. Cannot mess it up.
No called modules, no COBOL INSPECTs, no assembler-based TR-type translation of characters, no size limitation using packed-decimal concept.
This source code also performs edits to insure programmer does not make a mistake. However, edit routine PERFORMs should be removed before production.
You could use this source inside CICS error handling to produce 4-byte EIBRESP, EIBRESP2, EIBRCODE, etc hex values as 8-byte zone-digit or 2-byte EIBFN as 4 to a data area.
If you wanted to see all zones line followed by all digits lines, you could simple move 1-char zones characters to 1st line, followed by 1-char digits to second line underneath.
Actual COBOL DISPLAY command and formatting is not included in sample code, that is up to programmer. However, I do not think that you would want COBOL DISPLAY in CICS program.
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: Tue Apr 03, 2012 1:05 pm
Reply with quote

Yes, sometimes we have no idea what the TS/OP actually wants. Still don't in this case.

Mr Bill's solution is lightnig-fast. Even doing one byte at a time, it beats anything else I can throw at it into a "cocked hat". Then it can do multiple bytes at once. Not beyond the wit of personkind to include code to do this in a loop. It was not offered as a "full" solution like yours, just the conversion bit. It is probably as direct as you can get for a good Assembler implementation in Cobol.

Dick's solution is for where the caller wants the hex values. Minimal code in the caller. No extra storage in the caller beyond what is necessary for the output (and the call).

Mine is for displaying, anything from a single byte up to the whole of working-storage, maybe a bit of other stuff if you fancy. No need for somewhere to store what is to be displayed, or even the output (beyond an output line, anyway).

All of the above, you want 50 times (or more) in a program, no problem.

Relative subscripting, reference-modification, divide, Lots of fun stuff I suppose :-)
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: Tue Apr 03, 2012 3:34 pm
Reply with quote

Just made some comments on this. Not Cobol comments, they'll be the ones.


Dexter Morgan wrote:
Just noticed this old thread, which is a little hard to follow. If problem is truly to produce zone-digit character representation of hexadecimal, I would like to offer an alternative solution that, I think, is more straightforward and user-friendly. This solution involves simple calculation (COBOL divide) to derive hex characters. It requires 2 copybooks (1 working-storage, 1 procedure division).
Code:
*****************************************************************
      *           CONVERSION CHARACTER-TO-HEX WORKING STORAGE
      *    AREAS TO USE AND HOLD DATA FOR CONVERSION. CAN BE MADE A
      *    STATIC COPYBOOK WITH OVERRIDE FOR INPUT SIZE.
      *    Example: COPY cpybook-name REPLACING ==MAXINPTSZ==
      *                                      BY ==10==.
      ******************************************************************
       01  CHAR-TO-HEX-ZD-AREA.


           05  WHLD-DIVISION-FIELDS.
* the 03 and 02 lengths would benefit from being 04. Why the values for dividened, quotient, remainder, div-length?
* binary with decimal places I don't think is such fun.
               10  WHLD-DIVIDEND       PIC S9(03)    COMP VALUE +0.
               10  WHLD-DIVISOR        PIC S9(02)    COMP VALUE +16.
               10  WHLD-QUOTIENT       PIC S9(02)    COMP VALUE +0.
               10  WHLD-REMAINDER      PIC S9(02)    COMP VALUE +0.
               10  WHLD-DIV-LENGTH     PIC S9(06)V99 COMP VALUE +0.

           05  WHLD-HEX-ZD-VAL-ARRAY.
               10  FILLER              PIC  X(16) VALUE
                   '0123456789ABCDEF'.
           05  FILLER              REDEFINES
               WHLD-HEX-ZD-VAL-ARRAY.
               10  WTBL-HEX-ZD-VAL-ENTRY   OCCURS 16 TIMES.
                   15  WTBL-HEX-ZD-VALUE     PIC  X(01).

           05  WHLD-CHAR-X-AREA.
* why have a name?
               10  WHLD-CHAR-BINARY-H1 PIC  X(01) VALUE X'00'.
               10  WHLD-CHAR-BINARY-H2 PIC  X(01).
           05  FILLER              REDEFINES
               WHLD-CHAR-X-AREA.
* why not 04?
               10  WHLD-CHAR-BINARY-HW  PIC S9(03) COMP.
* why not 08? Why the value? Why the values for the 08s?
           05  WCNT-CHAR-CALCED-MAX    PIC S9(06) COMP VALUE +0.
           05  WLNG-HEX-OUTPUT-MAX     PIC S9(08) COMP VALUE +0.
           05  WLNG-CHAR-INPUT-MAX     PIC S9(08) COMP VALUE +0.
           05  WSUB-CHAR               PIC S9(08) COMP VALUE +0.
           05  WHLD-CHAR-AREA.
               10  WTBL-CHAR-POS-ENTRY OCCURS ==MAXINPTSZ== TIMES.
                   15  WTBL-CHAR-POS   PIC  X(01).

           05  WHLD-HEX-ZD-AREA.
               10  WTBL-HEX-ZD-ENTRY   OCCURS ==MAXINPTSZ== TIMES.
                   15  WTBL-HEX-ZD-ZONE   PIC  X(01).
                   15  WTBL-HEX-ZD-DIGIT  PIC  X(01).
      /****************************************************************
      *                   COMMON CONVERSION ROUTINE
      * CONVERT 1 CHARACTER BYTE TO 2 HEXADECIMAL ZONE-DIGIT CHAR
      * BYTES UNTIL ALL INPUT PROCESSED. (LEAVE AS IS; MAKE COPYBOOK?)
      ****************************************************************
       CONVERT-CHAR-TO-HEX-ZONE-DIGIT.
* should not be necessary
           MOVE SPACES                 TO WHLD-HEX-ZD-AREA
* although the compiler (if you use the optimiser) may well make it a constant anyway,
* this is one of those places where a constant is appropriate. You are never going to get more, or fewer, possible values for half-a-byte than 16. You have even defined it that way in the W-S....
           MOVE LENGTH OF WHLD-HEX-ZD-VAL-ARRAY TO WHLD-DIVISOR

           PERFORM
           VARYING WSUB-CHAR           FROM 1 BY 1
             UNTIL WSUB-CHAR           > WLNG-CHAR-INPUT-MAX
* not needed
                   MOVE ZEROES
                     TO WHLD-CHAR-BINARY-HW
                   MOVE WTBL-CHAR-POS (WSUB-CHAR)
                     TO WHLD-CHAR-BINARY-H2
* why not use whld-char-binary-hw instead of whld-dividend (you can even change the names) and ditch the move?
                   MOVE WHLD-CHAR-BINARY-HW
                     TO WHLD-DIVIDEND
                   DIVIDE WHLD-DIVIDEND
                                       BY        WHLD-DIVISOR
                                       GIVING    WHLD-QUOTIENT
                                       REMAINDER WHLD-REMAINDER
                   END-DIVIDE
* clearer to do the add ones.
                   MOVE WTBL-HEX-ZD-VALUE  (WHLD-QUOTIENT  + 1)
                     TO WTBL-HEX-ZD-ZONE   (WSUB-CHAR)
                   MOVE WTBL-HEX-ZD-VALUE  (WHLD-REMAINDER + 1)
                     TO WTBL-HEX-ZD-DIGIT  (WSUB-CHAR)
           END-PERFORM
           .
       CONVERT-CTHZD-EXIT.
           EXIT.
      /****************************************************************
      *                   COMMON EDIT ROUTINE
      * NOT REALLY REQUIRED IF YOU ARE CAREFUL AND CHECK LENGTHS
      * MANUALLY. (LEAVE AS IS: MAKE COPYBOOK WITH ABOVE PARAGRAPH?)
      ****************************************************************
       EDIT-CHAR-TO-HEX-ZONE-DIGIT.

* what is wrong with an IF? What is wrong with an 88?
           EVALUATE TRUE
           WHEN WLNG-CHAR-INPUT-MAX     = ZEROES
                DISPLAY 'INVALID WLNG-CHAR-INPUT-MAX, VALUE = ZEROES'
                abort process
           END-EVALUATE
* a great liker of dividing. Why not add wlng-char-input-max to itself and test whether greater than wlng-hex-output-max?
           COMPUTE WHLD-DIV-LENGTH =
              WLNG-HEX-OUTPUT-MAX /
              WLNG-CHAR-INPUT-MAX
* another IF?

           EVALUATE TRUE
           WHEN WHLD-DIV-LENGTH         >= 2.00
                CONTINUE
           WHEN OTHER
                DISPLAY 'ERROR. RATIO='
                        WHLD-DIV-LENGTH
                        ' OF HEX-ZD-FIELD LENGTH='
                        WLNG-HEX-OUTPUT-MAX
                        ' MUST BE 2 OR MORE TIMES CHAR LENGTH='
                        WLNG-CHAR-INPUT-MAX
                abort process
           END-EVALUATE

* this should not be calculated every time.
           COMPUTE WCNT-CHAR-CALCED-MAX =
               LENGTH OF WHLD-CHAR-AREA /
               LENGTH OF WTBL-CHAR-POS-ENTRY
* another IF....
           EVALUATE TRUE
           WHEN WLNG-CHAR-INPUT-MAX    > WCNT-CHAR-CALCED-MAX
                DISPLAY 'ERROR. INPUT LENGTH='
                        WLNG-CHAR-INPUT-MAX
                        ' GREATER THAN AVAILABLE LENGTH='
                        WCNT-CHAR-CALCED-MAX
                abort process
           END-EVALUATE
           .
       EDIT-CTHZD-EXIT.
           EXIT.

* I'm not sure zone-digit is a common nomenclature for this.

Only other source code is for each input field supplied by programmer to perform character hex zone-digit routines.
Code:
/***************************************************************
      *    THIS EXAMPLE CONVERTS your-data 10-CHAR TO 20-CHAR HEX
      *    ZONE-DIGIT DISPLAY. THIS IS ONLY NON-STATIC ROUTINE.
      *    (SUPPLY YOUR DATA HERE, EDIT AND PERFORM CONVERSION HERE)
      ****************************************************************
       CONVERT-10-CHAR-TO-20-HEX.
           MOVE LENGTH OF your-char-input
                                       TO WLNG-CHAR-INPUT-MAX

      **** VALIDATION TO NEXT FULL COMMENT CAN BE REMOVED WHEN *******
      **** ASSURED LENGTHS ARE CORRECT! ******************************
           MOVE LENGTH OF your-hex-ZD-output
                                       TO WLNG-HEX-OUTPUT-MAX
           PERFORM EDIT-CHAR-TO-HEX-ZONE-DIGIT
              THRU EDIT-CTHZD-EXIT
      ****************************************************************
* why the reference modification? Why not just a straight move?
           MOVE your-char-input (1:WLNG-CHAR-INPUT-MAX)
                                       TO WHLD-CHAR-AREA
           PERFORM CONVERT-CHAR-TO-HEX-ZONE-DIGIT
              THRU CONVERT-CTHZD-EXIT
* why the reference-modification, even with a multiply this one? Why not just a straight move?
           MOVE WHLD-HEX-ZD-AREA (1:WLNG-CHAR-INPUT-MAX * 2)
                                       TO your-hex-ZD-output
           .
       CONVERT-1CT2H-EXIT.
           EXIT.


Quote:

There are several benefits: main one, being you set the size of the input that you want to convert. Input can be 1 input hex character to 99,999 or whatever. Secondly, you are using mostly copybooks. Cannot mess it up.
No called modules, no COBOL INSPECTs, no assembler-based TR-type translation of characters, no size limitation using packed-decimal concept.
This source code also performs edits to insure programmer does not make a mistake. However, edit routine PERFORMs should be removed before production.
You could use this source inside CICS error handling to produce 4-byte EIBRESP, EIBRESP2, EIBRCODE, etc hex values as 8-byte zone-digit or 2-byte EIBFN as 4 to a data area.
If you wanted to see all zones line followed by all digits lines, you could simple move 1-char zones characters to 1st line, followed by 1-char digits to second line underneath.
Actual COBOL DISPLAY command and formatting is not included in sample code, that is up to programmer. However, I do not think that you would want COBOL DISPLAY in CICS program.


There are several benefits of not doing it the above way:

  • No need to define storage of any size becuase it is already defined (the stuff being used)
  • Input can be one to a very large number of bytes
  • Copybooks can be used. Can mess it up, but with only a length and a data-name needed as a minimum, you have to work hard to do so
  • Call is used to make functionality discrete and easily reusable. If necessary, only one place to change how the code is done
  • No size-limitations, code of choice to satisfy requirement
  • If data is not returned, nothing to check
  • If data is returned, can be checked anyway
  • No need to remove checking from production
  • No compromises in code if displaying multiple fields of different sizes
  • No problem with DISPLAY if the intention was to allow fields to be DISPLAYed in hex. Since DISPLAY in CICS is less likely...
Back to top
View user's profile Send private message
ajaydwivedi4u

New User


Joined: 21 Sep 2019
Posts: 4
Location: India

PostPosted: Sat Sep 21, 2019 1:34 pm
Reply with quote

Delete - tail-gating 7 year-old topic. No code tags. Asking for help from a specific person. No evidence of what had been tried and why it was wrong.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
No new posts Mark Previous & next lines when a... DFSORT/ICETOOL 9
No new posts sort to find out the char which repea... Mainframe Interview Questions 10
No new posts Help with C character vs C string All Other Mainframe Topics 3
Search our Forums:

Back to Top