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

Author Message
dipanshu

New User

Joined: 16 Jan 2006
Posts: 53
Location: pune

 Posted: Thu Feb 02, 2006 9:16 am    Post subject: How to remove leading & trailing space. 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

bhardwajparitosh

New User

Joined: 30 Jul 2005
Posts: 4
Location: india

 Posted: Thu Feb 02, 2006 12:56 pm    Post subject: i think i know 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
dipanshu

New User

Joined: 16 Jan 2006
Posts: 53
Location: pune

 Posted: Thu Feb 02, 2006 1:40 pm    Post subject: 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
sudheer_kumar

New User

Joined: 27 Dec 2005
Posts: 16

 Posted: Thu Feb 02, 2006 3:44 pm    Post subject: 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
DavidatK

Active Member

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

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

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

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics The TS7720 is out of cache space. Rex Montemayor All Other Mainframe Topics 2 Mon Sep 25, 2017 7:18 am Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am VSAM Space Allocation mrgnndhmk JCL & VSAM 7 Sat Apr 22, 2017 12:42 am Need help in estimating space of unlo... ashek15 IMS DB/DC 12 Fri Apr 07, 2017 5:11 am Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm

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