To use RFC HU_GET_RFC_DATA from your own ABAP’s, there are two steps.
- If you have defined packing station profiles in customizing (transaction HUPAST_C), you can use the function module read_packstation to determine the profile based on the hostname of the user’s PC.
- Use the RFC call HU_GET_RFC_DATA in conjunction with ERP-Scale to determine the current weight from the serial device
Note: You can use the packing station profile with ERP-Scale even if you have not activated handling unit management in SAP.
Determine Packing station profile based on hostname of user’s PC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | FORM read_packstation. statics sf_terminal(20). DATA: lt_profile TYPE TABLE OF hupast_t. * Get the Hostname from the PC. CALL FUNCTION 'TH_USER_INFO' IMPORTING terminal = sf_terminal. * Prerequisite only one profile per PC SELECT * FROM hupast_t CLIENT SPECIFIED INTO TABLE lt_profile WHERE terminal = sf_terminal AND client = sy-mandt. IF NOT sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile TRANSPORTING NO FIELDS INDEX 2. IF sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile INTO gs_profile INDEX 1. * PERFORM set_profile. ENDFORM. "read_packstation |
Call to RFC function HU_GET_RFC_DATA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | data: lt_weight type table of hum_scale, ls_weight type hum_scale, L_RFC_DESTINATION LIKE RFCDISPLAY-RFCDEST. l_rfc_destination = RFC_FOR_SCALE. "RFC Destination ls_weight-waage = NAME_OF_SCALE. "Name of scale in ERP-Scale ls_weight-brgew = '0.000'. ls_weight-gewei = space. append ls_weight to lt_weight. CALL FUNCTION 'HU_GET_RFC_DATA' destination l_rfc_destination TABLES ET_WEIGHT = lt_weight EXCEPTIONS COMMUNICATION_FAILURE = 1 MESSAGE MSG_TEXT SYSTEM_FAILURE = 2 MESSAGE MSG_TEXT. . if not sy-subrc is initial. concatenate text-040 l_rfc_destination msg_text into msg_text separated by space. message s001(vl) with msg_text. leave to transaction 'ZTESTWEIGH'. endif. clear ls_weight. read table lt_weight into ls_weight index 1. if ls_weight-brgew is initial. message e203(hudialog) with l_rfc_destination. endif. catch system-exceptions CONVT_NO_NUMBER = 9 . p_weight = ls_weight-brgew. endcatch. |
Complete example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | *&---------------------------------------------------------------------* *& Report ZTESTSCALE * *& * *&---------------------------------------------------------------------* *& Author: Pocket Programs 2013 * *& ============================= * *& Example ABAP for use with ERP-Scale see www.pocketprograms.com * *& * *& Requires transaction ZTESTWEIGH to be created to run this report * *& * *&---------------------------------------------------------------------* REPORT ZPP_TEST_ERPSCALE . TABLES: sscrfields. parameter: p_packst type HUM_PROFILE default 'ERPSCALE'. * Declaration of sel screen buttons SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN PUSHBUTTON (30) w_button USER-COMMAND BUT1. SELECTION-SCREEN END OF LINE. parameter: p_weight(20) MODIF ID DSP. parameter: p_unit(20) MODIF ID DSP. parameter: p_text(20) MODIF ID DSP. parameter: p_dummy1(20) MODIF ID DSP. parameter: p_dummy2(20) MODIF ID DSP. 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 L_RFC_DESTINATION LIKE RFCDISPLAY-RFCDEST. data: l_weight like vekp-brgew. data: p_msg(80). *================================================= initialization. * Make result fields read-only LOOP AT SCREEN. IF SCREEN-GROUP1 = 'DSP'. SCREEN-INPUT = 0. MODIFY SCREEN. ENDIF. ENDLOOP. * Add displayed text string to buttons w_button = 'Get weight using ERP-Scale'. * Determine packing station profile from PC hostname perform read_packstation. p_packst = gs_profile-packing_station. *================================================ AT SELECTION-SCREEN. * Check if button has been pressed if sscrfields-ucomm eq 'BUT1'. perform read_profile using p_packst. * rfc-destination aus Customizing: l_rfc_destination = gs_profile-RFC_FOR_SCALE. ls_weight-waage = gs_profile-NAME_OF_SCALE. if l_rfc_destination is initial. clear: p_weight, p_unit, p_text, p_dummy1, p_dummy2. message e203(hudialog) with l_rfc_destination. endif. * Function module must be called with at least one * entry in the table ls_weight-brgew = '0.000'. ls_weight-gewei = space. append ls_weight to lt_weight. CALL FUNCTION 'HU_GET_RFC_DATA' destination l_rfc_destination TABLES ET_WEIGHT = lt_weight EXCEPTIONS "<< begin note 205878 COMMUNICATION_FAILURE = 1 MESSAGE MSG_TEXT SYSTEM_FAILURE = 2 MESSAGE MSG_TEXT. if not sy-subrc is initial. concatenate text-040 l_rfc_destination msg_text into msg_text separated by space. message s001(vl) with msg_text. clear: p_weight, p_unit, p_text, p_dummy1, p_dummy2. return. endif. clear ls_weight. read table lt_weight into ls_weight index 1. if ls_weight-brgew is initial. message e203(hudialog) with l_rfc_destination. endif. catch system-exceptions CONVT_NO_NUMBER = 9 . p_weight = ls_weight-brgew. endcatch. if sy-subrc = 9. message s000(zz) with ls_weight. endif. concatenate p_weight ls_weight-GEWEI into p_msg separated by space. * message s000(zz) with p_msg. p_unit = ls_weight-GEWEI. p_text = ls_weight-text. p_dummy1 = ls_weight-dummy1. p_dummy2 = ls_weight-dummy2. endif. *============================================================== at SELECTION-SCREEN OUTPUT. * Make result fields read-only LOOP AT SCREEN. IF SCREEN-GROUP1 = 'DSP'. SCREEN-INPUT = 0. MODIFY SCREEN. ENDIF. ENDLOOP. *============================================================== *&---------------------------------------------------------------------* *& Form READ_PROFILE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM read_packstation. statics sf_terminal(20). DATA: lt_profile TYPE TABLE OF hupast_t. * Get hostname from PC CALL FUNCTION 'TH_USER_INFO' IMPORTING terminal = sf_terminal. * prerequisite there is only one profile per PC SELECT * FROM hupast_t CLIENT SPECIFIED INTO TABLE lt_profile WHERE terminal = sf_terminal AND client = sy-mandt. IF NOT sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile TRANSPORTING NO FIELDS INDEX 2. IF sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile INTO gs_profile INDEX 1. * PERFORM set_profile. ENDFORM. "read_packstation *&---------------------------------------------------------------------* *& Form READ_PROFILE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM read_profile using p_st. DATA: lt_profile TYPE TABLE OF hupast_t. * prerequisite there is only one profile per PC SELECT * FROM hupast_t CLIENT SPECIFIED INTO TABLE lt_profile WHERE PACKING_STATION = p_st AND client = sy-mandt. IF NOT sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile TRANSPORTING NO FIELDS INDEX 2. IF sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile INTO gs_profile INDEX 1. * PERFORM set_profile. ENDFORM. "read_profile |
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. The FQDN of the operator’s PC can be determined using function module RFC_IP_TO_HOST.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | FORM read_packstation. statics sf_terminal(20). DATA: lt_profile TYPE TABLE OF hupast_t. * Get hostname from PC CALL FUNCTION 'TH_USER_INFO' IMPORTING terminal = sf_terminal. * prerequisite there is only one profile per PC SELECT * FROM hupast_t CLIENT SPECIFIED INTO TABLE lt_profile WHERE terminal = sf_terminal AND client = sy-mandt. IF NOT sy-subrc IS INITIAL. " No matching packing station profile found, perhaps Fiori? * Check if Fiori data lv_rfchost type RFCHOST_EXT. data lv_rfcip type RFCHOST_EXT. lv_rfcip = sf_terminal. CALL FUNCTION 'RFC_IP_TO_HOST' "Get the FQDN of the host PC EXPORTING rfcip = lv_rfcip IMPORTING RFCHOST = lv_rfchost EXCEPTIONS IP_TO_HOST_CONVERSION_ERROR = 1 OTHERS = 2. IF NOT sy-subrc IS INITIAL. "No FQDN returned exit. ENDIF. "Check if there is a profile for the FQDN SELECT * FROM hupast_t CLIENT SPECIFIED INTO TABLE lt_profile WHERE terminal = lv_rfchost AND client = sy-mandt. IF NOT sy-subrc IS INITIAL. EXIT. ENDIF. ENDIF. READ TABLE lt_profile TRANSPORTING NO FIELDS INDEX 2. IF sy-subrc IS INITIAL. EXIT. ENDIF. READ TABLE lt_profile INTO gs_profile INDEX 1. * PERFORM set_profile. ENDFORM. "read_packstation |