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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula to add zeros to a string 1

Status
Not open for further replies.

RedHeadedStepITChild

IS-IT--Management
May 31, 2007
46
US
Hello all,

I hope this post finds you all well.

I am using Crystal v.11. Connected via ODBC to a DB2 database on an AS400 v.5 r.3.

In the past we have used a report that I created to print out for inventory tags, which were manually filled out by the counters. This year we are attempting to use a barcode reader, which will capture data so that we can send it back to the ERP. So, in preparation for that I have taken the same report and added a field formatted as Code39 barcode. It is a formula that concatenates multiple fields from the DB. The problem is that one of the fields is not a set length, and for our parsing program to work correctly, it needs to be.

Example of the output as I have it now:

*1BT1012PS*

The *'s are the start/stop for the barcode readers
The first 1 is the tag number
BT1012 is the item number - (this field needs to be 10 characters long no matter the length in the DB)
PS is the warehouse location.

Here is the formula that I am attempting to use to add leading zeros to the item number:

StringVar itemNumber;
numberVar counter;

For counter := 0 to (10 - length({ICTL02.CTPROD})) do
(
itemNumber := 0 & {ICTL02.CTPROD}
);

itemNumber

The ICTL02.CTPROD is the item number field in the DB.

The output of this formula for the particular example posted above is 0BT1012 - so it looks like it is going through the loop once, but will not iterate.

Any ideas?

Best regards,

Jason
 
I think you could just use:

replicatestring("0",10-len({table.itemno})+{table.itemno}

-LB
 
Thanks LB!

I have not tried it out, but I will.

I just got the notification around the same time that I took a different route successfully.

I ended up just using:

numberVar zeroValue := 15 - length({ICTL02.CTPROD});

Select zeroValue
Case 14:
{ICTL02.CTPROD} & "=============="
Case 13:
{ICTL02.CTPROD} & "============="
Case 12:
{ICTL02.CTPROD} & "============"
Case 11:
{ICTL02.CTPROD} & "==========="
Case 10:
{ICTL02.CTPROD} & "=========="
Case 9:
{ICTL02.CTPROD} & "========="
Case 8:
{ICTL02.CTPROD} & "========"
Case 7:
{ICTL02.CTPROD} & "======="
Case 6:
{ICTL02.CTPROD} & "======"
Case 5:
{ICTL02.CTPROD} & "====="
Case 4:
{ICTL02.CTPROD} & "===="
Case 3:
{ICTL02.CTPROD} & "==="
Case 2:
{ICTL02.CTPROD} & "=="
Case 1:
{ICTL02.CTPROD} & "="
Case 0:
{ICTL02.CTPROD}

My RPG programmer decided he didn't want zeros, but wanted spaces to act as buffer space. I found that the = works well as a space "character" for the code39 barcode that we have.

My only question is -- depending on the location this report is being run for, there can be quite a few detail records. Would performance benefit from your formula, or would the switch still be sufficient?
 
I don't know whether it matters in any significant way. It's just that my formula would have been simpler to write!

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top