trim

From: Alain Reymond (no email)
Date: 12/18/03

  • Next message: docdwarf_at_panix.com: "Re: PROBLEM SOLVED - State of WORKING-STORAGE in Statically-Called Subroutines"
    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


  • Next message: docdwarf_at_panix.com: "Re: PROBLEM SOLVED - State of WORKING-STORAGE in Statically-Called Subroutines"

    Relevant Pages

    • Re: String Functions in MF
      ... Robert Wagner wrote ... in a low-values. ... If a subsequent assumed STRING, which you seem to want to refer to, ... uses DELIMITED BY LOW-VALUE (which is the point of doing this 'trim') ...
      (comp.lang.cobol)
    • Re: Perform forever
      ... > In Richard's example the problem is that you always execute the string with ... Oops, remove 'with test after'. ... perform get-input ... move low-values to wpppauthorblurb ...
      (comp.lang.cobol)
    • Re: Find number of characters read with accept.
      ... I tried something similar to that without success. ... whole string, before ACCEPTing the input. ... LOW-VALUES though. ...
      (comp.lang.cobol)