Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem moving C# String to a Cobol Group Item

Status
Not open for further replies.

SCALVI

IS-IT--Management
May 21, 2001
3
IT
I'M TRYING TO MOVE A RECORD STRING (SYSTEM.STRING) COMPOSED PARTIALLY FROM ESCAPED SEQUENCE, TO A COBOL GROUP ITEM STRUCTURE (REC-TAB) WITH COMP3 DATA ITEM.
I UNDERSTAND THE COMP3 COMPRESSION MECHANISM BUT I HAVE SOME PROBLEM WITH COBOL VALUE ASSIGNAMENT.
WITH HEX CHAR LOWER THAN "7F" IT LOOK FINE, BUT WITH HEX UPPER THEN "7F" LIKE "99" THE CHAR CONVERSION FAILS RETURNING STRANGE VALUES.

CORRECT WITH LOW VAL X'09776C2D31...
WAITING WITH HIGH VAL X'09996C2D31...
RESULT WITH HIGH VAL X'09C2996C2D31... WHY C2? WHILE I'M WAITING FOR X'09996C2D31...

I CANT'T FIND AN ALTERNATIVE HEX CONVERSION FUNCTION IN COBOL.

THANKS.

COBOL PROGRAM

IDENTIFICATION DIVISION.
PROGRAM-ID. Program1 AS "ConsoleApplication2.Program1".
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
REPOSITORY.
CLASS CLASS-String AS "System.String"
CLASS CLASS-PROVA AS "ClassLibrary4.Class1".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CLS1 OBJECT REFERENCE CLASS-PROVA.
01 String-Object OBJECT REFERENCE CLASS-String.
01 Alphanumeric-Item PIC X(50).
01 REC-TAB.
05 MII-NUMBER PIC S9(004) COMP-3.
05 MII-DESCRIPTION PIC X(025).
05 MII-DECIMAL PIC S9(009)V9(02) COMP-3.

PROCEDURE DIVISION.

INVOKE CLASS-PROVA "NEW" RETURNING CLS1.

INVOKE CLS1 "GetValuesOK" RETURNING String-Object.
SET Alphanumeric-Item TO String-Object
MOVE Alphanumeric-Item TO REC-TAB

INVOKE CLS1 "GetValuesKO" RETURNING String-Object.
SET Alphanumeric-Item TO String-Object *PROBLEM COMVERTING ANSI CHAR HIGER THEN X"7F"
MOVE Alphanumeric-Item TO REC-TAB

END PROGRAM Program1.

C# PROGRAM

using System;
using System.Text;

namespace ClassLibrary4
{
public class Class1
{
public Class1(){}
public string GetValuesOK()
{
string tmpstr = "\u0009\u0077\u006C-12345678901234567890123-\u0000\u0002\u0067\u0065\u0043\u005D ";
return tmpstr;
}
public string GetValuesKO()
{ // HIGHER HIGHER
string tmpstr = "\u0009\u0099\u006C-12345678901234567890123-\u0000\u0009\u0087\u0065\u0043\u009D ";
return tmpstr;
}
}
}
 
Scalvi -

Not sure what's going on except that \u0080 - \u009f are defined as Unicode control characters and don't map to any ASCII control/character value. Likely the SET statement is trying to convert to ASCII and stumbles at this point.

Regards.

Glenn
 
"WITH HEX UPPER THEN "7F" LIKE "99" THE CHAR CONVERSION FAILS RETURNING STRANGE VALUES."

Whyt is this a failure? There ARE 'strange' characters in that range.

Dimandja
 
Thanks 3gm and Dimandja,

Ok, the conversion does not fails, but result is not appropriate for Group Item structure assignment.

I'M WAITING FOR X'09996C2D31...
BUT RESULT IS X'09C2996C2D31... WHY C2?

Are there other ways to do this conversion?

Do you know a Cobol function that convert a string or a number like "99" into a Char?

Ste
 
Scalvi -

I might start by reducing the problem to its simplest form. I believe the problem is that SET doesn't convert the Unicode string the way you expect it to (i.e. give you x'C299' instead of x'99'). Change your GetValuesKO routine to just return the u\0099 string and see if my supposition is true.

If not, I suspect there's some other odd problem going on (some storage overlay or something).

If so, then I'd confirm the value of "string-object" is x'0099' after the call to GetValuesKO.

Perhaps there is a namespace issue involving string. You might consider qualifying the return type of GetValuesKO as system.string (forgive me if this is not exactly right - my C# is almost non-existent).

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top