Here we need to create two RFC in system. One in sender side and another one in receiver side.
In receiver side throw driver program table name is pass it as input to FRC. Then system will establish a connection to bring the respective table data from sender side (system).
SENDER SIDE DEVELOPMENT
- Provide Function Module Name
- Provide Function Group Name
- Define Process type as Remote-Enabled Module
Input Parameter
Export Parameter
Table Parameter
Create structure in SE11 like below
Program
FUNCTION ztable_rfc_fm.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(TBMA_VAL) TYPE TABNAME16
*" EXPORTING
*" VALUE(TAB_NAME) TYPE TABNAME16
*" TABLES
*" ITAB STRUCTURE ZTAB_STRING
*"----------------------------------------------------------------------
TYPE-POOLS : abap, slis.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs>,
<fs_wa>.
"<fs_field>.
DATA : dyn_table TYPE REF TO data,
dyn_line TYPE REF TO data,
wa_fieldcat TYPE lvc_s_fcat,
it_fieldcat TYPE lvc_t_fcat,
wa TYPE ztab_string.
DATA : loop1 TYPE sy-tabix,
loop2 TYPE sy-tabix,
curr_line TYPE sy-tabix.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv.
DATA : it_tabdescr TYPE abap_compdescr_tab,
wa_tabdescr TYPE abap_compdescr,
fieldname TYPE abap_compname.
DATA : ref_table_descr TYPE REF TO cl_abap_structdescr.
* Return structure of the table.
ref_table_descr ?= cl_abap_structdescr=>describe_by_name( tbma_val ). "typedescr
it_tabdescr[] = ref_table_descr->components[].
LOOP AT it_tabdescr INTO wa_tabdescr.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_tabdescr-name .
wa_fieldcat-datatype = wa_tabdescr-type_kind.
wa_fieldcat-inttype = wa_tabdescr-type_kind.
IF wa_tabdescr-type_kind = 'P'.
wa_tabdescr-length = 30.
ENDIF.
wa_fieldcat-intlen = wa_tabdescr-length / 2.
wa_fieldcat-decimals = wa_tabdescr-decimals.
APPEND wa_fieldcat TO it_fieldcat.
ENDLOOP.
* Create dynamic internal table and assign to Field-Symbol
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = dyn_table.
ASSIGN dyn_table->* TO <fs_table>.
* Create dynamic work area and assign to Field Symbol
CREATE DATA dyn_line LIKE LINE OF <fs_table>.
ASSIGN dyn_line->* TO <fs_wa>.
ASSIGN dyn_line->* TO <fs>.
* Select Data from table using field symbol which points to dynamic itab
SELECT * INTO CORRESPONDING FIELDS OF TABLE <fs_table>
FROM (tbma_val).
LOOP AT <fs_table> ASSIGNING <fs>.
loop1 = loop1 + 1.
CLEAR : loop2.
LOOP AT it_tabdescr INTO wa_tabdescr.
loop2 = loop2 + 1.
ASSIGN COMPONENT loop2 OF STRUCTURE <fs> TO <fs_wa>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
wa-row_n = loop1.
wa-col_n = loop2.
wa-value = <fs_wa>.
CONDENSE wa-value.
APPEND wa TO itab.
ENDLOOP.
ENDLOOP.
tab_name = tbma_val.
ENDFUNCTION.
RECEIVER SIDE DEVELOPMENT
- Provide Function Module Name
- Provide Function Group Name
- Define Process type as Remote-Enabled Module
Input Parameter
Export Parameter
Table Parameter
Create structure in SE11 like below
Program
FUNCTION ztable_rfc_fm .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(TBMA_VAL) TYPE TABNAME16
*" TABLES
*" ITAB STRUCTURE ZTAB_STRUCT
*"----------------------------------------------------------------------
DATA : DEST TYPE CHAR3.
IF sy-sysid = 'RQ1' AND sy-mandt = '300'. " Based on Quality or Production define your DESTINATION
dest = 'JD1'.
ENDIF.
IF sy-sysid = 'RP1' AND sy-mandt = '300'.
dest = 'JP1'.
ENDIF.
CALL FUNCTION 'ZTABLE_RFC_FM' DESTINATION dest
EXPORTING
tbma_val = tbma_val
TABLES
itab = itab.
ENDFUNCTION.
Driver program to call RFC function module
*&---------------------------------------------------------------------*
*& Report ZELVR_ZTABLE_GET_DATA
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zelvr_ztable_get_data.
TYPE-POOLS : abap, slis.
DATA : itab TYPE STANDARD TABLE OF ztab_struct.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs>,
<fs_wa1>,
<fs_wa>.
"<fs_field>.
DATA : wa TYPE ztab_struct.
DATA : lv_int1 TYPE INT1.
DATA : lv_int2 TYPE INT2.
DATA : lv_int4 TYPE INT4.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv.
DATA : it_tabdescr TYPE abap_compdescr_tab,
wa_tabdescr TYPE abap_compdescr,
lt_tot_comp TYPE cl_abap_structdescr=>component_table,
lt_comp TYPE cl_abap_structdescr=>component_table,
la_comp LIKE LINE OF lt_comp,
lo_new_type TYPE REF TO cl_abap_structdescr,
lo_table_type TYPE REF TO cl_abap_tabledescr,
w_tref TYPE REF TO data,
w_dy_line TYPE REF TO data,
count TYPE sy-tabix,
loop1 TYPE sy-tabix,
num TYPE char10,
msg TYPE char100.
DATA : ref_table_descr TYPE REF TO cl_abap_structdescr.
DATA : w_typ TYPE REF TO cl_abap_elemdescr.
DATA : DEST TYPE CHAR3.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS tbma_val TYPE tabname16.
SELECTION-SCREEN END OF BLOCK b1.
IF SY-SYSID = 'JD1' AND SY-MANDT = '400'.
DEST = 'RQ1'.
ENDIF.
IF SY-SYSID = 'JP1' AND SY-MANDT = '500'.
DEST = 'RP1'.
ENDIF.
CALL FUNCTION 'ZTABLE_RFC_FM' DESTINATION DEST
EXPORTING
tbma_val = tbma_val
TABLES
itab = itab.
IF sy-subrc = 0.
* Return structure of the table.
ref_table_descr ?= cl_abap_structdescr=>describe_by_name( tbma_val ).
it_tabdescr[] = ref_table_descr->components[].
LOOP AT it_tabdescr INTO wa_tabdescr.
count = count + 1.
IF wa_tabdescr-type_kind = 'P'.
wa_tabdescr-length = 16.
ENDIF.
wa_tabdescr-length = wa_tabdescr-length / 2.
CASE wa_tabdescr-type_kind.
WHEN 'STRING'. w_typ = cl_abap_elemdescr=>get_string( ).
WHEN 'XSTRING'. w_typ = cl_abap_elemdescr=>get_xstring( ).
WHEN 'b'. w_typ ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int1 ).
WHEN 's'. w_typ ?= cl_abap_elemdescr=>describe_by_data( p_data = lv_int2 ).
WHEN 'I'. w_typ = cl_abap_elemdescr=>get_i( ).
WHEN 'F'. w_typ = cl_abap_elemdescr=>get_f( ).
WHEN 'D'. w_typ = cl_abap_elemdescr=>get_d( ).
WHEN 'T'. w_typ = cl_abap_elemdescr=>get_t( ).
WHEN 'C'. w_typ = cl_abap_elemdescr=>get_c( p_length = wa_tabdescr-length ).
WHEN 'N'. w_typ = cl_abap_elemdescr=>get_n( p_length = wa_tabdescr-length ).
WHEN 'X'. w_typ = cl_abap_elemdescr=>get_x( p_length = wa_tabdescr-length ).
WHEN 'P'. w_typ = cl_abap_elemdescr=>get_p( p_length = wa_tabdescr-length p_decimals = wa_tabdescr-decimals ).
ENDCASE.
CLEAR la_comp.
la_comp-type = w_typ. "Field type
la_comp-name = wa_tabdescr-name. "Field name ex: FIELD1
APPEND la_comp TO lt_tot_comp. "Add entry to component table
ENDLOOP.
* Create new type from component table
lo_new_type = cl_abap_structdescr=>create( lt_tot_comp ).
* Create new table type
lo_table_type = cl_abap_tabledescr=>create( lo_new_type ).
* Create dynamic internal table and assign to Field Symbol
CREATE DATA w_tref TYPE HANDLE lo_table_type.
ASSIGN w_tref->* TO <fs_table>.
* Create dynamic work area and assign to Field Symbol
CREATE DATA w_dy_line LIKE LINE OF <fs_table>.
ASSIGN w_dy_line->* TO <fs_wa>.
LOOP AT itab INTO wa.
loop1 = loop1 + 1.
READ TABLE it_tabdescr INTO wa_tabdescr INDEX loop1.
IF sy-subrc = 0.
ASSIGN COMPONENT wa_tabdescr-name OF STRUCTURE <fs_wa> TO <fs>.
<fs> = wa-value.
IF loop1 = 1.
<fs> = sy-mandt.
ENDIF.
ENDIF.
IF count = loop1.
num = num + 1.
APPEND <fs_wa> TO <fs_table>.
CLEAR : loop1, <fs_wa>.
ENDIF.
ENDLOOP.
MODIFY (tbma_val) FROM TABLE <fs_table>.
IF sy-subrc = 0.
CONDENSE num.
CONCATENATE 'TABLE' tbma_val 'TOTAL' num 'RECORDS UPDATED SUCCESSFULLY!' INTO msg SEPARATED BY ''.
MESSAGE msg TYPE 'S'.
ELSE.
msg = 'ERROR IN TABLE UPDATE!'.
MESSAGE msg TYPE 'E'.
ENDIF.
ENDIF.
Driver program input screen