Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue with BAPI

pakula123
Participant
0 Likes
1,345

Hi Experts, This is the second time I am having this issue with BAPI.

script execution: TypeError: Unable to get property 'textContent' of undefined or null reference at GuiRFC.prototype.getResult

var objTable = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell");

var firstVisibleRow = objTable.firstVisibleRow ;

var selectedVisibleRow = parseInt( session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows );

var selectedTableRow = firstVisibleRow + selectedVisibleRow ;

//var colName = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getColumnName(1) ;

var order = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getCellValue(selectedTableRow ,"AUFNR") ;

var str1 = order ;

var str2 = "00";

var str3 = "000" ;

var order = str2.concat(str1);

session.findById("wnd[0]/usr/txtPersonas_1464198546735").text = order ;

//session.findById("wnd[0]/usr/txtPersonas_1461014548992").text = order ;

var rfc = session.createRFC("ZBAPI_ISUSMORDER_USERSTATUSSET") ;

rfc.setParameter("NUMBER", order); rfc.setParameter("VALUE", "E0014");

var rfc1 = session.createRFC("BAPI_TRANSACTION_COMMIT") ;

rfc.requestResults(JSON.stringify(["RETURN"]));======================FAILING SOMEWHERE HERE ===============

rfc.send(); "]))

var result = JSON.parse(rfc.getResult("RETURN"));"]));======================FAILING SOMEWHERE HERE ===============

if (result.NUMBER == str3 ) { //session.utils.showOptionDialog("", "Notitifcation Suspended", session.utils.MESSAGE_TYPE_INFORMATION, session.utils.MESSAGE_OPTION_OK, onOptionDialogClose, "1");

session.findById("wnd[0]/tbar[1]/btn[8]").press();

session.findById("wnd[0]/sbar").setMessage( " Order backlogged", "I" ) ;

//function onOptionDialogClose(decision, ID){} }

else { // session.utils.showOptionDialog("", "Notitifcation suspension Failed", session.utils.MESSAGE_TYPE_INFORMATION, session.utils.MESSAGE_OPTION_OK, onOptionDialogClose, "1");

session.findById("wnd[0]/tbar[1]/btn[8]").press();

session.findById("wnd[0]/sbar").setMessage( " order backlog failed ", "I" ) ;

//function onOptionDialogClose(decision, ID){} session.utils.log(result.NUMBER);

}

Kindly suggest .

Best regards,

pradeep.

1 ACCEPTED SOLUTION
Read only

clemens_gantert
Product and Topic Expert
Product and Topic Expert
0 Likes
1,283

Hello Pradeep,

if you want to use a changing RFC the change has to be commited with the RFC. Some RFCs have a special parameter to indicate whether or not to commit. If the the function does not have a commit flag, but requires a subsequent call to a commit BAPI, then it will not work.

You can solve this by writting a "wrapper" RFC (in ABAP) from which you call the desired functional RFC and then the commit BAPI.

Thanks,

Clemens

11 REPLIES 11
Read only

clemens_gantert
Product and Topic Expert
Product and Topic Expert
0 Likes
1,284

Hello Pradeep,

if you want to use a changing RFC the change has to be commited with the RFC. Some RFCs have a special parameter to indicate whether or not to commit. If the the function does not have a commit flag, but requires a subsequent call to a commit BAPI, then it will not work.

You can solve this by writting a "wrapper" RFC (in ABAP) from which you call the desired functional RFC and then the commit BAPI.

Thanks,

Clemens

Read only

0 Likes
1,283

Hi Clemens , I dont think so we need to use BAPI commit in our case ,I just put it in there just to make sure .But I have a concern on the next step var result = JSON.parse(rfc.getResult("RETURN"));

which is failing not sure why .We have discussed in this thread earlier http://scn.sap.com/thread/3903926

where you have mentioned to wait for SP3 .(in that case it was issue with dates ).

We are upgrading to SP3 . if we are using BAPI_ISUSMORDER_USERSTATUSSET to set the user status .will the RFC tool have auto code generation as shown in power play videos . Can SP3 fix the issue that I am having with line

var result = JSON.parse(rfc.getResult("RETURN"));

Please comment.





Best regards,

pradeep.

Read only

0 Likes
1,283

Hi,

if you are able to change the order by just running the FM in SM37, then it proves that you don't need a commit RFC.

I only now noticed that you didn't request any result parameters before creating the second rfc. In general it's a good idea to finish one rfc at a time and for now I strongly recommend to request some data back (even if you don't need it) before you create and send the next rfc.

The following is a script that I created with the RFC tool in SP03 and is working fine (well, it does not do anything, but it runs through and does not cause exceptions and the _RETURN1 object contains a sensible, functional error message).

var oRFC = session.createRFC("BAPI_ISUSMORDER_USERSTATUSSET");

oRFC.setParameter("INACTIVE", ""); // optional

oRFC.setParameter("NUMBER", "");

oRFC.setParameter("STATUS", {"INTERN":"","EXTERN":"","LANGU":"","LANGU_ISO":""});

oRFC.requestResults(["RETURN"]);

oRFC.send();

var _RETURN1 = oRFC.getResultObject("RETURN");

var oRFC2 = session.createRFC("BAPI_TRANSACTION_COMMIT");

oRFC2.requestResults(["RETURN"]);

oRFC2.send();

var _RETURN2 = oRFC2.getResultObject("RETURN");

Cheers,

Clemens

Read only

0 Likes
1,283

Hi Clemens ,

I requested the results and am still getting the same error as you can see I am using request results and JSON stringify in one line.

I tried using just request results only as well with out JSON stringify but still shows same error.

I tried concatenating with leading ZERO`s and with out leading ZERO`s and have set external break point in ABAP side but still no luck.

we are in SP2 and are planning to move to SP3 some time next week. Do you think that SP2 has some issue here .

var objTable = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell");

var firstVisibleRow = objTable.firstVisibleRow ;

var selectedVisibleRow = parseInt( session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows );

var selectedTableRow = firstVisibleRow + selectedVisibleRow ;

var order = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getCellValue(selectedTableRow ,"AUFNR") ;

var str1 = order ;

var str2 = "00";

var str3 = "000" ;

var order = str2.concat(str1);

var rfc = session.createRFC("ZBAPI_ISUSMORDER_USERSTATUSSET") ;

rfc.setParameter("NUMBER", order);

rfc.setParameter("VALUE", "E0014");

rfc.requestResults(JSON.stringify(["RETURN"]));

rfc.send();

var result = JSON.parse(rfc.getResult("RETURN"));

if (result.NUMBER == str3 ) { session.findById("wnd[0]/tbar[1]/btn[8]").press();

session.findById("wnd[0]/sbar").setMessage( " Order backlogged", "I" ) ; }

else

{

session.findById("wnd[0]/tbar[1]/btn[8]").press();

session.findById("wnd[0]/sbar").setMessage( " order backlog failed ", "I" ) ;

session.utils.log(result.NUMBER);

session.utils.log(result.MESSAGE);

session.utils.log(result.NUMBER);

session.utils.log(result.LOG_NO);

session.utils.log(result.LOG_MSG_NO);

session.utils.log(result.MESSAGE_V1);

session.utils.log(result.MESSAGE_V2);

session.utils.log(result.MESSAGE_V3);

session.utils.log(result.MESSAGE_V4);

}

Error as below :

Unable to get property 'textContent' of undefined or null reference at GuiRFC.prototype.getResult

Kindly suggest.

Best regards,

pradeep.

Read only

0 Likes
1,283

Hi,

Your script looks ok to me. My guess is the problem is with SP02. I know we fixed quite a few defects in how RFCs are processed during runtime with SP03.

Just try again after the upgarde.

Best Regards,

Clemens

Read only

0 Likes
1,283

Hi Clemens, Also when I try these lines of code

rfc.requestResults(["RETURN"]);

rfc.send();

var result = JSON.parse(rfc.getResult("RETURN"));

I get the following error .... Step 2 () returns: 101 [Personas XML element with specified path not found.]

Kindly suggest.

Best regards,

pradeep .

Read only

0 Likes
1,283

Hi,

yes, that's another indication that the RFC failed in the backend. The client is trying to parse an empty string as an xml document and fails. Because the rfc failed in the backend we received an empty string.

Please try again with SP03.

Cheers,

Clemens

Read only

0 Likes
1,283

Thank you Clemens. Best regards, pradeep.

Read only

0 Likes
1,283

Hi Clemens, Just a quick question. When I set a break point in bapi ,it is not hitting the BAPI ,why is this happening ? Is it the same reason that you mentioned ? " that's another indication that the RFC failed in the backend. The client is trying to parse an empty string as an xml document and fails. Because the rfc failed in the backend we received an empty string." Best regards, pradeep.

Read only

0 Likes
1,283

Hi,

yes, the first step of executing an RFC in the backend is to map the received importing parameter data to a corresponding data structure (which is created dynamically). In SP02 when this mapping fails the processing ends without an error message. In SP03, you should at least get some form of error message that you can inspect with GuiRFC. getExceptionText(), getExceptionType(). Only if the mapping was successful, the RFC is called and the system will hit your external breakpoint.

Thanks,

Clemens

Read only

0 Likes
1,283

Thank you Clemens. Best regards, pradeep.