This weblog is replacing Mukund Goenka's Blog Render an Idoc Schema onto a Spreadsheet.
The process of rendering an IDoc schema onto a spreadsheet is part of creating the Business Mappings in the development of Building an XI content package. Before creating the Technical Mappings using the graphical mapping tool, you first do the Business Mappings and understand the importance of business mappings. The easiest tool for business mappings is the Spreadsheet (XSL). This weblog will describe the creation of a Spreadsheet Template for an IDoc. A separate weblog describing the creation of a Spreadsheet Template for an XSD Schema will be published later in SDN.
Business mappings define how the fields of the target Interface need to be filled from a functional (business) point of view. An initial step in the business mapping process is to know the details, at the field level, of the structures that need to be mapped. The creation of business mappings requires the knowledge of the backend application, the interface used by the backend application, and the Industry Standard Interface. Therefore, you first need to possess the two structures:
Then you will map the two structures based on your functional knowledge. This initial business mapping can be done using the Spreadsheet. The field list of the target interface is created automatically using spreadsheet creation tool. This Spreadsheet mapping will form the basis on which you will later build the Technical mapping using XI.
In order to be able to create a spreadsheet template with the method described in this weblog the following system requirements must be met:
After you have implemented the required coding as described in the appendix, you can create a spreadsheet template using the following steps:
In this appendix we describe step by step how to create the required objects in order to run the program Z_RIDOCSHOW successfully.
Note that this code sample only works in an SAP R/3 4.6C environment.
The following data dictionary elements need to be created:
We need to create the data element ZDESCRP using the following steps:
We need to create the structure ZIDOC_STRUCT using the following steps:
We need to create the table type ZT_IDOC_STRUCT using the following steps:
Z_RIDOCSHOW is the program that needs to be executed for the creation of the spreadsheet. We can create this program using the following steps:
REPORT Z_RIDOCSHOW .
TABLES: sed5struc.
TYPE-POOLS: LEDID.
TYPES: BEGIN OF ty_output, ID LIKE snodetext-id, name LIKE snodetext-name, tlevel LIKE snodetext-tlevel, text8 LIKE snodetext-text8, tlength8 LIKE snodetext-tlength8, text9 LIKE snodetext-text9, tlength9 LIKE snodetext-tlength9, END OF ty_output.
----
----
*--- options SELECTION-SCREEN BEGIN OF BLOCK control WITH FRAME TITLE text-012. PARAMETERS: p_basic LIKE SED5STRUC-SELECT_ORG DEFAULT 'X'. PARAMETERS: p_ext LIKE SED5STRUC-SELECT_EXT. SELECTION-SCREEN END OF BLOCK control.
START-OF-SELECTION.
REFRESH sc_idoc.
sed5struc-object = sc_idoc-low. sed5struc-select_org = p_basic. sed5struc-select_ext = p_ext. IF sed5struc-object IS INITIAL. MESSAGE e001(idmc). EXIT. ENDIF.
IF NOT sed5struc-select_org IS INITIAL. DATA : l_idoctype LIKE edi_iapi00-idoctyp.
l_idoctype = sed5struc-object.
CALL FUNCTION 'IDOCTYPE_EXISTENCE_CHECK' EXPORTING pi_idoctyp = l_idoctype EXCEPTIONS object_not_found = 1 db_error = 2 OTHERS = 3. CASE sy-subrc. WHEN 0. " ok WHEN OTHERS. MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDCASE.
ELSEIF NOT sed5struc-select_ext IS INITIAL.
DATA: l_cimtype LIKE edi_iapi00-cimtyp. l_cimtype = sed5struc-object.
CALL FUNCTION 'EXTTYPE_EXISTENCE_CHECK' EXPORTING pi_cimtyp = l_cimtype EXCEPTIONS object_not_found = 1 db_error = 2 OTHERS = 3. CASE sy-subrc. WHEN 0. " ok WHEN OTHERS. MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDCASE. ENDIF.
END-OF-SELECTION.
DATA: l_objecttype TYPE c, l_obj TYPE edi_iapi00-idoctyp, released LIKE sy-saprl, version LIKE edi_verrec-version.
released = sy-saprl. version = '3'. l_obj = sed5struc-object.
IF NOT sed5struc-select_ext IS INITIAL. l_objecttype = 'E'. ELSEIF NOT sed5struc-select_org IS INITIAL. l_objecttype = 'B'. ENDIF.
*======================= DATA: l_tree TYPE snodetext OCCURS 1, lt_final TYPE zt_idoc_struct.
CALL FUNCTION 'ZEDI_FILL_IDOC_TREE' EXPORTING object = l_obj object_type = l_objecttype object_release = released pi_rec_version = version enable_further_output = 'X' TABLES pt_idocstruct = lt_final EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
*=========================
CONCATENATE l_idoctype '.xls' INTO l_idoctype.
CALL FUNCTION 'WS_EXCEL' EXPORTING filename = l_idoctype synchron = ' ' TABLES data = lt_final.
The program Z_RIDOCSHOW requires a number of function modules to be created in order to be able to run. These function modules are placed in the function group ZEDIT.
First we need to create the function group ZEDIT using the following steps:
The include LZEDITTOP contains the global data definitions for the function group. We can create this include using the following steps:
We can create the function module ZEDI_FILL_IDOC_TREE using the following steps:
FUNCTION zedi_fill_idoc_tree. *"----
""Local interface: *" IMPORTING *" VALUE(OBJECT) TYPE LEDID_IDOCTYPE *" VALUE(OBJECT_TYPE) TYPE LEDID_STRUCT_TYPE *" VALUE(OBJECT_RELEASE) LIKE SY-SAPRL DEFAULT SY-SAPRL *" VALUE(PI_REC_VERSION) LIKE EDI_VERREC-VERSION DEFAULT '3' *" VALUE(ENABLE_FURTHER_OUTPUT) TYPE LEDID_FLAG DEFAULT 'X' *" TABLES *" PT_IDOCSTRUCT TYPE ZT_IDOC_STRUCT *"----
TYPES: BEGIN OF ty_pre, tlevel TYPE i, pre(150) TYPE c, END OF ty_pre.
DATA: ls_idocstruct TYPE zidoc_struct, ls_tree TYPE snodetext, ls_idoc TYPE ledid_idoc_struct, ls_segment TYPE ledid_segment, ls_fields TYPE ledid_segment_struct, ls_pre TYPE ty_pre, lt_pre TYPE STANDARD TABLE OF ty_pre, l_pre(200) TYPE c, l_index TYPE i.
REFRESH: t_idoc, t_segments, t_fields.
CALL FUNCTION 'IDOC_TYPE_COMPLETE_READ' EXPORTING struct_type = object_type idoctype = object release = object_release version = pi_rec_version IMPORTING idoc_type = idoc TABLES idoc_struct = t_idoc segments = t_segments segment_struct = t_fields EXCEPTIONS OTHERS = 1. CASE sy-subrc. WHEN 0.
g_object_release = object_release.
g_object_version = pi_rec_version.
g_mode = 'I'.
REFRESH t_excl.
CALL FUNCTION 'ZEDI_CONVERT_IDOC_TAB_TO_TREE' TABLES tree = tree.
CALL FUNCTION 'RS_TREE_CONSTRUCT' TABLES nodetab = tree.
SORT: t_idoc BY segment_type, t_segments BY segment_type, t_fields BY segment_type fieldname.
ls_idocstruct-id = 'ID'. ls_idocstruct-fld_segtyp = 'Path'. ls_idocstruct-name = 'Name'. ls_idocstruct-tlevel = 'Depth'. ls_idocstruct-idoc_mustfl = 'Mandatory'. ls_idocstruct-idoc_occmin = 'Seg_OccMin'. ls_idocstruct-idoc_occmax = 'Seg_occMax'. ls_idocstruct-fld_datatype = 'Type'. ls_idocstruct-fld_domname = 'DomName'. ls_idocstruct-fld_decimals = 'DECIML'. ls_idocstruct-fld_signflag = 'Sign'. ls_idocstruct-fld_extlen = 'Len'. ls_idocstruct-text9 = 'Text'.
APPEND ls_idocstruct TO pt_idocstruct. CLEAR: ls_idocstruct.
LOOP AT tree INTO ls_tree. MOVE-CORRESPONDING ls_tree TO ls_idocstruct.
IF ls_tree-type = 'TB'.
CLEAR ls_pre.
IF ls_tree-tlevel = 2. REFRESH lt_pre. CLEAR l_pre. ls_pre-tlevel = 1. APPEND ls_pre TO lt_pre. ENDIF.
IF ls_tree-tlevel = 2. l_pre = ls_tree-name. ELSEIF ls_tree-tlevel > 2. l_index = ls_tree-tlevel - 1. READ TABLE lt_pre INTO ls_pre INDEX l_index. CONCATENATE ls_pre-pre ' /' ls_tree-name INTO l_pre. ENDIF.
ls_pre-tlevel = ls_tree-tlevel. ls_pre-pre = l_pre. INSERT ls_pre INTO lt_pre INDEX ls_tree-tlevel.
READ TABLE t_idoc INTO ls_idoc WITH KEY segment_type = ls_tree-name BINARY SEARCH. IF sy-subrc IS INITIAL. ls_idocstruct-idoc_mustfl = ls_idoc-syntax_attrib-mustfl. ls_idocstruct-idoc_occmin = ls_idoc-syntax_attrib-occmin. ls_idocstruct-idoc_occmax = ls_idoc-syntax_attrib-occmax. ENDIF.
ELSEIF ls_tree-type = 'DE'.
READ TABLE t_fields INTO ls_fields WITH KEY segment_type = ls_tree-text7 fieldname = ls_tree-name BINARY SEARCH. IF sy-subrc IS INITIAL. ls_idocstruct-fld_decimals = ls_fields-field_attrib-decimals. ls_idocstruct-fld_signflag = ls_fields-field_attrib-signflag. ls_idocstruct-fld_extlen = ls_fields-field_attrib-extlen. ls_idocstruct-fld_domname = ls_fields-field_attrib-domname. ls_idocstruct-fld_datatype = ls_fields-field_attrib-datatype. ENDIF.
ENDIF.
ls_idocstruct-fld_segtyp = l_pre.
APPEND ls_idocstruct TO pt_idocstruct. CLEAR: ls_idoc, ls_segment, ls_fields, ls_idocstruct. ENDLOOP.
WHEN OTHERS. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDCASE.
ENDFUNCTION.
We can create the function module ZEDI_CONVERT_IDOC_TAB_TO_TREE using the following steps:
FUNCTION zedi_convert_idoc_tab_to_tree. *"----
""Local interface: *" TABLES *" TREE STRUCTURE SNODETEXT *"----
DATA: wa_idoc TYPE ledid_idoc_struct.
REFRESH: tree.
PERFORM fa2_get_user_attributes_all.
PERFORM f01_construct_root_node TABLES tree CHANGING edi_attrib.
LOOP AT t_idoc INTO wa_idoc.
PERFORM f01_construct_segment_node TABLES tree USING wa_idoc edi_attrib.
IF edi_attrib-do2 EQ on. wa_idoc-dont_show_docu = off. ELSE. wa_idoc-dont_show_docu = on. ENDIF. IF edi_attrib-at2 EQ on. wa_idoc-dont_show_attrib = off. ELSE. wa_idoc-dont_show_attrib = on. ENDIF. MODIFY t_idoc FROM wa_idoc.
ENDLOOP.
ENDFUNCTION.
The include LZEDITF01 contains the following form routines used within the function group:
We can create this include using the following steps:
----
CLEAR: edi_attrib, edi_idcatt, edi_cfile, edi_htmfil.
CALL FUNCTION 'IDOC_CONFIGURE_DOC' EXPORTING service = 'R' CHANGING attrib_data = edi_attrib idcatt_data = edi_idcatt cfile_data = edi_cfile htmlfile_data = edi_htmfil EXCEPTIONS undefined_service = 1 user_action_cancel = 2 OTHERS = 3.
IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
ENDFORM. " FA2_GET_USER_ATTRIBUTES_ALL
&----
idoc-dont_show_docu = p_attrib-do1. m_toggle idoc-dont_show_docu. " negative logic! idoc-dont_show_attrib = p_attrib-at1. m_toggle idoc-dont_show_attrib. " negative logic!
CLEAR p_tree. p_tree-type = 'H'. p_tree-tlevel = 1.
IF idoc-idoc_type_attrib-struct_type EQ ledid_extended_idoc_type_id. p_tree-name = idoc-idoc_type_attrib-extension_type. ELSE. p_tree-name = idoc-idoc_type. ENDIF. p_tree-nlength = 30. p_tree-color = 1. p_tree-intensiv = 1.
PERFORM fa2_fill_field USING p_tree on '9' 'T' idoc-idoc_type_attrib-descrp(75).
PERFORM fa1_add_checkbox USING p_tree p_attrib-at1 '/' " no documentation '/'. " no values
APPEND p_tree.
ENDFORM. " F01_CONSTRUCT_ROOT_NODE
&----
CLEAR p_tree.
p_tree-type = 'TB'.
IF p_wa_idoc-syntax_attrib-parseg EQ space. IF p_wa_idoc-syntax_attrib-occmax EQ 1.
lev_offset = 1. ELSE.
lev_offset = 0. ENDIF.
IF idoc-idoc_type_attrib-struct_type EQ ledid_extension_type_id. lev_offset = lev_offset + 1. ENDIF. ENDIF.
p_tree-tlevel = p_wa_idoc-syntax_attrib-hlevel + lev_offset.
p_tree-color = 4.
IF p_wa_idoc-syntax_attrib-parflg EQ on. p_tree-intensiv = '1'. ELSE. p_tree-intensiv = '0'. ENDIF. p_tree-name = p_wa_idoc-segment_type.
p_tree-nlength = 30.
PERFORM fa2_fill_field USING p_tree on '9' 'T' p_wa_idoc-segment_type_attrib-descrp.
PERFORM fa1_add_checkbox USING p_tree p_attrib-at2 p_attrib-do2 '/'.
APPEND p_tree.
PERFORM f01_construct_field_node TABLES p_tree USING p_wa_idoc-segment_type p_tree-tlevel p_attrib.
ENDFORM. " F01_CONSTRUCT_SEGMENT_NODE
&----
DATA: l_level LIKE streenode-tlevel, l_field TYPE ledid_segment_struct.
l_level = p_tlevel + 1.
CLEAR p_tree. p_tree-type = 'D'. p_tree-tlevel = l_level. p_tree-name = text-101. p_tree-nlength = strlen( p_tree-name ). p_tree-color = 2. p_tree-intensiv = '0'. APPEND p_tree.
LOOP AT t_fields INTO l_field WHERE segment_type = p_segment_type.
PERFORM f01_construct_single_field TABLES p_tree USING l_field l_level p_attrib.
l_field-dont_show_docu = p_attrib-do3. m_toggle l_field-dont_show_docu. l_field-dont_show_attrib = p_attrib-at3. m_toggle l_field-dont_show_attrib. l_field-dont_show_values = p_attrib-val. m_toggle l_field-dont_show_values. MODIFY t_fields FROM l_field.
ENDLOOP.
ENDFORM. " F01_CONSTRUCT_FIELD_NODE
&----
CLEAR p_tree. p_tree-type = 'DE'. p_tree-tlevel = p_level + 1. p_tree-name = p_field-fieldname. p_tree-text7 = p_field-segment_type. " hide segment name p_tree-text8 = p_field-field_attrib-rollname. " hide data element p_tree-nlength = 30. p_tree-color = 2. p_tree-intensiv = '0'.
PERFORM fa2_fill_field USING p_tree on '9' 'T' p_field-field_attrib-descrp.
PERFORM fa1_add_checkbox USING p_tree p_attrib-at3 p_attrib-do3 p_attrib-val. APPEND p_tree. ENDFORM. " F01_CONSTRUCT_SINGLE_FIELD
&----
IF p_attr EQ on OR p_docu EQ on OR p_valu EQ on. p_node-moreinfo = on. ENDIF.
IF p_attr EQ '/'.
p_node-tlength2 = 0. ELSE. CASE p_attr. WHEN on.
p_node-text2 = 'SYM_FILLED_SQUARE'. WHEN off.
p_node-text2 = 'SYM_SQUARE'. ENDCASE. p_node-hotspot2 = on. p_node-tlength2 = 1. p_node-kind2 = 'S'. p_node-tcolor2 = 3. p_node-tintensiv2 = '0'. ENDIF.
IF p_docu EQ '/'.
p_node-tlength3 = 0. ELSE. CASE p_docu. WHEN on.
p_node-text3 = 'SYM_FILLED_CIRCLE'. WHEN off.
p_node-text3 = 'SYM_CIRCLE'. ENDCASE. p_node-hotspot3 = on. p_node-tlength3 = 1. p_node-kind3 = 'S'. p_node-tcolor3 = 3. p_node-tintensiv3 = '0'. ENDIF.
IF p_valu EQ '/'.
p_node-tlength4 = 0. ELSE. CASE p_valu. WHEN on.
p_node-text4 = 'SYM_FILLED_DIAMOND'. WHEN off.
p_node-text4 = 'SYM_DIAMOND'. ENDCASE. p_node-hotspot4 = on. p_node-tlength4 = 1. p_node-kind4 = 'S'. p_node-tcolor4 = 3. p_node-tintensiv4 = '0'. ENDIF.
ENDFORM.
&----
FIELD-SYMBOLS: .
= p_value.
IF p_adjust_length EQ on.