2024 May 21 11:43 AM - edited 2024 May 21 11:45 AM
Hi.
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);
oRFC.requestResults(["MRP_STOCK_DETAIL","RETURN"]);
oRFC.send();
var _ADDRESS = oRFC.getResultObject("MRP_STOCK_DETAIL");
var _RETURN = oRFC.getResultObject("RETURN");
session.utils.alert(_ADDRESS.UNRESTRICTED_STCK);
var test = _ADDRESS.UNRESTRICTED_STCK;
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".
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'"}]);
oRFC.requestResults(["DATA"]);
oRFC.send();
var _DATA = oRFC.getResultObject("DATA");
//session.utils.alert(_DATA[0]["WA"]);
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.