trim
From: Alain Reymond (no email)
Date: 12/18/03
- Previous message: docdwarf_at_panix.com: "Re: PROBLEM SOLVED - State of WORKING-STORAGE in Statically-Called Subroutines"
- Next in thread: JerryMouse: "Re: trim"
- Reply: JerryMouse: "Re: trim"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 18 Dec 2003 14:54:41 +0100
Here is a small piece of code :
testrim is calling trim. The name says what it does :
testtrim
$set sourceformat"free"
1 b pic x(2000).
procedure division.
move "ABCDEFGHIJKLMNOPQRSTUVWXYZ" to b
call "trim" using
by reference address of b
by content length of b
end-call
exit program
stop run.
Can someone explain why this version works :
trim.cbl
$set sourceformat"free"
working-storage section.
01 i pic 9(4) comp.
linkage section.
01 ls-pStr usage pointer.
01 ls-len pic s9(9) usage binary.
01 lnk-texte pic x.
procedure division using ls-pStr, ls-len.
paragraphe.
*>version 1
set address of lnk-texte to ls-pStr
perform varying i from ls-len by -1
until ((i < 1) or (lnk-texte(i:1) <> " "))
move x'00' to lnk-texte(i:1)
end-perform
exit program
.
while this version hangs if b has a picture higher than 108 ? (but is
ok if you define b pic x(108) !!).
$set sourceformat"free"
working-storage section.
01 tally-count pic 9(7).
linkage section.
01 ls-pStr usage pointer.
01 ls-len pic s9(9) usage binary.
01 lnk-texte pic x.
procedure division using ls-pStr, ls-len.
paragraphe.
*> version 2
set address of lnk-texte to ls-pStr
move zero to tally-count
inspect function reverse (lnk-texte(1:ls-len))
tallying tally-count
for leading spaces
if tally-count > 0 then
move low-values to lnk-texte(ls-len - tally-count + 1 :
tally-count)
end-if
exit program
.
I am working with Micro Focus v4.1 under Linux.
This is a small routine to cut spaces at the end of a string. This is
useful in combination with the string instruction :
string
name delimited by low-values
" " deimited by size
last-name delimited by low-values
into a-string...
Regards.
Alain
- Previous message: docdwarf_at_panix.com: "Re: PROBLEM SOLVED - State of WORKING-STORAGE in Statically-Called Subroutines"
- Next in thread: JerryMouse: "Re: trim"
- Reply: JerryMouse: "Re: trim"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|