Solved

field name as variable

Posted on 2010-09-22
5
1,523 Views
Last Modified: 2012-08-13
Hi,

I have the following situation:
a data structure defined as:

File1Fields       E DS                  Extname(File1)

in File2 (fldname,value)  I have all the field names of File1 and their values (fld1,val1 ; fld2, val1).

now, i want to initialize File1Fields with the values from file2,

File1Fields.fld1 would equal a value of fld1 from File2 and so on...

The problem is how to reference  those fields in File1Fields without hardcoding their name
and having only field name in a variable (field) of File2.
if there would be a way to iterate through a data structure than there would not be a problem:

File1Fields(i) = value;

Any suggestions ?
0
Comment
Question by:iskibinska
  • 4
5 Comments
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 33743154
Hi Iskibinsa,

What you can do is to use fields from file 2, for creating a SQL insert or update command .
(Dynamic imbedded SQL)

Good Luck,
Murph


0
 

Author Comment

by:iskibinska
ID: 33743451
Hi Murph,

Could you send me a code snippet ?
i am not sure if i follow your idea

Thanks
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 33743848
Just an example to get the idea, not sompiled, not tested:
D**************************************************                                                                

D SQLSTMT         S           1024A   

D**************************************************                                                                

 /free

    Eval SQLSTM = 'INSERT INTO FILE1 (' + Field1 + ', 'Field2 + ','    

                + Field2 + ', 'Field3 + ',' + Field4 + ') Values(' +    

                + Val1 + ', 'Val2 + ',' + Val3 +',' + Val4 + ')

 /end-free

C*************************************************************

C* Prepare STMT as initialized in declare section            *

C*************************************************************

C/EXEC SQL

C+ PREPARE S1 FROM :SQLSTM

C/END-EXEC

C*

C*************************************

C* Declare Cursor for STMT           *

C*************************************

C/EXEC SQL

C+ DECLARE C1 CURSOR FOR S1

C/END-EXEC



C**********************

C* Open Cursor        *

C**********************

C/EXEC SQL

C+ OPEN C1 

C/END-EXEC

C*

C******************

C* Close cursor   *

C******************

C/EXEC SQL

C+  CLOSE C1

C/END-EXEC    

Open in new window

0
 
LVL 16

Accepted Solution

by:
theo kouwenhoven earned 500 total points
ID: 33743927
Hi Hi Iskibinsa,

See also this link for more info and examples, I hope it will help


http://www.mcpressonline.com/programming/sql/using-dynamic-sql-in-cl-part-1running-action-queries.html


GoodLuck,
murph
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 33783789
And does it work????
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now