Daten von SAP nach Word schieben (ohne Serienbrieffunktion) Thema ist als GELÖST markiert

Alle Fragen rund um Basisthemen
4 Beiträge • Seite 1 von 1
4 Beiträge Seite 1 von 1

Daten von SAP nach Word schieben (ohne Serienbrieffunktion)

Beitrag von Gast ( / / 0 / 3 ) »
Hi,

für den Schriftverkehr sollen Daten von SAP nach Word geschoben werden.
Bisher ging das mit der Serienbrieffunktion recht gut. Doch bei knapp 200 Variablen verliert man beim Auswählen der Seriendruckfelder leicht die Übersicht.
Ich wollte das jetzt über die OLE Schnittstelle machen (oder ADO?).
Was habt ihr für Erfahrungen?
Auf SAPScript/SmartForms möchte ich verzichten, da die Dokumente im Nachhinein noch bearbeitet werden müssen.

Danke im vorraus

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Beitrag von Gast ( / / 0 / 3 ) »
Dies habe ich mal irgendwo gefunden...

Code: Alles auswählen.

REPORT zz_bestellung_word .

TABLES: ekpo, eket, ekko, ekan, lfa1.


INCLUDE ole2incl.
INCLUDE docsincl.


DATA:
  itab  LIKE ekpo OCCURS 0 WITH HEADER LINE,
  itaba LIKE eket OCCURS 0 WITH HEADER LINE,
  itabb LIKE ekko OCCURS 0 WITH HEADER LINE,
  itabc LIKE lfa1 OCCURS 0 WITH HEADER LINE,
  h_word TYPE ole2_object.



DATA:
  value(20) TYPE c,
  quantity(15) TYPE c,
  netvalue(20) TYPE c,
  sum(20) TYPE c,
  temp(16) TYPE p DECIMALS 2, " like itab-netpr,
  temp2(16) TYPE p DECIMALS 2. " like itab-netpr.


PARAMETERS:
  getorder LIKE ekpo-ebeln DEFAULT '**********',
  contpers(80) TYPE c DEFAULT 'First second name',
  telnr(15) TYPE c DEFAULT 'Telephonenumber'.




IF getorder NE ''.

  PERFORM write_order.

ENDIF.



*---------------------------------------------------------------------*
* FORM WRITE_ORDER
*---------------------------------------------------------------------*
FORM write_order.

  IF h_word-header = space OR h_word-handle EQ -1.

    CREATE OBJECT h_word 'Word.Basic'.
    CALL METHOD OF h_word 'FileNew' EXPORTING #1 = 'normal.dot'.
    CALL METHOD OF h_word 'AppShow'.
    CALL METHOD OF h_word 'ViewHeader'.
    CALL METHOD OF h_word 'TableGridLines'
         EXPORTING #1 = '0'.
    CALL METHOD OF h_word 'TableInsertTable'
         EXPORTING #1 = ' '
                   #2 = '2'
                   #3 = '1'
                   #4 = 'Auto'.

* call method of h_word 'InsertPicture'
* exporting #1 = 'c:\data\logo.bmp'.


    PERFORM write_text
      USING 'ERICSSON L'    "text
            'Ericsson'      "font
            '24'            "size
            'Bold'.         "look

    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '9,0 cm'.

    CALL METHOD OF h_word 'NextCell'.

    CALL METHOD OF h_word 'CloseViewHeaderFooter'.


    CALL METHOD OF h_word 'TableInsertTable'
         EXPORTING #1 = ' '
                   #2 = '2'
                   #3 = '1'
                   #4 = 'Auto'.

    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '9,0 cm'.

    PERFORM write_text
      USING 'Ericsson Data AB'
            'TimesNewRoman '
            '12'
            ''.

    CALL METHOD OF h_word 'NextCell'.

    DATA: order(21) TYPE c.
    DATA: contact(80) TYPE c.
    DATA: tsize TYPE i VALUE 0.

    order = getorder.
    order+10(3) = ' / '.
    order+13(8) = sy-datum.
    contact = contpers.
    tsize = strlen( contact ).
    contact+tsize(3) = ' / '.
    tsize = strlen( contact ).
    contact+tsize(15) = telnr.

    PERFORM write_text
      USING 'Purchase order' 'TimesNewRoman' '10' 'Italic'.

    CALL METHOD OF h_word 'NextCell'.
    PERFORM write_text USING 'BigCity' 'TimesNewRoman ' '12'  ''.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NormalStyle'.

    PERFORM write_text
      USING 'PO number/date' 'TimesNewRoman' '14' 'Bold'.

    CALL METHOD OF h_word 'NextCell'.

    PERFORM write_text
      USING 'STOCKHOLM SWEDEN' 'TimesNewRoman ' '12' ''.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NormalStyle'.

    PERFORM write_text USING order 'TimesNewRoman' '10' 'Italic'.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NormalStyle'.

    PERFORM write_text
      USING 'Contact person/Telephone' 'TimesNewRoman' '14' 'Bold'.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NormalStyle'.

    PERFORM write_text USING contact 'TimesNewRoman' '10' 'Italic'.

    CALL METHOD OF h_word 'EndOfDocument'.
    CALL METHOD OF h_word 'EndOfLine'.
    CALL METHOD OF h_word 'InsertPara'.

    SELECT * FROM ekpo WHERE ebeln EQ getorder.
      itab = ekpo.
      APPEND itab.
    ENDSELECT.

    SELECT * FROM ekko WHERE ebeln = getorder.
      itabb = ekko.
      APPEND itabb.
    ENDSELECT.

    SELECT * FROM lfa1 WHERE lifnr = itabb-lifnr.
      itabc = lfa1.
    ENDSELECT.


    DATA: ind TYPE i VALUE 0.
    LOOP AT itab.
      IF ind = 0.
        CALL METHOD OF h_word 'TableInsertTable'
             EXPORTING #1 = ' '
                       #2 = '2'
                       #3 = '8'
                       #4 = 'Auto'.

        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '9,0 cm'.

        PERFORM write_text
          USING 'Your vendor number with us:'
                'TimesNewRoman' '14' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NextCell'.

        PERFORM write_text USING itabb-lifnr 'TimesNewRoman' '10' ''.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NormalStyle'.

        PERFORM write_text
          USING 'Payt. terms:' 'TimesNewRoman' '10' ''.

        CALL METHOD OF h_word 'NextCell'.

        PERFORM write_text
          USING itabc-name1 'TimesNewRoman' '10' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NormalStyle'.

        PERFORM write_text
          USING 'Within 14 days 3% cash discount'
                'TimesNewRoman' '10' ''.

        CALL METHOD OF h_word 'NextCell'.

        PERFORM write_text
          USING itabc-stras 'TimesNewRoman' '10' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NormalStyle'.

        PERFORM write_text
          USING 'Within 20 days 2% cash discount'
                'TimesNewRoman' '10' ''.

        CALL METHOD OF h_word 'NextCell'.

        PERFORM write_text
          USING itabc-ort01 'TimesNewRoman' '10' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NormalStyle'.

        PERFORM write_text
          USING 'Within 30 days Due net'
                'TimesNewRoman' '10' ''.

        CALL METHOD OF h_word 'EndOfDocument'.
        CALL METHOD OF h_word 'EndOfLine'.
        CALL METHOD OF h_word 'InsertPara'.


* call method of h_word 'InsertLine'.

**********************************************************************

* call method of h_word 'InsertPara'.
* call method of h_word 'InsertPara'.

        CALL METHOD OF h_word 'TableInsertTable'
             EXPORTING #1 = ' '
                       #2 = '6'
                       #3 = '1'
                       #4 = 'Auto'.

        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '2,0 cm'.

        PERFORM write_text
          USING 'Material number' 'TimesNewRoman' '12' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.

        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '4,0 cm'.

        PERFORM write_text
          USING 'Material description'
                'TimesNewRoman' '12'  'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '2,1 cm'.

        PERFORM write_text
          USING 'Quantity' 'TimesNewRoman' '12' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '1,6 cm'.

        PERFORM write_text
          USING ' Unit' 'TimesNewRoman' '12' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '3,0 cm'.

        CALL METHOD OF h_word 'RightPara' EXPORTING #01 = 'AlignRight'.

        PERFORM write_text
          USING 'Price / Unit' 'TimesNewRoman' '12' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'TableColumnWidth'
             EXPORTING #01 = '3,2 cm'.

        CALL METHOD OF h_word 'RightPara'
             EXPORTING #01 = 'AlignRight'.

        PERFORM write_text
          USING 'Net value' 'TimesNewRoman' '12' 'Bold'.

        CALL METHOD OF h_word 'NextCell'.
        CALL METHOD OF h_word 'NormalStyle'.
      ENDIF.


      PERFORM write_text USING itab-matnr 'TimesNewRoman' '10' ''.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.


      PERFORM write_text USING itab-txz01 'TimesNewRoman' '10' ''.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.

      MOVE itab-menge TO quantity. " Change to character
      quantity = quantity(10). " Take away the decimals
      PERFORM write_text USING quantity 'TimesNewRoman' '10' ''.

      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.

      PERFORM write_text USING itab-meins 'TimesNewRoman' '10' ''.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.

      CALL METHOD OF h_word 'RightPara' EXPORTING #01 = 'AlignRight'.
      MOVE itab-netpr TO value. " Change numeric to character
      PERFORM write_text USING value 'TimesNewRoman' '10' ''.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.


      CALL METHOD OF h_word 'RightPara' EXPORTING #01 = 'AlignRight'.
      temp = quantity * itab-netpr.
      MOVE temp TO netvalue. " Change numeric to character
      PERFORM write_text USING netvalue 'TimesNewRoman' '10' ''.

      ind = ind + 1.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NextCell'.
      CALL METHOD OF h_word 'NormalStyle'.

      temp = quantity * itab-netpr.
      MOVE temp TO netvalue. " Change numeric to character
      temp2 = netvalue + temp2.
    ENDLOOP.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.

    CALL METHOD OF h_word 'EndOfDocument'.
    CALL METHOD OF h_word 'EndOfLine'.
    CALL METHOD OF h_word 'InsertPara'.

    CALL METHOD OF h_word 'TableInsertTable'
         EXPORTING #1 = ' '
                   #2 = '4'
                   #3 = '1'
                   #4 = 'Auto'.

    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '4,6 cm'.

    PERFORM write_text
      USING 'Delivery Date' 'TimesNewRoman' '14' 'Bold'.

    CALL METHOD OF h_word 'NextCell'.

**************
    SELECT * FROM eket WHERE ebeln EQ getorder.
      itaba = eket.
      APPEND itaba.
    ENDSELECT.

    PERFORM write_text USING itaba-slfdt 'TimesNewRoman' '10' ''.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '4,5 cm'.

    PERFORM write_text
      USING 'Total Net Value' 'TimesNewRoman' '14' 'Bold'.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '2,9 cm'.

    CALL METHOD OF h_word 'RightPara'
         EXPORTING #01 = 'AlignRight'.

    MOVE temp2 TO sum. " Change numeric to character
    PERFORM write_text USING sum 'TimesNewRoman' '10' ''.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'EndOfDocument'.
    CALL METHOD OF h_word 'EndOfLine'.
    CALL METHOD OF h_word 'InsertPara'.

    CALL METHOD OF h_word 'TableInsertTable'
         EXPORTING #1 = ' '
                   #2 = '2'
                   #3 = '6'
                   #4 = 'Auto'.

    CALL METHOD OF h_word 'TableColumnWidth'
         EXPORTING #01 = '8,0 cm'.

    PERFORM write_text
      USING 'Please deliver to:' 'TimesNewRoman' '14' 'Bold'.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.

    PERFORM write_text
      USING 'Company name' 'TimesNewRoman' '10' ''.
    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.

    PERFORM write_text
      USING 'Longstreet 111' 'TimesNewRoman' '10' ''.

    CALL METHOD OF h_word 'NextCell'.
    CALL METHOD OF h_word 'NextCell'.

    PERFORM write_text
      USING '11111 Stockholm' 'TimesNewRoman' '10' ''.

  ENDIF.

  IF sy-subrc NE 0.
    WRITE: / 'Error when opening word.application', sy-msgli.
  ENDIF.

  FREE OBJECT h_word.
  h_word-handle = -1.

ENDFORM.



*---------------------------------------------------------------------*
* FORM WRITE_TEXT                                                     *
*---------------------------------------------------------------------*
* --> TEXT
* --> FONT
* --> SIZE
* --> LOOK
*---------------------------------------------------------------------*
FORM write_text USING text font size look.

  CALL METHOD OF h_word 'Font' EXPORTING #01 = font.
  CALL METHOD OF h_word 'FontSize' EXPORTING #1 = size.

  IF look NE ''.
    CALL METHOD OF h_word look.
  ENDIF.

  CALL METHOD OF h_word 'Insert' EXPORTING #1 = text.

ENDFORM.

Beitrag von Bitburki (ForumUser / 6 / 0 / 0 ) »
danke. Das ist die OLE Methode.
Funktioniert auch prima, und ich würde gerne darauf aufbauen.
Ich will jedoch keine Seriendruckfelder verwenden, sondern "Formfields" (ist in Word unter Ansicht->Symbolleisten->Formular zu finden).

Hab das ganze jetzt aber mal probieren wollen und schaffe es nicht dieses definierte Feld zu füllen. Laut MSDN hat die Methode folgende Propertys:

Code: Alles auswählen.

FormFieldOptions Entry, Exit, Name, Enable, TextType, TextWidth, TextDefault, TextFormat, CheckSize, CheckWidth, CheckDefault, Type, OwnHelp, HelpText, OwnStat, StatText
Kriegs aber einfach nicht hin.

Wie kann ich das Feld füllen?

Beitrag von ereglam (Top Expert / 1829 / 2 / 7 ) »
xy hat geschrieben:Hallo!

Ich kann mit der Methode 'TableInsertTable' eine Tabelle in mein Worddokument einfügen. Aber kann mir jemand sagen wie ich um diese Tabelle einen Rahmen ziehen kann?

Danke im Voraus!
Bei Abtrennen von einen Spam-Eintrag ist leider der nachfolgende Post mit abgetrennt worde.
mea culpa
Gruß
Ereglam


May the Force be with your code
|| .| |.|| | .... . ..|. ||| .|. |.|. . |... . .|| .. | .... |.|| ||| ..| .|. |.|. ||| |.. .

Seite 1 von 1

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Vergleichbare Themen

OLE2 + Word + Serienbrieffunktion
von roieli » 13.03.2007 10:30
ALV-liste-Daten mit der DB-Tabelle-Daten vergleichen
von Nadine_2706 » 31.08.2011 11:57
OLE WORD Textmarke
von Kerstin » 21.02.2019 11:15
Word Upload
von Ichse2 » 17.11.2020 10:05
OLE - Word-Datei
von Kerstin » 16.07.2008 11:38