Commander
Commander
405 views

How can I compute the 8-bit CRC sum check within an Net Express/VC COBOL program?

Hello,
I need to calculate the CRC code to a 36 position alphanumeric field, applying the crc8 algorithm. Is there any example in COBOL for NetExpress or VC?
I have tried, from several examples in C#, to generate a cobol program, using the C# to MF COBOL converter from https://cs2cobol.microfocuscloud.com/, but the sources that generate give problems.

0 Likes
8 Replies
Commander
Commander

Attached examples of C# programs used

0 Likes
Micro Focus Expert
Micro Focus Expert

Neither one of these example programs is a C# program. 
crc8.zip contains a native C program source and prcrc8.txt is a Java program.

On what platform do you require this routine?
How are you compiling, to native code or to managed code?

0 Likes
Commander
Commander

Hello,

In my case, I prefer the routine in native code.

I searched the RM-Cobol forum and found a sample file crc32.zip.

Thank you.

 

0 Likes
Micro Focus Expert
Micro Focus Expert

I wasn't sure if your last reply here meant that you already had a solution to your question but the following is a translation to COBOL of the C program you attached. I don't know much about CRC so cannot guarantee the validity of the program functionality but here is the conversion anyway.

Calling Program:

       identification division.
       program-id. mainprog.
       data division.
       working-storage section.
       01 input-str pic x(10) value "ABCDEFGHIJ".
	   01 num-bytes binary-long value 10.
	   01 crc       binary-char unsigned value zeroes.
       procedure division.

           call "crc8" using input-str num-bytes crc
           display crc
           goback.
           

CRC subprogram:

      $set sourceformat"variable"
       identification division.
       program-id. crc-8.
       data division.
       working-storage section.
	   78 CRC-START-8 value 0.
       01 sht75-crc-table binary-char unsigned occurs 256
          values  0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76,  31,  46,
	             67,  114, 33,  16,  135, 182, 229, 212, 250, 203, 152, 169, 62,  15,  92,  109,
	            134, 183, 228, 213, 66,  115, 32,  17,  63,  14,  93,  108, 251, 202, 153, 168,
	            197, 244, 167, 150, 1,   48,  99,  82,  124, 77,  30,  47,  184, 137, 218, 235,
	             61,  12,  95,  110, 249, 200, 155, 170, 132, 181, 230, 215, 64,  113, 34,  19,
	            126, 79,  28,  45,  186, 139, 216, 233, 199, 246, 165, 148, 3,   50,  97,  80,
	            187, 138, 217, 232, 127, 78,  29,  44,  2,   51,  96,  81,  198, 247, 164, 149,
	            248, 201, 154, 171, 60,  13,  94,  111, 65,  112, 35,  18,  133, 180, 231, 214,
	            122, 75,  24,  41,  190, 143, 220, 237, 195, 242, 161, 144, 7,   54,  101, 84,
	             57,  8,   91,  106, 253, 204, 159, 174, 128, 177, 226, 211, 68,  117, 38,  23,
	            252, 205, 158, 175, 56,  9,   90,  107, 69,  116, 39,  22,  129, 176, 227, 210,
	            191, 142, 221, 236, 123, 74,  25,  40,  6,   55,  100, 85,  194, 243, 160, 145,
	             71,  118, 37,  20,  131, 178, 225, 208, 254, 207, 156, 173, 58,  11,  88,  105,
	              4,   53,  102, 87,  192, 241, 162, 147, 189, 140, 223, 238, 121, 72,  27,  42,
	            193, 240, 163, 146, 5,   52,  103, 86,  120, 73,  26,  43,  188, 141, 222, 239,
	            130, 179, 224, 209, 70,  119, 36,  21,  59,  10,  89,  104, 255, 206, 157, 172.
	   	   
	   01 char-pos       binary-long value 0.
	   01 input-str-hold pic x.
	   01 input-str-b    binary-char unsigned redefines input-str-hold.
	   linkage section.
	   01 input-str pic x.  *>  this will actually be num-bytes in length
	   01 num-bytes binary-long.
	   01 crc       binary-char unsigned. *> This will be the return value
       procedure division using input-str num-bytes crc.

		   move CRC-START-8 to crc
		   perform varying char-pos from 1 by 1 until char-pos > num-bytes
			   move input-str(char-pos:1) to input-str-hold
               compute crc = sht75-crc-table(input-str-b b-xor crc)
           end-perform
           goback.
0 Likes
Commander
Commander

Hello, 

In principle, yes, thank you very much.
I have had to adapt the source program a bit, to which I attach, to try it with different strings. And I see that the value of crc-8 is always the same, I do not know if the program is correct.

 

For example:

 

*01 input-str pic x(36) value
* "TBAI-00000006Y-251019-btFpwP8dcLGAF-". .
*01 num-bytes binary-long value 36.
*01 crc binary-char unsigned value zeroes.

ccrc8.  CALL "crc8" USING input-str num-bytes crc.

Can you confirm me if it is correct?

 

 

 

0 Likes
Micro Focus Expert
Micro Focus Expert

I tested your version of the program and it worked fine. If I change the input string value then the return value will be a different value. What values do you see being returned?

I tested under Visual COBOL 6.0.

0 Likes
Commander
Commander

Hello,

 

In my case, varying the characters of the 36 position string, the result is always the same: crc = 544.

I have tried it with VC 60 and with NetExpress, and crc = 544.

On the other hand, debugging the program crc8.cbl, in VC 6.0, I find it complicated, examine and monitor the crc field, while in NetExpress, it seems simpler, passing the mouse over the field, it does it by default, and pressing the right button, you have the option to change, monitor it.

 

How should I configure the editor in VCVS2019, so that it behaves in a similar way to NE?


Reading the help in
https://www.microfocus.com/documentation/visual-cobol/vc60/VS2019/GUID-C4313D85-8CD0-47AE-9154-E09DCE81FA0D.html
Pressing Shift+F9 , Examine data item' on VC60, shows nothing.


Translated with www.DeepL.com/Translator (free version)

0 Likes
Micro Focus Expert
Micro Focus Expert

Visual COBOL should allow you to hover the mouse over the data item and it should display in a popup. You can edit the value in place. You can also right click on a data item and select Watch to place it in a watch list.

Something appears to be wrong with your project.

Can you please zip up the solution/project folder and attach it to this post or email it to chris.glazier@microfocus.com?

Thanks

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.