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: 

Read PO attachments

Former Member
0 Kudos

Hi,

I have a requirement to read Purchase Order attachments and e-mail them.

Is there a FM to read the attachemnts with the document number as input? or is there any other way to do it?

Thanks,

K.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The following program may get you started.

It displays attached notes and lets the user click to display attached Word, Excel etc.

REPORT YJNM_DISPLAY_GOS_NOTES.

  • Displays contents of notes attached to a business object.

  • Displays header info for attached files, and displays the

  • attached files via drill-down.

parameters:

p_botype like tojtb-name default 'BUS2080', " e.g. 'BUS2012'

p_bo_id like borident-objkey default '000200000591'.

data:

msg(80) type c,

ntext like tojtt-ntext,

folder_id type soodk,

object_id like soodk,

object_hd_display type sood2,

objects like table of sood5,

rf type ref to CL_GOS_DOCUMENT_SERVICE,

is_object type sibflporb,

et_links type obl_t_link,

et_links_s type obl_s_link,

document type sood4,

header_data type sood2,

icx_obl_parameter_error type ref to cx_obl_parameter_error,

icx_obl_internal_error type ref to cx_obl_internal_error,

icx_obl_model_error type ref to cx_obl_model_error,

header_row type solisti1,

content_row type solisti1,

object_header like table of header_row,

object_content like table of content_row,

document_data type sofolenti1,

subline like content_row,

subline_fragment like subline-line,

subline_temp like subline,

sublines like table of subline,

all_sublines like table of subline,

document_id type sofOlenti1-doc_id,

exception_string type string.

include:

<icon>,

RSSOCONS.

*include <CNTN01>.

----


at line-selection.

check not document is initial.

CALL FUNCTION 'SO_DYNP_DOCUMENT_DISPLAY'

EXPORTING

OBJECTS = document.

----


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

----


start-of-selection.

class CL_GOS_DOCUMENT_SERVICE definition load.

create object rf.

----


is_object-instid = p_bo_id.

is_object-typeid = p_botype.

is_object-catid = 'BO'.

perform:

header,

notes,

attachments.

----


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

----


FORM notes .

  • find links to the notes

try.

call method cl_binary_relation=>read_links_of_binrel

exporting

is_object = is_object

ip_relation = 'NOTE'

importing

et_links = et_links.

catch cx_obl_parameter_error into icx_obl_parameter_error.

exception_string = icx_obl_parameter_error->get_longtext( ).

catch cx_obl_internal_error into icx_obl_internal_error .

exception_string = icx_obl_internal_error->get_longtext( ).

catch cx_obl_model_error into icx_obl_model_error.

exception_string = icx_obl_model_error->get_longtext( ).

endtry.

----


  • use the links to where the notes are stored

sort et_links by utctime.

loop at et_links into et_links_s.

at first.

format reset.

format color col_total.

skip.

write: / 'Note(s):'.

endat.

  • get the data for a note

refresh all_sublines.

document_id = et_links_s-instid_b .

CALL FUNCTION 'SO_DOCUMENT_READ_API1'

EXPORTING

DOCUMENT_ID = document_id

IMPORTING

DOCUMENT_DATA = document_data

TABLES

OBJECT_HEADER = object_header

OBJECT_CONTENT = object_content.

  • display a header for the note

format reset.

skip.

format color col_heading.

write: /3 'Note description:',

document_data-obj_descr,

/3 'Created by:',

document_data-creat_name,

document_data-creat_fnam,

'Last changed:',

document_data-chang_date.

  • interpret and display the note contents

format reset.

clear subline_fragment.

  • EOL (end of line) in the table object_content has nothing to do

  • with EOL for the note.

  • The table object_content is just a stream of characters - including

  • embedded CRLFs (carriage return & line feed) - that happens to be

  • 255-character rows.

loop at object_content into content_row.

  • split content row at embedded CRLFs

split content_row-line

at cl_abap_char_utilities=>cr_lf into table sublines.

loop at sublines into subline.

  • store in subline_temp for full visibility within AT/ENDAT

subline_temp = subline.

at first.

  • subline_fragment from end of previous content_row needs to be

  • stuck on to the first subline of this content_row

concatenate subline_fragment subline_temp-line

into subline_temp-line.

endat.

at last.

  • final subline may not be a complete line of the note -

  • so save it to use with beginning of next content_row

subline_fragment = subline_temp-line.

exit.

endat.

  • if we reach here, subline_temp will be a complete note-line

append subline_temp to all_sublines.

endloop.

endloop.

subline-line = subline_fragment.

append subline to all_sublines.

loop at all_sublines into subline.

write: /3 subline-line.

endloop.

endloop.

ENDFORM. " notes

----


FORM attachments .

  • find links to attachments

refresh et_links.

try.

call method cl_binary_relation=>read_links_of_binrel

exporting

is_object = is_object

ip_relation = 'ATTA'

importing

et_links = et_links.

catch cx_obl_parameter_error into icx_obl_parameter_error.

exception_string = icx_obl_parameter_error->get_longtext( ).

catch cx_obl_internal_error into icx_obl_internal_error .

exception_string = icx_obl_internal_error->get_longtext( ).

catch cx_obl_model_error into icx_obl_model_error.

exception_string = icx_obl_model_error->get_longtext( ).

endtry.

----


  • use the links to where the attachments are stored

sort et_links by utctime.

loop at et_links into et_links_s.

at first.

skip.

format reset.

format color col_total.

write: / 'Attachment(s):'.

endat.

document-foltp = et_links_s-instid_b+0(3).

document-folyr = et_links_s-instid_b+3(2).

document-folno = et_links_s-instid_b+5(12).

document-objtp = et_links_s-instid_b+17(3).

document-objyr = et_links_s-instid_b+20(2).

document-objno = et_links_s-instid_b+22(12).

folder_id-objtp = document-foltp.

folder_id-objyr = document-folyr.

folder_id-objno = document-folno.

move-corresponding document to object_id.

CALL FUNCTION 'SO_OBJECT_READ'

EXPORTING

FOLDER_ID = folder_id

OBJECT_ID = object_id

IMPORTING

OBJECT_HD_DISPLAY = object_hd_display

EXCEPTIONS

ACTIVE_USER_NOT_EXIST = 1

COMMUNICATION_FAILURE = 2

COMPONENT_NOT_AVAILABLE = 3

FOLDER_NOT_EXIST = 4

FOLDER_NO_AUTHORIZATION = 5

OBJECT_NOT_EXIST = 6

OBJECT_NO_AUTHORIZATION = 7

OPERATION_NO_AUTHORIZATION = 8

OWNER_NOT_EXIST = 9

PARAMETER_ERROR = 10

SUBSTITUTE_NOT_ACTIVE = 11

SUBSTITUTE_NOT_DEFINED = 12

SYSTEM_FAILURE = 13

X_ERROR = 14

OTHERS = 15.

IF SY-SUBRC eq 0.

skip.

format color col_heading.

write: /3 icon_display as icon hotspot,

object_hd_display-objdes,

object_hd_display-file_ext.

hide document.

write: /3 'Created by:',

object_hd_display-cronam,

object_hd_display-croadr,

'Last changed:',

object_hd_display-chdat.

hide document.

else.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear document. "in case of drill-down

endloop.

ENDFORM. " attachments

----


FORM header .

select single ntext

from tojtt

into ntext

where

name = p_botype and

language = sy-langu.

if sy-subrc eq 0.

format reset.

format color col_positive.

write: / 'Business object:',

20 ntext.

write: / 'Key:',

20 p_bo_id.

else.

concatenate 'Business-object type' p_botype 'not found.'

into msg separated by space.

write: / msg.

endif.

ENDFORM. " header

For a purchase order, the business-object type is BUS2012,

and the business-object key is just the document number (internal format).

John

11 REPLIES 11

Former Member
0 Kudos

Hi,

The following program may get you started.

It displays attached notes and lets the user click to display attached Word, Excel etc.

REPORT YJNM_DISPLAY_GOS_NOTES.

  • Displays contents of notes attached to a business object.

  • Displays header info for attached files, and displays the

  • attached files via drill-down.

parameters:

p_botype like tojtb-name default 'BUS2080', " e.g. 'BUS2012'

p_bo_id like borident-objkey default '000200000591'.

data:

msg(80) type c,

ntext like tojtt-ntext,

folder_id type soodk,

object_id like soodk,

object_hd_display type sood2,

objects like table of sood5,

rf type ref to CL_GOS_DOCUMENT_SERVICE,

is_object type sibflporb,

et_links type obl_t_link,

et_links_s type obl_s_link,

document type sood4,

header_data type sood2,

icx_obl_parameter_error type ref to cx_obl_parameter_error,

icx_obl_internal_error type ref to cx_obl_internal_error,

icx_obl_model_error type ref to cx_obl_model_error,

header_row type solisti1,

content_row type solisti1,

object_header like table of header_row,

object_content like table of content_row,

document_data type sofolenti1,

subline like content_row,

subline_fragment like subline-line,

subline_temp like subline,

sublines like table of subline,

all_sublines like table of subline,

document_id type sofOlenti1-doc_id,

exception_string type string.

include:

<icon>,

RSSOCONS.

*include <CNTN01>.

----


at line-selection.

check not document is initial.

CALL FUNCTION 'SO_DYNP_DOCUMENT_DISPLAY'

EXPORTING

OBJECTS = document.

----


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

----


start-of-selection.

class CL_GOS_DOCUMENT_SERVICE definition load.

create object rf.

----


is_object-instid = p_bo_id.

is_object-typeid = p_botype.

is_object-catid = 'BO'.

perform:

header,

notes,

attachments.

----


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

----


FORM notes .

  • find links to the notes

try.

call method cl_binary_relation=>read_links_of_binrel

exporting

is_object = is_object

ip_relation = 'NOTE'

importing

et_links = et_links.

catch cx_obl_parameter_error into icx_obl_parameter_error.

exception_string = icx_obl_parameter_error->get_longtext( ).

catch cx_obl_internal_error into icx_obl_internal_error .

exception_string = icx_obl_internal_error->get_longtext( ).

catch cx_obl_model_error into icx_obl_model_error.

exception_string = icx_obl_model_error->get_longtext( ).

endtry.

----


  • use the links to where the notes are stored

sort et_links by utctime.

loop at et_links into et_links_s.

at first.

format reset.

format color col_total.

skip.

write: / 'Note(s):'.

endat.

  • get the data for a note

refresh all_sublines.

document_id = et_links_s-instid_b .

CALL FUNCTION 'SO_DOCUMENT_READ_API1'

EXPORTING

DOCUMENT_ID = document_id

IMPORTING

DOCUMENT_DATA = document_data

TABLES

OBJECT_HEADER = object_header

OBJECT_CONTENT = object_content.

  • display a header for the note

format reset.

skip.

format color col_heading.

write: /3 'Note description:',

document_data-obj_descr,

/3 'Created by:',

document_data-creat_name,

document_data-creat_fnam,

'Last changed:',

document_data-chang_date.

  • interpret and display the note contents

format reset.

clear subline_fragment.

  • EOL (end of line) in the table object_content has nothing to do

  • with EOL for the note.

  • The table object_content is just a stream of characters - including

  • embedded CRLFs (carriage return & line feed) - that happens to be

  • 255-character rows.

loop at object_content into content_row.

  • split content row at embedded CRLFs

split content_row-line

at cl_abap_char_utilities=>cr_lf into table sublines.

loop at sublines into subline.

  • store in subline_temp for full visibility within AT/ENDAT

subline_temp = subline.

at first.

  • subline_fragment from end of previous content_row needs to be

  • stuck on to the first subline of this content_row

concatenate subline_fragment subline_temp-line

into subline_temp-line.

endat.

at last.

  • final subline may not be a complete line of the note -

  • so save it to use with beginning of next content_row

subline_fragment = subline_temp-line.

exit.

endat.

  • if we reach here, subline_temp will be a complete note-line

append subline_temp to all_sublines.

endloop.

endloop.

subline-line = subline_fragment.

append subline to all_sublines.

loop at all_sublines into subline.

write: /3 subline-line.

endloop.

endloop.

ENDFORM. " notes

----


FORM attachments .

  • find links to attachments

refresh et_links.

try.

call method cl_binary_relation=>read_links_of_binrel

exporting

is_object = is_object

ip_relation = 'ATTA'

importing

et_links = et_links.

catch cx_obl_parameter_error into icx_obl_parameter_error.

exception_string = icx_obl_parameter_error->get_longtext( ).

catch cx_obl_internal_error into icx_obl_internal_error .

exception_string = icx_obl_internal_error->get_longtext( ).

catch cx_obl_model_error into icx_obl_model_error.

exception_string = icx_obl_model_error->get_longtext( ).

endtry.

----


  • use the links to where the attachments are stored

sort et_links by utctime.

loop at et_links into et_links_s.

at first.

skip.

format reset.

format color col_total.

write: / 'Attachment(s):'.

endat.

document-foltp = et_links_s-instid_b+0(3).

document-folyr = et_links_s-instid_b+3(2).

document-folno = et_links_s-instid_b+5(12).

document-objtp = et_links_s-instid_b+17(3).

document-objyr = et_links_s-instid_b+20(2).

document-objno = et_links_s-instid_b+22(12).

folder_id-objtp = document-foltp.

folder_id-objyr = document-folyr.

folder_id-objno = document-folno.

move-corresponding document to object_id.

CALL FUNCTION 'SO_OBJECT_READ'

EXPORTING

FOLDER_ID = folder_id

OBJECT_ID = object_id

IMPORTING

OBJECT_HD_DISPLAY = object_hd_display

EXCEPTIONS

ACTIVE_USER_NOT_EXIST = 1

COMMUNICATION_FAILURE = 2

COMPONENT_NOT_AVAILABLE = 3

FOLDER_NOT_EXIST = 4

FOLDER_NO_AUTHORIZATION = 5

OBJECT_NOT_EXIST = 6

OBJECT_NO_AUTHORIZATION = 7

OPERATION_NO_AUTHORIZATION = 8

OWNER_NOT_EXIST = 9

PARAMETER_ERROR = 10

SUBSTITUTE_NOT_ACTIVE = 11

SUBSTITUTE_NOT_DEFINED = 12

SYSTEM_FAILURE = 13

X_ERROR = 14

OTHERS = 15.

IF SY-SUBRC eq 0.

skip.

format color col_heading.

write: /3 icon_display as icon hotspot,

object_hd_display-objdes,

object_hd_display-file_ext.

hide document.

write: /3 'Created by:',

object_hd_display-cronam,

object_hd_display-croadr,

'Last changed:',

object_hd_display-chdat.

hide document.

else.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear document. "in case of drill-down

endloop.

ENDFORM. " attachments

----


FORM header .

select single ntext

from tojtt

into ntext

where

name = p_botype and

language = sy-langu.

if sy-subrc eq 0.

format reset.

format color col_positive.

write: / 'Business object:',

20 ntext.

write: / 'Key:',

20 p_bo_id.

else.

concatenate 'Business-object type' p_botype 'not found.'

into msg separated by space.

write: / msg.

endif.

ENDFORM. " header

For a purchase order, the business-object type is BUS2012,

and the business-object key is just the document number (internal format).

John

0 Kudos

Greed

Former Member
0 Kudos

Hi John,

I have executed your program but it is not diplaying the document attachments.

I am using the business-object type as BUS2012 and the business-object key as the purchase order number. I have attached some documents at the line item level, but cannot find them in the output. Any suggestions?

thanks,

K.

Former Member
0 Kudos

Hi John,

The program is working for attachments that are attached at the header level.

I also want to get the attachments at the line item level. However these attachments are coming from a different table - (DRAW - Document info records). Is there a way to retrieve these attachments. Like a FM?

Thanks,

K.

Former Member
0 Kudos

Kiran,

Hmmm.

The program works for me for purchase orders.

Are notes being displayed OK?

Is your document number 10 characters, with leading zeros if necessary?

John

Former Member
0 Kudos

John,

The program is working for attachments at the header level of the PO (The small button for attachements at the top beside the Document Overview On button).

However, in the PO we can also add attachments at the line item level. You can see an attachment button at the line item detail level box. I wanna read these attachemnts too. Looks to me these attachments are stored as Document Info records in table DRAW.

thanks, K.

Former Member
0 Kudos

Kiran,

I don't know about DRAW.

There is, however, a business-object type called DRAW.

Perhaps that's what you need.

If so, then you'll need to figure out how to set up the business-object key.

If this is for a line item, then try simply the document number concatenated with the item number (again, internal values).

John

Former Member
0 Kudos

Kiran,

You've got me interested now.

How do you attach to a PO line-item?

Perhaps it can't be done on our system.

John

Former Member
0 Kudos

John,

You can see an attachment button under the Item overview box of the PO. You can add Document info records as attachments to the line item.

These records are stored in DRAW table. We create document info records using cv01n.

The link between an object and the document info record is stored in DRAD table. with the object key as the material number if the document info record is attached to a material or the object key can be document number + line item (internal) if the attachment is attached to the PO line item.

There are BAPI's associated with this object - DRAW. You can search for BAPI_DOCUMENT*.

I am trying to get the attached documents for every PO and e-mail them to the vendor along with the PO. I hope it makes sense to you..

Thanks,

K.

Former Member
0 Kudos

Kiran,

Thanks.

Sorry, but it's not something that we use.

So can't help any more.

All the best,

John

0 Kudos

This message was moderated.