Skip to Content
0
Jan 17, 2008 at 12:48 PM

ABAP MAPPING : Getting An Error

19 Views

hi all

i am using a scenario where i am sending data from r/3(prog) >xi >R/3(RFC).

in between i am using ABAP MAPPING

i am getting an error:

ERROR: "" MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7: com.sap.aii.af.rfc.afcommunication.RfcAFWException: java.lang.StringIndexOutOfBoundsException: String index out of range: -7""

the ABAP MAPPING which i am using:

METHOD IF_MAPPING~EXECUTE.

BREAK-POINT.

  • * initialize iXML

TYPE-POOLS: IXML.

TYPE-POOLS: IXML.

DATA: L_IXML TYPE REF TO IF_IXML.

*creating the Interface by calling the create method in class C_IXML

CALL METHOD CL_IXML=>CREATE

  • EXPORTING

  • TYPE = 0

RECEIVING

RVAL = L_IXML.

  • create stream factory

DATA: STREAMFACTORY TYPE REF TO IF_IXML_STREAM_FACTORY.

CALL METHOD L_IXML->CREATE_STREAM_FACTORY

RECEIVING

RVAL = STREAMFACTORY.

  • create input stream

DATA: ISTREAM TYPE REF TO IF_IXML_ISTREAM.

CALL METHOD STREAMFACTORY->CREATE_ISTREAM_XSTRING

EXPORTING

STRING = SOURCE

RECEIVING

RVAL = ISTREAM.

*This iXML factory can create an empty XML document object named IDOCUMENT.

  • initialize input document

DATA: IDOCUMENT TYPE REF TO IF_IXML_DOCUMENT.

CALL METHOD L_IXML->CREATE_DOCUMENT

RECEIVING

RVAL = IDOCUMENT.

  • parse input document

DATA: IPARSER TYPE REF TO IF_IXML_PARSER.

CALL METHOD L_IXML->CREATE_PARSER

EXPORTING

DOCUMENT = IDOCUMENT

ISTREAM = ISTREAM

STREAM_FACTORY = STREAMFACTORY

RECEIVING

RVAL = IPARSER.

IPARSER->PARSE( ).

DATA: ROOT TYPE REF TO IF_IXML_ELEMENT.

  • get message content of tag

DATA: INCODE TYPE REF TO IF_IXML_NODE_COLLECTION,

INCODE1 TYPE REF TO IF_IXML_NODE_COLLECTION,

INCODE2 TYPE REF TO IF_IXML_NODE_COLLECTION,

INCODE0 TYPE REF TO IF_IXML_NODE_COLLECTION.

CALL METHOD IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME

EXPORTING

  • DEPTH = 0

NAME = 'MANDT'

  • NAMESPACE = ''

RECEIVING

RVAL = INCODE0 .

CALL METHOD IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME

EXPORTING

  • DEPTH = 0

NAME = 'EMPNO'

  • NAMESPACE = ''

RECEIVING

RVAL = INCODE.

CALL METHOD IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME

EXPORTING

  • DEPTH = 0

NAME = 'EMPNAME'

  • NAMESPACE = ''

RECEIVING

RVAL = INCODE1.

CALL METHOD IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME

EXPORTING

  • DEPTH = 0

NAME = 'DEPARTMENTNAME'

  • NAMESPACE = ''

RECEIVING

RVAL = INCODE2.

DATA: URI TYPE STRING.

URI = 'urn:sap-com:document:sap:rfc:functions'.

  • * build up output document =============================================

  • create output document

DATA: ODOCUMENT TYPE REF TO IF_IXML_DOCUMENT.

CALL METHOD L_IXML->CREATE_DOCUMENT

RECEIVING

RVAL = ODOCUMENT.

DATA: RET_VALUE TYPE I.

*At this point you can add the nodes (elements, attributes) into the document. First you have to declare the root element node.

DATA: L_ELEMENT_ROOT TYPE REF TO IF_IXML_ELEMENT.

CALL METHOD ODOCUMENT->CREATE_ELEMENT_NS

EXPORTING

NAME = 'ZTEST1'

PREFIX = 'ns1'

URI = 'urn:sap-com:document:sap:rfc:functions'

RECEIVING

RVAL = L_ELEMENT_ROOT.

DATA: L_ELEMENT_NODE TYPE REF TO IF_IXML_ELEMENT.

CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT

EXPORTING

NAME = 'ZTEST1'

  • NAMESPACE = 'xmlns ns1 urn:sap-com:document:sap:rfc:functions'

PARENT = ODOCUMENT

  • VALUE = '?xml version="1.0" encoding="UTF-8"?'

RECEIVING

RVAL = L_ELEMENT_ROOT.

DATA: ATTRIBUTE TYPE REF TO IF_IXML_ATTRIBUTE.

CALL METHOD ODOCUMENT->CREATE_ATTRIBUTE_NS

EXPORTING

NAME = 'ZTEST1'

PREFIX = 'xmlns'" ns1="urn:sap-com:document:sap:rfc:functions"'

URI = 'urn:sap-com:document:sap:rfc:functions'

RECEIVING

RVAL = ATTRIBUTE.

RET_VALUE = ODOCUMENT->SET_NAMESPACE_PREFIX(

PREFIX = 'ns1').

CALL METHOD ATTRIBUTE->SET_VALUE

EXPORTING

VALUE = URI

RECEIVING

RVAL = RET_VALUE.

CALL METHOD L_ELEMENT_ROOT->SET_ATTRIBUTE_NODE_NS

EXPORTING

NEW_ATTR = ATTRIBUTE

RECEIVING

RVAL = RET_VALUE.

DATA: NODE_LIST_COLLECTION TYPE REF TO IF_IXML_NODE_COLLECTION.

  • add node to the output document

DATA: OUTCODE0 TYPE REF TO IF_IXML_NODE.

DATA: OUTCODE TYPE REF TO IF_IXML_NODE.

DATA: OUTCODE1 TYPE REF TO IF_IXML_NODE.

DATA: OUTCODE2 TYPE REF TO IF_IXML_NODE.

DATA: INDEX1 TYPE SY-INDEX.

DATA: INDEX TYPE SY-INDEX.

DATA IRC TYPE I.

CALL METHOD IDOCUMENT->GET_ELEMENTS_BY_TAG_NAME

EXPORTING

  • DEPTH = 0

NAME = 'MANDT'

  • NAMESPACE = ''

RECEIVING

RVAL = NODE_LIST_COLLECTION.

DATA: LENGTH TYPE I.

CALL METHOD NODE_LIST_COLLECTION->GET_LENGTH

RECEIVING

RVAL = LENGTH.

WHILE INDEX < LENGTH.

CALL METHOD IDOCUMENT->CREATE_SIMPLE_ELEMENT

EXPORTING

NAME = 'DATA'

  • NAMESPACE = ''

PARENT = L_ELEMENT_ROOT

  • VALUE =

RECEIVING

RVAL = L_ELEMENT_NODE .

CALL METHOD INCODE0->GET_ITEM

EXPORTING

INDEX = INDEX

RECEIVING

RVAL = OUTCODE0.

CALL METHOD INCODE->GET_ITEM

EXPORTING

INDEX = INDEX

RECEIVING

RVAL = OUTCODE.

CALL METHOD INCODE1->GET_ITEM

EXPORTING

INDEX = INDEX

RECEIVING

RVAL = OUTCODE1.

CALL METHOD INCODE2->GET_ITEM

EXPORTING

INDEX = INDEX

RECEIVING

RVAL = OUTCODE2.

CALL METHOD L_ELEMENT_NODE->APPEND_CHILD

EXPORTING

NEW_CHILD = OUTCODE0

RECEIVING

RVAL = IRC.

CALL METHOD L_ELEMENT_NODE->APPEND_CHILD

EXPORTING

NEW_CHILD = OUTCODE

RECEIVING

RVAL = IRC.

CALL METHOD L_ELEMENT_NODE->APPEND_CHILD

EXPORTING

NEW_CHILD = OUTCODE1

RECEIVING

RVAL = IRC.

CALL METHOD L_ELEMENT_NODE->APPEND_CHILD

EXPORTING

NEW_CHILD = OUTCODE2

RECEIVING

RVAL = IRC.

ADD 1 TO INDEX.

ENDWHILE.

  • render document ======================================================

  • create output stream

DATA: OSTREAM TYPE REF TO IF_IXML_OSTREAM.

CALL METHOD STREAMFACTORY->CREATE_OSTREAM_XSTRING

EXPORTING

STRING = RESULT

RECEIVING

RVAL = OSTREAM.

  • DATA: IPARSER TYPE REF TO IF_IXML_PARSER.

CALL METHOD L_IXML->CREATE_PARSER

EXPORTING

DOCUMENT = ODOCUMENT

ISTREAM = ISTREAM

STREAM_FACTORY = STREAMFACTORY

RECEIVING

RVAL = IPARSER.

IPARSER->PARSE( ).

  • create renderer

DATA: RENDERER TYPE REF TO IF_IXML_RENDERER.

CALL METHOD L_IXML->CREATE_RENDERER

EXPORTING

DOCUMENT = ODOCUMENT

OSTREAM = OSTREAM

RECEIVING

RVAL = RENDERER.

IRC = RENDERER->RENDER( ).

ENDMETHOD.

plz help me out ASAP

thnks

kalyan