3

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'

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
mac100
  • 137
  • 2
  • 13

1 Answers1

3

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.
Jensd
  • 7,886
  • 2
  • 28
  • 37
  • Yes I am working with edifact , somehow able to extract what each elements say , still fighting to get exact info I need , this question is to filter segment tags before parsing . Thanks . – mac100 Apr 04 '16 at 09:16
  • BTW if you have earlier worked in edifact and have some working library is it possible to help me out with it , thanks – mac100 Apr 04 '16 at 09:29
  • @mac100 We stopped working with EDIFACT some 10 years ago so I don't think we have anything useful left... – Jensd Apr 04 '16 at 09:30