共计 5306 个字符,预计需要花费 14 分钟才能阅读完成。
我先撸一个最简略的 rfc
RFC 有
LT_TABLES TYPE RSFB_PARA,
LT_IMPORT TYPE RSFB_PARA,
LT_EXPORT TYPE RSFB_PARA,
LT_CHANGE TYPE RSFB_PARA,
再加一个异样
FUNCTION ZFMALL_SEND_TO_SAP.
*"----------------------------------------------------------------------
*"*" 本地接口:*" IMPORTING
*" REFERENCE(IS_INPUT) TYPE ZSHALL_0001_INS
*" EXPORTING
*" VALUE(ES_OUTPUT) TYPE ZSHRALL_OUS
*"----------------------------------------------------------------------
* [Global data declarations](global-zfmall_send_to_sap.html)
DATA:
LT_PTAB TYPE ABAP_FUNC_PARMBIND_TAB,
LS_PTAB LIKE LINE OF LT_PTAB,
LT_ETAB TYPE ABAP_FUNC_EXCPBIND_TAB,
LS_ETAB LIKE LINE OF LT_ETAB,
LS_HEADER_GD TYPE HEADER_FB,
LT_TABLES TYPE RSFB_PARA,
LT_IMPORT TYPE RSFB_PARA,
LT_EXPORT TYPE RSFB_PARA,
LT_CHANGE TYPE RSFB_PARA,
DYN_WA_INS TYPE REF TO DATA,
DYN_WA_OUS TYPE REF TO DATA,
LV_STRCRQ TYPE ZESTRCRQ,
LV_STRCRS TYPE ZESTRCRS,
LV_STRING TYPE STRING,
LV_TABNAME TYPE TABNAME.
DATA: LV_DATE_START LIKE SY-DATUM,
LV_TIME_START LIKE SY-UZEIT,
LV_DATE_END LIKE SY-DATUM,
LV_TIME_END LIKE SY-UZEIT,
LV_DAYS TYPE I,
LV_TIMES TYPE CVA_TIME,
LV_TSPAN TYPE ZETSPAN.
CLEAR: LV_DATE_START, LV_TIME_START.
LV_DATE_START = SY-DATUM.
LV_TIME_START = SY-UZEIT.
FIELD-SYMBOLS:<DYN_WA_INS> TYPE ANY,
<DYN_WA_OUS> TYPE ANY.
SELECT SINGLE FUNCNAME INTO @DATA(LV_FUNCNAME)
FROM ZINTFLOG002
WHERE SYSNM = @IS_INPUT-IS_SAPSYS-SYSNM
AND INTNR = @IS_INPUT-IS_SAPSYS-INTNR
AND ACTIV = 'X'.
CHECK SY-SUBRC = 0.
CLEAR: LT_PTAB[].
SELECT SINGLE PNAME INTO @DATA(LV_PNAME) FROM TFDIR WHERE FUNCNAME = @LV_FUNCNAME.
LS_HEADER_GD-NAME = LV_FUNCNAME.
CALL FUNCTION 'FUNCTION_INCLUDE_SPLIT'
EXPORTING
PROGRAM = LV_PNAME
IMPORTING
GROUP = LS_HEADER_GD-AREA
NAMESPACE = LS_HEADER_GD-NAMESPACE
EXCEPTIONS
OTHE = 12.
IF SY-SUBRC = 0.
CONCATENATE LS_HEADER_GD-NAMESPACE LS_HEADER_GD-AREA INTO LS_HEADER_GD-AREA.
REFRESH:LT_TABLES,LT_IMPORT,LT_EXPORT,LT_CHANGE.
CALL METHOD CL_FB_PARAMETER_DB=>READ
IMPORTING
TABLES = LT_TABLES
IMPORT = LT_IMPORT
EXPORT = LT_EXPORT
CHANGE = LT_CHANGE
CHANGING
HEADER = LS_HEADER_GD.
ENDIF.
****import 操作
IF LT_IMPORT[] IS NOT INITIAL.
READ TABLE LT_IMPORT ASSIGNING FIELD-SYMBOL(<FS_IMPORT>) INDEX 1.
CREATE DATA DYN_WA_INS TYPE (<FS_IMPORT>-STRUCTURE).
ASSIGN DYN_WA_INS->* TO <DYN_WA_INS>.
call function 'ZFM_EHR_JSON_TO_ABAP'
EXPORTING
IV_JSON = IS_INPUT-INPUT
IMPORTING
EV_DATA = <DYN_WA_INS>.
LS_PTAB-NAME = <FS_IMPORT>-PARAMETER.
LS_PTAB-KIND = ABAP_FUNC_EXPORTING.
GET REFERENCE OF <DYN_WA_INS> INTO LS_PTAB-VALUE.
INSERT LS_PTAB INTO TABLE LT_PTAB.
CLEAR:LS_PTAB.
ENDIF.
**** export 操作
IF LT_EXPORT[] IS NOT INITIAL.
READ TABLE LT_EXPORT ASSIGNING FIELD-SYMBOL(<FS_EXPORT>) INDEX 1.
CREATE DATA DYN_WA_OUS TYPE (<FS_EXPORT>-STRUCTURE).
ASSIGN DYN_WA_OUS->* TO <DYN_WA_OUS>.
LS_PTAB-NAME = <FS_EXPORT>-PARAMETER.
LS_PTAB-KIND = ABAP_FUNC_IMPORTING.
GET REFERENCE OF <DYN_WA_OUS> INTO LS_PTAB-VALUE.
INSERT LS_PTAB INTO TABLE LT_PTAB.
CLEAR:LS_PTAB.
ENDIF.
"FILL Exceptions
CLEAR: LT_ETAB[].
PERFORM FRM_FILL_EXCP_TAB USING: 'DATA_NOT_FOUND' '1' CHANGING LT_ETAB.
PERFORM FRM_FILL_EXCP_TAB USING: 'OTHERS' '2' CHANGING LT_ETAB.
CALL FUNCTION LV_FUNCNAME
PARAMETER-TABLE
LT_PTAB
EXCEPTION-TABLE
LT_ETAB.
IF SY-SUBRC NE 0.
ES_OUTPUT-MESSAGE-MSGTX = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = SY-MSGID
MSGNR = SY-MSGNO
MSGV1 = SY-MSGV1
MSGV2 = SY-MSGV1
MSGV3 = SY-MSGV1
MSGV4 = SY-MSGV1
IMPORTING
MESSAGE_TEXT_OUTPUT = ES_OUTPUT-MESSAGE-MSGTY.
ENDIF.
IF ES_OUTPUT-MESSAGE-MSGTX = 'E'.
EXIT.
ENDIF.
call function 'ZFM_EHR_ABAP_TO_JSON'
EXPORTING
IV_DATA = <DYN_WA_OUS>
IMPORTING
EV_JSON = LV_STRING.
ES_OUTPUT-OUTPUT = LV_STRING.
CLEAR: LV_DATE_END, LV_TIME_END.
LV_DATE_END = SY-DATUM.
LV_TIME_END = SY-UZEIT.
CLEAR: LV_DAYS, LV_TIMES.
CALL FUNCTION 'SCOV_TIME_DIFF'
EXPORTING
IM_DATE1 = LV_DATE_START
IM_DATE2 = LV_DATE_END
IM_TIME1 = LV_TIME_START
IM_TIME2 = LV_TIME_END
IMPORTING
EX_DAYS = LV_DAYS
EX_TIME = LV_TIMES
EXCEPTIONS
START_LARGER_THAN_END = 1
OTHERS = 2.
IF SY-SUBRC = 0.
* Implement suitable error handling here
LV_TSPAN = LV_DAYS * 24 * 60 * 60 + LV_TIMES+0(2) * 60 * 60 + LV_TIMES+2(2) * 60 + LV_TIMES+4(2).
ENDIF.
CLEAR:LV_STRCRQ,LV_STRCRS.
LV_STRCRQ = <FS_IMPORT>-STRUCTURE.
LV_STRCRS = <FS_EXPORT>-STRUCTURE.
call function 'ZINTFLOG_SAVE'
EXPORTING
IV_SYSNM = IS_INPUT-IS_SAPSYS-SYSNM
IV_INTNR = IS_INPUT-IS_SAPSYS-INTNR
IV_FUNCN = LV_FUNCNAME
IV_STRCRQ = LV_STRCRQ
IV_STRCRS = LV_STRCRS
IV_TYPE = ES_OUTPUT-MESSAGE-MSGTX
IV_MESSAGE = ES_OUTPUT-MESSAGE-MSGTY
IV_TSPAN = LV_TSPAN
CHANGING
CS_REQUEST = <DYN_WA_INS>
CS_RESPONSE = <DYN_WA_OUS>.
ENDFUNCTION.
正文完