为了方便用 sql 来取出订单的行文本和特性值 ,写了一个 bapi 把取出值并写入一个自定义表中。
然后在 订单保存的出口中调用此 bapi,以后只要订单有变化就会自动更新的自定义表中。
FUNCTION ZBAPI_READ_VBAPEX.
*"----------------------------------------------------------------------
* "
*"*"Local interface:
*" IMPORTING
*" VALUE(VBELN) TYPE VBELN_VA
*" VALUE(POSNR) TYPE POSNR_VA
*" VALUE(CUOBJ) TYPE CUOBJ
*" VALUE(AUTOSAVE) TYPE CHAR1 "是否自动存入表里
*" EXPORTING
*" VALUE(VBAPEX) TYPE ZSDVBAP_EX
*"----------------------------------------------------------------------
tables: ZSDVBAP_EX.
DATA: itab_sohead like thead ,
itab_soline like tline occurs 0 with header line .
DATA: p_Name Like THEAD-TDNAME,
p1 LIKE VBELN,
p2 LIKE POSNR .
DATA:tmp TYPE String value ''.
data:begin of itmText ,
ITMTXT1 like ZSDVBAP_EX-ITMTXT1,
ITMTXT2 like ZSDVBAP_EX-ITMTXT2,
ITMTXT3 like ZSDVBAP_EX-ITMTXT3,
end of itmText .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = VBELN
IMPORTING
output = p1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = POSNR
IMPORTING
output = p2.
CONCATENATE p1 p2 into p_Name.
" ID :0001 Name: 销售单+行项目号 0000110298000010 object: VBBP
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = '0001'
LANGUAGE = '1'
NAME = p_Name
OBJECT = 'VBBP'
IMPORTING
HEADER = itab_sohead
TABLES
LINES = itab_soline
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
Loop at itab_soline.
CONCATENATE ' ' tmp itab_soline-tdline INTO tmp.
endloop .
IF tmp <> ''.
move tmp to itmText .
move-CORRESPONDING itmText to VBAPEX.
else.
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = '0001'
LANGUAGE = 'E'
NAME = p_Name
OBJECT = 'VBBP'
IMPORTING
HEADER = itab_sohead
TABLES
LINES = itab_soline
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
Loop at itab_soline.
CONCATENATE ' ' tmp itab_soline-tdline INTO tmp.
endloop .
move tmp to itmText .
move-CORRESPONDING itmText to VBAPEX.
endif.
clear tmp.
if CUOBJ = 0.
select single cuobj into CUOBJ from vbap where vbeln = p1 and posnr = p2 .
endif.
if CUOBJ <> 0.
DATA: i_configuration LIKE api_value OCCURS 0 WITH HEADER LINE.
DATA: stratwtb(50) TYPE c.
CALL FUNCTION 'VC_I_GET_CONFIGURATION'
EXPORTING
instance = CUOBJ "特性值
language = sy-langu
print_sales = 'X'
TABLES
configuration_idoc = i_configuration
EXCEPTIONS
OTHERS = 4.
DATA: idx TYPE i value 1.
LOOP AT i_configuration .
CASE idx.
WHEN 1.
VBAPEX-ATWTB1 = i_configuration-ATWTB.
CONCATENATE ' ' i_configuration-ATBEZ INTO tmp.
WHEN 2.
VBAPEX-ATWTB2 = i_configuration-ATWTB.
CONCATENATE tmp ',' i_configuration-ATBEZ INTO tmp.
WHEN 3.
VBAPEX-ATWTB3 = i_configuration-ATWTB.
CONCATENATE tmp ',' i_configuration-ATBEZ INTO tmp.
WHEN 4.
VBAPEX-ATWTB4 = i_configuration-ATWTB.
CONCATENATE tmp ',' i_configuration-ATBEZ INTO tmp.
WHEN OTHERS.
ENDCASE.
idx = idx + 1.
ENDLOOP.
endif.
VBAPEX-mandt = sy-mandt.
VBAPEX-VBELN = p1.
VBAPEX-POSNR = p2.
VBAPEX-ATDESC = tmp .
if AUTOSAVE = 'X' .
move VBAPEX to ZSDVBAP_EX .
delete from ZSDVBAP_EX where vbeln = p1 and posnr = p2 .
insert ZSDVBAP_EX.
commit work.
endif.
ENDFUNCTION.
--------------------------------------------------------------------------------------------------------------------------
出口调用: