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: 

BDC in User Exit

Former Member
0 Kudos

Dear Gurus,

I have one requirement in user exit while saving the Process Order in COR1.

I want to run a BDC Call Transaction Method in the User Exit include "ZXCO1U06" to store the Condition Records for the new Batch created in VK11.

When i write the code in this include, it gives me an error of FORM, ENDFORM.

Can anyone please help me out with this?

Thanks,

Praveen

21 REPLIES 21

Sridharnekkanti
Active Participant
0 Kudos

First record the COR1 transaction. After that copy & manipulate the related required code of the recording & use in your user exit.

0 Kudos

Hi Sridhar,

I know that we have to a recording and include that code in COR1 user exit.

But when i try to include that code which has FORM and PERFORM in it, then it gives me error as the include code is inside a function module.

Can you please let me know any other solutions for this?

Thanks,

Praveen

Sandra_Rossi
Active Contributor
0 Kudos

You can't write a routine inside the ZXCO1U07 include, as it is embedded in FUNCTION ... ENDFUNCTION. So, just put your form in another include, like ZXC01F01 (you have to create it), that SAP should propose to refer from SAPLXCO1 (i.e. the XCO1 function group).

0 Kudos

Hi Sandra,

Thanks for the reply.

I will create a new include and write the BDC code in that as per your suggestion.

Now, can you please let me know how should i link that new include with the Save event of COR1 transaction.

I am not able to understand your second point.

Can you please clarify this in more details?

Thanks,

Praveen

0 Kudos

SAPLXCO1 contains:


  include lxco1top.      " Global Data
  include lxco1uxx.      " Function Modules
  include lxco1f00.      " SAP-Formpool for Customer-Use
  include zxco1zzz.      " Subprograms and Modules

So, you create include zxco1zzz by double-clicking it, and add your routine in it:


FORM your_routine. "add the parameters you want
* ...
ENDFORM.

You implement zxco1u06 like this:


perform your_routine. "add the parameters you want

For information, EXIT_SAPLCOZV_001 function module contains:


FUNCTION EXIT_SAPLCOZV_001.
  include zxco1u06 .
ENDFUNCTION.

0 Kudos

Dear Sandra,

Your answer was very helpfull to me.

I will try to complete my requirement now and will get back to you if i have any further queries.

Thanks,

Praveen

0 Kudos

Hi Sandra,

I am able to run the BDC while saving the Process Order.

But the big problem i am facing in this is, when i run the bdc for creating the Condition Records in VK11 for the new batch that will be created when i save the process order it gives me an error.

The reason for this error is, the batch that i create during COR1 get saved in MCH1,MCHA etc. tables once i save the process order.

Now i have written the BDC code at the below location.

Exit = PPCO0007 - Exit when saving production order

Function Module = EXIT_SAPLCOZV_001

Include = ZXCO1U06

Until this point the batch is not created in the tables, when i use the same batch number in VK11 for creating the condition records it gives me an error as below.

" Object Batch not provided with characteristic 0000102345. (Note other fields!) ".

Can you tell me how should i handle this?

Thanks in advance,

Praveen

0 Kudos

Hi Praveen,

Check whether there is any other user exit, badi or enhacment. which will be hit after saving the process order.

Thanks

kamath

0 Kudos

Hi Kamath,

Can you please tell me how should i search for those after the Process Order is saved?

Thanks,

Praveen

0 Kudos

Hi,

Create the Function module with processing type as "Update Module" and Write your BDC code inside this function module. Call this function module in Update Task within the user exit mentioned by you.

This SDN blog may be helpful for you. [Calling a BDC in parallel using update task|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/16558] [original link is broken] [original link is broken] [original link is broken];

Regards

Vinod

0 Kudos

Hi Vinod,

Thanks for replying.

The link which you provided is a bit confusing to me.

Can you please tell me the steps for achieving this?

Thanks,

Praveen

0 Kudos

Hi Praveen,

Check the user exit or badi required from spro transaction where it gives when the badi or exit will be called in the transaction.

Thanks

Kamath

0 Kudos

Hi Kamath,

I have got the User Exit that will be called when Saving the Production Order which is "EXIT_SAPLCOZV_001".

Now i want to run a BDC for storing the condition records in VK11 for the new batch that will be created once we save the Process Order.

When i write the BDC code in the above Exit, then it gives me an error as the batch is still not created till this time.

So, i want to run a BDC immidiately after the Batch and Process Order are created.

Can you please help me with this?

Thanks,

Praveen

0 Kudos

Hi,

As mentioned in my earlier post,

Create the Function module with processing type as "Update Module" and Write your BDC code inside this function module. Call this function module in Update Task (CALL FUNCTION '<function module name>' IN UPDATE TASK) within the user exit mentioned by you.

Regards

Vinod

0 Kudos

Hi Vinod,

I have created an Update Function Module with the below structure.

function zisd_call_transaction.

*"----


""Update Function Module:

*"

""Local Interface:

*"----


perform zxco1zzz_include.

endfunction.

I do not have any Import, Export, Tables Parameteres specified for this FM.

I have written the BDC code in the perform written in this FM, i.e. "zxco1zzz_include".

I am calling this function module in the include "ZXCO1U01" as below.

call function 'ZISD_CALL_TRANSACTION' IN UPDATE TASK.

.

The location of thi include i.e. zxco1u01 is as below.

Function Module = EXIT_SAPLCOBT_001

Enhancement = PPCO0001

My Update FM is not being executed, how should i execute my update FM?

Can youp please help me with this?

Thanks,

Praveen

0 Kudos

Hi,

Hope your code for BDC recording is within the function module. Put the Breakpoint inside the function module, Execute the standard transaction which calls the Enhancement mentioned by you. Activate [Update Debugging|; so that the control will stop in the breakpoint inside the function module.

Regards

Vinod

0 Kudos

Hi Vinod,

The control does stop in my FM while calling the standard TCode.

But, as i said initially i want to creat the Pricing Condition Records in VK11 using BDC for the new Batch that is being created in COR1 whenever i save the new process order.

My BDC does get called, but when i try to create the Pricing Condition Records for that new batch it gives me an error as below.

*****************************************************************************************************

Object Batch not provided with characteristic 0000102369. (Note other

fields!)

Message no. VK432

Diagnosis

The value entered in a field is not permitted.

System Response

The system issues an error message.

Procedure

Check the entry and make the necessary corrections. Note any

relationships between the individual fields. Entries in other fields may

also be incorrect.

Example: There are two fields for maintaining the country and region.

These fields are linked. The country chosen would be permitted if it

were by itself. So would the region. But the region may not be in the

the country chosen. In this case, an error message is issued. The

country should then be corrected, not the region!

*****************************************************************************************************

The Batch for which we are creating Condition Records in VK11 is still not created in DB Tables and thats why it gives me an error.

So, how should i handle this?

Thanks,

Praveen

Former Member
0 Kudos

Try implementing BADI: WORKORDER_UPDATE. This BADI have method like: at_save, at_release, before_update*.

Also my vote to go with z-function module w/attr update task checked and write your BDC code here.

Good luck!

0 Kudos

I have to do 2 comments about these remarks from Vinod and Vikash::

>

> Create the Function module with processing type as "Update Module" and Write your BDC code inside this function module. Call this function module in Update Task (CALL FUNCTION '<function module name>' IN UPDATE TASK) within the user exit mentioned by you.

>

> Also my vote to go with z-function module w/attr update task checked and write your BDC code here.

1) SAP forbides to use CALL TRANSACTION in an asynchronous update task (dump POSTING_ILLEGAL_STATEMENT), and it is really dangerous to use it in a local/synchronous (set update task local) update task (SAP doesn't dump in that case, incredible! ) as it would commit updates of preceding update function modules, while successor update function modules could fail and a rollback couldn't do its expected job. So advising to use BDC (which does updates) inside an update task is not a very good idea

2) A better idea, is to start the BDC after all the updates of COR1 have been committed.

As user exits are usually called before the database commit (I don't know if one of the methods of WORKORDER_UPDATE BAdI is executed after), we need to postpone the execution by "registering" the BDC call in the user exit, by the use of tRFC (transactional RFC). The tRFC are always called after all the update (task) function modules.

So, you must create an RFC-enabled function module which contains the CALL TRANSACTION, and call the function module this way::


CALL FUNCTION 'Z...' IN BACKGROUND TASK (DESTINATION 'NONE') AS SEPARATE UNIT.

You must use AS SEPARATE UNIT in case another tRFC with NONE destination is executed, because a BDC must run in its own LUW.

Another important thing: If the BDC fails, it is impossible to rollback COR1 updates. You can recover the failed BDCs using SM58 transaction.

Don't use asynchronous (aRFC/pRFC) or synchronous RFC (sRFC) instead of tRFC, that wouldn't work. You might use qRFC, bgRFC, but it's more complex and there's no advantage in this situation.

Note that the update function module (call in update task) is useless.

You might avoid the tRFC by calling the BDC inside the TRANSACTION_FINISHED event of the system class CL_SYSTEM_TRANSACTION_STATE, but you would have then to develop a recovery function, while the tRFC has already one.

Don't hesitate to correct me if I'm wrong or if you have other tricks to run a BDC from a user exit at save time.

Edited by: Sandra Rossi on Aug 2, 2010 6:50 PM (I made a little confusion in point 1, about the dump cause of a CALL TRANSACTION in an update task (I initially said that the cause was COMMIT WORK, which is wrong as we don't even reach it in that scenario; nevertheless, it's true that a COMMIT WORK causes a COMMIT_IN_POSTING dump in an update task)

0 Kudos

Dear Gurus,

I have solved this problem at my end.

Thanks a lot for all your comments and help on this.

Thanks,

Praveen

Former Member
0 Kudos

Forgot to tell you that you can also create z-function module with out or with update task attr checked and call function using RFC (with destination option, RFC to same system).

Let me know if that works for you or not?