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

Pass a variable value between methods in BADI

ishwarya_doss
Participant
0 Likes
4,476

Hi Experts,

I've implemented a BADI which has 2 methods. Inside the loop for every record, I need the parameter of method1 in order to set the logic in method2.

What is the best possible way to achieve that?

1. Tried creating Instance attribute to implementation class and populated it in method 1. But it's getting cleared when it comes out of method1.

2. Tried Static Attribute and it's not clearing the variable for every record in the loop.

3. Import/Export, Set/Get - What are the possible consequences of using memory ID. For example, if 2 users use the same transaction at the same time?

Kindly share your suggestions.

15 REPLIES 15
Read only

ishwarya_doss
Participant
0 Likes
3,297

@matthew.billingham

Read only

FredericGirod
Active Contributor
0 Likes
3,297
Read only

3,297

BAdI use the "instance pattern", one instance per implementation/filter (maybe I simplify a little bit...), why using "singleton"? (to transfer values between BAdI implementations?)

Read only

3,297

Yes! you are right! if it is the same Class for the badi, you don't need SingleTon, the badi should already be a singleton ...

Read only

Sandra_Rossi
Active Contributor
3,297

I think it would help us if you explain the real case. I don't understand what mean 1, 2 and 3...

Read only

ishwarya_doss
Participant
0 Likes
3,297

I need to set the status of purchase req based on a field.

One method is to modify PR before inbound - This has the field value based on which the status should be set.

Another method modify PR during inbound - This has the EBAN details where i need to set the status value based on the value of a variable i get from above method.

For doing this, I've tried creating an instance & static attributes in the implementing class. Its not working. Need your suggestions in achieving this efficiently.

Read only

matt
Active Contributor
3,297

"Not working" isn't a recognised error description!

When you tried keeping the result from the first method in an instance attribute, exactly what did you do? What was your code? And when you debugged, what happened to the value in the attribute?

Instance attribute would be the approach I'd use.

Read only

ishwarya_doss
Participant
0 Likes
3,297

Instance attribute - Z_DEPLOY Instance Attribute Public

First method -

z_deploy = is_ibp_order_output-deployment.

Second method

IF z_deploy = 'X'.
      cs_eban-statu = 'D'.
    ENDIF.

Z_deploy was set to X in first method but got cleared when it came out of the method.
Read only

FredericGirod
Active Contributor
0 Likes
3,297

Are you sure you are in the same instance of the badi ?

Read only

ishwarya_doss
Participant
0 Likes
3,297

So, the standard program has a global object . But multiple get badi and call badi statements which means its not in the same instance and hence the variable is getting cleared, Am i right? So , will export import be a good solution?

Read only

Sandra_Rossi
Active Contributor
0 Likes
3,297

Is it BAdI ME_PROCESS_PO_CUST?

What are the 2 methods you use?

Or is it a secret?

Read only

ishwarya_doss
Participant
0 Likes
3,297

Sure. To update purchase requisition data sent back from IBP to an SAP ERP system using the BAdI /IBP/ECC_MODIFY_PREQ. -modify preq and modify preq before in methods

Using this option as SAP note 2803585 cannot be implemented for the version we use.

Thanks!

Read only

FredericGirod
Active Contributor
3,297

In debug you check the instance of the Badi is not the same ?

Because my_badi->modify_preq and my_badi->modify_preq_before should used the same instance

So

  1. If it is the same instance, you don't need anything, just used a global (private) variable
  2. if it is not the same instance, but the same LUW: you could use Design Pattern SingleTon
  3. If it is not the same instance, not the same LUW, but the same transaction: you could used SHMA
  4. If it is not the same instance, same LUW, same transaction: there is no simple and strong solution
Read only

Sandra_Rossi
Active Contributor
3,297

Thanks.

I don't have SCM but I guess that the method MODIFY_PREQ runs in the "main session" and MODIFY_PREQ_BEFORE_SAVE runs in the update task (it's another User Session), so they cannot communicate except by passing parameters via CALL FUNCTION ... IN UPDATE TASK, because all these calls are executed in the same update task (same User Session/same memory).

You may create your own Z update function module, do an Implicit Enhancement of the standard to run before the first update function module is called, from which you call your Z update function module and pass the parameter(s) you want. In the Z function group, you may define a global variable (or, if you prefer, create a Z class pool, an instance attribute and work with it through a singleton), that you use to store the parameter, and read it later from the method MODIFY_PREQ_BEFORE_SAVE.

Read only

ishwarya_doss
Participant
0 Likes
3,297

Thanks everyone for your suggestions!