Salut mon amis !!

I recently struggled to add an original to an existing DIR in a custom program . After a lot of debugging I finall got through it.

Here is the sample code to achieve it . Hope it helps someone struggling on the same.

API Interface :

IV_FILE_CONTENT TYPE /PRD1/S_DIR_ATTACH-FILE_CONTENT

IV_FILE_NAME TYPE /PLMB/FILEP

IV_FILE_SIZE TYPE /PRD1/S_DIR_ATTACH-FILE_SIZE

IV_DIR_DESC TYPE DKTXT

IV_FILE_STOR_CATEG TYPE SDOK_STCAT

IS_DIR_KEY TYPE /PLMB/S_DIR_ID

ET_MESSAGE TYPE /PLMB/T_SPI_MSG

EV_SEVERITY TYPE /PLMB/SPI_MSG_SEVERITY


API code :


**********Data Declaration ******************

*

  TYPES: BEGIN OF lty_binary,

             line(2550) TYPE x,

           END OF lty_binary.

  “”” DIR API related data declaration

  CONSTANTS : lc_pf_orig_cont_prov TYPE mcdok-content_provide VALUE ‘TBL’ ,

        lc_api_tcode         TYPE cvapi_api_control-tcode  VALUE ‘CV02’.

  DATA :    lv_fname_wo_path  TYPE /plmb/filep ,

            lv_error          TYPE c ,

            lv_size           TYPE int4.

*****  DIR API related Data declaration

  DATA : lt_orig_content  TYPE TABLE OF drao ,

         lt_binary        TYPE TABLE OF lty_binary ,

         lt_orig_appl     TYPE          /plmb/t_dir_orig_crt ,

         lt_kpro_data     TYPE          dms_tbl_file ,

         lt_kpro_data_new TYPE          dms_tbl_file ,

         lt_files_x       TYPE TABLE OF cvapi_doc_file,

         lt_comp_x        TYPE TABLE OF cvapi_doc_comp,

         lt_draz          TYPE TABLE OF draz,

         lt_drao          TYPE TABLE OF drao,

         lt_draoz         TYPE TABLE OF draoz,

         lt_toav0         TYPE TABLE OF toav0 ,

         lt_dms_tbl_phio   TYPE dms_tbl_phio.

  DATA  : ls_draw           TYPE draw ,

          ls_api_ctrl       TYPE cvapi_api_control ,

          ls_orig_content   LIKE LINE OF lt_orig_content ,

          ls_orig_appl      LIKE LINE OF lt_orig_appl  ,

          ls_dms_rec_file   TYPE dms_rec_file ,

          ls_dir_key        TYPE dms_doc_key,

          ls_dms_tbl_phio   LIKE LINE OF lt_dms_tbl_phio ,

          ls_sdok_obj       TYPE sdokobject,

          ls_mssgs          TYPE messages ,

          ls_kpro_data      LIKE LINE OF lt_kpro_data,

          ls_files_x        LIKE LINE OF lt_files_x,

          ls_drao           LIKE LINE OF lt_drao ,

          ls_draw_form      TYPE draw ,

          ls_audits         TYPE dms_audits.

  FIELD-SYMBOLS :  <fs_binary> TYPE lty_binary.

  “”get file name from File path

  go_dir_bo->split_file_path(

    EXPORTING

      iv_docfile      =   iv_file_name   ” DIR: Original

    IMPORTING

*    ev_docpath      =     ” DIR: Original

      ev_docfile      =  lv_fname_wo_path     ” Original of document

      et_message       =  et_message  ” Message

      ev_msg_severity  =  ev_severity    ” Severity

  ).

  IF ev_severity CA /plmb/if_spi_c=>gs_c_severity_category-error_or_worse.

    RETURN .

  ENDIF.

****  Get appl from file extension

  go_dir_bo->get_ws_appl(

    EXPORTING

      iv_path          = lv_fname_wo_path     ” Original of document

*      iv_host          =     ” Data carrier type

    IMPORTING

      et_appl_original =  lt_orig_appl  ” Workstation Applications

      et_message       =  et_message  ” Message

      ev_msg_severity  =  ev_severity    ” Severity

  ).

  IF ev_severity CA /plmb/if_spi_c=>gs_c_severity_category-error_or_worse.

    RETURN .

  ENDIF.

  READ TABLE lt_orig_appl INTO ls_orig_appl INDEX 1 .

  “””” Get the PDF content which is to be checked in Original to DIR

  CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’

    EXPORTING

      buffer        = iv_file_content “lv_pdfsource

    IMPORTING

      output_length = lv_size

    TABLES

      binary_tab    = lt_binary

    EXCEPTIONS

      error_message = 1

      OTHERS        = 2.

  IF sy-subrc <> 0.

* Implement suitable error handling here

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    CLEAR: gs_message , gv_message.

    MESSAGE e138(zep_plm_ecr) INTO gv_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

    RETURN .

  ENDIF.

  LOOP AT lt_binary ASSIGNING <fs_binary>.

    CLEAR ls_orig_content.

    ls_orig_content-orblk = <fs_binary>-line.

    ls_orig_content-orln  = lv_size.

    APPEND ls_orig_content TO lt_orig_content.

  ENDLOOP.

  “”” ====================call the api to add orig to DIR=========================

  ls_draw-dokar    = is_dir_key-documenttype .

  ls_draw-doknr    = is_dir_key-documentnumber .

  ls_draw-doktl    = is_dir_key-documentpart .

  ls_draw-dokvr    = is_dir_key-documentversion .

**************************************************************

**************************************************************

**  Initialized DOKAR settings to be used in API’s further specially for doc checkin

  PERFORM cust_read_data IN PROGRAM saplcvapi01

         USING ls_draw-dokar .

  IF sy-subrc NE 0 .

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

*

  ls_dms_rec_file-dappl   =  ls_orig_appl-wsapplication .

  ls_dms_rec_file-updateflag = ‘I’ .

  ls_dms_tbl_phio-langu   =  sy-langu.

  ls_dms_tbl_phio-active_version  = ‘X’.

  ls_dms_tbl_phio-delete_flag    = ‘X’.

  ls_dms_tbl_phio-default_langu  = ‘X’.

  ls_dms_tbl_phio-storage_cat = iv_file_stor_categ.

  ls_dms_tbl_phio-check_in  = ‘X’.

*  ls_dms_tbl_phio-content_desc = iv_dir_desc .

  ls_dms_tbl_phio-filename = lv_fname_wo_path   .

  APPEND ls_dms_tbl_phio TO lt_dms_tbl_phio.

  ls_dms_rec_file-tbl_phios =  lt_dms_tbl_phio                         .

  CALL FUNCTION ‘CV120_KPRO_MASTER_CREATE’

* EXPORTING

*   PF_IGNORE_DUPLICATE_PHIO       = ‘ ‘

    CHANGING

      ps_data                        = ls_dms_rec_file

   EXCEPTIONS

     error                          = 1

     OTHERS                         = 2

            .

  IF sy-subrc <> 0.

* Implement suitable error handling here

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

  READ TABLE ls_dms_rec_file-tbl_phios INTO ls_dms_tbl_phio INDEX 1 .

  ls_sdok_obj-class = ls_dms_tbl_phio-ph_class .

  ls_sdok_obj-objid = ls_dms_tbl_phio-ph_objid .

  ls_files_x-updateflag   = abap_true .

  ls_files_x-dappl  = ls_orig_appl-wsapplication .

  ls_files_x-storage_cat  = iv_file_stor_categ.

  ls_files_x-filename  =  lv_fname_wo_path.

  ls_files_x-checked_in  = abap_true .

  ls_files_x-description = iv_dir_desc.

  APPEND ls_files_x TO lt_files_x.

  APPEND ls_dms_rec_file TO lt_kpro_data .

  SELECT SINGLE * FROM draw INTO ls_draw_form WHERE

  dokar                  = ls_draw-dokar

  AND doknr                  = ls_draw-doknr

  AND dokvr                  = ls_draw-dokvr

  AND doktl                  = ls_draw-doktl.

  PERFORM doc_checkin  IN PROGRAM saplcvapi01

      TABLES lt_kpro_data

            lt_kpro_data_new

            lt_files_x

                       lt_comp_x

                        lt_draz

                        lt_orig_content

                        lt_draoz

                        lt_toav0

                 USING  ”

                        ”

                        ”

                        ”

                        lc_pf_orig_cont_prov

                 CHANGING ls_draw_form

                          ls_audits

                          lv_error.

  IF sy-subrc NE 0 .

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

  MOVE-CORRESPONDING ls_draw_form TO ls_dir_key.

  CALL FUNCTION ‘CV111_DRAW_SAVE’

    EXPORTING

      pf_tacode          = lc_api_tcode

      ps_draw_new        = ls_draw_form

     ps_draw_old        = ls_draw_form

*   PS_AUDITS          =

* TABLES

*   PT_DRAO            =

*   PT_ARCH_CONN       =

   EXCEPTIONS

     error              = 1

     OTHERS             = 2

            .

  IF sy-subrc <> 0.

* Implement suitable error handling here

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

****Get old kpro master data  or existing originals

  CLEAR : lt_kpro_data .

  CALL FUNCTION ‘CV120_KPRO_MASTER_DATA_GET’

    EXPORTING

      pf_dokar            = ls_draw-dokar

      pf_doknr            = ls_draw-doknr

      pf_dokvr            = ls_draw-dokvr

      pf_doktl            = ls_draw-doktl

      pf_active_only      = abap_true

*     PF_ACTIVE_ATTR_ONLY = ‘ ‘

*     PF_COMP_GET         = ‘X’

    TABLES

      ptx_data            = lt_kpro_data

    EXCEPTIONS

      not_found           = 1

      error               = 2

      OTHERS              = 3.

  IF sy-subrc <> 0.

* Implement suitable error handling here

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

  APPEND LINES OF lt_kpro_data TO lt_kpro_data_new .

**************Call kpro save

  CALL FUNCTION ‘CV111_KPRO_SAVE’

    EXPORTING

*     PF_CLEAR_ALL =

      ps_doc_key   = ls_dir_key

    TABLES

      pt_data      = lt_kpro_data_new

*     PT_DATA_OLD  = lt_kpro_data

    EXCEPTIONS

      error        = 1

      OTHERS       = 2.

  IF sy-subrc <> 0.

* Implement suitable error handling here

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

  “”Update DB

  CALL FUNCTION ‘CV111_DOC_SAVE’

    EXPORTING

*     PF_COMMIT      = ‘ ‘

      pf_update_task = ‘X’

*     PF_API_FLAG    = ‘ ‘

    EXCEPTIONS

      error          = 1

      OTHERS         = 2.

  IF sy-subrc <> 0.

* Implement suitable error handling here

***  return add error message

    CLEAR gs_message .

    MOVE-CORRESPONDING sy TO gs_message .

    APPEND gs_message TO et_message .

    “”update severity

    ev_severity = sy-msgty.

  ENDIF.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply