配额 EQUK EQUP
*--------------------------------------------------------------------*
FORM FRM_SYNQUOTA.
DATA:LTOKEN TYPE STRING.
DATA: LL_LINES(10),"行数
LL_TABIX(10),"循环标号
LL_PECNT TYPE P LENGTH 6 DECIMALS 2, "百分比
LL_PECET(6),"百分数
LL_TEXT(40)."消息
CLEAR: LL_LINES,LL_TABIX,LL_PECNT,LL_PECET,LL_TEXT.
DATA: LEN TYPE I, "发送报文长度
LEN_STRING TYPE STRING,
URL TYPE STRING, "接口地址
SQLSTR TYPE STRING,
LV_SERVER_NAME TYPE ZE_SERVER_NAME,
POST_STRING TYPE STRING,
RESULT TYPE STRING,
LTIMEEND TYPE STRING, "时间戳结束
LTIMEST TYPE STRING. "时间戳开始
DATA: L_JSON_ROOT_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: L_ERRORTYPE_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: L_SAP_TEST_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: L_ERRORNO_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: L_SAP_TEST_ROW1_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: L_SAP_TEST_FUNC_ID_OBJECT TYPE REF TO ZCL_MDP_JSON_NODE.
DATA: LTAR TYPE TABLE OF ZCL_MDP_JSON_NODE=>TYP_ARRAY_CHILDREN.
DATA: LTARS TYPE TABLE OF ZCL_MDP_JSON_NODE=>TYP_ARRAY_CHILDREN.
DATA:LT_RETURN TYPE BAPIRETM.
IF S_SRCMAT IS INITIAL AND S_SRCWRK IS INITIAL.
SQLSTR = 'SELECT * FROM EQUK WHERE CLIENT = 800 AND VDATU <= ' && SY-DATUM && ' and BDATU >= ' && SY-DATUM .
ELSE.
SQLSTR = 'SELECT * FROM BUT000 WHERE CLIENT = 800 AND VDATU <= ' && SY-DATUM && ' and BDATU >= ' && SY-DATUM .
IF S_QAMAT IS NOT INITIAL.
IF S_QAMAT-HIGH IS INITIAL.
S_QAMAT-HIGH = S_QAMAT-LOW.
ENDIF.
SQLSTR = SQLSTR && ' AND MATNR BETWEEN ''' && S_QAMAT-LOW && ''' AND ''' && S_QAMAT-HIGH && ''''.
ENDIF.
IF S_QAWRK IS NOT INITIAL.
IF S_QAWRK-HIGH IS INITIAL.
S_QAWRK-HIGH = S_QAWRK-LOW.
ENDIF.
SQLSTR = SQLSTR && ' AND WERKS BETWEEN ''' && S_QAWRK-LOW && ''' AND ''' && S_QAWRK-HIGH && ''''.
ENDIF.
ENDIF.
PERFORM FRM_SYNOBJ(ZABAP_COMMON_PROGRAM) USING LV_URL_STR SQLSTR CHANGING L_JSON_ROOT_OBJECT.
DATA: L_STRING TYPE STRING.
DATA:CNT TYPE I.
DATA:LMATNR TYPE MARA-MATNR,
LWERKS TYPE WERKS_D,
LQUNUM TYPE EQUP-QUMNG,
LLIFNR TYPE LFA1-LIFNR.
DATA:LT_EORDU LIKE TABLE OF EORDU WITH HEADER LINE.
DATA:PINDX TYPE I.
DATA:LXEQUK TYPE TABLE OF EQUKU WITH HEADER LINE,
LXUEQUP TYPE TABLE OF UEQUP WITH HEADER LINE,
LYEQUK TYPE TABLE OF EQUKU WITH HEADER LINE,
LYUEQUP TYPE TABLE OF UEQUP WITH HEADER LINE.
L_ERRORTYPE_OBJECT = L_JSON_ROOT_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'RESULT').
LTAR = L_ERRORTYPE_OBJECT->ARRAY_CHILDREN().
DESCRIBE TABLE LTAR LINES CNT.
LOOP AT LTAR INTO DATA(LSAR).
CLEAR:LXEQUK[],LXUEQUP[],LYEQUK[],LYUEQUP[].
PINDX = SY-TABIX.
L_SAP_TEST_OBJECT = LSAR-NODE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'MATNR' ).
LMATNR = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'WERKS' ).
LWERKS = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'QUNUM' ).
LQUNUM = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
SELECT SINGLE MATNR FROM MARC WHERE MATNR = @LMATNR AND WERKS = @LWERKS
INTO @DATA(LSMATNR).
IF LSMATNR IS INITIAL.
WRITE :/ '物料' && LMATNR && '在工厂' && LWERKS && '中不存在'.
CONTINUE.
ENDIF.
LXEQUK-MATNR = LMATNR.
LXEQUK-WERKS = LWERKS.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'BDATU' ).
LXEQUK-BDATU = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'VDATU' ).
LXEQUK-VDATU = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'SCMNG' ).
LXEQUK-SCMNG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
LXEQUK-ERDAT = SY-DATUM.
LXEQUK-ERNAM = SY-UNAME.
SELECT SINGLE * FROM EQUK WHERE MATNR = @LMATNR AND WERKS = @LWERKS AND BDATU >= @SY-DATUM AND VDATU <= @SY-DATUM INTO @DATA(LSEQUK).
IF LSEQUK IS NOT INITIAL AND SY-SUBRC = 0.
LXEQUK-KZ = 'U'.
LXEQUK-QUNUM = LSEQUK-QUNUM.
APPEND LXEQUK TO LYEQUK.
ELSE.
LXEQUK-KZ = 'I'.
APPEND LXEQUK.
ENDIF.
SQLSTR = 'SELECT * FROM EQUP WHERE MANDT = 800 AND QUNUM = ' && LQUNUM .
PERFORM FRM_SYNOBJ(ZABAP_COMMON_PROGRAM) USING LV_URL_STR SQLSTR CHANGING L_JSON_ROOT_OBJECT.
L_ERRORTYPE_OBJECT = L_JSON_ROOT_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'RESULT').
LTARS = L_ERRORTYPE_OBJECT->ARRAY_CHILDREN().
LOOP AT LTARS INTO DATA(LSTARS).
PINDX = SY-TABIX.
L_SAP_TEST_OBJECT = LSTARS-NODE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'BESKZ' ).
LXUEQUP-BESKZ = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'SOBES' ).
LXUEQUP-SOBES = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'LIFNR' ).
LXUEQUP-LIFNR = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
SELECT SINGLE * FROM LFA1 WHERE LIFNR = @LXUEQUP-LIFNR
INTO @DATA(LSLFA1).
IF LSLFA1 IS INITIAL.
WRITE :/ '供应商' && LXUEQUP-LIFNR && '不存在,请先同步'.
CLEAR LSLFA1.
CONTINUE.
ENDIF.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'BEWRK' ).
LXUEQUP-BEWRK = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'QUOTE' ).
LXUEQUP-QUOTE = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'QUBMG' ).
LXUEQUP-QUBMG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'QUMNG' ).
LXUEQUP-QUMNG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'MAXMG' ).
LXUEQUP-MAXMG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'VERID' ).
LXUEQUP-VERID = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'MAXLS' ).
LXUEQUP-MAXLS = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'MINLS' ).
LXUEQUP-MINLS = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'RDPRF' ).
LXUEQUP-RDPRF = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'KZEIN' ).
LXUEQUP-KZEIN = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'ABRMG' ).
LXUEQUP-ABRMG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'ABPER' ).
LXUEQUP-ABPER = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'ABANZ' ).
LXUEQUP-ABANZ = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'PREIH' ).
LXUEQUP-PREIH = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'EMATN' ).
LXUEQUP-EMATN = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'PLIFZ' ).
LXUEQUP-PLIFZ = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.
IF LXEQUK-KZ = 'I'.
LXUEQUP-KZ = 'I'.
APPEND LXUEQUP.
ELSE.
SELECT SINGLE * FROM EQUP WHERE QUNUM = @LXEQUK-QUNUM AND LIFNR = @LXUEQUP-LIFNR
INTO @DATA(LSEQUP).
IF LSEQUP IS INITIAL.
LXUEQUP-KZ = 'I'.
APPEND LXUEQUP.
ELSE.
LXUEQUP-KZ = 'U'.
LXUEQUP-QUPOS = LSEQUP-QUPOS.
LXUEQUP-QUNUM = LXEQUK-QUNUM.
APPEND LXUEQUP TO LYUEQUP.
ENDIF.
ENDIF.
ENDLOOP.
CALL FUNCTION 'ZRFC_MM_QUOTA_BAPI'
TABLES
XEQUK = LXEQUK
XEQUP = LXUEQUP.
* YEQUK =
* YEQUP =
ENDLOOP.
ENDFORM.