Created by Jerry Wang on Mar 13, 2014

很多时候为了进行性能测试,需要在系统里准备大量的测试数据。

下面这个工具可以按照输入产生指定的大量Product数据。

指定要产生的product的个数

Product mass creation tool

 

执行之后按照指定的product ID的prefix能搜索出创建好的product数据

Product mass creation tool

 

如果要产生的product数量非常大,可以将product schedule成background job来执行:

Product mass creation tool

 

Product mass creation tool

 

可以通过System->Own Jobs查看Job执行情况:

Product mass creation tool

 

Product mass creation tool

 

当job的状态变成Finished之后, 点击Spool button查看输出:

 

Product mass creation tool

 

Product mass creation tool

 

report  zhana_product_create_mass.

SELECTION-SCREEN BEGIN OF BLOCK rad1
                          WITH FRAME TITLE title.

SELECTION-SCREEN COMMENT 1(79) text-001
                                   FOR FIELD prefix.

parameters: prefix   type c LENGTH 20 obligatory LOWER CASE.
SELECTION-SCREEN SKIP.


SELECTION-SCREEN COMMENT 1(79) text-002
                                   FOR FIELD cat_id.
PARAMETERS: cat_id    type comt_category_id obligatory default 'MAT_'.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-003
                                   FOR FIELD descrip.
PARAMETERS: descrip   type string OBLIGATORY DEFAULT 'Description' LOWER CASE.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-004
                                   FOR FIELD bs_uom.
PARAMETERS: bs_uom    type COML_PR_UNIT_UI_DYNP-unit default 'EA'.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-005
                                   FOR FIELD note.
PARAMETERS: note      type string OBLIGATORY DEFAULT 'Long Text' LOWER CASE.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-006
                                   FOR FIELD config.
PARAMETERS: config      type COMT_PRODUCT_UI-config  DEFAULT  abap_true.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-007
                                   FOR FIELD so_org .
PARAMETERS: so_org      type CRMT_PRIL_DC_UI-sales_org OBLIGATORY DEFAULT 'O 50000732'.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-008
                                   FOR FIELD dist_c.
PARAMETERS: dist_c      type CRMT_PRIL_DC_UI-DISTR_CHAN OBLIGATORY DEFAULT '01'.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-009
                                   FOR FIELD status.
PARAMETERS: status      type CRMT_PRIL_STATUS_ATT-stat DEFAULT 'I1103'.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-010
                                   FOR FIELD altid.
PARAMETERS: altid      type ISAM_O_VEH_IDS_DYNP_SV-ALTVEHNO OBLIGATORY.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-011
                                   FOR FIELD cusproid.
PARAMETERS: cusproid  type string OBLIGATORY.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-012
                                   FOR FIELD count.
PARAMETERS: count     type i DEFAULT 100.
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT 1(79) text-013
                                   FOR FIELD start.
PARAMETERS: start     type i DEFAULT 0.
SELECTION-SCREEN SKIP.

*SELECTION-SCREEN COMMENT 1(79) text-013
*                                   FOR FIELD comp.
*PARAMETERS: comp     type COMT_PR_COMP.
*SELECTION-SCREEN SKIP.






SELECTION-SCREEN END OF BLOCK rad1.

data: lo_core               type ref to cl_crm_bol_core,
      lo_collection         type ref to if_bol_entity_col,
      lo_root_entity        type ref to cl_crm_bol_entity,
      lr_product            type ref to cl_crm_bol_entity,
      lr_note               type ref to cl_crm_bol_entity,
      lr_altid              type ref to cl_crm_bol_entity,
      lr_dischain           type ref to cl_crm_bol_entity,
      lr_status             type ref to cl_crm_bol_entity,
      lo_transaction        type ref to if_bol_transaction_context,
      lr_fac                type ref to cl_crm_bol_entity_factory,
      lt_param              type crmt_name_value_pair_tab,
      ls_param              type crmt_name_value_pair,
      lv_success            type abap_bool,
      lv_index              TYPE string,
      lv_header_failed      TYPE abap_bool,
      ls_name               TYPE string,
      lv_input_invalid      TYPE abap_bool,
      lr_product_id         TYPE REF TO data,
      ls_product            type comt_product_ui,
      lv_changed            type abap_bool,
      lv_note               type string,
      lv_altid              type string,
      lv_msg                type string,
      lo_glb_msg_cont       type ref to cl_crm_genil_global_mess_cont,
      lt_msg                type crmt_genil_message_tab,
      ls_msg                type crmt_genil_message,
      lo_altid              type ref to cl_crm_bol_entity.

FIELD-SYMBOLS: <product_id> TYPE COMT_PRODUCT_ID.

INITIALIZATION.
  title = 'Product Mass Creation Option'.

START-OF-SELECTION.

  PERFORM check_input.
  CHECK lv_input_invalid = abap_false.

  lo_core = cl_crm_bol_core=>get_instance( ).
  lo_core->load_component_set( 'PROD_ALL' ).
  lr_fac   = lo_core->get_entity_factory( 'Product' ).

  DO count TIMES.

    PERFORM create_header.
    CHECK lv_header_failed = abap_false.

    "************** 1: LONG TEXT
    PERFORM create_long_text.
    "************** 2: ALT ID
    PERFORM create_alt_id.
    "************** 3: SALES ORG and DISTRI CHAIN
    PERFORM create_sale_org.
    "************** 4: STATUS
    PERFORM create_status.
    "************** 5: CONFIG
    PERFORM set_config.
    "************** 6: COMPETITOR
*    PERFORM set_competitor.

    PERFORM create_customer_id.

    PERFORM save_single.



  ENDDO.

FORM check_input.
  IF count <= 0 OR count > 100000.
    WRITE:/ 'Specify number of product you want to mass create: between 1 and 100000' COLOR COL_NEGATIVE INTENSIFIED ON.
    lv_input_invalid = abap_true.
  ENDIF.

  IF start < 0 OR start > 100000.
    WRITE:/ 'Specify start index: between 1 and 100000' COLOR COL_NEGATIVE INTENSIFIED ON.
    lv_input_invalid = abap_true.
  ENDIF.
ENDFORM.

FORM create_header.
  CLEAR: lv_header_failed.
  clear lt_param.
  ls_param-name = 'PRODUCT_ID'.
  lv_index = sy-index + start.
  CONCATENATE prefix lv_index INTO ls_param-value.
  append ls_param to lt_param.

  CONCATENATE 'Creating Product:' ls_param-value INTO lv_msg SEPARATED BY space.
  PERFORM display_progress USING sy-index count lv_msg.

  ls_param-name = 'PRODUCT_TYPE'.
  ls_param-value = '01'.
  append ls_param to lt_param.

  ls_param-name = 'ROOT_CAT_ID'.
  ls_param-value = cat_id.
  append ls_param to lt_param.

  ls_param-name = 'ROOT_HIER_ID'.
  ls_param-value = 'R3PRODSTYP'.
  append ls_param to lt_param.

  ls_param-name = 'SHORT_TEXT'.
  CONCATENATE descrip lv_index INTO ls_param-value.
  append ls_param to lt_param.

  ls_param-name = 'BASE_UOM'.
  ls_param-value = bs_uom.
  append ls_param to lt_param.

  lr_product = lr_fac->create( lt_param ).

  if lr_product is initial.
    lo_glb_msg_cont = lo_core->get_global_message_cont( ).
    CALL METHOD lo_glb_msg_cont->if_genil_message_container~get_messages
      EXPORTING
        iv_message_type = if_genil_message_container=>mt_all
      IMPORTING
        et_messages     = lt_msg.
    loop at lt_msg into ls_msg.
      write:/ ls_msg-message.
    endloop.
    lv_header_failed = abap_true.
  endif.

ENDFORM.

FORM save_single.

  lo_core->modify( ).
  lo_transaction = lr_product->get_transaction( ).
  lv_changed = lo_transaction->check_save_needed( ).
  lr_product_id = lr_product->get_property( 'PRODUCT_ID' ).
  ASSIGN lr_product_id->* TO <product_id>.
  check lv_changed eq abap_true.
  lv_success = lo_transaction->save( ).
  if lv_success = abap_true.
    lo_transaction->commit( ).
    write:/ 'Product Created Successfully, Product ID: ', <product_id> COLOR COL_POSITIVE INTENSIFIED ON.
  else.
    lo_transaction->rollback( ).
    WRITE:/ 'Product Created Failed, index: ' , sy-index.
  endif.
  lo_core->reset( ).
ENDFORM.


FORM create_sale_org.
  CLEAR: lr_dischain.
  PERFORM create_sub_node USING 'ProductDistrChain' CHANGING lr_dischain.
  CHECK lr_dischain IS NOT INITIAL.
  lr_dischain->set_property( iv_attr_name = 'SALES_ORG' iv_value = so_org ).
  lr_dischain->set_property( iv_attr_name = 'DISTR_CHAN' iv_value = dist_c ).

ENDFORM.

FORM create_alt_id.

  CLEAR: lr_altid, lv_altid.
  CONCATENATE altid lv_index INTO lv_altid.
  PERFORM create_sub_node USING 'ProductVehIDs' CHANGING lr_altid.

  CHECK lr_altid IS NOT INITIAL.

  lr_altid->set_property( iv_attr_name = 'ALTVEHNO' iv_value = lv_altid ).


ENDFORM.

FORM create_customer_id.

  CLEAR: lo_altid.
  PERFORM create_sub_node USING 'ProductRelPrdCpn' CHANGING lo_altid.

  CHECK lo_altid IS NOT INITIAL.
  lo_altid->set_property( iv_attr_name = 'BU_PARTNER_ID' iv_value = '118' ).
  lo_altid->set_property( iv_attr_name = 'PRID_VENDOR' iv_value = cusproid ).

ENDFORM.

FORM create_long_text.

  CLEAR: lv_note, lr_note.
  CONCATENATE note lv_index INTO lv_note.

  PERFORM create_sub_node USING 'ProductLongtext' CHANGING lr_note.

  CHECK lr_note IS NOT INITIAL.

  lr_note->set_property( iv_attr_name = 'TDSPRAS'
                       iv_value     = 'E' ).

  lr_note->set_property( iv_attr_name = 'TDID'
                       iv_value     = 'BASE' ).

  lr_note->set_property( iv_attr_name = 'CONC_LINES'
                       iv_value     = lv_note ).
ENDFORM.

FORM create_status.
  CLEAR: lr_status.
  CHECK status IS NOT INITIAL.
  PERFORM create_sub_node USING 'ProductStat' CHANGING lr_status.

  CHECK lr_status IS NOT INITIAL.

  lr_status->set_property( iv_attr_name = 'STAT' iv_value = status ).

ENDFORM.

FORM create_sub_node USING iv_relation_name TYPE CRMT_RELATION_NAME CHANGING ir_sub.
  CLEAR: ir_sub.

  CALL METHOD lr_product->create_related_entity
    EXPORTING
      iv_relation_name = iv_relation_name
    RECEIVING
      rv_result        = ir_sub.

ENDFORM.

FORM set_config.
  lr_product->set_property( iv_attr_name = 'CONFIG'
                        iv_value     = config ).
ENDFORM.

*FORM set_competitor.
*  CHECK comp IS NOT INITIAL.
*  lr_product->set_property( iv_attr_name = 'COMPETITOR_PROD'
*                      iv_value     = comp ).
*ENDFORM.

FORM display_progress USING current type i total type i text type string.
  DATA: percent TYPE i.

  percent = current * 100 / total.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      PERCENTAGE = percent
      text       = text.
ENDFORM.

Product mass creation tool

 

 

 

相关文章: