cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with updating UItable values into BAPI table.

konchada_saikrishna
Active Participant
0 Kudos

Hi All,

I am having a bapi which fetches table values from R/3.

with this bapi I could get table values and display in the UITable.

I could Edit the table values,

But when I try to save them back into R/3, it is not getting updated. In fact when I try to execute the bapi in se37 it works fine.

actually the bapi takes 2 import parametrs and a table to process

param 1 -- action values (fetch/save)

param 2 -- Form_type values (INCIDENT/HAZARD)

If the action is fetch then it fetches the values from R/3 depending on Form_type

If the action is save then it saves the values into R/3 depending on Form_type

To perform save action I have a method name SAVE in custom controller

Here is the code, please look a it and help me in resolving that,

IPrivateConfig_Fields_View.IForm_ConfigElement ele;

Zbapi_Config_Flds_Input input = new Zbapi_Config_Flds_Input();

Zbapi_Form_Config tab = new Zbapi_Form_Config();

String opt = wdContext.currentContextElement().getConfig_To_Option();

int size = wdContext.nodeForm_Config().size();

input.setForm_Type("INCIDENT");

input.setForm_Act(action);

tab = new Zbapi_Form_Config();

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

{

tab.setFld_Check(wdContext.nodeForm_Config().getElementAt(i).getAttributeAsText("Fld_Check"));

input.addForm_Config(tab);

}

opt = tab.getFld_Check();

wdContext.nodeZbapi_Config_Flds_Input().bind(input);

try

{

wdContext.currentZbapi_Config_Flds_InputElement().modelObject().execute();

}

catch(Exception ex)

{

ex.printStackTrace();

}

wdContext.nodeOutput().invalidate();

return wdContext.currentReturnElement().getMessage();

on exeuting this, the bapi is returning a error msg handled by us.

Please help me if resolving this, If u need more clarification please post the requirements.

Thanks & Regards,

Sai krishna.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sai,

It would be clear if u can post the exception.

You said that u r getting an error that is handled by u. What is the bapi return message?

And I have some doubts regarding ur code:

1. U might not be getting bapi return message. If so, it is because u r invalidating output node before displaying Return message.

2. U r setting only one field:

setFld_Check(wdContext.nodeForm_Config().getElementAt(i).getAttributeAsText("Fld_Check"));

why are u not sending complete row with changes to bapi.

Anyways, as per my understanding i am putting some code here. Pls try this,

IWDMessageManager msg = wdComponentApi.getMessageManager();

Zbapi_Config_Flds_Input input = new Zbapi_Config_Flds_Input();

int size = wdContext.nodeForm_Config().size();

// if ur bapi is allowing multiply rows to be saved/updated at a time u should pass

// an abstractlist.

AbstractList tabList = new Zbapi_Form_Config.Zbapi_Form_ConfigList()

input.setForm_Type("INCIDENT");

input.setForm_Act(action);

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

{

// adds complete row to the list not a single attribute

tabList.add(wdContext.nodeForm_Config().getForm_ConfigElementAt(i).modelObject());

}

input.setForm_Config(tabList);

wdContext.nodeZbapi_Config_Flds_Input().bind(input);

try

{

wdContext.currentZbapi_Config_Flds_InputElement().modelObject().execute();

}

catch(Exception ex)

{

msg.reportWarning("exec"+ex);

ex.printStackTrace();

}

// check whether bapi is returning any message on success and failure or not.

msg.reportWarning("Return message"+ wdContext.currentReturnElement().getMessage());

wdContext.nodeOutput().invalidate();

//return wdContext.currentReturnElement().getMessage();

<b>Note: if bapi accepts multiple rows it should be passed as abstractlist.</b>

konchada_saikrishna
Active Participant
0 Kudos

Hi Aparna,

Your code i.e., using Abstract list works fine now.

Thanks, I have some problem continuing with this table i.e.,

I need to display a table with 5 rows and 7 columns.

5 of the columns are drop downs from R/3,

My requirement is the table should be in editable mode such that the user is allowed to enter some values(rows). on clicking the save button the table values are to be sent to R/3 table through bapi. Initially we will not get any Table from the Bapi, but the UITable values are to be sent to the bapi.

Please help me in resolving this.

Thanks & Regards,

Sai Krishna.

Former Member
0 Kudos

Hi,

Use the code which i have sent in my previous response On save action.

For displaying rows in ur table ui and allow user to enter some data follow the below steps:

1. In View Layout apply template as table in the wizard click next and u can change the table cell editor to inputfield initially it will text view.

2. Write this code in doInit() method of ur controller:

Bapi__Input() input = new Bapi_Input();

Bapi_Table<ur bapi table> table = new Bapi_Table();

for(int i = 0; i<5; i++){

table = new Bapi_Table();

wdContext.nodeBapi_Input().addElement(wdContext.nodeBapi_Input().createElement(table));

}

<replace table name and bapi names with urs>

This will display a table with 5 rows.

3. And to save the data u can use the previous code.

Note: Reward the helpful answers

Regards,

Aparna .P

konchada_saikrishna
Active Participant
0 Kudos

Hi Aparna,

I tried adding the UItable rows as you directed but it raised an exception as Class not found, here is the code.

Zbapi_Create_Incident_Input input = new Zbapi_Create_Incident_Input();

Zbapi_Incident_Create_Wittable table = new Zbapi_Incident_Create_Wittable();

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

{

table = new Zbapi_Incident_Create_Wittable();

wdContext.nodeINCCRE().addElement(wdContext.nodeINCCRE().createElement(table));

}

I Think you are not clear about the table requirements.

one table with 7 columns & 5 rows.

5 of the columns are different drop downs, whose values come from different Bapis.

2 columns are Input fields.

the user has to be allowed to enter some rows & only the filled rows are to be sent to R/3.

However you helped & solved my previous problem I am giving you the full points, please continue with this solution.

Thanks & Regards,

Sai Krishna.

Answers (5)

Answers (5)

Former Member
0 Kudos

hi

To make 7 colmuns make 7 attributes and to make 5 rows enable try this:

for(i=0;i<5;i++)

{

wdContex.nodeZ_node.addElement(wdContext.nodeZ_node.createZ_nodeElement());

}

When you have created this table ,pass it as a list to your Bapi parameter as Aparana has explained you.

*Please reward with points if you find suggestion helpful**

Regards

Nidhideep

Former Member
0 Kudos

hi ,

try like this and I need <b>small clarifications</b>

IPrivateConfig_Fields_View.IForm_ConfigElement ele;

Zbapi_Config_Flds_Input input = new Zbapi_Config_Flds_Input();

wdContext.nodeZbapi_Config_Flds_Input().bind(input);

input.setForm_Type("INCIDENT");

input.setForm_Act(action);

String opt = wdContext.currentContextElement().getConfig_To_Option();

Zbapi_Form_Config tab = new Zbapi_Form_Config();

int size = wdContext.nodeForm_Config().size();

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

{

tab.setFld_Check(wdContext.nodeForm_Config().getElementAt(i).getAttributeAsText("Fld_Check"));

input.addForm_Config(tab); <b>Wht this statement meaning </b>

}

opt = tab.getFld_Check();

try

{

wdContext.currentZbapi_Config_Flds_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch(Exception ex)

{

ex.printStackTrace();

}

return wdContext.currentReturnElement().getMessage();

Other wise write your requirement and BAPI(import and export)

I will give you the code

Thanks,

Lohi.

Former Member
0 Kudos

hi

Plz let us know the exception that you are getting

Regards

Nidhideep

Former Member
0 Kudos

pl post the exception .

Regards, Anilkumar

konchada_saikrishna
Active Participant
0 Kudos

Hi Anil,

The error msg returned from the bapi which is a user handled one,

I.e, I am getting a MSg on either Sucess or failure of the Save Action.

Regards,

sai krishna.

former_member182294
Active Contributor
0 Kudos

Hi Sai,

Can you please post where exactly its failing and which condition?

Regards

Abhilash

konchada_saikrishna
Active Participant
0 Kudos

Hi Abhilash,

The error msg returned from the bapi which is a user handled one,

I.e, I am getting a MSg on either Sucess or failure of the Save Action.

Regards,

sai krishna.

former_member182294
Active Contributor
0 Kudos

Hi Sai,

Please elaborate on your conditions like in which case your BAPI returns the error message. But I can suggest you one thing as you are able to execute successfully with SE37. When you are working with JCO all the values which are passed are case sensitive but in SE37 , SAP System is not case sensitive. Please make sure that whatever the values your passing while executing the BAPI are proper and as expected.

Regards

Abhilash

konchada_saikrishna
Active Participant
0 Kudos

Hi Anil,

If U dont mind here is the bapi code, please have a look at this, if u want more explanation ask me,

CONSTANTS : c_incident LIKE zform_config-form_type VALUE 'INCIDENT',

c_hazard LIKE zform_config-form_type VALUE 'HAZARD'.

DATA : wa_form_config TYPE zbapi_form_config,

wa_form_update TYPE zbapi_form_config.

IF form_act NE 'SAVE'.

SELECT COUNT(*)

FROM zform_config

WHERE form_type EQ form_type.

IF sy-subrc EQ 0.

IF form_type EQ c_incident.

SELECT *

FROM zform_config

INTO TABLE form_config

WHERE form_type EQ c_incident.

IF sy-subrc NE 0.

return-number = 1.

return-message = 'Table Contains No Data'.

ELSE.

return-number = 0.

return-message = 'Successful Retrieval of Data'.

ENDIF.

ELSEIF form_type EQ c_hazard.

SELECT *

FROM zform_config

INTO TABLE form_config

WHERE form_type EQ c_hazard.

IF sy-subrc NE 0.

return-number = 1.

return-message = 'Table Contains No Data'.

ELSE.

return-number = 0.

return-message = 'Successful Retrieval of Data'.

ENDIF.

ENDIF.

ELSE.

return-number = 2.

return-message = 'Form Type Not Exists'.

ENDIF.

ELSEIF form_act EQ 'SAVE'.

LOOP AT form_config INTO wa_form_config.

wa_form_update-form_type = wa_form_config-form_type.

wa_form_update-fld_name = wa_form_config-fld_name.

wa_form_update-fld_type = wa_form_config-fld_type.

wa_form_update-fld_len = wa_form_config-fld_len.

wa_form_update-fld_check = wa_form_config-fld_check.

wa_form_update-fld_control = wa_form_config-fld_control.

wa_form_update-fld_mandatory = wa_form_config-fld_mandatory.

UPDATE zform_config FROM wa_form_update.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = return.

ELSE.

return-number = 4.

return-message = 'UPDATION UNSUCESSFUL'.

ENDIF.

CLEAR : wa_form_config,

wa_form_update.

ENDLOOP.

SELECT *

FROM zform_config

INTO TABLE form_CONFIG.

ENDIF.

ENDFUNCTION.

Thanks ,

Sai krishna.

Message was edited by:

Konchada Sai Krishna

former_member182294
Active Contributor
0 Kudos

Sai,

Which condition is failed? Is it your application giving 'Table Contains No Data' message or any other message?

From your code I understand that your passing INCIDENT as one of the parameter; are you passing any other parameters give me the text also which you are passing.

Regards

Abhilash

konchada_saikrishna
Active Participant
0 Kudos

Hi Abhilash,

I am passing action = SAVE & Form_type = INCIDENT.

I am getting return msg as "Updation Unsucessful".

Sai krishna.