×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is the equivalent string data type in cobol

What is the equivalent string data type in cobol

What is the equivalent string data type in cobol

(OP)
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!!!

RE: What is the equivalent string data type in cobol

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.

RE: What is the equivalent string data type in cobol

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?
 

RE: What is the equivalent string data type in cobol

(OP)
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

RE: What is the equivalent string data type in cobol

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.

RE: What is the equivalent string data type in cobol

(OP)
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

RE: What is the equivalent string data type in cobol

(OP)
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

RE: What is the equivalent string data type in cobol

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
http://www.microfocus.com/Resources/whitepapers/wpviewall.asp?ln=View%20All
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close