cancel
Showing results for 
Search instead for 
Did you mean: 

Inserting a record in R/3

Former Member
0 Kudos

Hello,

I have developed a webdynpro application to read and insert data into a R/3 Custom table.....the read works fine....but i need help to insert record once the user fills out the screen and hits submit button....what is the code required to be written in the view and the component controller and the appropriate bindings between the view,component controller and the model?

Any help would be highly appreicated.

Regards,

Anil

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Anil,

For inserting the record into the BAPI, you need to map the Corresponding nodes of BAPI to the Component Controller , i.e., if the BAPI name is Z_BAPI then

1) the parameters under Z_BAPI_INPUT should be mapped

2) In the Begin Others you must have created the object eg

Z_BAPI_Input object = new Z_BAPI_Input();

3) In the init part you must have bind the node to the BAPI, i.e.,

wdContext.nodeZ_BAPI_Input().bind(object);

4) Now in the method to execute the BAPI

try{ object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.execute();

}catch(exception e){

}

Hope this should help you.

Regards.

Rajat

Answers (5)

Answers (5)

Former Member
0 Kudos

hi

As soon as the user fill the user data on the screen , you can fetch the data from the context ,

for example ,

you are filling the TWO INPUT FIELDS FIRSTNAME and LASTNAME ,

after fillimg this input fields you can get the data as \

String firstname= wdcontext.node<NODENAME>.current<nodeelementname>.getfirstname();

String lastname= wdcontext.node<NODENAME>.current<nodeelementname>.getlastname();

so if you are inserting it to the RFC , there are many structure present with CLASS NAME beside the strucure , you can find this in data modelor ,

suppose class name

RFCNAME rfc = new RFCNAME();

ZEmployee employee = new ZEmployee();

employee.setfirstname(firstname);

employee.setlastname(lastname)

rfc.addelement(emplopyee);

wdcontext.nodeEmployee.bind(rfc);

Thanks

Former Member
0 Kudos

Thanks all for your replies...so this is the code i have written in the component controller:

Z_Bapi_<Insert Bapi> in = new Z_Bapi_<Insert Bapi>

Z<struct> zz = new Z<struct>();

zz.set<parameter>(wdContext.current<Currentnode>Element().get<parameter>());

in.set<input>(zz);

wdContext.node<bindednode>().bind(in);

wdContext.current<bindednode>tElement().modelObject().execute();

where Z_Bapi_<Insert Bapi> is the insert BAPI

Z<struct> is the structure used to insert

<parameter> is one of the fields to be inserted

<Currentnode> is the node holding current data binded to the node in the view controller.

<bindednode> is the node binded to the model object Z_Bapi_<Insert Bapi>

after executing this code there is nor error but the row is not getting inserted in the table...

Please help.

Regards,

Anil

Former Member
0 Kudos

Hi,

The WD code is fine. I think there is a problem in the RFC of R/3 Sytem . Ask the ABAP developers whether they have committed the changes to the ZTable. Please try to debug the funciton module in ABAP workbench by setting external breakpoing.

Rgds,

Aditya

Former Member
0 Kudos

You are right the ABAPer had to move some changes to the client where the portal is connected ....his development client was different than my testing client....

Former Member
0 Kudos

Hi Anil,

follow this procedure,

1. first studdy the Import Parameters or Tables if any.

2. Then Implement the Model for the same. and then do the Field Mapping from Model Import Params/Tables to the Component.

3. Now Map the required fields from Component to your View.

4. Now write your logic to insert the data from UI (in View) to Model.

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi

For inserting the record into the FM, you need to map the Corresponding nodes of BAPI to the Component Controller , i.e., if the FM name is Z_Test then

1) the parameters under Z_Test_INPUT should be mapped

2) In the Begin Others you must have created the object eg

Z_Test_Input object = new Z_Test_Input();

3) in the action method of Submit you need to bind the FM object

wdContext.nodeZ_Test_Input().bind(object);

4) If there is a structure having the fields of the table to which you want to insert the data.

try{

Z_Test_Struct struct = new Z_Test_Struct ();

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

object.set<parameter name>(parameter value);

struct.setInput(object);

wdContext.currentZ_Test_InputElement().modelObject().execute();

wdContext.node<OutputNode>.invalidate();

}catch(exception e){

}

Hope this will help to insert data to the table.

Thanks

Ritushree

Former Member
0 Kudos

Hi ,

Let us consider the following context structure for your example

Z_bapi_input (Zbapi)(Bapi Node mapped to component controller(Class in the model)))

|

|-- ZTable(ZTabClass) (Node for table mapped from model (Class in the model))

Create a node with structure binding of ZTabClass say Table.

Map this node to the view Controller.

Create a method execute_Bapi()

public void execute_Bapi()

{

Zbapi obj = new Zbapi();

wdCopyService.copyCorresponding(wdContext.nodeTable,wdContext.nodeZTable);

wdContext.nodeZ_bapi_input.bind(obj);

try{

wdContext.currentZ_bapi_inputElement.execute();

}catch(Exception e)

{

}

}

Now in the view controller Click on the button .. Go to properties tab and in the property onClick go to the icon '...' and create a new action and event handler say 'SubmitData'

Write the code in the following method.

onSubmitData()

{

wdThis.wdGetComponentControllerName.execute_Bapi();

}

Best Wishes

Idhaya R

Former Member
0 Kudos

Hi,

Go through the following threads

Regards

Suresh