Question
· Aug 6, 2021

delete a filed from repeating fields

I am trying to delete a field based on a value in one of the subfields.  I would like to remove the below Field with the Field value "Field8". I know how to find the number of fields and iterate.  If I just use "" I still get a tilde at the end.

Ex  .

|Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8

Product version: IRIS 2020.4
Discussion (3)0
Log in or sign up to continue

If you want to remove the N-th field, in the your example, "Field8" is the 6-th field, then:

set fields = "Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8"
set N=6
set $piece(fields, "^", N, N+1) = $piece(fields, "^", N+1)

If you have to work with subfields, you have to get first those subfields in a temporary variable, for example, in the above example, you want to remove "Field3" then do this:

set temp=$piece(fields, "^", 3)  // get the subfields
set N=1
set $piece(temp, "~", N,N+1) = $piece(temp, "~", N+1)
set $piece(fields, "^", 3) = temp // put the subfields back into the outer string

If you want to remove the N-th field, in the your example, "Field8" is the 6-th field, then:

set fields = "Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8"
set N=6
set $piece(fields, "^", N, N+1) = $piece(fields, "^", N+1)

If you have to work with subfields, you have to get first those subfields in a temporary variable, for example, in the above example, you want to remove "Field3" then do this:

set temp=$piece(fields, "^", 3)  // get the subfields
set N=1
set $piece(temp, "~", N,N+1) = $piece(temp, "~", N+1)
set $piece(fields, "^", 3) = temp // put the subfields back into the outer string