【ABAP】BAPI资产凭证自动生成的问题和解决办法

BAPI自动生成资产凭证时,提示错误: E AU 33 无法找到区域 01 的帐户 ‘对应科目: 购置价值记帐’。
DEBUG中发现函数BAPI_ACC_DOCUMENT_POST中变量obj_key若为空值,就会产生错误。
所以添加了下面一段代码。

call function 'OWN_LOGICAL_SYSTEM_GET' "当前逻辑系统
          importing
              own_logical_system = l_awsys
          exceptions
              own_logical_system_not_defined = 1.
  refresh itab_t003.
  clear itab_t003.

  select * into corresponding fields of table itab_t003
    from t003
    where numkr = '01'.

  loop at itab_t003.
    s_blart-sign = 'I'.
    s_blart-option = 'EQ'.
    s_blart-low = itab_t003-blart.
    append s_blart.
    clear itab_t003.
  endloop.

  clear l_belnr.
  select single max( belnr ) from bkpf into l_belnr
  where bukrs = zbapi_f_02_header-bukrs
  and gjahr = zbapi_f_02_header-budat+0(4)
  and blart in s_blart.

  l_belnr = l_belnr + 1.
  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = l_belnr
    importing
      output = l_belnr.


  call function 'RANDOM_C' "参考字段加上2位随机码与正常凭证区分
  exporting
  len_min = 2
  len_max = 2
  char_max = 27
  importing
  rnd_value = rnd_value.

  concatenate l_belnr zbapi_f_02_header-bukrs zbapi_f_02_header-budat+0(4) rnd_value into lt_documentheader-obj_key.

  lt_documentheader-obj_type = 'ZBKPF'.
  lt_documentheader-obj_sys = l_awsys.
  lt_documentheader-bus_act = 'RMWE'.
  

部分字段的定义如下:

data:l_awsys type bkpf-awsys.
 data: begin of itab_t003 occurs 0.
  data:blart like t003-blart.
  data: end of itab_t003.
  ranges:s_blart for t003-blart.
  data: rnd_value type datatype-char0128.

通过这段代码赋值给obj_key一个值,凭证号+公司+年度+一个随机数,经过测试,成功生成obj_key。

你可能感兴趣的:(abap,abap,sap)