Hi,

with this blog post I want to share a code example of how to implement Country Settings of SAP Note 1064448 during runtime. The code is a modified copy of Kai Gutenkunst‘s blog post http://scn.sap.com/people/kai.gutenkunst/blog/2008/10/22/bi-chart-item-modifying-chart-settings-at-runtime.

The scenario is simple. A company wants texts to be displayed in one language (for example English for all users) and the number format should follow another country setting (for example Swedish).

Without BAdI Implementation (example EN) With BAdI implementation (example SV)
1064448_EN.png 1064448_SV.png

At the end of Note 1064448 there is an XML snippet that describes how to change Country Settings. Here is how you can change the XML during runtime using BAdI RS_BADI_CHART:

Method  if_rs_chart_enhancement~modify_chart_request


METHOD if_rs_chart_enhancement~modify_chart_request
*
* Customizing XML
   c_customizing_xml = set_xml_language( iv_language = 'SV'  "Swedish
                                              iv_xml = c_customizing_xml ).
*
* Delta Customizing XML
   c_delta_customizing_xml = set_xml_language( iv_language =  'SV'  "Swedish
                                                    iv_xml = c_delta_customizing_xml ).
ENDMETHOD.








The determination of what language to set can be made much more sofisticated. For the purpose of simplicity, I have hardcoded the language in the example above.

Method  set_xml_language

The parameters of the set_xml_language method looks like this:

/wp-content/uploads/2014/01/set_xml_language_361954.png


METHOD set_xml_language.
*
 TYPE-POOLS: ixml.
*
 CLASS cl_ixml DEFINITION LOAD.
*
   DATA: lr_ixml TYPE REF TO if_ixml.
   DATA: lr_streamfactory TYPE REF TO if_ixml_stream_factory.
   DATA: lr_xml TYPE REF TO if_ixml_istream.
   DATA: lr_xml_ostr TYPE REF TO if_ixml_ostream.
   DATA: lr_document TYPE REF TO if_ixml_document.
   DATA: lr_parser TYPE REF TO if_ixml_parser.
   DATA: lr_global_settings TYPE REF TO if_ixml_node.
   DATA: lr_first_child TYPE REF TO if_ixml_node.
   DATA: lr_language_node TYPE REF TO if_ixml_node.
   DATA: lr_language_element TYPE REF TO if_ixml_element.
   DATA: lv_xml TYPE xstring.
   DATA: lv_rc TYPE i.
*
* Create iXml factory
   lr_ixml = cl_ixml=>create( ).
*
* Create stream factory
   lr_streamfactory = lr_ixml->create_stream_factory( ).
*
* Create input stream
   lr_xml = lr_streamfactory->create_istream_xstring( iv_xml ).
*
* Create output stream
   lr_xml_ostr = lr_streamfactory->create_ostream_xstring( lv_xml ).
*
* Create document
   lr_document = lr_ixml->create_document( ).
*
* Parse Xml
   lr_parser = lr_ixml->create_parser( stream_factory = lr_streamfactory
                                              istream = lr_xml
                                             document = lr_document ).
*
* Parsing successful?
   IF lr_parser->parse( ) = 0.
*
* Find <Language> element
     lr_language_element = lr_document->find_from_name( name = 'Language' ).
     IF lr_language_element IS NOT INITIAL.
*
* Set language of the <Language> element
       lr_language_element->set_value( iv_language ).
     ELSE.
*
* Find <GlobalSettings> element
       lr_global_settings = lr_document->find_from_name( name = 'GlobalSettings' ).
       lr_first_child = lr_global_settings->get_first_child( ).
       lr_language_node = lr_first_child->clone( ).
       lr_language_node->set_name( 'Language').
       lr_language_node->set_value( 'SV' ).
*
* Insert a <Language> element in the XML
       lr_global_settings->insert_child( new_child = lr_language_node ref_child = lr_first_child ).
     ENDIF.
*
* Serialize xml
     lv_rc = lr_ixml->create_renderer( ostream = lr_xml_ostr document = lr_document )->render( ).
*
* Return xml
     rv_xml = lv_xml.
   ENDIF.
ENDMETHOD.








All strings should of course be externalized, but I excluded that here to enhance the readability.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply