RFC_READ_TABLE
Posted 想发财的小夏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RFC_READ_TABLE相关的知识,希望对你有一定的参考价值。
记录一下RFC_READ_TABLE函数的跨客户端使用,EWM catch ERP的数据,同时也可应用于其它系统直接通过RFC方式catch SAP的数据
FUNCTION zbc_fm_read_afpo.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IV_WERKS) TYPE WERKS_D
*" VALUE(IV_MATNR) TYPE MATNR
*" VALUE(IV_DATUM) TYPE DATUM
*" EXPORTING
*" VALUE(EV_STATUS) TYPE BAPI_MTYPE
*" VALUE(EV_MESSAGE) TYPE BAPI_MSG
*" TABLES
*" ET_DATA STRUCTURE AFPO
*"----------------------------------------------------------------------
DATA:lv_query_table TYPE dd02l-tabname,
lv_delimiter TYPE sonv-flag,
lt_options TYPE STANDARD TABLE OF rfc_db_opt,
lt_fields TYPE STANDARD TABLE OF rfc_db_fld,
lt_data TYPE STANDARD TABLE OF tab512.
DATA:l_begda TYPE sy-datum,
l_endda TYPE sy-datum.
DATA:BEGIN OF ls_afpo,
aufnr TYPE aufnr,
posnr TYPE co_posnr,
END OF ls_afpo,
lt_afpo LIKE TABLE OF ls_afpo.
zcl_pc_methods=>get_logsys_and_rfcdest( IMPORTING es_tblsysdest = DATA(ls_system) )."获取逻辑系统
* 获取当月日期
l_begda = iv_datum+0(6) && '01'.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = iv_datum
IMPORTING
last_day_of_month = l_endda
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = iv_matnr
IMPORTING
output = iv_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
CLEAR: lv_query_table,lv_delimiter,lt_options,lt_fields,lt_data.
lv_query_table = 'AFPO'.
lt_options = VALUE #( ( |DWERK = '{ iv_werks }'| )
( |AND MATNR = '{ iv_matnr }'| )
( |AND DGLTS BETWEEN '{ l_begda }' AND '{ l_endda }'| ) ).
* ( |AND XLOEK = ''| ) ).
lt_fields = VALUE #( ( fieldname = 'AUFNR' offset = '000000' length = '000012' )
( fieldname = 'POSNR' offset = '000010' length = '000004' ) ).
CALL FUNCTION 'RFC_READ_TABLE' DESTINATION ls_system-rfcdest
EXPORTING
query_table = lv_query_table
delimiter = lv_delimiter
TABLES
options = lt_options
fields = lt_fields
data = lt_data
EXCEPTIONS
system_failure = 1
communication_failure = 2
OTHERS = 3.
lt_afpo = lt_data.
et_data[] = CORRESPONDING #( lt_afpo ).
ENDFUNCTION.
以上是关于RFC_READ_TABLE的主要内容,如果未能解决你的问题,请参考以下文章