9 Replies Latest reply on May 27, 2017 7:20 PM by mainframe

    using field names as input in a layout 'as input'

    mainframe

      Is it possible at all with FM12 or higher ...

       

      To generate data: I want that a user is able to provide known 'table/field names' on a layout input field name, which in turn gets resolved in a script.

       

      e.g.

       

      Input field on layout: " RENAME   "  &   table:field1   & " NEWNAME("  & table:field2 & ")  "

       

      using a script with SET VARIABLE= does work to resolve it, but that's not what I need.

       

      Has anybody even tried this?

       

      Gene

        • 1. Re: using field names as input in a layout 'as input'
          philmodjunk

          I'm not at all clear on what you are describing, but you can set a field to a value by using the field's name if you use the Set Field By Name script step. You can "read" the data from a field by name by using the Getfield function.

           

          Both should be used with care. You should not put the "tableoccurrenceName::FieldName" reference as quoted text if you can avoid doing so as this locks your solution to those table occurrence and field names. Renaming a field in Manage Database could then Break your script or calculation. GetFIeldName is a function that becomes very handy in this type of indirect referencing.

          • 2. Re: using field names as input in a layout 'as input'
            mainframe

            Hi

             

            thanks for the answer . . .

             

            The same data I can use in a SET VARIABLE = script and it resolves all field names as required and works fine.

            SET VARIABLE $$LINE1 value: " RENAME   "  &   table:field1   & " NEWNAME("  & table:field2 & ")  "

             

            however since there are hundreds of field names & > 100 tables  I want to open the possibility that such a value string can be passed as an INPUt  from a layout to a variable in a script to achieve the same effect.

             

            I know to some it sounds strange this issue - but for another IT  platform there is a need to 'create' any kind of commands.

            So such a command line to be generated could have up to 50 FM field names ....

             

            Regards

            gene

            • 3. Re: using field names as input in a layout 'as input'
              mainframe

              FYI - RENAME could be anything ... it is here just as an example and the generated commands are not intended to change to content of the FM database at all.  The generated table with commands will be exported to a flat text file.

               

              Gene

              • 4. Re: using field names as input in a layout 'as input'
                philmodjunk

                Sounds like you want code like this example:

                 

                Set Field by name [ get ( scriptparameter ) ; getField ( get ( scriptParameter ) + 1 ]

                 

                this takes whatever field is identified with in the script parameter and adds one to the value stored in that field.

                 

                The script parameter expression might be getfieldname ( student::count ) for one button and it might be getfieldname ( player::count ) for a different button.

                 

                Any text that evaluates as tableoccurrence::Field can be passed to this script.

                • 5. Re: using field names as input in a layout 'as input'
                  mainframe

                  Thanks ... it goes in that direction .. but then it becomes too complicated for a user ....

                   

                  Since all is free format on such an input field , buttons etc are not an option.

                  I am talking here about >100 tables with >700 field names.

                   

                  I guess I have to drop this idea.

                   

                  Many thanks again for all the great efforts.

                  • 6. Re: using field names as input in a layout 'as input'
                    philmodjunk

                    Then I really have no idea what you are describing here.

                     

                    Without an example, I can't tell what "rename" is supposed to accomplish.

                     

                    What I demonstrated is completely transparent to the user. They would never even know that this technique was or was not in use.

                    • 7. Re: using field names as input in a layout 'as input'
                      mainframe

                      'Without an example, I can't tell what "rename" is supposed to accomplish.'

                      maybe look at it as a  free format text file generator based on information supplied in  a single input field on a layout....  forget about 'rename' etc. as such ... the text can be anything the user wants to be generated.

                       

                      We import tens of thousand of records weekly from a mainframe server to many tables for research/verifications.

                       

                      The idea is, that a user can generate anything in free format - the only thing a user has to know is a table name and one or more field names.

                      e.g. a command(=text) on the input field to be generated could look like this, whereby up to 70 field names could be used in any order in a single 'input field name' on the layout. :

                      " CHECK  "  &   table1::NAME  & 

                      " LOCATION("  &  table1::LOCATION & ")"  &

                      " FLOOR('"  & Trim(table1::FLOOR) & "')"

                       

                      Result e.g.

                      'CHECK GENE LOCATION(OXFORD) FLOOR(3)'

                      'CHECK JOHN LOCATION(BOSTON) FLOOR(17)' etc.

                       

                      For each occurrence in the current table(found set) a record gets added to a temp table which in turn gets exported at the end to a flat file.

                       

                      The created text file can than be used for whatever purpose... on a mainframe again etc.

                       

                       

                      • 8. Re: using field names as input in a layout 'as input'
                        TomHays

                        mainframe wrote:

                         

                        The idea is, that a user can generate anything in free format - the only thing a user has to know is a table name and one or more field names.

                        e.g. a command(=text) on the input field to be generated could look like this, whereby up to 70 field names could be used in any order in a single 'input field name' on the layout. :

                        " CHECK " & table1::NAME &

                        " LOCATION(" & table1::LOCATION & ")" &

                        " FLOOR('" & Trim(table1::FLOOR) & "')"

                         

                        It sounds like you want the user to type in

                        " CHECK " & table1::NAME &

                        " LOCATION(" & table1::LOCATION & ")" &

                        " FLOOR('" & Trim(table1::FLOOR) & "')"

                        into a field on a layout.

                         

                        Then you want the script to use that as a calculation to apply to each record in the found set.

                        You want assistance in figuring out how you can apply that user-provided calculation instead of hard-coding it into your script.

                         

                        If that is the situation, the missing piece is the Evaluate() function.

                        For example you may be looking for the script step:

                        Set Variable[$evaluatedCalc; Value:Evaluate(MyTable::theUserProvidedCalc)]

                        which you can apply in a loop for each record.

                         

                        -Tom

                        1 of 1 people found this helpful
                        • 9. Re: using field names as input in a layout 'as input'
                          mainframe

                          Thanks Tom - you worded it much better than me.

                           

                          Indeed I want apply a 'user defined calculation' instead of a hard coded one.

                           

                          I try it out ...