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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the equivalent string data type in cobol

Status
Not open for further replies.

ronaldTest

Programmer
Nov 29, 2008
5
0
0
hi there,

I'm trying to call a cobol dll from .Net application but when the dll returns the string value, it returns the extended ascii characters.

It is working fine if i'm passing the integer value.

please help!!!
 
Almost all languages other then COBOL define strings as variable length, either terminated by a Low-Value character ("null terminated") or preceded by a length field. The length field is a one-byte binary value. If your dialect of COBOL does not support one-byte binary fields, do the following:
01 STRING.
05 STRING-LENGTH PIC X(01).
05 STRING-DATA PIC X(nn).

01 STRING-LENGTH-BINARY PIC S9(4) COMP.
01 REDEFINES STRING-LENGTH-BINARY.
05 Pic X(01).
05 STRING-LENGTH-X Pic X(01).
. . .
MOVE ZERO TO STRING-LENGTH-BINARY
Move STRING-LENGTH TO STRING-LENGTH-X

STRING-LENGTH-BINARY now contains the length of the string.
 
Ok then convert the .Net-string into a string which COBOL needs before passing it to the COBOL program or convert returned result from COBOL to a format you need in .Net.

If you want to help you need more specify the problem you have:
1. What a string you try to pass to COBOL (ascii, unicode,...)?
2. What you mean with "extended ascii characters" returned by COBOL ? And where is the problem, i.e. why you are not able to decode this extended ASCII into your string (probably unicode)?
3. What COBOL compiler are you using?
 
OK, here is my cobol code:

-----------------------------------------
IDENTIFICATION DIVISION.
PROGRAM-ID. TRIAL.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS SYS-STRING AS "System.String".

001000 DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TRY PIC X(10).

LINKAGE SECTION.

01 WS-TEST-2 PIC S9(04) COMP-5.
01 WS-TEST OBJECT REFERENCE SYS-STRING.
/
100000 PROCEDURE DIVISION USING WS-TEST-2
WS-TEST.
100100 0000-MAINLINE SECTION.
0000.
COMPUTE WS-test-2 = WS-test-2 + 3.
SET WS-TRY TO WS-TEST
display ws-try
STOP RUN.
100700 goback.
0099-EXIT.
EXIT.
--------------------------------------------------

I took the above code from the internet and tried to compile/run it using .Net express 5.1 and below are the questions:

1) at the line "SET WS-TRY TO WS-TEST" I'm having this error: "Operand WS-TRY should be numeric". do you know why?

2) i'm not sure about "System.String". can you please explain this to me? is this some kinda default class from cobol?

Thanks
R
 
I think, you try to compile with NetExpress a source, which was written for NetCOBOL. These are 2 different compilers: NetCOBOL for .NET is from Fujitsu a and NetExpress from MicroFocus. Therefore your source won't compile.

System.String is a Class from .Net Framework.

I never used this compiler, but I guess that this
Code:
       REPOSITORY.
          CLASS SYS-STRING AS "System.String".
only gives to .Net System-String Class other name i.e. for the program is now the class named SYS-STRING class.

Then this in LINKAGE SECTION would said
Code:
   01 WS-TEST      OBJECT REFERENCE SYS-STRING.
that WS-TEST is a instance of the class SYS-STRING aka System.String

And at end this
Code:
SET WS-TRY TO WS-TEST
sets the reference of WS-TRY TO WS-TEST, i.e. what was passed to the program via LINKAGE SECTION into WS-TEST argument will be now inside of the program available in WS-TRY field.

The source could be ok, but it won't compile with NetExpress, because it's source for NetCOBOL and these are 2 different and incompatible COBOL compilers.
 
ok... don't worry about the "netcobol for .net".. my company is using microfocus netexpress 3.1 anyway so it won't work with class system.string.

I was testing using netcobol for the testing purpose only.

back to your questions:
1. What a string you try to pass to COBOL (ascii, unicode,...)? -- just a normal string from .NET (e.g. "test")

2. What you mean with "extended ascii characters" returned by COBOL ? -- like a cross sign and square sign

And where is the problem, i.e. why you are not able to decode this extended ASCII into your string (probably unicode)? -- how do I decode this?

3. What COBOL compiler are you using? -- net express 3.1

below are my original cobol program:
----------------------------------

IDENTIFICATION DIVISION.
PROGRAM-ID. TRIAL.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.

001000 DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TRY PIC X(5) VALUES 'hello'.

LINKAGE SECTION.

01 WS-TEST-2 PIC S9(04) COMP-5.
01 WS-TEST PIC X(100).

/
100000 PROCEDURE DIVISION USING WS-TEST-2
WS-TEST.

100100 0000-MAINLINE SECTION.
0000.
COMPUTE WS-test-2 = WS-test-2 + 3.
MOVE 'hello' TO WS-TEST.

100700 goback.

0099-EXIT.
EXIT.

----------------------------------------------

Below is the calling code from ASP.NET

------------------------------------------
'Web service cobol dll
<DllImport("TRIAL.DLL", EntryPoint:="TRIAL", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub test(ByRef Size As Integer, ByVal Buffer _
As String)
End Sub


Public Function wsCobol() As String
Dim sString As String
Dim iInt As Integer

sString = "temp"
iInt = 10

test(iInt, sString)

return sString
-------------------------------------------

do you have any further thoughts?

Thanks
R
 
hey mate.. sorry just giving you the updates.. the dllimport statement from ASP.NET below should be passing byref for string.

'Web service cobol dll
<DllImport("TRIAL.DLL", EntryPoint:="TRIAL", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Sub test(ByRef Size As Integer, ByRef Buffer _
As String)
End Sub

Now, here is another real problem (please ignore all the questions that I had asked you - sorry for the confusion):

1) when execute this line "test(iInt, sString)" in wsCobol function, the application is halted immediately.

2) When I tried to call this dll from VBA code, I'm getting the error: "114 Attempt to access item beyond bounds of memory" and the application was also terminated.

3) In the import dll statement, When I used "ByVal Buffer as string" instead of "ByRef Buffer as string" then the dll cobol will return the extended ASCII char.

It's been driving me crazy.. i need get this done by the end of this year as I need to ensure the stakeholders by next year if the project is a "go" or not.

Please help..

Thanks
R
 
Hi ronaldTest,

Sorry, but I cannot help you with this, because lack of my knowledge in this area. I don't develop with Microfocus NetExpress and/or Visual Basic.

But try following:
*Look in your MF NetExpress manuals delivered with compiler
*Look at some examples in the NetExpress directory
*Look at these whitepapers
e.g. this one could be interesting Developing Mixed Visual Basic/COBOL Applications
* or try other web sources or forums specialized for MF COBOL and VB.

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top