IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Truncate the leading zeros and concatnate with another Var


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gneelu

New User


Joined: 26 May 2006
Posts: 18

PostPosted: Tue Nov 21, 2006 10:17 am
Reply with quote

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
View user's profile Send private message
hey_its_me
Warnings : 1

New User


Joined: 23 Aug 2006
Posts: 14
Location: USA

PostPosted: Tue Nov 21, 2006 11:54 am
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue Nov 21, 2006 12:17 pm
Reply with quote

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
View user's profile Send private message
hey_its_me
Warnings : 1

New User


Joined: 23 Aug 2006
Posts: 14
Location: USA

PostPosted: Tue Nov 21, 2006 12:53 pm
Reply with quote

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
View user's profile Send private message
hey_its_me
Warnings : 1

New User


Joined: 23 Aug 2006
Posts: 14
Location: USA

PostPosted: Tue Nov 21, 2006 1:32 pm
Reply with quote

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
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Tue Nov 21, 2006 2:28 pm
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue Nov 21, 2006 4:15 pm
Reply with quote

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
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Wed Nov 22, 2006 9:16 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts How to display the leading zeros of a... DB2 7
This topic is locked: you cannot edit posts or make replies. Suppressing only leading zeros (not s... DFSORT/ICETOOL 9
Search our Forums:

Back to Top