SAPHRABAP调用Visio生成组织架构图.docx
《SAPHRABAP调用Visio生成组织架构图.docx》由会员分享,可在线阅读,更多相关《SAPHRABAP调用Visio生成组织架构图.docx(53页珍藏版)》请在冰豆网上搜索。
SAPHRABAP调用Visio生成组织架构图
提供树表报和Visio展示两种方式。
基于标准程序RHSTRU00改造。
*&-----------------------------------------------------------------
*& Report ZHR_REP_01
*&------------------------------------------------------------------
*& Program Name :
ZHR_REP_01
*& Description :
XX组织结构图
*& Author :
*& Date :
*& Tcode :
*& Note :
Based on standard report RHSTRU00. Calls MS
Visio object.
*&------------------------------------------------------------------
REPORT ZHR_REP_01.
TYPE-POOLS:
icon.
TABLES:
objec, t77eo, gdstr, gdset, pdstr.
TYPES:
BEGIN OF t_node ,
id LIKE struc-seqnr,
parent LIKE struc-seqnr,
tree_id TYPE lvc_nkey,
text(25),
text4(40),
short(14),
otype
(2),
realo TYPE realo,
istat
(1),
begda(10),
endda(10),
vistat
(1),
vbegda(10),
vendda(10),
prozt(8),
objid LIKE objec-objid,
END OF t_node.
TYPES:
BEGIN OF type_trec,
key TYPE lvc_nkey,
id LIKE struc-seqnr,
END OF type_trec.
TYPES:
BEGIN OF parent_stack_line,
level TYPE struc-level,
id LIKE struc-seqnr,
END OF parent_stack_line.
*----------------------------------------------------------------------*
* error handling (for internal errors)
*----------------------------------------------------------------------*
* type for ABAP callstack
TYPES:
BEGIN OF t_s_abap_callstack,
mainprogram LIKE sy-repid,
include LIKE sy-repid,
line TYPE i,
eventtype LIKE abdbg-leventtype,
event LIKE abdbg-levent,
flag_system,
END OF t_s_abap_callstack.
* variable for ABAP callstack
DATA:
g_callstack TYPE STANDARD TABLE OF t_s_abap_callstack,
g_callstack_wa TYPE t_s_abap_callstack.
* macro should never be called ;-)
DEFINE internal_error. "&1 action that lead to error
* get callstack
call 'ABAP_CALLSTACK' id 'DEPTH' field 99
id 'CALLSTACK' field g_callstack.
* get current form/event
read table g_callstack into g_callstack_wa index 1.
message i001(aq_ad_hoc) with g_callstack_wa-event
&1. "action.
END-OF-DEFINITION.
DATA:
it_node TYPE STANDARD TABLE OF t_node,
it_tab TYPE STANDARD TABLE OF t_node,
wa_node TYPE t_node.
DATA:
BEGIN OF waobjec,
stext LIKE objec-stext,
short LIKE objec-short,
realo LIKE objec-realo,
plvar LIKE objec-plvar,
otype LIKE objec-otype,
objid LIKE objec-objid,
begda LIKE objec-begda,
endda LIKE objec-endda,
istat LIKE objec-istat,
seqnr LIKE struc-seqnr,
END OF waobjec.
DATA:
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
CLASS cl_gui_object DEFINITION LOAD.
DATA:
control_container TYPE REF TO cl_gui_custom_container,
alv_tree_control TYPE REF TO cl_gui_alv_tree,
alv_html_header TYPE REF TO cl_gui_html_viewer,
fieldcatalog TYPE STANDARD TABLE OF lvc_s_fcat,
hierarchy_header TYPE treev_hhdr.
DATA:
lt_list_commentary TYPE slis_t_listheader,
gs_variant TYPE disvariant.
DATA:
s_node TYPE lvc_nkey.
DATA:
otype TYPE otype.
DATA:
answer
(1).
DATA:
it_toolbar_excluding TYPE ui_functions.
DATA:
excl_tab TYPE TABLE OF sy-ucomm.
DATA:
it_recursions TYPE STANDARD TABLE OF type_trec,
exist_rec TYPE flag_x.
DATA:
repid LIKE sy-repid,
sel_table TYPE TABLE OF rsparams.
DATA:
g_optimize_flag TYPE flag VALUE ' ', "note 768405
g_optimize_button TYPE smp_dyntxt. "#EC NEEDED
* parent handling
DATA:
g_parent_stack TYPE STANDARD TABLE OF parent_stack_line,
g_parent_stack_wa TYPE parent_stack_line.
DATA:
lv_string TYPE string.
DATA:
gx_acc_mode_on TYPE abap_bool.
TYPES:
BEGIN OF t_data,
id TYPE struc-seqnr,
parent TYPE struc-seqnr,
oname TYPE hrp1000-short,
sname TYPE hrp1000-short,
pname TYPE hrp1000-short,
orgid TYPE hrp1000-objid,
posid TYPE hrp1000-objid,
perid TYPE hrp1000-objid,
kname TYPE hrp1000-short,
kccid TYPE hrp1000-objid,
graph TYPE i,
imagefile TYPE char40,
END OF t_data.
DATA:
gt_data TYPE STANDARD TABLE OF t_data.
DATA:
wa_data TYPE t_data.
DATA:
g_visio_path TYPE string,
g_visio_para TYPE string.
* OLE对象
DATA:
g_aplicacion TYPE ole2_object. "Aplicacion Visio
DATA:
g_documentos TYPE ole2_object. "Coleccion de Documentos Visio
DATA:
g_documento TYPE ole2_object. "Documento Visio
DATA:
g_addon TYPE ole2_object. "Addon
DATA:
g_addons TYPE ole2_object. "Addons
DATA:
g_sistema TYPE ole2_object. "Addons
DATA:
g_template_path TYPE string.
DATA:
g_template_file TYPE string.
DATA:
g_data_file TYPE string.
DATA:
g_workdir TYPE string.
DATA:
g_parametro_macro TYPE string,
g_orgwiz TYPE string VALUE 'OrgCWIZ'.
*----------------------------------------------------------------------*
* SELECTION SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK block1
WITH FRAME
TITLE text-001.
* technical depth
PARAMETERS :
tdepth LIKE gdstr-tdepth.
SELECTION-SCREEN SKIP.
* recursion check
PARAMETERS:
recurs RADIOBUTTON GROUP g2 LIKE pppch-recurs DEFAULT 'X'.
PARAMETERS:
visio RADIOBUTTON GROUP g2 TYPE flag_x .
SELECTION-SCREEN END OF BLOCK block1.
*PARAMETERS:
ORG_PATH TYPE STRING DEFAULT 'C:
\Program Files\Microsoft Office\Office12\ORGWIZ.EXE'.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
* Structured evaluation
$pch$-acces = $structured$.
pchtimed = 'D'.
* initialize variables
CLEAR:
waobjec,
it_node[].
repid = sy-repid.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
* perform report for all objects?
IF pchobjid[] IS INITIAL AND pchsobid[] IS INITIAL.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = '消息'(027)
text_question = '查询所有部门?
'(015)
display_cancel_button = ' '
IMPORTING
answer = answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
internal_error 'FUNCTION POPUP_TO_CONFIRM' . "#EC NOTEXT
ENDIF.
* back to selection screen
IF answer = '2'.
CLEAR sel_table[].
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = repid
TABLES
selection_table = sel_table
EXCEPTIONS
not_found = 1
no_report = 2
OTHERS = 3.
IF sy-subrc <> 0.
internal_error 'RS_REFRESH_FROM_SELECTOPTIONS'. "#EC NOTEXT
ENDIF.
SUBMIT rhstru00
VIA SELECTION-SCREEN
WITH SELECTION-TABLE sel_table.
ENDIF.
ENDIF.
* Branchwise authority
$pch$-stru_authy = 'A'.
* Check recursions
IF recurs = 'X'.
$pch$-recurs = 'X'.
ENDIF.
* technical depth
$pch$-tdepth = tdepth.
$pch$-refre = $off$.
*----------------------------------------------------------------------*
* GET OBJEC *
*----------------------------------------------------------------------*
GET objec.
CLEAR waobjec.
MOVE-CORRESPONDING objec TO waobjec.
waobjec-seqnr = struc-seqnr.
* set the current id of the node
wa_node-id = struc-seqnr.
* determine the correct parent id
IF struc-pup = 0.
* there is no parent as this is the topmost node
CLEAR:
g_parent_stack, g_parent_stack_wa.
wa_node-parent = struc-pup.
* add the current node as parent to the stack
g_parent_stack_wa-level = struc-level.
g_parent_stack_wa-id = struc-seqnr.
INSERT g_parent_stack_wa INTO g_parent_stack
INDEX 1.
ELSE.
* there was a parent
READ TABLE g_parent_stack
INDEX 1
INTO g_parent_stack_wa.
IF sy-subrc = 0.
*there is a parent in the stack available now check if the levels match
IF g_parent_stack_wa-level >= struc-level.
* delete the entries that are deeper in the structure
* as they can not be the parents
DELETE g_parent_stack
WHERE level >= struc-level.
ENDIF.
* read again the topmost entry from the stack
READ TABLE g_parent_stack
INDEX 1
INTO g_parent_stack_wa.
IF sy-subrc = 0.
* there is a parent
wa_node-parent = g_parent_stack_wa-id.
* add the current node as parent to the stack
g_parent_stack_wa-level = struc-level.
g_parent_stack_wa-id = struc-seqnr.
INSERT g_parent_stack_wa INTO g_parent_stack
INDEX 1.
ELSE.
* there is no parent this is the topmost node others where skipped
wa_node-parent = struc-pup.
* add the current node as parent to the stack
g_parent_stack_wa-level = struc-level.
g_parent_stack_wa-id = struc-seqnr.
INSERT g_parent_stack_wa INTO g_parent_stack
INDEX 1.
ENDIF.
ELSE.
* there is no parent this is the topmost node others where skipped
wa_node-parent = struc-pup.
* add the current node as parent to the stack
g_parent_stack_wa-level = struc-level.
g_parent_stack_wa-id = struc-seqnr.
INSERT g_parent_stack_wa INTO g_parent_stack
INDEX 1.
ENDIF.
ENDIF.
* node text
IF NOT wa