Permalink
Fetching contributors…
Cannot retrieve contributors at this time
433 lines (385 sloc) 18 KB
<?xml version="1.0" encoding="utf-8"?>
<CLAS CLSNAME="ZSAPLINK_MESSAGE_CLASS" VERSION="1" LANGU="E" DESCRIPT="SAPLink - Message Class plugin" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " REFCLSNAME="ZSAPLINK">
<localImplementation>*&quot;* local class implementation for public class
*&quot;* use this source file for the implementation part of
*&quot;* local helper classes</localImplementation>
<localTypes>*&quot;* use this source file for any type declarations (class
*&quot;* definitions, interfaces or data types) you need for method
*&quot;* implementation or private method&apos;s signature</localTypes>
<localMacros>*&quot;* use this source file for any macro definitions you need
*&quot;* in the implementation part of the class</localMacros>
<inheritance CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" STATE="1">
<redefinition CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" MTDNAME="CHECKEXISTS"/>
<redefinition CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" MTDNAME="CREATEIXMLDOCFROMOBJECT"/>
<redefinition CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" MTDNAME="CREATEOBJECTFROMIXMLDOC"/>
<redefinition CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" MTDNAME="DELETEOBJECT"/>
<redefinition CLSNAME="ZSAPLINK_MESSAGE_CLASS" REFCLSNAME="ZSAPLINK" VERSION="1" MTDNAME="GETOBJECTTYPE"/>
</inheritance>
<method CLSNAME="ZSAPLINK" CMPNAME="CHECKEXISTS" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink is free software; you can redistribute it and/or modify |
*| it under the terms of the GNU General Public License as published |
*| by the Free Software Foundation; either version 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink is distributed in the hope that it will be useful, |
*| but WITHOUT ANY WARRANTY; without even the implied warranty of |
*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
*| GNU General Public License for more details. |
*| |
*| You should have received a copy of the GNU General Public License |
*| along with SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD checkexists .
* Plugin created by:
* John Patterson
* patterjo@gmail.com
DATA: ls_t100a TYPE t100a,
lv_msgid TYPE msgid.
lv_msgid = objname.
SELECT SINGLE *
INTO ls_t100a
FROM t100a
WHERE arbgb = lv_msgid.
IF sy-subrc = 0.
exists = &apos;X&apos;.
ENDIF.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="CREATEIXMLDOCFROMOBJECT" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink is free software; you can redistribute it and/or modify |
*| it under the terms of the GNU General Public License as published |
*| by the Free Software Foundation; either version 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink is distributed in the hope that it will be useful, |
*| but WITHOUT ANY WARRANTY; without even the implied warranty of |
*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
*| GNU General Public License for more details. |
*| |
*| You should have received a copy of the GNU General Public License |
*| along with SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD createixmldocfromobject .
* Plugin created by:
* John Patterson
* patterjo@gmail.com
DATA: lt_t100 TYPE STANDARD TABLE OF t100,
lt_t100t TYPE STANDARD TABLE OF t100t,
ls_t100 LIKE LINE OF lt_t100,
ls_t100t LIKE LINE OF lt_t100t,
ls_t100a TYPE t100a.
DATA: lv_msgid TYPE msgid,
lv_rc TYPE sysubrc,
lv_objtype TYPE string.
*xml nodes
DATA: lr_rootnode TYPE REF TO if_ixml_element,
lr_t100_node TYPE REF TO if_ixml_element,
lr_t100t_node TYPE REF TO if_ixml_element.
lv_msgid = objname.
SELECT SINGLE *
INTO ls_t100a
FROM t100a WHERE arbgb = lv_msgid.
IF sy-subrc NE 0.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;not_found.
ENDIF.
CALL FUNCTION &apos;RS_ACCESS_PERMISSION&apos;
EXPORTING
authority_check = &apos;X&apos;
global_lock = space
mode = &apos;SHOW&apos;
object = lv_msgid
object_class = &apos;T100&apos;
EXCEPTIONS
canceled_in_corr = 01
enqueued_by_user = 02
enqueue_system_failure = 03
illegal_parameter_values = 04
locked_by_author = 05
no_modify_permission = 06
no_show_permission = 07
permission_failure = 08.
CASE sy-subrc.
WHEN 0.
WHEN 2 OR 5.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;locked.
WHEN 6 OR 7 OR 8 OR 9.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;not_authorized.
WHEN OTHERS.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;system_error.
ENDCASE.
*--- get messages for all maintained languages
SELECT *
INTO TABLE lt_t100
FROM t100
WHERE arbgb = lv_msgid
ORDER BY sprsl msgnr.
*--- get text for t100a
SELECT *
INTO TABLE lt_t100t
FROM t100t
WHERE arbgb = lv_msgid
ORDER BY sprsl.
*-- Create parent node
lv_objtype = getobjecttype( ).
lr_rootnode = xmldoc-&gt;create_element( lv_objtype ).
setattributesfromstructure( node = lr_rootnode
structure = ls_t100a ).
*--- Create Elements for Messages
LOOP AT lt_t100 INTO ls_t100.
lr_t100_node = xmldoc-&gt;create_element( &apos;t100&apos; ).
setattributesfromstructure( node = lr_t100_node
structure = ls_t100 ).
lv_rc = lr_rootnode-&gt;append_child( lr_t100_node ).
ENDLOOP.
*--- Create Elements for Texts
LOOP AT lt_t100t INTO ls_t100t.
lr_t100t_node = xmldoc-&gt;create_element( &apos;t100t&apos; ).
setattributesfromstructure( node = lr_t100t_node
structure = ls_t100t ).
lv_rc = lr_rootnode-&gt;append_child( lr_t100t_node ).
ENDLOOP.
lv_rc = xmldoc-&gt;append_child( lr_rootnode ).
ixmldocument = xmldoc.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="CREATEOBJECTFROMIXMLDOC" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink is free software; you can redistribute it and/or modify |
*| it under the terms of the GNU General Public License as published |
*| by the Free Software Foundation; either version 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink is distributed in the hope that it will be useful, |
*| but WITHOUT ANY WARRANTY; without even the implied warranty of |
*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
*| GNU General Public License for more details. |
*| |
*| You should have received a copy of the GNU General Public License |
*| along with SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD createobjectfromixmldoc .
* Plugin created by:
* John Patterson
* patterjo@gmail.com
DATA: lt_t100 TYPE STANDARD TABLE OF t100,
lt_t100t TYPE STANDARD TABLE OF t100t,
ls_t100 LIKE LINE OF lt_t100,
ls_t100t LIKE LINE OF lt_t100t,
ls_t100a TYPE t100a.
DATA: lv_msgid TYPE msgid,
lv_rc TYPE sysubrc,
lv_objtype TYPE string,
lv_checkexists TYPE char1,
lv_len TYPE i.
*--- xml data objects
DATA: lr_rootnode TYPE REF TO if_ixml_element,
lr_t100_node TYPE REF TO if_ixml_element,
lr_t100t_node TYPE REF TO if_ixml_element,
lr_filter TYPE REF TO if_ixml_node_filter,
lr_iterator TYPE REF TO if_ixml_node_iterator.
lv_msgid = objname.
lv_objtype = getobjecttype( ).
xmldoc = ixmldocument.
lr_rootnode = xmldoc-&gt;find_from_name( lv_objtype ).
CALL METHOD getstructurefromattributes
EXPORTING
node = lr_rootnode
CHANGING
structure = ls_t100a.
objname = ls_t100a-arbgb.
lv_checkexists = checkexists( ).
IF lv_checkexists IS NOT INITIAL.
IF overwrite IS INITIAL.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;existing.
ELSE.
deleteobject( ).
ENDIF.
ENDIF.
*--- Read Elements for Messages
FREE: lr_filter, lr_iterator, lr_t100_node, lr_t100t_node.
lr_filter = xmldoc-&gt;create_filter_name( &apos;t100&apos; ).
lr_iterator = xmldoc-&gt;create_iterator_filtered( lr_filter ).
lr_t100_node ?= lr_iterator-&gt;get_next( ).
WHILE lr_t100_node IS NOT INITIAL.
CLEAR ls_t100.
CALL METHOD getstructurefromattributes
EXPORTING
node = lr_t100_node
CHANGING
structure = ls_t100.
APPEND ls_t100 TO lt_t100.
lr_t100_node ?= lr_iterator-&gt;get_next( ).
ENDWHILE.
*--- Create Elements for Texts
FREE: lr_filter, lr_iterator, lr_t100_node, lr_t100t_node.
lr_filter = xmldoc-&gt;create_filter_name( &apos;t100t&apos; ).
lr_iterator = xmldoc-&gt;create_iterator_filtered( lr_filter ).
lr_t100t_node ?= lr_iterator-&gt;get_next( ).
WHILE lr_t100t_node IS NOT INITIAL.
CLEAR ls_t100t.
CALL METHOD getstructurefromattributes
EXPORTING
node = lr_t100t_node
CHANGING
structure = ls_t100t.
APPEND ls_t100t TO lt_t100t.
lr_t100t_node ?= lr_iterator-&gt;get_next( ).
ENDWHILE.
CALL FUNCTION &apos;RS_ACCESS_PERMISSION&apos;
EXPORTING
mode = &apos;FREE&apos;
object = lv_msgid
object_class = &apos;T100&apos;.
*--- Check permission
CALL FUNCTION &apos;RS_ACCESS_PERMISSION&apos;
EXPORTING
authority_check = &apos;X&apos;
global_lock = &apos;X&apos;
mode = &apos;INSERT&apos;
language_upd_exit = &apos;UPDATE_MASTER&apos;
master_language = ls_t100a-masterlang
object = lv_msgid
object_class = &apos;T100&apos;
suppress_language_check = &apos; &apos;
EXCEPTIONS
canceled_in_corr = 01
enqueued_by_user = 02
enqueue_system_failure = 03
illegal_parameter_values = 04
locked_by_author = 05
no_modify_permission = 06
no_show_permission = 07
permission_failure = 08.
CASE sy-subrc.
WHEN 0.
WHEN 2 OR 5.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;locked.
WHEN 6 OR 7 OR 8 OR 9.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;not_authorized.
WHEN OTHERS.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;system_error.
ENDCASE.
CALL FUNCTION &apos;RS_CORR_INSERT&apos;
EXPORTING
author = sy-uname
global_lock = &apos;X&apos;
object = objname
object_class = &apos;T100&apos;
devclass = devclass
master_language = sy-langu
mode = &apos;INSERT&apos;
* IMPORTING
* AUTHOR = UNAME
* KORRNUM = CORRNUMBER_LOCAL
* DEVCLASS = DEVCLASS_LOCAL
EXCEPTIONS
cancelled = 1
permission_failure = 2
unknown_objectclass = 3.
IF sy-subrc &lt;&gt; 0.
CASE sy-subrc.
WHEN 2.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING
textid = zcx_saplink=&gt;not_authorized.
WHEN OTHERS.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING
textid = zcx_saplink=&gt;system_error.
ENDCASE.
ENDIF.
*--- update message tables
CLEAR: ls_t100a-applclass.
ls_t100a-lastuser = sy-uname.
ls_t100a-ldate = sy-datum.
ls_t100a-ltime = sy-uzeit.
MODIFY t100a FROM ls_t100a.
MODIFY t100 FROM TABLE lt_t100.
MODIFY t100t FROM TABLE lt_t100t.
CALL FUNCTION &apos;RS_TREE_OBJECT_PLACEMENT&apos;
EXPORTING
object = lv_msgid
operation = &apos;INSERT&apos;
type = &apos;CN&apos;.
CALL FUNCTION &apos;RS_ACCESS_PERMISSION&apos;
EXPORTING
mode = &apos;FREE&apos;
object = lv_msgid
object_class = &apos;T100&apos;.
name = objname.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="DELETEOBJECT" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink is free software; you can redistribute it and/or modify |
*| it under the terms of the GNU General Public License as published |
*| by the Free Software Foundation; either version 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink is distributed in the hope that it will be useful, |
*| but WITHOUT ANY WARRANTY; without even the implied warranty of |
*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
*| GNU General Public License for more details. |
*| |
*| You should have received a copy of the GNU General Public License |
*| along with SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
method DELETEOBJECT .
* Plugin created by:
* John Patterson
* patterjo@gmail.com
endmethod.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="GETOBJECTTYPE" VERSION="0" EXPOSURE="0" STATE="0" EDITORDER="0 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink is free software; you can redistribute it and/or modify |
*| it under the terms of the GNU General Public License as published |
*| by the Free Software Foundation; either version 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink is distributed in the hope that it will be useful, |
*| but WITHOUT ANY WARRANTY; without even the implied warranty of |
*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
*| GNU General Public License for more details. |
*| |
*| You should have received a copy of the GNU General Public License |
*| along with SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD getobjecttype .
* Plugin created by:
* John Patterson
* patterjo@gmail.com
objecttype = &apos;MSAG&apos;. &quot;Message Class
ENDMETHOD.</source>
</method>
</CLAS>