Skip to Content
author's profile photo Former Member
Former Member

I am trying to save a DMS File through File upload UI element to CV01n Transactions....It works fine for .TXT file but other files it is not downloading coorectly and file is getting damaged


Hi, I am downloading DMS file using following code and the file contents are getting damaged and cannot be retieved back. I am also getting hard time to open a DMS file in seperate browser.

Can anybody please help me.

TYPES : BEGIN OF ty_ts_raw_line,

* line TYPE sdokcntbin ,

line(2550) TYPE x,

END OF ty_ts_raw_line.



DATA: ls_documentdata TYPE bapi_doc_draw2,

lv_doctype TYPE bapi_doc_aux-doctype,

lv_docnumber TYPE bapi_doc_aux-docnumber,

lv_documentpart TYPE bapi_doc_aux-docpart,

lv_documentversion TYPE bapi_doc_aux-docversion,

ls_return TYPE bapiret2,

gt_bapi_doc_files2 TYPE TABLE OF bapi_doc_files2,

gs_bapi_doc_files2 LIKE LINE OF gt_bapi_doc_files2,

lo_nd_nd_cost_rate TYPE REF TO if_wd_context_node,

lt_nd_cost_rate TYPE wd_this->elements_nd_cost_rate,

ls_nd_cost_rate TYPE wd_this->element_nd_cost_rate,

lv_string TYPE string,

lv_temp TYPE string,

lv_input_file_name TYPE string,

lv_size TYPE i ,

lt_bindata TYPE STANDARD TABLE OF ty_ts_raw_line," STANDARD TABLE OF zst_ts_raw_line,

ls_bindata TYPE sdokcntbin,

ls_drao TYPE drao,

lt_drao TYPE TABLE OF drao,

lt_files TYPE cvapi_tbl_doc_files,

ls_files TYPE cvapi_doc_file,

ls_api_ctrl TYPE cvapi_api_control,

ls_message TYPE messages,

lv_dappl TYPE draw-dappl,

lv_filename TYPE char200,

lv_filename_draw_filep TYPE draw-filep,

lv_doc_succ TYPE c,

lv_tabix TYPE sy-tabix,

lv_char_tabix(5) TYPE c,

* get message manager

lo_api_controller TYPE REF TO if_wd_controller,

lo_message_manager TYPE REF TO if_wd_message_manager,

lv_text TYPE string,

lt_tabix TYPE STANDARD TABLE OF sytabix,

lv_api_ctrl TYPE cvapi_api_control VALUE 'CV01N',

lv_documentnumber TYPE draw-doknr,

lt_drat TYPE TABLE OF dms_db_drat,

ls_drat TYPE dms_db_drat.



CONSTANTS: lc_cst(3) TYPE c VALUE 'CST',

lc_000(3) TYPE c VALUE '000',

lc_00(2) TYPE c VALUE '00',

lc_zng_test(8) TYPE c VALUE 'ZNG-TEST',

lc_desc(11) TYPE c VALUE 'Cost Rate',

lc_test(4) TYPE c VALUE 'Test',

* lc_file_path(31) TYPE c VALUE 'C:\FAKEPATH\COST_RATE_TABLE.TXT',

lc_x TYPE c VALUE 'X',

lc_blank TYPE c VALUE '',

lc_nd(2) TYPE c VALUE '&1'.



FIELD-SYMBOLS <ls_wd_assist_mt_input> LIKE LINE OF wd_assist->mt_input.



lo_api_controller ?= wd_this->wd_get_api( ).



CALL METHOD lo_api_controller->get_message_manager

RECEIVING

message_manager = lo_message_manager.



* navigate from <CONTEXT> to <ND_COST_RATE> via lead selection

lo_nd_nd_cost_rate = wd_context->get_child_node( name = wd_this->wdctx_nd_cost_rate ).

* @TODO handle non existant child

IF lo_nd_nd_cost_rate IS NOT INITIAL.

lo_nd_nd_cost_rate->get_static_attributes_table( IMPORTING table = lt_nd_cost_rate ).

ENDIF.

ls_documentdata-documenttype = lc_cst.

ls_documentdata-documentnumber = lc_cst.

ls_documentdata-documentversion = lc_00.

ls_documentdata-documentpart = lc_000.

ls_documentdata-description = lc_desc.

* ls_documentdata-

* ls_drat-dktxt = lc_desc.

* append ls_drat to lt_drat.

* clear ls_drat.

* lv_api_ctrl = 'CV01N'.

LOOP AT lt_nd_cost_rate INTO ls_nd_cost_rate WHERE row_index IS NOT INITIAL.

lv_tabix = sy-tabix.



* CALL FUNCTION 'CVAPI_DOC_CREATE'

* EXPORTING

* ps_draw = ls_documentdata " wa_documentfiles

* ps_api_control = lv_api_ctrl

* IMPORTING

* psx_message = ls_message

* pfx_doknr = lv_documentnumber.

** TABLES

** pt_drat_x = it_drat.





CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

EXPORTING

documentdata = ls_documentdata

defaultclass = 'X'

IMPORTING

documenttype = lv_doctype

documentnumber = lv_docnumber

documentpart = lv_documentpart

documentversion = lv_documentversion

return = ls_return.

IF ls_return-type CA 'EA'.

ROLLBACK WORK.

ELSE.

COMMIT WORK.

ENDIF.

LOOP AT wd_assist->mt_input ASSIGNING <ls_wd_assist_mt_input> WHERE row_index = ls_nd_cost_rate-row_index.



CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = <ls_wd_assist_mt_input>-file_data

IMPORTING

output_length = lv_size

TABLES

binary_tab = lt_bindata.



lv_filename_draw_filep = <ls_wd_assist_mt_input>-filename.

WHILE lv_filename_draw_filep CA '\'.

SPLIT lv_filename_draw_filep AT '\'

INTO lv_temp lv_filename_draw_filep.

ENDWHILE.



LOOP AT lt_bindata INTO ls_bindata.

CLEAR ls_drao.

ls_drao-orblk = ls_bindata-line.

ls_drao-orln = lv_size.

ls_drao-dokar = lv_doctype.

ls_drao-doknr = lv_docnumber.

ls_drao-dokvr = lv_documentversion.

ls_drao-doktl = lv_documentpart.

ls_drao-appnr = '1'.

APPEND ls_drao TO lt_drao.

CLEAR ls_drao.

ENDLOOP.



CONDENSE lv_input_file_name.

* lv_input_file_name = 'Test.txt'.

CALL FUNCTION 'CV120_DOC_GET_APPL'

EXPORTING

pf_file = lv_filename_draw_filep

IMPORTING

pfx_dappl = lv_dappl.



ls_files-appnr = '1'.

ls_files-dappl = lv_dappl.

ls_files-filename = lv_filename_draw_filep.

ls_files-updateflag = 'I'.

ls_files-langu = sy-langu.

ls_files-storage_cat = 'SAP-SYSTEM'.

ls_files-description = lv_filename_draw_filep..

APPEND ls_files TO lt_files.

CLEAR ls_files.



ls_api_ctrl-tcode = 'CV01N'.



CALL FUNCTION 'CVAPI_DOC_CHECKIN'

EXPORTING

pf_dokar = lv_doctype

pf_doknr = lv_docnumber

pf_dokvr = lv_documentversion

pf_doktl = lv_documentpart

ps_api_control = ls_api_ctrl

pf_content_provide = 'TBL'

pf_http_dest = 'SAPHTTPA'

pf_ftp_dest = 'SAPFTPA'

IMPORTING

psx_message = ls_message

TABLES

pt_files_x = lt_files

pt_content = lt_drao.

IF ls_message-msg_type CA 'EA'.

lv_doc_succ = lc_blank.

ELSE.

COMMIT WORK.

lv_doc_succ = lc_x.

CLEAR lv_text .

lv_text = <ls_wd_assist_mt_input>-comments.

ENDIF.

CLEAR: ls_api_ctrl,ls_message,lt_files[],lt_drao[].

ENDLOOP.



IF lv_doc_succ = lc_x.

ls_nd_cost_rate-dokar = lv_doctype.

ls_nd_cost_rate-doknr = lv_docnumber.

ls_nd_cost_rate-doktl = lv_documentpart.

ls_nd_cost_rate-dokvr = lv_documentversion.

ls_nd_cost_rate-comments = lv_text.

MODIFY lt_nd_cost_rate FROM ls_nd_cost_rate INDEX lv_tabix TRANSPORTING dokar doknr doktl dokvr comments.

ELSE.

APPEND lv_tabix TO lt_tabix.

ENDIF.

CLEAR ls_nd_cost_rate.

ENDLOOP.

I am also having hardtime to show DMS file on browser.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jun 04, 2014 at 04:40 AM

    Hi I've done DMS Creation like below code. Just check it .

    LS_DOC-DOCUMENTTYPE = LW_DMS_APP-DOCUMENTTYPE.

    LS_DOC-DOCUMENTVERSION = LW_DMS_APP-DOCUMENTVERSION.

    LS_DOC-DOCUMENTPART = LW_DMS_APP-DOCUMENTPART.

    LS_DOC-STATUSEXTERN = LW_DMS_APP-STATUSEXTERN.

    LS_DOC-LABORATORY = ' '.


    CONCATENATE WD_THIS->LW_REQ-BUKRS LS_DMS-REQ_NO LS_DMS-CR_YR INTO LW_OBJKEY SEPARATED BY '\'.

    LW_DRAD-OBJECTKEY = LW_OBJKEY.

    LW_DRAD-OBJECTTYPE = 'ZAPR_REQ'.

    APPEND LW_DRAD TO LT_DRAD.



    LW_DRAT-LANGUAGE = SY-LANGU.

    LW_DRAT-DESCRIPTION = LS_STRIPPEDNAME.

    APPEND LW_DRAT TO LT_DRAT.



    CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

    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.


    *--------Creating DMS Document Using BAPI-----------------*

    IF LS_RETURN-TYPE NA 'EA'.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'.



    LS_DRAW-DOKAR = LW_DMS_APP-DOCUMENTTYPE.

    LS_DRAW-DOKVR = LW_DMS_APP-DOCUMENTVERSION.

    LS_DRAW-DOKTL = LW_DMS_APP-DOCUMENTPART.

    LS_DRAW-DWNAM = SY-UNAME.

    LS_DRAW-DOKST = LW_DMS_APP-STATUSEXTERN.



    LV_STORAGE_CAT = LW_DMS_APP-STORAGECATEGORY.

    LS_API_CONTROL-TCODE = 'CV01N'.



    IF LF_DOCNUMBER IS NOT INITIAL.



    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

    BUFFER = LS_DMS_FILE-FILE_CTGRY

    IMPORTING

    OUTPUT_LENGTH = LV_SIZE

    TABLES

    BINARY_TAB = LT_BINDATA.



    LOOP AT LT_BINDATA INTO LS_BINDATA.

    CLEAR LS_DRAO.

    LS_DRAO-ORBLK = LS_BINDATA-LINE.

    LS_DRAO-ORLN = LV_SIZE.

    LS_DRAO-DOKAR = LS_DRAW-DOKAR.

    LS_DRAO-DOKNR = LF_DOCNUMBER.

    LS_DRAO-DOKVR = LS_DRAW-DOKVR.

    LS_DRAO-DOKTL = LS_DRAW-DOKTL.

    LS_DRAO-APPNR = '1'.

    APPEND LS_DRAO TO LT_DRAO.

    ENDLOOP.



    CALL FUNCTION 'CV120_DOC_GET_APPL'

    EXPORTING

    PF_FILE = LS_STRIPPEDNAME

    IMPORTING

    PFX_DAPPL = LS_FILES-DAPPL.



    LS_DRAW-FILEP = LS_STRIPPEDNAME.

    LS_DRAW-DAPPL = LS_FILES-DAPPL.



    LS_FILES-APPNR = '1'.

    LS_FILES-FILENAME = LS_STRIPPEDNAME.

    LS_FILES-UPDATEFLAG = 'I'.

    LS_FILES-LANGU = SY-LANGU.

    LS_FILES-STORAGE_CAT = LW_DMS_APP-STORAGECATEGORY. "'ZDMS_DI'.

    LS_FILES-DESCRIPTION = LS_STRIPPEDNAME.



    APPEND LS_FILES TO LT_FILES.
    *

    CALL FUNCTION 'CVAPI_DOC_CHECKIN'

    EXPORTING

    PF_DOKAR = LS_DRAW-DOKAR

    PF_DOKNR = LF_DOCNUMBER

    PF_DOKVR = LS_DRAW-DOKVR

    PF_DOKTL = LS_DRAW-DOKTL

    PS_API_CONTROL = LS_API_CONTROL

    PF_CONTENT_PROVIDE = 'TBL'

    IMPORTING

    PSX_MESSAGE = LS_MESSAGE

    TABLES

    PT_FILES_X = LT_FILES

    PT_CONTENT = LT_DRAO.

    IF NOT LS_MESSAGE-MSG_TYPE CA 'EA' AND

    LF_DOCNUMBER IS NOT INITIAL.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    ENDIF.

    Regards,

    Jack.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.