Solved

field name as variable

Posted on 2010-09-22
5
1,534 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

947 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

20 Experts available now in Live!

Get 1:1 Help Now