cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving the content from attachment in ABAP mapping?

krishg
Active Participant
0 Kudos

We are using PI 7.1 and i have an attachment that I can access in my ABAP mapping. I am able to get the content of my attachment using the IF_MAPPING_ATTACHMENTS-get_attachment method.

Unfortunately the content retrieved is 'XSTRING' type and i have tried all possible options (like below) but I cannot convert the xstring to string? Any ideas? My attachment content is just single line 'XXX'

*  DATA: conv   TYPE REF TO CL_ABAP_CONV_IN_CE.

*        conv = CL_ABAP_CONV_IN_CE=>CREATE( input = string ).

*        conv->READ( importing data = lv_content).

Accepted Solutions (1)

Accepted Solutions (1)

krishg
Active Participant
0 Kudos

I was able to read the attachment once I check the 'read attachment' box in operation mapping

Answers (2)

Answers (2)

former_member184681
Active Contributor
0 Kudos

Hi,

I just checked that I am using exactly identical code to the one you menioned, to convert xstring to string in one of my scenarios. For your code below:

  DATA: conv   TYPE REF TO CL_ABAP_CONV_IN_CE.

        conv = CL_ABAP_CONV_IN_CE=>CREATE( input = string ).

        conv->READ( importing data = lv_content).

Simply make sure that "string" variable that you pass to the CREATE() method is of type xstring and lv_content that you pass to READ() method is of type string.

By the way, were you really able to name your variable "string"?

Regards,

Greg

krishg
Active Participant
0 Kudos

sorry ,I didn't name my variable String...

the only explanation seems to be that  IF_MAPPING_ATTACHMENTS-get_attachment does not work correctly

When I used SCMS_XSTRING_TO_BINARY FM, the Output length I got was '1'... something tells me that the "content" retrieved from Get_Attachment does not work (though the content type is perfect). My content type is text/plain.

I  was able to use the inbound proxy to read this attachment, but the fact that I am not able to do this in ABAP mapping bothers me. Any other ideas?

iaki_vila
Active Contributor
0 Kudos

Hi Krish,

That solution that you point, should work. You cant try to copy the HR_KR_XSTRING_TO_STRING from R/3 system, but finally it uses CL_ABAP_CONV_IN_CE too.

Try to improve your code like that:

DATA: LOC_CONV TYPE REF TO CL_ABAP_CONV_IN_CE,
           LOC_XSTRING TYPE XSTRING,
           LOC_STRING TYPE STRING.
*   Convert XString to String
CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
   EXPORTING
     INPUT       = LOC_XSTRING
     ENCODING    = 'UTF-8'
     REPLACEMENT = '?'
     IGNORE_CERR = ABAP_TRUE
   RECEIVING
     CONV        = LOC_CONV.

TRY.
     CALL METHOD LOC_CONV->READ
       IMPORTING
         DATA = LOC_STRING.
   CATCH CX_SY_CONVERSION_CODEPAGE.
*-- Should ignore errors in code conversions
   CATCH CX_SY_CODEPAGE_CONVERTER_INIT.
*-- Should ignore errors in code conversions
   CATCH CX_PARAMETER_INVALID_TYPE.
   CATCH CX_PARAMETER_INVALID_RANGE.
ENDTRY.

Do you obtain any exception with this code?, could you say us what exception is?

Regards.

krishg
Active Participant
0 Kudos

No exceptions were returned.. My output string is always empty. Please note that my content type is plain/text (could it be a cause?)