cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_DOCUMENT_CREATE2 in Web Dynpro ABAP

Former Member
0 Kudos

Hi Friends,

I want to upload PDF file from my System and get it stored in content server Using WEB DYNPRO APPLICATION. I tried using it by calling the FM but its not uploading the file in the server.

Can i know the steps involved in uploading the file. I also created a custom Function Module and called this FM in WEB DYNPRO.

*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENTDATA) LIKE  BAPI_DOC_DRAW2 STRUCTURE
*"        BAPI_DOC_DRAW2
*"     VALUE(BIN_CONTENT) TYPE  XSTRING
*"  EXPORTING
*"     VALUE(DOCUMENTTYPE) LIKE  BAPI_DOC_AUX-DOCTYPE
*"     VALUE(DOCUMENTNUMBER) LIKE  BAPI_DOC_AUX-DOCNUMBER
*"     VALUE(DOCUMENTPART) LIKE  BAPI_DOC_AUX-DOCPART
*"     VALUE(DOCUMENTVERSION) LIKE  BAPI_DOC_AUX-DOCVERSION
*"     VALUE(RETURN) LIKE  BAPIRET2 STRUCTURE  BAPIRET2
*"  TABLES
*"      CHARACTERISTICVALUES STRUCTURE  BAPI_CHARACTERISTIC_VALUES
*"       OPTIONAL
*"      CLASSALLOCATIONS STRUCTURE  BAPI_CLASS_ALLOCATION OPTIONAL
*"      DOCUMENTDESCRIPTIONS STRUCTURE  BAPI_DOC_DRAT OPTIONAL
*"      OBJECTLINKS STRUCTURE  BAPI_DOC_DRAD OPTIONAL
*"      DOCUMENTSTRUCTURE STRUCTURE  BAPI_DOC_STRUCTURE OPTIONAL
*"      DOCUMENTFILES STRUCTURE  BAPI_DOC_FILES2 OPTIONAL
*"      LONGTEXTS STRUCTURE  BAPI_DOC_TEXT OPTIONAL
*"      COMPONENTS STRUCTURE  BAPI_DOC_COMP OPTIONAL
*"----------------------------------------------------------------------

*..... Document data
 data: ls_doc like bapi_doc_files2.
**..... Bapi return structure
 data: ls_return like bapiret2.
**.... Originals that are checked in at the same time
 data: lt_files like bapi_doc_files2 occurs 0 with header line.
data: tstampl like tzonref-tstampl, tstampl_c(21) type c,
           file_name type localfile, msg(80) type c.
constants path_name type localfile value '/tmp/'.
constants log type localfile value '/tmp/logFO.txt'.
* --------------------------------------------------------------------- *
*Create document
* ---------------------------------------------------------------------
describe table documentfiles lines sy-tfill.
 if sy-tfill > 0.
clear ls_doc.
clear lt_files.
loop at documentfiles into ls_doc from 1 to 1.
open dataset log for output in text mode encoding default.
transfer ls_doc-wsapplication to log.
transfer ls_doc-description to log.
get time stamp field tstampl.
unpack tstampl to tstampl_c.
clear file_name.
concatenate path_name '/' sy-repid '_' 'ATT' tstampl_c '.' ls_doc-wsapplication into file_name.

condense file_name no-gaps.
 transfer file_name to log.
open dataset file_name for output in binary mode message msg.
if sy-subrc = 0.
message a899(zz) with file_name msg 'SY-SUBRC:' sy-subrc.
 endif.
 transfer bin_content to file_name.
 close dataset file_name.
transfer 'move data to lt_files' to log.
move:documentdata-documenttype to lt_files-documenttype,
           documentdata-documentpart to lt_files-documentpart,
           documentdata-documentversion to lt_files-documentversion,
           ls_doc-description to lt_files-description,
           '1' to lt_files-originaltype,
            'Z_TEST_SAP' to lt_files-storagecategory,
            ls_doc-wsapplication to lt_files-wsapplication,
            file_name to lt_files-docfile,
            'X' to lt_files-checkedin.
translate lt_files-wsapplication to upper case.
append lt_files.
** CLEAR ls_return.
 transfer 'call BAPI_DOCUMENT_CREATE2' to log.
 call function 'BAPI_DOCUMENT_CREATE2'
      exporting
        documentdata = documentdata
        pf_http_dest = 'SAPHTTPA'
      importing
         documentnumber = documentnumber
         documenttype = documenttype
         documentversion = documentversion
         documentpart = documentpart
         return = return
     tables
         objectlinks = objectlinks
         documentfiles = lt_files
     exceptions
          others = 1.
     close dataset log.
      endloop.
      endif.
     endfunction.

But i am getting short Dump stating File /tmp/logFO.txt is not open.

Can anyone help me with this issue..

Regards,

Santosh

Accepted Solutions (0)

Answers (2)

Answers (2)

om_awasthi1
Participant
0 Kudos

Hi,

Please share the solution . I am also facing the same problem .

Omm

Former Member
0 Kudos

please help me with this issue as it is gettin very critical..

Former Member
0 Kudos

Soved by myself...

Thanks...

Former Member
0 Kudos

Hello,

I'm facing the same issue, could you please tell me how did you solve your problem.

Thanks in advance for your help.