Generic / variable reference to json array field name
hi -- I have a javascript function that I want to make variable-based, so it can be used throughout my application.
It creates and parses a json object. I ultimately need to reference a field in that object. The field name is the name of database column
that was queried in the called application process.
For example, if the query executed was: select my_id from my_table where my_name = 'the_name', and the object that holds the parsed
AJAX response is jsonobj, then I need to reference: jsonobj.row[0].my_id
I don't want my_id to be hardcoded in the reference. Rather, I want to pass the string 'my_id' into the javascript function (let's call
the variable dest_item_name) and then reference (something like): jsonobj.row[0].<dest_item_name>.
(How) can I do this? Please tell me I can! :)
Thanks,
Carol
Hmmm, well, I thought I described my goal in the first post... but I'll try again.
hi -- I have a javascript function that I want to make variable-based, so it can be used throughout my application.
The function does this:
ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=LOOKUP_VALUE',0);
ajaxRequest.addParam('x01', source_item_value); -- equal to 'basin'; this is the value that will be used to lookup the value of dest_column_name
ajaxRequest.addParam('x02', source_column_name); -- equal to 'my_name'; this is the name of the database table column that will be = 'basin'
ajaxRequest.addParam('x03', dest_item_name); -- equal to P3_MY_ID; this is the name of the page item that will be set to the returned value
ajaxRequest.addParam('x04', dest_column_name); -- equal to 'my_id'; this is the name of the table column that gets queried
ajaxRequest.addParam('x05', lookup_table_name); -- my_data; this is the table to query
ajaxResponse = ajaxRequest.get();
if (ajaxResponse) {
var jsonobj= ajaxResponse.parseJSON();
$s(dest_item_name, jsonobj.row[0].my_id);
The goal of this javascript and application procedure is to have a generic method for looking up values
in the database. In the above example, I want to query my_data to get the value of my_id where my_name = 'basin'.
The application procedure LOOKUP_VALUE uses the x variables to construct that SQL query. For the above values, the
returned query is: select my_id from my_data where my_name = 'basin';
Then I set my dest_item_name (P3_MY_ID) to the value in the parsed json object. But as you can see, if I'm querying a different
table with different column names, the reference to jsonobj.row[0].my_id won't work, because the database column name
will be different. I've gotten around this by aliasing the queried field to RETURN_VALUE, so I'm just doing:
$s(dest_item_name, jsonobj.row[0].rerturn_value); -- which works great.
But my goal was to somehow be able to reference the variable dest_item_name (which is the name of the queried database
column) in my $s set statement.
Possible? If so, I'm sure it could come in handy at some point.
Thanks,
Carol
Similar Messages
-
Variable Reference of Instance Name
While I have had no problems with bracket evaluation of
constants and number variables, I don't know the coding convention
for brack evaluation of a string.
I get an undefined for oBtnName
oBtnName = new Object;
oBtnName = this["mcWing" + aWingColor[nIdx] + "Btn"];
where aWingColor is an array of strings. So I tried setting
aWingColor[nIdx] to variable thinking the inside array brackets
were goofing this up:
oBtnName = new Object;
var sWingColor:String = aWingColor[nIdx];
oBtnName = this["mcWing" + sWingColor + "Btn"];
trace (sWingColor + " " + oBtnName._name );
returns Pink undefined
and interactive debug is showing oBtnName as undefined as
well.
So, then I tried this
oBtnName = this["mcWing" + sWingColor._value + "Btn"];
and then this
oBtnName = this["mcWing" + "[sWingColor]" + "Btn"];
and so on and so on. . . .Isn't
this["mcWing" + aWingColor[nIdx] + "Btn"]=new Object()
the same as
var oBtnName:Object = new Object;
oBtnName = this["mcWing" + aWingColor[nWingRollIdx] + "Btn"];
I am doing this to shorten the reference name
Here is the rest of the code
mcWingPinkBtn.onRollOut = function () {
clearInterval(nInterval);
nWingRollIdx = 1;
nInterval = setInterval(fFadeOutWing, 1);
function fFadeOutWing():Void {
var oBtnName:Object = new Object;
oBtnName = this["mcWing" + aWingColor[nWingRollIdx] +
"Btn"];
oBtnName._alpha -= nAlphaIncrement;
----oBtnName is undefined here so the following if doesn't
work -----
if(oBtnName._alpha <= nAlphaStart) {
oBtnName._alpha = nAlphaStart;
clearInterval(nInterval);
updateAfterEvent(); -
How to find the field name of variable system information on SAP B1
Hi All,
I recently wanted to create a simple SQL query to list all ITEM MASTER DATE where the weight is blank. This is so i can get a list of all items with the weight information missing from the system to investigate.
It turns out the weight field within the SALES DATA tab is a system variable. When i pull the OITM table up within the query generator i can not identify where this variable name come up without guessing which can give me the wrong information.
Can someone point me into the direction on how to assisocate variable to a field name within SAP B1. This is also another problem if i wanted to display variable within Crystal report layout.
RegardsHi Nick Dang,
Try This
SELECT T0.[ItemCode], T0.[ItemName], T0.[SalUnitMsr], T0.[SHeight1], T0.[SWidth1], T0.[SLength1], T0.[SVolume], T0.[SWeight1] FROM OITM T0 WHERE T0.[ItemCode] =[%0]
Thanks,
Srujal Patel -
Using variable with the same name as field name?
I have a complex proc where I have variables with the same name as field name used on a query. something like this:
SELECT a.id_table WHERE a.id_table = id_table
where the last id_table is a parameter sent to the proc:
declare procedure myproc(id_table int)
Is there any way or notation to declare the variable inside the query as a variable or I have to use a different name?Well, variables are not the only thing you have to change if you want to switch to Oracle.
Although I don't think it is good practice (to use variable name same as column name), here is one example how you can achieve it using EXECUTE IMMEDIATE and bind variable
SQL> select deptno, count(1)
2 from scott.emp
3 group by deptno;
DEPTNO COUNT(1)
30 6
20 5
10 3
SQL> set serveroutput on
SQL> declare
2 deptno varchar2(10);
3 i number;
4 begin
5 deptno:=10;
6 execute immediate
7 'select count(1) from scott.emp where deptno=:deptno' into i using deptno;
8 dbms_output.put_line('OUT ---> '||i);
9 end;
10 /
OUT ---> 3
PL/SQL procedure successfully completed.
SQL> Message was edited by:
tekicora
Message was edited by:
tekicora -
Used variable substitution to substiture the field 'date' in file name
Hi gurus
I have used variable substitution to substiture the field 'date' (dd/MM/yyyy/hh/mm/ss) in the file name so when empty payload (a valid xml ) is generated by Message mapping then the communication channel is failing by showing the following error
File processing failed with com.sap.aii.adapter.file.configuration.DynamicConfigurationException: Error during
variable substitution: com.sap.aii.adapter.file.varsubst.VariableDataSourceException: The following variable was not found in the message payload
: date
As of now the business is not getting effected as the business scenarion needs only customer master data at the reciever side But when ever there is no custmer master data in the sourse side the message mapping is generating an empty payload and the communication channel is failing ( so it is an internal issue and is there any way which could solve the both (ie the business must not get effected and as well the communication channel must not fail)
any coments on this will be higly apreciated
thanks and regards
sandeepHi Sandeep -
Yes If you use the Variable substitution from the payload , that perticular field has to be generated in the target structure.
To handle this You can do the following:
Sourcefield --->exists -> IfThenElse-->TargetField
Where SourceField>exists(node function)-> If
SourceField -
>Then
CurrentDate(Date Function)----->Else
Hope this will help !!
Regards.
Jeet. -
Is it possible to store a field name in a variable, then assign it a value?
Good day, everyone!
I am working on a program in which there are many different amount fields in which an amount may be assigned. For reusability purposes, I was wondering if it would be possible to write a routine that identifies the target amount field, stores it in a variable that is passed back to the calling program, and then assigns a value to it. There may be different structures having the same field name; what I'm trying to do is avoid having to code a huge IF or CASE statement for each structure. For example:
Structures S1, S2, and S3 have some fields identically named. Call one of them F1.
What I'd like to do is call a routine that identifies "F1" as my target field to populate. Then, upon return, I can assign it to the desired structure. Kinda like this:
S1-fieldname = 24.17. (but fieldname isn't a true field in the structure -- it would hold the value of the true field, "F1").
I realize this might not even be possible, but given how talented the folks are on this forum, I thought I should at least pose the question.
As always, points given for all helpful answers, and thank you!!
DaveOk. I gave that a shot, but what happens is that my ASSIGN COMPONENT statement doesn't work. It gets a sy-subrc of 4, and <column> remains unassigned. The program then abends on the line to assign <a1>-trbtr's value to the field because of <column> being unassigned.
DATA:
w_setname TYPE setleaf-setname,
w_column_name(20) TYPE c.
ASSIGN COMPONENT w_column_name OF STRUCTURE wa_expense_ng_report
TO <column>.
<column> = <a1>-trbtr.
Any thoughts on what I might be doing wrong? -
Using table field name as a variable
Hi ,
Is it possible to map some values to a field in a Ztable , if I have the field name of the Ztable in a variable.
For ex:
I have a ZTABLE -- which has some fields - ZF1 and ZF2.
In my code, I determine the field in which I want to put data at runtime. For ex, in my code i determine at runtime I want to update field ZF2 , but I have this field name in a variable <V_FIELDNAME>
So, Is it possible to do something as:
<V_FIELDNAME> = ZF2.
ZTABLE-<V_FIELDNAME> = <VARIABLE -SOME VALUE>.
and this value should actually maps to ZTABLE-ZF2.
If it is possible , how to do it ?
Thanks-Hi Tamas,
Thanks a lot for ur post ! it did certainly help. However, I need some more help.
Here is what I need -
I will have a string coming up from an interface which would be something like : Val1;Val2;Val3
And in SAP R/3 I have a variable maintained as : Field1;Field2;Field3
Field1 Field2 and Field3 are fields of a ZTABLE.
So , at runtime, using the variable I have to determine which Value goes to which field and then insert this field in ZTABLE.
So, ultimately , code should perform the following actions:
ZTABLE-FIELD1 = Val1
ZTABLE-FIELD2 = Val2
ZTABLE-FIELD3 = Val3
Insert ZTABLE.
Going by code you provided, I can assign individual values, But then ultimately I need to map it to a structure which can be used to insert in a DB table. How can I do this?
Thanks- -
Hi Friends,
While doing GR am geting document number and can see that in MB03. Now in MKPF table there is field called Customs reference number( field name # GTS_CUSREF_NO) , and after putting material document number in MKPF am getting all the detail including Customs reference number.
Now my question is where can I see the detail of Customs Reference number in material document in t code (MB03).
Any pointers
Regardsno reply closing the thrd.
-
Variables for Field Names.
This may be a silly one for ya but I am having a brain fart
now.
I am doing a dynamic form where the form questions are
created fro a database.
The different field names are dynamic variables generated via
itererations (++) from the database table.
The problem is that when I submit the form I need the field
names as the insert or update value to populate the values
statement in the query. I am having a problem locking down the
actual values to use for the insert or update statement.
I will need to use a loop to iterate through the variables.
Look at the code form the form.
Thanks in advance.
GeneToo much code for me to analyze.
But see if any of these development tricks lead the way for
you.
On your action page:
<cfdump var="#form#>
<cfoutput>
<cfloop collection="#form#" item="field">
#field# = #form[field]#<br>
</cfloop>
<cfoutput>
<cfoutput>
#form.fieldNames#<br>
<cfloop list="#form.fieldNames#" index="field">
#field# = #form[field]#<br>
</cfloop>
<cfoutput> -
Trying to reference field name of my record Type in my procedure!
Hello,
I am stuck. I am trying to reference field names in my record type declared in my Package declaration.
Here is an example. Don't be scared, it's a very simple package. I just need some directions what to use to accomplish this.
--look into this part of the package body
FOR cur_rate IN c_rate
LOOP
rate_data(1).field_name := cur_rate.rate_pct;
--field name = AK_PCT, AL_PCT and so on ...
END LOOP;
END rate_tab_qry;
CREATE OR REPLACE PACKAGE rate_pkg IS
TYPE rate_rec IS RECORD (
id cycle_rates.id%TYPE
,cycle cycle_rates.cycle%TYPE
,scac cycle_rates.scac%TYPE
,gbloc cycle_rates.gbloc%TYPE
,code cycle_rates.code%TYPE
,AK_PCT cycle_rates.rate_pct%TYPE
,AL_PCT cycle_rates.rate_pct%TYPE
,AR_PCT cycle_rates.rate_pct%TYPE
,so on...
TYPE cycle_rate_tab IS TABLE OF rate_rec INDEX BY BINARY_INTEGER;
PROCEDURE rate_tab_qry(rate_data IN OUT cycle_rate_tab,
p_id cycle_rates.id%TYPE,
p_cycle cycle_rates.cycle%TYPE,
p_scac cycle_rates.scac%TYPE,
p_gbloc cycle_rates.gbloc%TYPE,
p_code cycle_rates.code%TYPE);
END;
CREATE OR REPLACE PACKAGE BODY rate_pkg IS
PROCEDURE rate_tab_qry(rate_data IN OUT cycle_rate_tab,
p_id cycle_rates.id%TYPE,
p_cycle cycle_rates.cycle%TYPE,
p_scac cycle_rates.scac%TYPE,
p_gbloc cycle_rates.gbloc%TYPE,
p_code cycle_rates.code%TYPE)
IS
CURSOR c_rate IS
SELECT state, rate_pct
FROM cycle_rates
WHERE cycle = p_cycle
AND scac = p_scac
AND gbloc = p_gbloc
AND code = p_code;
BEGIN
rate_data(1).id := p_id;
rate_data(1).cycle := p_cycle;
rate_data(1).scac := p_scac;
rate_data(1).gbloc := p_gbloc;
rate_data(1).code := p_code;
FOR cur_rate IN c_rate
LOOP
rate_data(1).field_name := cur_rate.rate_pct;
--field name = AK_PCT, AL_PCT and so on ...
END LOOP;
END rate_tab_qry;
I need to know, how to reference my field name for each state in my procedure that are in my record type. The problem is it won't allow me to use something like this.
select state || '_PCT
from cycle_rates;
which would eventually show me each state concatenated with '_PCT, e.g. AK_PCT and that's my field names.
For example,
FOR cur_rate IN c_rate
LOOP
rate_data(1).field_name := cur_rate.rate_pct;
--field_name = AK_PCT, AL_PCT and so on...
END LOOP;
I would appreciate it if somene can direct me. Thanks.
Message was edited by:
[email protected]This is a sample output from my cusror. Just to make it easier for you guys to see it.
ST RATE_PCT
AK 0
AL 2
AR 2
AZ 2
CA 2
CO 2
CT 2
DC 2
DE 2
FL 2
Hope it helps. -
Is it possible to use internal table field name as variable?
data : temp_string(10) type c.
data : result type string.
temp_string = 'field1'.
loop at itab1 into str1.
result = str1-temp_string. "error here"
endloop.
HI.
think this code not executable and actually fail to compile.
is it possible to put structure field name with variable?
anyone can help me ? please
thank you.
Regards
BaeYou may use of COMPONENT of your structure.
FIELD-SYMBOLS: <F>.
ASSIGN COMPONENT I OF STRUCTURE F TO <F>.
To find index of component you may use
DESCRIBE FIELD f INTO td.
(But SAP beware us)
Regards -
Dynamic creation of table with variable field-names
HI
I am looking for a way in order to create a table during runtime. The problem is that the field names of the table are provided in another table.
TO illustrate the case at hand, an example:
The initial table contains the fields
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name - Jon
d00587 - last_name - Smith
d00587 - age - 48
d00127 - first_name - Jack
d00127 - last_name - Daniels
d00127 - position - Manager
Now I need to create a table per User that looks as follows:
for user d00587
first_name - last_name - age
**Values
Jon - Smith - 48
for user d00127
first_name - last_name - positioin
Jack - Daniels - Manager
I split the initial table by sorting it according to userID and then looping into an itab with an AT END OF userid, thus I receive the table per user:
Example iTab
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name - Jon
d00587 - last_name - Smith
d00587 - age - 48
However I have no clue on how to create a new internal table with field-names = attribute_name.
Does anybody have an idea or example code for this?
Thanks a lot for your help,
Kind regards,
MingoloHello Minima
Here is some sample coding:
DATA:
gt_fcat type lvc_t_fcat,
gdo_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_itab> TYPE table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'MARA'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
* I_STYLE_TABLE =
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gdo_data
* E_STYLE_FNAME =
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ASSIGN gdo_data->* TO <gt_itab>.
In your case, you would call the function module with your tables (D00587, D00127). Remove all fields from the fieldcatalog that you do not need before calling the static method.
Regards
Uwe -
Substitution Variable for Field Name - Use in LOV Defintion
Hi,
I need to build an application with a lrage number of fields based on an LOV (Select List). All the LOVs will be sourced from a single table:
LOOKUP_TYPE VARCHAR2(30)
LOOKUP_CODE VARCHAR2(30)
MEANING VARCHAR2(100)
Each field will therefore need a simple LOV of:
select lookup_code, meaning
from
app_lookups
where
lookup_type = 'LOOKUP_TYPE_NAME'
order by 2Not complicated but it will take a long time due to the number of fields (across many pages).
I would like to be able to have the same code for all fields. Something like:
select lookup_code, meaning
from
app_lookups
where
lookup_type = V('THIS_FIELDS_NAME')
order by 2With this code I could simply copy fields around and rename them - the LOVs would automatiically select the right values by using the Field Name to find the correct codes.
A long shot - but worth asking.
Any thoughts?
Thanks,
MartinHi Andy,
Yes I know about Shared Component LOVs but this does not address my issue. I am also not restricting based on a page item value. I just want to restrict dynamically based on the field name.
On a page I will have at least 30 items, each with their own LOV. I can define an LOV for each item (either directly or though shared components) but each needs to be individually coded (where lookup_type = 'XXXX' with XXXX being different for every field).
If possible I would like to dynamically use the field name to select the group of lookup codes that I want - all fields could then have the same code (or potentially the same Shared Component LOV).
Not a major issue, but it would make my life a lot easier!!
Martin -
I'm working on two sheets, one with all the nitty-gritty details of my bills, the other a summary.
When I wanted to put an if() formula that reads a cell in the summary sheet to read from one field in the details screen the Field Name changes. It was working on most of the fields until I got to one set of them then this happened:
when I put in
=IF('Bill/Exp Comparator' :: '12/29/09' J C Penney="","",'Bill/Exp Comparator' :: '12/29/09' J C Penney)
and hit enter I'd get
=IF('Bill/Exp Comparator' :: '12/29/09' '3/9/10' C Penney="","",'Bill/Exp Comparator' :: '12/29/09' '3/9/10' C Penney)
I would delete the '3/9/10' and hit enter again, it would change back to it. I don't know why is it doing it with one field or how to stop it.
This is another reason why I should stick to a Windows' product.MWSibert wrote:
2. I don't know what you mean by:
<startupVolume>:Users:<yourAccount>:Library:Preferences:com.apple.iWork.Numbers. plist
<startupVolume>:Users:<yourAccount>:Library:Preferences:com.apple.iWork.Numbers. LSSharedFileList.plist
These are the paths to two preferences files that could be causing the abnormal behaviour.
Go to the Finder, open a new Finder Window.
In the sidebar, the house icon with your (user)name under it is <yourAccount>. Start there with a double click or single click, depending which view (icons, list or columns) you are using in the Finder Window, to open that item. In the new list that opens, repeat with the next item (Library) in the path.
The last item in the path is a preferences file, identified by the .plist suffix on the filename.
Preferences files are constantly being read, changed and written to by the application, and occasionally become corrupted. Deleting them is a common 'first aid' step. The application (Numbers in this case) will create a new, clean copy of the file when the need arises.
if this is using a script, I'm not practiced at that, and the "LSSharedFileList" part bugs me. "share" with what, where, whom? Is this opening my computer to others without my knowledge?
If your profile is correct (it says you are using Mac OS X v10.4.11), you are unlikely to find the second file (com.apple.iWork.Numbers.LSSharedFileList.plist). This is a file associated with Launch Services, and was introduced in OS X v 10.5. It's on Yvan's machine as he has Numbers set up to Launch as one of his log in items.
I don't mind emailing a template because it's nothing impressive to anybody. Would you mind if I send a template?
Go ahead. Please put "Numbers Ref Field Changes" in the subject line. My address is available in my profile—click my neme to the left of this message to get there.
Regards,
Barry -
Getting an object's field name
In the snippet of code shown below, 'parent' represents a UI dialog, and 'child' represents one of the components of the dialog. What I would like to know is the field name of 'child'. The variable 'fieldName' would contain the name I am seeking, if I knew how to determine the value of 'ii' that corresponds to the object 'child'.
I hope you can help.
Thanks,
Miguel
String getFieldName(Object parent,Component child) {
Class cl = parent.getClass();
Field [] fields = cl.getDeclaredFields();
String fieldName = fields[ii].getName();
// problem: how to get 'ii' that corresponds to 'child'?
return fieldName;
}Is there a way to get the
corresponding array of component objects? It depends on the way the "parent" class is defined.
For example (a BAD example, but an example):
I could have the parent keep it's components in a HashMap, with a key of the component type and a value of an ArrayList that contains each component matching the component type.
This would be very annoying to deal with, and hard to find any given component (whether reflectively or with normal code).
If I can get
the value of a field (Object val =
field.get(parent);), there must be a way to get the
reference to the object that correspond to the pair
'field','parent'.
Thanks.Huh?
What do you think field[1].get(parent) returned?
It's the value that the field is referring to (e.g. the actual object refered to by the field).
I think dubwai's questions about "what are you trying to do" are very relevant. Using reflection like this usually means the design is lacking some important functionality
Maybe you are looking for
-
Problems setting up a Domain - javax.management.InstanceNotFoundException
I am having problems setting up a Domain. The following steps summarize what I have done. 1. Created FooDomain in d:/bea/wlserver6.0/config and created appropriate config.xml, startup scripts, security, etc... (FooDomain boots ok) 2. Moved console.wa
-
Is it possible to transfer songs from a rhapsody account over to itunes
Both of my kids were given I pod touches for christmas and previously had mp3 players that used rhapsody. Is it possible to transfer their music from their rhapsody acconts over to itunes. Also, if they both want the same songs downloaded from the
-
Need help in Fine Tuning this query
Hello Gurus, The below sql's are from Application engine . It runs more than 5 hours to complete . I have fewer knowledge on sql tuning and request to repharse the sql's to perform and complete the program within One hour. PS_GE_GAPS_INV is going thr
-
I am using BI Publisher Template builder for Word 10.1.3.3.1 and I am trying to insert parameter values into reports I am creating.I can select and insert fields okay but how do I insert parameters ?
-
i have iphone 5,after i update to ios 8.1.3 the lasted version,i gain some problems like slowing in any activities i wanna do and there is blue row apears some time while i using my phone,what should i do to fix these???