‎2020 Oct 27 12:12 PM
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.
‎2020 Oct 27 12:14 PM
‎2020 Oct 27 12:28 PM
You need to use the Design Patern SingleTon
Here an example :
https://answers.sap.com/questions/12988109/how-do-we-use-singleton-in-oo-abap-can-someone-ple.html
‎2020 Oct 27 1:34 PM
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?)
‎2020 Oct 27 1:38 PM
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 ...
‎2020 Oct 27 1:35 PM
I think it would help us if you explain the real case. I don't understand what mean 1, 2 and 3...
‎2020 Oct 27 2:28 PM
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.
‎2020 Oct 27 3:02 PM
"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.
‎2020 Oct 27 3:30 PM
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.
‎2020 Oct 27 3:54 PM
‎2020 Oct 27 6:08 PM
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?
‎2020 Oct 27 7:56 PM
Is it BAdI ME_PROCESS_PO_CUST?
What are the 2 methods you use?
Or is it a secret?
‎2020 Oct 28 1:12 AM
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!
‎2020 Oct 28 6:24 AM
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
‎2020 Oct 28 6:24 AM
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.
‎2020 Nov 02 11:04 AM