This sample code uses the list of registered servers from the SAP gateway to determine the RFC destination. This negates the need to create a packing station profile.
See: Sample ABAP code ECC for sample ABAP using packing station profile.
*&---------------------------------------------------------------------* *& Report ZTESTSCALE CONFIG FREE * *& * *&---------------------------------------------------------------------* *& Author: Pocket Programs 2025 * *& ============================= * *& Example ABAP for use with ERP-Scale see www.pocketprograms.com * *& * *& Uses list of connected systems to determine RFC destination * *& * *&---------------------------------------------------------------------* REPORT ZPP_TEST_ERPSCALE MESSAGE-ID gw . INCLUDE lsgwydef. data: gs_profile type hupast_t. data: lt_weight type table of hum_scale, ls_weight type hum_scale, MSG_TEXT(120) TYPE C, "Message text RFC_DESTINATION LIKE RFCDISPLAY-RFCDEST, RFC_TPNAME LIKE RFCDISPLAZ-RFCREGID, RFC_DOC3 LIKE RFCDOC-RFCDOC3, p_weight(10). * Read connected systems variables DATA: locgwhost LIKE gwy_struct-gwhost, locgwserv LIKE gwy_struct-gwserv, snagwhost LIKE gwy_struct-gwhost, snagwserv LIKE gwy_struct-gwserv, use_gwsys2 TYPE c VALUE ' ', use_gwsys3 TYPE c VALUE 'X', sf_terminal(20). *================================================= INITIALIZATION. perform get_terminal. write: / 'Terminal :', AT 30 sf_terminal. PERFORM gw_get_loc_host_and_service. * PERFORM gw_get_sna_host_and_service. CALL FUNCTION 'GWY_SET_HOST_AND_SERVICE' EXPORTING gwhost = locgwhost gwserv = locgwserv EXCEPTIONS gwy_connect_failed = 1 OTHERS = 99. IF sy-subrc <> 0. MESSAGE a056 WITH locgwhost locgwserv. EXIT. ENDIF. PERFORM get_tpname. write: / 'RFC program id :', AT 30 RFC_TPNAME. if RFC_TPNAME IS NOT INITIAL. data: l_search(100). concatenate '%,N=' RFC_TPNAME ',%' into l_search. SELECT SINGLE RFCDEST into RFC_DESTINATION FROM RFCDES WHERE RFCOPTIONS LIKE l_search. write: / 'RFC destination :', AT 30 RFC_DESTINATION. if RFC_DESTINATION is not INITIAL. SELECT SINGLE RFCDOC3 FROM RFCDOC INTO RFC_DOC3 WHERE RFCLANG EQ SY-LANGU AND RFCDEST EQ RFC_DESTINATION. write: / 'RFC documentation 3 :', AT 30 RFC_DOC3. if RFC_DESTINATION is not INITIAL. perform do_weighing. write: / 'Weight :', AT 30 p_weight, AT 40 ls_weight-GEWEI. ENDIF. ENDIF. ENDIF. *============================================================== FORM do_weighing. data: l_weight like vekp-brgew. * rfc-destination aus Customizing: * l_rfc_destination = gs_profile-RFC_FOR_SCALE. ls_weight-waage = 'SCALE'. "gs_profile-NAME_OF_SCALE. if rfc_destination is initial. message e203(hudialog) with rfc_destination. endif. * Function module must be called with at least one * entry in the table refresh lt_weight. append ls_weight to lt_weight. CALL FUNCTION 'HU_GET_RFC_DATA' destination rfc_destination TABLES ET_WEIGHT = lt_weight EXCEPTIONS "<< begin note 205878 COMMUNICATION_FAILURE = 1 MESSAGE MSG_TEXT SYSTEM_FAILURE = 2 MESSAGE MSG_TEXT OTHERS = 5. if not sy-subrc is initial. concatenate text-040 rfc_destination msg_text into msg_text separated by space. message s001(vl) with msg_text. clear: l_weight. endif. clear ls_weight. read table lt_weight into ls_weight index 1. if ls_weight-brgew is initial. message s203(hudialog) with rfc_destination DISPLAY LIKE 'E'. endif. catch system-exceptions CONVT_NO_NUMBER = 9 . l_weight = ls_weight-brgew. p_weight = l_weight. endcatch. if sy-subrc = 9. message s000(zz) with ls_weight. endif. endform. *&---------------------------------------------------------------------* *& Form GET_RFC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM get_tpname. *--------------------------------------------------------------------- * Struktur für angemeldete Systeme *--------------------------------------------------------------------- DATA: BEGIN OF gwsys OCCURS 0. INCLUDE STRUCTURE gwy_system. DATA: END OF gwsys. DATA: BEGIN OF gwsys2 OCCURS 0. INCLUDE STRUCTURE gwy_syste2. DATA: END OF gwsys2. DATA: BEGIN OF gwsys3 OCCURS 0. INCLUDE STRUCTURE gwy_syste3. DATA: END OF gwsys3. DATA: loc_luname LIKE gwsys-luname, fbst(30),tabn(30). tabn = 'GWSYS3'. fbst = 'GWY_READ_CONNECTED_SYSTEMS3'. IF use_gwsys3 = 'X'. REFRESH gwsys3. CLEAR gwsys3. CALL FUNCTION 'GWY_READ_CONNECTED_SYSTEMS3' EXPORTING gwhost = locgwhost gwserv = locgwserv TABLES connected_systems = gwsys3 EXCEPTIONS OTHERS = 1. IF sy-subrc = 0. use_gwsys3 = 'X'. use_gwsys2 = 'N'. ELSE. use_gwsys3 = 'N'. use_gwsys2 = 'X'. ENDIF. ENDIF. IF use_gwsys2 = 'X'. fbst = 'GWY_READ_CONNECTED_SYSTEMS2'. tabn = 'GWSYS2'. REFRESH gwsys2. CLEAR gwsys2. CALL FUNCTION 'GWY_READ_CONNECTED_SYSTEMS2' EXPORTING gwhost = locgwhost gwserv = locgwserv TABLES connected_systems = gwsys2 EXCEPTIONS OTHERS = 1. IF sy-subrc = 0. use_gwsys2 = 'X'. use_gwsys3 = 'N'. ELSE. use_gwsys2 = 'N'. ENDIF. ENDIF. IF use_gwsys2 = 'N'. fbst = 'GWY_READ_CONNECTED_SYSTEMS'. tabn = 'GWSYS'. REFRESH gwsys. CLEAR gwsys. CALL FUNCTION 'GWY_READ_CONNECTED_SYSTEMS' EXPORTING gwhost = locgwhost gwserv = locgwserv TABLES connected_systems = gwsys EXCEPTIONS gwy_unknown_opcode = gwy_unknown_opcode gwy_communication_failure = gwy_communication_failure gwy_get_tab_failed = gwy_get_tab_failed gwy_newline_failed = gwy_newline_failed gwy_tablen_too_short = gwy_tablen_too_short gwy_get_opcode_failed = gwy_get_opcode_failed gwy_get_gwhost_failed = gwy_get_gwhost_failed gwy_get_gwserv_failed = gwy_get_gwserv_failed gwy_monitor_disabled = gwy_monitor_disabled OTHERS = 9999. ENDIF. * PERFORM gw_check_rc USING sy-subrc fbst tabn. * action = disp_gwsys. IF use_gwsys3 = 'X'. LOOP AT gwsys3. IF gwsys3-luname = space. PERFORM get_luname USING gwsys3-luname gwsys3-addr CHANGING loc_luname. gwsys3-luname = loc_luname. MODIFY gwsys3. ENDIF. IF gwsys3-luname eq sf_terminal. RFC_TPNAME = gwsys3-TPNAME. endif. ENDLOOP. ELSEIF use_gwsys2 = 'X'. LOOP AT gwsys2. IF gwsys2-luname = space. PERFORM get_luname USING gwsys2-luname gwsys2-host CHANGING loc_luname. gwsys2-luname = loc_luname. MODIFY gwsys2. ENDIF. IF gwsys2-luname eq sf_terminal. RFC_TPNAME = gwsys2-TPNAME. endif. ENDLOOP. ELSE. REFRESH gwsys2. LOOP AT gwsys. IF gwsys-luname = space. PERFORM get_luname USING gwsys-luname gwsys-host1 CHANGING loc_luname. gwsys-luname = loc_luname. MODIFY gwsys. MOVE-CORRESPONDING gwsys TO gwsys2. gwsys2-no = sy-tabix. APPEND gwsys2. ENDIF. ENDLOOP. ENDIF. CLEAR gwsys. ENDFORM. "GW_SYSTEM_LIST *--------------------------------------------------------------------- * FORM GW_GET_LOC_HOST_AND_SERVICE *--------------------------------------------------------------------- * Gateway Namen und Service des Gateways holen *--------------------------------------------------------------------- FORM gw_get_loc_host_and_service. DATA: sapsys(2). CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'SAPLOCALHOSTFULL' ID 'VALUE' FIELD locgwhost. CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'SAPSYSTEM' ID 'VALUE' FIELD sapsys. locgwserv = 'sapgw'. "#EC NOTEXT locgwserv+5 = sapsys. ENDFORM. *--------------------------------------------------------------------- * FORM GW_GET_SNA_HOST_AND_SERVICE *--------------------------------------------------------------------- * Gateway Namen und Service des SNA Gateways holen *--------------------------------------------------------------------- FORM gw_get_sna_host_and_service. CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'rdisp/sna_gateway' ID 'VALUE' FIELD snagwhost. CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'rdisp/sna_gw_service' ID 'VALUE' FIELD snagwserv. ENDFORM. "GW_GET_SNA_HOST_AND_SERVICE *--------------------------------------------------------------------- * FORM GET_LUNAME *--------------------------------------------------------------------- * Falls Luname leer ist wird er aus dem Rechnernamen gebildet *--------------------------------------------------------------------- FORM get_luname USING luname TYPE c hostname TYPE c CHANGING loc_luname TYPE c. IF luname = space. loc_luname = hostname. ELSE. loc_luname = luname. ENDIF. ENDFORM. FORM get_terminal. * Get hostname from PC CALL FUNCTION 'TH_USER_INFO' IMPORTING terminal = sf_terminal. ENDFORM.
Determine Packing station profile based on hostname of user’s PC when using Fiori.
If the code is being used in a Fiori app, the function module TH_USER_INFO does not return the hostname of the operator’s PC, but the IP address. This can be used to match the column ADDR in the table returned by function module GWY_READ_CONNECTED_SYSTEMS3.