So let's say that I have a variable that stores two-digit numbers. 01 my-int PIC 99
. But when my-int
takes one digit values such as 01
, I want it to take the form 1
when printed in which the digit is always in the leftmost and space on the right. Any ideas about how I should define my-int
in order to achieve that?
Thanks!
Add a comment
|
1 Answer
Define my-int to store the data 01 my-int PIC 99
, then either use an edited 01 my-edit PIC z9
and use MOVE my-int TO my-edit
and DISPLAY FUNCTION TRIM (my-edit LEADING)
or (in this special case where you only have one space):
IF my-int > 9
DISPLAY my-int
ELSE
DISPLAY my-int (2:)
END-IF
-
1Is that
TRIM (my-edit LEFT)
orTRIM (my-edit LEADING)
? IBM Enterprise COBOL uses the latter but they're not always standards-conforming.– cschneidFeb 2, 2019 at 15:48 -
@cschneid LEADING is standards-conforming and correct, I've fixed-edited the answer, thx for the remark Feb 4, 2019 at 12:54