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

easy way to move 'PIC 9' to 'PIC X JUST LEFT' with zero supression?

Status
Not open for further replies.

alexss

Programmer
May 12, 2005
1
CH
hello all

how can i do the following:

SENDIG FIELD:
PIC: 9FIELD PIC 9(10).
DATA: 0000000450

RECEIVING FIELD:
PIC: XFIELD PIC X(10).
DATA: '450 '

is there an easy way to move this without programming?

i tried the way over a 'ZZZZZZZZZZ'-pictured workfield but that doesnt work, the leading spaces were also moved to the PIC X field...

can i STRING or UNSTRING something? or do i have to check each position of the field for leading zeros?


thanks for any hints!
alex
 
A starting point:
01 Field9 PIC 9(10) VALUE 450.
01 FieldX PIC X(10) VALUE SPACE.
01 I2 PIC 99 VALUE ZERO.
...
MOVE 1 TO I2
INSPECT Field9 TALLYING i4 FOR LEADING "0"
MOVE Field9(I2:) TO FieldX

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Just inspect the field removing zeros till you reach the first non-zero digit. There are various ways to do this. If you do an inspect you can just increment a counter to count the leading zeros and use that number and the total field size to calculate what to move in a satatement where you have a variable XYZ:

MOVE VAR-1 (XYZ:) TO RESULT-FIELD.

Here is an example of something I did with an address edit routine. I was doing several things in this example to break up an address field where the entire address is in one field including the city, state, Zip and spaces on the end of the field:

It might be a little crude but it works.


..1....+....2....+....3....+....4....+....5....+..
ADDRESS-EDIT.
MOVE ZERO TO BLK-CTR, TEMP-CTR.
INSPECT FUNCTION REVERSE(WS-ADDRESS-1)
TALLYING BLK-CTR FOR LEADING SPACES.
MOVE WS-ADDRESS-1 TO WS-ADDRESS.
COMPUTE TEMP-CTR = (30 - BLK-CTR).
ADD 1 TO TEMP-CTR.
MOVE ', ' TO WS-ADDRESS (TEMP-CTR:2).
ADD 3 TO TEMP-CTR.
MOVE ZERO TO BLK-CTR.
INSPECT FUNCTION REVERSE(WS-CITY)
TALLYING BLK-CTR FOR LEADING SPACES.
MOVE WS-CITY (1:(19 - BLK-CTR)) TO
WS-ADDRESS (TEMP-CTR:(19 - BLK-CTR)).
COMPUTE TEMP-CTR = (TEMP-CTR + (19 - BLK-CTR)).
MOVE ZERO TO BLK-CTR.
MOVE ', ' TO WS-ADDRESS (TEMP-CTR:2).
ADD 2 TO TEMP-CTR.
MOVE WS-STATE TO WS-ADDRESS (TEMP-CTR:2).
ADD 3 TO TEMP-CTR.
IF WS-ZIP-2 = SPACES MOVE WS-ZIP-1 TO
WS-ADDRESS (TEMP-CTR:5)
ELSE
MOVE WS-ZIP-1 TO WS-ADDRESS (TEMP-CTR:5)
MOVE '-' TO WS-ADDRESS ((TEMP-CTR + 5):1)
MOVE WS-ZIP-2 TO WS-ADDRESS ((TEMP-CTR + 6):4).




If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top