메뉴 건너뛰기

SAP 한국 커뮤니티

ip

양파링 2011.11.02 23:19 조회 수 : 6128

DATA: BEGIN OF DESTI OCCURS 100.
        INCLUDE STRUCTURE MSXXLIST.
DATA: END OF DESTI.

DATA: BEGIN OF USR_LIST OCCURS 1000.
        INCLUDE STRUCTURE UINFO.
DATA: END OF USR_LIST.

DATA: BEGIN OF SERVERP OCCURS 100, " Presentationserver
        S(32),
        SL(15),
        X(4) TYPE X,
        L(5),
        H(5),
        M(5),
        C,
        PRO(4),
        COMMU,
        " SL(31) for new IP-Address
END OF SERVERP.

 

 

 

FORM GET_IP   CHANGING P_IP.

  REFRESH DESTI.
  CALL FUNCTION 'RFC_GET_LOCAL_SERVERS'
    TABLES
      HOSTS         = DESTI
    EXCEPTIONS
      NOT_AVAILABLE = 1.

  CLEAR DESTI.
  READ TABLE DESTI WITH KEY HOST = SY-HOST.
  IF SY-SUBRC EQ 0.
    REFRESH USR_LIST.
    CALL FUNCTION 'THUSRINFO' DESTINATION DESTI-NAME
      TABLES
        USR_TABL              = USR_LIST
      EXCEPTIONS
        COMMUNICATION_FAILURE = 17.
    IF SY-SUBRC = '17'.
      SERVERP-COMMU = 'P'.
      EXIT.
    ELSE.
      SERVERP-COMMU = ' '.
    ENDIF.

    CLEAR USR_LIST.
    READ TABLE USR_LIST WITH KEY BNAME = SY-UNAME.
    IF SY-SUBRC EQ 0.
      CLEAR SERVERP-S.
      SERVERP-S = USR_LIST-TERM.
      SERVERP-X = USR_LIST-HOSTADR.
      PERFORM IP_HEX2ASCII_N USING SERVERP-X CHANGING SERVERP-SL.
      MOVE SERVERP-SL TO P_IP.
    ENDIF.
  ENDIF.

ENDFORM.                    " GET_IP
*&---------------------------------------------------------------------*
*&      Form  IP_HEX2ASCII_N
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SERVERP_X  text
*      <--P_SERVERP_SL  text
*----------------------------------------------------------------------*
FORM IP_HEX2ASCII_N USING DESI CHANGING ERGEBNIS.
  DATA: T     TYPE X,
        TT(3),
        HELP  TYPE I,
        HELP1 TYPE I VALUE 0,
        DESTI_X(8) TYPE X ,
        DESI_HLP TYPE I,
        H_TYPE.

* unicode
  DESCRIBE FIELD DESI LENGTH DESI_HLP IN BYTE MODE.
* non-unicode
*  DESCRIBE FIELD DESI LENGTH DESI_HLP.

  DESCRIBE FIELD DESI TYPE H_TYPE.

  IF DESI_HLP <> 4 AND DESI_HLP <> 8.
*    WRITE: / 'Length of processed IP-address is'(026), DESI_HLP, '.'.
*    WRITE: / 'It should be of length 4 or 8 !'(027).
  ELSE.
    IF H_TYPE = 'X'.
      DESTI_X = DESI.
      DESI_HLP = DESI_HLP - 1.

      CLEAR ERGEBNIS.
      DO DESI_HLP TIMES. " 4 or 8 Bytes ?3 or 7 times
        T = DESTI_X+HELP1(1).
        PERFORM HEX2ASCII USING T CHANGING TT.
        HELP = STRLEN( ERGEBNIS ).
        ERGEBNIS+HELP = TT.
        HELP = STRLEN( ERGEBNIS ).
        ERGEBNIS+HELP = '.'.
        HELP1 = HELP1 + 1.
      ENDDO.
      T = DESTI_X+HELP1(1).
      PERFORM HEX2ASCII USING T CHANGING TT.
      HELP = STRLEN( ERGEBNIS ).
      ERGEBNIS+HELP = TT.
    ELSE.
      EXIT.
    ENDIF.
  ENDIF.

ENDFORM.                    " IP_HEX2ASCII_N
*&---------------------------------------------------------------------*
*&      Form  HEX2ASCII
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T  text
*      <--P_TT  text
*----------------------------------------------------------------------*
FORM HEX2ASCII USING T CHANGING V.

  DATA : H TYPE I,
         E(3).
  H = T. E = H.
  CONDENSE E.
  V = E.

ENDFORM.                                                    " HEX2ASCII