cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger an outbound Idoc when a PR is created.

masna_7
Participant
0 Kudos
508

Hi Peers,

 

I have a requirement to trigger an outbound Idoc whenever a PR (Purchase Requisition) is created. 

Idoc types : Create : PREQCR104, Change : PREQCHANGE04.

 

I have found out that this can be achieved through a FM ALE_PR_CREATE. But, I am not sure how to achieve this. Any pseudo code or other possible ways is greatly appreciated.

 

Thanks and Regards

View Entire Topic
raymond_giuseppi
Active Contributor
0 Kudos

You can call this FM and generate an IDOC thru a BAdI such as ME_PROCESS_REQ_CUST or (better) ME_REQ_POSTED but not thru NACE (AFAIK only PO not PR - A Purchase Requistion is an internal document that is not meant to be sent externally)

You could also consider using FM MASTER_IDOC_DISTRIBUTE and not ALE_PR_CREATE or CHANGE (more threads available)

masna_7
Participant
0 Kudos

Hi Raymond, If I understood correctly, you are asking me to use FM ALE_PR_CREATE in BADI ME_REQ_POSTED ? and when all the PR details are entered in ME51N and after clicking on Save button, this FM will trigger an outbound Idoc with the details passed on to it ?

raymond_giuseppi
Active Contributor
0 Kudos
Personally, I would have called the FM MASTER_IDOC_DISTRIBUTE in the POSTED method of the BAdI ME_REQ_POSTED, but that's the general idea.
masna_7
Participant
0 Kudos

thanks for the suggestion, The Idoc has to triggered in two cases here

1. Create : trigger an Idoc when PR is Created

2. Change : Create an Idoc when PR is Changes

 

The Idea is to use FM : MASTER_IDOC_DISTRIBUTE in IF_EX_ME_REQ_POSTED~POSTED of BADI ME_REQ_POSTED. 

 

I will try to trigger an Idoc as per your suggestion and let you know the results

 

Regards,

raymond_giuseppi
Active Contributor
0 Kudos

You may also consider PR deletion (another IDOC)

Look also at FM such as

  • OWN_LOGICAL_SYSTEM_GET
  • EDI_AGREE_OUT_MESSTYPE_READ (to find port from message type and receiver)

to initialize some technical data

 

masna_7
Participant
0 Kudos
Hi Raymond, the same BAPi can be used for PR Create and PR Change ?
raymond_giuseppi
Active Contributor
0 Kudos
Yes you can use this single FM for many IDOC types (fill the field IDOCTP of parameter MASTER_IDOC_CONTROL)
masna_7
Participant
0 Kudos

Hi Raymond, what has to be updated in the communication_idoc_control parameter ? Do we pass any control data ?

 

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE
        TABLES
          communication_idoc_control     t_comm_control.

raymond_giuseppi
Active Contributor
0 Kudos
Yes, as already written fill this parameter with information on sender/receiver type and value, idoc and message types, etc.
masna_7
Participant
0 Kudos

Hi Raymond, can you please give a brief idea on what data these function module might be expecting. Because, I have tried passing different values, but, still this FM is failing with an Exception.

 

CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
        EXPORTING
          master_idoc_control            idoc_control
        TABLES
          communication_idoc_control     t_comm_control
          master_idoc_data               lt_idoc_data
        EXCEPTIONS
          error_in_idoc_control          1
          error_writing_idoc_status      2
          error_in_idoc_data             3
          sending_logical_system_unknown 4
          OTHERS                         5.

 

Regards.

raymond_giuseppi
Active Contributor
0 Kudos

There are samples in online documentation

masna_7
Participant
0 Kudos

Hi Raymond, everythings done, all the connections has been established from my end (partner functions, logical system etc., ), now the Idoc is getting triggered whenever a PR is created in the System.

the only thing that is pending now is filling the Idoc_Data.

 

I am currently using the Idoc type PREQCR104, I successfully passed the data into the first segment which is 'E1PREQCR1' which is test_run as 'X' as below :

 

       wa_idoc_data-segnam 'E1PREQCR1'.
        ls_header-testrun 'X'.
        wa_idoc_data-sdata ls_header.
        APPEND wa_idoc_data TO lt_idoc_data.
        CLEAR wa_idoc_data.
 

But, I am not getting how to pass the data into the below segments of the Idoc (lets say 'e1bpmereqheader'). If I pass the data as above, it is creating the Segment as Root but not as its child. How can I achieve this ?

masna_7_0-1730984915061.png

 

I tried to go through the link you provided, but that was not helpful. Can you please help in filling these data records ?

 

Regards,

raymond_giuseppi
Active Contributor
0 Kudos

How did you fill segnam, segnum and hlevel when filling records of MASTER_IDOC_DATA?

(If you have problem reading online help, look at the multiple MASTER_IDOC_CREATE* FM in your system)

masna_7
Participant
0 Kudos

Hi Raymond, everythings done, Now, the last thing that is remaining is to attach this Idoc to the PR in 'Relationships' of PR, any Idea or suggested content ?