SAP OLE to MS Word

I have used this coding for sap OLE to Ms word... but if i run this program... MS Word just opens but i am not able to view any of the statements... that is new documents are not openings and the statements  are not reflecting...
Any one give me a tips what to change in this following code...
Include for OLE-enabling definitions
INCLUDE ole2incl .
*Global variables *Variables to hold OLE object and entity handles
DATA:     gs_word       TYPE   ole2_object ,
*"OLE object handle
        gs_documents    TYPE   ole2_object ,
*"Documents
        gs_actdoc       TYPE   ole2_object  , "Active document
        gs_application  TYPE   ole2_object  , "Application
        gs_options      TYPE   ole2_object  , "Application options
        gs_actwin       TYPE   ole2_object  , "Active window
        gs_actpan       TYPE   ole2_object  , "Active pane
        gs_view         TYPE   ole2_object  , "View
        gs_selection    TYPE   ole2_object  , "Selection
        gs_font         TYPE   ole2_object  , "Font
        gs_parformat    TYPE   ole2_object  , "Paragraph format
        gs_tables       TYPE   ole2_object  , "Tables
        gs_range        TYPE   ole2_object  , "Range handle for various ranges
        gs_table        TYPE   ole2_object  , "One table
        gs_table_border TYPE   ole2_object  , "Table border
        gs_cell         TYPE   ole2_object  , "One cell of a table
        gs_paragraph    TYPE   ole2_object  , "Paragraph
        gv_pos(5)       TYPE   n . "Position information for table
START-OF-SELECTION .
*--Creating OLE object handle variable
  CREATE OBJECT gs_word 'WORD.APPLICATION' .
  IF sy-subrc NE 0 .
    MESSAGE s000(su) WITH 'Error while creating OLE object!'.
    LEAVE PROGRAM .
  ENDIF .
*--Setting object's visibility property
  SET PROPERTY OF gs_word 'Visible' = '1' .
*--Opening a new document
  GET PROPERTY OF gs_word 'Documents' = gs_documents .
**--Setting the measurement unit
  GET PROPERTY OF gs_application 'Options' = gs_options .
SET PROPERTY OF gs_options 'MeasurementUnit' = '1' . "CM
*Getting handle for the selection which is here the character at the *cursor position
  GET PROPERTY OF gs_application 'Selection' = gs_selection .
  GET PROPERTY OF gs_selection 'Font' = gs_font .
  GET PROPERTY OF gs_selection 'ParagraphFormat' = gs_parformat .
*--Setting font attributes
  SET PROPERTY OF gs_font 'Name' = 'Arial' .
  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = '0' . "Not bold
  SET PROPERTY OF gs_font 'Italic' = '1' . "Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Setting paragraph format attribute
  SET PROPERTY OF gs_parformat 'Alignment' = '2' . "Right-justified
  CALL METHOD OF gs_selection 'TypeText'
    EXPORTING #1 = 'This is an OLE example!'.
*--Setting the view to the main document again
  SET PROPERTY OF gs_view 'SeekView' = '0' . "Main document view
*--Reseting font attributes for the title
  SET PROPERTY OF gs_font 'Name' = 'Times New Roman' .
  SET PROPERTY OF gs_font 'Size' = '16' .
  SET PROPERTY OF gs_font 'Bold' = '1' . "Bold
  SET PROPERTY OF gs_font 'Italic' = '0' . "Not Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Setting paragraph format attribute
  SET PROPERTY OF gs_parformat 'Alignment' = '1' . "Centered
  CALL METHOD OF gs_selection 'TypeText'
    EXPORTING #1 = text-001.
*--Advancing cursor to the new line
  CALL METHOD OF gs_selection 'TypeParagraph' .
*--Reseting font attributes for ordinary text
  SET PROPERTY OF gs_font 'Name' = 'Times New Roman' .
  SET PROPERTY OF gs_font 'Size' = '12' .
  SET PROPERTY OF gs_font 'Bold' = '0' . "Not bold
  SET PROPERTY OF gs_font 'Italic' = '0' . "Not Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Setting paragraph format attribute
  SET PROPERTY OF gs_parformat 'Alignment' = '3' . "Justified
  CALL METHOD OF gs_selection 'TypeText'
    EXPORTING #1 = text-001.
*--skip some lines
  DO 4 TIMES .
    CALL METHOD OF gs_selection 'TypeParagraph' .
  ENDDO .
*--Getting entity handles for the entities on the way
  GET PROPERTY OF gs_actdoc 'Tables' = gs_tables .
  GET PROPERTY OF gs_selection 'Range' = gs_range .
*--Adding a table with 3 rows and 2 columns
  CALL METHOD OF gs_tables 'Add' = gs_table
  EXPORTING #1 = gs_range " Handle for range entity
            #2 = '3' "Number of rows
            #3 = '2'. "Number of columns
*--Setting border attribute for the table
  GET PROPERTY OF gs_table 'Borders' = gs_table_border .
  SET PROPERTY OF gs_table_border 'Enable' = '1' . "With border
*Filling the table with dummy data *Reseting font attributes for table content
  SET PROPERTY OF gs_font 'Name' = 'Garamond' .
  SET PROPERTY OF gs_font 'Size' = '11' .
  SET PROPERTY OF gs_font 'Bold' = '0' . "Not bold
  SET PROPERTY OF gs_font 'Italic' = '0' . "Not Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Getting cell coordinates
  CALL METHOD OF gs_table 'Cell' = gs_cell
  EXPORTING #1 = '1' "first row
            #2 = '1'. "first column
*--Getting the range handle to write the text
  GET PROPERTY OF gs_cell 'Range' = gs_range .
*--Filling the cell
  SET PROPERTY OF gs_range 'Text' = 'OLE' .
*--Getting cell coordinates
  CALL METHOD OF gs_table 'Cell' = gs_cell
  EXPORTING
        #1 = '3' "third row
        #2 = '2'. "second column
*--Reseting font attributes for ordinary text
  SET PROPERTY OF gs_font 'Name' = 'Times New Roman' .
  SET PROPERTY OF gs_font 'Size' = '12' .
  SET PROPERTY OF gs_font 'Bold' = '0' . "Not bold
  SET PROPERTY OF gs_font 'Italic' = '0' . "Not Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Setting paragraph format attribute
  SET PROPERTY OF gs_parformat 'Alignment' = '3' . "Justified *--Indent the paragraph once
  GET PROPERTY OF gs_selection 'Paragraphs' = gs_paragraph .
  CALL METHOD OF gs_paragraph 'Indent' .
  CALL METHOD OF gs_selection 'TypeText'
    EXPORTING
    #1 = text-001.
  FREE OBJECT gs_word .
Thanks @ Regards,
Hema

HI Hema,
To open new document add this line.
*--Opening a new document
get property of gs_word 'Documents' = gs_documents.
call method of gs_documents 'ADD' ."= gs_document.
Regards,
Sravanthi

Similar Messages

  • SAP OLE to Visio

    hi i worked on sap ole 2 to word and excel.. but i do not know how to proceed with visio.can anyone give me a sample code to work on visio

    It s too complicated i went through structural graphics and solved

  • SAP OLE to Word Usage of Text Boxes & Arrow Diagrams

    hi this my Macro recording in MS word How to use this as sap Code using SAP OLE
    ' Macro recorded 3/30/2009 by Nirmala
        ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 216#, _
            72#, 108#, 54#).Select
        Selection.ShapeRange.TextFrame.TextRange.Select
        Selection.Collapse
        Selection.TypeText Text:="Hma"
        Selection.ShapeRange.Select
        ActiveDocument.Shapes.AddLine(207#, 135#, 261#, 207#).Select
        Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
        Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
        Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
        Selection.ShapeRange.Flip msoFlipHorizontal
        ActiveDocument.Shapes.AddLine(261#, 135#, 306#, 198#).Select
        Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
        Selection.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
        Selection.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
        ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 153#, _
            216#, 90#, 54#).Select
        Selection.ShapeRange.TextFrame.TextRange.Select
        Selection.Collapse
        Selection.TypeText Text:="xys"
        Selection.ShapeRange.Select
        ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 297#, _
            207#, 81#, 63#).Select
        Selection.ShapeRange.TextFrame.TextRange.Select
        Selection.Collapse
        Selection.TypeText Text:="lop"

    hi
    Hthis is my sap program.. where to use this coding concept what are the data s to be declared
    *DATA declarations
    *--Include for OLE-enabling definitions
    INCLUDE ole2incl .
    *--Global variables *--Variables to hold OLE object and entity handles
    DATA:   word TYPE ole2_object , "OLE object handle
        documents TYPE ole2_object  , "Documents
      doc TYPE ole2_object  , "Documents
        actdoc TYPE ole2_object  , "Active document
        application TYPE ole2_object  , "Application D
        options TYPE ole2_object  , "Application options
        actwin TYPE ole2_object  , "Active window
        actpan TYPE ole2_object  , "Active pane
        view TYPE ole2_object  , "View
        selection TYPE ole2_object  , "Selection
        font TYPE ole2_object  , "Font
        parformat TYPE ole2_object  , "Paragraph format
        tables TYPE ole2_object  , "Tables
        range TYPE ole2_object  , "Range handle for various ranges
        table TYPE ole2_object  , "One table
        table_border TYPE ole2_object  , "Table border
        cell TYPE ole2_object  , "One cell of a table
        paragraph TYPE ole2_object  , "Paragraph
        shapes  TYPE ole2_object  ,
        logo TYPE ole2_object  ,
        textbox  TYPE ole2_object,
        find TYPE ole2_object,
    picture(128) ,
      gv_pos(5) TYPE n . "Position information for table
    START-OF-SELECTION .
      picture = 'D:\BMP\test.bmp'.
    *-Creating OLE object handle variable
      CREATE OBJECT   word 'WORD.APPLICATION' .
      IF sy-subrc NE 0 .
        MESSAGE s000(su) WITH 'Error while creating OLE object!'.
        LEAVE PROGRAM .
      ENDIF .
    *-Setting object's visibility property
      SET PROPERTY OF   word 'Visible' = '1' .
    * Adding documents
      CALL METHOD OF word 'DOCUMENTS' = documents.
    * Adding New page
      CALL METHOD OF documents 'Add' = doc.
    * Retrieving thre Property of Word for Alignment Changes
      GET PROPERTY OF   word      'Selection' =   selection.
      GET PROPERTY OF   selection 'Font' =   font .
      GET PROPERTY OF   selection 'ParagraphFormat' =   parformat.
    * Changes in Our Requirement
      SET PROPERTY OF   font 'Name' = 'Arial' .
      SET PROPERTY OF   font 'Size' = '20' .
      SET PROPERTY OF   font 'Bold' = '1' . "Not bold
      SET PROPERTY OF   font 'Italic' = '1' . "Italic
      SET PROPERTY OF   font 'Underline' = '1' . "Not underlined
    * Paragraph Format 1 - Center 2 - Right  3 - Left
      SET PROPERTY OF parformat 'Alignment' = '1'.
    * Text to be displayed
      CALL METHOD OF selection 'TypeText'
        EXPORTING
        #1 = 'Organisational Structure'.
    *--Getting active document handle
      GET PROPERTY OF word 'activedocument' = actdoc .
    *  To Save the document
      CALL METHOD OF doc 'SaveAs'
        EXPORTING
        #1 = 'D:\TEMP\WordFormatOLE.doc'.
    **  To Quit the Document
    CALL METHOD OF word 'Quit' .

  • INTERNAL ERROR IN SAP OLE DOCUMENT CONTAINER CONTROL. in transaction PBWW

    Well while running a transaction PBWW when we click on create button it opens the word document with the
    text in it but suddenly the text is gone and it is showing a error which is INTERNAL ERROR IN SAP OLE DOCUMENT CONTAINER CONTROL.
    how can it be resolved????
    Thanks And regards
    Amit

    Friend,
    See this line from OSS#427615:
    Note:
    This note is a continuation of the correction from Note 402195 (Stabilization of the Word interface). Thus, the correction from Note 402195 is an absolutely necessary prerequisite for this note.
    i'm about to sure that if you implement first 402195 than 427615 problem would be solved.
    Both OSS are made in continuation.

  • Internal error in SAP OLE document container control

    While opening WW-Invitation in so10 with standard text - WW-INVITATION where Text ID - Palt the doc is not opening and the following error as coming :
    Internal error in SAP OLE document container control
    Message no. SOFFICEINTEGRATION019
    Can any body suggest the solution on this.....
    We have SAP HR patch level 72 .
    I checked in the scn they are saying about some note but those note are not applicable in my system
    Thanks

    Same thing over here.
    ECC5.0, SAP GUI 7.1 Comp 3 (win).
    Whenever I try to open any Document (Transaction PBWW) I get the same error: Word 2007 opens and as soon as the document itself is loaded, it vanishes. All that is left, is the GUI showing the "Internal Error in SAP OLE Document Container Control" (SOFFICEINTEGRATION019).
    What's wrong with that. GUI 6.4 and 7.1 Comp. 2 did their job...
    Even GUI 7.1 Comp. 3 and Word 2003 do as they're supposed to and open the documents nicely.
    What I've found out is that the Word template R3_TP97_D.dot which is created in the temporary folder in Windows needs to be deleted before using PBWW. Once the file is gone, opening any document via PBWW succeeds. SAP Note 558548 does not resolve the issue.
    Regards, Oliver
    Edited by: Oliver Günther on Sep 15, 2009 1:34 PM
    Edited by: Oliver Günther on Sep 15, 2009 1:37 PM

  • SAP OLE

    Hi,
    While maintaining Standard text in MS-WORD it giving a error 'Internal error in SAP OLE Container Control'.
    According to my knowlegde its giving error because some file missed in msofficeintegration in OLE.
    But i am unable to sort out this problem.
    If any one have idea in this pls reply me.

    Hello,
    Try this for Landscape (all ole objects are of type OLE2_OBJECT)
    CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
    IF SY-SUBRC NE 0.
      WRITE: / 'No EXCEL creation possible'.
      STOP.
    ENDIF.
    SET PROPERTY OF EXCEL 'DisplayAlerts' = 0.
    CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK .
    SET PROPERTY OF EXCEL 'VISIBLE' = 1.
    * creating workbook
    SET PROPERTY OF EXCEL 'SheetsInNewWorkbook' = 1.
    CALL METHOD OF WORKBOOK 'ADD'.
    CALL METHOD OF EXCEL 'WORKSHEETS' = SHEET.
    CALL METHOD OF SHEET 'ADD'.
    FREE OBJECT SHEET.
    CALL METHOD OF EXCEL 'WORKSHEETS' = SHEET
      EXPORTING
        #1 = 1.
    GET PROPERTY OF sheet 'PageSetup' = h_pagesetup.
    set PROPERTY OF h_pagesetup 'Orientation' = 2.

  • Download SAP Script as MS word format

    Can we download SAP Script in MS word format? If so Please suggest me the way.

    I'm not very sure on how it can be achieved, but this can help you.
    Spool to word -> http://sap4.com/codigofuente/102/396.html

  • OLE automation with Word

    I had forms developped with forms 4.5
    I did things like that :
    -- open OLE object in Word
    Forms_OLE.Activate_Server(wordItem);
    application :=OLE2.CREATE_OBJ('Word.Basic');
    Forms_OLE.Exec_Verb(wordItem, 1);
    -- insert text in Word document
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args, text);
    OLE2.Invoke(application, 'Insert', args);
    OLE2.Destroy_Arglist(args);
    -- print document
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args, 0);
    OLE2.Invoke(application, 'FilePrint', args);
    OLE2.Destroy_Arglist(args);
    -- exit Word
    OLE2.Invoke(application, 'FileExit');
    -- release server
    if (Forms_OLE.Server_Active(item_id)) then
    Forms_OLE.Close_Server(item_id);
    end if;
    With Form 6.0, Invoke method seems not to work anymore.
    I suppose I have to use
    Init_OleArgs(2);
    Add_OleArg('insertText', VT_BSTR);
    Add_OleArg('my text', VT_BSTR);
    Call_Ole(itemName, ?);
    Is it that and what should be the 2nd parameter of Call_Ole method ?
    Thanks
    Nico
    null

    With Forte Release2 supporting only OLE callout, you can use DDE
    to pass data; but with Release 3 which supports OLE callin , you
    should be able to pass data both ways.
    - Arvind
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Arvind Kumar Krishnaswamy
    Digital/Forte Software Products Group
    Digital Equipment Corporation ______________________
    1800,Harrison Street,Suite 1700, | | | | | | | |
    Oakland.CA 94612 USA |d |i |g |i |t |a |l |
    | | | | | | | |
    Tel : 510-251-6537 ----------------------
    Fax : 510-251-6531
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • RE: Internal error in SAP OLE document container control

    Hi,
    When i execute the transaction for assigning standard document to an applicant activity, PBWW, i get an error message stating 'Internal error in SAP OLE document container control'.  Please help me out of this problem.
    We are using SAP version ECC 6
    Thanks and Regards,
    sowmya

    Hi,
    Sorry for replying so late.
    Follow these steps
    •     Create a report ZPAPUT04 in your system.
    •     Using ZPAPUT04, upload all the templates in TEMPLATES.zip one by one. Please make sure that only the option 'Upload' in the selection screen is chosen. You have to pass the other inputs as given below
    If you have extracted the templates in the 'C: \ folder of your system
    then
    For R3_TP97_E.dot template
    FILENAME = C:\R3_TP97_E.DOT
    DOTNAME = R3_TP97_E
    For TEMPLATE_E.DOT template
    FILENAME = C:\TEMPLATE_E.DOT
    DOTNAME = TEMPLATE_E
    Execute the upload program ZPAPUT04
    For R3_TP97A_E.dot template
    FILENAME = C:\R3_TP97A_E.DOT
    DOTNAME = R3_TP97A_E
    Execute the upload program ZPAPUT04
    <b>Report to be executed</b>
    REPORT  ZPAPUT04                                .
    types: begin of data_type,
            line(132) type x,
          end of data_type.
    DATA langu type thead-tdspras VALUE 'D'.                  
    DATA data_x type table of data_type.
    DATA wa_data_x type data_type.
    DATA text type table of tline.
    DATA wa_text type tline.
    DATA header type thead.
    DATA header_x type xstring.
    field-symbols: <data_x> type x,
                   <text> type x.
    DATA filename type string.
    parameters:  file_c(128) default 'C:\R3_TP97_D.DOT',
                 dotname type TDOBNAME default 'R3_TP97_D',
                 download as checkbox default 'X',
                 upload as checkbox default 'X'.
    DATA bytes_up type i.
    DATA bytes_down type i.
    DATA result1 type string.
    DATA result2 type string.
    data charsize type i.
    class CL_ABAP_CHAR_UTILITIES definition load.
    charsize = CL_ABAP_CHAR_UTILITIES=>charsize.
    filename = file_c.
    if upload = 'X'.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = filename
        FILETYPE                      = 'BIN'
      HAS_FIELD_SEPARATOR           = ' '
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      IMPORTING
        FILELENGTH                    = bytes_up
      HEADER                        =
      TABLES
        DATA_TAB                      = data_x
      EXCEPTIONS
        FILE_OPEN_ERROR               = 1
        FILE_READ_ERROR               = 2
        NO_BATCH                      = 3
        GUI_REFUSE_FILETRANSFER       = 4
        INVALID_TYPE                  = 5
        NO_AUTHORITY                  = 6
        UNKNOWN_ERROR                 = 7
        BAD_DATA_FORMAT               = 8
        HEADER_NOT_ALLOWED            = 9
        SEPARATOR_NOT_ALLOWED         = 10
        HEADER_TOO_LONG               = 11
        UNKNOWN_DP_ERROR              = 12
        ACCESS_DENIED                 = 13
        DP_OUT_OF_MEMORY              = 14
        DISK_FULL                     = 15
        DP_TIMEOUT                    = 16
        OTHERS                        = 17
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF bytes_up <= 0.
      result1 = 'UPLOAD ERROR ?:o('.
    ELSE.
      result1 = 'UPLOAD OK :o)'.
    ENDIF.
    LOOP AT data_x INTO wa_data_x.
      assign wa_data_x-line to <data_x> casting.
      assign wa_text-tdline to <text> casting.
      <text> = <data_x>.
      append wa_text TO text.
    ENDLOOP.
    CALL FUNCTION 'INIT_TEXT'
      EXPORTING
        ID             = 'TAPP'
        LANGUAGE       = langu                                 
        NAME           = dotname
        OBJECT         = 'APP-DOT'
      IMPORTING
        HEADER         = header
      TABLES
        LINES          = text
      EXCEPTIONS
        ID             = 1
        LANGUAGE       = 2
        NAME           = 3
        OBJECT         = 4
        OTHERS         = 5
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT data_x INTO wa_data_x.
      assign wa_data_x-line to <data_x> casting.
      assign wa_text-tdline to <text> casting.
      <text> = <data_x>.
      append wa_text TO text.
    ENDLOOP.
    CALL FUNCTION 'SAVE_TEXT'
      EXPORTING
        CLIENT                = '000'                          
        HEADER                = header
      INSERT                = ' '
      SAVEMODE_DIRECT       = ' '
      OWNER_SPECIFIED       = ' '
      LOCAL_CAT             = ' '
    IMPORTING
      FUNCTION              =
      NEWHEADER             =
      TABLES
        LINES                 = text
      EXCEPTIONS
        ID                    = 1
        LANGUAGE              = 2
        NAME                  = 3
        OBJECT                = 4
        OTHERS                = 5
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDIF.
    if download = 'X'.
    refresh data_x.
    refresh text.
    clear wa_data_x.
    clear wa_text.
    unassign <data_x>.
    unassign <text>.
    DOWNLOAD
    CALL FUNCTION 'READ_TEXT'
      EXPORTING
        CLIENT                        = '000'                  
        ID                            = 'TAPP'
        LANGUAGE                      = langu                  
        NAME                          = dotname
        OBJECT                        = 'APP-DOT'
      ARCHIVE_HANDLE                = 0
      LOCAL_CAT                     = ' '
    IMPORTING
      HEADER                        =
      TABLES
        LINES                         = text
      EXCEPTIONS
        ID                            = 1
        LANGUAGE                      = 2
        NAME                          = 3
        NOT_FOUND                     = 4
        OBJECT                        = 5
        REFERENCE_CHECK               = 6
        WRONG_ACCESS_TO_ARCHIVE       = 7
        OTHERS                        = 8
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT text INTO wa_text.
      assign wa_data_x-line to <data_x> casting.
      assign wa_text-tdline to <text> casting.
      <data_x> = <text>.
      append wa_data_x TO data_x.
    ENDLOOP.
    *DATA fn_length type i.
    *DATA offset type i.
    *fn_length = strlen( file_c ).
    *offset = fn_length - 4.
    *concatenate filename(offset) '_DOWN' filename+offset(4) INTO filename.
    IF upload <> 'X'.
      DATA dx_ln type i.
      describe table data_x lines dx_ln.
      bytes_up = dx_ln * sy-tleng.
    ENDIF.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        BIN_FILESIZE                  = bytes_up
        FILENAME                      = filename
        FILETYPE                      = 'BIN'
      APPEND                        = ' '
      WRITE_FIELD_SEPARATOR         = ' '
      HEADER                        = '00'
      TRUNC_TRAILING_BLANKS         = ' '
      WRITE_LF                      = 'X'
      COL_SELECT                    = ' '
      COL_SELECT_MASK               = ' '
      IMPORTING
        FILELENGTH                    = bytes_down
      TABLES
        DATA_TAB                      = data_x
      EXCEPTIONS
        FILE_WRITE_ERROR              = 1
        NO_BATCH                      = 2
        GUI_REFUSE_FILETRANSFER       = 3
        INVALID_TYPE                  = 4
        NO_AUTHORITY                  = 5
        UNKNOWN_ERROR                 = 6
        HEADER_NOT_ALLOWED            = 7
        SEPARATOR_NOT_ALLOWED         = 8
        FILESIZE_NOT_ALLOWED          = 9
        HEADER_TOO_LONG               = 10
        DP_ERROR_CREATE               = 11
        DP_ERROR_SEND                 = 12
        DP_ERROR_WRITE                = 13
        UNKNOWN_DP_ERROR              = 14
        ACCESS_DENIED                 = 15
        DP_OUT_OF_MEMORY              = 16
        DISK_FULL                     = 17
        DP_TIMEOUT                    = 18
        FILE_NOT_FOUND                = 19
        DATAPROVIDER_EXCEPTION        = 20
        CONTROL_FLUSH_ERROR           = 21
        OTHERS                        = 22
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF bytes_down <> bytes_up and upload = 'X'.
      result2 = 'DOWNLOAD ERROR ?:o('.
    ELSEIF bytes_down > 0.
      result2 = 'DOWNLOAD OK :o)'.
    ELSE.
      result2 = 'DOWNLOAD ERROR ?:o('.
    ENDIF.
    endif.
    write: result1, / result2, / 'Bytes per Character: ', charsize.
    Download the template attached to note 558548
    Regards,
    Sowmya

  • SAP OLE - Create Hyperling on a Word Document

    Hi,
    My next step of creating a word document using OLE is to define some hyperlinks on a document. I have ran a macro in word to 'see what it does' when manually creating a hyperlink. Below is the macro: -
        ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
            SubAddress:="_Program_Z_OPEN_HRS_UPD_WRF1", ScreenTip:="", TextToDisplay _
            :="This is the program"
    I have tried to implement this using ABAP with no success. Maybe because I still dont fully understand how to interprete these marcos as ABAP.
    Has anybody created a hyperlink on a word document before, if so, seeing the code would be a great help.
    Thanks
    Martin
    Edited by: Martin Shinks on Dec 21, 2011 9:52 AM

    Never mind, with a bit of jiggery pokery, I fixed it myself.

  • SAP Output as MS word doc.

    My requirement is to get the output as a MS word format ..
    without using any third party toool? Can we really achieve it or not ?
    What we propsed is a solution is to get the output to a PDF file then to use
    the PDF to word converter  which cost them some amount but they were not satisfied to that .
    they need the output directly from SAP .
    Can we do this in SAP or not ?

    >> NO experts are replying for this Question ....
    Hm... I don't think you will get very far with comments like this
    But anyway...
    I don't think there is a way to convert any output to MS Word format natively using only ABAP. It is possible using OLE but that requires MS Word to be installed on the workstation, plus due to OLE, this doesn't work in programs running in the background.
    The situation is similar to generating an Excel spreadsheet (and now I'm not talking about DAT and tab delimited format but real native Excel output). It is also not possible without involving OLE or some other third party tool as far as I'm aware.
    I'm sure there is a reason for this - probably related to licensing or something like that.
    It'd be certainly nice to have a way to create .DOC or .XLS files natively from ABAP... just nobody developed it yet

  • Ole - writing to word document

    Hi,
    I have created a new word document with a table of 1 row and 3 columns using the ole concept. The text in all the 3 columns should be of different font and size. Please let me know if this can be done ?
    Attached below is the code which i have used. But with this everything is getting printed with same font and size. Please let me know if there is anything wrong in it?
      get property of gs_word 'documents' = gs_documents.
      call method of gs_documents 'add'.
      get property of gs_word 'activedocument' = gs_actdoc.
      get property of gs_actdoc 'application' = gs_application.
      get property of gs_application 'options' = gs_options.
      set property of gs_options 'measurementunit' = '1'. "cm
      get property of gs_application 'selection' = gs_selection.
      get property of gs_selection 'font' = gs_font.
      get property of gs_selection 'paragraphformat' = gs_parformat.
      perform font_style using 'arial' '12' '1' '0' '0' '1'.
      call method of gs_selection 'typeparagraph'.
      perform create_table using '1' '3'.
      perform fill_cell using '1' '2' 'abc'.
      perform font_style using 'arial' '10' '0' '0' '0' '1'.
      perform fill_cell using '1' '3' 'di-03
      version 2.00'.
    form font_style  using    value(p_0383)
                              value(p_0384)
                              value(p_0385)
                              value(p_0386)
                              value(p_0387)
                              value(p_0388).
      set property of gs_font 'name' = p_0383.
      set property of gs_font 'size' = p_0384.
      set property of gs_font 'bold' = p_0385.
      set property of gs_font 'italic' = p_0386.
      set property of gs_font 'underline' = p_0387 .
      set property of gs_parformat 'alignment' = p_0388.
    endform.
    form create_table  using    value(p_0262)
                                value(p_0263).
      get property of gs_actdoc 'tables' = gs_tables.
      get property of gs_selection 'range' = gs_range.
      call method of gs_tables 'add' = gs_table
        exporting
          #1 = gs_range "handle for range entity
          #2 = p_0262 "number of rows
          #3 = p_0263. "number of columns
      get property of gs_table 'borders' = gs_table_border.
      set property of gs_table_border 'enable' = '1'. "with border
    endform.                    " create_table
    form fill_cell  using    value(p_0185)
                             value(p_0186)
                             value(p_0187).
      call method of gs_table 'cell' = gs_cell
        exporting
          #1 = p_0185
          #2 = p_0186.
      get property of gs_cell 'range' = gs_range.
      set property of gs_range 'text' = p_0187.
    endform.
    Thanks
    Aruna

    Hi Aruna,
    Check this link.
    An easy reference for ole automation.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c1d54348-0601-0010-3e98-bd2a2dcd9e6c
    This may help you.
    Thanks,
    Bhaskar

  • Can we download SAP Script to a word document  ?

    Is it possible to download the SAP Script to a local Word documnet . and then is it possible to upload the Wrd Doc back to SAP SCript with a new Script name ..?

    Hi
    Hope it will help you.
    <REMOVED BY MODERATOR>
    want to Insert SAP ICONS into from SAP into Word document (OLE) .
    (1) Copy program DD_ADD_PICTURE into your own version called ZDD_ADD_PICTURE. Make sure
    you select all the checkboxes (including GUI Status and screens).
    (2) Paste the modified code at the end of this reply into your ZZ_ADD_PICTURE program.
    (3) Run ZZ_ADD_PICTURE for a range of Icons (e.g. enter Icon name ICON_IN* on the selection screen)
    (4) When you get the result list, type in ok-code EXPO directly in the ok-code
    field (you could also add a button for this function in the GUI status).
    (5) Download all the displayed icons as .gif files into a Windows folder
    that you have created to hold the icon .gif files (e.g. C:SAPICONS)
    (6) Now you can work with the icon files as you would any .gif file. (e.g. In a Word doc, use menu path
    Insert -> Picture -> From file.)
    Here is the code:
    REPORT dd_add_picture.
    TYPE-POOLS: sdydo.
    DATA: do TYPE REF TO cl_dd_document.
    DATA: is_displayed.
    TABLES: icont.
    DATA: BEGIN OF icontab OCCURS 0.
            INCLUDE STRUCTURE icon.
    DATA: END OF icontab.
    select-options: s_icon for icontab-name obligatory.
    SELECT * FROM icon INTO TABLE icontab WHERE locked NE 'X'
                        AND name in s_icon.
    Event Handler Definition, handling changes of GUI fonts, colors,...
    CLASS cl_my_event_handler DEFINITION.
      PUBLIC SECTION.
        METHODS:
          use_new_resources FOR EVENT resources_changed OF cl_gui_resources.
    ENDCLASS.
    DATA: my_handler TYPE REF TO cl_my_event_handler.
    CREATE OBJECT my_handler.
    Call Screen
    CALL SCREEN 100.
    *&      Module  STATUS_0100  OUTPUT
    MODULE status_0100 OUTPUT.
      IF is_displayed IS INITIAL.
        SET PF-STATUS 'BRP'.
        SET HANDLER my_handler->use_new_resources.
    create document
        CREATE OBJECT do.
    fill document
        PERFORM dd_add_icon USING do.
    merge document
        CALL METHOD do->merge_document.
    display document .
        CALL METHOD do->display_document
                           EXPORTING  container          = 'HTML'
                           EXCEPTIONS html_display_error = 1.
                                           " do some exception handling ...
        is_displayed = 'X'.
      ENDIF.
    ENDMODULE.                             " STATUS_0100  OUTPUT
    MODULE user_command_0100 INPUT.
      CASE sy-ucomm.
        WHEN 'BACK'.                       "Beenden
          LEAVE PROGRAM.
        WHEN 'PRN'.
          CALL METHOD do->print_document
                  EXPORTING reuse_control = 'X'.
        WHEN 'PRN_NEW'.
          DATA text TYPE sdydo_text_element.
          CALL METHOD do->initialize_document.
          text = 'Dies Dokument wurde speziell fürs Drucken erstellt!' &
                            ' Druckdatum: '(500).
          CALL METHOD do->add_text EXPORTING
                               text         = text
                               sap_fontsize = cl_dd_area=>large.
          WRITE sy-datum TO text DD/MM/YYYY.
          CALL METHOD do->add_text EXPORTING text = text .
          CALL METHOD do->new_line EXPORTING repeat = 2.
          PERFORM dd_add_icon USING do.
          CALL METHOD do->merge_document.
          CALL METHOD do->print_document.
        WHEN 'EXPO'.
          CALL METHOD do->export_document EXPORTING to_filesystem = 'X'.
      ENDCASE.
      CLEAR sy-ucomm.
    ENDMODULE.                             " USER_COMMAND_0100  INPUT
    *&      Form  DD_ADD_ICON
          text
    FORM dd_add_icon USING p_do TYPE REF TO cl_dd_document.
      DATA ta TYPE REF TO cl_dd_table_element.
      DATA col1 TYPE REF TO cl_dd_area.
      DATA col2 TYPE REF TO cl_dd_area.
      DATA col3 TYPE REF TO cl_dd_area.
      DATA text TYPE sdydo_text_element.
    set Heading
      text = ' Bilder in Dynamischen Dokumenten'(001).
      CALL METHOD p_do->add_text EXPORTING text = text
                                      sap_style = 'heading'.
      CALL METHOD p_do->new_line.
      CALL METHOD p_do->new_line.
      CALL METHOD p_do->add_table EXPORTING with_heading    = 'X'
                                          no_of_columns     = 3
                                          width             = '100%'
                                          IMPORTING table   = ta.
    set columns
      text = 'Ikone'(011).
      CALL METHOD ta->add_column EXPORTING heading  = text
                                 IMPORTING column   = col1.
    fill table
      LOOP AT icontab.
        SELECT SINGLE * FROM icont WHERE langu = sy-langu
                                   AND   id    = icontab-id.
        CALL METHOD col1->add_icon EXPORTING sap_icon = icontab-name
                                             sap_color = 'LIST_GROUP'.
      ENDLOOP.
    ENDFORM.                               " DD_ADD_ICON
    CLASS cl_my_event_handler IMPLEMENTATION.
    CLASS cl_my_event_handler IMPLEMENTATION.
      METHOD use_new_resources.
        IF is_displayed EQ 'X'.
    initialize document
          CALL METHOD do->initialize_document.
    fill document
          PERFORM dd_add_icon USING do.
    merge document
          CALL METHOD do->merge_document.
    display document
          CALL METHOD do->display_document
                              EXPORTING reuse_control        = 'X'
                                        reuse_registration   = 'X'.
        ENDIF.
      ENDMETHOD.
    ENDCLASS.
    Edited by: Alvaro Tejada Galindo on Feb 18, 2008 6:22 PM

  • Webforms ole with ms word

    hi there,
    having problems with webforms code that in 6i client server would launch ms word (no problem there) and show a templates dialog box.
    errors thrown from webforms are:
    WUO-714: Unable to get the last OLE Error details;
    Exception
    null
    WUO-705: Unable to invoke Method: Show; Exception
    com.jacob.com.ComFailException:
    VariantChangeType failed
    the code is as follows (no idea what argument '79' represents):
    Procedure Open_Word_Dialog IS
    app client_OLE2.OBJ_TYPE;
         dialogs client_OLE2.OBJ_TYPE;
         dialog client_OLE2.OBJ_TYPE;
         doc client_OLE2.OBJ_TYPE;
    arglist      client_OLE2.LIST_TYPE;
         l_type_num client_OLE2.OBJ_TYPE;
    Begin
    app := client_OLE2.CREATE_OBJ('WORD.Application');
    CLIENT_OLE2.SET_PROPERTY(app,'Visible',1);
    client_OLE2.INVOKE(app,'Activate');
    dialogs := client_ole2.get_obj_property(app, 'Dialogs');
    arglist:= client_OLE2.CREATE_ARGLIST;
    client_OLE2.ADD_ARG(arglist, 79);
    dialog := client_ole2.invoke_obj(dialogs, 'Item', arglist);
    client_OLE2.DESTROY_ARGLIST(arglist);
    l_type_num := client_ole2.Invoke_obj(dialog, 'Show');
    doc := client_ole2.get_obj_property(app, 'ActiveDocument');
    client_ole2.Release_OBJ(doc);
    client_ole2.Release_OBJ(dialog);
    client_ole2.Release_OBJ(dialogs);
         client_ole2.Release_OBJ(app);     
    Exception
         When others then
    null;
    End;
    end;
    any assistance would be most appreciated.
    thanks in advance.

    I've finally had a chance to run your code. Oddly enough, it runs fine for me (most likely a JACOB versioning quirk.) Upon closer inspection, I find that the Show method of a Dialog object returns a Long, not an object, suggesting that the problem is an incompatible return value type. Try declaring I_type_num_client as type NUMBER, rather than CLIENT_OLE2.OBJ_TYPE -- I'm guessing that should fix your error.
    If you're wondering where Word's objects, methods, arguments and argument types are documented, I use VBA's Object Browser for this, and simply couldn't manage without it. Have a look at the section entitled A BRIEF INTRODUCTION TO THE VBA IDE & THE OBJECT BROWSER UTILITY, which appears at the beginning of the following article:
       [b]Tutorial:[/b] Simplify Developing OLE Automation Code Using VBA
    The rest of the article shows how I prefer to write custom OLE procedures -- by first writing them as VBA procedures and testing them in the VBA environment, before adapting them to PL/SQL. Because the VBA IDE provides syntax checking, code completion and meaningful error messages, writing automation code goes much more smoothly on this end, and errors are usually detected at design time. So much more smoothly, in fact, that I can implement a procedure twice -- once in VBA, and once in PL/SQL -- more quickly than I can implement it once in PL/SQL, skipping the VBA prototype. Also, most of my VBA prototypes run to completion more quickly than launching a trivial web form, so a significant time savings can realized by experimenting and refining on the VBA end, rather than spending all of my time effectively waiting for my web form to load.
    Hope this helps,
    Eric Adamson
    Lansing, Michigan

  • OLE Automation for Word. EditGoto with Word 97

    I found a solution. Instead EditGoto, use WW7_EditGoto.
    Example:
    .- A Word Template whith two bookmarks
    (Texto1, Tabla1). A normal bookmark
    (Texto1) and a bookmark into a Word
    Table (Tabla1).
    In the Word Table, is posible change
    cell o create a new row with the same
    command (NextCell).
    The word table has two columns an two
    rows.
    The first row is the Header.
    The second row the first column contain
    a bookmark (Tabla1).
    .- A Form whit two blocks:
    First block with two items:
    nombre_doc
    texto1
    Secod Block (multirecord) whit two items
    col1
    col2
    with a When-Button-Pressed:
    DECLARE
    application OLE2.OBJ_TYPE;
    args OLE2.LIST_TYPE;
    BEGIN
    -- Start WordBasic and make Word visible
    application:=OLE2.CREATE_OBJ('Word.Basic');
    OLE2.INVOKE(application, 'AppShow');
    -- Open a Word document
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,'Plantilla.dot');
    OLE2.INVOKE(application, 'FileOpen', args);
    OLE2.DESTROY_ARGLIST(args);
    -- Put Text in the first bookmark
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,'Texto1');
    OLE2.INVOKE(application, 'WW7_EditGoto', args);
    OLE2.DESTROY_ARGLIST(args);
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,:Texto1);
    OLE2.INVOKE(application, 'Insert', args);
    OLE2.DESTROY_ARGLIST(args);
    -- Send data from Multirecord Block to Word Table
    GO_BLOCK('MULTI');
    FIRST_RECORD;
    IF :SYSTEM.RECORD_STATUS != 'NEW' THEN
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,'Tabla1');
    OLE2.INVOKE(application, 'WW7_EditGoto', args);
    OLE2.DESTROY_ARGLIST(args);
    LOOP
    IF :col1 IS NOT NULL THEN
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,:col1);
    OLE2.INVOKE(application, 'Insert', args);
    OLE2.DESTROY_ARGLIST(args);
    END IF;
    OLE2.INVOKE(application, 'NextCell');
    IF :col2 IS NOT NULL THEN
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,:col2);
    OLE2.INVOKE(application, 'Insert', args);
    OLE2.DESTROY_ARGLIST(args);
    END IF;
    EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
    NEXT_RECORD;
    OLE2.INVOKE(application, 'NextCell');
    END LOOP;
    -- Save a Word document
    args := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args,:nombre_doc);
    OLE2.INVOKE(application, 'FileSaveas', args);
    OLE2.DESTROY_ARGLIST(args);
    --Release the OLE object
    OLE2.RELEASE_OBJ(application);
    END;
    Sorry by the sintax, but i don't speak English.
    I hope it solves this problem.

    Hello,
    I am also trying to use the OLE2 package for OLE Automation. But
    difference being that I am not using Word but am using an
    invisible control for Mail services, using the objects
    MAPISession, MAPImessages. If anyone out there had already done
    this do please give me a code snippet.
    Thanx in advance
    Anup Mistry,
    Programmer/Analyst,
    IIS,Inc
    Vasile (guest) wrote:
    : Hi Daniel,
    : I used OLE with forms 5 ,but now it work without problems in
    : forms 6, too.
    : A procedure that save doc. look like that:
    : procedure filesaveas (fname in varchar2) is
    : arglist ole2.list_type;
    : begin
    : arglist := ole2.create_arglist;
    : ole2.add_arg (arglist, fname);
    : ole2.invoke (obj_hnd, 'filesaveas', arglist);
    : ole2.destroy_arglist (arglist);
    : end;
    : I hope this help you.
    : Vasile
    : Daniel Fox (guest) wrote:
    : : I am using Forms 6.0
    : : Can anyone help with OLE automation using OLE2.
    : : I can open Word, document stored in long raw, even insert
    data
    : : from other form field into the Word Document (only at the
    : : beginning of the Document, though).
    : : All the File commands, such as FileSaveAs, EditGoTo, etc..
    : don't
    : : work. They are simply ignored - no error messages, nothing.
    : : Does anyone use Word Automation through Forms 6.0?
    : : Please, HELP....
    : : Thanks in advance,
    : : Desperate Daniel.
    null

Maybe you are looking for

  • Problem with installing the drivers from cd-rom CTREG

    I have the following problems. st.. this one is the most urgent.. the problem is I can't seem to install from a drivers cd.. the error I get is like CTREGSVR.. it says it cannot find differnt applications on dri've c... there is like a whole bunch an

  • New version of Firefox no longer playes videos on my website

    Have no problem playing them on IE, Safari and Chrome. Used to play on prior versions of Firefox. Link to site is http://www.somaxsports.com/video.php Hope someone can help. Lots of people use Firefox to view our site.

  • Get file not found error when I try to sync

    I get file not found error when I try to sync Iphone.

  • Oracle and MS sql

    hi Is it possible to create a trigger in oracle so that when a row is inserted in a table it execute a stored procedure in MS sql server? Thanks

  • Not case sensitive input of username?

    I have a login section that has a username and password input field. I am not sure if I am doing this right, but since there is only one username and one password, this is how I did this. function checkPassword(userN:String, passW:String):Void { if(u