× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



There are only 2 ways that I know of to do this.  One is to write a code
generator program, the other is via embedded SQL.

Here is a sample of the embedded SQL.  Hope this helps!!!


Thanks,
Tommy Holden


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Lim Hock-Chai
Sent: Friday, March 18, 2005 10:45 AM
To: RPG programming on the AS400 / iSeries
Subject: RE: Variable Variable names 


Clarify.  

Datastructure mentioned below should be an external datastructure.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Lim Hock-Chai
Sent: Friday, March 18, 2005 10:26 AM
To: RPG programming on the AS400 / iSeries
Subject: RE: Variable Variable names 


There is no such bif in RPG.  It is possible if all those variables are in a
datastrucure.  You can use an api to get a list of field location of the
datastructure and then use %subst to get the value.



-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of PAPWORTH Paul
Sent: Friday, March 18, 2005 9:28 AM
To: rpg400-l@xxxxxxxxxxxx
Cc: GAZIN Florence; DEVILLE Jacques
Subject: Variable Variable names 


Does any one know if it is possible in RPG (or any other i_series)
language to do the following

 

Ws_work_zone = %pgmvar(var) 

 

%pgmvar would be a function which would allow you to get the contents of
a variable , whose name is contained in a variable.

 

Eg if in my imaginary function var contains the name of a field  'FRED'
,  and FRED contains 'ABC' ,  I would end up with 'ABC' in ws_work_zone

 

Many thanks in advance

-- 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


-- 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


-- 
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

     H DFTACTGRP(*NO)
     H OPTION(*SRCSTMT: *NODEBUGIO: *NOSHOWCPY)

      /copy prodkr/qcopysrc,clcmdexec
      /copy prodkr/qcopysrc,getcurdb

     ?* SQLDA Descriptor Area
     D SQLDA           DS
     D  SQLDAID                1      8A
     D  SQLDABC                9     12B 0
     D  SQLN                  13     14B 0
     D  SQLD                  15     16B 0
     D  SQL_VAR                      80A   DIM(400)
     D  SQL_Data_Type         17     18B 0
     D  SQL_Var_Len           19     20B 0
     D  SQL_Resrvd            21     32A
     D  SQL_Data_Pntr         33     48*
     D  SQL_Null_Ind          49     64*
     D  SQL_Name_Len          65     66B 0
     D  SQL_Col_Name          67     96A

     ?* SQLDA Variable Data
     D SQLVAR          DS
     D  SQLTYPE                1      2B 0
     D  SQLLEN                 3      4B 0
     D  SQLRES                 5     16A
     D  SQLDATA               17     32*
     D  SQLIND                33     48*
     D  SQLNAMELEN            49     50B 0
     D  SQLNAME               51     80A

     ?* SQLDA Variable Data (Extended)
     D SQLVAR2         DS
     D  SQLLONGL               1      4B 0
     D  SQLRSVDL               5     32A
     D  SQLDATAL              33     48*
     D  SQLTNAMELN            49     50B 0
     D  SQLTNAME              51     80A

     ?* Work Variables
     D File            s             10a
     D Lib             s             10a
     D TempFile        s             10a
     D TempLib         s             10a
     Drowcountx        s             10I 0
     DOrdinal          s             10I 0
     DColName          s             10a
     DDataType         s              8a
     DLength           s             10i 0
     DScale            s             10i 0
     Dn1               s              4b 0
     DPuNo             s              6a
     DDatabaseName     s            100a
     D XLSPath         s            100a
     D SQLSelect       s           5000a   Varying
     DColumnNumber     s             10i 0
     D RecordData      s          32766a
     DElement          s             10i 0

     ?* Parameter Entry
     C     *Entry        PList
     C                   Parm                    FileName         20
     C                   Parm                    TemplateFile     20
     C                   Parm                    XLSPath

     ?* SQL Error Trapping
     c/exec sql
     c+ Whenever SQLError Continue
     c/end-exec

      /free

       //?*    Extract The Input File Name
       //?*     & Load The Output Path If Not Specified

       If XLSPath=*Blanks;
          XLSPath='/tmp/xl.xls';
       EndIf;
       File=%Subst(FileName:1:10);
       Lib=%Subst(FileName:11:10);
       TempFile=%Subst(TemplateFile:1:10);
       TempLib=%Subst(TemplateFile:11:10);

       //?*  Override The Database File Being Processed

       CmdStr='OVRDBF '+%Trim(File)+' '+
             %Trim(Lib)+'/'+%Trim(File)+
             ' Share(*Yes)';
       CmdStrSize=%Len(%Trim(CmdStr));
       monitor;
       Run(CmdStr:CmdStrSize);
        on-error;
       endmon;

       //?* Build The Dynamic Excel Generation Program

       ExSR SQLSelectBuild;
      /end-free

     c/exec sql
     c+ Prepare SQLExtract From :SQLSelect
     c/end-exec
     c                   Eval      SqlN=1
     C/exec sql
     c+ Describe SQLExtract Into :SQLDA
     c/end-exec
     c                   Eval      SqlN=SqlD
     c                   Eval      SQLABC=SqlN*%Len(SqlVar)+16
     c/exec sql
     c+ Describe SQLExtract Into :SQLDA
     c/end-exec
     c/exec sql
     c+ Declare SQL_Extract Cursor For SQLExtract
     c/end-exec
     c/exec sql
     c+ open SQL_Extract Using Descriptor :SQLDA
     c/end-exec
     c                   DoU       SqlCod=100
     c/exec sql
     c+ Fetch SQL_Extract Into Descriptor :SQLDA
     c/end-exec
     c                   If        SqlCod=100
     c/exec sql
     c+ Close SQL_Extract
     c/end-exec
     c                   Leave
     c                   EndIf
     c                   ExSR      ExtractData
     c                   EndDo
      /free

       //?* Terminate

        *inlr = *on;

       BegSR ExtractData;
           For Element = 1 By 1 To SqlD;
              SQLVAR=SQL_VAR(Element);
           EndFor;
       EndSR;

      /end-free

     ?*
     ?*  Build SQL Select Statement From Template File
     C     SQLSelectBuildBegSR
     C                   Eval      SQLSelect='Select '

     ?* Declare The SQL Cursor
     c/exec sql
     c+ Declare StringBuild Cursor
     c+   For Select Column_Name,Data_Type,Length,Numeric_Scale,
     c+           Ordinal_Position From SYSCOLUMNS
     c+        Where System_Table_Name= :TempFile And
     c+                 System_Table_Schema = :TempLib
     c+         Order By Ordinal_Position
     c/end-exec

     ?* Open The SQL Cursor
     c/exec sql
     c+ Open StringBuild
     c/end-exec

     ?* Error Occurred On Open
     c                   If        SQLCod<0
     c                   LeaveSR
     c                   EndIf

     ?* Load The Source Code For All Fields In the File
     c                   Eval      rowcountx=4
     c                   DoU       SQLCod=100
     c/exec sql
     c+ Fetch StringBuild Into :ColName,:DataType,:Length,
     c+             :Scale:n1,:Ordinal
     c/end-exec

     ?* End Of Records
     c                   If        SQLCod=100
     c                   Leave
     c                   EndIf

     ?* Error On Fetch
     c                   If        SQLCod<0
     c                   Iter
     c                   EndIf
     c                   Eval      SQLSelect=%Trim(SQLSelect)+' '+
     c                             %Trim(ColName)+','
     c                   EndDo
     c                   Eval      Length=%Len(%Trim(SQLSelect))
     c                   Eval      SQLSelect=%Subst(SQLSelect:1:Length-1)
     c                   Eval      SQLSelect=%Trim(SQLSelect)+
     c                             ' From '+%Trim(Lib)+'/'
     c                             +%Trim(File)
     c                   EndSR

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.