Skip to Content
Technical Articles

Mass download of documents from SOLAR01 by using custom ABAP Report.

In some cases, When we do a  fresh installation of solution manager 7.2, need to download all documents which exist in the older solution manager system. The probability is very high that thousand’s of documents are stored in SOLAR01 transaction.

To mass download all these documents manually is difficult and could be missed. To avoid such issues this ABAP custom report will perform a mass download of documents from SOLAR01 for a project, if knowledge workbench is not an alternate option.

*&———————————————————————*
*& Report  Z_MASS_DOWNLOAD_SOLAR01
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  Z_MASS_DOWNLOAD_SOLAR01.
type-POOLs: spro.
TYPE-POOLS tcdat.
TYPES: BEGIN OF st_SACONT01,
PHIO_ID LIKE SACONT01-PHIO_ID,
CLUSTD like SACONT01-CLUSTD,
SRTF2 LIKE SACONT01-SRTF2,
END OF ST_SACONT01.
data: lv_project_id type tproject-project_id,
lv_filter TYPE TTREE-ID,
ls_message type HIER_MESS,
lt_nodes_all type TABLE OF HIER_IFACE,
ls_nodes_all TYPE HIER_IFACE,
lt_texts TYPE TABLE OF HIER_TEXTS,
ls_texts TYPE HIER_TEXTS,
node_ids TYPE spro_notes_tab,
ls_node_ids TYPE spro_notes_struc,
ls_id type ISTATIFACE-ID,
lt_SA01PHIO TYPE TABLE OF SA01PHIO,
ls_SA01PHIO TYPE SA01PHIO,
lt_SACONT01 TYPE TABLE OF ST_SACONT01,
ls_SACONT01 TYPE ST_SACONT01.
DATA: docu_tab TYPE REF TO cl_sa_tab_docu,
lv_count type i,
lv_total_count TYPE i.
data: lv_CLUSTD type INDX_CLUST.
DATA fcode TYPE  syucomm.
DATA tabtype TYPE sa_tabtype.
DATA strucname TYPE string.
DATA: lt_attach_bin       TYPE solix_tab.
data: gt_data TYPE TABLE OF xstring WITH HEADER LINE.
data: lv_filename TYPE string.
FIELD-SYMBOLS: <picked_line> TYPE ANY,
<all_items> TYPE table,
<marked_items> TYPE table.
DATA ref TYPE REF TO data.
DATA reftab TYPE REF TO data.
DATA reftab1 TYPE REF TO data.
DATA cursor_field TYPE dfies-fieldname.
TYPES: BEGIN OF tc_handler1,
tc_repid TYPE syrepid,
tc_subnr TYPE sydynnr,  ” TC subscreen
handle TYPE tcdat_tab_handle ,
tabname TYPE sa_tabtype,
END OF tc_handler1.
DATA tc_handle TYPE tc_handler1.
DATA:MANDT type SY-MANDT,
STOR_CAT type  SDOKSTCA-STOR_CAT,
CREP_ID(30) TYPE  C,
DOC_ID(32) TYPE  C,
ACCESS_INFO TYPE TABLE OF SCMS_ACINF,
ls_ACCESS_INFO TYPE SCMS_ACINF,
CONTENT_TXT TYPE TABLE OF SDOKCNTASC,
CONTENT_BIN TYPE TABLE OF SDOKCNTBIN,
ls_content_bin type SDOKCNTBIN,
CREA_TIME TYPE  T,
CHNG_TIM TYPE  T,
DOC_PROT(10) TYPE  C,
stor_rep  type  sdokstca-stor_rep,
PHIO_ID TYPE  SDOK_PHID.

DATA: ls_file_path type string.
DATA: lt_file_path TYPE TABLE OF DFIES.

 

* Inputs to the report is Project ID and path to store downloaded documents.


selection-screen begin of line.
PARAMETERS:R_S RADIOBUTTON GROUP G1.
SELECTION-SCREEN COMMENT 4(15) text-001.
selection-screen position 20.
PARAMETERS:p_projid type tproject-project_id.
selection-screen end of line.

PARAMETERS: p_path TYPE string OBLIGATORY.

AT SELECTION-SCREEN on VALUE-REQUEST FOR p_path.

CALL METHOD cl_gui_frontend_services=>directory_browse
CHANGING
selected_folder      = p_path.

START-OF-SELECTION.
lv_project_id = p_projid.

 

* To get project hierarchy call the below function modules by giving input as project ID.

 

CALL FUNCTION ‘SPROJECT_GET_REAL_OF_PROJ’
EXPORTING
project_id         = lv_project_id
IMPORTING
realization_filter = lv_filter.
CALL FUNCTION ‘SASAP_HIERARCHY_READ’
EXPORTING
structure_id          = lv_filter
read_texts            = ‘X’
read_references       = ”
language              = sy-langu
include_substructures = ‘X’
text_of_references    = ‘X’
IMPORTING
message               = ls_message
TABLES
list_of_nodes         = lt_nodes_all
list_of_texts         = lt_texts.

loop at lt_nodes_all INTO ls_nodes_all.

* Call the below function module to get the logical Document ID.


    CALL FUNCTION ‘NOTE_OBJECT_GET’
EXPORTING
FILTERTREE  = ls_nodes_all-TREE_ID
APPLICATION = ‘CU’
NODE        = ls_nodes_all
IMPORTING
ID          = ls_id
TABLES
NOTE_IDS    = node_ids.
if node_ids is not INITIAL.
delete ADJACENT DUPLICATES FROM node_ids.
loop at node_ids INTO ls_node_ids.

* We can get the Physical Document ID from Logical Document ID by using table SA01PHIO


        SELECT * from SA01PHIO INTO table lt_SA01PHIO where LOIO_ID = ls_node_ids-docu_id.
loop at lt_SA01PHIO INTO ls_SA01PHIO.
stor_rep = ‘SOLARCONTENTDB’.
mandt = ‘100’.
doc_id = ls_SA01PHIO-PHIO_ID.
phio_id = ls_SA01PHIO-PHIO_ID.

* Call the below function module to get the binary content of the document based on Physical Document ID.
          call function ‘SCMS_R3DB_IMPORT’
exporting
mandt        = mandt
crep_id      = stor_rep
doc_id       = doc_id
phio_id      = phio_id
importing
doc_prot     = doc_prot
*    crea_time    = crea_time
*    chng_time    = chng_tim
tables
content_info = access_info
content_txt  = content_txt
content_bin  = content_bin
exceptions
error_import = 1
error_config = 2
others       = 3.

loop at ACCESS_INFO INTO ls_ACCESS_INFO.
CONCATENATE ls_access_info-CHNG_TIME ls_access_info-COMP_ID INTO lv_filename SEPARATED BY ‘_’.
CONCATENATE p_path lv_filename INTO lv_filename SEPARATED BY ‘_.
endloop.

* Use the below method to download actual document based on the binary content of document.


          call method cl_gui_frontend_services=>gui_download
exporting
*      bin_filesize            = input_length
filename                = lv_filename
filetype                = ‘BIN’
changing
data_tab                = content_bin
exceptions
file_write_error        = 1
no_batch                = 2.
endloop.
endloop.
endif.
ENDLOOP.

 

 

Input: Provide the project ID and path details to download files and execute the report.

 

 

Output: Files will be stored in the given location.

Note: If project contained different versions of documents, all version of documents will be downloaded.

3 Comments
You must be Logged on to comment or reply to a post.
  • In the blog editor, there’s a button like {;} that you can use to post ABAP code in a nicely formatted way.

    WRITE: / 'Like this'.

    Mixture of prefixed/non-prefixed variables. l for local when all are global. Not exactly best of breed coding.

  • You are talking about the migration from one Solution Manager version to another one, so I understand that your program will mass download all the documents, but how to do the mass upload?