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!

search/remove/reformat an alphanumeric data field

Status
Not open for further replies.

danadoo

Programmer
May 30, 2003
1
US
I have a alphanumeric field, length of 10, that can contain a decimal point in at least one position (not always the same position). My challenge is to search the field for the decimal point, remove it, and then move the reformatted field into another alphanumeric field with the same length. Leading spaces are not an issue, but trailing spaces are. Please help.
 
Hi Dan,

You say "a decimal point in at least one position" are we to assume more than one. The rest of your post doesn't suppurt that assumption.

You also say "Leading spaces are not an issue, but trailing spaces are." Why don't you give us a few before and after scenerios, e.g.:

B - "bb123.456b" A - "0000123456"

or is it:

B - "bb123.456b" A - "1234560000"

or

B - "bb123.456b" A - "0001234560"

or

B - "bb123.456b" A - "0012345600"

well, you get the idea.

Regards, Jack.
 
A solution I have seen implemented in several shops is to process the string byte by byte, starting in the first non space char, until the first space after that point (or end of field).
All chars not in 0-9, "-", "+" and whatever is defined as decimal point are ignored from a first processing of the string.
E..G.
01 input-string pic x(20) value "bb1,123.45678b234".
01 work-num-int pic X(10).
01 work-num-dec pic X(10).
01 work-num-int-count pic 99.
01 work-num-dec-count pic 99.
01 output-string pic 9(10)V9(10).
01 output-string-r redefines output-string.
05 output-string-int pic 9(10).
05 output-string-dec pic 9(10).

Step 1
work-num-int = "1123bbbbbb"
work-num-int-count = 4
work-num-dec = "45678bbbbb"
work-num-dec-count = 5

Step 2
move work-num-int(1:work-num-int-count) to output-string-int.

As for how to populate the decimal bit I leave that up to you. There are several ways this can be acomplished, and this should make you think on some of the problems that will arise.

The final result would be
output-string = "00000011234567800000"

Note that I have ignored a possible sign. This should be subject to the same type of handling.

Hope this is enough to help you. If not please post whatever code you have done, and w'ill try to give you more pointers
 
Hi,

Is it possible to use one of the newer functions like NUMVAL and NUMVAL-C?

MOVE FUNCTION NUMVAL-C UR10BYTES-FIELD TO THE-NUMERIC-FIELD.

Regards,

Crox
 
This is why I asked for some data samples. What Dan's looking to do and to what is open to debate.

For example, how is ".1234bbbbb" converted? "0000001234"? Probably, but it depends on what he intends to do w/the data.

I'm sure he'll clarify.

Regard, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top