Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing trailing spaces... 1

Status
Not open for further replies.

hawley26

Programmer
Oct 29, 2003
6
US
I am trying to remove a trailing space from a variable. I am using the string...into and am still not getting the correct results. I have tried delimiting by size and still get the same thing. I am sure it is one small thing I am missing but I have been looking at it for so long I don't see it. Thanks for you help in advance!!!!

05 PC-L-PAR PIC X(01) VALUE '('.
05 PC-R-PAR PIC X(01) VALUE ')'.
05 PV-STR-CNT PIC 9(08) VALUE ZEROS.
05 HDR06-SALES-03 PIC X(05) VALUE SPACES.

MOVE 1 TO PV-COUNT.
INSPECT PV-STR-CNT TALLYING PV-COUNT FOR LEADING ZEROS.
IF PV-COUNT > 10 MOVE 10 TO PV-COUNT.

STRING PC-L-PAR
PV-STR-CNT (PV-COUNT:)
PC-R-PAR DELIMITED BY SPACE
INTO HDR06-SALES-03

HDR06-SALES-03 = "(43) "

I want HDR06-SALES-03 = "(43)"
 
HDR06-SALES-03 is defined as 5 bytes long. You may only string 4 characters into the field, but it is still 5 bytes long and contains the leftover space initialized by the VALUE clause. Nothing is really wrong with the STRING command. In your case, I would use DELIMITED BY SIZE since you don't have any spaces in the fields you're using.

If you want to move HDR06-SALES-03 and only use the 4 characters, I would INSPECT and TALLY the characters before the first space and then use reference mod to move that many characters.

By the way...
You may have some trouble PV-STR-CNT is only 8 bytes long but you allow the PV-COUNT to be 10. You may get some unexpected results.
 
Hawley26,

You have several issues:[ul]
[li]if PV-STR-CNT contains zero, your STRING will misbehave badly;[/li]
[li]you need to know how many characters your STRING statement moved;[/li]
[li]you need to deal with a value too large to be represented in three character positions; and[/li]
[li]we don't know what compiler you might be using so we don't know what particular extensions might make a solution to your need a little less cumbersome.[/li]
[/ul]

Let's look at the first issue:

When PV-STR-CNT contains the value zero, PV-COUNT will contain the value 9 after the INSPECT statement (the initial value 1 plus 8 zero digits). When the STRING statement evaluates the reference modification PV-STR-CNT (PV-COUNT:), it will be attempting to reference the ninth character in an eight character field. :-(

I will illustrate a least-common-denominator solution. Depending on your compiler's capabilities, there may be something more elegant.

Regarding the second issue:

I will illustrate the use of the POINTER phrase.

Regarding the third issue:

I will illustrate the use of the ON OVERFLOW phrase.

Code:
05  PC-L-PAR                     PIC X(01)  VALUE '('.
05  PC-R-PAR                     PIC X(01)  VALUE ')'.
05  PV-STR-CNT                   PIC  9(08) VALUE ZEROS.
05  HDR06-SALES-03               PIC  X(05)  VALUE SPACES.

01  PV-SIZE   PIC 99.
01  COUNT-OF-CHARS-MOVED PIC 99.

MOVE 1 TO PV-COUNT.
INSPECT PV-STR-CNT TALLYING PV-COUNT FOR LEADING ZEROS.
MOVE 0 TO PV-SIZE.
INSPECT PV-STR-CNT TALLYING PV-SIZE FOR CHARACTERS.
IF PV-COUNT > PV-SIZE MOVE PV-SIZE TO PV-COUNT.

MOVE 1 TO COUNT-OF-CHARS-MOVED.
STRING PC-L-PAR DELIMITED BY SIZE
       PV-STR-CNT (PV-COUNT:) DELIMITED BY SIZE
       PC-R-PAR DELIMITED BY SIZE
  INTO  HDR06-SALES-03
  POINTER COUNT-OF-CHARS-MOVED
  ON OVERFLOW
       MOVE ALL "*" TO HDR06-SALES-03
       MOVE 1 TO COUNT-OF-CHARS-MOVED
       INSPECT HDR06-SALES-03 
           TALLYING COUNT-OF-CHARS-MOVED FOR CHARACTERS
END-STRING.

SUBTRACT 1 FROM COUNT-OF-CHARS-MOVED.
At this point you may use HDR06-SALES-03(1:COUNT-OF-CHARS-MOVED) as the exact result of the STRING.


Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top