Reputation: 137
ABC+123:xy+123++23'EFG+123:xy+123++23'GHI+123:xy+123++23+mki+123'LMV++123:xy'
I have above string . Apostrophe(') acts as a terminator which denotes end of segments . Hence ABC+123:xy+123++23 is a segment , its start tag is three chars ABC which is unique. Now I need to trim this string based on these start tags eg I need segments starting only with ABC and LMV . resulting string should be ABC+123:xy+123++23'LMV++123:xy'
Upvotes: 3
Views: 548
Reputation: 8011
Based on this question and your other questions you work with EDIFACT.
EDIFACT is delimited with the single quote ' (or apostrophe if you so will).
ENTRY
and NUM-ENTRIES
is your friend. I would suggest moving your data into a more usable format than a string - more precisely a temp-table. Then you can do whatever you want with the temp-table. First process the data "line by line" or rather "entry by entry" and then move on to do whatever you want with it.
DEFINE VARIABLE cString AS CHARACTER NO-UNDO.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
DEFINE TEMP-TABLE ttEdifact NO-UNDO
FIELD lineno AS INTEGER
FIELD linedata AS CHARACTER FORMAT "x(60)".
/* The string in your example ends with a delimiter (') thus your temp-table will have one empty record in the end - it could be trimmed away */
cString = "ABC+123:xy+123++23'EFG+123:xy+123++23'GHI+123:xy+123++23+mki+123'LMV++123:xy'".
DO iEntry = 1 TO NUM-ENTRIES(cString, "'").
CREATE ttEdiFact.
ASSIGN
ttEdifact.lineno = iEntry
ttEdifact.lineData = ENTRY(iEntry, cString, "'").
END.
/* Now it's up to you to do something */
FOR EACH ttEdifact WHERE ttEdifact.lineData BEGINS "ABC":
DISP ttEdiFact.
END.
Upvotes: 3