Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

field name as variable

Posted on 2010-09-22
5
Medium Priority
?
1,658 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

927 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