Showing results for 
Search instead for 
Did you mean: 

SAP Personas script short help

0 Kudos


I am currently learning to use FM in scripts, and I cannot go past the problem:

I am fetching data from FM and it comes back when I put it in the message. That's ok.



But when putting this result into a text field, I receive this message





var material = session.findById("wnd[0]/usr/subPersonas_171517773671885/txtPersonas_171628553481856").text;
var plant = "5590"

var oRFC = session.createRFC("BAPI_MATERIAL_STOCK_REQ_LIST");
oRFC.setParameter("MATERIAL", material);
oRFC.setParameter("PLANT", plant);

var _ADDRESS = oRFC.getResultObject("MRP_STOCK_DETAIL");
var _RETURN = oRFC.getResultObject("RETURN");



session.findById("wnd[0]/usr/subPersonas_171517773671885/txtPersonas_171620992281151").text = test;




Also, can please someone help me write a script for fetching data directly from the table?

I tried and tried, but couldn't succeed. Hours have pasted and I don't know how to approach this. Already searched the internet, but no success.

For example, I would use FM "RFC_READ_TABLE" to read MARD table with filter material and plant, and receive back one field "VMINS".



View Entire Topic
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Martin,

To the first question, the answer is really simple. The .text property of your screen field expects a string value, but the unrestricted stock field comes from the BAPI as a numeric value. All you have to do is turn that into a string, by using the .toString() function.  So, simply change your line 16 to 
var test = _ADDRESS.UNRESTRICTED_STCK.toString();
and it will work.

As for the use of the RFC_READ_TABLE function module: Let's say, you are interested in reading the unrestricted stock directly via this FM instead of the BAPI. So, you need the MARD-LABST field value for the selected material, plant and storage location.

In the below example, material ID is FG126, plant is 1710 and storage location is 171A. The corresponding script will look like this, writing the unrestricted stock into your screen field or displaying an alert with the same value:


var oRFC = session.createRFC("RFC_READ_TABLE");
oRFC.setParameter("QUERY_TABLE", "MARD");
oRFC.setParameter("FIELDS", [{"FIELDNAME":"LABST"}]);
oRFC.setParameter("OPTIONS", [{"TEXT":"MATNR = 'FG126' AND WERKS = '1710' AND LGORT = '171A'"}]);
var _DATA = oRFC.getResultObject("DATA");
session.findById("wnd[0]/usr/txtPersonas_171631923761773").text = _DATA[0]["WA"];


Keep in mind though that when using this FM, the user running the flavor would need the corresponding table authorization which may not always be provided - so this is not an ultimate solution to read table content. I would recommend relying on BAPIs instead. Not saying that there is no possibility for authorization issues there, but it's probably less likely if the user has the proper authorizations related to the application area of the BAPI.


0 Kudos
Tamas, working like a charm. My days of trying to solve this are in the past (I even created query SQVI and then recorded steps to read this data). To much time spend for just one function. Thank you wery much. Also thank you for table read and warning about using it.