cobol - Replace values with nothing / null -
i have text file delimiters (like #rt#, #lt#, #bc# etc) need removed.
for example:-
original: taxes owed:#rt#$3000
fixed version: taxes owed:$3000
replacing spaces doesnt work obviously, puts in spaces - computer read file - needs exact - nothing/null do.
any ideas?
the above representative sample of data... random paragraphs of data #rt# , #lt# in it. currently, replacing spaces used. need removed entirely in example above. cant post code till tomorrow im on road.
the inspect yourtext replacing spaces
leaves spaces. inspect yourtext replacing ""
not allowed (both need same length or replacing identifier figurative constant: space[s], zero[s|es], or quote[s]) - compiler output understandable message if try this.
this leaves 3 options:
don't use cobol (would #1 option if don't want else text file) system call, example
sed -e 's/#rt#//g' yourfile > yourtarget
, depending on cobol runtime use (it idea add information in question!) may start process via cobolcall "system" using external-command
.read
data, use extension specific runtime translate (for example gnucobol:move function substitute (yourtext, '#rt#', '', '#lt#'. '') translated-text
) - mayfunction
, system librarycall
- ,write
data back.the old cobol way - see below.
as question not reading data or writing replacing part:
option a): unstring statement
move 0 t1, t2, t3, t4 unstring yourtext delimited '#rt#' or '#lt#' or ... target-1 count in t1 target-2 count in t2 target-3 count in t3 target-4 count in t4 ... end-unstring move spaces translated-text string target-1 (1:t1) target-2 (1:t2) target-2 (1:t2) target-2 (1:t2) ... delimited size translated-text end-string
option b) simple perform varying
2 pointers, combined simple if
statement.
*> may more performance if `redefine` source-text `pic x occurs length-of-text times` - find 1 more better read , shouldn't consume more time... move 0 target-pointer perform varying source-pointer 1 1 until source-pointer > length-of-text if source-text (source-pointer:1) = '#' *> optimizer calculate constant on *> right side, may write directly if source-pointer + 4 > length-of-text add 1 target-pointer move source-text (source-pointer:) target-text (target-pointer:) exit perform end-if if source-text (source-pointer:4) = '#rt#' or '#lt#' or ... add 4 source-pointer exit perform cycle end-if end-if add 1 target-pointer move source-text (source-pointer:1) target-text (target-pointer:1) end-perform
Comments
Post a Comment