货源同步 EORD
FORM FRM_SYNEORD.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: LBUTPARTNER LIKE BUT000-PARTNER.DATA: LT_DATA TYPE CVIS_EI_EXTERN_T,LT_DATAU TYPE CVIS_EI_EXTERN_T,LS_DATA TYPE CVIS_EI_EXTERN,LT_CMDSALE TYPE CMDS_EI_SALES_T,LS_CMDSALE TYPE CMDS_EI_SALES,LS_PAADR TYPE BUS_EI_BUPA_ADDRESS,LS_BANK TYPE BUS_EI_BUPA_BANKDETAIL,LS_SALES TYPE CMDS_EI_SALES,LT_SALES TYPE CMDS_EI_SALES_T,LS_TAX TYPE CMDS_EI_TAX_IND,LT_TAX TYPE CMDS_EI_TAX_IND_T.DATA: LV_GUID TYPE GUID_16,LV_BPGUID TYPE BU_PARTNER_GUID.DATA:LT_ROLES TYPE BUS_EI_BUPA_ROLES_T,LS_ROLES TYPE BUS_EI_BUPA_ROLES,LT_BANK TYPE TABLE OF BUS_EI_BUPA_BANKDETAIL,LT_RETURN TYPE BAPIRETM.DATA:BEGIN OF LT_BUT021 OCCURS 0 ,PARTNER LIKE BUT020-PARTNER,ADDRNUMBER LIKE BUT020-ADDRNUMBER,ADDRESS_GUID LIKE BUT020-ADDRESS_GUID,ADR_KIND LIKE BUT021_FS-ADR_KIND,END OF LT_BUT021.IF S_SRCMAT IS INITIAL AND S_SRCWRK IS INITIAL.SQLSTR = 'SELECT DISTINCT MATNR,WERKS,LIFNR,VDATU,BDATU,EKORG,RESWK,AUTET FROM EORD WHERE CLIENT = 800 AND VDATU <= ' && SY-DATUM && ' and BDATU >= ' && SY-DATUM .ELSE.SQLSTR = 'SELECT DISTINCT MATNR,WERKS,LIFNR,VDATU,BDATU,EKORG,RESWK,AUTET FROM BUT000 WHERE CLIENT = 800 AND VDATU <= ' && SY-DATUM && ' and BDATU >= ' && SY-DATUM .IF S_SRCMAT IS NOT INITIAL.IF S_SRCMAT-HIGH IS INITIAL.S_SRCMAT-HIGH = S_SRCMAT-LOW.ENDIF.SQLSTR = SQLSTR && ' AND MATNR BETWEEN ''' && S_SRCMAT-LOW && ''' AND ''' && S_SRCMAT-HIGH && ''''.ENDIF.IF S_SRCWRK IS NOT INITIAL.IF S_SRCWRK-HIGH IS INITIAL.S_SRCWRK-HIGH = S_SRCWRK-LOW.ENDIF.SQLSTR = SQLSTR && ' AND WERKS BETWEEN ''' && S_SRCWRK-LOW && ''' AND ''' && S_SRCWRK-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,LLIFNR TYPE LFA1-LIFNR.DATA:LT_EORDU LIKE TABLE OF EORDU WITH HEADER LINE.DATA:PINDX TYPE I.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).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.SELECT SINGLE MATNR FROM MARA WHERE MATNR = @LMATNR INTO @DATA(LSMATNR).IF LSMATNR IS INITIAL.WRITE :/ '物料' && LMATNR && '尚不存在于本系统,请先同步物料'.CLEAR LSMATNR.CONTINUE.ENDIF.SQLSTR = 'SELECT MATNR,WERKS,LIFNR,VDATU,BDATU,EKORG,RESWK,AUTET FROM EORD WHERE CLIENT = 800 AND VDATU <= ' && SY-DATUM && ' and BDATU >= ' && SY-DATUM&& ' AND WERKS = ' && LWERKS && ' AND MATNR = ' && LSMATNR .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(LSLTARS).L_SAP_TEST_OBJECT = LSLTARS-NODE.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'LIFNR' ).LLIFNR = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.SELECT SINGLE LIFNR FROM LFA1 WHERE LIFNR = @LLIFNR INTO @DATA(LSLIFNR).IF LSLIFNR IS INITIAL.WRITE :/ '供应商' && LSLIFNR && '尚不存在于本系统,请先同步BP'.CLEAR LSLIFNR.CONTINUE.ENDIF.LT_EORDU-MATNR = LMATNR.LT_EORDU-WERKS = LWERKS.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'VDATU' ).LT_EORDU-VDATU = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'BDATU' ).LT_EORDU-BDATU = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.LT_EORDU-LIFNR = LLIFNR.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'EKORG' ).LT_EORDU-EKORG = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'RESWK' ).LT_EORDU-RESWK = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.L_SAP_TEST_FUNC_ID_OBJECT = L_SAP_TEST_OBJECT->OBJECT_GET_CHILD_NODE( KEY = 'AUTET' ).LT_EORDU-AUTET = L_SAP_TEST_FUNC_ID_OBJECT->VALUE.LT_EORDU-ERDAT = SY-DATUM.LT_EORDU-ERNAM = SY-UNAME.SELECT COUNT(*) INTO @DATA(L_COUNT)FROM EORDWHERE MATNR EQ @LMATNRAND WERKS EQ @LWERKSAND LIFNR EQ @LLIFNR.IF L_COUNT >= 1.SELECT ZEORD INTO @DATA(L_ZEORD)FROM EORDUP TO 1 ROWSWHERE MATNR EQ @LMATNRAND WERKS EQ @LWERKSAND LIFNR EQ @LLIFNRORDER BY VDATU DESCENDING.ENDSELECT.LT_EORDU-ZEORD = L_ZEORD.CLEAR:L_COUNT.ENDIF.IF L_ZEORD IS INITIAL.LT_EORDU-KZ = 'I'.ELSE.LT_EORDU-KZ = 'U'.ENDIF.CLEAR:L_ZEORD.APPEND LT_EORDU.CALL FUNCTION 'ME_INITIALIZE_SOURCE_LIST'.CALL FUNCTION 'ME_DIRECT_INPUT_SOURCE_LIST'EXPORTINGI_MATNR = LMATNRI_WERKS = LWERKS
* I_MT06E =
* I_NO_MATERIAL_READ =
* ACTIVITY = 'V'
* I_VORGA =
* I_LOGSY =TABLEST_EORD = LT_EORDU[]EXCEPTIONSPLANT_MISSING = 1MATERIAL_MISSING = 2OTHERS = 3.IF SY-SUBRC <> 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ELSE.CALL FUNCTION 'ME_POST_SOURCE_LIST_NEW'EXPORTINGI_MATNR = LMATNR.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = 'X'.ENDIF.ENDLOOP.ENDLOOP.
ENDFORM.