You are on page 1of 6

4/12/13

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

Requested Technical Tip


Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records
Solution ID: Product(s): Version(s): Primary subject: Last Modified: 125246 Aspen SQLplus 2004.2, 2006, 2006.0.3, 2006.5 Query Syntax 26-Dec-2008

Associated Solutions: ID: 124935 ID: 108764 ID: 130610 ID: 103780 ID: 103395 ID: 119241 ID: 119108 ID: 116004 How do I move a GET record to a different Logical device in Aspen InfoPlus.21? How to remove unwanted tags from a transfer record Query to remove IP_AnalogDef tags from Aspen InfoPlus.21 database after deleting references from IOGetDef records What are the different ways to populate the tags in Aspen Cim-IO Transfer record? What are the recommended steps for performing maintenance on Aspen Cim-IO transfer records? What does error "Store Process had error on send; listid -nnnnn" in cimio_msg.log file mean? What is the 'Best Practice' that AspenTech recommends when adding new occurrences to Get or Unsol records especially when using Aspen Cim-IO Store and Forward? What is the maximum number of tags that can be added to a transfer record?

Training Classes: Click here to see the training options for this product

Problem Statement
Where can I find Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records?

Solution
QUERY EXECUTION PRE-REQUISITES: Recommended pre-requisites that AspenTech Support suggests be completed before running any of the example queries provided below are as follows: 1. Save a backup copy of your Aspen InfoPlus.21 database snapshot before running any of the example queries provided below in this knowledge base article. 2. Review the Aspen SQLplus help file regarding the TRIM command and the examples provided in the TRIM help file, as it may not do what you expect depending on how you use it, and two of the examples provided below include the TRIM command. The TRIM function will remove characters from the start, end, or both of a character value by truncating characters from the value based on whether or not you specify one of the three trim types (LEADING, TRAILING, or BOTH), and BOTH is assumed if no trim type is specified. Also, if the "string" of specified trim characters to trim from the value contains more than one character, TRIM will then remove any of the specified characters in whatever order they appear until it finds the first character in the value to be trimmed that does not match any of the specified trim characters. 3. AspenTech ALWAYS recommends that you first turn "OFF" the IO_RECORD_PROCESSING for each of the selected Get records to be updated BEFORE actually making any changes to those selected Get records, and reasons for this recommendation are provided in KB Solutions 103395, 119108, 119241, which are linked to this article. Some additional Support articles you may want to review in regards to Aspen SQLplus queries that can be used to modify transfer records are KB Articles 103780, 108764, and 124935. NOTE: The queries below already include commands to toggle the IO_RECORD_PROCESSING during the query execution. The IO_RECORD_PROCESSING toggle commands (OFF / ON) can be removed from the queries but as stated above doing so is NOT recommended by AspenTech Support. IO_TAGNAME CHARACTER LIMIT REMINDER: Each I/O transfer record type has 3 sizes that are based on the Maximum Length of the I/O tag name that will be used to reference the device data point. This is mentioned in KB Article 116004. Definition Record (Type) IoGetDef IoLongTagGetDef Type Size Description Regular Long (IoLongTag definition records) Character limitation 39 character tag names 79 character tag names
1/6

support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246

4/12/13

IoLongTagGetDef IoLLTagGetDef

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

Long (IoLongTag definition records)

79 character tag names

LongLong (IoLLTag definition records)

255 character tag names

_____________________________________________________________________________ Three example queries have been provided below, which can be modified and used as needed to accomplish the task of updating the IO_TAGNAME for specified tags in one or multiple Get records. The examples (#1) show how existing IO_TAGNAME values can be updated by simply replacing part of the existing name with a different text string using the REPLACE Command, and (#2, #3) when using the REPLACE command is not a suitable option then how the IO_TAGNAME values can be updated using a concatenation of strings including suffixes and prefixes when the associated Aspen InfoPlus.21 record name is required as part of the IO_TAGNAME. NOTE: The items highlighted in Yellow in the example queries indicate the text strings to search for and/or replace in regards to the specified Get record and corresponding IO_TAGNAME values to be updated, and also indicate the allowed character lengths for the local variables used. EXAMPLE #1: This query allows you to Automatically Update IO_TAGNAME values in all or specified Get records by using the REPLACE command to substitute into each IO_TAGNAME value a new text string to replace an existing specified text string, where the IO_TAGNAME values to be updated are located ONLY in the Get records where the associated Aspen InfoPlus.21 record (tag) name defined for one or more of the IO_TAGNAME values is similar to or includes in the name the text string as specified by the user in the query by using the LIKE command. --Update the String Length as needed for the CHAR Variables based on your IO_TAGNAME lengths --and also modify the remaining query lines as needed before executing. LOCAL CurrentTag CHAR(40); LOCAL NewTag CHAR(40); LOCAL UpdateCount INTEGER; LOCAL intIOGETCount INTEGER; LOCAL x, arrIOGETDEF; UpdateCount = 0; intIOGETCount = 0; FOR (SELECT NAME as IOGETREC, OCCNUM as Occurrence, "IO_TAGNAME" as IOTAG, "IO_VALUE_RECORD&&FLD" -> NAME as RECNAME FROM IOGETDEF WHERE NAME LIKE 'Get_%') DO IF RECNAMENAME LIKE 'TagPrefix.%' THEN --NOTE: RECNAME can also be replaced with IOTAG in the above IF THEN LIKE Statement, --which would then make the update execution be based on the existing IO_TAGNAME itself --rather than the update being based on the associated IP.21 Record (tag) Name. --Set IO_RECORD_PROCESSING to OFF. --Again, this step is Optional BUT ALWAYS Recommended BEFORE making any Transfer Record Changes. IF (SELECT IO_RECORD_PROCESSING FROM IOGETDEF WHERE NAME = IOGETREC) = 'ON' THEN UPDATEUPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'OFF' WHERE NAME = IOGETREC; redim (arrIOGETDEF, intIOGETCount); arrIOGETDEF[intIOGETCount] = IOGETREC; intIOGETCount = intIOGETCount + 1; END; --Use the REPLACE command on Current IO_TAGNAME to Set the New IO_TAGNAME, then display --the Old and New (replacement) IO_TAGNAMES then execute the UPDATE. CurrentTag = IOTAG; NewTag = REPLACE('TagPrefix.' WITH 'ABC123.' IN CurrentTag); WRITE 'Selected Get Record and IOTAG# (i.e., Occurrence) to Update = ' || IOGETREC || ' and IOTAG# ' || Occurrence; WRITEWRITE 'Old IO_TAGNAME = ' || CurrentTag; WRITE 'New IO_TAGNAME = ' || NewTag; UPDATE IOGETDEF SET "IO_TAGNAME" = NewTag WHERE NAME = IOGETREC AND OCCNUM = Occurrence; WRITE ' '; UpdateCount = UpdateCount + 1; END;
support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246 2/6

4/12/13

END;

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

END; --Set IO_RECORD_PROCESSING back to ON fO_RECORD_PROCESSING back to ON for Each IOGETDEF that was Updated. FOR EACH x IN arrIOGETDEF DO UPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'ON', "IO_ACTIVATE?" = 'YES' WHERE NAME = x; END; --Write out a Final combined Summary Table of the IOTAGNAME Updates completed. IF UpdateCount > 0 THEN WRITE 'The Get Records should now be Updated with the New IO_TAGNAME values as follows:'; WRITE ' '; SELECT NAME as "GETREC NAME", OCCNUM "IOTAG OCCNUM", "IO_TAGNAME" as "NEW IO_TAGNAME" FROM IOGETDEF WHERE NAME LIKE 'Get_%' AND "IO_TAGNAME" LIKE '%ABC123.%'; ELSE WRITE 'IO_TAGNAME Updates Completed = 0'; END; _____________________________________________________________________________ NOTE: The next two example queries provided below both use the UPDATE statement instead of the REPLACE statement in order to update the IO_TAGNAME values using a different naming method and to show an alternative way of writing the query. In both cases though, the included SELECT statements and command lines in the queries below could be modified as needed and used in conjunction with a REPLACE statement as well in order to provide the same functionality, rather than using the SELECT statement as shown in the examples, such that in the examples shown below the desired REPLACE statement would be placed in between the Prefix and Suffix concatenation strings instead of the SELECT statement used in both examples. EXAMPLE #2: This query also allows you to automatically search all or specified Get records and update ONLY the IO_TAGNAME values in each Get record as needed by searching for and using the actual record names defined in Aspen InfoPlus.21 for the Get record tags in order to then specify and limit which IO_TAGNAME values to update based on those tags that are associated with Aspen InfoPlus.21 records that are defined with names that start with a specified text string as identified using the LIKE command. Essentially this query serves the same purpose as the query provided in Example #1, except that instead of replacing part of the existing IO_TAGNAME with a new text string this query builds a new tag name altogether including a part of the associated Aspen InfoPlus.21 record (tag) name combined with a user defined prefix and suffix. LOCAL UpdateCount INTEGER; LOCAL intIOGETCount INTEGER; LOCAL x, arrIOGETDEF; UpdateCount = 0; intIOGETCount = 0; FOR (SELECT NAME as IOGETREC, OCCNUM as Occurence_Number, "IO_TAGNAME" as IOTAG, "IO_VALUE_RECORD&&FLD" -> NAME as IORECORD FROM IOGETDEF WHERE NAME LIKE 'Get_%') DO; --For each IOTAGNAME selected, Check to verify if it meets the required criteria, and if so, then update. IF IORECORD LIKE 'ABCXYZ123_%' THEN --NOTE: IORECORD can also be replaced with IOTAG in the above IF THEN LIKE Statement, --which would then make the update execution be based on the existing IO_TAGNAME itself --rather than the update being based on the associated IP.21 Record (tag) Name. --Set IO_RECORD_PROCESSING to OFF. --Again, this step is Optional BUT ALWAYS Recommended BEFORE making any Transfer Record Changes. IF IF (SELECT IO_RECORD_PROCESSING FROM IOGETDEF WHERE NAME = IOGETREC) = 'ON' THEN UPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'OFF' WHERE NAME = IOGETREC; redim (arrIOGETDEF, intIOGETCount); arrIOGETDEF[intIOGETCount] = IOGETREC; intIOGETCount = intIOGETCount + 1; END; WRITE 'Existing Record to be Updated:'; WRITE ' '; SELECT NAME as "GETREC NAME", OCCNUM as "IOTAG OCCNUM", "IO_TAGNAME", "IO_VALUE_RECORD&&FLD" -> NAME FROM IOGETDEF WHERE NAME = IOGETREC WHERE NAME = IOGETREC AND OCCNUM = Occurence_Number; WRITE ' ';
support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246 3/6

4/12/13

WRITE ' ';

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

--Update the Existing selected IOTAGNAME based on the following Concatenation of Strings: --User Defined Tag Prefix + Selected Portion of Associated IP.21 Record Name + User Defined Tag Suffix --Then Write out the Update Results to display the New IOTAGNAME. UPDATE IOGETDEF SET "IO_TAGNAME" = 'TagPrefix.' || (SELECT TRIM(LEADING 'ABCXYZ123_' FROM "IO_VALUE_RECORD&&FLD" -> NAME) FROM IOGETDEF WHERE NAME = IOGETREC AND OCCNUM = Occurence_Number) || '.TagSuffix ' WHERE NAME = IOGETREC AND OCCNUM = Occurence_Number; WRITE 'Updated Record with New IO_TAGNAME = ' || (SELECT "IO_TAGNAME" FROM IOGETDEF Where NAME = IOGETREC AND OCCNUM = Occurence_Number); Write ' '; WRITE ' '; UpdateCount = UpdateCount + 1; END; END; --Set IO_RECORD_PROCESSING back to ON for Each IOGETDEF that was Updated. FOR EACH x IN arrIOGETDEF DO UPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'ON', "IO_ACTIVATE?" = 'YES' WHERE NAME = x; END; --Write out a Final combined Summary Table of the IOTAGNAME Updates completed. IF UpdateCount > 0 THEN WRITE 'The Get Records should now be updated with the New IO_TAGNAME values as follows:'; WRITE ' '; SELECT NAME as "GETREC NAME", OCCNUM "IOTAG OCCNUM", "IO_TAGNAME" as "NEW IO_TAGNAME" FROM IOGETDEF WHERE NAME LIKE 'Get_%' AND "IO_TAGNAME" LIKE 'TagPrefix.%.TagSuffix '; ELSE WRITE 'IO_TAGNAME Updates Completed = 0'; END; ADDITIONAL NOTE: The SELECT statement used inside the Update statement shown in the query example above that is located in between the Tag Prefix and Suffix Concatenation Strings could also be removed and replaced with a REPLACE statement to provide similar functionality if you wish instead for the new IO_TAGNAME to include as part of the new name, the name as it previously existed based on the original IO Tag Name or the corresponding Aspen InfoPlus.21 Record Name but with a replacement of a specified string found in that name with a new string, and the modified UPDATE statement including the substihe substituted REPLACE statement to be used instead of the SELECT statement would look like the example provided here below: UPDATE IOGETDEF SET "IO_TAGNAME" = 'TagPrefix.' || REPLACE('OLD_STRING' WITH 'NEW_STRING' IN IORECORD) || '.TagSuffix ' Where NAME = IOGETREC AND OCCNUM = Occurence_Number; And Likewise, again IOTAG could be used in the above statement instead of IORECORD if the replacement is to be based on the Existing IO_TAGNAME itself and not the corresponding Aspen InfoPlus.21 Record, but in that case the update statement in this example would assume that you also want to change the Tag Prefix and Suffix on the Existing IO_TAGNAME or add both if they did not previously exist; otherwise, if you are basing the replacement command for the tag update on the existing IO_TAGNAME and you want to keep as is any current Tag Prefix and/or Suffix that exits then the concatenation would not be needed and you could then simply use example query #1 provided above . _____________________________________________________________________________ EXAMPLE #3: This query allows the user to manually specify the Get record name and number of occurrences to update , i.e., the TAGCOUNT for the number of IO_TAGNAME values to be updated per the specified Get record, and per the command lines included to build the new tag name(s) and the update statement also provided in the query the user can then use and modify as needed the example query below to update the IO_TAGNAME values in the specified Get record with the new tag name values. This manual query essentially executes the same update as the automated query provided in Example #2, except ONLY for the one specified Get record. LOCAL TAGCOUNT INTEGER; LOCAL EXISTING_IOTAG CHAR(40); LOCAL NEW_IOTAG CHAR(40); LOCAL IOGETRECNAME CHAR(40); LOCAL IPVALRECFLD_NAME CHAR(40); --Verify and Update the required TAGCOUNT Range and Get Reecord NAME,
support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246 4/6

4/12/13

--Verify and Update the required TAGCOUNT Range and Get Reecord NAME, --and also modify the remaining query lines as needed before executing. IOGETRECNAME = 'Get_IOCOMM_TestTags'; --Set IO_RECORD_PROCESSING to OFF.

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

--Again, this step is optional BUT ALWAYS recommended BEFORE making any Transfer Record changes. IF (SELECT IO_RECORD_PROCESSING FROM IOGETDEF WHERE NAME = IOGETRECNAME) = 'ON' THEN UPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'OFF' WHERE NAME = IOGETRECNAME; END; WRITE 'IO_TAGNAME Update Results for Get Record = ' || IOGETRECNAME; WRITE ' '; FOR TAGCOUNT = 1 TO 20 DO --Select Existing IOTAGNAME EXISTING_IOTAG = (SELECT "IO_TAGNAME" FROM IOGETDEF WHERE NAME = IOGETRECNAME AND OCCNUM = TAGCOUNT); IPVALRECFLD_NAME = (SELECT "IO_VALUE_RECORD&&FLD"-> NAME FROM IOGETDEF WHERE NAME = IOGETRECNAME AND OCCNUM = TAGCOUNT); IF EXISTING_IOTAG <> '' AND IPVALRECFLD_NAME LIKE 'ABCXYZ123_%' THEN --NOTE: IPVALRECFLD_NAME can also be replaced with EXISTING_IOTAG after the AND in the above --IF THEN LIKE Statement, which would then make the update execution be based ONLY on the existing --IO_TAGNAME itself rather than the update being based also on the associated IP.21 Record (tag) Name. --Build the New IOTAGNAME based on the following Concatenation of Strings: --User Defined Tag Prefix + Selected Portion of Associated IP.21 Record Name + User Defined Tag Suffix NEW_IOTAG = 'TagPrefix.' || (SELECT TRIM(LEADING 'ABCXYZ123_' FROM "IO_VALUE_RECORD&&FLD"-> NAME) FROM IOGETDEF WHERE NAME = IOGETRECNAME AND OCCNUM = TAGCOUNT) || '.TagSuffix '; --Update IOTAGNAME field with New IOTAGNAME and Write out Results UPDATE IOGETDEF SET "IO_TAGNAME" = NEW_IOTAG WHERE NAME = IOGETRECNAME AND OCCNUM = TAGCOUNT; WRITE 'Occurrence Tag ' || TAGCOUNT || ': IO_TAGNAME Changed from ' || EXISTING_IOTAG || ' to ' || NEW_IOTAG; WRITE ' '; END; END; --Set IO_RECORD_PROCESSING back to ON for Each IOGETDEF that was Updated. UPDATE IOGETDEF SET IO_RECORD_PROCESSING = 'ON', "IO_ACTIVATE?" = 'YES' WHERE NAME = IOGETRECNAME;

Keywords
Get Records IOGetDef IO_TAGNAME SQLplus Update Query

We would like to get your feedback:

Click here to rate this solution and provide your com m ents

Upcoming Training for this Product in your Region Start Date


03-Jun2013

Course Name
PME201 Aspen SQLplus for Aspen InfoPlus.21: Using and Configuring for Pow er Users

End Date
07-Jun2013

Location
Pune, India

Price
INR 41000

Registration
Register Now

TimeAddress
Logistics

Language English

support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246

5/6

4/12/13

Aspen SQLplus query examples to update the IO_TAGNAME for specified tags in multiple Get records

How do you rate this solution?

(Not Helpful)

(Very Helpful)

Please add any additional comments regarding how this solution could be improved:

Submit

This document contains proprietary information of Aspen Technology, Inc. and is tendered subject to the condition that no copy or other reproduction be made in whole or in part for use other than customer's internal use. Access to this document is strictly limited to customers of Aspen Technology, Inc. who are registered users of the support web site; no access or further distribution to any third party, including contractors or other agents of customer, is permitted. No use may be made of information herein except for which it is transmitted, without the express prior written consent of Aspen Technology, Inc. Aspen Technology may provide information regarding possible future product developments including new products, product features, product interfaces, integration, design, architecture, etc. that may be represented as "product roadmaps." Any such information is for discussion purposes only and does not constitute a commitment by Aspen Technology to do or deliver anything in these product roadmaps or otherwise. Any such commitment must be explicitly set forth in a written contract between the customer and Aspen Technology, executed by an authorized officer of each company.

support.aspentech.com/webteamcgi/SolutionDisplay_view.cgi?key=125246

6/6

You might also like