Search390.com Developer Tip July 25, 2001 ======================================================== SPONSORED BY: Postmaster Direct ======================================================== What do you like? Networks? Computer Games? Downloads? How about Free Stuff? Search390.com can get you FREE info on the topics that interest you most - and there are so many to choose from! We'll find related news, information and special offers and deliver them directly to your e-mailbox, all at no charge! Sign up here today http://search390.techtarget.com/postmasterDirect/ ======================================================== ========================================================= CALLING ALL DINOS! ========================================================= July's tip of the month contest is underway! This month's prize is an awesome King T-Rex radio control dinotronic dinosaur chosen with all of you dinos in mind! To submit a tip, or to check out this month's prize and contest rules, click here: http://search390.techtarget.com/tipsPrize/0,289492,sid10_prz750651_cts750650,00.thml ========================================================= TODAY'S DEVELOPER TIP: Dumping COBOL storage for the hexadecimally challenged By Jim Keohane Some of the tips recently submitted by Search390 members brought back memories. When someone needed something slightly unorthodox done in a COBOL program, I would just code an assembler subroutine to do so. However, often it was both fun and illustrative to accomplish the task in COBOL itself. As the other tips showed, there are legitimate reasons for doing as much as possible in COBOL to avoid support issues with assembler code. One frequent requested item was the ability to dump the contents of a memory location in hexadecimal notation. Reasons for this varied. The data being "dumped" may be in ASCII. It may contain unprintable characters. It may be of an unknown structure or a freeform structure that could do with some help during debugging. It may be storage that you suspect has been corrupted. All reasons that are even more valid in this day of cross-platform data transfer and communications. Here's some simple COBOL code to translate storage into hex. It works with 8 bytes at a time but you could easily make that larger and/or variable. First we have 3 tables. They are each 256 bytes in size. The first contains all 256 byte values from x'00' th x'FF'. The next contains the correct leftmost hex nibble that corresponds to the byte in first table. The last table contains the corresponding rightmost hex nibble. They never change. How quickly can you say "good candidate for a copy book?" Then, we have an 8 byte WORK field in which we move data to be converted to hex. This exercise plays with the 8 bytes "5-ABCabc". We will produce 4 lines of output like: 5-ABCabc F6CCC888 50123123 F560-C1C2-C381-8283 This is the original data. The left hex nibbles. The right hex nibbles, and then the hex results in a formatted rendering. It takes 10 lines of code or less to produce the above 4 lines of output. See full source below. Note that WORK is redefined as both WORK-L and WORK-R so that the left and right nibbles can be moved into their proper positions in the formatted field BOTH. Be warned that this code uses the dreaded MOVE CORRESPONDING feature that is anathema to some shops. Probably the same shops that proscribe use of qualification (MONDAY IN WEEK OF PAY-PERIOD) in deference to the more cryptic WKS-PAYP-WK-MOND. For extra credit: Code this as a COBOL subroutine that is passed two parameters, BUFFER-LENGTH and BUFFER. Obviously the caller can pass almost any DATA-NAME as BUFFER along with the length to be dumped. You could construct a very nice formatted dump directed to SYSPRINT. Before calling the subroutine, the caller could DISPLAY "CONTENTS OF MQSERIES BUFFER WITH LENGTH = " BUFFER-LENGTH. Code ID DIVISION. PROGRAM-ID. HEXCOBOL. DATA DIVISION. WORKING-STORAGE SECTION. 01 ALL-256-VALUES. 05 PIC X(16) VALUE X'000102030405060708090A0B0C0D0E0F'. 05 PIC X(16) VALUE X'101112131415161718191A1B1C1D1E1F'. 05 PIC X(16) VALUE X'202122232425262728292A2B2C2D2E2F'. 05 PIC X(16) VALUE X'303132333435363738393A3B3C3D3E3F'. 05 PIC X(16) VALUE X'404142434445464748494A4B4C4D4E4F'. 05 PIC X(16) VALUE X'505152535455565758595A5B5C5D5E5F'. 05 PIC X(16) VALUE X'606162636465666768696A6B6C6D6E6F'. 05 PIC X(16) VALUE X'707172737475767778797A7B7C7D7E7F'. 05 PIC X(16) VALUE X'808182838485868788898A8B8C8D8E8F'. 05 PIC X(16) VALUE X'909192939495969798999A9B9C9D9E9F'. 05 PIC X(16) VALUE X'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'. 05 PIC X(16) VALUE X'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'. 05 PIC X(16) VALUE X'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'. 05 PIC X(16) VALUE X'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'. 05 PIC X(16) VALUE X'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'. 05 PIC X(16) VALUE X'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'. 01 ALL-256 REDEFINES ALL-256-VALUES PIC X(256). 01 LEFT-NIBBLES-VALUES. 05 PIC X(16) VALUE '0000000000000000'. 05 PIC X(16) VALUE '1111111111111111'. 05 PIC X(16) VALUE '2222222222222222'. 05 PIC X(16) VALUE '3333333333333333'. 05 PIC X(16) VALUE '4444444444444444'. 05 PIC X(16) VALUE '5555555555555555'. 05 PIC X(16) VALUE '6666666666666666'. 05 PIC X(16) VALUE '7777777777777777'. 05 PIC X(16) VALUE '8888888888888888'. 05 PIC X(16) VALUE '9999999999999999'. 05 PIC X(16) VALUE 'AAAAAAAAAAAAAAAA'. 05 PIC X(16) VALUE 'BBBBBBBBBBBBBBBB'. 05 PIC X(16) VALUE 'CCCCCCCCCCCCCCCC'. 05 PIC X(16) VALUE 'DDDDDDDDDDDDDDDD'. 05 PIC X(16) VALUE 'EEEEEEEEEEEEEEEE'. 05 PIC X(16) VALUE 'FFFFFFFFFFFFFFFF'. 01 LEFT-NIBBLES REDEFINES LEFT-NIBBLES-VALUES PIC X(256). 01 RIGHT-NIBBLES-VALUES. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 05 PIC X(16) VALUE '0123456789ABCDEF'. 01 RIGHT-NIBBLES REDEFINES RIGHT-NIBBLES-VALUES PIC X(256). 01 WORK PIC X(8). 01 WORK-L REDEFINES WORK. 05 L1 PIC X. 05 L2 PIC X. 05 L3 PIC X. 05 L4 PIC X. 05 L5 PIC X. 05 L6 PIC X. 05 L7 PIC X. 05 L8 PIC X. 01 WORK-R REDEFINES WORK. 05 R1 PIC X. 05 R2 PIC X. 05 R3 PIC X. 05 R4 PIC X. 05 R5 PIC X. 05 R6 PIC X. 05 R7 PIC X. 05 R8 PIC X. 01 BOTH. 05 L1 PIC X. 05 R1 PIC X. 05 L2 PIC X. 05 R2 PIC X. 05 PIC X VALUE '-'. 05 L3 PIC X. 05 R3 PIC X. 05 L4 PIC X. 05 R4 PIC X. 05 PIC X VALUE '-'. 05 L5 PIC X. 05 R5 PIC X. 05 L6 PIC X. 05 R6 PIC X. 05 PIC X VALUE '-'. 05 L7 PIC X. 05 R7 PIC X. 05 L8 PIC X. 05 R8 PIC X. PROCEDURE DIVISION. MOVE '5-ABCabc' TO WORK. DISPLAY WORK. INSPECT WORK CONVERTING ALL-256 TO LEFT-NIBBLES. DISPLAY WORK. MOVE CORR WORK-L TO BOTH. MOVE '5-ABCabc' TO WORK. INSPECT WORK CONVERTING ALL-256 TO RIGHT-NIBBLES. DISPLAY WORK. MOVE CORR WORK-R TO BOTH. DISPLAY BOTH. GOBACK. ------------------------------------------------------ About the author: Jim Keohane ([EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>) is president of New York consulting company Multi-Platforms, Inc. His company specializes in commercial software development/consulting with emphasis on cross-platform and performance issues. Did you like this tip? Send us an email <mailto:[EMAIL PROTECTED]> to let us know your thoughts, or rate this tip by scrolling to the bottom of http://www.search390.com/tip/1,289483,sid10_gci755509,00.html ======================================================= Share the knowledge! ======================================================= Have you got some code secrets to share with your colleagues? Don't miss out on the opportunity to help someone else or to post your own questions. Check out our search390 Developer Discussion Forum at http://search390.discussions.techtarget.com/WebX?50@@.ee83ff7 Also check out our other search390 forums on operating systems, e-business, and sound off (aka miscellaneous!). There's sure to be something there to spark your interest. ======================================================== Disclaimer: Our tips exchange is a forum for you to share technical advice and expertise with your peers and to learn from other IT professionals. Techtarget.com provides the infrastructure to facilitate this sharing of information. However, we can't guarantee the accuracy and validity of the material submitted. You agree that your use of the ask the expert services and your reliance on any questions, answers, information or other materials received through the web site will be at your own risk. ======================================================== ======================================================== If you would like to sponsor this or any TechTarget newsletter, please contact Gabrielle DeRussy at [EMAIL PROTECTED] ======================================================== If you no longer wish to receive this newsletter simply reply to this message with "REMOVE" in the subject line. Or, visit http://search390.techtarget.com/register and adjust your subscriptions accordingly. If you choose to unsubscribe using our automated processing, you must send the "REMOVE" request from the email account to which this newsletter was delivered. Please allow 24 hours for your "REMOVE" request to be processed.
