错误消息KI 180:You must enter a company code for transaction Create sales document
代码:
REPORT zcreate_so.
DATA: ls_header TYPE bapisdhd1,
ls_headerx TYPE bapisdhd1x,
lt_bapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
ls_header-serv_date = '20200101'.
ls_header-doc_type = 'TA'.
ls_headerx-doc_type = 'X'.
ls_headerx-updateflag = 'U'.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in = ls_header
sales_header_inx = ls_headerx
int_number_assignment = 'X'
TABLES
return = lt_bapiret2.
LOOP AT lt_bapiret2 ASSIGNING FIELD-SYMBOL(<return>) WHERE type = 'E'.
WRITE:/ 'Error:', <return>-message COLOR COL_NEGATIVE.
RETURN.
ENDLOOP.
通过调试,发现错误消息是在下面的函数里抛出的:
原因:事务码VA03,打开一个已有的Sales Order,Goto->Header->Billing, 查看Company code:
得知Company code存储于表VBAK的字段BUKRS里。
解决方案:上述代码加上下面两行,问题即解决:
ls_header-comp_cde_b = '0001'.
ls_headerx-comp_cde_b = 'X'.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":