ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Retrieve what field to use from the value of another field in another file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieve what field to use from the value of another field in another file

    Not sure if the title makes sense or not, but here is what I am wanting to do and not sure if it's possible:

    I have a Trading Partner Profile file. In this file, I will to put the constants and/or fields that should be used to populate another file.

    Example:
    TPFile
    Test1 field can have one of these value: ASN#, INV#, PO#, DELIVERY#, PICKTICKET#
    Key field is Account#

    I want to be able to chain to the TPFile
    Retrieve the value within the Test1 field and use that value as the field name for populating the HEADERFile
    HEADERFile field for sample purposes REF01

    Chain '12345' TPFile; //Test1 is populated with 'PO#'
    if %found(TPFile);
    REF01 = PO# //this PO# field would be the field name within the SHIPMENTFile
    endif;

    I hope I make sense in writing this and not a clue if possible.
    Just trying to find a way to eliminate a bunch of IF or SELECT statements in my program and put the data in a TPFile.

    Thanks


  • #2
    Sounds like you could use dynamic SQL.

    Comment


    • #3
      Sounds like dynamic SQL to me, too. Just to elaborate slightly for you, Heerschap, if you're not sure what we mean by that: Dynamic SQL refers to building your SQL statements on-the-fly, at execution time rather than compile time. For a quick example: sBigSqlStatement = 'SELECT Field1, Field2, Field3 FROM SomeTable WHERE ' + Test1 + ' EQ ' + seekValue;
      You use the content of your Test1 field to build an SQL statement as text, then use the PREPARE SQL statement to turn your text string into an executable SQL statement.

      Comment


      • #4
        OK. Thank you both for the help. Much appreciated.

        Comment

        Working...
        X