Application Development 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: 

Download Invoice Attachment with method cl_binary_relation=>read_links_of_binrel

0 Kudos

Hello together,

I want to download the attachment from an invoice via method cl_binary_relation=>read_links_of_binrel.

Unfortunately I don't get any result.

I tried with the business objects BU2037, VBRK and BUS2037001 but nothing works.

Do you have any idea.

My coding is:

" Businessobjekt-ID übernehmen

gs_object-instid = gs_invoices-vbeln.

gs_object-typeid = 'BUS2037'.

gs_object-catid = 'BO'.

TRY.

" Verknüpfungen zum Objekt lesen

CALL METHOD cl_binary_relation=>read_links_of_binrel

EXPORTING

is_object = gs_object

ip_relation = 'NOTE'

IMPORTING

et_links = gt_links.

IF NOT gt_links IS INITIAL.

LOOP AT gt_links INTO gs_links WHERE typeid_b = 'MESSAGE'.

" Optional: Schlüsselkomponenten extrahieren

gs_key = gs_links-instid_b.

WRITE: / 'foltp', gs_key-foltp

, / 'folyr', gs_key-folyr

, / 'folno', gs_key-folno

, / 'objtp', gs_key-objtp

, / 'objyr', gs_key-objyr

, / 'objno', gs_key-objno

.

" Die Dokumenten-ID für SAPOffice entspricht der ermittelten

" Instanz-ID

gd_doc_id = gs_links-instid_b.

" Dokumenteninhalte löschen

CLEAR

: gt_cont

, gt_contx

.

" Dokument lesen

CALL FUNCTION 'SO_DOCUMENT_READ_API1'

EXPORTING

document_id = gd_doc_id

IMPORTING

document_data = gs_doc_data

TABLES

object_content = gt_cont

contents_hex = gt_contx

EXCEPTIONS

document_id_not_exist = 1

operation_no_authorization = 2

x_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

" Fehlerbehandlung: Lesen des Dokuments

ELSE.

" Ausgabe einiger Kopfdaten

WRITE: / gs_doc_data-object_id

, gs_doc_data-obj_type

, gs_doc_data-obj_name

, gs_doc_data-obj_descr

.

ENDIF.

SKIP.

IF NOT gt_cont[] IS INITIAL.

" Es gibt Inhalt im Textformat

WRITE: 7 'TXT'.

ENDIF.

IF NOT gt_contx[] IS INITIAL.

" Es gibt Inhalt im Binärformat

WRITE: 14 'BIN'.

ENDIF.

ENDLOOP.

ENDIF.

ENDTRY.

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

It's not "NOTE", it's "ATTA".

0 Kudos

Hi Sandra,

thanks for your comment.

But even with ATTA it does not work.

Best regards

Udo

0 Kudos

Now it's working.

Seems I tested with the wrong invoices.

Thanks Sandra!