4 Replies Latest reply: Jun 22, 2010 2:38 PM by Oliver Schultze RSS

OLE: Why placeholders of MS Word document are not replaced?

Oliver Schultze
Currently Being Moderated

Hi Experts, I am using OLE to create Word Documents within a LOOP. The problem I have is that the Word Documents are created and seved well but the placeholders (&nom_prov') and (&ncod_prov') are not replaces by the values (in the example: test1 and test2).

 

Anybody can help me in with that issue?

 

LOOP AT lt_partner1 INTO ls_partner1.
 
  AT FIRST.
    CREATE OBJECT zword 'WORD.BASIC'.
    CALL METHOD OF zword 'FILEOPEN' EXPORTING #1 = 'C:\DOCS\PRUEBA_1.DOC'.
  ENDAT.
 
  CALL METHOD OF zword 'EDITSELECTALL'.
  CALL METHOD OF zword 'EDITCOPY'.
  CALL METHOD OF zword 'FILENEW'.
  CALL METHOD OF zword 'EDITPASTE'.
  CALL METHOD OF zword 'STARTOFDOCUMENT'.
  
 CALL METHOD OF zword 'WW2_EDITREPLACE' EXPORTING #1 = '&cod_prov'
    #2 = 'test 1'. "ls_partner1-nif.
  CALL METHOD OF zword 'WW2_EDITREPLACE' EXPORTING #1 = '&nom_prov'
    #2 = 'test 2'. "ls_partner1-name_org1.
 
  CALL METHOD OF zword 'STARTOFDOCUMENT'.
  CALL METHOD OF zword 'EDITSELECTALL'.
  CALL METHOD OF zword 'EDITCLEAR'.
  CALL METHOD OF zword 'EDITPASTE'.
  lv_contador = lv_contador + 1.
  CONCATENATE 'C:\DOCS\' 'PRUEBA' lv_contador '_' sy-datum '.DOC' INTO  lv_file_save_as.
  CALL METHOD OF zword 'FILESAVEAS' EXPORTING #1 = lv_file_save_as.
  CALL METHOD OF zword 'DOCCLOSE' EXPORTING #1 = 2.
  
 AT LAST.
   CALL METHOD OF zword 'APPCLOSE'.
   FREE OBJECT zword.
 ENDAT.
 
ENDLOOP.

 

  • Re: OLE: Why placeholders of MS Word document are not replaced?
    Otto Gold
    Currently Being Moderated

    Where did you find this approach? I have never seen this before. Otto

    • Re: OLE: Why placeholders of MS Word document are not replaced?
      Oliver Schultze
      Currently Being Moderated

      Hello Otto,

       

      this concept has the name OLE which is desribed in this document:

       

      http://help.sap.com/printdocu/core/print46c/en/data/pdf/bcfesde6/bcfesde6.pdf

       

      The ABAP programming language supports the OLE2 Automation technique. Desktop

      applications supporting OLE2 can be thus be called from R/3. By this way you can create Excel or for example Word Documents. In my case I create Word Documents and than attach them to a Business Document in SAP CRM (Activity).

       

      The only problem I have is that the placeholdes does not get replaces by the values of the internal table while I am doing the loop.

       

      Best Regards

      • Re: OLE: Why placeholders of MS Word document are not replaced?
        Oliver Schultze
        Currently Being Moderated

        Hello, I have found out what was the problem. In the end I have used method EDITREPLACE and not WW2_EDITREPLACE and I put the method EDITREPLACE more to the end of my ABAP Code:

         

        REPORT  z_prueba_oliver.
         
        TYPES: BEGIN OF ty_partner,
                     nif            TYPE bu_partner,
                     name_org1      TYPE bu_nameor1,
                     conting_com    TYPE c LENGTH 2,
                     fecha_efecto   TYPE zbufecha_ef,
                     END OF ty_partner.
         
        DATA:  lt_partner1     TYPE TABLE OF ty_partner,
                     ls_partner1     TYPE ty_partner,
                     lv_file_save_as TYPE c LENGTH 40,
                     lv_contador     TYPE n LENGTH 3.
         
        ************************************************************************
        * Include necesario para la declaracion de objetos OLE2
        ************************************************************************
        INCLUDE ole2incl.
        ***********************************************************************
        * Declaraciones para la llamada a WORD.
        DATA zword TYPE ole2_object.
        CLEAR zword.
         
        ls_partner1-nif = 'X7510034M'.
        ls_partner1-name_org1 = 'Razon Social 1'.
        APPEND ls_partner1 TO lt_partner1.
         
        ls_partner1-nif = 'X7510034M'.
        ls_partner1-name_org1 = 'Razon Social 2'.
        APPEND ls_partner1 TO lt_partner1.
         
        ls_partner1-nif = 'X7510034M'.
        ls_partner1-name_org1 = 'Razon Social 3'.
        APPEND ls_partner1 TO lt_partner1.
         
        ls_partner1-nif = 'X7510035M'.
        ls_partner1-name_org1 = 'Razon Social 4'.
        APPEND ls_partner1 TO lt_partner1.
         
        ls_partner1-nif = 'X7510035M'.
        ls_partner1-name_org1 = 'Razon Social 5'.
        APPEND ls_partner1 TO lt_partner1.
         
        LOOP AT lt_partner1 INTO ls_partner1.
         
          AT FIRST.
            CREATE OBJECT zword 'WORD.BASIC'.
        * Se abre el fichero que contiene la plantilla de la carta
            CALL METHOD OF zword 'FILEOPEN'
              EXPORTING
              #1 = 'C:DOCSPRUEBA_1.DOC'.
          ENDAT.
         
        * Se selecciona todo el texto del archivo PRUEBA_1.DOC
          CALL METHOD OF zword 'EDITSELECTALL'.
        * Se copia el texto seleccionado al portapapeles
          CALL METHOD OF zword 'EDITCOPY'.
        * Se crea un documento nuevo, al que WORD llama documento1
          CALL METHOD OF zword 'FILENEW'.
        * Se pega el texto del portapapeles a documento1
          CALL METHOD OF zword 'EDITPASTE'.
        * Posicionar al principio del documento
          CALL METHOD OF zword 'STARTOFDOCUMENT'.
        * Posicionar al principio del documento
          CALL METHOD OF zword 'STARTOFDOCUMENT'.
        * Se selecciona todo
          CALL METHOD OF zword 'EDITSELECTALL'.
        * Se borra la selección
          CALL METHOD OF zword 'EDITCLEAR'.
        * Se incorpora el texto original de PRUEBA_1.DOC
          CALL METHOD OF zword 'EDITPASTE'.
         
        *IF ls_partner1-conting_com is initial.*
           *CALL METHOD OF zword 'EDITREPLACE'*
            *EXPORTING*
            *#01 = '#linea2y3#'*
            *#02 = 'texttexttexttext'*
            *#03 = 0*
            *#04 = 0*
            *#05 = 0*
            *#06 = 0*
            *#07 = 0*
            *#08 = 0*
            *#09 = 0*
            *#10 = 1*
            *#11 = 0*
            *#12 = 1.*
        *else.*
             *CALL METHOD OF zword 'EDITREPLACE'*
            *EXPORTING*
            *#01 = '#linea2y3#'*
            *#02 = 'texttexttexttext'*
            *#03 = 0*
            *#04 = 0*
            *#05 = 0*
            *#06 = 0*
            *#07 = 0*
            *#08 = 0*
            *#09 = 0*
            *#10 = 1*
            *#11 = 0*
            *#12 = 1.*
        *ENDIF.*
         
          *CALL METHOD OF zword 'EDITREPLACE'*
            *EXPORTING*
            *#01 = '#codprov#'*
            *#02 = ls_partner1-nif*
            *#03 = 0*
            *#04 = 0*
            *#05 = 0*
            *#06 = 0*
            *#07 = 0*
            *#08 = 0*
            *#09 = 0*
            *#10 = 1*
            *#11 = 0*
            *#12 = 1.*
         
          CALL METHOD OF zword 'EDITREPLACE'
            EXPORTING
            #01 = '#nomprov#'
            #02 = ls_partner1-name_org1
            #03 = 0
            #04 = 0
            #05 = 0
            #06 = 0
            #07 = 0
            #08 = 0
            #09 = 0
            #10 = 1
            #11 = 0
            #12 = 1.
         
        * Se reemplaza el campo #nomprov# con el valor de la tabla interna.
          CALL METHOD OF zword 'EDITREPLACE'
            EXPORTING
            #01 = '#FECHA_EFECTO#'
            #02 = '10 de Junio de 2010'
            #03 = 0
            #04 = 0
            #05 = 0
            #06 = 0
            #07 = 0
            #08 = 0
            #09 = 0
            #10 = 1
            #11 = 0
            #12 = 1.
         
          lv_contador = lv_contador + 1.
          CONCATENATE 'C:DOCS' 'PRUEBA' lv_contador '_' sy-datum '.DOC' INTO lv_file_save_as.
        * Se cierra el documento activo, documento1 con opción de salir sin salvar
          CALL METHOD OF zword 'FILESAVEAS' EXPORTING #1 = lv_file_save_as.
        * Se cierra el documento activo PRUEBA.DOC con opción salir sin salvar
          CALL METHOD OF zword 'DOCCLOSE' EXPORTING #1 = 2.
         
          AT LAST.
        *   Se cierra WORD
            CALL METHOD OF zword 'APPCLOSE'.
        *   Se libera el objeto ZWORD
            FREE OBJECT zword.
          ENDAT.
         
        ENDLOOP.

         

         

Actions