Introduction

Recently I worked on a SAP PI Integration Project with POS(Point of Sales) system.For this particular requirement client want the complete mapping in ABAP rather then Graphical.As we all knows usually Graphical Mapping is very popular in Integration with any POS system and most of the PI consultants are very good in that but  some customer prefer ABAP Mapping over Graphical mapping mainly because of business critical scenarios which can’t be resolved through Graphical Scenario.I am not a expert in PI so never done any detail comparison between Graphical and ABAP mapping but as per my experience in some cases I feel ABAP mapping definitely upper hand then Graphical Mapping.The step by step approach that i am sharing here will give the brief about the

a–>PI  configuration with respect to mapping the ABAP Class.

b–>ABAP Class to read the IDOC and transform it to POS understandable XML output.

c–>Steps to test the IDOC and generate the XML file.

Process Flow

As I mentioned earlier the requirement is based upon the POS integration with SAP System.In a typical integration scenario an IDOC  trigger from the SAP system and when it reached to XI system it get converted into POS understandable XML output file then it move to the POS system and BI system if required.

PI Configuration Steps

In this document I have not covered the step by step process to configure the  PI for the ABAP class mapping in a impression  that the consultants having basic idea of the config ,however I am sharing the screen shot where exactly the ABAP Class need to map during PI configuration.

Image1.png

ABAP Class mapping in PI

Code

ABAP Class Method–>

method if_mapping~execute.

*====================================================================================================*
*                               VARIABLES FOR BUILDING XML
*====================================================================================================*
data:
odocument                      
type ref to if_ixml_document,
element                        
type ref to if_ixml_element,
messages                       
type ref to if_ixml_element,
message1                       
type ref to if_ixml_element,
message2                       
type ref to if_ixml_element,
file                           
type ref to if_ixml_element,
transaction                     type ref to if_ixml_element,
selling_code                   
type ref to if_ixml_element,
product                        
type ref to if_ixml_element,
level1                         
type ref to if_ixml_element,
level2                         
type ref to if_ixml_element,
level3                         
type ref to if_ixml_element,
level4                         
type ref to if_ixml_element,
level5                         
type ref to if_ixml_element,
level6                         
type ref to if_ixml_element,
level7                         
type ref to if_ixml_element,
level8                         
type ref to if_ixml_element,
level9                         
type ref to if_ixml_element,
idocument                      
type ref to if_ixml_document,
customer                       
type ref to if_ixml_element.

data:
segname                        
type string,
fieldname                      
type string,
fieldvalue                     
type string,
fullname                       
type string,
l_segment_flag,
string                         
type string,
doc_no                         
type string,
trans_no                       
type string,
count                           type i,
l_docnum                       
type string,
l_docnum1                      
type string,
l_string                       
type string,
zpgtyp                         
type string,
zpgcod                         
type string,
date                            type string.

data:
attributes                     
type ref to if_ixml_named_node_map,
attribute                      
type ref to if_ixml_attribute,
child                          
type ref to if_ixml_node,
prodgroupdoc                   
type ref to if_ixml_element.

data:
edi_dc40                       
type edidc.

*====================================================================================================*
*               DATA TYPE DECLARATION ENDS                                                           *
*====================================================================================================*
*====================================================================================================*
*               INTERNAL TABLE DECLARATION STARTS                                                    *
*====================================================================================================*
types:
begin of z15_wpper ,
zidnm                          
type i,
zaend                          
type string,
zname                          
type string,
zprns                          
type string,
zstss                          
type string,
zplz0                          
type string,
ztele                          
type string,
zort1                          
type string,
zfldg                          
type string,
zfldn                          
type string,
zfldv                          
type string,
zvalu                          
type string,
zvalu1                         
type string,
zvalu2                         
type string,
zvalu3                         
type string,
zvalu4                         
type string,
zvalu5                         
type string,
zvalu6                         
type string,
zvalu7                         
type string,
zvalu8                         
type string,
zvalu9                         
type string,
end of z15_wpper,

begin of z15_temp ,
zidnm                          
type i,
zaend                          
type string,
zname                          
type string,
zprns                          
type string,
zstss                          
type string,
zplz0                          
type string,
ztele                          
type string,
zort1                          
type string,
zfldg                          
type string,
zfldn                          
type string,
zfldv                          
type string,
zvalu                          
type string,
zvalu1                         
type string,
zvalu2                         
type string,
zvalu3                         
type string,
zvalu4                         
type string,
zvalu5                         
type string,
zvalu6                         
type string,
zvalu7                         
type string,
zvalu8                         
type string,
zvalu9                         
type string,
end of z15_temp.

data:
t_wpper                        
type standard table of z15_wpper,
wa_wpper                       
type z15_wpper,
wa_wpper1                      
like line of t_wpper,

t_temp                          type standard table of z15_temp,
wa_temp                        
type z15_temp,
wa_temp1                       
like line of t_temp.
*====================================================================================================*
*               INTERNAL TABLE DECLARATION ENDS                                                      *
*====================================================================================================*
data:
event                           type ref to if_ixml_event,
event_sub                      
type i,
node                           
type ref to if_ixml_node,
v_idnum                        
like wa_wpper-zidnm,
no_of_hierarchy_levels         
type i,
top_level_hierarchy_no         
type i.

*====================================================================================================*
*               STANDARD XML TYPE DECLARATION STARTS                                                 *
*====================================================================================================*
l_trace =
‘Start of ABAP mapping’.
trace->trace( level =
‘1’
message = l_trace ).

*====================================================================================================*
* CREATES AN INSTANCE OF THE iXML CLASS AND RETURNS AN INTERFACE POINTER TO THE INSTANCE             *
*====================================================================================================*
ixml_factory = cl_ixml=>create( ).

*====================================================================================================*
*                NEXT CREATE STREAM FACTORY                                                          *
* CREATES A NEW STREAMFACTORY INSTANCE AND RETURNS AN INTERFACE POINTER TO THIS INSTANCE             *
*====================================================================================================*
stream_factory = ixml_factory->create_stream_factory( ).

*====================================================================================================*
*                  TO CREATE INPUT STREAM WE NEED THE ABOVE STREAM FACTORY INSTANCE CREATED          *
*                  CREATE INPUT STREAM                                                               *
*                  CREATES A NEW XML INPUT STREAM FOR THE GIVEN ABAP XSTRING                         *
*====================================================================================================*
istream = stream_factory->create_istream_xstring( source ).

*====================================================================================================*
*                PARSE INPUT DOCUMENT                                                                *
*               INITIALIZE INPUT DOCUMENT                                                            *
* CREATE A NEW DOCUMENT INSTANCE AND RETURN AN INTERFACE POINTER TO THIS INSTANCE                    *
*====================================================================================================*
idocument = ixml_factory->create_document( ).

*====================================================================================================*
* CREATES A NEW PARSER INSTANCE AND RETURNS IN INTERFACE POINTER TO THIS INSTANCE                    *
*====================================================================================================*
iparser = ixml_factory->create_parser( stream_factory = stream_factory
istream        = istream
document       = idocument ).

*====================================================================================================*
* IMPLEMENTS THE DOM-GENERATING INTERFACE TO THE PARSER                                              *
*====================================================================================================*
l_trace =
‘Start of ABAP mapping’.
trace->trace( level   =
‘1’
message = l_trace ).

*====================================================================================================*
* CREATES AN INSTANCE OF THE iXML CLASS AND RETURNS AN INTERFACE POINTER TO THE INSTANCE             *
*====================================================================================================*
ixml_factory = cl_ixml=>create( ).

*====================================================================================================*
* CREATES A NEW STRREAMFACTORY INSTANCE AND RETURNS AN INTERFACE POINTER TO THIS INSTANCE            *
*====================================================================================================*
stream_factory = ixml_factory->create_stream_factory( ).

*====================================================================================================*
* TO CREATE INPUT STREAM WE NEED THE ABOVE STREAM FACTORY INSTANCE CREATED                           *
* CREATE INPUT STREAM                                                                                *
* CREATES A NEW XML INPUT STREAM FOR THE GIVEN ABAP XSTRING                                          *
*====================================================================================================*
istream = stream_factory->create_istream_xstring( source ).

*====================================================================================================*
*PARSE INPUT DOCUMENT                                                                                *
*INITIALIZE INPUT DOCUMENT                                                                           *
*CREATES A NEW DOCUMENT INSTANCE AND RETURNS AN INTERFACE POINTER TO THIS INSTANCE                   *
*====================================================================================================*
idocument = ixml_factory->create_document( ).

*====================================================================================================*
* CREATES A NEW PARSER INSTANCE AND RETURNS AN INTERFACE POINTER TO THIS INSTANCE                    *
*====================================================================================================*
iparser  = ixml_factory->create_parser( stream_factory = stream_factory
istream        = istream
document       = idocument ).

*====================================================================================================*
*                             READ IDOC
*====================================================================================================*
v_idnum =
‘1’.
event_sub = if_ixml_event=>co_event_element_pre2 +
if_ixml_event=>co_event_element_post.
iparser->set_event_subscription(
events = event_sub ).

do.
event = iparser->parse_event( ).
if event is initial.
exit.
endif.
node  = event->get_node( ).

*====================================================================================================*
*                VALUE FOR THE PARENT NODE SEGMENT                                                   *
*====================================================================================================*
clear l_segment_flag.
attributes = node->get_attributes( ).
if not attributes is initial.
child = attributes->get_named_item( name =
‘SEGMENT’ ).
if not child is initial.
l_segment_flag =
‘X’.
endif.
endif.

*=====================================================================================================*
*                  FOR EACH NEW SEGMENT                                                               *
**====================================================================================================*
if not l_segment_flag is initial.
case event->get_type( ).
when if_ixml_event=>co_event_element_pre2.

*=====================================================================================================*
*               PRE PROCESSING OF SEGMENT                                                             *
*=====================================================================================================*
segname = event->get_name( ).
when if_ixml_event=>co_event_element_post.

*====================================================================================================*
*                    POST PROCESSING OF SEGMENT                                                      *
*====================================================================================================*
segname = event->get_name( ).
case segname.
when ‘WA_CODE’.
wa_wpper-zidnm = v_idnum.
endcase.
endcase.
else.
if event->get_type( ) = if_ixml_event=>co_event_element_post.
fieldname  = node->get_name( ).
fieldvalue = node->get_value( ).

*=====================================================================================================*
*            ADDING THE VALUE FOR THE HEADER FIELD  DOCUNUM                                           *
*=====================================================================================================*
if sy-subrc eq 0.
if fieldname eq ‘DOCNUM’.
l_docnum = fieldvalue.
endif.
endif.

*===================================================================================================*
*            ADDING THE VALUE FOR THE ITEM FIELDS                                                   *
*===================================================================================================*
if sy-subrc eq 0.
case  fieldname .
when ‘AENDKENNZ’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zaend              = fieldname.
wa_wpper-zvalu              = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zaend             = wa_wpper-zaend.
wa_wpper1-zvalu             = wa_wpper-zvalu.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘NAME’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zname              = fieldname.
wa_wpper-zvalu1             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zname             = wa_wpper-zname.
wa_wpper1-zvalu1            = wa_wpper-zvalu1.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘PERSNR’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zprns              = fieldname.
wa_wpper-zvalu2             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zprns             = wa_wpper-zprns.
wa_wpper1-zvalu2            = wa_wpper-zvalu2.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘STRASSE’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zstss              = fieldname.
wa_wpper-zvalu3             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zstss             = wa_wpper-zstss.
wa_wpper1-zvalu3            = wa_wpper-zvalu3.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘PLZ’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zplz0              = fieldname.
wa_wpper-zvalu4             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zplz0             = wa_wpper-zplz0.
wa_wpper1-zvalu4            = wa_wpper-zvalu4.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘TELEFON’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-ztele              = fieldname.
wa_wpper-zvalu5             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-ztele             = wa_wpper-ztele.
wa_wpper1-zvalu5            = wa_wpper-zvalu5.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘ORT’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zort1              = fieldname.
wa_wpper-zvalu6             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zort1             = wa_wpper-zort1.
wa_wpper1-zvalu6            = wa_wpper-zvalu6.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘FLDGRP’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zfldg              = fieldname.
wa_wpper-zvalu7             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zfldg             = wa_wpper-zfldg.
wa_wpper1-zvalu7            = wa_wpper-zvalu7.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘FLDNAME’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zfldn              = fieldname.
wa_wpper-zvalu8             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zfldn             = wa_wpper-zfldn.
wa_wpper1-zvalu8            = wa_wpper-zvalu8.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.

when ‘FLDVAL’.
wa_wpper-zidnm              = v_idnum.
wa_wpper-zfldv              = fieldname.
wa_wpper-zvalu9             = fieldvalue.

wa_wpper1-zidnm             = wa_wpper-zidnm.
wa_wpper1-zfldv             = wa_wpper-zfldv.
wa_wpper1-zvalu9            = wa_wpper-zvalu9.

append wa_wpper1 to t_wpper.
clear  wa_wpper1.
endcase.
endif.
endif.
endif.
if fieldname eq ‘FLDVAL’ and segname eq ‘E1WPP01’.
v_idnum = v_idnum +
1.
clear fieldname.
clear segname.
endif.
enddo.

*==========================================================================================================*
*             PUTTING DATA INTO FINAL INTERNAL TABLE                                                       *
*==========================================================================================================*
loop at   t_wpper into wa_wpper.
if wa_temp-zidnm is initial and not wa_wpper-zidnm is initial.
wa_temp-zidnm  = wa_wpper-zidnm.
endif.
if wa_temp-zaend  is initial and not wa_wpper-zaend  is initial.
wa_temp-zaend  = wa_wpper-zaend .
endif.
if wa_temp-zname is initial and not wa_wpper-zname is initial.
wa_temp-zname  = wa_wpper-zname.
endif.
if wa_temp-zprns is initial and not wa_wpper-zprns is initial.
wa_temp-zprns  = wa_wpper-zprns.
endif.
if wa_temp-zstss is initial and not wa_wpper-zstss is initial.
wa_temp-zstss  = wa_wpper-zstss.
endif.
if wa_temp-zplz0 is initial and not wa_wpper-zplz0 is initial.
wa_temp-zplz0  = wa_wpper-zplz0.
endif.
if wa_temp-ztele is initial and not wa_wpper-ztele is initial.
wa_temp-ztele  = wa_wpper-ztele.
endif.
if wa_temp-zort1 is initial and not wa_wpper-zort1 is initial.
wa_temp-zort1  = wa_wpper-zort1.
endif.
if wa_temp-zfldg is initial and not wa_wpper-zfldg is initial.
wa_temp-zfldg  = wa_wpper-zfldg.
endif.
if wa_temp-zfldn is initial and not wa_wpper-zfldn is initial.
wa_temp-zfldn  = wa_wpper-zfldn.
endif.
if wa_temp-zfldv is initial and not wa_wpper-zfldv is initial.
wa_temp-zfldv  = wa_wpper-zfldv.
endif.
if wa_temp-zvalu is initial and not wa_wpper-zvalu is initial.
wa_temp-zvalu  = wa_wpper-zvalu.
endif.
if wa_temp-zvalu1 is initial and not wa_wpper-zvalu1 is initial.
wa_temp-zvalu1 = wa_wpper-zvalu1.
endif.
if wa_temp-zvalu2 is initial and not wa_wpper-zvalu2 is initial.
wa_temp-zvalu2 = wa_wpper-zvalu2.
endif.
if wa_temp-zvalu3 is initial and not wa_wpper-zvalu3 is initial.
wa_temp-zvalu3 = wa_wpper-zvalu3.
endif.
if wa_temp-zvalu4 is initial and not wa_wpper-zvalu4 is initial.
wa_temp-zvalu4 = wa_wpper-zvalu4.
endif.
if wa_temp-zvalu5 is initial and not wa_wpper-zvalu5 is initial.
wa_temp-zvalu5 = wa_wpper-zvalu5.
endif.
if wa_temp-zvalu6 is initial and not wa_wpper-zvalu6 is initial.
wa_temp-zvalu6 = wa_wpper-zvalu6.
endif.
if wa_temp-zvalu7 is initial and not wa_wpper-zvalu7 is initial.
wa_temp-zvalu7 = wa_wpper-zvalu7.
endif.
if wa_temp-zvalu8 is initial and not wa_wpper-zvalu8 is initial.
wa_temp-zvalu8 = wa_wpper-zvalu8.
endif.
if wa_temp-zvalu9 is initial and not wa_wpper-zvalu9 is initial.
wa_temp-zvalu9 = wa_wpper-zvalu9.
endif.

if count eq 28.
append wa_temp to t_temp.
clear  count.
clear  wa_temp.
endif.

count = count + 1.

endloop.

*==========================================================================================================*
*                    NOW MOVE THE IDOC FIELDS TO THE WORK FIELDS                                           *
*==========================================================================================================*
l_docnum1 = l_docnum.
shift l_docnum1 left deleting leading ‘0’.

*==========================================================================================================*
*                BUILD XML OUTPUT DOCUMENT                                                                 *
* CREATES A NEW DOCUMENT INSTANCE AND RETURNS AN INTERFACE POINTER TO THIS INSTANCE                        *
*==========================================================================================================*
odocument = ixml_factory->create_document( ).

*==========================================================================================================*
*                         ADD TOP ELEMENT AND ITS ATTRIBUTES                                               *
*==========================================================================================================*
file = odocument->create_simple_element_ns( name =
‘FILE’ parent = odocument ).
l_rc = file->set_attribute_ns( name =
‘changeId’ value = ‘1’ ).
l_rc = file->set_attribute_ns( name =
‘batchNo’ value = l_docnum1 ).

*==============================================================================================================*
*                           VALUE FOR THE TRANSACTION NODE                                                     *
*==============================================================================================================*
count = 1.
loop at t_temp into wa_temp .
trans_no = trans_no +
1.
condense trans_no no-gaps.
shift trans_no left deleting leading ‘0’.

transaction = odocument->create_simple_element_ns( name = ‘TRANSACTION’ parent = file ).
l_rc  = transaction->set_attribute_ns( name =
‘transactionNo’ value = trans_no ).

*==============================================================================================================*
*                           VALUE FOR THE CUSTOMER NODE                                                        *
*==============================================================================================================*
doc_no = doc_no +
1.
condense doc_no no-gaps.
shift doc_no left deleting leading ‘0’.

customer = odocument->create_simple_element_ns( name = ‘CUSTOMER’ parent = transaction ).
l_rc = customer->set_attribute_ns( name =
‘docNo’ value = doc_no ).

*==============================================================================================================*
*                           VALUE FOR THE CRUD NODE                                                            *
*==============================================================================================================*
if wa_temp-zvalu eq ‘DELE’ and not wa_temp-zaend is initial.
level1 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = customer value = ‘D’ ).
else.
level1 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = customer value = ‘P’ ).
endif.

*==============================================================================================================*
*                           VALUE FOR THE CUSTOMER NAME                                                        *
*==============================================================================================================*
level1 = odocument->create_simple_element_ns( name =
‘CUSTOMER_NAME’ parent = customer value = wa_temp-zvalu1 ).

*==============================================================================================================*
*                           VALUE FOR THE CUSTOMER CODE                                                        *
*==============================================================================================================*
condense wa_temp-zvalu2 no-gaps.
shift wa_temp-zvalu2 left deleting leading ‘0’.

level1 = odocument->create_simple_element_ns( name = ‘CUSTOMER_CODE’ parent = customer value = wa_temp-zvalu2 ).

*==============================================================================================================*
*                           VALUE FOR THE CUSTOMER TYPE                                                        *
*==============================================================================================================*
level1 = odocument->create_simple_element_ns( name =
‘CUSTOMER_TYPE’ parent = customer value = ‘1’ ).

*==============================================================================================================*
*                           VALUE FOR THE CUSTOMER STATUS                                                        *
*==============================================================================================================*
level1 = odocument->create_simple_element_ns( name =
‘CUSTOMER_STATUS’ parent = customer value = ‘48001’ ).

*=================================================================================================================*
**                           VALUE FOR THE ADDRESSES CHILD NODE                                                   *
**================================================================================================================*
level1 = odocument->create_simple_element_ns( name =
‘ADDRESSES’ parent = customer ).

*=================================================================================================================*
**                           VALUE FOR THE ADDRESS CHILD NODE                                                     *
**================================================================================================================*
level2 = odocument->create_simple_element_ns( name =
‘ADDRESS’ parent = level1 ).

*=================================================================================================================*
**                           VALUE FOR THE CRUD CHILD NODE                                                        *
**================================================================================================================*
if wa_temp-zvalu eq ‘DELE’ and not wa_temp-zaend is initial.
level3 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level2 value = ‘D’ ).
else.
level3 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level2 value = ‘P’ ).
endif.

*=================================================================================================================*
**                           VALUE FOR THE TYPE CHILD NODE                                                        *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘TYPE’ parent = level2 value = ‘2’ ).

*=================================================================================================================*
**                           VALUE FOR THE ADDRESS_LINE_1 CHILD NODE                                                        *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘ADDRESS_LINE_1’ parent = level2 value = wa_temp-zvalu3 ).

*=================================================================================================================*
**                           VALUE FOR THE POST_CODE CHILD NODE                                                   *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘POST_CODE’ parent = level2 value = wa_temp-zvalu4 ).

*=================================================================================================================*
**                           VALUE FOR THE TELEPHONE_NUMBER CHILD NODE                                            *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘TELEPHONE_NUMBER’ parent = level2 value = wa_temp-zvalu5 ).

*=================================================================================================================*
**                           VALUE FOR THE CITY CHILD NODE                                                        *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘CITY’ parent = level2 value = wa_temp-zvalu6 ).

*=================================================================================================================*
**                           VALUE FOR THE TITLE CHILD NODE                                                        *
**================================================================================================================*
if wa_temp-zvalu7 eq ‘KNA1’ and wa_temp-zvalu8 eq ‘STCD2’ and wa_temp-zvalu9 ne ‘0’.
level3 = odocument->create_simple_element_ns( name =
‘TITLE’ parent = level2 value = wa_temp-zvalu9 ).
else.
level3 = odocument->create_simple_element_ns( name =
‘TITLE’ parent = level2  ).
endif.

*=================================================================================================================*
**                           VALUE FOR THE ACCOUNTS CHILD NODE                                                    *
**================================================================================================================*
level3 = odocument->create_simple_element_ns( name =
‘ACCOUNTS’ parent = customer ).

*=================================================================================================================*
**                           VALUE FOR THE ACCOUNT CHILD NODE                                                     *
**================================================================================================================*
level4 = odocument->create_simple_element_ns( name =
‘ACCOUNT’ parent = level3 ).

*=================================================================================================================*
**                           VALUE FOR THE CRUD CHILD NODE                                                        *
**================================================================================================================*
if wa_temp-zvalu eq ‘DELE’ and not wa_temp-zaend is initial.
level5 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level4 value = ‘D’ ).
else.
level5 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level4 value = ‘P’ ).
endif.

*=================================================================================================================*
**                           VALUE FOR THE COMPANY CHILD NODE                                                     *
**================================================================================================================*
level5 = odocument->create_simple_element_ns( name =
‘COMPANY’ parent = level4 value = ‘ABCD’ ).

*=================================================================================================================*
**                           VALUE FOR THE ACCOUNT_NUMBER CHILD NODE                                              *
**================================================================================================================*
level5 = odocument->create_simple_element_ns( name =
‘ACCOUNT_NUMBER’ parent = level4 value = wa_temp-zvalu2 ).

*=================================================================================================================*
**                           VALUE FOR THE ACCOUNT_NAME CHILD NODE                                                *
**================================================================================================================*
level5 = odocument->create_simple_element_ns( name =
‘ACCOUNT_NAME’ parent = level4 value = ‘Head Office Charge’ ).

*=================================================================================================================*
**                           VALUE FOR THE STATUS CHILD NODE                                                      *
**================================================================================================================*
if wa_temp-zvalu7 eq ‘KNVV’ and wa_temp-zvalu8 eq ‘KVGR3’ and wa_temp-zvalu9 eq ‘Y’ .
level5 = odocument->create_simple_element_ns( name =
‘STATUS’ parent = level4 value = ‘60301’ ).
else.
if wa_temp-zvalu7 eq ‘KNKK’ and wa_temp-zvalu8 eq ‘KLIMK’ and wa_temp-zvalu9 eq ‘0’.
level5 = odocument->create_simple_element_ns( name =
‘STATUS’ parent = level4 value = ‘60302’ ).
else.
level5 = odocument->create_simple_element_ns( name =
‘STATUS’ parent = level4  ).
endif.
endif.

*=================================================================================================================*
**                           VALUE FOR THE  TYPE CHILD NODE                                                       *
**================================================================================================================*
level5   = odocument->create_simple_element_ns( name =
‘TYPE’ parent = level4 value = ‘76202’ ).

*=================================================================================================================*
**                           VALUE FOR THE STATUS_DATE CHILD NODE                                                 *
**================================================================================================================*
date     = sy-datum + sy-uzeit.
level5   = odocument->create_simple_element_ns( name =
‘STATUS_DATE’ parent = level4 value = date ).

*=================================================================================================================*
**                           VALUE FOR THE CREDIT_LIMIT CHILD NODE                                                *
**================================================================================================================*
if wa_temp-zvalu7 eq ‘KNKK’ and wa_temp-zvalu8 eq ‘KLIMK’ .
level5 = odocument->create_simple_element_ns( name =
‘CREDIT_LIMIT’ parent = level4 value = wa_temp-zvalu9 ).
else.
level5 = odocument->create_simple_element_ns( name =
‘CREDIT_LIMIT’ parent = level4 ).
endif.

*=================================================================================================================*
**                           VALUE FOR THE LEGAL_TENDER CHILD NODE                                                *
**================================================================================================================*
level5   = odocument->create_simple_element_ns( name =
‘LEGAL_TENDER’ parent = level4 value = ‘CAD’ ).

*=================================================================================================================*
**                           VALUE FOR THE CARDS CHILD NODE                                                       *
**================================================================================================================*
level5   = odocument->create_simple_element_ns( name =
‘CARDS’ parent = customer ).

*=================================================================================================================*
**                           VALUE FOR THE CARD CHILD NODE                                                        *
**================================================================================================================*
level6   = odocument->create_simple_element_ns( name =
‘CARD’ parent = level5 ).

*=================================================================================================================*
**                           VALUE FOR THE CRUD CHILD NODE                                                        *
**================================================================================================================*
if wa_temp-zvalu eq ‘DELE’ and not wa_temp-zaend is initial.
level7 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level6 value = ‘D’ ).
else.
level7 = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level6 value = ‘P’ ).
endif.
*=================================================================================================================*
**                           VALUE FOR THE CARD_NUMBER CHILD NODE                                                 *
**================================================================================================================*
condense wa_temp-zvalu2 no-gaps.
shift wa_temp-zvalu2 left deleting leading ‘0’.
level7   = odocument->create_simple_element_ns( name =
‘CARD_NUMBER’ parent = level6 value = wa_temp-zvalu2 ).

*=================================================================================================================*
**                           VALUE FOR THE CARD STATUS CODE CHILD NODE                                            *
**================================================================================================================*
if wa_temp-zvalu7 eq ‘KNVV’ and wa_temp-zvalu8 eq ‘KVGR3’ and wa_temp-zvalu9 eq ‘Y’ .
level7 = odocument->create_simple_element_ns( name =
‘STATUS’ parent = level6 value = ‘76101’ ).
else.
if wa_temp-zvalu7 eq ‘KNKK’ and wa_temp-zvalu8 eq ‘KLIMK’ and wa_temp-zvalu9 eq ‘0’.
level7  = odocument->create_simple_element_ns( name =
‘STATUS’ parent = level6 value = ‘76103’ ).
endif.
endif.

*=================================================================================================================*
**                           VALUE FOR THE PAYMENT_MEDIAS CHILD NODE                                              *
**================================================================================================================*
level7   = odocument->create_simple_element_ns( name =
‘PAYMENT_MEDIAS’ parent = customer  ).

*=================================================================================================================*
**                           VALUE FOR THE PAYMENT_MEDIA CHILD NODE                                               *
**================================================================================================================*
level8   = odocument->create_simple_element_ns( name =
‘PAYMENT_MEDIA’ parent = level7  ).

*=================================================================================================================*
**                           VALUE FOR THE CRUD CHILD NODE                                                        *
**================================================================================================================*
level9   = odocument->create_simple_element_ns( name =
‘CRUD’ parent = level8 value = ‘P’ ).

*=================================================================================================================*
**                           VALUE FOR THE MEDIA_NUMBER CHILD NODE                                                *
**================================================================================================================*
level9   = odocument->create_simple_element_ns( name =
‘MEDIA_NUMBER’ parent = level8 value = ’30’ ).

*=================================================================================================================*
**                           VALUE FOR THE CAN_BE_USED CHILD NODE                                                 *
**================================================================================================================*
if wa_temp-zvalu7 eq ‘KNVV’ and wa_temp-zvalu8 eq ‘KVGR2’ and wa_temp-zvalu9 eq ‘Y’ .
level8 = odocument->create_simple_element_ns( name =
‘CAN_BE_USED’ parent = level7 value = ‘1’ ).
else.
level8 = odocument->create_simple_element_ns( name =
‘CAN_BE_USED’ parent = level7 value = ‘0’ ).
endif.
clear wa_temp.
endloop.
*==================================================================================================================*
*                   ADD TRANSACTION MESSAGE ON END OF XML TO INDICATE THAT XML IS FINISHED                         *
*==================================================================================================================*
trans_no = trans_no +
1.
level1   = odocument->create_simple_element_ns( name =
‘TRANSACTION’ parent = file ).
l_rc = level1->set_attribute_ns( name =
‘transactionNo’ value = trans_no ).

*===================================================================================================================*
*          ADD END OF BATCH MESSAGE ON END OF XML TO INDICATE THAT XML IS FINISHED                                  *
*===================================================================================================================*
doc_no = doc_no +
1.

level2 = odocument->create_simple_element_ns( name = ‘END_OF_BATCH’ parent = level1 ).
l_rc = level2->set_attribute_ns( name =
‘docNo’ value = doc_no ).

*===================================================================================================================*
* ADD TRANSACTION MESSAGE ON END OF XML TO INDICATE THAT XML IS FINISHED                                            *
*===================================================================================================================*
trans_no = trans_no +
1.
level1   = odocument->create_simple_element_ns( name =
‘TRANSACTION’ parent = file  ).
l_rc = level1->set_attribute_ns( name =
‘transactionNo’ value = trans_no ).

*===================================================================================================================*
*          ADD END OF PROCESSINGMESSAGE ON END OF XML TO INDICATE THAT XML IS FINISHED                              *
*===================================================================================================================*
doc_no = doc_no +
1.

level2 = odocument->create_simple_element_ns( name = ‘END_OF_PROCESSING’ parent = level1 ).
l_rc = level2->set_attribute_ns( name =
‘docNo’ value = doc_no ).

*====================================================================================================*
*      CREATE THE XML OUTPUT STREAM IN AL11 DIRECTORY                                                *
*====================================================================================================*
data: ostream type ref to if_ixml_ostream.
ostream  = stream_factory->create_ostream_xstring( result ).

data: renderer type ref to if_ixml_renderer.
renderer = ixml_factory->create_renderer( ostream  = ostream
document = odocument ).
renderer->render( ).

endmethod.


Requirement before Development of the method–>

1–>Mapping document  between IDOC fields and xml fields

2–>Old sample XML file if available or the xsd file after conversion of IDOC structure

IDOC Testing Approach–>

IDOC NAME   – WP_PER1

IDOC NUMBER- 3217798

ABAP Class Name- ZRT_CUST_MASTER_397

Interface Name-Outbound_Customer Master (WP_PER)

Image1.jpg

    Enter the IDOC Number

Image1.jpg

    Process the IDOC

Image1.jpg

   Execute the IDOC

  Image1.jpg

    1–>Tcode-SXMB_MONI

      2–>Check the last successful message generated

     3–>Double click on that

     4–>Check the part Receiver Grouping–>Payloads–>Main Document(Application/xml)

    If the XML file is successfully generate it would display in the right hand side of the screen as it seen above.,

    




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