Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Search Command

Former Member
0 Likes
752

Hello,

I have an XML file and need to grab a couple of fields from that. Iam passing each record of the XML file into the internal table and below is what I see. I need to pull AUFNR, AUART, TIDNR and STTXT from the code.

Iam thinking of this logic:

1. search for <AUFNR> in the string.

2. Pick 12 characters from <AUFNR>

3. Pass that value into another internal table for further processing.

Similar with the other fields.

I need some help with the code. It would be really great if someone can help me with this.

Thanks much ~V

<?xml version="1.0" encoding="iso-8859-1"?>

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"><asx:values><OUTPUT><item><AUFNR>000005000292</AUFNR><AUART>PM01</AUART><TIDNR/><STTXT>REL NMAT PRC SETC</STTXT></item></OUTPUT></asx:values></asx:abap>

8 REPLIES 8
Read only

Former Member
0 Likes
721

search for aufnr field and check sy-subrc and then use offset concept and pass that value to itab.

Read only

Former Member
0 Likes
721

Find the ending position of <AUFNR> and the start position of </AUFNR>. Use offsets to take everything between.

Be careful if this can cross line breaks.

Rob

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
721

What release of SAP are you using. If in a new release, you can use the built in XML handling using the CALL TRANSFORMATIONs statement.

Regards,

Rich HEilman

Read only

Read only

Read only

Former Member
0 Likes
721

Thankyou all for the replies. We are on SAP Enterprise..I looked at the links I tried using the cal transformation unsucessfully.

Also, Iam new to the concept of offset, can anyone provide me a sample code?

Thanks,

-V

Read only

0 Likes
721

You'll probably be better off pursuing the CALL TRANSFORMATION, but if you still decide to go the other way, you can try something like:


REPORT ztest MESSAGE-ID 00.

DATA: itab TYPE TABLE OF string WITH HEADER LINE,
      wa   TYPE string,
      order(12).

CONCATENATE: '<?xml version="1.0" encoding="iso-8859-1"?>'
'<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">'
'<asx:values><OUTPUT><item><AUFNR>000005000292</AUFNR>'
'<AUART>PM01</AUART><TIDNR/>'
'<STTXT>REL NMAT PRC SETC</STTXT>'
'</item></OUTPUT></asx:values></asx:abap> '
INTO wa.

SPLIT wa AT 'AUFNR>' INTO TABLE itab.

IF sy-subrc = 0.
  READ TABLE itab INDEX 2.
  REPLACE '</' IN itab WITH space.
  order = itab.
ENDIF.

I'm using the split instead of offsets to avoid problems with new lines. An I assume there is no more than one order.

It's not pretty but you can use it as a start.

Rob

Read only

Former Member
0 Likes
721

HI check these examples:

DATA string7(30) TYPE c VALUE 'This is a little sentence.'.

WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.

SEARCH string7 FOR 'X'.

WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR 'itt '.

WRITE: / 'itt ', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR '.e .'.

WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR '*e'.

WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

Praveen