记账部分写的比较烂,贴出来主要是分享调用接口的方法
*&---------------------------------------------------------------------*
*& Report ZFI_RESTFUL_JSON
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZFI_RESTFUL_JSON.
TABLES:SSCRFIELDS.
TYPE-POOLS : SLIS.
DATA:GT_ITAB TYPE TABLE OF ZFIT011.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:
P_CLIENT TYPE CHAR20 OBLIGATORY DEFAULT 'DEFAULT_SOB',
P_STADAT TYPE AUGCP DEFAULT SY-DATUM,
P_ENDDAT TYPE AUGCP DEFAULT SY-DATUM,
P_TIMES TYPE ERZET,
P_TIMEE TYPE ERZET DEFAULT '235959'.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
PERFORM FRM_ALV_SHOW.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA .
"TOKEN接口获取动态UUID参数
DATA: LO_HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT,
LV_SERVICE TYPE STRING,
LV_RESULT TYPE STRING,
LO_IXML TYPE REF TO IF_IXML,
LO_STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY,
LO_ISTREAM TYPE REF TO IF_IXML_ISTREAM,
LO_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
LO_PARSER TYPE REF TO IF_IXML_PARSER.
IF SY-MANDT NE '888'.
LV_SERVICE = 'http://****'.
ELSE.
LV_SERVICE = 'http://*****'.
ENDIF.
CL_HTTP_CLIENT=>CREATE_BY_URL(
EXPORTING
URL = LV_SERVICE
IMPORTING
CLIENT = LO_HTTP_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4 ).
LO_HTTP_CLIENT->PROPERTYTYPE_LOGON_POPUP = LO_HTTP_CLIENT->CO_DISABLED.
IF SY-MANDT NE '888'.
CALL METHOD LO_HTTP_CLIENT->AUTHENTICATE(
EXPORTING
* client = ''
* proxy_authentication = 'X'
USERNAME = '9896ccc'
PASSWORD = 'YTg1Y2R'
* LANGUAGE = 'E'
).
ELSE.
CALL METHOD LO_HTTP_CLIENT->AUTHENTICATE(
EXPORTING
* client = ''
* proxy_authentication = 'X'
USERNAME = '460930b3-d'
PASSWORD = 'YWI0M'
* LANGUAGE = 'E'
).
ENDIF.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_METHOD( 'POST' ).
LO_HTTP_CLIENT->SEND(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2 ).
LO_HTTP_CLIENT->RECEIVE(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3 ).
* * 接收返回消息
DATA:
LV_ERROCODE TYPE SYSUBRC,
LV_MESSAGE TYPE STRING.
CALL METHOD LO_HTTP_CLIENT->GET_LAST_ERROR
IMPORTING
CODE = LV_ERROCODE
MESSAGE = LV_MESSAGE.
CLEAR LV_RESULT .
LV_RESULT = LO_HTTP_CLIENT->RESPONSE->GET_CDATA( ).
"解析数据
DATA: BEGIN OF LTY_TOKEN,
ACCESS_TOKEN TYPE STRING,
TOKEN_TYPE TYPE STRING,
EXPIRES_IN TYPE STRING,
SCOPE TYPE STRING,
TENANTID TYPE STRING,
END OF LTY_TOKEN.
DATA:LS_TOKEN LIKE LTY_TOKEN,
LT_TOKEN LIKE TABLE OF LTY_TOKEN,
LO_JSON_DES TYPE REF TO CL_TREX_JSON_DESERIALIZER.
*JSON->内表
/UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON = LV_RESULT
CHANGING DATA = LS_TOKEN ).
"关闭接口
CALL METHOD LO_HTTP_CLIENT->CLOSE.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"获取业务端数据
DATA:L_AUTHORIZATION TYPE STRING.
CONCATENATE LS_TOKEN-TOKEN_TYPE LS_TOKEN-ACCESS_TOKEN INTO L_AUTHORIZATION SEPARATED BY ''.
IF SY-MANDT NE '888'.
LV_SERVICE = 'http://apistage.huilianyi.com/gateway/api/open/ledger/journal/incremental/query'.
ELSE.
LV_SERVICE = 'http://api.huilianyi.com/gateway/api/open/ledger/journal/incremental/query'.
ENDIF.
CL_HTTP_CLIENT=>CREATE_BY_URL(
EXPORTING
URL = LV_SERVICE
IMPORTING
CLIENT = LO_HTTP_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4 ).
LO_HTTP_CLIENT->PROPERTYTYPE_LOGON_POPUP = LO_HTTP_CLIENT->CO_DISABLED.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'Content-Type'
VALUE = 'application/JSON; charset=utf-8'.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'Authorization'
VALUE = L_AUTHORIZATION.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_METHOD( 'POST' ).
"编辑请求数据
DATA: BEGIN OF LTY_SENDDATA,
* companycode TYPE string,
SETOFBOOKSCODE TYPE STRING,
CREATEDDATESTART TYPE STRING,
CREATEDDATEEND TYPE STRING,
PAGE TYPE STRING,
SIZE TYPE STRING,
END OF LTY_SENDDATA.
DATA:LS_SENDDATA LIKE LTY_SENDDATA.
* ls_senddata-companycode = p_bukrs.
LS_SENDDATA-SETOFBOOKSCODE = P_CLIENT.
DATA:L_DATE TYPE STRING,L_TIME TYPE STRING.
CONCATENATE P_STADAT+0(4) '-' P_STADAT+4(2) '-' P_STADAT+6(2) INTO L_DATE.
CONCATENATE P_TIMES+0(2) ':' P_TIMES+2(2) ':' P_TIMES+4(2) INTO L_TIME.
CONCATENATE L_DATE L_TIME INTO LS_SENDDATA-CREATEDDATESTART SEPARATED BY ' '.
CONCATENATE P_ENDDAT+0(4) '-' P_ENDDAT+4(2) '-' P_ENDDAT+6(2) INTO L_DATE.
CONCATENATE P_TIMEE+0(2) ':' P_TIMEE+2(2) ':' P_TIMEE+4(2) INTO L_TIME.
CONCATENATE L_DATE L_TIME INTO LS_SENDDATA-CREATEDDATEEND SEPARATED BY ' '.
DATA LV_JSON TYPE STRING.
DATA: LEN TYPE I .
DATA:L_PAGE TYPE N VALUE '0'.
TYPES: BEGIN OF LTY_JSON,
MESSAGE TYPE STRING,
ERRORCODE TYPE STRING,
DATA TYPE ZREST001_T,
END OF LTY_JSON.
DATA:LT_JSON TYPE STANDARD TABLE OF LTY_JSON WITH HEADER LINE,
LS_JSON TYPE LTY_JSON,
LS_JSONDATA TYPE ZFIT012,
LS_ZFIT011 TYPE ZFIT011,
LS_ZFIT011_DEL TYPE ZFIT011,
LT_ZFIT011 TYPE TABLE OF ZFIT011,
LT_ZFIT011_DEL TYPE TABLE OF ZFIT011,
LT_ZFIT011_DELTMP TYPE TABLE OF ZFIT011,
LT_JSONDATA TYPE TABLE OF ZFIT012.
DATA:LT_ZFIT011TMP TYPE TABLE OF ZFIT011.
DO 10000 TIMES.
* LV_JSON = '{"setOfBooksCode":"DEFAULT_SOB","createdDateStart":"2018-09-08 04:53:46","createdDateEnd":"2019-09-26 09:53:46","page":"","size":"10"}'.
CONCATENATE '{"setOfBooksCode":"DEFAULT_SOB","createdDateStart":"' LS_SENDDATA-CREATEDDATESTART '","createdDateEnd":"' LS_SENDDATA-CREATEDDATEEND '","page":"' L_PAGE '","size":"100"}' INTO LV_JSON.
"SAP不区分大小写,JAVA/C会区分,一定让对方修改代码,不然只能SBB的拼接
* LV_JSON = /UI2/CL_JSON=>SERIALIZE( LS_SENDDATA ).
LEN = STRLEN( LV_JSON ) .
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_CDATA
EXPORTING
DATA = LV_JSON
OFFSET = 0
LENGTH = LEN.
LO_HTTP_CLIENT->SEND(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2 ).
LO_HTTP_CLIENT->RECEIVE(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3 ).
CLEAR:LV_RESULT,LS_JSON.
LV_RESULT = LO_HTTP_CLIENT->RESPONSE->GET_CDATA( ).
"解析JSON串
/UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON = LV_RESULT PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-CAMEL_CASE CHANGING DATA = LS_JSON ).
IF LS_JSON-DATA IS INITIAL.
EXIT.
ENDIF.
LOOP AT LS_JSON-DATA INTO LS_JSONDATA.
APPEND LS_JSONDATA TO LT_JSONDATA.
ENDLOOP.
L_PAGE = L_PAGE + 1.
ENDDO.
DATA:L_ZLINE TYPE ZFIT011-ZLINE.
SORT LT_JSONDATA BY XBLNR.
SELECT *
FROM ZFIT011
INTO CORRESPONDING FIELDS OF TABLE LT_ZFIT011_DEL
FOR ALL ENTRIES IN LT_JSONDATA
WHERE XBLNR = LT_JSONDATA-XBLNR.
LOOP AT LT_JSONDATA INTO LS_JSONDATA.
CLEAR LS_ZFIT011.
READ TABLE LT_ZFIT011_DEL INTO LS_ZFIT011_DEL WITH KEY XBLNR = LS_JSONDATA-XBLNR.
IF SY-SUBRC IS INITIAL AND LS_ZFIT011_DEL-BELNR NE ''.
APPEND LS_ZFIT011_DEL TO LT_ZFIT011_DELTMP.
CONTINUE.
ENDIF.
MOVE-CORRESPONDING LS_JSONDATA TO LS_ZFIT011.
L_ZLINE = L_ZLINE + 10.
LS_ZFIT011-ZLINE = L_ZLINE.
APPEND LS_ZFIT011 TO LT_ZFIT011.
AT END OF XBLNR.
CLEAR L_ZLINE.
ENDAT.
ENDLOOP.
MODIFY ZFIT011 FROM TABLE LT_ZFIT011.
IF SY-SUBRC IS INITIAL.
COMMIT WORK.
ENDIF.
DELETE ADJACENT DUPLICATES FROM LT_ZFIT011_DELTMP COMPARING XBLNR ZLINE.
IF LT_ZFIT011[] IS INITIAL AND LT_ZFIT011_DELTMP IS NOT INITIAL.
APPEND LINES OF LT_ZFIT011_DELTMP TO LT_ZFIT011TMP."展示
APPEND LINES OF LT_ZFIT011TMP[] TO GT_ITAB[].
ENDIF.
******************************************************************过账***************************************************************************
DATA:LS_EXCH_RATE TYPE BAPI1093_0.
DATA:L_DOCUMENTHEADER TYPE BAPIACHE09.
DATA:
LT_ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL09, "总帐科目项表类型
LT_ACCOUNTRECEIVABLE TYPE STANDARD TABLE OF BAPIACAR09, "客户项目表类型
LT_ACCOUNTPAYABLE TYPE STANDARD TABLE OF BAPIACAP09, "供应商项目表类型
LT_CURRENCYAMOUNT TYPE STANDARD TABLE OF BAPIACCR09. "货币项目表类型
DATA:
LW_ACCOUNTPAYABLE TYPE BAPIACAP09,
LW_ACCOUNTGL TYPE BAPIACGL09,
LW_CURRENCYAMOUNT TYPE BAPIACCR09,
L_OBJKEY TYPE BAPIACHE09-OBJ_KEY, "生成的凭证编号.
LI_RETURN TYPE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE, "凭证导入结果返回信息内表
L_ERRORMESSAGE TYPE STRING.
DATA:
WL_PZPLDR TYPE ZFIS_PZPLDR.
DATA: I_EXT2 TYPE TABLE OF BAPIPAREX,
I_EXT1 TYPE TABLE OF BAPIACEXTC,
WA_EXT1 TYPE BAPIACEXTC,
WA_EXT2 TYPE BAPIPAREX.
SORT LT_ZFIT011 BY XBLNR BUZEI.
LOOP AT LT_ZFIT011 INTO LS_ZFIT011.
APPEND LS_ZFIT011 TO LT_ZFIT011TMP.
*******************************************表 头 数 据****************************************************
CLEAR L_DOCUMENTHEADER.
L_DOCUMENTHEADER-BUS_ACT = 'RFBU'. "业务类型
L_DOCUMENTHEADER-COMP_CODE = LS_ZFIT011-BUKRS. "公司代码
L_DOCUMENTHEADER-USERNAME = 'JIANGZG'.
L_DOCUMENTHEADER-FISC_YEAR = LS_ZFIT011-GJAHR. "会计年度
L_DOCUMENTHEADER-DOC_DATE = LS_ZFIT011-BLDAT. "凭证日期
L_DOCUMENTHEADER-PSTNG_DATE = LS_ZFIT011-BUDAT. "过账日期
L_DOCUMENTHEADER-DOC_TYPE = LS_ZFIT011-BLART. "凭证类型
L_DOCUMENTHEADER-HEADER_TXT = LS_ZFIT011-BKTXT. "凭证抬头文本
*******************************************供 应 商****************************************************
* 科目类型为供应商
CLEAR:LW_ACCOUNTPAYABLE,LW_ACCOUNTGL.
IF LS_ZFIT011-BSCHL = '31' OR LS_ZFIT011-BSCHL = '39'.
* 构建供应商项目内表数据
CLEAR LW_ACCOUNTPAYABLE.
LW_ACCOUNTPAYABLE-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
IF LS_ZFIT011-HKONT = '22410200' OR LS_ZFIT011-HKONT = '22020200' OR LS_ZFIT011-HKONT = '22020100'.
LS_ZFIT011-HKONT = LS_ZFIT011-ZUONR.
ENDIF.
LW_ACCOUNTPAYABLE-VENDOR_NO = LS_ZFIT011-HKONT. "供应商或债权人的帐号
* UNPACK LW_ACCOUNTPAYABLE-VENDOR_NO TO LW_ACCOUNTPAYABLE-VENDOR_NO. "补前导零
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTPAYABLE-VENDOR_NO
IMPORTING
OUTPUT = LW_ACCOUNTPAYABLE-VENDOR_NO.
LW_ACCOUNTPAYABLE-SP_GL_IND = LS_ZFIT011-UMSKZ. "特殊总分类帐标志
* LW_ACCOUNTPAYABLE-GL_ACCOUNT = LS_ZFIT011-HKONT. "备选统驭科目
LW_ACCOUNTPAYABLE-TAX_CODE = LS_ZFIT011-MWSKZ. "销售税代码
LW_ACCOUNTPAYABLE-PROFIT_CTR = LS_ZFIT011-PRCTR. "利润中心
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTPAYABLE-PROFIT_CTR
IMPORTING
OUTPUT = LW_ACCOUNTPAYABLE-PROFIT_CTR.
LW_ACCOUNTPAYABLE-ITEM_TEXT = LS_ZFIT011-SGTXT. "行项目文本
LW_ACCOUNTPAYABLE-ALLOC_NMBR = LS_ZFIT011-ZUONR. "定位号(分配)
LW_ACCOUNTPAYABLE-COMP_CODE = LS_ZFIT011-BUKRS. "公司代码
LW_ACCOUNTPAYABLE-REF_KEY_1 = LS_ZFIT011-XREF1. "参考码1
LW_ACCOUNTPAYABLE-REF_KEY_2 = LS_ZFIT011-XREF2. "参考码2
LW_ACCOUNTPAYABLE-REF_KEY_3 = LS_ZFIT011-XREF3. "参考码3
APPEND LW_ACCOUNTPAYABLE TO LT_ACCOUNTPAYABLE.
****************************************************构建货币内表数据*****************************************************
LS_ZFIT011-DMBTR = - LS_ZFIT011-DMBTR.
IF LS_ZFIT011-WAERS EQ 'CNY' OR LS_ZFIT011-WAERS EQ 'RMB'.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '00'. "
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = LS_ZFIT011-WAERS. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "原币金额
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
ELSE.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '00'. "
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = LS_ZFIT011-WAERS. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "原币金额(外币)
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
IF LS_ZFIT011-DMBTR IS NOT INITIAL.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '10'.
"
CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
EXPORTING
RATE_TYPE = 'M'
FROM_CURR = LS_ZFIT011-WAERS
TO_CURRNCY = 'CNY'
DATE = SY-DATUM
IMPORTING
EXCH_RATE = LS_EXCH_RATE
* RETURN =
.
IF SY-SUBRC IS INITIAL.
LW_CURRENCYAMOUNT-EXCH_RATE = LS_EXCH_RATE-EXCH_RATE.
ENDIF.
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "本位币金额(人民币)
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
ENDIF.
ENDIF.
********************************************** 总 账 ****************************************************
* 科目类型为总分类帐科目、资产或物料
ELSEIF LS_ZFIT011-BSCHL = '40'.
* 构建总账科目项内表数据
CLEAR LW_ACCOUNTGL.
LW_ACCOUNTGL-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
* lw_accountgl-acct_type = LS_ZFIT011-koart. "科目类型
IF LS_ZFIT011-HKONT = '22410200' OR LS_ZFIT011-HKONT = '22020200' OR LS_ZFIT011-HKONT = '22020100'.
LS_ZFIT011-HKONT = LS_ZFIT011-ZUONR.
ENDIF.
LW_ACCOUNTGL-GL_ACCOUNT = LS_ZFIT011-HKONT. "会计科目
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-GL_ACCOUNT
IMPORTING
OUTPUT = LW_ACCOUNTGL-GL_ACCOUNT.
LW_ACCOUNTGL-ASSET_NO = LS_ZFIT011-ANLN1. "主资产号
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-ASSET_NO
IMPORTING
OUTPUT = LW_ACCOUNTGL-ASSET_NO.
* lw_accountgl-sub_number = LS_ZFIT011-sub_number. "资产次级编号
*
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* input = lw_accountgl-sub_number
* IMPORTING
* output = lw_accountgl-sub_number.
LW_ACCOUNTGL-TAX_CODE = LS_ZFIT011-MWSKZ. "销售税代码
* LW_ACCOUNTGL-PROFIT_CTR = LS_ZFIT011-PRCTR. "利润中心
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-PROFIT_CTR
IMPORTING
OUTPUT = LW_ACCOUNTGL-PROFIT_CTR.
* lw_accountgl-part_prctr = LS_ZFIT011-field13. "伙伴利润中心
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* input = lw_accountgl-part_prctr
* IMPORTING
* output = lw_accountgl-part_prctr.
LW_ACCOUNTGL-COSTCENTER = LS_ZFIT011-KOSTL. "成本中心
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-COSTCENTER
IMPORTING
OUTPUT = LW_ACCOUNTGL-COSTCENTER.
* LW_ACCOUNTGL-WBS_ELEMENT = LS_ZFIT011-FIELD17. "工作分解结构元素 (WBS 元素)
CALL FUNCTION 'CONVERSION_EXIT_ABPSN_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-WBS_ELEMENT
IMPORTING
OUTPUT = LW_ACCOUNTGL-WBS_ELEMENT.
LW_ACCOUNTGL-ITEM_TEXT = LS_ZFIT011-SGTXT. "行项目文本
* 订单
IF LS_ZFIT011-AUFNR IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_ZFIT011-AUFNR
IMPORTING
OUTPUT = LW_ACCOUNTGL-ORDERID.
ENDIF.
LW_ACCOUNTGL-ALLOC_NMBR = LS_ZFIT011-ZUONR. "分配
* lw_accountgl-po_number = LS_ZFIT011-field15. "采购凭证号
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-PO_NUMBER
IMPORTING
OUTPUT = LW_ACCOUNTGL-PO_NUMBER.
LW_ACCOUNTGL-COMP_CODE = LS_ZFIT011-BUKRS. "公司代码
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LW_ACCOUNTGL-PART_ACCT
IMPORTING
OUTPUT = LW_ACCOUNTGL-PART_ACCT.
* LW_ACCOUNTGL-TR_PART_BA = LS_ZFIT011-FIELD40. "贸易伙伴
* lw_accountgl-value_date = LS_ZFIT011-field19. "起息日
* lw_accountgl-plant = LS_ZFIT011-field24. "工厂
* CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
* EXPORTING
* input = LS_ZFIT011-field25
* IMPORTING
* output = lw_accountgl-material
* EXCEPTIONS
* length_error = 1
* OTHERS = 2.
* 错误的时候
* IF sy-subrc <> 0.
*
* lw_accountgl-material = LS_ZFIT011-field25. "物料号
*
* ENDIF.
LW_ACCOUNTGL-REF_KEY_1 = LS_ZFIT011-XREF1. "参考码1
LW_ACCOUNTGL-REF_KEY_2 = LS_ZFIT011-XREF2. "参考码2
LW_ACCOUNTGL-REF_KEY_3 = LS_ZFIT011-XREF3. "参考码3
APPEND LW_ACCOUNTGL TO LT_ACCOUNTGL.
****************************************************构建货币内表数据*****************************************************
IF LS_ZFIT011-WAERS EQ 'CNY' OR LS_ZFIT011-WAERS EQ 'RMB'.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '00'. "
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = LS_ZFIT011-WAERS. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "原币金额
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
ELSE.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '00'. "
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = LS_ZFIT011-WAERS. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "原币金额(外币)
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
IF LS_ZFIT011-DMBTR IS NOT INITIAL.
CLEAR LW_CURRENCYAMOUNT.
LW_CURRENCYAMOUNT-ITEMNO_ACC = LS_ZFIT011-ZLINE. "凭证行项目编号
LW_CURRENCYAMOUNT-CURR_TYPE = '10'.
"
CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
EXPORTING
RATE_TYPE = 'M'
FROM_CURR = LS_ZFIT011-WAERS
TO_CURRNCY = 'CNY'
DATE = SY-DATUM
IMPORTING
EXCH_RATE = LS_EXCH_RATE
* RETURN =
.
IF SY-SUBRC IS INITIAL.
LW_CURRENCYAMOUNT-EXCH_RATE = LS_EXCH_RATE-EXCH_RATE.
ENDIF.
* lw_currencyamount-exch_rate = LS_ZFIT011-kursf. "汇率
LW_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货币
LW_CURRENCYAMOUNT-AMT_DOCCUR = LS_ZFIT011-DMBTR. "本位币金额(人民币)
APPEND LW_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
ENDIF.
ENDIF.
ENDIF.
*********************************************** extension2 构 建 *****************************************************
WL_PZPLDR-POSNR = LS_ZFIT011-ZLINE. "会计凭证行项目编号
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WL_PZPLDR-POSNR
IMPORTING
OUTPUT = WL_PZPLDR-POSNR.
WL_PZPLDR-ANBWA = LS_ZFIT011-ANBWA. "资产业务类型
WL_PZPLDR-BSCHL = LS_ZFIT011-BSCHL. "过账码
WA_EXT2-STRUCTURE = 'ZFIS_PZPLDR'.
WA_EXT2-VALUEPART1 = WL_PZPLDR.
APPEND WA_EXT2 TO I_EXT2.
CLEAR WA_EXT2.
***************************************************BAPI记账****************************************************
AT END OF XBLNR."如果字段发生变化执行下面代码
* 导入会计凭证
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = L_DOCUMENTHEADER
IMPORTING
OBJ_KEY = L_OBJKEY
TABLES
ACCOUNTGL = LT_ACCOUNTGL
* accountreceivable = lT_accountreceivable
ACCOUNTPAYABLE = LT_ACCOUNTPAYABLE
CURRENCYAMOUNT = LT_CURRENCYAMOUNT
RETURN = LI_RETURN
EXTENSION2 = I_EXT2.
LOOP AT LI_RETURN WHERE TYPE = 'E'.
CONCATENATE LI_RETURN-MESSAGE L_ERRORMESSAGE INTO L_ERRORMESSAGE.
ENDLOOP.
IF L_ERRORMESSAGE NE ''.
L_OBJKEY = ''.
ENDIF.
LOOP AT LT_ZFIT011TMP INTO LS_ZFIT011.
LS_ZFIT011-BELNR = L_OBJKEY.
LS_ZFIT011-MSG = L_ERRORMESSAGE.
MODIFY LT_ZFIT011TMP FROM LS_ZFIT011 TRANSPORTING BELNR MSG.
ENDLOOP.
APPEND LINES OF LT_ZFIT011_DELTMP TO LT_ZFIT011TMP."展示
APPEND LINES OF LT_ZFIT011TMP[] TO GT_ITAB[].
MODIFY ZFIT011 FROM TABLE LT_ZFIT011TMP.
COMMIT WORK AND WAIT.
CLEAR:L_DOCUMENTHEADER,LT_ACCOUNTGL[],LT_ACCOUNTPAYABLE,LT_CURRENCYAMOUNT[],I_EXT2[],LI_RETURN[],
LT_ZFIT011TMP[],LT_ZFIT011_DELTMP[].
"返回凭证编码----------------------------
IF SY-MANDT = '888'.
IF L_OBJKEY NE ''.
CONCATENATE 'http://a***************lNo?businessKey='
LS_ZFIT011-XBLNR '&journalNo=' L_OBJKEY '&companyCode=' LS_ZFIT011-XBLNR+0(4)
INTO LV_SERVICE.
ELSE.
CONCATENATE 'http://a**************?businessKey='
LS_ZFIT011-XBLNR '&journalNo=' L_ERRORMESSAGE '&companyCode=' LS_ZFIT011-XBLNR+0(4)
INTO LV_SERVICE.
ENDIF.
ELSE.
IF L_OBJKEY NE ''.
CONCATENATE 'http://*****************?businessKey='
LS_ZFIT011-XBLNR '&journalNo=' L_OBJKEY '&companyCode=' LS_ZFIT011-XBLNR+0(4)
INTO LV_SERVICE.
ELSE.
CONCATENATE 'http://**************?businessKey='
LS_ZFIT011-XBLNR '&journalNo=' L_ERRORMESSAGE '&companyCode=' LS_ZFIT011-XBLNR+0(4)
INTO LV_SERVICE.
ENDIF.
ENDIF.
CL_HTTP_CLIENT=>CREATE_BY_URL(
EXPORTING
URL = LV_SERVICE
IMPORTING
CLIENT = LO_HTTP_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4 ).
LO_HTTP_CLIENT->PROPERTYTYPE_LOGON_POPUP = LO_HTTP_CLIENT->CO_DISABLED.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = 'Authorization'
VALUE = L_AUTHORIZATION.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_METHOD( 'PUT' ).
LO_HTTP_CLIENT->SEND(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2 ).
LO_HTTP_CLIENT->RECEIVE(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3 ).
CLEAR:L_OBJKEY,L_ERRORMESSAGE.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_ALV_SHOW .
DATA:LR_TABLE TYPE REF TO CL_SALV_TABLE.
* TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
* EXPORTING
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
* R_CONTAINER =
* CONTAINER_NAME =
IMPORTING
R_SALV_TABLE = LR_TABLE
CHANGING
T_TABLE = GT_ITAB.
* CATCH CX_SALV_MSG .
* ENDTRY.
DATA:LR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.
CALL METHOD LR_TABLE->GET_FUNCTIONS
RECEIVING
VALUE = LR_FUNCTIONS.
CALL METHOD LR_FUNCTIONS->SET_ALL
* EXPORTING
* VALUE = IF_SALV_C_BOOL_SAP=>TRUE
.
CALL METHOD LR_TABLE->DISPLAY.
ENDFORM.