SAP Function Modules

BAPI_DOCUMENT_CREATE2 SAP Function module







BAPI_DOCUMENT_CREATE2 is a standard SAP function module available within R/3 SAP systems depending on your version and release level. Below is the pattern details for this FM showing its interface including any import and export parameters, exceptions etc as well as any documentation contributions (Comments) specific to the object.

See here to view full function module documentation and code listing, simply by entering the name BAPI_DOCUMENT_CREATE2 into the relevant SAP transaction such as SE37 or SE80.

Associated Function Group: CVBAPI
Released Date: 25.03.1999
Processing type: Remote-Enabled
remote enabled module settings


Pattern for FM BAPI_DOCUMENT_CREATE2 - BAPI DOCUMENT CREATE2





CALL FUNCTION 'BAPI_DOCUMENT_CREATE2' "
  EXPORTING
    documentdata =              " bapi_doc_draw2  Document Data
*   hostname =                  " bapi_doc_aux-hostname  Name of Frontend
*   docbomchangenumber =        " bapi_doc_draw2-ecnumber  Change Number
*   docbomvalidfrom =           " bapi_doc_draw2-validfromdate  Valid-From Date
*   docbomrevisionlevel =       " bapi_doc_draw2-revlevel  Revision level
*   cad_mode = SPACE            " csdata-xfeld  CAD FLag for Document Structure
*   pf_ftp_dest = SPACE         " rfcdes-rfcdest  Logical Destination (Specified in Function Call)
*   pf_http_dest = SPACE        " rfcdes-rfcdest  Logical Destination (Specified in Function Call)
*   defaultclass = 'X'          " bapi_doc_aux-flag  Uses class maintained in customization
  IMPORTING
    documenttype =              " bapi_doc_aux-doctype  Document Type
    documentnumber =            " bapi_doc_aux-docnumber  Document Number
    documentpart =              " bapi_doc_aux-docpart  Document Part
    documentversion =           " bapi_doc_aux-docversion  Document Version
    return =                    " bapiret2      Return Structure
* TABLES
*   characteristicvalues =      " bapi_characteristic_values  Characteristic Value Assignments
*   classallocations =          " bapi_class_allocation  Classifications
*   documentdescriptions =      " bapi_doc_drat  Descriptions
*   objectlinks =               " bapi_doc_drad  Object Links
*   documentstructure =         " bapi_doc_structure  Document Structure
*   documentfiles =             " bapi_doc_files2  Originals
*   longtexts =                 " bapi_doc_text  Long Texts
*   components =                " bapi_doc_comp  Additional Files for Originals (in future development)
    .  "  BAPI_DOCUMENT_CREATE2

ABAP code example for Function Module BAPI_DOCUMENT_CREATE2





The ABAP code below is a full code listing to execute function module BAPI_DOCUMENT_CREATE2 including all data declarations. The code uses the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the original method of declaring data variables up front. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8).

DATA:
ld_documenttype  TYPE BAPI_DOC_AUX-DOCTYPE ,
ld_documentnumber  TYPE BAPI_DOC_AUX-DOCNUMBER ,
ld_documentpart  TYPE BAPI_DOC_AUX-DOCPART ,
ld_documentversion  TYPE BAPI_DOC_AUX-DOCVERSION ,
ld_return  TYPE BAPIRET2 ,
it_characteristicvalues  TYPE STANDARD TABLE OF BAPI_CHARACTERISTIC_VALUES,"TABLES PARAM
wa_characteristicvalues  LIKE LINE OF it_characteristicvalues ,
it_classallocations  TYPE STANDARD TABLE OF BAPI_CLASS_ALLOCATION,"TABLES PARAM
wa_classallocations  LIKE LINE OF it_classallocations ,
it_documentdescriptions  TYPE STANDARD TABLE OF BAPI_DOC_DRAT,"TABLES PARAM
wa_documentdescriptions  LIKE LINE OF it_documentdescriptions ,
it_objectlinks  TYPE STANDARD TABLE OF BAPI_DOC_DRAD,"TABLES PARAM
wa_objectlinks  LIKE LINE OF it_objectlinks ,
it_documentstructure  TYPE STANDARD TABLE OF BAPI_DOC_STRUCTURE,"TABLES PARAM
wa_documentstructure  LIKE LINE OF it_documentstructure ,
it_documentfiles  TYPE STANDARD TABLE OF BAPI_DOC_FILES2,"TABLES PARAM
wa_documentfiles  LIKE LINE OF it_documentfiles ,
it_longtexts  TYPE STANDARD TABLE OF BAPI_DOC_TEXT,"TABLES PARAM
wa_longtexts  LIKE LINE OF it_longtexts ,
it_components  TYPE STANDARD TABLE OF BAPI_DOC_COMP,"TABLES PARAM
wa_components  LIKE LINE OF it_components .

DATA(ld_documentdata) = 'Check type of data required'.

DATA(ld_hostname) = some text here

DATA(ld_docbomchangenumber) = some text here

DATA(ld_docbomvalidfrom) = 20210129

DATA(ld_docbomrevisionlevel) = some text here

DATA(ld_cad_mode) = some text here

SELECT single RFCDEST
FROM RFCDES
INTO @DATA(ld_pf_ftp_dest).


SELECT single RFCDEST
FROM RFCDES
INTO @DATA(ld_pf_http_dest).


DATA(ld_defaultclass) = some text here

"populate fields of struture and append to itab
append wa_characteristicvalues to it_characteristicvalues.

"populate fields of struture and append to itab
append wa_classallocations to it_classallocations.

"populate fields of struture and append to itab
append wa_documentdescriptions to it_documentdescriptions.

"populate fields of struture and append to itab
append wa_objectlinks to it_objectlinks.

"populate fields of struture and append to itab
append wa_documentstructure to it_documentstructure.

"populate fields of struture and append to itab
append wa_documentfiles to it_documentfiles.

"populate fields of struture and append to itab
append wa_longtexts to it_longtexts.

"populate fields of struture and append to itab
append wa_components to it_components. . CALL FUNCTION 'BAPI_DOCUMENT_CREATE2' EXPORTING documentdata = ld_documentdata * hostname = ld_hostname * docbomchangenumber = ld_docbomchangenumber * docbomvalidfrom = ld_docbomvalidfrom * docbomrevisionlevel = ld_docbomrevisionlevel * cad_mode = ld_cad_mode * pf_ftp_dest = ld_pf_ftp_dest * pf_http_dest = ld_pf_http_dest * defaultclass = ld_defaultclass IMPORTING documenttype = ld_documenttype documentnumber = ld_documentnumber documentpart = ld_documentpart documentversion = ld_documentversion return = ld_return * TABLES * characteristicvalues = it_characteristicvalues * classallocations = it_classallocations * documentdescriptions = it_documentdescriptions * objectlinks = it_objectlinks * documentstructure = it_documentstructure * documentfiles = it_documentfiles * longtexts = it_longtexts * components = it_components . " BAPI_DOCUMENT_CREATE2
IF SY-SUBRC EQ 0. "All OK ENDIF.







ABAP code to compare 7.40 inline data declaration with original syntax

The below ABAP code uses the older none in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. It may also be useful if you are using an older version of SAP as some of the newer syntax above, such as the @DATA is not available until 4.70 EHP 8.

DATA:
ld_documenttype  TYPE BAPI_DOC_AUX-DOCTYPE ,
ld_documentdata  TYPE BAPI_DOC_DRAW2 ,
it_characteristicvalues  TYPE STANDARD TABLE OF BAPI_CHARACTERISTIC_VALUES ,
wa_characteristicvalues  LIKE LINE OF it_characteristicvalues,
ld_documentnumber  TYPE BAPI_DOC_AUX-DOCNUMBER ,
ld_hostname  TYPE BAPI_DOC_AUX-HOSTNAME ,
it_classallocations  TYPE STANDARD TABLE OF BAPI_CLASS_ALLOCATION ,
wa_classallocations  LIKE LINE OF it_classallocations,
ld_documentpart  TYPE BAPI_DOC_AUX-DOCPART ,
ld_docbomchangenumber  TYPE BAPI_DOC_DRAW2-ECNUMBER ,
it_documentdescriptions  TYPE STANDARD TABLE OF BAPI_DOC_DRAT ,
wa_documentdescriptions  LIKE LINE OF it_documentdescriptions,
ld_documentversion  TYPE BAPI_DOC_AUX-DOCVERSION ,
ld_docbomvalidfrom  TYPE BAPI_DOC_DRAW2-VALIDFROMDATE ,
it_objectlinks  TYPE STANDARD TABLE OF BAPI_DOC_DRAD ,
wa_objectlinks  LIKE LINE OF it_objectlinks,
ld_return  TYPE BAPIRET2 ,
ld_docbomrevisionlevel  TYPE BAPI_DOC_DRAW2-REVLEVEL ,
it_documentstructure  TYPE STANDARD TABLE OF BAPI_DOC_STRUCTURE ,
wa_documentstructure  LIKE LINE OF it_documentstructure,
it_documentfiles  TYPE STANDARD TABLE OF BAPI_DOC_FILES2 ,
wa_documentfiles  LIKE LINE OF it_documentfiles,
ld_cad_mode  TYPE CSDATA-XFELD ,
ld_pf_ftp_dest  TYPE RFCDES-RFCDEST ,
it_longtexts  TYPE STANDARD TABLE OF BAPI_DOC_TEXT ,
wa_longtexts  LIKE LINE OF it_longtexts,
ld_pf_http_dest  TYPE RFCDES-RFCDEST ,
it_components  TYPE STANDARD TABLE OF BAPI_DOC_COMP ,
wa_components  LIKE LINE OF it_components,
ld_defaultclass  TYPE BAPI_DOC_AUX-FLAG .

ld_documentdata = 'Check type of data required'.

"populate fields of struture and append to itab
append wa_characteristicvalues to it_characteristicvalues.

ld_hostname = some text here

"populate fields of struture and append to itab
append wa_classallocations to it_classallocations.

ld_docbomchangenumber = some text here

"populate fields of struture and append to itab
append wa_documentdescriptions to it_documentdescriptions.

ld_docbomvalidfrom = 20210129

"populate fields of struture and append to itab
append wa_objectlinks to it_objectlinks.

ld_docbomrevisionlevel = some text here

"populate fields of struture and append to itab
append wa_documentstructure to it_documentstructure.

"populate fields of struture and append to itab
append wa_documentfiles to it_documentfiles.

ld_cad_mode = some text here

SELECT single RFCDEST
FROM RFCDES
INTO ld_pf_ftp_dest.


"populate fields of struture and append to itab
append wa_longtexts to it_longtexts.

SELECT single RFCDEST
FROM RFCDES
INTO ld_pf_http_dest.


"populate fields of struture and append to itab
append wa_components to it_components.

ld_defaultclass = some text here

SAP Documentation for FM BAPI_DOCUMENT_CREATE2


You can use this function module to create documents and all data that belongs to it. ...See here for full SAP fm documentation

Contribute (Add Comments)

Please help keep this info upto date and use the comments section below to add useful hints, tips and information specific to this SAP function. This will then be available for you and other users to easily find by simply searching on the object name BAPI_DOCUMENT_CREATE2 or its description.