ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [XML] ABAP 下载XML文件

[XML] ABAP 下载XML文件

原创 Linux操作系统 作者:alpheren 时间:2009-01-07 14:35:37 0 删除 编辑
********************************************************************
* Report for generating class from XML-file
* Author: Sergey Korolev (slkorolev@mail.ru)
* Does not work with interfaces and exception classes
********************************************************************
REPORT  yrs_class_upload_xml                                        .
PARAMETERS:
xmlfile TYPE localfile.
TYPE-POOLS: seok, seop.
INCLUDE yrs_class_xml_const.
DATA:
corr_mode,
* Extracted structures (from XML file)
gt_locals_src    TYPE	seop_source_string,
gt_locals_def    TYPE	seop_source_string,
gt_locals_imp    TYPE	seop_source_string,
gt_locals_mac    TYPE	seop_source_string,
gs_class  TYPE  vseoclass,
gt_attributes TYPE  seoo_attributes_r,
gt_methods  TYPE  seoo_methods_r,
gt_events TYPE  seoo_events_r,
gt_types  TYPE  seoo_types_r,
gt_parameters TYPE  seos_parameters_r,
gt_exceps TYPE  seos_exceptions_r,
gt_implementings  TYPE  seor_implementings_r,
gs_inheritance  TYPE  vseoextend,
gt_redefinitions  TYPE  seor_redefinitions_r,
gt_impl_details TYPE  seor_redefinitions_r,
gt_friendships  TYPE  seof_friendships_r,
gt_typepusages  TYPE  seot_typepusages_r,
gt_clsdeferrds  TYPE  seot_clsdeferrds_r,
gt_intdeferrds  TYPE  seot_intdeferrds_r,
gt_aliases  TYPE  seoo_aliases_r,
gt_interfaces TYPE  seok_int_typeinfos,
gs_includes TYPE  seop_methods_w_include,
gt_texts TYPE TABLE OF textpool,
gt_source TYPE  seop_source,
gt_type_source     TYPE	seop_source,
gt_mtd_source   TYPE seo_method_source_table,
wa_mtd_source   TYPE seo_method_source.
CLASS lcx_xml_error DEFINITION DEFERRED.
DATA:
ex TYPE REF TO lcx_xml_error.
*----------------------------------------------------------------------*
*       CLASS lCX_xml_error  DEFINITIO
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_xml_error DEFINITION
INHERITING FROM cx_static_check.
PUBLIC SECTION.
DATA: error TYPE string.
METHODS: constructor IMPORTING value(i_error) TYPE string OPTIONAL.
ENDCLASS.                    "lCX_xml_error  DEFINITIO
*----------------------------------------------------------------------*
*       CLASS lcx_xml_section_error  DEFINITIO
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_xml_section_error DEFINITION
INHERITING FROM lcx_xml_error.
PUBLIC SECTION.
METHODS: constructor IMPORTING value(i_section) TYPE string OPTIONAL
.
ENDCLASS.                    "lCX_xml_error  DEFINITIO
*----------------------------------------------------------------------*
*       CLASS lcx_xml_error IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_xml_error IMPLEMENTATION.
METHOD constructor.
CALL METHOD super->constructor.
error = i_error.
ENDMETHOD.                    "constructor
ENDCLASS.                    "lcx_xml_error IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS lcx_xml__section_error IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_xml_section_error IMPLEMENTATION.
METHOD constructor.
DATA:
msg TYPE string.
CONCATENATE 'File does not contain obligatory section'
i_section
INTO msg
SEPARATED BY space.
CALL METHOD super->constructor
EXPORTING
i_error = msg.
ENDMETHOD.                    "constructor
ENDCLASS.                    "lcx_xml__section_error IMPLEMENTATION
AT SELECTION-SCREEN ON VALUE-REQUEST FOR xmlfile.
DATA:
file_table  TYPE filetable,
action TYPE i,
rc TYPE sysubrc.
FIELD-SYMBOLS:
 TYPE file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
default_extension       = 'xml'
file_filter             = cl_gui_frontend_services=>filetype_xml
CHANGING
file_table              = file_table
rc                      = rc
user_action             = action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error              = 2
error_no_gui            = 3
not_supported_by_gui    = 4
OTHERS                  = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CHECK action = cl_gui_frontend_services=>action_ok.
READ TABLE file_table INDEX 1 ASSIGNING .
xmlfile = .
START-OF-SELECTION.
DATA:
retcode TYPE sysubrc,
source_node TYPE REF TO if_ixml_node,
xml TYPE REF TO cl_xml_document.
CREATE OBJECT xml.
TRY.
CALL METHOD xml->import_from_file
EXPORTING
filename = xmlfile
RECEIVING
retcode  = retcode.
IF retcode NE xml->c_ok.
DATA:
msg TYPE string.
CASE retcode.
WHEN xml->c_no_ixml.
msg = 'This is not XML file'.
WHEN xml->c_failed.
msg = 'Failed to parse the XML file'.
WHEN xml->c_not_found.
msg = 'XML file not found'.
ENDCASE.
RAISE EXCEPTION TYPE lcx_xml_error
EXPORTING i_error = msg.
ENDIF.
DEFINE load_section.
call method xml->get_data
exporting
name       = &1
importing
retcode    = retcode
changing
dataobject = &2.
if retcode ne xml->c_ok.
raise exception type lcx_xml_section_error
exporting i_section = &1.
endif.
END-OF-DEFINITION.
load_section:
c_xml_root gs_class,
c_xml_attributes gt_attributes,
c_xml_methods gt_methods,
c_xml_events gt_events,
c_xml_types gt_types,
c_xml_parameters gt_parameters,
c_xml_exceps gt_exceps,
c_xml_implementings gt_implementings,
c_xml_impl_details gt_impl_details,
c_xml_friendships gt_friendships,
c_xml_typepusages gt_typepusages,
c_xml_clsdeferrds gt_clsdeferrds,
c_xml_intdeferrds gt_intdeferrds,
c_xml_aliases gt_aliases,
c_xml_inheritance gs_inheritance,
c_xml_interfaces gt_interfaces,
c_xml_redefinitions gt_redefinitions,
c_xml_typesource gt_type_source,
*        c_xml_text_pool gt_texts,
c_xml_locals_src gt_locals_src,
c_xml_locals_def gt_locals_def,
c_xml_locals_mac gt_locals_mac,
c_xml_locals_imp gt_locals_imp.
* Now find method implementation node containing sources
* for each method as a subnode
CALL METHOD xml->find_node
EXPORTING
name = c_xml_method_src
RECEIVING
node = source_node.
IF source_node IS INITIAL.
RAISE EXCEPTION TYPE lcx_xml_section_error
EXPORTING i_section = c_xml_methods.
ENDIF.
source_node = source_node->get_first_child( ).
DATA:
name1 TYPE string,
name2 TYPE string,
xml_sep(5) VALUE '_--7E'.
WHILE NOT source_node IS INITIAL.
CLEAR wa_mtd_source.
name1 = source_node->get_name( ).
SPLIT name1 AT xml_sep INTO name1 name2.
IF name2 IS INITIAL.
wa_mtd_source-cpdname = name1.
ELSE.
CONCATENATE name1 name2 INTO wa_mtd_source-cpdname
SEPARATED BY '~'.
ENDIF.
CALL METHOD xml->get_node_data
EXPORTING
node       = source_node
IMPORTING
dataobject = wa_mtd_source-source
retcode    = retcode.
IF retcode = xml->c_ok.
APPEND wa_mtd_source TO gt_mtd_source.
ENDIF.
source_node = source_node->get_next( ).
ENDWHILE.
CATCH lcx_xml_error INTO ex.
MESSAGE ex->error TYPE 'E'.
ENDTRY.
DATA:
answer,
fields TYPE TABLE OF sval WITH HEADER LINE,
parameter	TYPE TABLE OF spar WITH HEADER LINE,
clskey TYPE seoclskey.
clskey-clsname = gs_class-clsname.
corr_mode = 'I'.
DO.
CALL FUNCTION 'SEO_CLASS_GET'
EXPORTING
clskey       = clskey
EXCEPTIONS
not_existing = 1
deleted      = 2
is_interface = 3
model_only   = 4
OTHERS       = 5.
IF sy-subrc NE 0.
EXIT.
ENDIF.
REFRESH parameter.
parameter-param = 'CLASS'.
parameter-value = clskey-clsname.
APPEND parameter.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar              = 'Class already exists'
text_question         =
'Class &CLASS& already exists. Overwrite?'
default_button        = '2'
IMPORTING
answer                = answer
TABLES
parameter             = parameter
EXCEPTIONS
text_not_found        = 0
OTHERS                = 0.
CASE answer.
WHEN '1'.
corr_mode = 'U'.
EXIT.
WHEN 'A'.
RETURN.
ENDCASE.
REFRESH fields.
fields-tabname = 'SEOCLSKEY'.
fields-fieldname = 'CLSNAME'.
fields-value = clskey-clsname.
APPEND fields.
CALL FUNCTION 'POPUP_GET_VALUES'
EXPORTING
popup_title     = 'Enter new class name'
IMPORTING
returncode      = answer
TABLES
fields          = fields
EXCEPTIONS
error_in_fields = 1
OTHERS          = 2.
IF answer = 'A'.
RETURN.
ENDIF.
READ TABLE fields INDEX 1.
clskey-clsname = fields-value.
ENDDO.
IF clskey-clsname NE gs_class-clsname.
gs_class-clsname = clskey-clsname.
gs_class-author = sy-uname.
gs_class-changedby = sy-uname.
gs_class-changedon = sy-datum.
gs_inheritance-clsname = clskey-clsname.
PERFORM. rename_class TABLES gt_implementings USING clskey-clsname.
PERFORM. rename_class TABLES gt_attributes USING clskey-clsname.
PERFORM. rename_class TABLES gt_methods USING clskey-clsname.
PERFORM. rename_class TABLES gt_events USING clskey-clsname.
PERFORM. rename_class TABLES gt_types USING clskey-clsname.
PERFORM. rename_class TABLES gt_parameters USING clskey-clsname.
PERFORM. rename_class TABLES gt_exceps USING clskey-clsname.
PERFORM. rename_class TABLES gt_aliases USING clskey-clsname.
PERFORM. rename_class TABLES gt_typepusages USING clskey-clsname.
PERFORM. rename_class TABLES gt_clsdeferrds USING clskey-clsname.
PERFORM. rename_class TABLES gt_intdeferrds USING clskey-clsname.
PERFORM. rename_class TABLES gt_redefinitions USING clskey-clsname.
PERFORM. rename_class TABLES gt_impl_details USING clskey-clsname.
PERFORM. rename_class TABLES gt_friendships USING clskey-clsname.
ENDIF.
DATA:
devclass  LIKE  tadir-devclass,
korrnum LIKE  e070-trkorr.
CALL FUNCTION 'RS_CORR_INSERT'
EXPORTING
object              = gs_class-clsname
object_class        = 'CLAS'
mode                = corr_mode
global_lock         = 'X'
master_language     = gs_class-langu
IMPORTING
devclass            = devclass
korrnum             = korrnum
EXCEPTIONS
cancelled           = 1
permission_failure  = 2
unknown_objectclass = 3
OTHERS              = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA:
overwrite TYPE seox_boolean.
IF corr_mode = 'U'.
verwrite = seox_true.
ENDIF.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Generating class definition'.
CALL FUNCTION 'SEO_CLASS_CREATE_COMPLETE'
EXPORTING
corrnr          = korrnum
devclass        = devclass
version         = seoc_version_inactive
overwrite       = overwrite
IMPORTING
korrnr          = korrnum
CHANGING
class           = gs_class
inheritance     = gs_inheritance
redefinitions   = gt_redefinitions
implementings   = gt_implementings
impl_details    = gt_impl_details
attributes      = gt_attributes
methods         = gt_methods
events          = gt_events
types           = gt_types
type_source     = gt_type_source
PARAMETERS      = gt_parameters
exceps          = gt_exceps
aliases         = gt_aliases
typepusages     = gt_typepusages
clsdeferrds     = gt_clsdeferrds
intdeferrds     = gt_intdeferrds
friendships     = gt_friendships
EXCEPTIONS
existing        = 1
is_interface    = 2
db_error        = 3
component_error = 4
no_access       = 5
other           = 6
OTHERS          = 7.
IF sy-subrc <> 0.
MESSAGE 'Error generating class' TYPE 'E'.
ENDIF.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Generating local class definitions'.
CALL FUNCTION 'SEO_CLASS_GENERATE_LOCALS'
EXPORTING
clskey                 = clskey
force                  = seox_true
corrnr                 = korrnum
implementation         = gt_locals_src
locals_def             = gt_locals_def
locals_imp             = gt_locals_imp
locals_mac             = gt_locals_mac
EXCEPTIONS
not_existing           = 1
model_only             = 2
locals_not_generated   = 3
locals_not_initialised = 4
OTHERS                 = 5.
IF sy-subrc <> 0.
MESSAGE 'Error generating local class definitions' TYPE 'E'.
ENDIF.
FIELD-SYMBOLS:
 TYPE seo_method_source.
DATA:
status_line(128),
mtdkey TYPE seocpdkey.
LOOP AT gt_mtd_source ASSIGNING .
CONCATENATE 'Generating implementation of the method'
-cpdname
INTO status_line
SEPARATED BY space.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = status_line.
mtdkey-clsname = clskey-clsname.
mtdkey-cpdname = -cpdname.
CALL FUNCTION 'SEO_METHOD_GENERATE_INCLUDE'
EXPORTING
mtdkey                         = mtdkey
force                          = seox_true
suppress_corr                  = seox_true
implementation_expanded        = -source
corrnr                         = korrnum
without_method_frame. = seox_true
EXCEPTIONS
not_existing                   = 1
model_only                     = 2
include_existing               = 3
method_imp_not_generated       = 4
method_imp_not_initialised     = 5
_internal_class_not_existing   = 6
_internal_method_overflow      = 7
cancelled                      = 8
method_is_abstract_implemented = 9
method_is_final_implemented    = 10
internal_error_insert_report   = 11
OTHERS                         = 12.
*    IF sy-subrc <> 0.
*      MESSAGE 'Error generating class' TYPE 'E'.
*    ENDIF.
ENDLOOP.
* Now find text pool node containing textpools for
* different languages as subnodes
DATA:
langu TYPE sy-langu,
include_name TYPE programm.
TRY.
CALL FUNCTION 'SEO_CLASS_GET_INCLUDE_BY_NAME'
EXPORTING
clskey   = clskey
IMPORTING
progname = include_name.
CALL METHOD xml->find_node
EXPORTING
name = c_xml_text_pool
RECEIVING
node = source_node.
IF source_node IS INITIAL.
RAISE EXCEPTION TYPE lcx_xml_section_error
EXPORTING i_section = c_xml_text_pool.
ENDIF.
source_node = source_node->get_first_child( ).
WHILE NOT source_node IS INITIAL.
langu = source_node->get_name( ).
REFRESH gt_texts.
CALL METHOD xml->get_node_data
EXPORTING
node       = source_node
IMPORTING
dataobject = gt_texts
retcode    = retcode.
source_node = source_node->get_next( ).
CHECK retcode = xml->c_ok
AND   NOT gt_texts IS INITIAL.
CONCATENATE 'Generating class text pool for language'
langu
INTO msg
SEPARATED BY space.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = msg.
INSERT textpool include_name
FROM gt_texts
LANGUAGE langu.
ENDWHILE.
CATCH lcx_xml_section_error.
MESSAGE 'XML-file does not contain Text pool data' TYPE 'S'.
ENDTRY.
SET PARAMETER ID 'CLASS' FIELD clskey-clsname.
CALL TRANSACTION 'SE24'.
*&---------------------------------------------------------------------*
*&      Form. rename_class
*&---------------------------------------------------------------------*
*       Renames class references in arbitrary table
*----------------------------------------------------------------------*
*      -->P_TABLE    some generation structure
*      -->P_NAME     new class name
*----------------------------------------------------------------------*
FORM. rename_class  TABLES   p_table
USING    p_name.
FIELD-SYMBOLS:
 TYPE ANY,
 TYPE ANY.
DEFINE set_field.
assign component &1 of structure  to .
if sy-subrc = 0.
 = &2.
endif.
END-OF-DEFINITION.
LOOP AT p_table ASSIGNING .
set_field 'CLSNAME' p_name.
set_field 'AUTHOR' sy-uname.
set_field 'CHANGEDBY' sy-uname.
ENDLOOP.
ENDFORM.                    " rename_class

[Edit section] Report YRS_CLASS_DOWNLOAD_XML

********************************************************************
* Report for generating XML-file from class
* Author: Sergey Korolev (slkorolev@mail.ru)
* Does not work with interfaces and exception classes
********************************************************************
REPORT yrs_class_download.
PARAMETERS: class TYPE seoclskey OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS: p_show AS CHECKBOX.
TYPE-POOLS: seok, seop, srext.
INCLUDE yrs_class_xml_const.
INCLUDE lseopm01.
DATA:
g_xml TYPE REF TO cl_xml_document,
gs_class  TYPE  vseoclass,
gt_attributes TYPE  seoo_attributes_r,
gt_methods  TYPE  seoo_methods_r,
gt_events TYPE  seoo_events_r,
gt_types  TYPE  seoo_types_r,
gt_parameters TYPE  seos_parameters_r,
gt_exceps TYPE  seos_exceptions_r,
gt_implementings  TYPE  seor_implementings_r,
gs_inheritance  TYPE  vseoextend,
gt_redefinitions  TYPE  seor_redefinitions_r,
gt_impl_details TYPE  seor_redefinitions_r,
gt_friendships  TYPE  seof_friendships_r,
gt_typepusages  TYPE  seot_typepusages_r,
gt_clsdeferrds  TYPE  seot_clsdeferrds_r,
gt_intdeferrds  TYPE  seot_intdeferrds_r,
gt_aliases  TYPE  seoo_aliases_r,
gt_interfaces TYPE  seok_int_typeinfos,
gs_includes TYPE  seop_methods_w_include,
gt_source TYPE  seop_source_string.
DATA:
typkey TYPE seocmpkey,
single_source TYPE seop_source,
type_source TYPE seop_source_string.
FIELD-SYMBOLS:
 TYPE seoo_type_r,
 TYPE LINE OF seop_source.
FIELD-SYMBOLS:
 TYPE LINE OF seop_methods_w_include.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR class.
DATA:
clsname TYPE seoclass-clsname.
clsname = class.
CALL FUNCTION 'F4_OBJECTS_CLASS'
EXPORTING
bject = clsname
IMPORTING
RESULT = clsname.
class = clsname.
AT SELECTION-SCREEN ON class.
DATA:
clskey  TYPE  seoclskey.
clskey-clsname = class.
* Check if active version of class exists
CALL FUNCTION 'SEO_CLASS_GET'
EXPORTING
clskey       = clskey
version      = '1'
state        = '1'
EXCEPTIONS
not_existing = 1
deleted      = 2
is_interface = 3
model_only   = 4
OTHERS       = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
START-OF-SELECTION.
CALL FUNCTION 'SEO_CLASS_TYPEINFO_GET'
EXPORTING
clskey        = class
version       = seoc_version_active
IMPORTING
class         = gs_class
attributes    = gt_attributes
methods       = gt_methods
events        = gt_events
types         = gt_types
PARAMETERS    = gt_parameters
exceps        = gt_exceps
implementings = gt_implementings
inheritance   = gs_inheritance
redefinitions = gt_redefinitions
impl_details  = gt_impl_details
friendships   = gt_friendships
typepusages   = gt_typepusages
clsdeferrds   = gt_clsdeferrds
intdeferrds   = gt_intdeferrds
aliases       = gt_aliases
EXCEPTIONS
not_existing  = 1
is_interface  = 2
model_only    = 3
OTHERS        = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Load all method include names
CALL FUNCTION 'SEO_CLASS_GET_METHOD_INCLUDES'
EXPORTING
clskey                       = class
IMPORTING
includes                     = gs_includes
EXCEPTIONS
_internal_class_not_existing = 1
OTHERS                       = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Gathering together internal type source
LOOP AT gt_types ASSIGNING .
typkey-clsname = -clsname.
typkey-cmpname = -cmpname.
REFRESH single_source.
PERFORM. get_type_source USING    typkey
CHANGING single_source.
*    CALL FUNCTION 'SEO_CLASS_GET_TYPE_SOURCE'
*      EXPORTING
*        typkey                       = typkey
*      IMPORTING
*        SOURCE                       = single_source
*      EXCEPTIONS
*        _internal_class_not_existing = 1
*        not_existing                 = 2
*        not_edited                   = 3
*        OTHERS                       = 4.
CHECK NOT single_source[] IS INITIAL.
-srcrow1 = LINES( type_source ) + 1.
-srccolumn1 = 0.
LOOP AT single_source ASSIGNING .
CONDENSE .
-srccolumn2 = STRLEN(  ).
APPEND  TO type_source.
ENDLOOP.
-srcrow2 = LINES( type_source ).
ENDLOOP.
END-OF-SELECTION.
DATA:
mtd_name TYPE string,
class_root TYPE REF TO if_ixml_node,
section    TYPE REF TO if_ixml_node,
l_description TYPE sdok_descr.
l_description = gs_class-descript.
CREATE OBJECT g_xml
EXPORTING
description = l_description
object_type = cl_xml_document=>c_bor_classtype
object_name = gs_class-clsname.
* Simply generate sections of XML document
* First create root section
g_xml->set_data( name = c_xml_root
dataobject  = gs_class ).
class_root = g_xml->find_node( name   = c_xml_root ).
* All other sections will be under the root (see parent_node)
g_xml->set_data( name = c_xml_attributes
parent_node = class_root
dataobject  = gt_attributes ).
g_xml->set_data( name = c_xml_methods
parent_node = class_root
dataobject  = gt_methods ).
g_xml->set_data( name = c_xml_events
parent_node = class_root
dataobject  = gt_events ).
g_xml->set_data( name = c_xml_types
parent_node = class_root
dataobject  = gt_types ).
g_xml->set_data( name = c_xml_parameters
parent_node = class_root
dataobject  = gt_parameters ).
g_xml->set_data( name = c_xml_exceps
parent_node = class_root
dataobject  = gt_exceps ).
g_xml->set_data( name = c_xml_implementings
parent_node = class_root
dataobject  = gt_implementings ).
g_xml->set_data( name = c_xml_impl_details
parent_node = class_root
dataobject  = gt_impl_details ).
g_xml->set_data( name = c_xml_friendships
parent_node = class_root
dataobject  = gt_friendships ).
g_xml->set_data( name = c_xml_typepusages
parent_node = class_root
dataobject  = gt_typepusages ).
g_xml->set_data( name = c_xml_clsdeferrds
parent_node = class_root
dataobject  = gt_clsdeferrds ).
g_xml->set_data( name = c_xml_intdeferrds
parent_node = class_root
dataobject  = gt_intdeferrds ).
g_xml->set_data( name = c_xml_aliases
parent_node = class_root
dataobject  = gt_aliases ).
g_xml->set_data( name = c_xml_inheritance
parent_node = class_root
dataobject  = gs_inheritance ).
g_xml->set_data( name = c_xml_interfaces
parent_node = class_root
dataobject  = gt_interfaces ).
g_xml->set_data( name = c_xml_redefinitions
parent_node = class_root
dataobject  = gt_redefinitions ).
g_xml->set_data( name = c_xml_typesource
parent_node = class_root
dataobject  = type_source ).
* Extract local definitions (classes, macros)
DEFINE set_locals.
refresh gt_source.
call function 'SEO_CLASS_GET_INCLUDE_SOURCE'
exporting
clskey                       = class
inctype                      = &1
importing
source_expanded              = gt_source
exceptions
_internal_class_not_existing = 0
not_existing                 = 0
others                       = 0.
g_xml->set_data( name = &2
parent_node = class_root
dataobject  = gt_source ).
END-OF-DEFINITION.
DATA:
include_name TYPE programm.
CALL FUNCTION 'SEO_CLASS_GET_INCLUDE_BY_NAME'
EXPORTING
clskey   = class
limu     = seok_limu_locals
IMPORTING
progname = include_name.
set_locals:
include_name c_xml_locals_src,
seop_ext_class_locals_def c_xml_locals_def,
seop_ext_class_locals_imp c_xml_locals_imp,
seop_ext_class_macros c_xml_locals_mac.
* Extract text pool
DATA:
gt_texts TYPE TABLE OF textpool.
CALL FUNCTION 'SEO_CLASS_GET_INCLUDE_BY_NAME'
EXPORTING
clskey   = class
IMPORTING
progname = include_name.
READ TEXTPOOL include_name INTO gt_texts LANGUAGE sy-langu.
g_xml->set_data( name = c_xml_text_pool
parent_node = class_root
dataobject  = gt_texts ).
* Create section for method source.
* Then each metod as a single node under the common section
section = g_xml->create_simple_element( name   = c_xml_method_src
parent = class_root ).
LOOP AT gs_includes ASSIGNING .
REFRESH gt_source.
CALL FUNCTION 'SEO_METHOD_GET_SOURCE'
EXPORTING
mtdkey                        = -cpdkey
state                         = 'A'
IMPORTING
source_expanded               = gt_source
EXCEPTIONS
_internal_method_not_existing = 1
_internal_class_not_existing  = 2
version_not_existing          = 3
inactive_new                  = 4
inactive_deleted              = 5
OTHERS                        = 6.
CHECK sy-subrc = 0.
mtd_name = -cpdkey-cpdname.
g_xml->set_data( name = mtd_name
parent_node = section
dataobject  = gt_source[] ).
ENDLOOP.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Now display resulting XML-file or export it into workstation file
mtd_name = class.
IF p_show = 'X'.
g_xml->display( ).
EXIT.
ENDIF.
DATA:
user_action TYPE i,
path TYPE string,
full_path TYPE string,
file_name TYPE string.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension    = 'xml'
default_file_name    = mtd_name
file_filter          = cl_gui_frontend_services=>filetype_xml
CHANGING
filename             = file_name
path                 = path
fullpath             = full_path
user_action          = user_action
EXCEPTIONS
cntl_error           = 1
error_no_gui         = 2
not_supported_by_gui = 3
OTHERS               = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CHECK user_action = cl_gui_frontend_services=>action_ok.
DATA:
localfile TYPE localfile.
localfile = full_path.
g_xml->export_to_file( filename = localfile ).
*&---------------------------------------------------------------------*
*&      Form. get_type_source
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->VALUE(P_TYPKEY)  text
*      -->P_SOURCE         text
*----------------------------------------------------------------------*
FORM. get_type_source  USING    value(p_typkey) TYPE seocmpkey
CHANGING p_source TYPE seop_source.
STATICS:
loaded,
private_section TYPE seop_source,
protected_section TYPE seop_source.
DATA:
filename TYPE progstruc,
expanded_srouce TYPE seop_source_string,
type TYPE vseotype.
FIELD-SYMBOLS:
 TYPE seop_source.
IF loaded IS INITIAL.
class_include p_typkey srext_ext_class_protected filename.
READ REPORT filename INTO expanded_srouce.
protected_section[] = expanded_srouce[].
class_include p_typkey srext_ext_class_private filename.
READ REPORT filename INTO expanded_srouce.
private_section[] = expanded_srouce[].
loaded = 'X'.
ENDIF.
CALL FUNCTION 'SEO_TYPE_GET'
EXPORTING
typkey  = typkey
version = seoc_version_inactive
IMPORTING
type    = type
EXCEPTIONS
OTHERS  = 0.
IF type-exposure = seoc_exposure_protected.
ASSIGN protected_section TO .
ELSE.
ASSIGN private_section TO .
ENDIF.
PERFORM. extract_type_source(saplseop)
USING  type-srcrow1 type-srccolumn1
type-srcrow2 type-srccolumn2
CHANGING p_source.
*  CALL FUNCTION 'SEO_CLASS_GET_TYPE_SOURCE'.
ENDFORM.                    " GET_TYPE_SOURCE

[Edit section] Include YRS_CLASS_XML_CONST

*&---------------------------------------------------------------------*
*&  Include           YRS_CLASS_XML_CONST
*&---------------------------------------------------------------------*
CONSTANTS:
c_xml_root TYPE string VALUE 'CLASS_ROOT',
c_xml_public TYPE string VALUE 'PUBLIC_SECTION',
c_xml_protected TYPE string VALUE 'PROTECTED_SECTION',
c_xml_private TYPE string VALUE 'PRIVATE_SECTION',
c_xml_inheritance TYPE string VALUE 'INHERITANCE',
c_xml_friends TYPE string VALUE 'FRIENDS',
c_xml_interfaces TYPE string VALUE 'INTERFACES',
c_xml_redefinitions TYPE string VALUE 'REDEFINITIONS',
c_xml_typesource TYPE string VALUE 'TYPE_SOURCE',
c_xml_locals_src TYPE string VALUE 'LOCALS_SRC',
c_xml_locals_def TYPE string VALUE 'LOCALS_DEF',
c_xml_locals_imp TYPE string VALUE 'LOCALS_IMP',
c_xml_locals_mac TYPE string VALUE 'LOCALS_MAC',
c_xml_method_src TYPE string VALUE 'METHOD_SOURCE'.
CONSTANTS:
c_xml_attributes TYPE string VALUE 'ATTRIBUTES',
c_xml_methods TYPE string VALUE 'METHODS',
c_xml_events TYPE string VALUE 'EVENTS',
c_xml_types TYPE string VALUE 'TYPES',
c_xml_parameters TYPE string VALUE 'PARAMETERS',
c_xml_exceps TYPE string VALUE 'EXCEPTIONS',
c_xml_implementings TYPE string VALUE 'IMPLEMENTINGS',
c_xml_impl_details TYPE string VALUE 'IMPL_DETAILS',
c_xml_friendships TYPE string VALUE 'FRIENDSHIPS',
c_xml_typepusages TYPE string VALUE 'TYPEPUSAGES',
c_xml_clsdeferrds TYPE string VALUE 'CLSDEFERRDS',
c_xml_intdeferrds TYPE string VALUE 'INTDEFERRDS',
c_xml_aliases TYPE string VALUE 'ALIASES',
c_xml_text_pool TYPE string VALUE 'TEXT_POOL'.

[Edit section] Sample class

This is tiny yet useful ABAP class, implementing progress indicator functionality by utilizing SAPGUI_PROGRESS_INDICATOR function module. Sometimes you need to show a progress of some process. For example, you can process quite large internal table in a loop. Also it should be better to show progress only when it really changes and not very often or else a user can see blinking watch-icon in the GUI status line. Also it would be nice not to bother with percent calculation. All this can be done with ZCL_PROGRESS_INDICATOR class. First, call its START method to define total amount of process steps (say internal table line count) and status line text. Also you can set percent threshold which defines frequency of progress indicator updates. If you set threshold to 5 then the progress indicator will be updated less often than 5% of step count. Next, call ADVANCE method on every countable process step (say on every loop step). It will show progress when needed and increment internal progress counts. Also you can call SET method to set current progress absolutely. Finally, call FINISH method to clear GUI status line.

Save the contents of this page starting with tag and ending with tag, then save it as XML file and finally upload with YRS_UPLOAD_CLASS_XML report.

 ZCL_PROGRESS_INDICATOR
1
E
Progress indicator
CHTdPkI0GECU1I4g7Jzm4A==
00
2
1
0
SKOROLEV
2005-10-19
0000-00-00
0000-00-00
X
X
700
00
0
0


ZCL_PROGRESS_INDICATOR
PROGRESS_TEXT
1
E
Progress text
2
1
1
KOROLESE
2006-07-31
0000-00-00
0
0
1
STRING
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
HIGH_BOUND
1
E
High bound
2
1
2
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
TIME_LIMIT
1
E
System time out limit
2
1
3
KOROLESE
2006-07-31
0000-00-00
0
X
0
1
F
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
CURRENT_PROGRESS
1
E
Current indicator value (absolute)
2
1
4
KOROLESE
2006-07-31
0000-00-00
0
X
0
1
I
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
LAST_SHOWN_PROGRESS
1
E
Last shown indicator value (absolute)
0
1
1
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
TRESHOLD
1
E
Percent treshold
0
1
2
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
START_TIME_STAMP
1
E
Start time
0
1
3
KOROLESE
2006-07-31
0000-00-00
0
0
1
TIMESTAMP
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
TRESHOLD_SEC
1
E
Treshold in seconds
0
1
4
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
0
0
0
0
700
0


ZCL_PROGRESS_INDICATOR
STEP_TIME_STAMP
1
E
step timestamp
0
1
5
KOROLESE
2006-07-31
0000-00-00
0
0
1
TIMESTAMP
0
0
0
0
700
0




ZCL_PROGRESS_INDICATOR
START
1
E
Start progress
2
1
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
FINISH
1
E
Finish progress, clear status line
2
1
2
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
ADVANCE
1
E
Advance indicator relatively
2
1
3
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
SET
1
E
Set indicator absolutely
2
1
4
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
START_TIME
1
E
Start Time checking
2
1
5
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
SET_STATUS_TEXT
1
E
Set Status Text
2
1
6
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
RESET_TIME
1
E
reset times
0
1
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0


ZCL_PROGRESS_INDICATOR
CHECK_TIME
1
E
check elapsed time
0
1
2
0
KOROLESE
2006-07-31
0000-00-00
0
0
700
00
0




ZCL_PROGRESS_INDICATOR
ON_TIMEOUT
1
E
Fired when system timeout treshold exceeded
2
1
1
KOROLESE
2006-07-31
0000-00-00
0
700
00





ZCL_PROGRESS_INDICATOR
ADVANCE
I_STATUS_TEXT
1
E
Status line text
1
0
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
ANY
X


ZCL_PROGRESS_INDICATOR
ADVANCE
I_STEP
1
E
Advance step
1
0
2
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
1


ZCL_PROGRESS_INDICATOR
ON_TIMEOUT
I_PERCENT_REMAINING
1
E
Number of percent remaining in curr process
2
0
1
0
KOROLESE
2006-07-31
0000-00-00
1
0
1
I
X


ZCL_PROGRESS_INDICATOR
SET
I_STATUS_TEXT
1
E
Status line text
1
0
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
ANY
X


ZCL_PROGRESS_INDICATOR
SET
I_PROGRESS
1
E
New indicator value (absolute)
1
0
2
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
I


ZCL_PROGRESS_INDICATOR
SET_STATUS_TEXT
I_STATUS_TEXT
1
E
Status line text
1
0
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
ANY
X


ZCL_PROGRESS_INDICATOR
START
I_STATUS_TEXT
1
E
Status line text
1
0
1
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
ANY
X


ZCL_PROGRESS_INDICATOR
START
I_HIGH_BOUND
1
E
Maximum step count
1
0
2
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
100


ZCL_PROGRESS_INDICATOR
START
I_PERCENT_TRESHOLD
1
E
Percent treshold to update indicator and status

line

     1
0
3
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
5


ZCL_PROGRESS_INDICATOR
START
I_ANY_TAB
1
E
Data table to count the high bound
1
0
4
0
KOROLESE
2006-07-31
0000-00-00
0
1
1
ANY TABLE
X


ZCL_PROGRESS_INDICATOR
START
I_SEC_TRESHOLD
1
E
Seconds treshold
1
0
5
0
KOROLESE
2006-07-31
0000-00-00
0
0
1
I
X











0
0
0000-00-00
0000-00-00













METHOD advance.
  DATA:
    l_progress TYPE i.

  l_progress = current_progress + i_step.
  CALL METHOD set( i_status_text = i_status_text
                   i_progress = l_progress ).
ENDMETHOD.


METHOD finish.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'.
ENDMETHOD.


METHOD set.
  DATA:
    text TYPE string,
    delta TYPE i,
    timestamp TYPE timestamp,
    last_percent TYPE i,
    need_show,
    l_new_progress TYPE i.

  current_progress = i_progress.
  IF current_progress > high_bound.
    current_progress = high_bound.
  ENDIF.

  l_new_progress = 100 * current_progress / high_bound.
  CHECK last_shown_progress NE l_new_progress.

  last_percent = 100 - treshold.

  CALL METHOD check_time.

  IF  treshold_sec > 0
  AND l_new_progress < last_percent.
    GET TIME STAMP FIELD timestamp.
    IF timestamp > step_time_stamp.
      CALL FUNCTION 'SRET_TIME_DIFF_GET'
           EXPORTING
                utc_start = step_time_stamp
                utc_end   = timestamp
           IMPORTING
                second    = delta
           EXCEPTIONS
                paramerr  = 0
                OTHERS    = 0.

      IF delta > treshold_sec.
        need_show = 'X'.
        step_time_stamp = timestamp.
      ENDIF.
    ENDIF.
  ELSE.
    delta = abs( l_new_progress - last_shown_progress ).
         IF delta >= treshold.
      need_show = 'X'.
    ENDIF.
  ENDIF.

  IF  need_show = 'X'.

    last_shown_progress = l_new_progress.

    IF i_status_text IS INITIAL.
      text = progress_text.
    ELSE.
      text = i_status_text.
    ENDIF.

    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              percentage = last_shown_progress
              text       = text.
  ENDIF.

ENDMETHOD.


METHOD start.
  CLEAR:
    current_progress,
    last_shown_progress.

  treshold = i_percent_treshold.
  progress_text = i_status_text.

  GET TIME STAMP FIELD step_time_stamp.

  IF i_any_tab[] IS INITIAL.
    high_bound = i_high_bound.
  ELSE.
    DESCRIBE TABLE i_any_tab LINES high_bound.
  ENDIF.

  IF high_bound > 0.
    last_shown_progress = 1.
  ENDIF.

  IF i_sec_treshold > 0.
    treshold_sec = i_sec_treshold.
  ENDIF.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
            percentage = last_shown_progress
            text       = i_status_text.


ENDMETHOD.


METHOD reset_time.
  DATA:
    e_value TYPE spfpflpar-pvalue.

  GET TIME STAMP FIELD start_time_stamp.

  CALL FUNCTION 'RSAN_SYSTEM_PARAMETER_READ'
       EXPORTING
            i_name     = 'rdisp/max_wprun_time'
       IMPORTING
            e_value    = e_value
       EXCEPTIONS
            read_error = 0
            OTHERS     = 0.

  time_limit = e_value + e_value / 2.

ENDMETHOD.


METHOD check_time.
  DATA:
    diff TYPE i,
    l_remaining_percent TYPE i,
    current_time TYPE timestamp.

  CHECK NOT start_time_stamp IS INITIAL
  AND   NOT time_limit       IS INITIAL.

  GET TIME STAMP FIELD current_time.
  CHECK current_time > start_time_stamp.

  CALL FUNCTION 'SRET_TIME_DIFF_GET'
       EXPORTING
            utc_start = start_time_stamp
            utc_end   = current_time
       IMPORTING
            second    = diff
       EXCEPTIONS
            paramerr  = 0
            OTHERS    = 0.

  IF diff > time_limit.
    CALL METHOD reset_time.

    l_remaining_percent = 100 - 100 * current_progress /

high_bound.

         RAISE EVENT on_timeout
      EXPORTING i_percent_remaining =

l_remaining_percent.

       ENDIF.
ENDMETHOD.


METHOD start_time.
  CALL METHOD reset_time.
ENDMETHOD.


METHOD set_status_text .
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = i_status_text.
ENDMETHOD.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/99072/viewspace-531633/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-08-01

  • 博文量
    95
  • 访问量
    131046