Skip to Content

Mass Upload DMS Originals and Set Status

Hello

Sometimes DIR have more than one origin LSMW is poor to upload more than one originals fllowing code upload orginals and set Status.

Excel Structure must :

Doc number Doc type Part Version Document Status Original format * Origin Description Path
0000000000060000000026926 ENG 000 00 NC PDF PDF file z:\new foldr\a.pdf
0000000000060000000026926 ENG 000 00 NC XLS native file z:\new foldr\a.xlsx
0000000000060000000026926 ENG 000 01 RW WRD native file z:\new foldr\b.docx
0000000000060000000026926 ENG 000 02 RW PDF PDF file z:\new foldr\b.pdf


* Original format : Must Capital and format must similar in customizing t.code:dc30 (for example word file in dc30 is WRD you must write WRD in this filed)


*&---------------------------------------------------------------------*
 *& Report  ZDMS_SET_ORIGINAL_STATUS
 *&
 *&---------------------------------------------------------------------*
 *&
 *&
 *&---------------------------------------------------------------------*
 REPORT  ZDMS_SET_ORIGINAL_STATUS.
 "CONSTANTS STORAGE_NAME TYPE CV_STORAGE_CAT VALUE 'DMS_C1_ST'.
 TYPES:
       BEGIN OF ST_DIR,
         DOKAR TYPE DOKAR,
         DOKNR TYPE DOKNR,
         DOKVR TYPE DOKVR,
         DOKTL TYPE DOKTL,
         DOKST TYPE DOKST,
         DOKTYPE TYPE CHAR3,
         ORGDES TYPE CHAR40,
         ORGPATH TYPE FILEP,
         VISITED TYPE CHAR1,
       END OF ST_DIR,
       BEGIN OF ST_ERROR_DOCS,
         DOKAR TYPE DOKAR,
         DOKNR TYPE DOKNR,
         DOKVR TYPE DOKVR,
         DOKTL TYPE DOKTL,
         ERRORMSG TYPE CHAR100,
       END OF ST_ERROR_DOCS.
 PARAMETERS BEG_ROW TYPE i DEFAULT 2.
 PARAMETERS END_ROW TYPE i DEFAULT 101.
 PARAMETERS FILEPATH LIKE RLGRAP-FILENAME DEFAULT 'c:\phase1.xlsx'.
 PARAMETERS STRGNAME TYPE CV_STORAGE_CAT DEFAULT 'PPL-PROJ'.
 DATA: it_documents TYPE TABLE OF st_dir,
       wa_documents TYPE st_dir.
 DATA: it_error_docs TYPE TABLE OF ST_ERROR_DOCS WITH HEADER LINE.
 *DATA it_file_content TYPE TABLE OF ALSMEX_TABLINE WITH HEADER LINE.
 *CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
 DATA it_file_content TYPE TABLE OF ZKCDE_CELLS WITH HEADER LINE.
 CALL FUNCTION 'ZKCD_EXCEL_OLE_TO_INT_CONVERT'
   EXPORTING
     FILENAME                      = FILEPATH
     I_BEGIN_COL                   = 1
     I_BEGIN_ROW                   = BEG_ROW
     I_END_COL                     = 8
     I_END_ROW                     = END_ROW
   TABLES
     INTERN                        = it_file_content
 * EXCEPTIONS
 *   INCONSISTENT_PARAMETERS       = 1
 *   UPLOAD_OLE                    = 2
 *   OTHERS                        = 3
           .
 IF SY-SUBRC <> 0.
 * Implement suitable error handling here
 ENDIF.
 DATA: current_row TYPE i VALUE 1,
       rowCount TYPE i.
 rowCount = LINES( it_file_content ).
 WHILE current_row <= rowCount.
   LOOP AT it_file_content FROM CURRENT_ROW TO CURRENT_ROW + 7.
     CASE it_file_content-COL.
       WHEN '1'.
         WA_DOCUMENTS-DOKNR = it_file_content-VALUE.
       WHEN '2'.
         WA_DOCUMENTS-DOKAR = it_file_content-VALUE.
       WHEN '3'.
         WA_DOCUMENTS-DOKTL = it_file_content-VALUE.
       WHEN '4'.
         WA_DOCUMENTS-DOKVR = it_file_content-VALUE.
       WHEN '5'.
         WA_DOCUMENTS-DOKST = it_file_content-VALUE.
       WHEN '6'.
         WA_DOCUMENTS-DOKTYPE = it_file_content-VALUE.
       WHEN '7'.
         WA_DOCUMENTS-ORGDES = it_file_content-VALUE.
       WHEN '8'.
         WA_DOCUMENTS-ORGPATH = it_file_content-VALUE.
     ENDCASE.
   ENDLOOP.
   APPEND WA_DOCUMENTS TO IT_DOCUMENTS.
   CLEAR WA_DOCUMENTS.
   current_row = current_row + 8.
 ENDWHILE.
 "Pepare error file
 REFRESH IT_ERROR_DOCS.
 IT_ERROR_DOCS-DOKAR = 'TYP'.
 IT_ERROR_DOCS-DOKNR = 'DOC NO'.
 IT_ERROR_DOCS-DOKTL = 'PRT'.
 IT_ERROR_DOCS-DOKVR = 'VR'.
 IT_ERROR_DOCS-ERRORMSG = 'Error Message'.
 APPEND IT_ERROR_DOCS.
 LOOP AT IT_DOCUMENTS INTO WA_DOCUMENTS.
   PERFORM ADD_ORG USING WA_DOCUMENTS.
 ENDLOOP.
 CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
 *   BIN_FILESIZE                    =
     FILENAME                        = 'D:\Error.xls'
     FILETYPE                        = 'DAT'
     APPEND                          = 'X'
 *   WRITE_FIELD_SEPARATOR           = ' '
 *   HEADER                          = '00'
 *   TRUNC_TRAILING_BLANKS           = ' '
 *   WRITE_LF                        = 'X'
 *   COL_SELECT                      = ' '
 *   COL_SELECT_MASK                 = ' '
 *   DAT_MODE                        = ' '
 *   CONFIRM_OVERWRITE               = ' '
 *   NO_AUTH_CHECK                   = ' '
 *   CODEPAGE                        = ' '
 *   IGNORE_CERR                     = ABAP_TRUE
 *   REPLACEMENT                     = '#'
 *   WRITE_BOM                       = ' '
 *   TRUNC_TRAILING_BLANKS_EOL       = 'X'
 *   WK1_N_FORMAT                    = ' '
 *   WK1_N_SIZE                      = ' '
 *   WK1_T_FORMAT                    = ' '
 *   WK1_T_SIZE                      = ' '
 *   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
 *   SHOW_TRANSFER_STATUS            = ABAP_TRUE
 * IMPORTING
 *   FILELENGTH                      =
   TABLES
     DATA_TAB                        = IT_ERROR_DOCS
 *   FIELDNAMES                      =
 * EXCEPTIONS
 *   FILE_WRITE_ERROR                = 1
 *   NO_BATCH                        = 2
 *   GUI_REFUSE_FILETRANSFER         = 3
 *   INVALID_TYPE                    = 4
 *   NO_AUTHORITY                    = 5
 *   UNKNOWN_ERROR                   = 6
 *   HEADER_NOT_ALLOWED              = 7
 *   SEPARATOR_NOT_ALLOWED           = 8
 *   FILESIZE_NOT_ALLOWED            = 9
 *   HEADER_TOO_LONG                 = 10
 *   DP_ERROR_CREATE                 = 11
 *   DP_ERROR_SEND                   = 12
 *   DP_ERROR_WRITE                  = 13
 *   UNKNOWN_DP_ERROR                = 14
 *   ACCESS_DENIED                   = 15
 *   DP_OUT_OF_MEMORY                = 16
 *   DISK_FULL                       = 17
 *   DP_TIMEOUT                      = 18
 *   FILE_NOT_FOUND                  = 19
 *   DATAPROVIDER_EXCEPTION          = 20
 *   CONTROL_FLUSH_ERROR             = 21
 *   OTHERS                          = 22
           .
 IF SY-SUBRC <> 0.
 * Implement suitable error handling here
 ENDIF.
 FORMAT COLOR COL_BACKGROUND INTENSIFIED.
 WRITE:/ 'Finished!!'.
 " Show errors in ALV
 DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
       GD_LAYOUT    TYPE SLIS_LAYOUT_ALV,
       GD_REPID     LIKE SY-REPID,
       G_VARIANT TYPE DISVARIANT
       .
 " Remove header row in excel file
 DELETE IT_ERROR_DOCS INDEX 1.
 PERFORM field_cat.
 GD_REPID = SY-REPID.
 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     I_CALLBACK_PROGRAM      = GD_REPID
 *   I_CALLBACK_TOP_OF_PAGE  = 'TOP-OF-PAGE' "see FORM
 *   I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
     IT_FIELDCAT             = FIELDCATALOG[]
     I_SAVE                  = 'X'
     IS_VARIANT              = G_VARIANT
   TABLES
     T_OUTTAB                = IT_ERROR_DOCS
   EXCEPTIONS
     PROGRAM_ERROR           = 1
     OTHERS                  = 2.
 *&---------------------------------------------------------------------*
 *&      Form  FIELD_CAT
 *&---------------------------------------------------------------------*
 *       text
 *----------------------------------------------------------------------*
 *  -->  p1        text
 *  <--  p2        text
 *----------------------------------------------------------------------*
 FORM FIELD_CAT .
   FIELDCATALOG-FIELDNAME   = 'DOKNR'.
   FIELDCATALOG-SELTEXT_M   = 'SAP Doc No.'.
   FIELDCATALOG-OUTPUTLEN = '27'.
   FIELDCATALOG-COL_POS     = 0.
   APPEND FIELDCATALOG TO FIELDCATALOG.
   CLEAR  FIELDCATALOG.
   FIELDCATALOG-FIELDNAME   = 'DOKVR'.
   FIELDCATALOG-SELTEXT_M   = 'Doc Version'.
   FIELDCATALOG-COL_POS     = 1.
   APPEND FIELDCATALOG TO FIELDCATALOG.
   CLEAR  FIELDCATALOG.
   FIELDCATALOG-FIELDNAME   = 'DOKAR'.
   FIELDCATALOG-SELTEXT_M   = 'Doc Cat.'.
   FIELDCATALOG-COL_POS     = 2.
   APPEND FIELDCATALOG TO FIELDCATALOG.
   CLEAR  FIELDCATALOG.
   FIELDCATALOG-FIELDNAME   = 'DOKTL'.
   FIELDCATALOG-SELTEXT_M   = 'Doc Part'.
   FIELDCATALOG-COL_POS     = 3.
   APPEND FIELDCATALOG TO FIELDCATALOG.
   CLEAR  FIELDCATALOG.
   FIELDCATALOG-FIELDNAME   = 'ERRORMSG'.
   FIELDCATALOG-SELTEXT_M   = 'Error Message'.
   FIELDCATALOG-OUTPUTLEN = '50'.
   FIELDCATALOG-COL_POS     = 4.
   APPEND FIELDCATALOG TO FIELDCATALOG.
   CLEAR  FIELDCATALOG.
 ENDFORM.                    " FIELD_CAT
 FORM ADD_ORG USING wa_documents TYPE st_dir.
   DATA: it_old_originals TYPE TABLE OF BAPI_DOC_FILES2 WITH HEADER LINE,
         wa_old_originals TYPE BAPI_DOC_FILES2,
         ret TYPE BAPIRET2,
         ls_doc    LIKE bapi_doc_draw2,
         ls_docx   LIKE bapi_doc_drawx2,
         wa_documents2 TYPE st_dir.
     IF WA_DOCUMENTS-VISITED = 'X'.
       RETURN.
     ENDIF.
   ls_doc-DOCUMENTNUMBER = wa_documents-doknr.
   ls_doc-DOCUMENTPART = wa_documents-doktl.
   ls_doc-DOCUMENTTYPE = wa_documents-dokar.
   ls_doc-DOCUMENTVERSION = wa_documents-dokvr.
 *  CALL FUNCTION 'BAPI_DOCUMENT_GETDETAIL2'
 *    EXPORTING
 *      DOCUMENTTYPE         = ls_doc-DOCUMENTTYPE
 *      DOCUMENTNUMBER       = ls_doc-DOCUMENTNUMBER
 *      DOCUMENTPART         = LS_DOC-DOCUMENTPART
 *      DOCUMENTVERSION      = ls_doc-DOCUMENTVERSION
 **     GETOBJECTLINKS       = ' '
 **     GETCOMPONENTS        = ' '
 **     GETSTATUSLOG         = ' '
 **     GETLONGTEXTS         = ' '
 *      GETACTIVEFILES       = 'X'
 *      GETDOCDESCRIPTIONS   = 'X'
 *      GETDOCFILES          = 'X'
 **     GETCLASSIFICATION    = ' '
 **     GETSTRUCTURE         = ' '
 **     GETWHEREUSED         = ' '
 **     HOSTNAME             = ' '
 *      INHERITED            = 'X'
 *    IMPORTING
 **     DOCUMENTDATA         =
 *      RETURN               = ret
 *    TABLES
 **     OBJECTLINKS          =
 **     DOCUMENTDESCRIPTIONS =
 **     LONGTEXTS            =
 **     STATUSLOG            =
 *      DOCUMENTFILES        = it_old_originals
 **     COMPONENTS           =
 **     CHARACTERISTICVALUES =
 **     CLASSALLOCATIONS     =
 **     DOCUMENTSTRUCTURE    =
 **     WHEREUSEDLIST        =
 *    .
 * REFRESH IT_OLD_ORIGINALS.
   LOOP AT IT_DOCUMENTS INTO WA_DOCUMENTS2
     WHERE DOKAR = WA_DOCUMENTS-DOKAR AND DOKNR = wa_documents-DOKNR AND DOKVR = wa_documents-DOKVR AND DOKTL = wa_documents-DOKTL.
     CLEAR IT_OLD_ORIGINALS.
     it_old_originals-DOCFILE = wa_documents2-ORGPATH.
     "it_old_originals-DOCPATH = 'C:\'.
     it_old_originals-STORAGECATEGORY = STRGNAME.
     it_old_originals-WSAPPLICATION = WA_DOCUMENTS2-DOKTYPE.
     it_old_originals-DESCRIPTION = WA_DOCUMENTS2-ORGDES.
     it_old_originals-ACTIVE_VERSION = 'X'.
     "WA_OLD_ORIGINALS-CHECKEDIN = 'X'.
     "WA_OLD_ORIGINALS-ORIGINALTYPE = '1'.
     it_old_originals-LANGUAGE = 'E'.
     APPEND it_old_originals TO IT_OLD_ORIGINALS.
 * Make document dirty
     WA_DOCUMENTS2-VISITED = 'X'.
     MODIFY IT_DOCUMENTS FROM WA_DOCUMENTS2.
   ENDLOOP.
   " Setting status of document
   ls_doc-STATUSEXTERN = WA_DOCUMENTS-DOKST.
   ls_docx-STATUSEXTERN = 'X'.
   CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'
     EXPORTING
       DOCUMENTTYPE         = ls_doc-DOCUMENTTYPE
       DOCUMENTNUMBER       = ls_doc-DOCUMENTNUMBER
       DOCUMENTPART         = LS_DOC-DOCUMENTPART
       DOCUMENTVERSION      = ls_doc-DOCUMENTVERSION
       DOCUMENTDATA         = LS_DOC
       DOCUMENTDATAX        = LS_DOCX
 *     HOSTNAME             =
 *     DOCBOMCHANGENUMBER   =
 *     DOCBOMVALIDFROM      =
 *     DOCBOMREVISIONLEVEL  =
 *     SENDCOMPLETEBOM      = ' '
 *     PF_FTP_DEST          = ' '
 *     PF_HTTP_DEST         = ' '
 *     CAD_MODE             = ' '
 *     ACCEPT_EMPTY_BOM     = ' '
     IMPORTING
       RETURN               = ret
     TABLES
 *     CHARACTERISTICVALUES =
 *     CLASSALLOCATIONS     =
 *     DOCUMENTDESCRIPTIONS =
 *     OBJECTLINKS          =
 *     DOCUMENTSTRUCTURE    =
       DOCUMENTFILES        = it_old_originals
 *     LONGTEXTS            =
 *     COMPONENTS           =
     .
   DATA msg TYPE char100.
     IF ret-type CA 'EA'.
       ROLLBACK WORK.
 *      MESSAGE ID '26' TYPE 'I' NUMBER '000'
 *              WITH ret-message.
       CONCATENATE 'ERROR: ' ret-MESSAGE ' :: ' INTO msg SEPARATED BY SPACE.
       WRITE:/ msg.
       CONCATENATE 'Document: ' ls_doc-DOCUMENTNUMBER ls_doc-DOCUMENTTYPE  ls_doc-DOCUMENTPART  ls_doc-DOCUMENTVERSION ' NOT Updated!.' INTO msg SEPARATED BY SPACE.
       WRITE:/ msg.
       MOVE-CORRESPONDING WA_DOCUMENTS TO IT_ERROR_DOCS.
       IT_ERROR_DOCS-ERRORMSG = ret-MESSAGE.
       APPEND IT_ERROR_DOCS.
     ELSE.
       COMMIT WORK.
       CONCATENATE 'Document: ' ls_doc-DOCUMENTNUMBER ls_doc-DOCUMENTTYPE ls_doc-DOCUMENTPART ls_doc-DOCUMENTVERSION ' Updated.' INTO msg SEPARATED BY SPACE.
       WRITE:/ msg.
     ENDIF.
 ENDFORM.
Be the first to leave a comment
You must be Logged on to comment or reply to a post.