Skip to Content

Reading a SO file (attachment in an invoice document) and encode it as base64

Hi all,

Hope to explain this clearly:

we have some attachments(Service Ojects) in invoices (vf01) .

Those files(PDF,DOC etc etc) must be encoded as base64 and used within an XML file.

This is what i was able to do so far:

identify the attached document(i.e. JPG) inside the invoice document and read it in an internal table using FM

SO_DOCUMENT_READ_API1.

IT all works fine.I downloaded the internal table onto my local machine(GUI_DOWNLOAD) and it worked fine,in fact i was able to read it with the proper viewer (pdf reader or jpg reader )

I need a new step:

i don't have to download the file to local machineanymore but i need to append this file within an xml tag which requires a base64 encoding.

So, after i read my attachment into the internal table, what should i do next?

Don't forget i am working on a 46C machine.

Thanks a lot.

Add comment
10|10000 characters needed characters exceeded

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 21, 2014 at 03:39 PM

    Hi,

    you can try this way:


    DATA: contents_hex TYPE solix_tab,

    document_id LIKE sofolenti1-doc_id,

    xstr TYPE xstring,

    b64string TYPE string.

    CALL FUNCTION 'SO_DOCUMENT_READ_API1'

    EXPORTING

    document_id = document_id

    TABLES

    contents_hex = contents_hex

    EXCEPTIONS

    document_id_not_exist = 1

    operation_no_authorization = 2

    x_error = 3

    OTHERS = 4.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    xstr = cl_bcs_convert=>solix_to_xstring(

    it_solix = contents_hex

    ).

    CALL FUNCTION 'SSFC_BASE64_ENCODE'

    EXPORTING

    bindata = xstr

    IMPORTING

    b64data = b64string

    EXCEPTIONS

    ssf_krn_error = 1

    ssf_krn_noop = 2

    ssf_krn_nomemory = 3

    ssf_krn_opinv = 4

    ssf_krn_input_data_error = 5

    ssf_krn_invalid_par = 6

    ssf_krn_invalid_parlen = 7

    OTHERS = 8.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.



    Marco

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 21, 2014 at 03:00 PM

    what you can do is converting your internal table to xstring (you will find many examples in the posts). There is a FM SCMS_BASE64_ENCODE_STR that can process xstring -> base64. Look in your system if you have it.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 25, 2014 at 08:32 AM

    Hi Bruno,

    I have seen your post about Service object attachment, I have same kind of requirement where I have to download the pdf file from invoice service object URL into Application server, Could you please help me on this with the sample code?

    Anurag

    Add comment
    10|10000 characters needed characters exceeded