cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi import problem(filling dropdown with bapi output)

Former Member
0 Kudos

Hi all,

I am trying to fill the drop down box (drop down by key) with a Bapi. the UI is a drop down which should populate whenever screen gets loaded. so I am writing the following code in my doInit()

My bapi strcture is

Context
      |_Bapi node(Zad_bapi_search_form_Input)
            |_Output
                  _Advertiser_out
                          |_Name1

in doInit() of view

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().setIm_Agencyid("11111");

<b>//Here Im_Agencyid id is the input to bapi which I am hardcoding for time being</b>

    wdThis.wdGetCanelAdCompController().executeZad_Bapi_Pop_Search_Form_Input();
    IWDAttributeInfo attAdvert=wdContext.nodeAdvertiser_out().getNodeInfo().getAttribute("Name1");
    ISimpleTypeModifiable advertSMT=attAdvert.getModifiableSimpleType();
    IModifiableSimpleValueSet advert_Node=advertSMT.getSVServices().getModifiableSimpleValueSet();
    advert_Node.clear();
    if(wdContext.nodeAdvertiser_out().size()>0)
    {
    	for(int countAdvert=0;countAdvert<wdContext.nodeAdvertiser_out().size();countAdvert++)
    	{
    		advert_Node.put(wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getName1(),wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getName1());
    	}
    }

In doinit() of the controller

 CancelAdModel cancel=(CancelAdModel)WDModelFactory.getModelInstance(CancelAdModel.class,WDModelScopeType.TASK_SCOPE);
    Zad_Bapi_Pop_Search_Form_Input bapIn=(Zad_Bapi_Pop_Search_Form_Input)cancel.createModelObject(Zad_Bapi_Pop_Search_Form_Input.class);
    wdContext.nodeZad_Bapi_Pop_Search_Form_Input().bind(bapIn);
    
 
    try {
		wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();
		cancel.disconnectIfAlive();
		
	} catch (WDDynamicRFCExecuteException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

I mapped the Bapi node to my UI element and changed the cardinality to 1..n

<b>Its giving me the error... and error log trace is</b>

500 Internal Server Error

SAP NetWeaver Application Server 7.00/Java AS 7.00

Failed to process request. Please contact your system administrator.

Error Summary

While processing the current request, an exception occured which could not be handled by the application or the framework.

If the information contained on this page doesn't help you to find and correct the cause of the problem, please contact your system administrator. To facilitate analysis of the problem, keep a copy of this error page. Hint: Most browsers allow to select all content, copy it and then paste it into an empty document (e.g. email or simple text file).

Root Cause

The initial exception that caused the request to fail, was:

com.sap.tc.webdynpro.progmodel.context.ContextException: MappedAttributeInfo(MainView.Zad_Bapi_Pop_Search_Form_Input.Output.Advertiser_out.Name1): must not modify the datatype of a mapped attribute

at com.sap.tc.webdynpro.progmodel.context.MappedAttributeInfo.getModifiableSimpleType(MappedAttributeInfo.java:117)

at com.sap.nyt.MainView.wdDoInit(MainView.java:103)

at com.sap.nyt.wdp.InternalMainView.wdDoInit(InternalMainView.java:229)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit(DelegatingView.java:61)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

... 52 more

Please Help me out and get FULL REWARD points

advance thanks,

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

former_member206397
Contributor
0 Kudos

Hi,

You can do one thing, remove all the code form the doInit() of view. Map put all the code in doInit() of Controller. like bellow.

// for initialize and set teh input value

Zad_Bapi_Pop_Search_Form_Input bapIn = new Zad_Bapi_Pop_Search_Form_Input();

bapIn.set<Input Parameter>;

wdContext. nodeZad_Bapi_Pop_Search_Form_Input bapIn.bind(bapIn);

//Now Execute your BAPI

try {

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();

wdContext.nodeOutput().invelidate();

} catch (WDDynamicRFCExecuteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//Now you use a store the size of output node witin a variable. suppose

int nodeSize = wdContext.nodeOutput().size();

//Now you use a for loop and get the value of each row and set it to your dropdown attribute.

// Here you can write all the codes for your dropdown. within the for loop will just get the value from output node of BAPI and set it to dropdown.

for(int i=0; i<nodeSize(); i++)

{

................

..............

...............

}

I think it should work. If it does not work please send me the BAPI name or details.

I will send you the ready code.

Thanks

Chandan

Former Member
0 Kudos

no... my problem is not solved yet. now its giving NULL POINTER exception

As I told you my structure..

Context
      |_Bapi node(Zad_bapi_search_form_Input)
            |_Output
                  _Advertiser_out
                          |_Name1

how to access the attribute.? is it correct to write code like below

IWDNodeInfo <b>selValsNodeInfo=wdContext.nodeZad_Bapi_Pop_Search_Form_Input().getNodeInfo();</b>
IModifiableSimpleValueSet advertSimp= selValsNodeInfo.getAttribute("Name1").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

Former Member
0 Kudos

Hi chandan,

Thanks for your reply.

Could you please tell me what will be the difference if I write the code in view or controller?

there is no difference when I put this code in the controller. I am getting null pointer exception. I changed the cardinality to 1..1 and mapped the UI element properly

please check out my code and tell me where is the problem?

 wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().setIm_Agencyid("11111");
    wdThis.wdGetCanelAdCompController().executeZad_Bapi_Pop_Search_Form_Input();
    
    IWDNodeInfo selValsNodeInfo=wdContext.nodeZad_Bapi_Pop_Search_Form_Input().nodeOutput().getNodeInfo();
    IWDAttributeInfo atrAdvert=selValsNodeInfo.getAttribute("Name1");
    ISimpleTypeModifiable advertSMT=atrAdvert.getModifiableSimpleType();
    IModifiableSimpleValueSet advert_Node=advertSMT.getSVServices().getModifiableSimpleValueSet();
	advert_Node.clear();
	
    if(wdContext.nodeAdvertiser_out().size()>0)
    {
    	for(int countAdvert=0;countAdvert<wdContext.nodeAdvertiser_out().size();countAdvert++)
    	{
    		advert_Node.put(wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getName1(),wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getName1());
    	}
    }

Former Member
0 Kudos

Hi,

While populating a dropdownbykey you access the attribute that is bound to the selectedKey property of the DDBK.

If this attribute is mapped from a model node to the view context then you cannot access that attribute inside view controller and modify it.You can access it only in component controller.

Instead create a method in component controller that will populate the DDBK node with value,kay pairs and access that method from view controller.

One more thing what I see from your code is that your <b>key</b> and <b>value</b> for DDBK have same value.If that is the case,

then go for DropDownByIndex. It is really simple to use and you dont have to do any coding.Just map your context attribute Name1 with the "texts" property of DDBI.

Former Member
0 Kudos

Hi Shriram,

Thanks for your response.

As told by many people, I can not access the model nodes directly in view controller and can not map the UI element to model node.

So Now I created local nodes under the context and will map that node to UI element. Now I have to map the local nodes to the model nodes. I mean to say to get all the values of model nodes into the local node. Will it works?? If yes how to do it??

Former Member
0 Kudos

Hi,

At the start of your thread you have mentioned

<i>In doinit() of the controller

CancelAdModel cancel=(CancelAdModel)WDModelFactory.getModelInstance(CancelAdModel.class,WDModelScopeType.TASK_SCOPE);

Zad_Bapi_Pop_Search_Form_Input bapIn=(Zad_Bapi_Pop_Search_Form_Input)cancel.createModelObject(Zad_Bapi_Pop_Search_Form_Input.class);

wdContext.nodeZad_Bapi_Pop_Search_Form_Input().bind(bapIn);

try {

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();

cancel.disconnectIfAlive();

} catch (WDDynamicRFCExecuteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}</i>

I am wondering what does your method executeZad_Bapi_Pop_Search_Form_Input(); contain.

Could you let us know ?

Former Member
0 Kudos

My Bapi takes one input and output contains nodes to fill the 7 drop downs.

The code mentioned here is the other way to bind.

now I am going in regular way ie in comp controller...

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().setIm_Agencyid("11111");
    Zad_Bapi_Pop_Search_Form_Input BapIn= new Zad_Bapi_Pop_Search_Form_Input();
    wdContext.nodeZad_Bapi_Pop_Search_Form_Input().bind(BapIn);
   try {
		 wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();
		    wdContext.nodeOutput().invalidate();
	} catch (WDDynamicRFCExecuteException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

now please tell me how to get data from model node to local nodes(which i created to map to UI elements.

Thanks in advance

Pradeep

Former Member
0 Kudos

executeZad_Bapi_Pop_Search_Form_Input(); is auto generated method and code inside it. it is created while selecting component controller->template->service controller. it contains

IWDMessageManager manager = wdComponentAPI.getMessageManager();
    try
    {
      wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();
      wdContext.nodeOutput().invalidate();
    }
    catch(WDDynamicRFCExecuteException e)
    {
      manager.reportException(e.getMessage(), false);
    }

Former Member
0 Kudos

Hi ,

Your output needs to be displayed by using DDBK only ?

The output of your Field will give you no of records not key and valu pair ?

Am I correct?

For that better to go for DDBI only is suitable for your requirement.

After executing the BAPI functionality simple bind with DDBI then it aumatically displays how many values do u have.

Thanks,

Lohi.

Former Member
0 Kudos

No my requirement is to use drop down by key only. I have key and value pair.

please let me know how to get all the values from model node and set it to local context nodes.

my context structure is

context
  |_bapi node
  |    |_output
  |           |_advertiser
  |                |_advertiserId
  |                _ advertiserName
  |_advertiser_Node ( local node created by me)
               |_vaAdvertiser
                _ vaAdvertiserName

Now I want to get all values from model nodes advertiser to my local nodes advertiser_Node. help me out how to do it

Former Member
0 Kudos

Hi,

No need of transferring the values from model node to local node.

Just re-arreange your code as given below.

In doinit() of the controller

Zad_Bapi_Pop_Search_Form_Input BapIn= new Zad_Bapi_Pop_Search_Form_Input();

wdContext.nodeZad_Bapi_Pop_Search_Form_Input().bind(BapIn);

try {

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

} catch (WDDynamicRFCExecuteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// create a method in component controller say populateDDBK and indside that method write. This method you can call from any other view if you need the same values to be populated in other DDBK.

public void populateDDBK();

{

IWDAttributeInfo attAdvert=wdContext.nodeAdvertiser_out().getNodeInfo().getAttribute("advertiserName");

ISimpleTypeModifiable advertSMT=attAdvert.getModifiableSimpleType();

IModifiableSimpleValueSet advert_Node=advertSMT.getSVServices().getModifiableSimpleValueSet();

if(wdContext.nodeAdvertiser_out().size()>0)

{

for(int countAdvert=0;countAdvert<wdContext.nodeAdvertiser_out().size();countAdvert++)

{

advertiser.put(wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getadvertiserId(),wdContext.nodeAdvertiser_out().getAdvertiser_outElementAt(countAdvert).getadvertiserName());

}

}

}

// in doInit() of view

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().setIm_Agencyid("11111");

wdThis.wdGetCanelAdCompController().executeZad_Bapi_Pop_Search_Form_Input();

wdThis.wdGetCanelAdCompController.populateDDBk();

Former Member
0 Kudos

Hi,

This is what I did previously but it was giving error in IwdModifiableXXX() saying can not change the model node attribute type. and you are suggesting the same. one of the reply for my post was....

U can't change model node attribute type.

IModifiableSimpleValueSet advert_Node=advertSMT.getSVServices().getModifiableSimpleValueSet();

With this statement you are trying to change enumeration of the model node attribute.This is not allowed.

That is the reason I preffered to create local nodes for all model nodes and transferring the values from model node to local node and then mapping the UI to local nodes.

Now what would you suggest me to do.

Former Member
0 Kudos

I did the same as it is to your code, but its giving java.lang.nullpointer exception.

I changed the cardinality to 1..1

I mapped the UI element to model nodes attribute ( advertiser_out->AdvertiserName) directly. Still its giving error. error trace is

java.lang.NullPointerException

at com.sap.nyt.CanelAdComp.wdDoInit(CanelAdComp.java:129)

at com.sap.nyt.wdp.InternalCanelAdComp.wdDoInit(InternalCanelAdComp.java:310)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.doInit(DelegatingComponent.java:108)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:200)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.init(ClientComponent.java:430)

at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.init(ClientApplication.java:362)

at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.initApplication(ApplicationSession.java:748)

at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:283)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingPortal(ClientSession.java:779)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:714)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:261)

at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:149)

at com.sap.tc.webdynpro.clientserver.session.core.ApplicationHandle.doProcessing(ApplicationHandle.java:73)

Can I directly map the UI element Dropdown by key's slected key to model nodes attribute? Is it correct? please let me know the problem.

Former Member
0 Kudos

Hi Shriram,

Now I could able to view the output screen but drop down is not populating and also bottom of the screen there is a error message please help me out where is the error.

the error message is

Could not create JCOClientConnection for logical System: WD_DISP_RFC_MODELDATA_SAP - Model: class com.sap.nyt.model.CancelAdModel. Please assure that you have configured the RFC connections and/or logical system name properly for this model!

Thanks in advance

Pradeep

Former Member
0 Kudos

Hi,

The reason for failure is explained in the error message

<b>Please assure that you have configured the RFC connections and/or logical system name properly for this model!</b>

Check for your JCO connection setup and the logical name that you have given.

Test if the model is available through the logical name you have specified.

Message was edited by:

Shriram Kabra

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

I have already sent you the application and again here pasting the code.. I have used the RFC called BAP_FLIGHT_GETLIST. Select a value from a Dropdown by key and get the actual key value of it.. Follow my project... I have sent you in you mail. Please reward points if it helps... Use the node structure of my code and paste this code in the wdinit of your view....

  
public void wdDoInit()
  {
    //@@begin wdDoInit()

	try
	 {
		 Bapi_Flight_Getlist_Input bapiinput = new Bapi_Flight_Getlist_Input();
		 wdContext.nodeBapi_Flight_Getlist_Input().bind(bapiinput);
		 wdContext.nodeAirlineValue().addElement(wdContext.nodeAirlineValue().createElement());    	
		 wdContext.currentBapi_Flight_Getlist_InputElement().modelObject().execute();
		 wdContext.nodeOutput().invalidate();
		 int size = wdContext.nodeFlight_List().size();
		 IWDMessageManager msg = wdComponentAPI.getMessageManager();
		 //String compAirlineid = "AA";
		 IPrivateTestComponentView.IAirlineValueElement airlineelem = wdContext.createAirlineValueElement();
		 List retval = new ArrayList();		
		 final IModifiableSimpleValueSet ValueSet =
					 wdThis
						 .wdGetTestComponentController()
						 .wdGetContext()
						 .getNodeInfo()
						 .getChild("AirlineValue")
						 .getAttribute("AirlineID")
						 .getModifiableSimpleType()
						 .getSVServices()
						 .getModifiableSimpleValueSet();		
		 for (int indx=0;indx < size ; indx++)		
		 {
		 	msg.reportSuccess("Index" + indx + " Value " + wdContext.nodeFlight_List().getElementAt(indx).getAttributeValue("Airlineid"));
		 	ValueSet.put(wdContext.nodeFlight_List().getElementAt(indx).getAttributeValue("Airlineid"),"Airlineid" + indx);				 
		 }
		 wdContext.nodeAirlineValue().addElement(airlineelem);		 
	 }
	 catch (Exception e) 
	 {
		 // TODO Auto-generated catch block
		 e.printStackTrace();
	 }
 
    //@@end
  }

Thanks and Regards

Avijit

Former Member
0 Kudos

Hi Pradip sent you the code,

In my sample application I have executed one Bapi , fetched the value and filterred the collection of value and displayed them in a combo box. Hope it helps. If you need further help clearly write me in a mail and i will surley create a sample project and try to help you out...

Please reward points if it helps...

Thanks and Regards

Avijit Dhar

Former Member
0 Kudos

Hi Avijit,

I did not get any of your mail, I explained my problem in this post only with my model structure please gothrough from the starting you will find my problem.

give me your mail id so that I can send you more info

Former Member
0 Kudos

Hi Pradeep,

Try this code in WdDOInit Method in ViewController...

IPublicFlightBooking.IFlight_ListNode CC_Node = wdThis.wdGetFlightBookingController().wdGetContext().nodeFlight_List();

IPrivateRFCView.IFlight_ListNode VC_Node = wdContext.nodeFlight_List();

WDCopyService.copySubtree((IWDNode)CC_Node,(IWDNode)VC_Node);

wdContext.nodeMasterFilter().invalidate();

If it will be helpful Reward some points...

URs GS

Former Member
0 Kudos

Hi,

Paste your mail address here.. I will send you a sample application that will surely help you to clear your doubts..

Thanks and Regards

Avijit

Former Member
0 Kudos

Hi Avijit,

My mail Id is pradeep_bondla@satyam.com

monalisa_biswal
Contributor
0 Kudos

Hi Pradeep,

U can't change model node attribute type.

IModifiableSimpleValueSet advert_Node=advertSMT.getSVServices().getModifiableSimpleValueSet();

With this statement you are trying to change enumeration of the model node attribute.This is not allowed.

For populating dropdown you create a value node in the view.

Copy date from value node to model node with the help of WDService methods.

former_member206397
Contributor
0 Kudos

Hi,

You need to Invalidate the output node. So put the code

wdContext.currentZad_Bapi_Pop_Search_Form_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

Thanks

Chandan

Former Member
0 Kudos

1. add code : wdContext.nodeOutput().invalidate()

after execute

2. change cardinality to 0..n (set selection to 1..1 if u dont need to see empty value in dd)

Former Member
0 Kudos

Thanks for the quick response, but its still giving the same error. I think its not with the missing of invalidate() or cardinality.

Error clearly saying the its with

The initial exception that caused the request to fail, was:
   com.sap.tc.webdynpro.progmodel.context.ContextException: MappedAttributeInfo(MainView.Zad_Bapi_Pop_Search_Form_Input.Output.Advertiser_out.Name1): must not modify the datatype of a mapped attribute 

    at com.sap.tc.webdynpro.progmodel.context.MappedAttributeInfo.getModifiableSimpleType(MappedAttributeInfo.java:117)
    at com.sap.nyt.MainView.wdDoInit(MainView.java:103)
    at com.sap.nyt.wdp.InternalMainView.wdDoInit(InternalMainView.java:229)
    at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit(DelegatingView.java:61)
    at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

<b>getModifiableSimpleType(), please look into it and help me out</b>