Search code examples
cobolmainframe

Need to remove leading spaces from a COBOL pic clause?


I need to be able to remove all leading spaces from a String in Cobol PIC x(80)

Code:

      UNSTRING ADDRESS DELIMITED BY SPACES INTO
 -             S-SP, ADDRESS              
 -    END-UNSTRING.                                         

Then I should be able to write the string ADDRESS to a file without any leading spaces.

Error code:

775 IGYPS0088-S The "UNSTRING" statement was invalid. Expected "INTO", but found "INTOWS-SPACES". The statement was discarded.


Solution

  • You have specified "continuations", minus-signs/dashes in column 7 of your source.

    Continuations are very, very, rarely required. They are only required for continuing a literal.

    Remove the "-"s from column 7.

    I don't think your code will do what you think, but if you have trouble with that, please ask a new question.

    When a literal is continued, the closing quote is not included on the lined being continued.

       "ABCDE<and then column 72 arrives
    -  "FGHIJ"
    

    This literal will be "ABCDEFGHIJ" when used.

    If you use the continuation on a line of code, the text will be concatenated without any intervening space, hence your error message.