‎2013 Feb 25 12:29 PM
Hello Gurus,
My requirement is to create PO with attachment through BAPI calling. I am able to create PO through BAPI "BAPI_PO_CREATE1" .
Now I need to send attachment to the PO while creating. This file will be uploaded through BSP page at the time when we are providing the inputs for creating the PO. This attachment should be seen in TCode ME23n/ME22n .
Can I use the same BAPI to send attachment to the PO. Please let me know. I have checked SDN but didn't get any relevant answer.
Thanks.
‎2013 Feb 25 12:39 PM
‎2013 Feb 26 6:14 AM
Hi Santanu, Thanks for your reply.
I have checked this thread. Program explained in this thread is creation PO through excel. Although there is another reply saying make any attachment after creating PO through "BAPI_PO_CREATE1" , but this link is not active now.
My requirement is to attach any document like PDF file to the PO once it is created through BAPI.
just select the file and give input for the PO need to be created through legacy system and call BAPI to create PO at SAP. This attachment should must be seen in the ME23N attachment for the PO.
Please help me on this.
Waiting for reply.
‎2013 Feb 26 7:09 AM
You will have to use GOS to create attachments. Please search in scn for more details
Try to check it with a sample program
INCLUDE cntn01_swc.
TYPES: BEGIN OF ty_message_key,
foltp TYPE so_fol_tp,
folyr TYPE so_fol_yr,
folno TYPE so_fol_no,
doctp TYPE so_doc_tp,
docyr TYPE so_doc_yr,
docno TYPE so_doc_no,
fortp TYPE so_for_tp,
foryr TYPE so_for_yr,
forno TYPE so_for_no,
END OF ty_message_key.
DATA:lv_xfname TYPE string,
lv_xdoctype TYPE sofm-doctp,
lv_xmessage TYPE swc0_object,
ls_xmessage_key TYPE ty_message_key,
lv_xdoctitle TYPE string.
DATA:lv_ename TYPE char255,
lv_ext TYPE char255.
DATA:lv_xobject_b TYPE borident,
lv_xobject_a TYPE borident.
CALL FUNCTION 'SO_TSOPE_CHECK'
EXPORTING
file_ext = lv_xtention "Extension of file
query = 'CREA'
IMPORTING
file_type = lv_file_type
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc = 0.
lv_f_type = lv_file_type.
ELSE.
lv_f_type = 'BIN'.
ENDIF.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file_full "Full path of file
filetype = lv_f_type
IMPORTING
filelength = lv_file_length
TABLES
data_tab = lt_doc_content
EXCEPTIONS
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 RAISING failed.
ENDIF.
lv_xobject_a-objkey = '0000000000'" Place purchase order no
lv_xfname = lv_ename. "File path + name without extension
lv_xdoctype = lv_ext. "File extension
TRANSLATE lv_xdoctype TO UPPER CASE.
lv_xdoctitle = lv_xfname. "Title
swc0_create_object lv_xmessage 'MESSAGE' ls_xmessage_key.
swc0_set_element lcl_swc=>swo_container 'DOCUMENTTITLE' lv_xfname.
swc0_set_element lcl_swc=>swo_container 'DOCUMENTLANGU' 'E'.
swc0_set_element lcl_swc=>swo_container 'NO_DIALOG' 'X'.
swc0_set_element lcl_swc=>swo_container 'DOCUMENTNAME' 'MESSAGE'.
swc0_set_element lcl_swc=>swo_container 'DOCUMENTTYPE' lv_xdoctype.
swc0_set_table lcl_swc=>swo_container 'DocumentContent' lt_doc_content.
swc0_set_element lcl_swc=>swo_container 'DOCUMENTSIZE' lv_file_length.
swc0_refresh_object lv_xmessage.
swc0_call_method lv_xmessage 'CREATE' lcl_swc=>swo_container.
swc0_get_object_key lv_xmessage ls_xmessage_key.
lv_xobject_a-objtype = 'BUS2012' "Po business object
lv_xobject_b-objkey = ls_xmessage_key.
lv_xobject_b-objtype = 'MESSAGE'.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = lv_xobject_a
obj_roleb = lv_xobject_b
relationtype = 'ATTA'
EXCEPTIONS
OTHERS = 1.
IF sy-subrc EQ 0.
COMMIT WORK.
ENDIF.