View previous topic :: View next topic
|
Author |
Message |
gneelu
New User
Joined: 26 May 2006 Posts: 18
|
|
|
|
HI ALL,
I have two variables and I need to truncate the leading zeros of one of the variables and concatnate the value with another variable...
FOR EXAMPLE
X(20) - 00000001234
X(3) - 66
I HAVE TO PREFIX 66 WITH 1234 , THE END RESULT WILL BE 661234
BUT I AM GETTING IT AS 660000001234
THANKS & REGARDS
NEELAVENI |
|
Back to top |
|
|
hey_its_me Warnings : 1 New User
Joined: 23 Aug 2006 Posts: 14 Location: USA
|
|
|
|
hi neelaveni,
could you try this manner.
let
no1_alpha pic x(20) = 00000001234.
no2_alpha pic x(03) = 66.
declare new variables
01 new_no.
05 no2_num pic 9(02).
05 no1_num pic 9(04).
01 concat pic x(06) redefines new_no.
procedure division.
move no1_alpha to no1_num.
move no2_alpha to no2_num.
with regards,
Anil |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi Anil
Suppose if I dont know the exact length of the numeric value contained in that PIC X(20) data item.How can I proceed in that scenario?.
Thanks |
|
Back to top |
|
|
hey_its_me Warnings : 1 New User
Joined: 23 Aug 2006 Posts: 14 Location: USA
|
|
|
|
HI,
I think there is a system function
function length(dataname) gives the length of the data in the variable.
correct me if i'm wrong.
with regards,
Anil |
|
Back to top |
|
|
hey_its_me Warnings : 1 New User
Joined: 23 Aug 2006 Posts: 14 Location: USA
|
|
|
|
Hi,
sorry the FUNCTION LENGTH(dataname) returns an integer which is the length of the variable.
like if the variable is x(20) then it returns 20.
try this way.
change the size of the variable we declared earlier no1_num to the same size of the no1_alpha.
01 rem pic 9(08) value 10.
01 concat pic x(30) value spaces.
perform find-length until div < 10
move no1_alpha to concat (1:length).
move length to length_temp.
do the find-length routine for the next no2-num.
then move no2_alpha to concat (length_tem+1:length).
stop run.
find-length.
divide no1_num by rem giving div.
multiply 10 by rem.
add 1 to length.
[/b] |
|
Back to top |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
we can use inspect and reference modifier
first use INSPECT on X(20) to find the char length after 0's
Code: |
INSPECT FIRSTNO TALLYING COUNTER FOR LEADING ZEROS.
|
Now use refference modifier to concat
Code: |
MOVE SECONDNO(1:2) TO FIRSTNO( COUNTER - 2 : 2 ) |
Hope this will work .Know me if i made any mistake |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi
Try this logic.It worked for me.
Code: |
WORKING-STORAGE SECTION.
77 NO1-ALPHA PIC X(20) VALUE '00000001234'.
77 NO2-ALPHA PIC X(03) VALUE '66'.
77 CNT PIC S9(04) COMP.
77 TEMP PIC X(20).
77 RESULT PIC X(30).
PROCEDURE DIVISION.
INSPECT NO1-ALPHA TALLYING CNT FOR LEADING "0"
MOVE NO1-ALPHA(CNT + 1:) TO TEMP.
STRING NO2-ALPHA,TEMP DELIMITED BY ' ' INTO RESULT.
DISPLAY "RESULT:" RESULT.
|
Thanks
Arun. |
|
Back to top |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
Hope this will work
Code: |
ID DIVISION.
PROGRAM-ID. COC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FIRSTNO PIC X(20).
01 SECONDNO PIC X(3).
01 COUNTER PIC 9(3).
PROCEDURE DIVISION.
MAIN.
ACCEPT FIRSTNO.
ACCEPT SECONDNO.
INSPECT FIRSTNO TALLYING COUNTER FOR LEADING '0'.
MOVE SECONDNO(1:3) TO FIRSTNO( COUNTER - 2 : 3).
DISPLAY FIRSTNO.
STOP RUN. |
|
|
Back to top |
|
|
|