Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Truncate the leading zeros and concatnate with another Var

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Truncate the leading zeros and concatnate with another Var
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    Post subject: Re: Truncate the leading zeros and concatnate with another V
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: 2180
Location: @my desk

PostPosted: Tue Nov 21, 2006 12:17 pm    Post subject: Re: Truncate the leading zeros and concatnate with another V
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    Post subject: Re: Truncate the leading zeros and concatnate with another V
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    Post subject: Re: Truncate the leading zeros and concatnate with another V
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: 128
Location: kerala,india

PostPosted: Tue Nov 21, 2006 2:28 pm    Post subject:
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: 2180
Location: @my desk

PostPosted: Tue Nov 21, 2006 4:15 pm    Post subject:
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: 128
Location: kerala,india

PostPosted: Wed Nov 22, 2006 9:16 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join key - Populate Zeros when Unpair... rexx77 DFSORT/ICETOOL 6 Thu May 12, 2016 12:22 am
No new posts Syncsort to remove the leading spaces V S Amarendra Reddy SYNCSORT 5 Fri Jan 08, 2016 9:47 pm
This topic is locked: you cannot edit posts or make replies. Mainframe Jobs in Leading Indian MNC aman2248 Mainframe Jobs 0 Mon Dec 21, 2015 3:25 pm
No new posts Removing Leading Spaces and Removing ... rahulpala COBOL Programming 4 Fri Sep 04, 2015 4:58 am
No new posts CSV file , to display numeric data w... Deepthy Jose P JCL & VSAM 10 Fri Nov 21, 2014 12:50 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us