Chinaunix首页 | 论坛 | 博客
  • 博客访问: 151520
  • 博文数量: 54
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 508
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-18 09:25
个人简介

好男人就是我,我就是你兵哥

文章分类

全部博文(54)

我的朋友

分类: Web开发

2013-10-08 09:03:24

report  ztest001.


parameters:
  pa_objid             type        crmt_object_id,
  pa_attxt             type        string
                         default     'Hi there, folks !'
                         lower case.


data:
  lv_object_id         type        crmt_object_id,
  lv_content_s         type        string,
  lr_core              type ref to cl_crm_bol_core,
  lr_factory           type ref to cl_crm_bol_entity_factory,
  lv_header_guid       type        crmt_object_guid,
  lt_params            type        crmt_name_value_pair_tab,
  ls_params            type        crmt_name_value_pair,
  lr_cmbo              type ref to cl_crm_bol_entity,
  lr_cmdocument        type ref to cl_crm_bol_entity,
  lv_content_length    type        i,
  lv_content_length_s  type        string,
  lv_content_utf8      type        string,
  lr_transaction       type ref to if_bol_transaction_context.
lv_object_id = pa_objid.
lv_content_s = pa_attxt.
call function 'CRM_ORDER_CONVERT_DOCNUMBER'
  exporting
    iv_object_id   = lv_object_id
    iv_object_type = 'BUS2000126'
  importing
    ev_header_guid = lv_header_guid
  exceptions
    others         = 1.
SELECT SINGLE GUID INTO LV_HEADER_GUID FROM CRMD_ORDERADM_H WHERE OBJECT_ID = LV_OBJECT_ID.
if sy-subrc is initial.
  lr_core = cl_crm_bol_core=>get_instance( ).
  if lr_core is bound.
    if lr_core->get_entity_manager( ) is not bound.
      "     only if running outside of WebUI: start BOL core for comp. set CM
      try.
          lr_core->start_up( iv_appl_name            = 'CM'
                             iv_display_mode_support = abap_false ).
        catch:
          cx_crm_genil_general_error.
      endtry.
    endif.
    lr_factory = lr_core->get_entity_factory( 'CMBO' ).


    if lr_factory is bound.
      ls_params-name = 'INSTID'.
      ls_params-value = lv_header_guid.        "- order header GUID
      append ls_params to lt_params.
      ls_params-name = 'TYPEID'.
      ls_params-value = 'BUS2000116'.
      append ls_params to lt_params.
      ls_params-name = 'CATID'.
      ls_params-value = 'BO'.
      append ls_params to lt_params.
      lr_cmbo = lr_factory->create( lt_params ).
      if lr_cmbo is bound.
        lr_cmdocument
          = lr_cmbo->create_related_entity( 'CMBODocumentRefRel' ).
        if lr_cmdocument is bound.
          "         prepare text file content
          lv_content_length = strlen( lv_content_s ).
          lv_content_length_s = lv_content_length.
          lv_content_utf8 = cl_rt_rep_toolkit=>s2xutf8( lv_content_s ).


          "         set attributes according to structure CRMT_CMIC_DOC_ATTR
          lr_cmdocument->set_property_as_string(
                           iv_attr_name = 'CONTENT'
                           iv_value     = lv_content_utf8 ).   "上传内容
          lr_cmdocument->set_property_as_string(
                           iv_attr_name = 'CONTENT_TYPE'
                           iv_value     = 'text/plain' ).
          lr_cmdocument->set_property_as_string(
                          iv_attr_name = 'FILENAME'
                           iv_value     = 'hi there.txt' ).
          lr_cmdocument->set_property_as_string(
                           iv_attr_name = 'FILE_SIZE'
                           iv_value     = lv_content_length_s ).
*        lr_cmdocument->set_property(
*                           iv_attr_name = 'KW_RELATIVE_URL'        "上传URL
*                           iv_value     = iv_url-kw_relative_url ).
*        lr_cmdocument->set_property(
*                           iv_attr_name = 'CONTENT_URL'
*                           iv_value     =  iv_url-content_url ).


          lr_core->modify( ).
          lr_transaction = lr_cmbo->get_transaction( ).
          if lr_transaction->save( ) = abap_true.
            lr_transaction->commit( ).
            write: / 'attachment OK'.
          else.
           lr_transaction->rollback( ).
            write: / 'document attachment failed'.
          endif.
        endif.
      endif.
    endif.
  endif.
endif.
阅读(841) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~