Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

CFX_API_DOC_DOCUMENT_WRITE

Hello All,

Please teach me Use of 'CFX_API_DOC_DOCUMENT_WRITE' .

I want to make the program which uploads a local file.

However, how to use 'CFX_API_DOC_DOCUMENT_WRITE' is not known.

What should be set to IT_CONTENT?

Regards,

Yuji

REPORT  ZCFX_FOLDER_CLEATE.

DATA: l_fol_name             TYPE string.
DATA: l_fol_desc             TYPE string.
DATA: l_file_name            TYPE string.
DATA: l_file_desc            TYPE string.
DATA: l_file_path            LIKE RLGRAP-FILENAME.
DATA: l_file_path_x          TYPE string.
DATA: l_file_size            TYPE I.
DATA: l_file_size_x          TYPE string.
DATA: l_file_URL             TYPE string.

DATA: ls_fault               TYPE cfx_api_ts_fault.
DATA: l_faultstring          TYPE cfx_api_t_faultstring.
DATA: l_fol_id               TYPE guid_32.
DATA: l_file_id              TYPE guid_32.

DATA: l_public_area_id       TYPE guid_32.
DATA: l_new_fol_id           TYPE guid_32.

DATA: l_subfolder1_id        TYPE guid_32.
DATA: l_subfolder2_id        TYPE guid_32.
DATA: l_hyperlink_id         TYPE guid_32.

DATA: begin of itab occurs 0,

       raw type SDOKCNTBINS,

end of itab.
*DATA: begin of ltab occurs 0,
*
*       SDOKCNTBINS,
*
*end of ltab.

DATA: lt_table               TYPE TABLE OF SDOKCNTBINS.


SELECTION-SCREEN BEGIN OF BLOCK a.
PARAMETERS: parfolid        TYPE text100.
PARAMETERS: folname         TYPE text100.
PARAMETERS: foldesc         TYPE text100.
PARAMETERS: filename        TYPE text100.
PARAMETERS: filedesc        TYPE text100.
PARAMETERS: filepath        TYPE text100.


SELECTION-SCREEN END OF BLOCK a.

START-OF-SELECTION.

*STEP1: FOLDER CREATE

* Input from UI
  IF  parfolid is not initial.

    l_fol_id   = parfolid.
    l_fol_name = folname.
    l_fol_desc = foldesc.
    WRITE: / 'Create fileder with name "', l_fol_name, '"'.

    CALL FUNCTION 'CFX_API_FOLDER_CREATE'
      EXPORTING
        I_PARENT_FOLDER_ID         = l_fol_id
        I_NAME                     = l_fol_name
        I_DESCRIPTION              = l_fol_desc
*       I_CATEGORY_ID              =
*       I_CATEGORY_NAMESPACE       =
     IMPORTING
       ES_FAULT                   =  ls_fault
       E_FAULTSTRING              =  l_faultstring
       E_FOLDER_ID                =  l_new_fol_id
                                                .

    IF ls_fault IS INITIAL.
      WRITE: / 'New Folder created, id = ', l_new_fol_id.
    ELSE.
      WRITE: / 'Error detected!'.
      WRITE: / 'Faultstring: ', l_faultstring.
      EXIT.
    ENDIF.

 ENDIF.


*STEP2: FILE CREATE

  IF  filename is not initial.
    l_file_name = filename.
    l_file_desc = filedesc.

    CALL FUNCTION 'CFX_API_DOC_CREATE'
      EXPORTING
        I_PARENT_FOLDER_ID         = l_new_fol_id
*       I_TYPE_ID                  =
*       I_TYPE_NAMESPACE           =
*       I_CATEGORY_ID              =
*       I_CATEGORY_NAMESPACE       =
        I_NAME                     = l_file_name
        I_DESCRIPTION              = l_file_desc
*       I_MASTER                   = CFXA0_SC_TRUE
*       I_BACKEND_SYSTEM           =
        I_DOC_TYPE                 = 'doc'
     IMPORTING
        ES_FAULT                   = ls_fault
        E_FAULTSTRING              = l_faultstring
        E_DOC_ID                   = l_file_id
        .

  IF ls_fault IS INITIAL.
      WRITE: / 'New File created, id = ', l_file_id.
    ELSE.
      WRITE: / 'Error detected!'.
      WRITE: / 'Faultstring: ', l_faultstring.
      EXIT.
    ENDIF.

  ENDIF.

*STEP3: FILE UPLOAD
  IF  filepath is not initial.
    l_file_path  = filepath.
    l_file_path_x  = filepath.
*    l_file_size = 68608.
*
    CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            codepage            = 'IBM'
            filename            = l_file_path
            filetype            = 'BIN'
       IMPORTING
            filelength          = l_file_size
       TABLES
            data_tab            = itab
       EXCEPTIONS
            conversion_error    = 1
            file_open_error     = 2
            file_read_error     = 3
            invalid_table_width = 4
            invalid_type        = 5.

*
      IF sy-subrc NE 0.
*        MESSAGE e888(sabapdocu) WITH text-001.
         WRITE: / 'Error Uploaded! =',sy-subrc.

      ELSE.

        l_file_size_x  =  l_file_size.
*        MOVE itab to lt_table.
*       OPEN DATASET l_file_path_x IN BINARY MODE.
*       READ DATASET l_file_path_x INTO lt_table[l_file_size].
*       CLOSE DATASET l_file_path_x.

        CALL FUNCTION 'CFX_API_DOC_DOCUMENT_WRITE'
          EXPORTING
            I_DOC_ID                   = l_file_id
*       I_VERSION_NAME                 =
*       I_VERSION_DESCRIPTION          =
*       I_CHANGE_CURRENT_VERSION       = CFXA0_SC_FALSE
*       I_BACKEND_SYSTEM               =
            I_FILE_PATH                = l_file_path_x
            I_FILE_SIZE                = l_file_size_x
*       I_MIME_TYPE                    =
*       I_CONTENT_URL                  = l_file_URL
*       I_CONTENT_PROXY                =
*       I_CONTENT_PROXYPORT            =
          IMPORTING
            ES_FAULT                   = ls_fault
            E_FAULTSTRING              = l_faultstring
*       E_DOC_VERSION_ID               =
*       E_VERSION_NAME                 =
*        E_CONTENT_RELATIVE_URL         =
          TABLES
            IT_CONTENT                 = itab.

        IF ls_fault IS INITIAL.
          WRITE: / 'New File Uploaded, SIZE = ', l_file_size.
        ELSE.
          WRITE: / 'Error Uploaded!'.
          WRITE: / 'Faultstring: ', l_faultstring.
          EXIT.
        ENDIF.

    ENDIF.
  ENDIF.

* done - successfull
  WRITE: / 'Everything OK!'.

Not what you were looking for? View more on this topic or Ask a question