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
 

 

How to remove leading & trailing space.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
dipanshu

New User


Joined: 16 Jan 2006
Posts: 53
Location: pune

PostPosted: Thu Feb 02, 2006 9:16 am    Post subject: How to remove leading & trailing space.
Reply with quote

Hi,

Suppose

x1 pic x(9) value is 'abc'
x2 pic x(9)

move x1 to x2

now x2 should display only 'abc' with no trailing spaces
pls suggest with code too.
thanks,
Dipanshu
Back to top
View user's profile Send private message

bhardwajparitosh

New User


Joined: 30 Jul 2005
Posts: 4
Location: india

PostPosted: Thu Feb 02, 2006 12:56 pm    Post subject: i think i know
Reply with quote

use refrence modification
move x1(1:3) to x2.
or at the time of display u can use
display x1(1:3).

this will most probably remove trailing space

another way to solve the proble to have x2 pic x(3) so everything will be automatically done if u move the variable
Back to top
View user's profile Send private message
dipanshu

New User


Joined: 16 Jan 2006
Posts: 53
Location: pune

PostPosted: Thu Feb 02, 2006 1:40 pm    Post subject:
Reply with quote

Hi,
You r right
but i want some generalised logic, The above I given is just the example, value may be vary from 1 chracter to 9 chracter and the logic u given is only meant for 3 chracter.

Pls reply with some flexible logic ?

Thanks,
Dipanshu
Back to top
View user's profile Send private message
sudheer_kumar

New User


Joined: 27 Dec 2005
Posts: 16

PostPosted: Thu Feb 02, 2006 3:44 pm    Post subject:
Reply with quote

01 WS-STR PIC X(15).
01 WS-STR1 PIC X(15).
01 I PIC 9 VALUE 1.
01 J PIC 9 VALUE 1.
01 WS-LEN-2 PIC S9(04) COMP.

MOVE ' NAVEEN ' TO WS-STR
MOVE LENGTH OF WS-STR TO WS-LEN-2

PERFORM VARYING I FROM 1 BY 1 UNTIL I > WS-LEN-2
IF WS-STR(I:1) NOT EQUAL SPACE
MOVE WS-STR(I:1) TO WS-STR1(J:1)
ADD 01 TO J
END-IF
END-PERFORM

The WS-STR1 contains 'NAVEEN'.

If I am wrong let me know.

Regards,
Sudheer
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Feb 04, 2006 2:25 am    Post subject: Re: How to remove leading & trailing space.
Reply with quote

dipanshu,

Question.

The title to your subject is:
Quote:

How to remove leading & trailing space.


Does this imply that your data might be " DAVE " with leading and trailing spaces? and you want the variable to display "DAVE" with no leading or trailing spaces?

The post by sudheer_kumar will not work as you might think.
If variable WS-STR1 initially contained "1234567890ABCDE" and you execute his moves, the result in WS-STR1 will be "NAVEEN7890ABCDE"

Then post by bhardwajparitosh


Quote:

use refrence modification
move x1(1:3) to x2.
or at the time of display u can use
display x1(1:3).

this will most probably remove trailing space

another way to solve the proble to have x2 pic x(3) so everything will be automatically done if u move the variable


is pretty close. If you move x1(1:3) to x2, x2 will contain "ABC " ("ABC trailed by 12 spaces)

The display x1(1:3) will work 'display x1(beg_loc:len)' is better, the problem is knowing where the starting char is and the length of the string you want to display.

The last suggestion I really like, the problem is knowing how long the PIC needs to be.

Making the assumption that you have taken care of the leading spaces so the text is left justified, the code below may be of interest to you.

Code:


01  PGM-VARIABLES.                                             
    05  CHAR-CNT                PIC 9(5)    VALUE 15.           
    05  X1                      PIC X(15)   VALUE 'ABC'.       
    05  X2.                                                     
        10  X2-X                OCCURS 1 TO 15 TIMES           
                                DEPENDING ON CHAR-CNT PIC X.
PROCEDURE DIVISION.                               
                                                   
    MOVE 'ABC'                  TO X1.             
    PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.   
    MOVE X1                     TO X2.             
    DISPLAY '>' X2 '<'.                           
                                                   
    MOVE 'DIPANSHU'             TO X1.             
    PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.   
    MOVE X1                     TO X2.             
    DISPLAY '>' X2 '<'.                           
                                                   
    MOVE SPACES                 TO X1.             
    PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.   
    MOVE X1                     TO X2.             
    DISPLAY '>' X2 '<'.     
                       
    MOVE 'HELLO DIPANSHU!'      TO X1.             
    PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.     
    MOVE X1                     TO X2.             
    DISPLAY '>' X2 '<'.                             
                                                   
    GOBACK.                                         
P1000-GET-CHAR-CNT.                                 
                                                   
    PERFORM                                         
      VARYING CHAR-CNT FROM LENGTH OF X1 BY -1     
      UNTIL X1(CHAR-CNT:1) NOT = ' '               
      OR CHAR-CNT < 1                               
    END-PERFORM.                                   
                                                   
P1000-EXIT.                                         
    EXIT.                                           


The above code produces the following output.

Code:

.SARPAGE 40           
.                     
.>ABC<                 
.>DIPANSHU<           
.><                   
.>HELLO DIPANSHU!<     
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 Remove Special Characters from Mainfr... Rodger Zhang All Other Mainframe Topics 6 Wed Jul 06, 2016 1:12 am
No new posts Difference space showed for TS and it... autobox DB2 1 Thu Apr 14, 2016 1:07 pm
No new posts Remove header only knobi SYNCSORT 5 Mon Feb 15, 2016 10:42 pm
No new posts How to find Table-space and Index-spa... venksiv DB2 5 Wed Feb 03, 2016 6:16 pm
No new posts Append to file, but also remove old r... Garry Carroll JCL & VSAM 3 Mon Jan 25, 2016 8:05 pm


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