REPORT z_barry_hex_to_ip_addr .
DATA: hexhost(8) ,
iptext(15) TYPE c ,
p(6) TYPE p .
DATA: tid LIKE arfctid.
CALL FUNCTION 'ARFC_GET_TID'
IMPORTING
tid = tid.
hexhost = tid-arfcipid.
PERFORM hex2ipstr USING hexhost iptext .
WRITE / iptext .
CLEAR p.
PERFORM ip2dec USING iptext p.
WRITE / p .
CLEAR iptext.
PERFORM dec2ip USING p iptext.
WRITE / iptext.
*&---------------------------------------------------------------------*
*& 十六进制转换成IP
*&---------------------------------------------------------------------*
FORM hex2ipstr USING value(hexstr) TYPE c
ipstr TYPE c .
DATA: hex TYPE x ,
dec TYPE i ,
ipstr_tmp TYPE string .
CLEAR ipstr.
DO 4 TIMES.
hex = hexstr+0(2).
dec = hex .
ipstr_tmp = dec .
CONCATENATE ipstr '.' ipstr_tmp INTO ipstr.
SHIFT hexstr LEFT BY 2 PLACES .
ENDDO.
SHIFT ipstr .
ENDFORM.
*&---------------------------------------------------------------------*
*& IP转换成长整型
*&---------------------------------------------------------------------*
FORM ip2dec USING value(ipstr) TYPE c
num TYPE p .
* ipstr= '192.168.0.1'.
DATA: sum(6) TYPE p ,
s1 TYPE string ,
s2 TYPE string .
CLEAR num.
s2 = ipstr .
DO 4 TIMES.
SPLIT s2 AT '.' INTO s1 s2.
sum = sum + s1 * ( 256 ** ( 4 - sy-index ) ).
ENDDO.
num = sum.
ENDFORM.
*&---------------------------------------------------------------------*
*& 长整型转换为IP
*&---------------------------------------------------------------------*
FORM dec2ip USING value(num) TYPE p
ipstr TYPE c .
* num = '3232235521'.
DATA: iptmp TYPE string ,
p(6) TYPE p DECIMALS 4 .
CLEAR ipstr.
DO 4 TIMES.
p = num / ( 256 ** ( 4 - sy-index ) ) .
iptmp = TRUNC( p ) .
num = num - iptmp * ( 256 ** ( 4 - sy-index ) ) .
CONCATENATE ipstr '.' iptmp INTO ipstr.
ENDDO.
SHIFT ipstr.
ENDFORM.
阅读(8919) | 评论(0) | 转发(0) |