Насколько мне известно, SolDoc не позволяет массово изменять документы. Однако, существует API, представляющее собой oData сервис, которое позволяет производить данные операции.
API предоставляет возможность использовать все основные операции(чтение, изменение, вставка и т.д. ).
Более подробно можно почитать на оф сайте:
API
Описание формата обмена
Также есть ссылки на два блога, которые работают с данным API на Python. Это не всем подходит, т.к. не всегда возможно запускать скрипты в сетях с продуктивной системой. Если у вас такой проблемы нет, можете использовать решения представленные в данных блогах, это будет даже удобнее.
https://blogs.sap.com/2020/05/04/mass-updating-solution-documentation-via-the-process-management-api/
https://blogs.sap.com/2020/02/28/process-management-api-in-sap-solution-manager/
Предлагаю реализовать тоже самое на ABAP.
Исходные данные
Есть название решения и ветки. Необходимо изменить все статусы вложенных документов определенного типа.
Описание решения
oData сервисы можно вызывать из ABAP при помощи класса /iwfnd/cl_sutil_client_proxy
Первым делом надо получить ID решения и ветки. Делается это при помощи GET запроса с URL следующих видов:
URL Для поиска решения:
1 |
/sap/opu/odata/sap/ProcessManagement/SolutionSet?$format=json |
URL для поиска ветки:
1 |
/sap/opu/odata/sap/ProcessManagement/BranchSet?$format=json |
Далее получаем содержимое ветки.
URL (GET):
1 |
/sap/opu/odata/sap/ProcessManagement/BranchContentSet(BranchId='{ iv_branch_id }',ScopeId='',SiteId='',SystemRole='')/$value |
Сам JSON в ответе довольно странный, содержимое узла section-content это json в виде строки, поэтому перед парсингом при помощи abap надо убрать часть символов из строки(ниже в коде это будет сделано при помощи REPLACE).
Для изменения статуса заменяем старый статус у нужных документов в узле "section-id": "NODES".
После изменений отправляем измененный JSON обратно в таком же формате, как и при получении.
Выполняем PUT запрос вида
1 |
/sap/opu/odata/sap/ProcessManagement/BranchContentImporterSet(BranchId='{ iv_branch_id }',ChangeDocumentId='{ iv_change_doc_id }')/$value |
В header обязательно надо подать токен.
Токена получаем GET запросом
1 |
/sap/opu/odata/sap/ProcessManagement |
В Header запроса передаем 'X-CSRF-Token' : 'Fetch'.
Результат в Soldoc:
Полная реализация:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
REPORT ztest_pau. CLASS lcl_solution_work_api DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING iv_sol TYPE string iv_branch TYPE string iv_doct TYPE string iv_stat TYPE string, get_branch_id IMPORTING iv_branch_name TYPE string iv_solution_id TYPE string RETURNING VALUE(rv_branch_id) TYPE string RAISING zcx_sb_sm, get_solution_by_name IMPORTING iv_solution_name TYPE string RETURNING VALUE(rv_solution_id) TYPE string RAISING zcx_sb_sm, change_document IMPORTING iv_branch_id TYPE string iv_change_doc_id TYPE string iv_request_body TYPE string iv_token TYPE string RAISING zcx_sb_sm, change_stat RAISING zcx_sb_sm. PRIVATE SECTION. TYPES: BEGIN OF lty_s_solution, solutionid TYPE string, solutionname TYPE string, solutiontitle TYPE string, END OF lty_s_solution, lty_t_solution TYPE TABLE OF lty_s_solution WITH DEFAULT KEY, BEGIN OF lty_s_results, results TYPE lty_t_solution, END OF lty_s_results, BEGIN OF lty_s_d, d TYPE lty_s_results, END OF lty_s_d. *-------------------- TYPES: BEGIN OF lty_s_branch, branchid TYPE string, branchname TYPE string, branchtitle TYPE string, parentbranchid TYPE string, solutionid TYPE string, branchtype TYPE string, ischangectrlenabled TYPE string, isdata_exchangeenabled TYPE string, END OF lty_s_branch, lty_t_branch TYPE TABLE OF lty_s_branch WITH DEFAULT KEY, BEGIN OF lty_s_results_branch, results TYPE lty_t_branch, END OF lty_s_results_branch, BEGIN OF lty_s_d_branch, d TYPE lty_s_results_branch, END OF lty_s_d_branch. *------------------------- TYPES: BEGIN OF lty_s_attributes, attr_type TYPE string, lang TYPE string, values TYPE TABLE OF string WITH DEFAULT KEY, END OF lty_s_attributes, lty_t_attributes TYPE TABLE OF lty_s_attributes WITH DEFAULT KEY, BEGIN OF lty_s_sectioncontent, occ_id TYPE string, obj_type TYPE string, reference TYPE string, deleted TYPE string, attributes TYPE lty_t_attributes, END OF lty_s_sectioncontent, lty_t_sectioncontent TYPE TABLE OF lty_s_sectioncontent WITH DEFAULT KEY, BEGIN OF lty_s_data, sectionid TYPE string, sectioncontentversion TYPE string, sectioncontent TYPE lty_t_sectioncontent, END OF lty_s_data, lty_t_data TYPE TABLE OF lty_s_data WITH DEFAULT KEY, BEGIN OF lty_s_results_doc, sections TYPE lty_t_data, END OF lty_s_results_doc, BEGIN OF lty_s_data_output, sectionid TYPE string, sectioncontentversion TYPE string, sectioncontent TYPE string, END OF lty_s_data_output, lty_t_data_output TYPE TABLE OF lty_s_data_output WITH DEFAULT KEY, BEGIN OF lty_s_output_doc, sections TYPE lty_t_data_output, END OF lty_s_output_doc. DATA: mv_output TYPE lty_s_output_doc, mv_sol TYPE string, mv_branch TYPE string, mv_doct TYPE string, mv_stat TYPE string. METHODS: request IMPORTING it_request_header TYPE /iwfnd/sutil_property_t iv_request_body TYPE xstring OPTIONAL EXPORTING et_response_header TYPE /iwfnd/sutil_property_t ev_str_response TYPE string CHANGING cs_json TYPE data RAISING zcx_sb_sm, get_branch_content IMPORTING iv_branch_id TYPE if_smuda_instance_typedef=>tgs_root_id RETURNING VALUE(rv_branch) TYPE lty_s_results_doc RAISING zcx_sb_sm, get_doc_list IMPORTING iv_branch_id TYPE if_smuda_instance_typedef=>tgs_root_id iv_doc_type TYPE string RETURNING VALUE(rt_doc_list) TYPE lty_t_sectioncontent RAISING zcx_sb_sm, changing IMPORTING it_doc_list TYPE lty_t_sectioncontent iv_target_stat TYPE string iv_branch_id TYPE string RAISING zcx_sb_sm, get_token RETURNING VALUE(rv_token) TYPE string RAISING zcx_sb_sm. DATA: mo_client_proxy TYPE REF TO /iwfnd/cl_sutil_client_proxy. * . ENDCLASS. START-OF-SELECTION. CLASS lcl_solution_work_api IMPLEMENTATION. METHOD constructor. mv_sol = iv_sol. mv_branch = iv_branch. mv_doct = iv_doct. mv_stat = iv_stat. mo_client_proxy = /iwfnd/cl_sutil_client_proxy=>get_instance( ). ENDMETHOD. METHOD change_stat. DATA(lv_solution_id) = get_solution_by_name( mv_sol ). DATA(lv_branch_id) = get_branch_id( iv_branch_name = mv_branch iv_solution_id = lv_solution_id ). DATA(lt_doc_list) = get_doc_list( iv_branch_id = CONV #( lv_branch_id ) iv_doc_type = mv_doct ). changing( it_doc_list = lt_doc_list iv_target_stat = mv_stat iv_branch_id = lv_branch_id ). ENDMETHOD. METHOD request. DATA lv_reuse TYPE xsdboolean . DATA lv_csrf_uri TYPE string. mo_client_proxy->web_request( EXPORTING it_request_header = it_request_header iv_csrf_uri = lv_csrf_uri iv_request_body = iv_request_body iv_reuse_connection = lv_reuse IMPORTING ev_status_code = DATA(lv_status_code) ev_status_text = DATA(lv_status_text) ev_content_type = DATA(lv_response_content_type) et_response_header = et_response_header ev_response_body = DATA(lv_response_body) et_add_request_header = DATA(lt_add_request_header) ev_sap_client = DATA(lv_sap_client) ev_local_client = DATA(lv_local_client) ev_uri_prefix = DATA(lv_uri_prefix) ev_request_id = DATA(lv_request_id) ev_error_text = DATA(lv_error_text) ev_error_timestamp = DATA(lv_error_timestamp) ev_duration = DATA(lv_duration) ). IF lv_status_code = 200 OR lv_status_code = 204. cl_bcs_convert=>xstring_to_string( EXPORTING iv_xstr = lv_response_body iv_cp = CONV cpcodepage( 4110 ) " SAP character set identification RECEIVING rv_string = DATA(lv_str_resp) ). ev_str_response = lv_str_resp. REPLACE ALL OCCURRENCES OF '\"' IN lv_str_resp WITH '"'. REPLACE ALL OCCURRENCES OF '"{' IN lv_str_resp WITH '{'. REPLACE ALL OCCURRENCES OF '}"' IN lv_str_resp WITH '}'. REPLACE ALL OCCURRENCES OF '"[' IN lv_str_resp WITH '['. REPLACE ALL OCCURRENCES OF ']"' IN lv_str_resp WITH ']'. /ui2/cl_json=>deserialize( EXPORTING json = lv_str_resp pretty_name = /ui2/cl_json=>pretty_mode-low_case name_mappings = VALUE #( ( abap = 'sectionid' json = 'section-id' ) ( abap = 'sectioncontentversion' json = 'section-content-version' ) ( abap = 'sectioncontent' json = 'section-content' ) ) CHANGING data = cs_json ). ELSE. MESSAGE e000(crm_case) WITH |Ошибка при обращении к сервису| lv_status_code lv_status_text INTO DATA(lv_dummy). RAISE EXCEPTION TYPE zcx_sb_sm EXPORTING textid = VALUE #( msgid = sy-msgid msgno = sy-msgno attr1 = sy-msgv1 attr2 = sy-msgv2 attr3 = sy-msgv3 ). ENDIF. ENDMETHOD. METHOD get_branch_content. DATA ls_json TYPE lty_s_results_doc. request( EXPORTING it_request_header = VALUE #( ( name = '~request_method' value = 'GET' ) ( name = '~request_uri' value = |/sap/opu/odata/sap/ProcessManagement/BranchContentSet(BranchId='{ iv_branch_id }',ScopeId='',SiteId='',SystemRole='')/$value| ) ( name = '~charset' value = 'utf-8' ) ) IMPORTING ev_str_response = DATA(lv_str_response) CHANGING cs_json = ls_json ). /ui2/cl_json=>deserialize( EXPORTING json = lv_str_response pretty_name = /ui2/cl_json=>pretty_mode-low_case name_mappings = VALUE #( ( abap = 'sectionid' json = 'section-id' ) ( abap = 'sectioncontentversion' json = 'section-content-version' ) ( abap = 'sectioncontent' json = 'section-content' ) ) CHANGING data = mv_output ). rv_branch = ls_json. ENDMETHOD. METHOD get_token. DATA ls_json TYPE string. request( EXPORTING it_request_header = VALUE #( ( name = '~request_method' value = 'GET' ) ( name = '~request_uri' value = |/sap/opu/odata/sap/ProcessManagement| ) ( name = '~charset' value = 'utf-8' ) ( name = 'X-CSRF-Token' value = 'Fetch' ) ( name = 'Accept' value = 'application/json' ) ( name = 'Content-Type' value = 'application/json' ) ) IMPORTING et_response_header = DATA(lt_response) CHANGING cs_json = ls_json ). rv_token = lt_response[ name = 'x-csrf-token' ]-value. ENDMETHOD. METHOD get_branch_id. DATA ls_json TYPE lty_s_d_branch. request( EXPORTING it_request_header = VALUE #( ( name = '~request_method' value = 'GET' ) ( name = '~request_uri' value = |/sap/opu/odata/sap/ProcessManagement/BranchSet?$format=json| ) ) CHANGING cs_json = ls_json ). rv_branch_id = VALUE #( ls_json-d-results[ branchtitle = iv_branch_name solutionid = iv_solution_id ]-branchid OPTIONAL ). ENDMETHOD. METHOD get_solution_by_name. DATA ls_json TYPE lty_s_d. request( EXPORTING it_request_header = VALUE #( ( name = '~request_method' value = 'GET' ) ( name = '~request_uri' value = |/sap/opu/odata/sap/ProcessManagement/SolutionSet?$format=json| ) ) CHANGING cs_json = ls_json ). rv_solution_id = VALUE #( ls_json-d-results[ solutiontitle = iv_solution_name ]-solutionid OPTIONAL ). ENDMETHOD. METHOD change_document. DATA ls_json TYPE string. TRY. DATA(lv_request_body) = cl_bcs_convert=>string_to_xstring( EXPORTING iv_string = iv_request_body iv_codepage = '4110' ). CATCH cx_root. MESSAGE e000(crm_case) WITH |Ошибка при обработке Json| INTO DATA(lv_dummy). RAISE EXCEPTION TYPE zcx_sb_sm EXPORTING textid = VALUE #( msgid = sy-msgid msgno = sy-msgno attr1 = sy-msgv1 attr2 = sy-msgv2 attr3 = sy-msgv3 ). ENDTRY. request( EXPORTING it_request_header = VALUE #( ( name = '~request_method' value = 'PUT' ) ( name = '~request_uri' value = |/sap/opu/odata/sap/ProcessManagement/BranchContentImporterSet(BranchId='{ iv_branch_id }',ChangeDocumentId='{ iv_change_doc_id }')/$value| ) ( name = 'X-CSRF-Token' value = iv_token ) ( name = 'Accept' value = 'application/json' ) ( name = 'Content-Type' value = 'application/json' ) ) iv_request_body = lv_request_body CHANGING cs_json = ls_json ). ENDMETHOD. METHOD changing. DATA lv_run TYPE abap_bool. DATA lv_request_body TYPE string. DATA(lv_token) = get_token( ). DATA(lt_doc_list) = it_doc_list. LOOP AT lt_doc_list ASSIGNING FIELD-SYMBOL(<ls_doc>). TRY. IF <ls_doc>-attributes[ attr_type = '_SMD_STATE' ]-values[ 1 ] = iv_target_stat. CONTINUE. ENDIF. CATCH cx_root. CONTINUE. ENDTRY. <ls_doc>-attributes[ attr_type = '_SMD_STATE' ]-values[ 1 ] = iv_target_stat. READ TABLE <ls_doc>-attributes ASSIGNING FIELD-SYMBOL(<ls_attributes>) WITH KEY attr_type = '_SMD_STATE'. READ TABLE <ls_attributes>-values ASSIGNING FIELD-SYMBOL(<lv_stat>) INDEX 1. <lv_stat> = iv_target_stat. lv_run = abap_true. ENDLOOP. IF lv_run = abap_true. mv_output-sections[ sectionid = 'NODES' ]-sectioncontent = /ui2/cl_json=>serialize( EXPORTING data = lt_doc_list pretty_name = /ui2/cl_json=>pretty_mode-low_case name_mappings = VALUE #( ( abap = 'sectionid' json = 'section-id' ) ( abap = 'sectioncontentversion' json = 'section-content-version' ) ( abap = 'sectioncontent' json = 'section-content' ) ) ). lv_request_body = /ui2/cl_json=>serialize( EXPORTING data = mv_output pretty_name = /ui2/cl_json=>pretty_mode-low_case name_mappings = VALUE #( ( abap = 'sectionid' json = 'section-id' ) ( abap = 'sectioncontentversion' json = 'section-content-version' ) ( abap = 'sectioncontent' json = 'section-content' ) ) ). change_document( iv_branch_id = iv_branch_id iv_change_doc_id = '' "<ls_doc>-occ_id iv_request_body = lv_request_body iv_token = lv_token ). ELSE. MESSAGE e000(crm_case) WITH |Документов для изменения нет| INTO DATA(lv_dummy). RAISE EXCEPTION TYPE zcx_sb_sm EXPORTING textid = VALUE #( msgid = sy-msgid msgno = sy-msgno attr1 = sy-msgv1 attr2 = sy-msgv2 attr3 = sy-msgv3 ). ENDIF.. ENDMETHOD. METHOD get_doc_list. DATA(ls_result) = get_branch_content( iv_branch_id ). LOOP AT ls_result-sections ASSIGNING FIELD-SYMBOL(<ls_selections>) WHERE sectionid = 'NODES'. LOOP AT <ls_selections>-sectioncontent ASSIGNING FIELD-SYMBOL(<ls_content>) WHERE obj_type = iv_doc_type. APPEND <ls_content> TO rt_doc_list. ENDLOOP. ENDLOOP. ENDMETHOD. ENDCLASS. PARAMETERS: p_sol TYPE text100 DEFAULT 'cCTS Solution strikes back'. PARAMETERS: p_branch TYPE text100 DEFAULT 'Сопровождение'. PARAMETERS: p_doct TYPE text100 DEFAULT 'KWOBJ'. PARAMETERS: p_stat TYPE text100 DEFAULT '0RELEASED'. START-OF-SELECTION. DATA(lo_solution) = NEW lcl_solution_work_api( iv_sol = CONV #( p_sol ) iv_branch = CONV #( p_branch ) iv_doct = CONV #( p_doct ) iv_stat = CONV #( p_stat ) ). TRY. lo_solution->change_stat( ). CATCH zcx_sb_sm INTO DATA(lo_error). MESSAGE lo_error->if_message~get_longtext( ) TYPE 'I' DISPLAY LIKE 'A'. ENDTRY. IF lo_error IS NOT BOUND. MESSAGE |Изменение статусов произведено| TYPE 'I'. ENDIF. |
.