Application Development and Automation 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 only

Before creating po in me21n,make attachment mandatory in dyna

former_member198180
Active Participant
0 Kudos
4,017

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

5 REPLIES 5
Read only

FredericGirod
Active Contributor
2,342

I read several time your question, but I didn't understand your issu ?

You have not the PO number ?

Read only

venkateswaran_k
Active Contributor
0 Kudos
2,342

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.
Read only

Sandra_Rossi
Active Contributor
2,342

Here's what happens if you start the creation of a purchase order via ME21N, attach a file and save (create) the purchase order:

  1. When you attach the file via the GOS service "create attachment", the attachment is saved and committed to the database, but there is no link created because the purchase order has no number yet (assigned only when it's saved). The link to the attachment is kept in memory in the private instance attribute GT_ATTACHMENTS of CL_GOS_SRV_ATTACHMENT_CREATE.
  2. When you save the purchase order:
  3. A/ There are the checks (method CHECK of BAdI ME_PROCESS_PO_CUST)
  4. B/ An automatic number is assigned to the purchase order, the GOS service is informed of this number, and consequently the GOS creates the link between the purchase order and the attachment.

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:

  1. Enhance CL_GOS_MANAGER and CL_GOS_SRV_ATTACHMENT_CREATE with a new ZZ method to return the contents of respectively GO_MODEL and GT_ATTACHMENTS. Then it's easy to call the ZZ methods to know if there is an attachment.

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.

Read only

2,342

Yes.. Simple and precise.

Read only

flowyoga
Explorer
0 Kudos
2,342

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.