×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

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!

*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

COBOL General discussion FAQ

Cobol Code Examples

Using COM to access Excel through Fujitsu COBOL (inc. POWER COBOL) by fredericofonseca
Posted: 18 Jan 05

The code below opens Excel on a separate process. It is not an embedded control.

It can be used from both NetCOBOL and POWERCOBOL.
For an initial test it is better if debugger is used to step through the code. Alternativelly place an accept before the "INVOKE OBJ-WBK "Close"." so that a result can be seen


CODE

 add to repository
           CLASS COM-EXCEPTION AS "*COM-EXCEPTION"
           CLASS COM AS "*COM".

CODE

 add to scriplets
       WORKING-STORAGE SECTION.
       01 GLOBAL-WS.
           05  XLS-APP-TYPE   PIC X(8192) VALUE "Excel.Application".  
           05  OBJ-APP  OBJECT REFERENCE COM.
           05  OBJ-WBKS   OBJECT REFERENCE COM.
           05  OBJ-WKS   OBJECT REFERENCE COM.
           05  OBJ-WKSS   OBJECT REFERENCE COM.
           05  OBJ-WBK   OBJECT REFERENCE COM.
           05  OBJ-RANGE   OBJECT REFERENCE COM.
           05  RETURN-ERROR   PIC 9(9) COMP-5.
           05  WINDEX PIC S9(9) COMP-5 VALUE 1.
       01 W-WORKBOOK PIC X(40) VALUE "mypathname\myexcelfile.xls".
       01 W-TRUE PIC S9(4) COMP-5 VALUE -1.
       01 M1 PIC X(2) VALUE "A ".
       01 M1-R REDEFINES M1.
          05 PIC X.
          05 N1 PIC 9.
       01 W-VALUE1 PIC X(10).
       PROCEDURE       DIVISION.
           INVOKE COM "CREATE-OBJECT"
                  USING XLS-APP-TYPE
                  RETURNING OBJ-APP.
           INVOKE OBJ-APP "GET-WORKBOOKS"
           RETURNING OBJ-WBKS.
           INVOKE OBJ-WBKS "OPEN"
                  USING W-WORKBOOK
              RETURNING OBJ-WBK
           INVOKE OBJ-WBK "GET-WORKSHEETS"
                  RETURNING OBJ-WKSS
           INVOKE OBJ-WKSS "GET-ITEM"
                  USING WINDEX
                  RETURNING OBJ-WKS
           INVOKE OBJ-WKS "ACTIVATE"
           INVOKE OBJ-APP "SET-Visible"
                  USING W-TRUE
                  RETURNING RETURN-ERROR.
           MOVE 1 TO TO WINDEX
           INVOKE OBJ-WKSS "GET-ITEM"
                  USING WINDEX
                  RETURNING OBJ-WKS
           INVOKE OBJ-WKS "ACTIVATE"
           INVOKE OBJ-WKS "GET-RANGE"
                  RETURNING
                  OBJ-RANGE
           PERFORM VARYING N1 FROM 1 BY 1 UNTIL N1 = 9
               DISPLAY "M1=" M1
               INVOKE OBJ-WKS "GET-RANGE"
                      USING M1
                      RETURNING
                      OBJ-RANGE
               INVOKE OBJ-RANGE "GET-VALUE"
                      RETURNING W-VALUE1
               DISPLAY "M1=" M1 " VAL=" W-VALUE1 "="
           END-PERFORM
           
           INVOKE OBJ-WBK "Close".
           INVOKE OBJ-APP "Quit".

Back to COBOL General discussion FAQ Index
Back to COBOL General discussion Forum

My Archive

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