更改销售订单配置

news/2024/7/5 23:16:53 标签: classification, header, object, input, output, sap

   这个事情,反映了自己做事情不够坚决,中间尝试了BAPI_SALESORDER_CHANGE,浪费了不少时间。

  既然可以同步了已经存在的配置,有配置但没有维护过的,应该也可以维护,可自己没有再深入一步。多走了许多弯  路。

  type-pools:ibco2.
  data:it_config_old type ibco2_instance_tab2,
       g_object      type cuib_business_object,
       g_cuobj       type vbap-cuobj.

 

 *& 检查配置的合法性,即当传入的特性,在系统里没有的直接报错
  perform configuration_validity_check tables cfg_list
                                       using it_config_old
                                             salesdocument
                                             ret_msg
                                             g_object
                                             g_cuobj.


*& update configuration.
  check ret_msg is initial.
  perform  update_configuration using  it_config_old
                                       g_cuobj
                                       g_object
                                       ret_msg .

*& update status
  check ret_msg is initial.
  if not status is initial.
    perform update_order_header_status using salesdocument
                                             status
                                             ret_msg.
  endif.
*& create header text.
  check ret_msg is initial.
  if not text[] is initial.
    perform create_order_header_text tables text
                                     using salesdocument
                                           ret_msg.

  endif.

  if ret_msg is initial.
    ret_msg-type = 'S'.
    ret_msg-message = '系统同步成功!'.

  endif.

 

 *&---------------------------------------------------------------------*
*&      Form  configuration_validity_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_CFG_LIST            text
*      -->CFG_OLD               text
*      -->P_VBELN               text
*      -->R_MSG                 text
*      -->CUIB_BUSINESS_OBJECT  text
*----------------------------------------------------------------------*
form configuration_validity_check tables t_cfg_list
                                   using  cfg_old type ibco2_instance_tab2
                                          p_vbeln
                                          r_msg   type bapiret2
                                          p_object type cuib_business_object
                                          p_cuobj.

  data:wa type ibvalue0,
       wa_config type  line of ibco2_instance_tab2 ,
       wa_ibco2  type ibco2_value_rec,
       g_object  type cuib_business_object,
       l_index   like sy-tabix,
       l_atinn_inner_format(10).
*& 注意应该修改,不 应该硬编码:特性不能指定内部形式
  loop at t_cfg_list into wa.

    if wa-atinn <> '0000002288' and
       wa-atinn <> '0000002291' and
       wa-atinn <> '0000002292' .
      r_msg-type = 'E'.
      r_msg-message = '修改的配置只能为备注,等待技术资料,评审上线时间,请核实!'.
      exit.
    endif.

    if wa-atwrt = ''.
      delete t_cfg_list .
    endif.

  endloop.

  check r_msg is initial.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = p_vbeln
    importing
      output = p_vbeln.

  select single cuobj
  into p_cuobj
  from vbap
  where vbeln = p_vbeln.

  if sy-subrc = 0.

    call function 'CUCB_GET_CONFIGURATION'
      exporting
        instance                           = p_cuobj
*   IS_BUSINESS_OBJECT                 =
*   IV_MOMENT                          =
*   IV_WITH_DB_INSTANCE                =
     importing
*   IBASE                              =
        configuration                      = cfg_old
*   EO_CBASE_REF                       =
     exceptions
       invalid_input                      = 1
       invalid_instance                   = 2
       instance_is_a_classification       = 3
       others                             4
              .
    if sy-subrc <> 0.
      r_msg-type = 'E'.
      r_msg-message = '订单的配置读取出现异常,请联系系统管理员!'.
    else.
*& 当传入的特性,在SAP内不存在时报错.
      loop at t_cfg_list into wa.
*        CALL FUNCTION 'CONVERSION_EXIT_ATINN_OUTPUT'
*          EXPORTING
*            input  = wa-atinn
*          IMPORTING
*            output = l_atinn_inner_format.

        check r_msg is initial.
        read table  cfg_old into wa_config index 1.
        if sy-subrc = 0.
          read table  wa_config-values into wa_ibco2 with key  atinn = wa-atinn.
          if sy-subrc <> 0.
            wa_ibco2-atwrt = wa-atwrt.
            wa_ibco2-atinn = wa-atinn.
            wa_ibco2-atcod = 1.
*& 当为日期时,后面的。ATFLV需赋值
            append wa_ibco2 to wa_config-values.
            wa_config-ind-indcha = 'X'.
            p_object-object_type = wa_config-owner+0(10).
            p_object-object_key  = wa_config-owner+10(50).
            modify cfg_old from wa_config index 1.
*            r_msg-type = 'E'.
*            r_msg-message = '传入的特性在SAP不存在,请联系系统管理员!'.
*            EXIT.
          else.
            l_index = sy-tabix.
            wa_ibco2-atwrt = wa-atwrt.
            modify  wa_config-values from  wa_ibco2 index l_index.

            wa_config-ind-indcha = 'X'.
            p_object-object_type = wa_config-owner+0(10).
            p_object-object_key  = wa_config-owner+10(50).
            modify cfg_old from wa_config index 1.
          endif.
        endif.
      endloop.

    endif.
  else.
    r_msg-type = 'E'.
    r_msg-message = '订单的对象编号不存在,请核实!'.
  endif.

endform.                    " CONFIGURATION_VALIDITY_CHECK
*&---------------------------------------------------------------------*
*&      Form  UPDATE_CONFIGURATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form update_configuration  using update_cfg
                                 p_cuobj
                                 p_object structure cuib_business_object
                                 r_msg type bapiret2.

  call function 'CUCB_SET_CONFIGURATION'
    exporting
      root_instance                      = p_cuobj
*   IS_CBASE_HEADER                    =
    changing
      configuration                      = update_cfg
   exceptions
     invalid_input                      = 1
     invalid_instance                   = 2
     instance_is_a_classification       = 3
     others                             4.
  if sy-subrc <> 0.
    r_msg-type = 'E'.
    case sy-subrc.
      when 1.
        concatenate 'invalid_input'请核查!' into r_msg-message.
      when 2.
        concatenate 'invalid_instance' '请核查!' into r_msg-message.
      when 3.
        concatenate 'instance_is_a_classification'请核查!' into r_msg-message.
      when 4.
        concatenate 'others_error' '请核查!' into r_msg-message.
    endcase.

  endif.

  call function 'CUCB_CONFIGURATION_TO_DB'
    exporting
      root_instance                       = p_cuobj
      root_object                         = p_object
*     FORCE_NEW_INSTANCE                  =
*     IV_WITHOUT_COMMIT_UPDATE            = ' '
*     IV_MATERIAL                         =
*     IV_LOCATION                         =
*     IV_TECHS                            =
*   IMPORTING
*     NEW_INSTANCE                        =
*   TABLES
*     EXP_NEW_NESTED_CUOBJS               =
   exceptions
     invalid_instance                    = 1
     invalid_root_instance               = 2
     no_changes                          = 3
     already_registered_for_update       = 4
     instance_is_a_classification        = 5
     others                              6
            .
  if sy-subrc <> 0.

    r_msg-type = 'E'.
    case sy-subrc.
      when 1.
        concatenate 'INVALID_INSTANCE' '请核查!' into r_msg-message.
      when 2.
        concatenate 'INVALID_ROOT_INSTANCE' '请核查!' into r_msg-message.
      when 3.
        concatenate 'NO_CHANGES' '请核查!' into r_msg-message.
      when 4.
        concatenate 'ALREADY_REGISTERED_FOR_UPDATE' '请核查!' into r_msg-message.
      when 5.
        concatenate 'INSTANCE_IS_A_CLASSIFICATION' '请核查!' into r_msg-message.
      when 6.
        concatenate 'others_error' '请核查!' into r_msg-message.
    endcase.
  else.
    call function 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
              .

  endif.

endform.                    " UPDATE_CONFIGURATION
*&---------------------------------------------------------------------*
*&      Form  UPDATE_ORDER_HEADER_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form update_order_header_status using p_vbeln
                                      p_status
                                      r_msg type bapiret2.
  data:l_objnr       like vbak-objnr,
       l_user_status like jest-stat,
       l_stsma       like jsto-stsma .

  select single objnr
  into l_objnr
  from vbak
  where vbeln = p_vbeln.

  select single stsma
  into l_stsma
  from jsto
  where objnr = l_objnr.

  select single estat
  into l_user_status
  from tj30t
  where stsma = l_stsma and
        spras = sy-langu and
        txt04 = p_status.

  call function 'STATUS_CHANGE_EXTERN'
    exporting
*     CHECK_ONLY                = ' '
*     CLIENT                    = SY-MANDT
      objnr                     = l_objnr
      user_status               = l_user_status
*     SET_INACT                 = ' '
*     SET_CHGKZ                 =
*     NO_CHECK                  = ' '
*   IMPORTING
*     STONR                     =
   exceptions
     object_not_found          = 1
     status_inconsistent       = 2
     status_not_allowed        = 3
     others                    4
            .
  if sy-subrc <> 0.
    r_msg-type = 'E'.
    case sy-subrc.
      when 1.
        concatenate 'OBJECT_NOT_FOUND' '请核查!' into r_msg-message.
      when 2.
        concatenate 'STATUS_INCONSISTENT' '请核查!' into r_msg-message.
      when 3.
        concatenate 'STATUS_NOT_ALLOWED ' '请核查!' into r_msg-message.
      when 4.
        concatenate 'others_error' '请核查!' into r_msg-message.
    endcase.
  else.
    call function 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
              .

  endif.

endform.                    " UPDATE_ORDER_HEADER_STATUS

*&---------------------------------------------------------------------*
*&      Form  create_order_header_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_TEXT     text
*      -->P_VBELN    text
*      -->R_MSG      text
*----------------------------------------------------------------------*
form create_order_header_text tables t_text
                               using p_vbeln
                                     r_msg structure bapiret2.

  data:l_fname like thead-tdname.
  l_fname = p_vbeln.

  call function 'CREATE_TEXT'
    exporting
      fid       = '0002'
      flanguage = sy-langu
      fname     = l_fname
      fobject   = 'VBBK'
    tables
      flines    = t_text
    exceptions
      no_init   = 1
      no_save   = 2
      others    3.
  if sy-subrc <> 0.
    r_msg-type = 'E'.
    case sy-subrc.
      when 1.
        concatenate 'no_init' '请核查!' into r_msg-message.
      when 2.
        concatenate 'no_save' '请核查!' into r_msg-message.
      when 4.
        concatenate 'others_error' '请核查!' into r_msg-message.
    endcase.
  endif.

endform.                    " CREATE_ORDER_HEADER_TEXT

 


http://www.niftyadmin.cn/n/1071133.html

相关文章

MySQL Replication--复制基本工作原理

复制工作原理(1) master将改变记录到二进制日志(binary log)中&#xff08;这些记录叫做二进制日志事件&#xff0c;binary log events&#xff09;&#xff1b;(2) slave将master的binary log events拷贝到它的中继日志(relay log)&#xff1b;(3) slave重做中继日志中的事件&…

【ExtJS实践】之七 :禁止Grid、Treegrid列排序和列菜单

Ext的Grid和Treegrid默认提供列菜单的功能&#xff0c;在列菜单中可以进行排序以及控制列显示状态。 在实际项目中&#xff0c;往往有些列是不需要用户看到的&#xff0c;因此就必须屏蔽列菜单的功能。 1、屏蔽Grid&#xff0c;包括EditorGrid的列菜单 方法&#xff1a; 在Grid…

python基础:用apply使用元祖和列表调用函数

python基础&#xff1a;内置模块&#xff0c;用apply使用元祖和列表调用函数 def my_fuc(a, b):print a, batuple(30,10) alist [Hello,World!] apply(my_fuc,atuple) apply(my_fuc,alist) 输出&#xff1a; D:\py>python buildin.py 30 10 Hello World! 用apply使用序列做参…

架构相关领域的学习材料(转)

架构相关领域的学习材料 http://hi.baidu.com/linsd99/item/c51cbb773c9be25a0c0a074f 对于工程师来说&#xff0c;到一定阶段后往往会遇到成长瓶颈。要突破此瓶颈&#xff0c;需要在所属技术领域更深入学习&#xff0c;了解本领域的问题本质、方法论与设计理念、发展历史等。以…

Web Drypro Simple Navigation

1,view,outbound plug,inbound plug.action,method tab,calling the methodfire_(name of plag)_plg 2,In windows create navigation link

wp 引用数据库

引用数据库&#xff08;将创建好的数据库部署到其他手机上&#xff09; 第一步&#xff1a;创建引用数据库 创建用来创建本地数据库并使用引用数据加载该数据库的帮助器应用程序。也就是创建一个含有本地数据库功能的APP&#xff0c;系统第一次运行的时候会自动在独立存储中创建…

服务器操作系统安装心得

昨晚重装了服务器操作系统&#xff0c;整理记录如下&#xff1a; 1. 开机自检界面。 2. 集显坏了&#xff0c;只能使用独显接显示器&#xff0c;出厂默认使用第三张&#xff08;从右往左&#xff09;独立显卡外显。 3. 对操作系统没有要求&#xff0c;Ubuntu可以作为服务器操作…

销售订单配置的另外一个取法

使用类CL_CUX_CBASE_CORE里的方法&#xff1a;GET_CBASE 输入参数基本一样&#xff0c;性能比VC_I_GET_CONFIGURATION &#xff0c;VC_I_GET_CONFIGURATION _IBASE更好