Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan-Schnell
Active Contributor
906
In many cases we need for the technical documentation some information from the Data Dictionary (DDIC). As in business usual we use Microsoft Word for our technical documents. From this perspective I build a function module (FM) which creates Word tables inside a document with informations from the DDIC - in my case TABNAME, POSITION, FIELDNAME, KEYFLAG, LENG, DECIMALS, DATATYPE and DDTEXT. With this FM it is now very easy to create some technical information automatically and fast, to copy it into the final document.



"-Begin-----------------------------------------------------------------

Function Z_TABDEFEXPORT.

*"----------------------------------------------------------------------

*"*"Lokale Schnittstelle:

*"  IMPORTING

*"     VALUE(TABNAMEPATTERN) TYPE  STRING

*"----------------------------------------------------------------------

  "-Constants-----------------------------------------------------------

    Constants wdStory Type i Value 6.

    Constants wdMove Type i Value 0.

    Constants wdPageBreak Type i Value 7.

    Constants wdLine Type i Value 5.

    Constants wdLineStyleSingle Type i Value 1.

    Constants wdLineWidth050pt Type i Value 4.

    Constants wdAutoFitContent Type i Value 1.

  "-Variables-----------------------------------------------------------

    Data tFields Type Standard Table Of DD03M.

    Data tTabs Type Standard Table Of DD02L.

    Data Fields Type DD03M.

    Data oWord Type OLE2_OBJECT.

    Data oDocs Type OLE2_OBJECT.

    Data oDoc Type OLE2_OBJECT.

    Data oSel Type OLE2_OBJECT.

    Data oTables Type OLE2_OBJECT.

    Data oTable Type OLE2_OBJECT.

    Data oRange Type OLE2_OBJECT.

    Data oBorders Type OLE2_OBJECT.

    Data oRows Type OLE2_OBJECT.

    Data oRow Type OLE2_OBJECT.

    Data Buffer Type String Value ''.

  "-Main----------------------------------------------------------------

    Select TABNAME From DD02L Into Corresponding Fields Of Table tTabs

      Where TABNAME Like TabNamePattern And TABCLASS = 'TRANSP'

      Order By TABNAME.

    Select TABNAME FIELDNAME POSITION KEYFLAG DATATYPE LENG DECIMALS

      DDTEXT From DD03M Into Corresponding Fields Of Table tFields

      For All Entries In tTabs Where TABNAME = tTabs-TABNAME

      And DDLANGUAGE = 'D'.

    Sort tFields By TABNAME POSITION.

    Create Object oWord 'Word.Application'.

    If sy-subrc = 0 And oWord-Handle <> 0 And oWord-Type = 'OLE2'.

      Set Property Of oWord 'Visible' = 1.

      Get Property Of oWord 'Documents' = oDocs.

      Call Method Of oDocs 'Add' = oDoc.

      PerForm OLEFlush.

      Loop At tFields Into Fields.

        Get Property Of oWord 'Selection' = oSel.

        At New TABNAME.

          Call Method Of oSel 'TypeText' Exporting #1 = Fields-TABNAME.

          Get Property Of oSel 'Range' = oRange.

          Get Property Of oSel 'Tables' = oTables.

          "-Create new table--------------------------------------------

            Call Method Of oTables 'Add' = oTable

              Exporting #1 = oRange #2 = 1 #3 = 8.

          "-Set border of table-----------------------------------------

            Get Property Of oTable 'Borders' = oBorders.

            Set Property Of oBorders 'OutsideLineStyle' = wdLineStyleSingle.

            Set Property Of oBorders 'OutsideLineWidth' = wdLineWidth050pt.

            Set Property Of oBorders 'InsideLineStyle' = wdLineStyleSingle.

            Set Property Of oBorders 'InsideLineWidth' = wdLineWidth050pt.

          "-Fill head line----------------------------------------------

            PerForm HeadLine Using oTable 'Tab.-Name' 1.

            PerForm HeadLine Using oTable 'Pos.' 2.

            PerForm HeadLine Using oTable 'Feldname' 3.

            PerForm HeadLine Using oTable 'Key' 4.

            PerForm HeadLine Using oTable 'Len' 5.

            PerForm HeadLine Using oTable 'Dec' 6.

            PerForm HeadLine Using oTable 'Typ' 7.

            PerForm HeadLine Using oTable 'Beschreibung' 8.

          Call Method Of oSel 'MoveDown' Exporting #1 = wdLine #2 = 1.

          Call Method Of oSel 'TypeParagraph'.

          Call Method Of oSel 'EndKey' Exporting #1 = wdStory.

          "-Page break after the new table------------------------------

            Call Method Of oSel 'InsertBreak' Exporting #1 = wdPageBreak.

          PerForm OLEFlush.

          Free Object oRange.

          Free Object oSel.

        EndAt.

        Get Property Of oTable 'Rows' = oRows.

        Call Method Of oRows 'Add' = oRow.

        "-Fill the fields-----------------------------------------------

          Do 8 Times.

            Case sy-index.

              When 1. Buffer = Fields-TABNAME.

              When 2. Buffer = Fields-POSITION.

              When 3. Buffer = Fields-FIELDNAME.

              When 4. Buffer = Fields-KEYFLAG.

              When 5. Buffer = Fields-LENG.

              When 6. Buffer = Fields-DECIMALS.

              When 7. Buffer = Fields-DATATYPE.

              When 8. Buffer = Fields-DDTEXT.

            EndCase.

            PerForm FillLine Using oRow Buffer sy-index.

          EndDo.

          PerForm OLEFlush.

        Free Object oRow.

        Free Object oRows.

        At End Of TABNAME.

          "-Fits the table----------------------------------------------

            Call Method Of oTable 'AutoFitBehavior'

              Exporting #1 = wdAutoFitContent.

          Free Object oTable.

          Free Object oTables.

        EndAt.

      EndLoop.

      Free Object oDoc.

      Free Object oDocs.

      Free Object oWord.

    EndIf.

EndFunction.

"-SubRoutines-----------------------------------------------------------

  "-HeadLine------------------------------------------------------------

    Form HeadLine Using oTable Type OLE2_OBJECT Text Type String

      Col Type i.

      "-Variables-------------------------------------------------------

        Data oCell Type OLE2_OBJECT.

        Data oText Type OLE2_OBJECT.

        Data oFont Type OLE2_OBJECT.

      Call Method Of oTable 'Cell' = oCell Exporting #1 = 1 #2 = Col.

      Get Property Of oCell 'Range' = oText.

      Set Property Of oText 'Text' = Text.

      Get Property Of oText 'Font' = oFont.

      Set Property Of oFont 'Size' = '7'.

      Set Property Of oFont 'Name' = 'Calibri'.

      Free Object oFont.

      Free Object oText.

      Free Object oCell.

    EndForm.

  "-FillLine------------------------------------------------------------

    Form FillLine Using oRow Type OLE2_OBJECT Text Type String

      Col Type i.

      "-Variables-------------------------------------------------------

        Data oCells Type OLE2_OBJECT.

        Data oCell Type OLE2_OBJECT.

        Data oText Type OLE2_OBJECT.

      Get Property Of oRow 'Cells' = oCells.

      Call Method Of oCells 'Item' = oCell Exporting #1 = Col.

      Get Property Of oCell 'Range' = oText.

      Set Property Of oText 'Text' = Text.

      Free Object oText.

      Free Object oCell.

      Free Object oCells.

    EndForm.

  "-OLEFlush------------------------------------------------------------

    Form OLEFlush.

      Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

    EndForm.

"-End-------------------------------------------------------------------

This FM offers a good base to expand resp. to individualize the functionality.

In my case I use table DD03M, but you can use the tables:

  • TDEVC for packages.

  • TADIR for repository objects, e.g. object FUGR for function groups.

  • TFDIR for function modules.

  • FUPARAREF for parameters of the function modules.

  • ...


Enjoy it.
Labels in this area