field symbol

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

field symbol

Post by Welcome » Mon Mar 26, 2018 2:51 pm

Hi.. Everyone..

How can i use field symbol ?
ex:
<FIELD> := 'FIni01'
UPDATE <FIELD> FROM <A01> WITH_KEY(#ABC)

who can tell me about <FILED> RDML Code???

MarkDale
Posts: 103
Joined: Wed Dec 02, 2015 10:06 am

Re: field symbol

Post by MarkDale » Mon Mar 26, 2018 3:39 pm

Could you explain a bit more about what you are trying to do.

Is 'Fini01' the name of a field that you want to update, or the value you want to update?

Normally if you want to update fields you would do something like:

Group_By Name(#SomeFields) Fields(#xEmployeeSurname #xEmployeeGivenName)

#xEmployeeSurname := 'MyValue'
Update Fields(#SomeFields) In_File(xEmployee) With_Key(#xEmployeeIdentification)

or

#xEmployeeSurname := 'MyValue'
Update Fields(#xEmployeeSurname #xEmployeeGivenName) In_File(xEmployee) With_Key(#xEmployeeIdentification)


You would not normally use '<FIELD>' in your code.

Welcome
Posts: 16
Joined: Mon May 08, 2017 3:15 pm

Re: field symbol

Post by Welcome » Mon Mar 26, 2018 4:03 pm

sorry ..my mean..
<FIELD> is Dynamic field name..
<FIELD> name maybe IS 'A001' or 'A002' or 'B001' Or 'C001' .....
so... i want..

<FIELD> := (TEXT) => #A001 := 'TEXT' or #B001 := 'TEXT'

UPDATE <FIELD> FROM <FILE> WITH_KEY(#AA)
= > UPDATE #A001 FROM <FILE> WITH_KEY(#AA) OR UPDATE #B001 FFROM <FILE> WITH_KEY(#AA)

MarkDale
Posts: 103
Joined: Wed Dec 02, 2015 10:06 am

Re: field symbol

Post by MarkDale » Mon Mar 26, 2018 6:02 pm

I think there is no commonly used feature like that in RDML/RDMLX code.

If you are reading data using SELECT_SQL, the SQL instruction can be a string, so you can build up the string any way you want.
That would allow you to specify the field name at run time.

See
https://docs.lansa.com/14/en/lansa015/c ... free_p.htm


Or depending on what you want to do with your code, you might get what you want by calling a subroutine that receives the field name and the value, and maps it into the appropriate field using a CASE statement.

Code: Select all

subroutine CONVERT parms(#Name #Value)

CASE #Name
When = 'A001'
#A001 := #Value
When =  'A002'
#A002 := #Value
...

endcase
endroutine
Others may have additional suggestions.

KevinW
Posts: 28
Joined: Thu May 26, 2016 11:18 am

Re: field symbol

Post by KevinW » Tue Mar 27, 2018 11:04 am

/* function where you want to "dynamically" set a field to a value */
/* #FIELD contains the name of the field you want to set without leading # */
/* #VALUE contains the value you want to set it to */
/* The field you want to set the value for must be used in this function */
Exchange Fields(#FIELD #VALUE)
Call Process(*DIRECT) FUNCTION(DYNAMIC)
<do whatever with the field>

/* DYNAMIC function that sets the field to the value */
FUNCTION OPTIONS(*DIRECT)
Use Builtin(EXCHANGE_ALPHA_VAR) With_Args(#FIELD #VALUE)
Return

If you want to set a numeric value, use EXCHANGE_NUMERIC_VAR in the above code instead of EXCHANGE_ALPHA_VAR. If #FIELD & #VALUE are both defined as fields in the data dictionary then this will work without defining them in each function. Alternatively, use INCLUDE in both functions. This may not be optimal as far as performance is concerned.

As far as doing I/O is concerned, I don't know how to do that in RDML.

jyoung
Posts: 652
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: field symbol

Post by jyoung » Wed Mar 28, 2018 12:59 am

Just thinking out loud here, but it looks like you are trying to dynamically build field / values and then update a table with those fields.

You might be able to do this with a variant and a keyed collection.

Code: Select all

define_com class(#PRIM_KCOL<#PRIM_VAR #STD_TEXT>) name(#MyFields)

#MyFields<'MyField1'> := 'My Value'
#MyFields<'MyField2'> := 205
The update command is not dynamic so you will have to build up a custom update SQL string. Should be doable by spinning through the collection and appending the field for each item. You will likely have to use the variant functions to determine types while building up the sql.

Then you could use the SQL free format to execute your update string, STD_NUM is just a dummy field as I think you have to have at least one.

Code: Select all

#wk_Sql := "my update string"

select_sql Fields(#STD_NUM) Using(#wk_Sql)
endselect.
- Joe

KevinW
Posts: 28
Joined: Thu May 26, 2016 11:18 am

Re: field symbol

Post by KevinW » Wed Mar 28, 2018 9:13 am

The other thing that occurs to me is that this is perhaps a code generation question, so that may mean creating and using a template to generate the requisite code.

It would also be useful to know what the actual problem is that needs an answer like dynamic field processing.

Post Reply