Absent Member.
Absent Member.

[archive] Array

[Migrated content. Thread originally posted on 04 September 2007]

I have problems to translate the following code to cobol..

Dim S(); Dim I
S = InfoArray
For I = Lbound(s) to Ubound(s)
Debug.Print S(I,0), S(I,1)
Next i

I tried this, but I dont now how to declare the array.

CALL "C$SETVARIANT" USING op-tab array-handle.
create api of cbfisch handle in cbfisch-handle.
inquire cbfisch-Handle @Info info-handle.
modify info-Handle @InfoID "OP-Liste".
modify info-Handle @InfoArray () array-handle.
CALL "C$GETVARIANT" USING array-handle op-tab.

Someone who can help me?.
The def file is attached
4 Replies
Absent Member.
Absent Member.

RE: [archive] Array

The InfoArray method apparently return a SAFEARRAY variant item. The unfortunate thing here is that ACUCOBOL-GT as of current do not support receiving an item like this. The problem being in that the allocation in WORKING-STORAGE is a static size, while the SAFEARRAY is by its very nature meant to be a dynamic entity.
You *may* try to do this:

01  S.
   03 FILLER                OCCURS 1000.
      05 CobItem             USAGE HANDLE OF VARIANT OCCURS 1000.

Setting the OCCURS values as high as predictably needed and then do the:

MODIFY info-handle InfoArray() GIVING S.

Chances are, provided the frame of 1000 by 1000 is not blown, you will be able to access the table:

   CobItem(x coordinate, y coordinate)

Problem however, is: How do you know to stop?
If the class have a method or two to tell you how many items it returns, well, then you might get this to work. Otherwise you will have to capture the exception and hope for the best.
Absent Member.
Absent Member.

RE: [archive] Array

I noticed the object also return RecordSet. Why don't you use this instead?
Here is an example of how to use RecordSet (from MSADO):

       PROGRAM-ID. ExModifyADO.
      * Copyright (c) 1996-2006 by Acucorp, Inc.  Users of ACUCOBOL
      * may freely modify and redistribute this program.
      * The purpose of this application is to illustrate use of the MSADO
      * technology for database access
       CONFIGURATION                SECTION.
           COPY    "MSADO.def".
       DATA        DIVISION.
       WORKING-STORAGE              SECTION.
       77 hConnection               HANDLE OF Connection.
       77 hRecordset                HANDLE OF Recordset.
       77 ConnStr                   PIC X(256).
       77 WS-ConnStat               PIC S9(9).
       Main section.
      *Create an instance of connection
           CREATE  Connection       OF ADODB
                   HANDLE           IN hConnection.
      *Create an instance of recordset
           Create  Recordset        OF ADODB
                   HANDLE           IN hRecordset.
      *Set up driver, database, path for connection
           STRING  "Driver={Microsoft Access Driver (*.mdb)};"
                   DELIMITED        BY SIZE INTO ConnStr.
      *Connect open) database
           MODIFY  hConnection      @Open(ConnStr).
           INQUIRE hConnection      State IN WS-ConnStat.
      *Did we open alright?
           IF      WS-ConnStat      NOT = adStateOpen
                   GO TO            MAIN-900
      *Connect the recordset to the table we want to work with
      *Include keys, optimistic locking, use existing connection
           MODIFY  hRecordset       @Open("Contacts", hConnection,
                   adOpenKeySet, adLockOptimistic, adCmdTable).
      *Add a record, add values to fields, commit
           MODIFY   hRecordset     
                    fields::Item("FirstName")::value = "Barbara"
                    fields::Item("LastName")::value  = "Streisand"
    ' Delete the new record because this is a demonstration
           MODIFY   hConnection     Execute(
                    "DELETE FROM Contacts WHERE LastName = 'Streisand'")
                    .                  .
           ACCEPT  OMITTED.
      *Close recordset
           MODIFY  hRecordset       @Close().
      *Close connection
           MODIFY  hConnection      @Close().
      *Finish up.
    DESTROY hRecordset.
    DESTROY hConnection.

Absent Member.
Absent Member.

RE: [archive] Array


thank you for the sample. I try to use it.
I noticed recordset too, but I have no experience
with it, so I first took the "easy way" with the array.

Absent Member.
Absent Member.

RE: [archive] Array


Good luck, and share your experience with us!
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.