Solved

field name as variable

Posted on 2010-09-22
5
1,580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 - Query with Sub Query? 7 114
RPG Free Prototypes using  *LDA data 5 219
Data transfer to iSeries failing with message ID SQL0462 6 180
DS3512 Replace HDD 2 58
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

697 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