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!

get rid of leading zeros with concatenation 1

Status
Not open for further replies.

hawley26

Programmer
Oct 29, 2003
6
US
Is there an easy way to concatenate three strings and ignore leading zeros in the concatenation?
For example:

05 PC-L-PAR PIC X(01) VALUE '('.
05 PC-R-PAR PIC X(01) VALUE ')'.
05 PV-STR-CNT PIC S9(10) VALUE ZEROES.
05 HDR06-SALES-01 PIC 9(10) VALUE ZEROS.

PV-STR-CNT = 0000000056

Here is what I have tried.
STRING PC-L-PAR DELIMITED BY SIZE
PV-STR-CNT DELIMITED BY ZEROS
PC-R-PAR DELIMITED BY SIZE
INTO HDR06-SALES-01
I get ()00000000

I have also tried
STRING PC-L-PAR DELIMITED BY SIZE
PV-STR-CNT DELIMITED BY ' '
PC-R-PAR DELIMITED BY SIZE
INTO HDR06-SALES-01
and I get (000000056

and I want (56)


Thanks for the help in advance.
 
hawly26,
Not your solution, just wondering why HDR06-SALES-01 isn't alphanumeric?
 
Tried it that way to and got the same results.

05 HDR06-SALES-01 PIC X(10) VALUE SPACES.
 
hawley26,
I don't think it's possible in one step, since the string statement is for text manipulation. You would have to first get the PV-STR-CNT numeric field into an alphanumeric field, stripping the zeros here.

Say PV-STR-CNT-ALPA, difined as a PIC X, in this case with a value of 56. Now your string should work as follows, with the receiving field also defined as alphanumeric. Now, I'm no Cobol guru (why I never post), so if someone can jump in, please do!

STRING PC-L-PAR DELIMITED BY SIZE
PV-STR-CNT-ALPHA DELIMITED BY SIZE
PC-R-PAR DELIMITED BY SIZE
INTO HDR06-SALES-01
 
hawley26,

I have highlighted in red one problem with your example. However, I have coded a suggestion based upon the assumption:
Code:
05  PV-STR-CNT     PIC 9(10) VALUE ZEROES.

This code uses INSPECT to determine the number of leading zeros (actually, the digit position of the most significant nonzero digit), and then uses reference modification within the STRING to constrain the size of the field from which the number is moved.

Code:
05  PC-L-PAR       PIC X(01)  VALUE '('.
05  PC-R-PAR       PIC X(01)  VALUE ')'.
05  PV-STR-CNT     PIC S9(10) VALUE ZEROES.
Code:
   leading sign??      ^
Code:
05  HDR06-SALES-01 PIC
Code:
X
Code:
(10)  VALUE ZEROS.
Code:
05  LZ-COUNT       PIC 99.
Code:
PV-STR-CNT = 0000000056[code][COLOR=red][b][code] does not agree with PIC
[/b][/color]
Code:
MOVE SPACES TO HDR06-SALES-01.
MOVE 1 TO LZ-COUNT.
INSPECT PV-STR-CNT TALLYING LZ-COUNT FOR LEADING ZERO.
IF LZ-COUNT > 10 MOVE 10 TO LZ-COUNT.
Code:
STRING PC-L-PAR
Code:
       PV-STR-CNT (LZ-COUNT:)
Code:
       PC-R-PAR DELIMITED BY SIZE
  INTO  HDR06-SALES-01

Note 1: The STRING statement does not space fill the receiving operand.

Note 2: The STRING statement does not care if the receiving field is PIC X(10) or PIC 9(10), but subsequent statements probably will care a lot.

Tom Morrison
 
Thank you both for you help. I went with k5tm's answer and it worked. I have one more question that is pretty basic. I want to put this into to two variables and was wondering if I could do something like below instead of moving or doing another string..into.

STRING PC-L-PAR
PV-STR-CNT (LZ-COUNT:)
PC-R-PAR DELIMITED BY SIZE
INTO HDR06-SALES-01
HDR06-AVG-SALES-01
 
k5tm,
Thanks. You helped me out on understanding the string statement, too. Have a star :)

Melissa
 
hi
try that
=======
01 I PIC 9(4).
01 FLSR-NUBER-OF-RECORDS PIC 9(12) COMP-4
01 FORMAT-19 PIC ---,---,---,---,--9.

MOVE FLSR-NUBER-OF-RECORDS TO FORMAT-19.
MOVE 0 TO I.
INSPECT FORMAT-19 TALLYING I FOR LEADING SPACES.
ADD 1 TO I.
DISPLAY SPACES LINE 22 POSITION 23 SIZE 19.
DISPLAY FORMAT-19(I:) LINE 22 POSITION 23 REVERSE.

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top