ABAP顾问
分类:
2007-06-24 11:03:05
得到一个获取SOLUTION MANAGER KEY的程序,不知道适用SAP的什么版本
*&---------------------------------------------------------------------*
*& Report Z_BARRY_GET_KEY *
*& *
*&---------------------------------------------------------------------*
*& 得到SOLUTION MANAGER KEY *
*& *
*&---------------------------------------------------------------------*
REPORT z_barry_get_key .
TYPES: BEGIN OF dswpclientkey,
instno TYPE num10,
dbid(3),
bundle_id(8),
service_key(40),
END OF dswpclientkey.
*data: dswpclientkey_w type standard table of dswpclientkey.
DATA: p_value(10),
p_instno(10).
PARAMETERS: p_sid(3),
p_sysno(2),
p_server(15).
START-OF-SELECTION.
PERFORM get_sp_value USING p_sid
p_sysno
p_server
p_instno
CHANGING p_value.
WRITE p_value.
*&---------------------------------------------------------------------*
*& Form get_sp_value
*&---------------------------------------------------------------------*
FORM get_sp_value USING p_pf_sid
p_pf_sysno
p_pf_server
p_pf_instno
CHANGING p_pf_value.
CONSTANTS: lc_part_len TYPE i VALUE 5,
lc_pw_len TYPE i VALUE 10,
lc_allowed_chars(38) TYPE c VALUE
'-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_'.
DATA: lf_string(20) TYPE c,
lf_key TYPE i,
ls_key TYPE dswpclientkey,
lf_part(lc_part_len) TYPE c,
lf_finalf(lc_pw_len) TYPE c,
lf_finalx TYPE xstring,
lf_xbuffer TYPE xstring,
lf_opf(10) TYPE c,
lf_langu LIKE sy-langu,
lf_subrc LIKE sy-subrc,
lf_len TYPE i,
lo_conv_to_x TYPE REF TO cl_abap_conv_out_ce.
CLEAR: lf_string, lf_finalx, lf_opf.
CONCATENATE p_pf_sid p_pf_sysno p_pf_server INTO lf_string.
TRANSLATE lf_string TO UPPER CASE.
lf_langu = sy-langu.
SET LOCALE LANGUAGE 'E'.
lo_conv_to_x = cl_abap_conv_out_ce=>create( encoding = '1100' ).
lf_len = STRLEN( lf_string ).
IF lf_string(lf_len) CN lc_allowed_chars.
ELSE.
WHILE lf_len > 0.
lf_part = lf_string(lc_part_len).
SHIFT lf_string BY lc_part_len PLACES.
lf_len = STRLEN( lf_string ).
CALL METHOD lo_conv_to_x->reset.
CALL METHOD lo_conv_to_x->write( data = lf_part n = -1 ).
lf_xbuffer = lo_conv_to_x->get_buffer( ).
lf_finalx = lf_finalx BIT-XOR lf_xbuffer.
ENDWHILE.
lf_key = 12.
PERFORM scramble USING lf_finalx
lf_key
lc_part_len
CHANGING lf_finalf
lf_subrc.
IF NOT lf_finalf IS INITIAL.
p_pf_value = lf_finalf.
ls_key-dbid = p_pf_sid.
ls_key-instno = p_pf_instno.
ls_key-bundle_id = 'SM_KEY'.
ls_key-service_key = lf_finalf.
IF NOT p_pf_instno IS INITIAL.
* insert dswpclientkey_w from ls_key.
IF sy-subrc <> 0.
* update dswpclientkey_w from ls_key.
ENDIF.
ENDIF.
ELSE.
CLEAR p_pf_value.
ENDIF.
ENDIF.
ENDFORM. " get_sp_value
*&---------------------------------------------------------------------*
*& Form scramble
*&---------------------------------------------------------------------*
FORM scramble USING iv_xstring TYPE xstring
iv_key TYPE i
iv_src_len TYPE i
CHANGING lf_finalf
lf_subrc LIKE sy-subrc.
CONSTANTS: lc_max_len TYPE i VALUE 20,
lc_mask(4) TYPE x VALUE '0000003F',
lc_random(64) TYPE x VALUE
'F0ED53B83244F1F876C67959FD4F13A2' &
'C15195EC5483C234774943A27DE26596' &
'5E5398789A17A33CD383A8B829FBDCA5' &
'55D702778413ACDDF9B83116610E6DFA'.
DATA: lv_key_index(4) TYPE x,
lv_rand_index(4) TYPE x,
lv_xkey(4) TYPE x,
lv_xkey_shl_1(4) TYPE x,
lv_xkey_shr_5(4) TYPE x,
lv_scramble_byte TYPE x,
lv_dest(lc_max_len) TYPE x,
lv_index TYPE i,
lv_len TYPE i.
CLEAR lf_subrc.
IF iv_src_len EQ 0. EXIT. ENDIF.
lv_len = XSTRLEN( iv_xstring ).
IF iv_src_len GT lc_max_len OR
iv_src_len GT lv_len.
lf_subrc = 2.
EXIT.
ENDIF.
lv_xkey = iv_key.
lv_xkey_shl_1 = iv_key * 2.
lv_xkey_shr_5 = iv_key DIV 32.
lv_rand_index = lv_xkey BIT-XOR lv_xkey_shr_5 BIT-XOR lv_xkey_shl_1.
lv_rand_index = lv_rand_index BIT-AND lc_mask.
lv_index = 0.
DO iv_src_len TIMES.
CATCH SYSTEM-EXCEPTIONS compute_int_times_overflow = 1.
lv_key_index = ( iv_key * lv_index * lv_index ) - lv_index.
ENDCATCH.
IF sy-subrc <> 0.
lf_subrc = 1.
EXIT.
ENDIF.
lv_scramble_byte = lc_random+lv_rand_index(1) BIT-XOR
lv_key_index+3(1).
lv_dest+lv_index(1) = iv_xstring+lv_index(1) BIT-XOR
lv_scramble_byte.
lv_index = lv_index + 1.
lv_rand_index = lv_rand_index + 1.
lv_rand_index = lv_rand_index BIT-AND lc_mask.
ENDDO.
IF lf_subrc <> 0.
EXIT.
ENDIF.
WRITE lv_dest(iv_src_len) TO lf_finalf.
ENDFORM. " scramble