加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[ABAP] 批次特性值调用与BAPI封装

(2012-12-01 12:32:24)
标签:

abap

it

分类: ABAP

BAPI:  Z_GET_OBJCL_OR_CONFIGURATION

http://s11/mw690/69f04819gcfc30b595dba&690批次特性值调用与BAPI封装" TITLE="[ABAP] 批次特性值调用与BAPI封装" />

http://s8/mw690/69f04819gcfc30c9fa707&690批次特性值调用与BAPI封装" TITLE="[ABAP] 批次特性值调用与BAPI封装" />

  function z_get_objcl_or_configuration.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(GET_TYPE) TYPE  CHAR01
*"     VALUE(I_OBJECTKEY) TYPE  BAPI1003_KEY-OBJECT OPTIONAL
*"     VALUE(I_OBJECTTABLE) TYPE  BAPI1003_KEY-OBJECTTABLE OPTIONAL
*"     VALUE(I_OBJECTCLASSTYPE) TYPE  BAPI1003_KEY-CLASSTYPE OPTIONAL
*"     VALUE(I_KEYDATE) TYPE  BAPI1003_KEY-KEYDATE DEFAULT SY-DATUM
*"     VALUE(I_LANGUAGE) TYPE  BAPIFIELDSCACL-BAPILANGUA DEFAULT
*"       SY-LANGU
*"     VALUE(I_CU_INSTANCE) TYPE  CUXT_INSTANCE_NO OPTIONAL
*"  TABLES
*"      RETURN STRUCTURE  BAPIRET2
*"      ALLOCLIST STRUCTURE  BAPI1003_ALLOC_LIST
*"      ALLOCVALUE STRUCTURE  ZCU_ALLOCVALUES
*"----------------------------------------------------------------------
  datagit_ret like bapiret2 occurs 0,
        wa_ret like bapiret2,
        wa_alloclist like bapi1003_alloc_list,
        wa_allocvalue like zcu_allocvalues.
  datagit_instances like cuxt_cuins_s occurs 0,
        wa_instances like cuxt_cuins_s,
        git_part_of like cuxt_cuprt_s occurs 0,
        git_values like cuxt_cuval_s occurs 0,
        wa_values like cuxt_cuval_s,
        git_var_keys like cuxt_cuvk_s occurs 0.
  datagit_valuechar like bapi1003_alloc_values_char occurs 0,
        wa_valuechar like bapi1003_alloc_values_char,
        git_valuenum like bapi1003_alloc_values_num occurs 0,
        wa_valuenum like bapi1003_alloc_values_num,
        git_valuecurr like bapi1003_alloc_values_curr occurs 0,
        wa_valuecurr like bapi1003_alloc_values_curr.

  refreshreturn ,alloclist, allocvalue.

  check get_type 'A' or get_type 'O' or get_type 'C'.

  if i_objectkey '' or i_objecttable '' or i_objectclasstype ''.

    if get_type 'A' or get_type 'O'.

      call function 'BALW_BAPIRETURN_GET2'
        exporting
          type   'E'
          cl     'ZHF01'
          number 001
          par1   '对象'
          par2   'I_OBJECTKEY'
          par3   'I_OBJECTTABLE'
          par4   'I_OBJECTCLASSTYPE'
        importing
          return wa_ret.
      append wa_ret to git_ret.
    endif.

  else.

    call function 'BAPI_OBJCL_GETCLASSES'
      exporting
        objectkey_imp   i_objectkey
        objecttable_imp i_objecttable
        classtype_imp   i_objectclasstype
        read_valuations 'X'
        keydate         i_keydate
        language        i_language
      tables
        alloclist       alloclist
        allocvalueschar git_valuechar
        allocvaluescurr git_valuecurr
        allocvaluesnum  git_valuenum
        return          git_ret.

    read table alloclist into wa_alloclist index 1.
    loop at git_valuechar into wa_valuechar.
      wa_allocvalue-class_type wa_alloclist-classtype.     "分类
      wa_allocvalue-charc wa_valuechar-charact.            "特性
      wa_allocvalue-charc_des wa_valuechar-charact_descr.  "特性描述
      wa_allocvalue-char_value wa_valuechar-value_char.    "特性值
      perform sub_get_chades using wa_allocvalue-charc wa_allocvalue-char_value i_language
                             changing wa_allocvalue-charc_type           "特性类型
                                      wa_allocvalue-charc_cnum           "特性长度
                                      wa_allocvalue-charc_dnum           "特性小数位
                                      wa_allocvalue-char_value_des       "特性值描述
                                      wa_valuechar-charact_descr.        "特性描述
      append wa_allocvalue to allocvalue.
      clear wa_allocvalue.
    endloop.

    loop at git_valuecurr into wa_valuecurr.
      wa_allocvalue-class_type wa_alloclist-classtype.     "分类
      wa_allocvalue-charc wa_valuecurr-charact.            "特性
      wa_allocvalue-charc_des wa_valuecurr-charact_descr.  "特性描述
      wa_allocvalue-nc_value_from wa_valuecurr-value_from.   "
      wa_allocvalue-currency_from wa_valuecurr-currency_from.
      wa_allocvalue-nc_value_to wa_valuecurr-value_to.
      wa_allocvalue-currency_to wa_valuecurr-currency_to.
      perform sub_get_chades using wa_allocvalue-charc wa_allocvalue-char_value i_language
                       changing wa_allocvalue-charc_type           "特性类型
                                wa_allocvalue-charc_cnum           "特性长度
                                wa_allocvalue-charc_dnum           "特性小数位
                                wa_allocvalue-char_value_des       "特性值描述
                                wa_valuechar-charact_descr.        "特性描述
      append wa_allocvalue to allocvalue.
      clear wa_allocvalue.
    endloop.

    loop at git_valuenum into wa_valuenum.
      wa_allocvalue-class_type wa_alloclist-classtype.     "分类
      wa_allocvalue-charc wa_valuenum-charact.            "特性
      wa_allocvalue-charc_des wa_valuenum-charact_descr.  "特性描述
      wa_allocvalue-nc_value_from wa_valuenum-value_from.
      wa_allocvalue-num_unit_from wa_valuenum-unit_from.
      wa_allocvalue-nc_value_to wa_valuenum-value_to.
      wa_allocvalue-num_unit_to wa_valuenum-unit_to.
      perform sub_get_chades using wa_allocvalue-charc wa_allocvalue-char_value i_language
                 changing wa_allocvalue-charc_type           "特性类型
                          wa_allocvalue-charc_cnum           "特性长度
                          wa_allocvalue-charc_dnum           "特性小数位
                          wa_allocvalue-char_value_des       "特性值描述
                          wa_valuechar-charact_descr.        "特性描述
      append wa_allocvalue to allocvalue.
      clear wa_allocvalue.
    endloop.

  endif.


  if i_cu_instance ''.

    if get_type 'C' or get_type 'A'.

      call function 'BALW_BAPIRETURN_GET2'
        exporting
          type   'E'
          cl     'ZHF01'
          number 001
          par1   '配置'
          par2   'I_CU_INSTANCE'
        importing
          return wa_ret.
      append wa_ret to git_ret.

    endif.

  elseif get_type <> 'O'.

    call function 'CUXI_GET_SINGLE_CONFIGURATION'
     exporting
       i_root_instance                    i_cu_instance
     tables
       e_tab_instances                    git_instances
       e_tab_part_of                      git_part_of
       e_tab_values                       git_values
       e_tab_var_keys                     git_var_keys
        E_TAB_BLOB                         =
    exceptions
      invalid_instance                   1
      no_root_instance                   2
      instance_is_a_classification       3
      internal_error                     4
      no_profile_found                   5
      invalid_data                       6
      others                             7.
    if sy-subrc 0.
      read table git_instances into wa_instances index 1.
      wa_alloclist-object wa_instances-obj_key.      "对象KEY
      wa_alloclist-objtyp wa_instances-obj_type.      "对象类
      wa_alloclist-classtype wa_instances-class_type.  "对象分类
      append wa_alloclist to alloclist.
      clear wa_alloclist.
      loop at git_values into wa_values.
        wa_allocvalue-class_type wa_instances-class_type.     "对象分类
        wa_allocvalue-charc wa_values-charc.                  "特性
        wa_allocvalue-char_value wa_values-value   "特性值
        perform sub_get_chades using wa_allocvalue-charc wa_allocvalue-char_value i_language
                               changing wa_allocvalue-charc_type           "特性类型
                                        wa_allocvalue-charc_cnum           "特性长度
                                        wa_allocvalue-charc_dnum           "特性小数位
                                        wa_allocvalue-char_value_des      "特性值描述
                                        wa_allocvalue-charc_des.          "特性描述
        if wa_allocvalue-charc_type <> 'CHAR'.
          wa_allocvalue-nc_value_from  wa_values-value.
          wa_allocvalue-char_value wa_values-value   "特性值
          clear wa_allocvalue-char_value.
        endif.
        wa_allocvalue-valcode wa_values-valcode.
        append wa_allocvalue to allocvalue.
        clear wa_allocvalue.
      endloop.

    else.

      call function 'BALW_BAPIRETURN_GET2'
        exporting
          type   sy-msgty
          cl     sy-msgid
          number sy-msgno
          par1   sy-msgv1
          par2   sy-msgv2
          par3   sy-msgv3
          par4   sy-msgv4
        importing
          return wa_ret.
      append wa_ret to git_ret.
    endif.

  endif.

  return[] git_ret[].

endfunction.



*&---------------------------------------------------------------------*
*&      Form  sub_get_chades
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
     -->I_CHARA    text
     -->I_VALUE    text
     -->I_LANG     text
     -->O_TYPE     text
     -->O_ANZST    text
     -->O_ANZDZ    text
     -->O_VDES     text
*----------------------------------------------------------------------*
form sub_get_chades  using i_chara i_value i_lang
                     changing o_type
                              o_anzst
                              o_anzdz
                              o_vdes
                              o_cdes.
  data:katalogart like cabn-katalogart,
       auswahlmge like cabn-auswahlmge,
       bewertung like qpac-bewertung,
       kurztext like qpct-kurztext.

  clearkatalogart, auswahlmge ,bewertung kurztext.
  select single anzst anzdz atfor atbez katalogart auswahlmge
    into (o_anzst, o_anzdz, o_type, o_cdes katalogart auswahlmge) from cabn
    inner join cabnt on cabn~atinn cabnt~atinn and cabn~adzhl cabnt~adzhl and cabnt~spras i_lang
  where cabn~atnam i_chara.

  if o_type 'CHAR' and i_value <> ''.
*取目录特性的特性值描述
    if katalogart <> '' and auswahlmge <> ''.
      select single bewertung kurztext into (bewertung,kurztext)
        from qpac inner join qpct on qpac~katalogart qpct~katalogart and qpac~codegruppe qpct~codegruppe
                                 and qpac~code qpct~code
        where qpac~katalogart katalogart and qpac~auswahlmge auswahlmge and qpct~sprache '1'
          and qpac~codegruppe i_value(8and qpac~code i_value+9(4).
     concatenate bewertung kurztext into o_vdes separated by space.
    else.
*取单个特性值描述和类型
    select single atwtb into o_vdes
      from cabn
      inner join cawn on cabn~atinn cawn~atinn
      inner join cawnt on cawn~atinn cawnt~atinn
             and cawn~atzhl cawnt~atzhl
             and cawnt~spras i_lang
      where cabn~atnam i_chara and
            cawn~atwrt i_value.
    endif.
  endif.
endform                   "sub_get_chades

 

调用BAPI

  *&---------------------------------------------------------------------*
*&      Form  SUB_GET_CHAR 取得批次特性
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  SUB_GET_CHAR
*&---------------------------------------------------------------------*
      text
*----------------------------------------------------------------------*
 -->  p1        text
 <--  p2        text
*----------------------------------------------------------------------*
form sub_get_char .
  datatemp_p1 type decimals 1,
        temp_p2 type decimals 2,
        temp_p4 type decimals 4,
        temp_p type decimals 3.
  data:key_object like bapi1003_key-object.
  datalit_return like bapiret2 occurs 0,
      lit_list like bapi1003_alloc_list occurs 0,
      lit_value like zcu_allocvalues occurs 0 with header line.
  concatenate itab-matnr itab-charg into key_object.
  call function 'Z_GET_OBJCL_OR_CONFIGURATION'
    exporting
      get_type          'O'
      i_objectkey       key_object
      i_objecttable     'MCH1'
      i_objectclasstype '023'
    tables
      return            lit_return
      alloclist         lit_list
      allocvalue        lit_value.

  clear lit_return.
  clear lit_list.
  clear lit_value.

  read table lit_value with key charc '70000'.
  if sy-subrc 0.
    itab-yongt lit_value-char_value_des.
    clear lit_value.  "用途
  endif.

  read table lit_value with key charc '000501'.
  if sy-subrc 0.
    itab-chand lit_value-char_value.
    clear lit_value.  "产地
  endif.

endform                   SUB_GET_CHAR

 

 

2013/02/20ADD

批次特性值表ausp:

http://s16/mw690/69f04819g7bd081db894f&690批次特性值调用与BAPI封装" TITLE="[ABAP] 批次特性值调用与BAPI封装" />

http://s13/mw690/69f04819g7bd08261fe5c&690批次特性值调用与BAPI封装" TITLE="[ABAP] 批次特性值调用与BAPI封装" />

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有