Skip to Content

Recently I came across an interesting requirement for Smartforms. A couple of very similar forms was supposed to be created with slightly different contents but identical as regards the layout. Also, upon any current or future need to adjust the layout, the changes should be distributed automatically across all the Smartforms belonging to that group. All in all, such a requirement comes down to some kind of a master page functionality like e.g. in any desktop word processing software. Natively Smartforms do not support such a feature. But with little programming help, perhaps?

h2. The Idea

Some time ago I have seen an excellent blog by Tobias Trapp: SmartForm Generation Using Advanced ABAP XSLT Techniques. Could this possibly suggest a solution? Suppose we download a scheme for the “master” Smartform to XML, merge its layout with the contents of the “slave” Smartform using XSLT and replace the “slave” Smartform in the editor with the merged content. Should it work? Why not?form sf_activate using    p_check  type tdbool

                          p_active type tdbool

                          p_save   type tdbool

                 changing p_cancel type tdsfflag.

“”””””””””””””””””””””””””””””””””””””””””””””””””””””$”$SE:(1 ) Form SF_ACTIVATE, Start                                                                                D

$$-Start: (1 )—-


$$

ENHANCEMENT 2  Z_SF_ACTIVATE.    “active version

  • Overlay current Smartform with the master (if applicable)

CONSTANTS:

  l_var_enh_name

    TYPE string VALUE ‘Z_SF_ACTIVATE’.

DATA:

  l_var_sform_master_name

    type tdsfname,

  l_rif_sf_sync

    type ref to Z_IF_SF_SYNC.

CREATE OBJECT l_rif_sf_sync type Z_CL_SF_SYNC.

TRY.

  l_rif_sf_sync->apply_sf_master(

    IMPORTING

      e_var_sform_master_name = l_var_sform_master_name

    CHANGING

      c_rcl_sform = sform

  ).

CATCH ZCX_ERROR.

  message e081 with formname l_var_enh_name.

ENDTRY.

ENDENHANCEMENT.

$$-End:   (1 )—-


$*$*

What is left out here is the actual contents of the method apply_sf_master which is supposed to replace original Smartform object with its processed copy:

METHOD z_if_sf_sync~apply_sf_master.

  DATA:

    l_rif_ixml_node

      TYPE REF TO if_ixml_node,

    l_rcl_error

      TYPE REF TO cx_root,

    l_xml_synced_sform

      TYPE xstring,

    l_rif_sf_slave

      TYPE REF TO if_ixml_document,

    l_rcl_templated_sform

      TYPE REF TO cl_ssf_fb_smart_form,

    l_rcl_sform_master

      TYPE REF TO cl_ssf_fb_smart_form,

    l_rif_sf_master

      TYPE REF TO if_ixml_document,

    l_var_master_name

      TYPE tdsfname,

    l_rcl_exception

      TYPE REF TO cx_ssf_fb.

  • Read Smartform conf – check for master

  TRY.

      l_var_master_name = me->get_sform_master_name(

        i_var_current_sf_name = c_rcl_sform->header-formname

      ).

    CATCH zcx_error .

      EXIT.” No error

  ENDTRY.

  • Read current Smartform as iXML

  me->read_sform_as_ixml(

    IMPORTING

      e_rif_ixml_document = l_rif_sf_slave

    CHANGING

      c_rcl_sform = c_rcl_sform

  ).

  • Read Smartform master from DB (active version)

  l_rcl_sform_master = me->get_sform_by_name(

    i_var_sfname = l_var_master_name

  ).

  • Read Smartform master as iXML

  me->read_sform_as_ixml(

    EXPORTING

      i_flg_dequeue = abap_true

    IMPORTING

      e_rif_ixml_document = l_rif_sf_master

    CHANGING

      c_rcl_sform = l_rcl_sform_master

  ).

  • Use XSLT transformation to overlay current Smartform with the master layout

  TRY.

      CALL TRANSFORMATION z_sync

        SOURCE XML l_rif_sf_slave

        RESULT XML l_xml_synced_sform” Cannot be DOM – xml_upload will not accept it

        PARAMETERS

          sf_master_xml = l_rif_sf_master.

    CATCH cx_root INTO l_rcl_error.

      RAISE EXCEPTION TYPE zcx_error

        EXPORTING

          previous = l_rcl_error.

  ENDTRY.

  • Convert transformation result to DOM

  FREE l_rif_sf_slave.

  l_rif_sf_slave = me->get_new_ixml_document( ).

  CALL FUNCTION ‘SDIXML_XML_TO_DOM’

    EXPORTING

      xml           = l_xml_synced_sform

    IMPORTING

      document      = l_rif_sf_slave

    EXCEPTIONS

      invalid_input = 1

      OTHERS        = 2.

  IF sy-subrc <> 0.

    RAISE EXCEPTION TYPE zcx_error.

  ENDIF.

  • Replace current Smartform contents with the synced result

  CREATE OBJECT l_rcl_templated_sform.

  c_rcl_sform->dequeue( c_rcl_sform->header-formname ).

  TRY.

      CALL METHOD l_rcl_templated_sform->enqueue

        EXPORTING

          suppress_corr_check = space

          language_upd_exit   = ‘ ‘

          master_language     = sy-langu

          mode                = ‘MODIFY’

          formname            = c_rcl_sform->header-formname.

    CATCH cx_ssf_fb INTO l_rcl_exception.

      RAISE EXCEPTION TYPE zcx_error

        EXPORTING

          previous = l_rcl_exception.

  ENDTRY.

  l_rif_ixml_node = l_rif_sf_slave->get_root_element( ).

  l_rcl_templated_sform->xml_upload(

    EXPORTING

      dom      = l_rif_ixml_node

      formname = c_rcl_sform->header-formname

    CHANGING

      sform    = l_rcl_templated_sform

  ).

  c_rcl_sform = l_rcl_templated_sform.

  e_var_sform_master_name = l_var_master_name.

ENDMETHOD.

To report this post you need to login first.

3 Comments

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

  1. Naimesh Patel
    Hello Wiktor,

    Great Idea and good implementation.

    I have some questions:
    – For the first time, when we activate Slave, it includes the Master’s layout in it. What happens when you enter in change Mode in the Slave after activation? Will you see all the layout from the master in the Slave or only the data nodes? (I don’t have a system which supports the enhancement point so, I am not able to check this)

    – If we change something in the master, do we need to reactivate all the Slave? Would it overwrite something in the slave?

    Thanks.

    Regards,
    Naimesh Patel

    (0) 
    1. Wiktor Nyckowski Post author
      Regarding Your first question: the enhancement in the beginning of the SF_ACTIVATE subroutine (meant to adjust the layout of the slave SF) is triggered every time upon Smartform activation. In other words, a slave Smartform can be hand edited just as if it had no master behind it (it is possible to alter the position of the windows, their size and so on) but upon activation all the changes to the _layout_ are being reverted back (in accordance with the master layout) while retaining all the (possibly edited) window contents, SF interface, coding, output conditions and such from the slave.

      To Your second question: I mentioned that there is another enhancement (in the end of SF_ACTIVATE subroutine) which is also triggered every time upon Smartform activation but this one is meant to dispatch / propagate master layout changes across all the slaves.

      Which one of the two enhancements is actually being called upon particular Smartform activation is controlled by a customizing table contaning assignment of master and slave Smartforms.
      Kind regards
      Wiktor Nyckowski

      (0) 
  2. Sandra Rossi
    Hi Wiktor,

    thank your for your very interesting blog. You found the solution for a problem we have since a design flaw : we created 3 smartforms with exactly the same layout but different code.
    But I’d like to adapt your idea a little bit because I’m not totally confident in adding an enhancement to the standard code and in the automatic transformation, and to the fact that all development/basis teams should agree although it concerns only 1 smartform.

    I’d prefer to implement it like this to add more manual control :

    1) Create an external transaction which merges the master smartform layout into the slave smartform (I would opt for the easy solution : 2 input fields on selection screen instead of creating a customizing table with relationships between slave/master)

    2) In case of problem with the transformation, I’d like to implement a version management (at save time via an implicit enhancement) to store the XML into Mime repository, and a separate program would allow to restore an old version. I’ll keep you informed you if we do the second option (I didn’t find any information how to do that).

    Best regards,
    sandra

    (0) 

Leave a Reply