Report for checkin all checked-out files in DMS
Tags:
Hi!
Sometimes it is necessary to check in all original files, especially before doing a data migration in DMS. To made this kind of total checkin process easier there is a special report. Please note that this is not an official SAP report and therefore it is also not supported and needs to be tested carefully first. Please feel free to test and if necessary adopt the report coding and so I hope that at the end we can have a real good working report which can be used by all of us.
*&---------------------------------------------------------------------*
*& Report Z_CHECKIN_REPORT *
*& *
*&---------------------------------------------------------------------*
*& This report reads a set of document info records and stored
*& all files, whic are currently not checked in, in a content server
*& or any other storage category
*&---------------------------------------------------------------------*
REPORT dms_check_in_files MESSAGE-ID 26.
INCLUDE: sbal_constants, <icon>.
TABLES: draw.
DATA: gt_draw TYPE TABLE OF draw.
DATA: gf_log_handle TYPE balloghndl,
lf_error(1) TYPE c.
**---------------------------------------------------------------------
**---------------------------------------------------------------------
* Parameter:
* s_dokar Selection via document type
* s_doknr Selection via document number
*
* p_log External Lognumber for application log
* p_svlog Save logfile
*
* p_scat Storage category
* p_ftp FTP-Destination for checkin (SAPFTP)
* p_http HTTP-Destination for checkin (SAPHTTP)
*
* p_test Testmode
**---------------------------------------------------------------------
*
* Selection-Texts
* ----------------
* P_FTP RFC-Destination FTP
* P_HTTP RFC-Destination HTTP
* P_LOG Ext. Lognummer
* P_SCAT Neue Ablagekategorie
* P_SVLOG Applikationslog sichern
* P_TEST Testmodus
* S_DOKAR Dokumentart
* S_DOKNR Dokument
*
*
SELECTION-SCREEN BEGIN OF BLOCK b10 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_dokar FOR draw-dokar MEMORY ID cv2,
s_doknr FOR draw-doknr MEMORY ID cv1.
SELECTION-SCREEN END OF BLOCK b10.
SELECTION-SCREEN BEGIN OF BLOCK b20 WITH FRAME TITLE text-002.
PARAMETERS: p_log TYPE bal_s_log-extnumber NO-DISPLAY,
p_svlog(1) TYPE c NO-DISPLAY.
*SELECTION-SCREEN SKIP 1.
PARAMETERS: p_scat TYPE draw-dttrg OBLIGATORY,
p_begr TYPE draw-begru.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_ftp TYPE rfcdest DEFAULT 'SAPFTP',
p_http TYPE rfcdest DEFAULT 'SAPHTTP'.
SELECTION-SCREEN END OF BLOCK b20.
PARAMETERS: p_test AS CHECKBOX DEFAULT 'X'.
**---------------------------------------------------------------------
* F4 for storage category
**---------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_scat.
PERFORM scat_show_list CHANGING p_scat.
**---------------------------------------------------------------------
* Start report
**---------------------------------------------------------------------
START-OF-SELECTION.
* PERFORM log_file_init
* USING p_log
* CHANGING gf_log_handle.
PERFORM doc_get_data.
PERFORM doc_checkin
TABLES gt_draw.
* PERFORM save_log.
* PERFORM show_log_file
* USING gf_log_handle.
*---------------------------------------------------------------------*
* FORM doc_get_data *
*---------------------------------------------------------------------*
* Get document data
*---------------------------------------------------------------------*
FORM doc_get_data.
DATA: lf_dummy(1) TYPE c.
**---------------------------------------------------------------------
REFRESH gt_draw.
SELECT * FROM draw INTO TABLE gt_draw
WHERE dokar IN s_dokar AND
doknr IN s_doknr.
IF sy-subrc <> 0.
MESSAGE s082 INTO lf_dummy.
PERFORM log_file_add_msg_sys.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM doc_checkin *
*---------------------------------------------------------------------*
* Checkin file into DMS
*---------------------------------------------------------------------*
* -> PT_DRAW Document data
*---------------------------------------------------------------------*
FORM doc_checkin TABLES pt_draw STRUCTURE draw.
DATA: lt_files TYPE TABLE OF cvapi_doc_file,
ls_files TYPE cvapi_doc_file.
DATA: ls_api_control TYPE cvapi_api_control,
ls_draw TYPE draw,
ls_drawx type draw,
ls_doc_key TYPE dms_doc_key,
ls_msg TYPE messages.
DATA: lf_dummy(256) TYPE c,
lf_txt(40) TYPE c.
FIELD-SYMBOLS: <fs> TYPE cvapi_doc_file.
** ---------------------------------------------------------------------
ls_api_control-check_level = '0'.
LOOP AT pt_draw INTO ls_draw.
MOVE-CORRESPONDING ls_draw TO ls_doc_key.
CALL FUNCTION 'CV115_DOCKEY_FORMAT'
EXPORTING: pf_no_gaps = 'X'
pf_dokar = ls_draw-dokar
pf_doknr = ls_draw-doknr
pf_dokvr = ls_draw-dokvr
pf_doktl = ls_draw-doktl
IMPORTING: pfx_doc_string = lf_txt.
* Get the actual data of the document
CALL FUNCTION 'CVAPI_DOC_GETDETAIL'
EXPORTING pf_dokar = ls_draw-dokar
pf_doknr = ls_draw-doknr
pf_dokvr = ls_draw-dokvr
pf_doktl = ls_draw-doktl
pf_active_files = 'X'
TABLES: pt_files = lt_files
EXCEPTIONS: not_found = 1
no_auth = 2
error = 3
OTHERS = 4.
IF sy-subrc <> 0.
PERFORM log_file_add_msg_sys.
CONTINUE.
ENDIF.
LOOP AT lt_files ASSIGNING <fs>.
IF <fs>-checked_in = 'X'.
DELETE lt_files.
ELSE.
IF <fs>-storage_cat IS INITIAL.
<fs>-storage_cat = p_scat.
ENDIF.
ENDIF.
ENDLOOP.
IF lt_files[] IS INITIAL.
CONTINUE.
ENDIF.
* Checkin the document
FORMAT RESET.
FORMAT COLOR COL_POSITIVE.
WRITE:/ 'Processing ', lf_txt.
CHECK p_test IS INITIAL.
CALL FUNCTION 'CVAPI_DOC_CHECKIN'
EXPORTING: pf_dokar = ls_draw-dokar
pf_doknr = ls_draw-doknr
pf_dokvr = ls_draw-dokvr
pf_doktl = ls_draw-doktl
pf_ftp_dest = p_ftp
pf_http_dest = p_http
ps_api_control = ls_api_control
IMPORTING: psx_message = ls_msg
TABLES: pt_files_x = lt_files.
IF ls_msg-msg_type CA 'EA'.
MESSAGE ID ls_msg-msg_id
TYPE ls_msg-msg_type
NUMBER ls_msg-msg_no
WITH ls_msg-msg_v1 ls_msg-msg_v2
ls_msg-msg_v3 ls_msg-msg_v4 INTO lf_dummy.
FORMAT RESET.
WRITE:/1 icon_failure AS ICON,
3 lf_dummy COLOR COL_NEGATIVE.
* PERFORM log_file_add_msg_sys.
ROLLBACK WORK.
ELSE.
* Set begru
IF NOT p_begr IS INITIAL.
ls_drawx-dokar = ls_draw-dokar.
ls_drawx-doknr = ls_draw-doknr.
ls_drawx-dokvr = ls_draw-dokvr.
ls_drawx-doktl = ls_draw-doktl.
ls_drawx-begru = p_begr.
CALL FUNCTION 'CV111_DRAW_SET'
EXPORTING: ps_draw = ls_drawx.
ENDIF.
COMMIT WORK. " AND WAIT.
ENDIF.
ULINE.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM scat_show_list *
*---------------------------------------------------------------------*
* Show list of available storage categories
*---------------------------------------------------------------------*
FORM scat_show_list CHANGING pfx_dttrg TYPE draw-dttrg.
CALL FUNCTION 'CV117_SCAT_SHOW_LIST'
EXPORTING: pf_stype = 'KPRO'
pf_show = 'X'
IMPORTING: pfx_scat = pfx_dttrg.
ENDFORM. "scat_show_list
*---------------------------------------------------------------------*
* FORM log_file_init *
*---------------------------------------------------------------------*
* Init the logfile for messages
*---------------------------------------------------------------------*
FORM log_file_init USING pf_log_title
CHANGING pfx_log_handle.
DATA: ls_log TYPE bal_s_log,
ls_msg TYPE bal_s_msg,
lf_dummy(1) TYPE c.
**----------------------------------------------------------------------
ls_log-extnumber = pf_log_title.
ls_log-object = 'CV'.
ls_log-subobject = 'API'.
ls_log-aluser = sy-uname.
ls_log-alprog = sy-repid.
* create a log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING: i_s_log = ls_log
IMPORTING: e_log_handle = pfx_log_handle
EXCEPTIONS: OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
ENDFORM. "log_file_init
*---------------------------------------------------------------------*
* FORM log_file_add_msg_sys *
*---------------------------------------------------------------------*
* add message form sy-xxx
*---------------------------------------------------------------------*
FORM log_file_add_msg_sys.
DATA: ls_msg TYPE bal_s_msg.
CLEAR ls_msg.
ls_msg-msgty = sy-msgty.
ls_msg-msgid = sy-msgid.
ls_msg-msgno = sy-msgno.
ls_msg-msgv1 = sy-msgv1.
ls_msg-msgv2 = sy-msgv2.
ls_msg-msgv3 = sy-msgv3.
ls_msg-msgv4 = sy-msgv4.
PERFORM log_file_add_msg
USING ls_msg.
ENDFORM. "log_file_add_msg_sys
*---------------------------------------------------------------------*
* FORM log_file_add_bapi_msg
*---------------------------------------------------------------------*
* add message from BAPIRET2
*---------------------------------------------------------------------*
FORM log_file_add_bapi_msg USING ps_msg TYPE bapiret2.
DATA: ls_msg TYPE bal_s_msg.
CLEAR ls_msg.
ls_msg-msgty = ps_msg-type.
ls_msg-msgid = ps_msg-id.
ls_msg-msgno = ps_msg-number.
ls_msg-msgv1 = ps_msg-message_v1.
ls_msg-msgv2 = ps_msg-message_v2.
ls_msg-msgv3 = ps_msg-message_v3.
ls_msg-msgv4 = ps_msg-message_v4.
PERFORM log_file_add_msg
USING ls_msg.
ENDFORM. "log_file_add_msg_sys
*---------------------------------------------------------------------*
* FORM log_file_add_msg *
*---------------------------------------------------------------------*
* Add message to the log
*---------------------------------------------------------------------*
FORM log_file_add_msg USING ps_msg TYPE bal_s_msg.
CHECK NOT gf_log_handle IS INITIAL.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING: i_log_handle = gf_log_handle
i_s_msg = ps_msg
EXCEPTIONS: log_not_found = 0
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. "log_file_add_msg
*---------------------------------------------------------------------*
* FORM show_log *
*---------------------------------------------------------------------*
* Show the log
*---------------------------------------------------------------------*
FORM show_log_file USING pf_loghandle.
DATA: ls_dis_prof TYPE bal_s_prof,
ls_mess_fcat TYPE bal_s_fcat,
lt_log_header TYPE balhdr_t.
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
* Define display-profile
* ----------------------------------------------------------------------
CALL FUNCTION 'BAL_DSP_PROFILE_STANDARD_GET'
IMPORTING: e_s_display_profile = ls_dis_prof.
* Use a grid
ls_dis_prof-use_grid = 'X'.
ls_dis_prof-show_all = 'X'.
ls_dis_prof-exp_level = 1.
* ----------------------------------------------------------------------
* Display log
* ----------------------------------------------------------------------
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING: i_s_display_profile = ls_dis_prof
EXCEPTIONS: profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "show_log_file
*---------------------------------------------------------------------*
* FORM save_log *
*---------------------------------------------------------------------*
* Save logfile
*---------------------------------------------------------------------*
FORM save_log.
IF p_svlog = 'X'.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING: i_in_update_task = ''
i_save_all = 'X'
EXCEPTIONS: log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDFORM. "save_log