SAP Function BAPI_DOCUMENT_CREATE - Create Document

Parameter Reference Type Length Default Optional Text
DOCUMENTDATA BAPI_DOC_DRAW u 1364 Document Data
HOSTNAME BAPI_DOC_AUX-HOSTNAME C 20 SPACE X Name of Frontend

Parameter Reference Type Length Text
DOCNUMBER BAPI_DOC_AUX-DOCNUMBER C 25 Document Number
DOCPART BAPI_DOC_AUX-DOCPART C 3 Document Part
DOCTYPE BAPI_DOC_AUX-DOCTYPE C 3 Document Type
DOCVERSION BAPI_DOC_AUX-DOCVERSION C 2 Document Version
RETURN BAPIRET2 u 548 BAPI Return

Parameter Reference Length Optional Text
CHARACTERISTICVALUES BAPI_CHARACTERISTIC_VALUES 82 X Assigned Characteristic Values
CLASSALLOCATIONS BAPI_CLASS_ALLOCATION 36 X Classifications
DOCUMENTDESCRIPTIONS BAPI_DOC_DRAT 45 X Short texts
DOCUMENTFILES BAPI_DOC_FILES 336 X Originals to Check In
DOCUMENTSTRUCTURE BAPI_DOC_STRUCTURE 64 X Document-Based Structure
LONGTEXTS BAPI_DOC_TEXT 136 X Long Texts
OBJECTLINKS BAPI_DOC_DRAD 215 X Object Links

Functionality
You can use this method to create documents and their respective data.
You can also check the original application files (1 and 2) into theSAP data base, vault, or archive.
Restrictions:

  • Additional files are not supported

  • Long texts for object links are not supported

  • Value assignments for the object links are not supported

  • **..... Document data
    DATA: ls_doc LIKE bapi_doc_draw.
    **..... Bapi return structure
    ls_return LIKE bapiret2.
    **.... key fields of new document
    DATA: lf_doctype LIKE bapi_doc_draw-documenttype,
    lf_docnumber LIKE bapi_doc_draw-documentnumber,
    lf_docpart LIKE bapi_doc_draw-documenttype,
    lf_docversion LIKE bapi_doc_draw-documenttype.
    **.... Originals that are checked in at the same time
    DATA: lt_files LIKE bapi_doc_files OCCURS 0 WITH HEADER LINE,
    **.... Descriptions
    lt_drat LIKE bapi_doc_drat OCCURS 0 WITH HEADER LINE,
    **.... Object links
    lt_drad LIKE bapi_doc_drad OCCURS 0 WITH HEADER LINE.
    **----------------------------------------------------------------------
    ** Allocate document data
    ls_doc-documenttype = 'DRW'.
    ls_doc-documentnumber = '4711'.
    ls_doc-documentversion = '000'.
    ls_doc-documentpart = '00'.
    ls_doc-description = 'Gear box'.
    ls_doc-statusextern = 'AF'.
    ls_doc-laboratory = '001'.
    ls_doc-wsapplication1 = 'DWG'.
    ** Check original 1 into the SAP data base at the same time
    REFRESH lt_files.
    CLEAR lt_files.
    lt_files-originaltype = '1'.
    lt_files-datacarrier = 'SAP-SYSTEM'.
    lt_files-docfile = 'c:\temp\drawing1.dwg'.
    APPEND lt_files.
    ** Description in english
    CLEAR lt_drat.
    REFRESH lt_drat.
    lt_drat-language = 'EN'.
    lt_drat-description = 'gear'.
    APPEND lt_drat.
    ** Object link to material master
    CLEAR lt_drad.
    REFRESH lt_drad.
    lt_drad-objecttype = 'MARA'.
    lt_drad-objectkey = 'M4711'.
    APPEND lt_drad.
    * ---------------------------------------------------------------------
    * Create document
    * ---------------------------------------------------------------------
    CALL FUNCTION 'BAPI_DOCUMENT_CREATE'
    EXPORTING: documentdata = ls_doc
    IMPORTING: documenttype = lf_doctype
    documentnumber = lf_docnumber
    documentpart = lf_docpart
    documentversion = lf_docversion
    return = ls_return
    TABLES: documentdescriptions = lt_drat
    objectlinks = lt_drad
    documentfiles = lt_files.
    ** Error occurred ??
    IF ls_return-type CA 'EA'.
    ROLLBACK WORK.
    MESSAGE ID '26' TYPE 'I' NUMBER '000'
    WITH ls_return-message.
    ELSE.
    COMMIT WORK.
    ENDIF.

    Hints
    Apart from the document data, you can create the following data:

    • Object links

    • Classifications and characteristic value assignments

    • Language-dependent document descriptions

    • Document long texts

    • Document structures

    • Originals (1 and 2)
    • Description
      Return structure for messages

      Description
      General document data

      Description
      Computer name of the front end computer that the function module wascalled from.
      You only need to enter this name if the function module call takesplace from an external system. The appropriate front end is determinedfrom Customizing for the DMS using this computer name.

      Description
      Characteristic values for document
      The class and characteristic definitions required must be determinedbeforehand. If you want to delete characteristic values, you must setthe "DELETEVALUE" indicator explicitly for those characteristics thatyou want to delete the values for.
      The appropriate classifications are delivered using CLASSALLOCATION.

      Description
      Classification for document
      The class and characteristic definitions required must be determinedbeforehand. If you want to delete classifications, you must set the"DELETEVALUE" deletion indicator explicitly for the class that you wantto delete.
      The appropriate characteristic values are delivered usingCHARACTERISTICVALUES.

      Description
      Language-dependent texts
      Texts that are delivered are always added to those already existing.This means that if you want to delete texts, you must set the"DELETEVALUE" deletion indicator explicitly for the appropriatelanguage.

      Description
      Document originals
      You can check in original 1 and 2 at the same time. If you want theoriginals to be checked in when you create the document, you must enterthis explicitly here (irrespective of the settings in DocumentData).
      You can define which original you are dealing with (1 or 2) using theORIGINALTYPE parameter.
      ORIGINALTYPE: Original 1 or orginal 2
      SOURCECARRIER: possible data carrier name of the server where theoriginal is stored
      DATACARRIER: Name of the data carrier that the original is to bechecked in to. Using the data carrier name, the functionmodule determines the storage type, that is, SAP database, vault, or archive.
      DOCFILE: File name of the original
      WSAPPLICATION: Name of the work station application.
      This is a required entry if the document info
      record has not yet been allocated to a work station
      application or the new "original" is of a different
      type.
      The parameters: INTERNAL STATUS, EXTERNAL STATUS and STATUS LOG have no
      relevance to this function module.

      Description
      Document structure/BOM for document
      You can use this BOM to represent document structures for a headerdocument, for example, assembly structures for 3D models. A documentstructure is always regarded as one unit. This means that an existingBOM is completely overwritten by the new one. If you just want todelete specific items in a BOM, you must set the "DELETEVALUE"indicator explicitly for these items.
      All the documents in your new structure must have already been created.

      Description
      Long text for document
      The long texts are always added to the texts that already exist. If youwant to delete texts, you must explicitly set the "DELETEVALUE"deletion indicator for the appropriate language.

      Description
      Object links for document
      Object links are always added to those that already exist. If you wantto delete links, you must explicitly set the "DELETEVALUE" deletionindicator.
      OBJECTTYPE: the internal descriptions from table TCLO are used (forexample, MARA for material) for the object type
      OBJECTKEY: the object key is copied as a complete string (according totable TCLO)