cancel
Showing results for 
Search instead for 
Did you mean: 

Calling RFCs in Java WebDynpro

Former Member
0 Kudos

Hello Experts,

I'm new to WebDynpro. I'm a novice at best and have just learned the basics. I'll probably be asking a lot of questions about this soon. Here is one problem I recently encountered:

I managed to call RFCs from R/3 using a user input and then another one by using one field retrieved from the first called RFC. Now i have to call a BAPI recursively from the data I got from the 2nd RFC that I called.

Here is the code so far:

public void executeBapi_Network_Getdetail_Input( )
  {
    //@@begin executeBapi_Network_Getdetail_Input()
    //$$begin Service Controller(246259973)
    IWDMessageManager manager = wdComponentAPI.getMessageManager();
    try
    {
      BigDecimal plannedCost = new BigDecimal(0);
	  for (int i=0; i<wdContext.nodeZps_Fm_Get_Network_Num_Input().nodeNetworks().nodeEx_Networks().size(); i++) {
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Network(false);
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Network_Activity(true);
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Relation(true);
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Activity_Element(true);
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Activity_Milestone(true);
		wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Component(true);
		wdContext.currentBapi_Network_Getdetail_InputElement().setNumber(
		  wdContext.nodeZps_Fm_Get_Network_Num_Input().nodeNetworks().nodeEx_Networks().getEx_NetworksElementAt(i).getAufnr());
		wdContext.currentBapi_Network_Getdetail_InputElement().modelObject().execute();
		wdContext.nodeNetworkDetails().invalidate();
		plannedCost.add(wdContext.nodeBapi_Network_Getdetail_Input().nodeNetworkDetails().nodeE_Network().getE_NetworkElementAt(i).getPlanned_Cost());
	  }
    }

sorry if this is totally wrong. I'm totally a newbie here.

Hoping for your kind and helpful responses.

Cheers,

Alfonso

Accepted Solutions (0)

Answers (9)

Answers (9)

Former Member
0 Kudos

Hi Pravesh,

Sorry, I think I accidentally clicked that.

I think I'll need to implement something similar to this later on, but yes for now, the issue is solved I think. Thank you and everybody for the suggestions!

Cheers,

Alfonso

Former Member
0 Kudos

Hi Pravesh,

Not with this implementation. With the code we've done, I still can't see my desired values. I tried to look for the values in the debugger but it was in vain. I couldn't find the values in the tree of wdThis.wdContext.

I made a workaround for this specific step, but would still want to learn how to do it correctly and elegantly.

Again, thank you for helping me out with this issue, you've been very helpful.

Best Regards,

Alfonso

pravesh_verma
Active Contributor
0 Kudos

Hi Alfonso,

Do you say thank you by reducing points !! Just kidding.. )

No issues if you problem is still there kindly let us know OR if you are ok with this kindly close the thread.

Regards

Pravesh

Former Member
0 Kudos

Hello Experts,

Thanks for the Help. Although I wasn't able to solve it the way I originally intended, I learned a lot from this thread.

Cheers,

Alfonso

pravesh_verma
Active Contributor
0 Kudos

Hi,

Is your problem not solved?? Please let us know if you are stuck somewhere and if we could help you!

Thanks and Regards

Pravesh

Edited by: Pravesh Verma on Mar 20, 2009 4:46 AM

Former Member
0 Kudos

Hi Pravesh and Siva,

Thanks for the links and explanation. It does clear things up for me.

Best Regards,

Alfonso

Former Member
0 Kudos

Hi Pravesh,

Thank you very much for the insight you gave in my code. I will try it along with some modifications.

Like I said, I'm a newbie at this so I don't actually know what the invalidate() method is for yet. I just assumed that this is required every time I execute an RFC.

I hope you can enlighten me further on this.

Again, thanks very much,

Alfonso

pravesh_verma
Active Contributor
0 Kudos

Hi Alfonso,

Invalidate works in two different ways:

1) In case of Model Node: It will reinitialize it to the initial data of the modeled node. You would require to use inva;idate only if there is a need to re instantiate a node.

2) In case of Value Node. It will again reinitialize the data. However since there is no data in the value node initially therefore it behaves as the delete functionality for the value node.

Have a llok to the Java Doc as well:


/**
   * With this method the node will be invalidated. It clears its element list
   * and calls the supply function again when asked for an element. A mapped
   * node passes this request to its origin and thus invalidates this one.
   * <p>
   * <b>Warning:</b> This method is not allowed within a supply function.
   * 
   * @throws WDRuntimeException when called from within a supply function.
   */

Check out these two links which also explain in detail what is purpose of invalidate.

1)

2)

I am sure this will clear your doubt. If you have any further issues kindly revert back.

Thanks nad Regards,

Pravesh

former_member197348
Active Contributor
0 Kudos

Hi Alfonso,

invalidate() is a method which refreshes the node. Means After RFC executing the RFC, if you use invalidate() method, it clears the content and fetches fresh data from R/3. Hope I made it clear.

I want to provide some useful tutorials in Web Dynpro

Check this [link |/docs/DOC-8061#15 [original link is broken]]

Regards,

Siva

Former Member
0 Kudos

Hi Ravi,

Yes, that is how one would basically call an RFC and I'm able to do so myself. But like i stated in my first email, my requirement is not as simple as that.

Still hoping y'all can help. Thanks in advance.

Best Regards,

Alfonso

pravesh_verma
Active Contributor
0 Kudos

Hi Alfonso,

Can you please try this code:


	  IWDMessageManager manager = wdComponentAPI.getMessageManager();
	    try
	    {
	      BigDecimal plannedCost = new BigDecimal(0);
	      
	      // Initializing a IWDNode to make code more readable and clean 
	      IWDNode nodeEx_Networks = wdContext.nodeZps_Fm_Get_Network_Num_Input().nodeNetworks().nodeEx_Networks();
	      
	      // I have initialized the int variable because you should never calculate the size() in for loop.
	      // It is major performance hit.
	      int size = nodeEx_Networks.size();
	      
	      for (int i=0; i<size; i++) {
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Network(false);
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Network_Activity(true);
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Relation(true);
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Activity_Element(true);
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Activity_Milestone(true);
			wdContext.currentBapi_Network_Getdetail_InputElement().setI_Without_Component(true);
			wdContext.currentBapi_Network_Getdetail_InputElement().setNumber(nodeEx_Networks.getEx_NetworksElementAt(i).getAufnr());
			wdContext.currentBapi_Network_Getdetail_InputElement().modelObject().execute();
			
			// WHY IS THIS INVALIDATE DONE.. WHICH IS THIS NODE???
			wdContext.nodeNetworkDetails().invalidate();
			
		  }
		  
		  IWDNode nodeE_Network = wdContext.nodeBapi_Network_Getdetail_Input().nodeNetworkDetails().nodeE_Network();
		    int sizeNetwork_Getdetail = nodeE_Network.size();
		    
		    for (int i = 0; i < sizeNetwork_Getdetail; i++) {
		    	plannedCost.add(nodeE_Network.getE_NetworkElementAt(i).getPlanned_Cost());
			}
		    
		    // Now you can check the plannedCost by printing it using the manager you have initialized above.
	    }

I hope this solves your issue. If you have any further issue please revert back.

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hi

To call the RFC,

Please write this sample code in your application.

try

{

wdContext.currentZero_address_InputElement( ).modelObject( ).execute( ).

wdContext.nodeOutbput.invalidate();

}

catch ( WdDynamicRFCExecuteException e)

{

manager.reportException(e.getMessage( ), false );

}

Best Regards

Ravi

Former Member
0 Kudos

Hello Jackson,

Thanks for the quick response.

Actually I was aiming to execute the BAPI using data from a previously executed RFC. Then I get the output for each call and then store it in a variable to be pushed into the context later on. Then repeat the call for a different input.

Former Member
0 Kudos

Hi there!

Welcome!!

What is the problem?

From what I see you are trying to execute the BAPI code and then you are trying to add one of the User Input into an element?

Is that what you are trying to do?