2020 Mar 18 11:34 AM
Good Day Team,
I have a requriement in which while creating PO in ME21N at least one document should be attached to that PO. If there is no Document attached,At the time of check and save i need to show an error message .
I have find one URL like as below,But idid not get any solution here,
https://answers.sap.com/questions/9991690/how-to-make-document-attachment-mandatory-for-po-c.html
I was implemented code like as below,but ididnt get any attachment before save and check .
* DATA:gs_lporb TYPE sibflporb,
* lt_links TYPE obl_t_link.
* gs_lporb-instid = lw_header_data-ebeln.
* gs_lporb-typeid = 'BUS2012'.
* gs_lporb-catid = 'BO'.
*
* CALL METHOD cl_binary_relation=>read_links_of_binrel
* EXPORTING
* is_object = gs_lporb
* ip_relation = 'ATTA'
* ip_role = 'GOSAPPLOBJ'
* IMPORTING
* et_links = lt_links.
Can you please help us how to implement this?where i need to implement the logic?
for quick resolution,highly appreciated.
Thanks & Reagrds
Kalpana
2020 Mar 18 11:44 AM
I read several time your question, but I didn't understand your issu ?
You have not the PO number ?
2020 Mar 20 6:07 PM
Hi Kalpana
Please implement the code here at the time of validation (Hope you are using BADI/Exit at the time of save)
We are using GOS Manager object - calling the method start_service_direct to get the list of attachments. If no attachments then sy-subrc will not be zero.
Please note that - here you need to pass the document number (which may not be generated at the time of exit.place..)
DATA: OBJTYPE TYPE BORIDENT-OBJTYPE VALUE 'ABCD'. "your object NAME
DATA: manager TYPE REF TO cl_gos_manager,
OBJ TYPE BORIDENT.
OBJ-OBJTYPE = OBJTYPE.
OBJ-OBJKEY = <document_number>.
CREATE OBJECT manager
EXPORTING
ip_no_commit = 'R'
EXCEPTIONS
OTHERS = 1.
CALL METHOD manager->start_service_direct
EXPORTING
ip_service = 'VIEW_ATTA'
is_object = obj
EXCEPTIONS
no_object = 1
object_invalid = 2
execution_failed = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE 'No object found' TYPE 'S'.
ENDIF.
2020 Mar 20 10:47 PM
Here's what happens if you start the creation of a purchase order via ME21N, attach a file and save (create) the purchase order:
If you get the GOS manager instance in the method CHECK as explained in the link you have provided, you should also find a way to query the attribute GT_ATTACHMENTS, that's not easy because you don't know the instance of CL_GOS_SRV_ATTACHMENT_CREATE, and the attribute is private.
The instance of this latter class can be obtained only if you can read the attribute GO_MODEL of the GOS manager, but it's a protected attribute.
So, I see just one solution:
Example of code in CHECK (I let you create the two ZZ methods):
if IM_HEADER is instance of CL_PO_HEADER_HANDLE_MM.
data(header2) = cast CL_PO_HEADER_HANDLE_MM( im_header ).
data(gos) = header2->get_gos_manager( ).
data(gos_model) = gos->zz_get_model( ).
data(gos_pcatta_crea) = gos_model->get_service_by_name( 'PCATTA_CREA' ).
data(attachments) = gos_pcatta_crea->zz_get_attachments( ).
" checks on attachments
endif.
Good luck!
NB: there are probably other ways to do it, maybe more simple, but it's the first one which came up to my mind.
2020 Mar 21 5:55 AM
2020 Sep 29 6:31 AM
gos_model->get_service_by_name does not returning parameter,there is only one Exporting structure "ES_SERVICE",how can i get CL_GOS_SRV_ATTACHMENT_CREATE-zz_get_attachments
My code
IF IM_HEADER IS INSTANCE OF CL_PO_HEADER_HANDLE_MM.
DATA(HEADER2) = CAST CL_PO_HEADER_HANDLE_MM( IM_HEADER ).
DATA(GOS) = HEADER2->GET_GOS_MANAGER( ).
DATA(GOS_MODEL) = GOS->ZZ_GET_MODEL( ).
CALL METHOD GOS_MODEL->GET_SERVICE_BY_NAME
EXPORTING
IP_SERVICE_NAME = 'PCATTA_CREA'
IMPORTING
ES_SERVICE = DATA(GOS_PCATTA_CREA)
EXCEPTIONS
SERVICE_NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
ENDIF.
ENDIF.