How do you strip leading zeros so that 1st significant digit will occupy 1st position 
Author Message
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Quote:

> How do you strip leading zeroes from a field so that the first significant
> digit will occupy the first position.  So that a pic x(4) like 0043  becomes
> 43bb (b for space).  PIC Z4 will strip them but leave blanks, same thing with
> INSPECT REPLACING.
>  I need to put the stripped field into a STRING command with a delimited
> by space or size option     so that the output will be like '43' not '0043' or
> '43  '.

> I am transferring data from a DB2 table on a mainframe to an ORACLE table on a
> SUN UNIX server.  I will select the data from DB2, output it to dataset that
> will consist of 131,000 SQL update statements, and then FTP it to the UNIX
> server to update the ORACLE table.  The records  contain a PIC X(10) field
> i.e.  0000000001, 0000013245,  0003467234 that needs to be put into a STRING
> command.

> One possibly is to use a bunch of IF statements testing out each position for
> 0 and moving only nonzero digits.  Like IF field2(1:1) = 0 and field2(1:2) = 0
> .. field2(9:1) =0 then move field(10:1) to out2(1:1)
> IF field2(2:1) = 0 etc  then string and delimit by space.

> However I will end up with close to 100 statements for just one field.

> Does anybody have a simpler more elegant solution?

1. Consider redefining your field as a table of PIC X so that you
can use the SEARCH command to find the first non-zero digit.  Having
found it, you can use reference modification to MOVE or STRING the
remaining digits as a block.

2. If you're using STRING to build SQL statements, you may be able
to just convert leading zeros to spaces, then STRING the entire
field, leading spaces and all.  A few extra spaces between tokens
will not bother the SQL engine.  Of course, if you have to concatenate
the digits to another string for some reason, this simple-minded
approach won't work.

3. If you write a separate SQL statement for each row, Oracle has
to parse each one from scratch.  For a one-time operation this
overhead may not matter, but for a recurring job it may be
worthwhile to develop something more efficient.  Write a single
SQL statement and apply it to each record in turn.  If Oracle
doesn't provide a suitable utility you can write your own customized
program using Pro-C, Pro-COBOL, or whatever.


http://www.*-*-*.com/



Tue, 26 Sep 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

I have not tried to compile this, so I may have the syntax slightly wrong,
but the intent should be clear:

    Move zero to count-field
    Inspect full-field tallying count-field for leading zeroes
    string first-whatever delimited by something
               full-field (count-field + 1:) delimited by size
               next-whatever ....
         into final-field.

--
+ +
+   Bill Klein -
         "C" is a nice letter to START the name of your programming language
with
      but I wouldn't want to end up there.

Quote:

>How do you strip leading zeroes from a field so that the first significant
>digit will occupy the first position.  So that a pic x(4) like 0043
becomes
>43bb (b for space).  PIC Z4 will strip them but leave blanks, same thing
with
>INSPECT REPLACING.
> I need to put the stripped field into a STRING command with a delimited
>by space or size option     so that the output will be like '43' not '0043'
or
>'43  '.

>I am transferring data from a DB2 table on a mainframe to an ORACLE table
on a
>SUN UNIX server.  I will select the data from DB2, output it to dataset
that
>will consist of 131,000 SQL update statements, and then FTP it to the UNIX
>server to update the ORACLE table.  The records  contain a PIC X(10) field
>i.e.  0000000001, 0000013245,  0003467234 that needs to be put into a
STRING
>command.

>One possibly is to use a bunch of IF statements testing out each position
for
>0 and moving only nonzero digits.  Like IF field2(1:1) = 0 and field2(1:2)
= 0
>.. field2(9:1) =0 then move field(10:1) to out2(1:1)
>IF field2(2:1) = 0 etc  then string and delimit by space.

>However I will end up with close to 100 statements for just one field.

>Does anybody have a simpler more elegant solution?



Tue, 26 Sep 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

How do you strip leading zeroes from a field so that the first significant
digit will occupy the first position.  So that a pic x(4) like 0043  becomes  
43bb (b for space).  PIC Z4 will strip them but leave blanks, same thing with
INSPECT REPLACING.    
 I need to put the stripped field into a STRING command with a delimited
by space or size option     so that the output will be like '43' not '0043' or
'43  '.

I am transferring data from a DB2 table on a mainframe to an ORACLE table on a
SUN UNIX server.  I will select the data from DB2, output it to dataset that
will consist of 131,000 SQL update statements, and then FTP it to the UNIX
server to update the ORACLE table.  The records  contain a PIC X(10) field  
i.e.  0000000001, 0000013245,  0003467234 that needs to be put into a STRING
command.

One possibly is to use a bunch of IF statements testing out each position for
0 and moving only nonzero digits.  Like IF field2(1:1) = 0 and field2(1:2) = 0
.. field2(9:1) =0 then move field(10:1) to out2(1:1)  
IF field2(2:1) = 0 etc  then string and delimit by space.

However I will end up with close to 100 statements for just one field.  

Does anybody have a simpler more elegant solution?



Wed, 27 Sep 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

How about:

  Move 1 to count-field.
  Unstring full-field delimited by all zeroes into dummy-var
    counter count-field.
  Move spaces to final-field.
  Unstring full-field delimited by size into final-field
    counter count-field.

I don't have a COBOL manual with me, so the Unstring syntax might be a
little off. All the first Unstring does is set the pointer
(count-field) to the first non-zero digit. dummy-var can be a single
byte and the snippet will still work.


Quote:
>I have not tried to compile this, so I may have the syntax slightly wrong,
>but the intent should be clear:

>    Move zero to count-field
>    Inspect full-field tallying count-field for leading zeroes
>    string first-whatever delimited by something
>               full-field (count-field + 1:) delimited by size
>               next-whatever ....
>         into final-field.



Wed, 27 Sep 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Quote:
>How do you strip leading zeroes from a field so that the first significant
>digit will occupy the first position.  So that a pic x(4) like 0043
becomes
>43bb (b for space).  PIC Z4 will strip them but leave blanks, same thing
with
>INSPECT REPLACING.
> I need to put the stripped field into a STRING command with a delimited
>by space or size option     so that the output will be like '43' not '0043'
or
>'43  '.
>Does anybody have a simpler more elegant solution?

You could use reference modification ... for example your PIC X(4)

* SAMPLE-VAL contains number to be stringed
MOVE '0043' TO SAMPLE-VAL

COMPUTE FIELD-LENGTH = 4
PERFORM VARYING I FROM 1 BY 1 UNTIL I > FIELD-LENGTH OR
    (SAMPLE-VAL(I:1) > '0')
END-PERFORM

* Now SAMPLE-VAL(I:FIELD-LENGTH - I + 1) contains your "trimmed" numeric
value.



Thu, 28 Sep 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Quote:

> >How do you strip leading zeroes from a field so that the first significant
> >digit will occupy the first position.  So that a pic x(4) like 0043
> becomes
> >43bb (b for space).  PIC Z4 will strip them but leave blanks, same thing
> with
> >INSPECT REPLACING.
> > I need to put the stripped field into a STRING command with a delimited
> >by space or size option     so that the output will be like '43' not '0043'
> or
> >'43  '.

> >Does anybody have a simpler more elegant solution?

> You could use reference modification ... for example your PIC X(4)

> * SAMPLE-VAL contains number to be stringed
> MOVE '0043' TO SAMPLE-VAL

> COMPUTE FIELD-LENGTH = 4
> PERFORM VARYING I FROM 1 BY 1 UNTIL I > FIELD-LENGTH OR
>     (SAMPLE-VAL(I:1) > '0')
> END-PERFORM

> * Now SAMPLE-VAL(I:FIELD-LENGTH - I + 1) contains your "trimmed" numeric
> value.

How about This:
Where Fld is:
          77 fld pic  x(07) value '0001234'.
          77 Ctr Pic s9     value  +0.

Inspect Fld Replacing Leading Space by Zero. /* Just in case...

Perform Until Fld(1:1) NOT = ZERO  /* 1stPass  2ndPass
3rdPass                   Move Fld(2: )             /* 0001234  001234_
01234__  
           to Fld                  /* 001234_  01234__  1234___
         Add  1                    /* Not required unless you need to
           to Ctr                  /* know number of bytes shifted...
End-Perform



Thu, 12 Oct 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Quote:

>How about This:
>Where Fld is:
>          77 fld pic  x(07) value '0001234'.
>          77 Ctr Pic s9     value  +0.

>Inspect Fld Replacing Leading Space by Zero. /* Just in case...

>Perform Until Fld(1:1) NOT = ZERO  /* 1stPass  2ndPass
>3rdPass                   Move Fld(2: )             /* 0001234  001234_
>01234__
>           to Fld                  /* 001234_  01234__  1234___
>         Add  1                    /* Not required unless you need to
>           to Ctr                  /* know number of bytes shifted...
>End-Perform

The statement

        Move Fld(2:) to Fld

contains overlapping operands. Such moves are "undefined" by the
COBOL standard. Some compilers have options which guarantee
that the statement will not have unintended effects; but the code is
not portable.

Rick Smith
--------------------------------------------------------------



Fri, 13 Oct 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Actually, I've a little subroutine I've written for such occassions ... the
sequence is...

01  FORTY-CHARACTER-FIELD.
      05  FILLER         PIC X(30).
      05  ZERO-SUP    PIC ZZZZZZZZZ9.

01  PADDING-CHARACTER.
      05  FILLER        PIC X(01) VALUE SPACE.

       MOVE 0001234 to ZERO-SUP.
       CALL 'LEFTJUST' USING FORTY-CHARACTER-FIELD PADDING-CHARACTER.

The subroutine does either left or right justification depending on the
entry point called.  I usually find that its best to devise a subroutine to
handle things is a dependable and repeatable manner, also, the logic only
need be documented in one place but can be used wherever.



Thu, 26 Oct 2000 03:00:00 GMT  
 How do you strip leading zeros so that 1st significant digit will occupy 1st position

Quote:

> Actually, I've a little subroutine I've written for such occassions ...

Kevin - can you post the code for the subroutine, or email me with it.
Sounds like a handy tool.  

Thanks
Bob
--
<---------------------------------------------------------------------->
                 Bob Berman   -    West Hartford, CT                  

                 THE TRUE TERRORISTS IN AMERICA ARE                    
          THE PEOPLE WHO DEMAND TO SEE THE STORE MANAGER !              
<----+----+----+----+----+----+----+----+----+----+----+----+----+----+>



Thu, 26 Oct 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. How do you strip leading zeroes from a field so that the 1st significant digit will occupy the 1st position

2. Get around str() limitation of 7 significant digits?

3. significant digits

4. str( ) significant digits

5. Printing significant digits past decimal point

6. sin/cos in 34 clocks @ almost 6 significant digits

7. Fractional Significant Digits

8. WRITE/FORMAT for significant digits

9. how to control significant digit ?

10. Significant digits

11. significant digits and rounding

12. significant digits

 

 
Powered by phpBB® Forum Software