Skip to content

Instantly share code, notes, and snippets.

@alezhu
Last active April 27, 2017 14:23
Show Gist options
  • Save alezhu/ac114c7daa2955454ec5823da5887f8b to your computer and use it in GitHub Desktop.
Save alezhu/ac114c7daa2955454ec5823da5887f8b to your computer and use it in GitHub Desktop.
*DEFINITION
private section.
types:
begin of ts_dest,
bskey type SLD_BSKEY,
logsys type TBLSYSDEST-logsys,
dest type TBLSYSDEST-rfcdest,
end of ts_dest,
tt_dest type HASHED TABLE OF ts_dest with UNIQUE key bskey.
class-data st_dest type tt_dest.
class-methods GET_ERP_CONNECTION
importing
!IV_BSKEY type SLD_BSKEY optional
returning
value(EV_CONNECTION) type RFCDEST .
*IMPLEMENTATION
METHOD get_erp_connection.
READ TABLE st_dest ASSIGNING FIELD-SYMBOL(<s_dest>) WITH TABLE KEY
bskey = iv_bskey
.
IF sy-subrc = 0.
ev_connection = <s_dest>-dest.
RETURN.
ENDIF.
IF iv_bskey IS NOT INITIAL.
TRY.
DATA(lo_bussys) = /scmb/cl_business_system=>get_instance( iv_bskey ).
* Set buffer
ev_connection = /scwm/cl_erp_system=>get_rfc_destination_by_logsys(
EXPORTING
iv_logsys = lo_bussys->m_v_logsys
).
INSERT VALUE #(
bskey = iv_bskey
logsys = lo_bussys->m_v_logsys
dest = ev_connection
) INTO TABLE st_dest.
RETURN.
CATCH /scmb/cx_business_system
/scwm/cx_erpintegration INTO DATA(lx_error).
ENDTRY.
ENDIF.
DO.
CASE sy-index.
WHEN 1.
ev_connection = zif_ewm_const=>connections-ewm_to_erp. "Just predefined name for ABAP connection from SM59 e.g.'EWM_to_ERP'
WHEN 2.
SELECT SINGLE rfcdest FROM tblsysdest INTO ev_connection WHERE rfcdest NE space.
WHEN OTHERS.
EXIT.
ENDCASE.
IF ev_connection IS NOT INITIAL.
TRY.
DATA(lo_erp) = /scwm/cl_it_s_system_erp=>get_instance(
iv_rfcdest = ev_connection
).
lo_erp->check( ).
lo_erp->get_logsys_dest(
IMPORTING
ev_logsys = DATA(lv_logsys)
).
INSERT VALUE #(
bskey = space
logsys = lv_logsys
dest = ev_connection
) INTO TABLE st_dest.
RETURN.
CATCH /scwm/cx_it_proxy. "
ENDTRY.
ENDIF.
ENDDO.
CLEAR ev_connection.
ENDMETHOD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment