Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
gneelu

New User

Joined: 26 May 2006
Posts: 18

 Posted: Tue Nov 21, 2006 10:17 am    Post subject: Truncate the leading zeros and concatnate with another Var 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

hey_its_me
Warnings : 1

New User

Joined: 23 Aug 2006
Posts: 14
Location: USA

 Posted: Tue Nov 21, 2006 11:54 am    Post subject: Re: Truncate the leading zeros and concatnate with another V 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
Arun Raj

Moderator

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

 Posted: Tue Nov 21, 2006 12:17 pm    Post subject: Re: Truncate the leading zeros and concatnate with another V 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
hey_its_me
Warnings : 1

New User

Joined: 23 Aug 2006
Posts: 14
Location: USA

 Posted: Tue Nov 21, 2006 12:53 pm    Post subject: Re: Truncate the leading zeros and concatnate with another V 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
hey_its_me
Warnings : 1

New User

Joined: 23 Aug 2006
Posts: 14
Location: USA

 Posted: Tue Nov 21, 2006 1:32 pm    Post subject: Re: Truncate the leading zeros and concatnate with another V 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]
cobolunni

Active User

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

Posted: Tue Nov 21, 2006 2:28 pm    Post subject:

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
Arun Raj

Moderator

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

Posted: Tue Nov 21, 2006 4:15 pm    Post subject:

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.
cobolunni

Active User

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

Posted: Wed Nov 22, 2006 9:16 am    Post subject:

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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Issue in suppressing leading zeros &a... Vijay_Sirisha COBOL Programming 21 Thu Jun 07, 2018 8:01 pm Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am editting the file by inserting zeros ... pramodrsingh DFSORT/ICETOOL 9 Mon Aug 21, 2017 5:58 pm Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm Join key - Populate Zeros when Unpair... rexx77 DFSORT/ICETOOL 6 Thu May 12, 2016 12:22 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us