FUNCTION ZBAPI_NETWORK_COMP_ADD.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" INPUT STRUCTURE ZBAPI_NETWORK_COMP_ADD OPTIONAL
*" OUTPUT STRUCTURE ZBAPI_NETWORK_COMP_ADD_OUT OPTIONAL
*"----------------------------------------------------------------------
DATA: G_INFO TYPE STRING.
DATA:FLAG(1),
m_MESSAGE(100),
m_DATE TYPE D.
DATA:NUMBER TYPE BAPI_NETWORK_LIST-NETWORK,
I_COMPONENTS_ADD TYPE TABLE OF BAPI_NETWORK_COMP_ADD WITH HEADER LINE,
E_MESSAGE_TABLE TYPE TABLE OF BAPI_METH_MESSAGE WITH HEADER LINE.
DATA:t_OBJNR TYPE AFVC-OBJNR,
m_STAT TYPE JEST-STAT.
LOOP AT INPUT.
MOVE-CORRESPONDING INPUT TO OUTPUT.
NUMBER = INPUT-AUFNR.
* 以下代码如果活动TECO之后,则不允许新增物料
CLEAR t_OBJNR.
CLEAR m_STAT.
SELECT SINGLE
B~OBJNR
INTO t_OBJNR
FROM CAUFV AS A INNER JOIN AFVC AS B ON A~AUFPL = B~AUFPL
WHERE A~AUFNR = INPUT-AUFNR
AND B~VORNR = INPUT-ACTIVITY.
SELECT SINGLE
A~STAT
INTO m_STAT
FROM JEST AS A INNER JOIN TJ02T AS B ON A~STAT = B~ISTAT AND B~SPRAS = ‘1‘
WHERE A~OBJNR = t_OBJNR
AND B~TXT04 = ‘TECO‘
AND A~INACT <> ‘X‘.
IF m_STAT <> ‘‘.
* 在结尾的时候,保存记录
* AT END OF AUFNR.
CALL FUNCTION ‘BAPI_NETWORK_COMP_ADD‘
EXPORTING
NUMBER = NUMBER
TABLES
I_COMPONENTS_ADD = I_COMPONENTS_ADD
E_MESSAGE_TABLE = E_MESSAGE_TABLE.
CLEAR E_MESSAGE_TABLE.
LOOP AT E_MESSAGE_TABLE WHERE MESSAGE_TYPE = ‘E‘ OR MESSAGE_TYPE = ‘A‘.
FLAG = ‘X‘.
OUTPUT-FLAG = ‘E‘.
CONCATENATE OUTPUT-MESSAGE ‘&‘ E_MESSAGE_TABLE-MESSAGE_TEXT INTO OUTPUT-MESSAGE.
ENDLOOP.
IF FLAG = ‘X‘.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘.
WAIT UP TO 1 SECONDS.
OUTPUT-FLAG = ‘S‘.