Highlighted
Super Contributor.
Super Contributor.
462 views

How to pass VT-BSTR object reference to PIC X

Jump to solution

I have this data type

01 aCharArray object reference.

It's VT-BSTR. How to pass it to standard PIC X(n) variable?

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

In what way are you using this VT-BSTR? Are you passing it to a non-COBOL COM object? Normally you can just define these as standard COBOL PIC X fields and they will automatically be converted to BSTR by the run-time system when passing to a COM object and will be converted back to PIC X upon return.

A real simple example of how to convert between a CharArray type and a PIC X:

       program-id. testchar.
       environment division.
       class-control.
           CharacterArray is class "chararry".
       working-storage section.
       01 astring    pic x(10)   value "Chris".
       01 asize      pic s9(9) comp-5   value 5.
       01 achararray object.
       01 anewstring pic x(10) value spaces.
       procedure division.
          invoke CharacterArray "fromBuffer"
              using asize
                    astring
              returning achararray
          end-invoke
          invoke achararray "getValue" returning anewstring
          display anewstring
          goback.

View solution in original post

0 Likes
2 Replies
Highlighted
Super Contributor.
Super Contributor.
I know about this article: https://supportline.microfocus.com/documentation/books/nx51ws01/dmolda.htm But there is only sample how to display such char array to command line.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

In what way are you using this VT-BSTR? Are you passing it to a non-COBOL COM object? Normally you can just define these as standard COBOL PIC X fields and they will automatically be converted to BSTR by the run-time system when passing to a COM object and will be converted back to PIC X upon return.

A real simple example of how to convert between a CharArray type and a PIC X:

       program-id. testchar.
       environment division.
       class-control.
           CharacterArray is class "chararry".
       working-storage section.
       01 astring    pic x(10)   value "Chris".
       01 asize      pic s9(9) comp-5   value 5.
       01 achararray object.
       01 anewstring pic x(10) value spaces.
       procedure division.
          invoke CharacterArray "fromBuffer"
              using asize
                    astring
              returning achararray
          end-invoke
          invoke achararray "getValue" returning anewstring
          display anewstring
          goback.

View solution in original post

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.