Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting data to Microsoft Project 2010

Former Member
0 Kudos

Hi everybody,

I have a question concerning the usage of OLE. I found tons of material about how to export data to word and excel with ole, but havent found a single resource that would explain how to export to Microsoft Project 2010.

So basically what I have to do is exporting an ALV table containing a lot of data into MS Project the same way we can do it with Word or Excel. Since I didnt find any other way, I directly called the ole methods of Office which you can find in Office by ALT + F11 -> Object Browser.

I even got the data into my MS Project quite nicely, but there is one small problem which is giving me headaches. When I export my data, it doesnt automatically open MS Project. It generates all the objects in the background, and if I had Office open before exporting, it would work perfectly.

So does anybody have an idea what I'm missing here to get MS Project to generate a new instance of itself and opening my newly exported document afterwards?


  METHOD ole.
    DATA: lr_app      TYPE ole2_object,
               lr_project  TYPE ole2_object.

    "MS Project
    CREATE OBJECT lr_app 'MSProject.Application'.
    CREATE OBJECT lr_project 'MSProject.Project'.

    "Pasting data
    LOOP AT gt_outtab INTO gs_outtab.

      "Task Name
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Outline Level'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Outline Level'
        #2 = gs_outtab-outline.


      "Name
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Name'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Name'
        #2 = gs_outtab-bez.


      "Duration
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Duration'
        #3 = 'false'.
      CALL METHOD OF lr_app 'SetTaskField'
        EXPORTING
        #1 = 'Duration'
        #2 = gs_outtab-bez.


      "Milestone or not?
      CALL METHOD OF lr_app 'SelectTaskField'
        EXPORTING
        #1 = index
        #2 = 'Milestone'
        #3 = 'false'.
    ENDLOOP.

    "Maximize application
    CALL METHOD OF lr_app 'AppMaximize'
      EXPORTING
      #1 = 'true'.

    "Free document
    FREE OBJECT lr_app.

    CALL FUNCTION 'FLUSH'
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2
        OTHERS            = 3.
    IF sy-subrc <> 0.
    ENDIF.
ENDMETHOD.

Edited by: Cédéric Grieder on Dec 7, 2011 3:02 PM

Edited by: Cédéric Grieder on Dec 7, 2011 3:03 PM

8 REPLIES 8

Former Member
0 Kudos

Thanks for the example Cederic,

I have the exact same request and I tried your code even with MS Project already opened and nothing happens, no data is transfered from SAP into MS Project 2010.

I used another OLE to interact with Excel in the past and it works fine but I don't know what I'm missing in order to make it work for MS Project.

I just noticed the table TOLE does not have any register for MS Project so I created one record (Using transaction SOLE) with the corresponding CLSID Lib type used by my computer registry but still nothing happens.

I only get to open MS Project using (SET PROPERTY OF lr_app 'VISIBLE' = 1) in debug mode, but that's all, no data get transfered and when it finished, just close the session for MS Project.

Please let me know if you did something else other than your code and also let me know if you have MSProject created in your TOLE table.

Thanks,

Juan

0 Kudos

Hi Juan,

I also found the way to create a new project and maintain the MSProject opened, but I didn't find the way yet to create tasks:

CREATE OBJECT   MSProject_app 'MSProject.Application'.
SET PROPERTY OF MSProject_app 'Visible'  = 1.
CALL METHOD OF  MSProject_app 'Projects' = MSProject_projects.
CALL METHOD OF MSProject_projects 'Add' = MSProject_project.
SET PROPERTY OF MSProject_project 'Activate' = 1.

****Until this point works

GET PROPERTY OF MSProject_project 'Tasks' = MSProject_tasks.
CALL METHOD OF MSProject_tasks 'Add' = MSProject_task.
SET PROPERTY OF MSProject_task 'Name' = 'Test'.

Did you find the way to add tasks?

Regards,

Rafael

0 Kudos

Hi! This code works:

method DO.

     DATA: lo_app TYPE ole2_object,

           lo_project TYPE ole2_object.

     DATA: l_index TYPE i VALUE 1.

     DATA: lo_projects TYPE ole2_object,

           lo_tasks TYPE ole2_object,

           lo_task TYPE ole2_object,

           lo_task2 TYPE ole2_object.

     CREATE OBJECT  lo_app 'MSProject.Application'.

     SET PROPERTY OF lo_app 'Visible' = 1.

     CALL METHOD OF lo_app 'Projects' = lo_projects.

     CALL METHOD OF lo_projects 'Add' = lo_project.

     GET PROPERTY OF lo_project 'Tasks' = lo_tasks.

     CALL METHOD OF lo_tasks 'Add' = lo_task.

     SET PROPERTY OF lo_task 'Name' = 'Test12323123'.

     SET PROPERTY OF lo_task 'Duration' = '5'.

     CALL METHOD OF lo_tasks 'Add' = lo_task2.

     SET PROPERTY OF lo_task2 'Name' = 'Test333333333'.

     SET PROPERTY OF lo_task2 'Duration' = '15'.

     DATA: l_id TYPE i.

     GET PROPERTY OF lo_task 'ID' = l_id.

     SET PROPERTY OF lo_task2 'Predecessors' = l_id.

endmethod.

0 Kudos

Hi Vladimir,

I test it and yes, it works.

Thanks a lot.

Rafael

0 Kudos

Thank you Vladimir,

I tested it, too and it works great.

But there is one problem for me. Maybe you have a solution?

I like to add an extra, custom named column which only holds some additional information.

The Application->TableEdit doesn't work for me.

Application->AddNewColum creates a new column but the user have to type the column-name by himself. The "SendKey"-method doesn't work for simulating some user-input.

Regards,

Arne

0 Kudos

Hi, Arne.
This code works from Project macros:

    Application.TableEditEx Name:="&Entry", Title:="AAA222", TaskTable:=True, NewName:="", NewFieldName:="Text1", Width:=20, ShowInMenu:=True, LockFirstColumn:=True, DateFormat:=255, RowHeight:=1, ColumnPosition:=2

    Application.TableApply Name:="&Entry"

0 Kudos

Hi Vladimir,

thanks for your reply.

Yes, I got nearly the same snippet by macro-recording in Project and it works fine in Project macros.

But it doesn't work in my report and I don't know why. I tested a lot of things like replacing abap_true with 1 or with 'true' as char, fill all parameters, only use the needed parameters... no success for me.

Here my code snippet. May you like to play with it and find some information of interests:

DATA: app TYPE ole2_object,

       projects TYPE ole2_object,

       project TYPE ole2_object.

CREATE OBJECT app 'MSProject.Application'.

SET PROPERTY OF app 'Visible' = 1.

CALL METHOD OF

     app

     'Projects' = projects.

CALL METHOD OF

     projects

     'Add'    = project.

CALL METHOD OF

     app

     'TableEdit'

   EXPORTING

     #1  = 'Entry'   " Name As String

*    #2  =           " TaskTable As Boolean

*    #3  =           " [Create]

*    #4  =           " [OverwriteExisting]

*    #5  =           " [NewName]

     #6  = 'Text8'   " [FieldName]

*    #7  =           " [NewFieldName]

     #8  = ''        " [Title]

     #9  = 9         " [Width]

     #10 = 2         " [Align]

*    #11 =           " [ShowInMenu]

     #12 = abap_true " [LockFirstColumn]

     #13 = 255       " [DateFormat]

     #14 = 1         " [RowHeight]

*    #15 =           " [ColumnPosition]

     #16 = 1.        " [AlignTitle]

*    #17 =           " [HeaderAutoRowHeightAdjustment]

*    #18 =           " [HeaderTextWrap]

CALL METHOD OF

     app

     'TableApply'

   EXPORTING

     #1           = 'Entry'.

0 Kudos

Hi, Arne!

DATA: lo_app TYPE ole2_object.

      CREATE OBJECT  lo_app 'MSProject.Application'.

      SET PROPERTY OF lo_app 'Visible' = 1.

        CALL METHOD OF lo_app 'TableEditEx'

         EXPORTING #1 = '&Entry'

             #2 = 1

             #3 = 0

             #4 = 0

             #5 = ''

             #6 = ''

             #7 = 'Text1'

             #8 = 'AAA2222'

             #9 = 20

             #11 = 1

             #12 = 1

             #13 = 255

             #14 = 1

             #15 = 2.

      CALL METHOD OF lo_app 'TableApply'

         EXPORTING #1 = '&Entry'.