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

How to remove spaces while performing STRING operation


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

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 15, 2009 12:51 pm
Reply with quote

Hi,

I am stringing the below 2 fields into W-OUTPUT-REC.

77 VENDOR PIC X(20).
77 LOCATION PIC X(20).

77 W-OUTPUT-REC PIC X(60).

If VENDOR and LOCATION has contains the data as below

VENDOR: FIRST DATA
LOCATION: BOMBAY

After i execute

STRING VENDOR DELIMITED BY SIZE
LOCATION DELIMITED BY SIZE
INTO W-OUTPUT-REC.

o/p : FIRST DATA BOMBAY

after BOMBY i am getting 20 dots, i want to remove the dots also

I want o/p should be FIRST DATABOMBAY

Could any one help in this.

Regards
Suneel
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Thu Jan 15, 2009 3:34 pm
Reply with quote

Hi,

You can try this..

MOVE SPACES TO ERROR-RECORD.

STRING VENDOR DELIMITED BY SIZE
LOCATION DELIMITED BY SIZE
INTO ERROR-RECORD

OR .............

01 ERROR-RECORD.
05 ERROR-REC1 PIC X(40).
05 FILLER PIC X(20) VALUE SPACES.

STRING WS-VENDOR DELIMITED BY SIZE
WS-LOCATION DELIMITED BY SIZE
INTO ERROR-REC1

Let me know if this works for you.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 15, 2009 5:35 pm
Reply with quote

Hi,

Its not working.

Regards
Suneel
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Thu Jan 15, 2009 5:51 pm
Reply with quote

It had worked for me when I did a test. Are you getting null values now also at the end of the file?

Which option you tried of both? More details would help!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 15, 2009 6:48 pm
Reply with quote

The dots are probably LOW-VALUES from not initializing the output field before you use it. Move spaces to it before the STRING or add VALUE SPACES to its definition.

As far as what you want,
Code:
           05  VENDOR                  PIC X(20) VALUE 'FIRST DATA'.
           05  SEP                     PIC X(01) VALUE SPACE.
           05  LOCATION                PIC X(20) VALUE 'BOMBAY'.
           05  WS-VAR-OUT              PIC X(60).

       LINKAGE SECTION.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE SPACES                 TO  WS-VAR-OUT.
           STRING VENDOR   DELIMITED BY '  '
                  SEP      DELIMITED BY SIZE
                  LOCATION DELIMITED BY SPACE
             INTO WS-VAR-OUT.
           DISPLAY 'VENDOR:    ' VENDOR.
           DISPLAY 'LOCATION:  ' LOCATION.
           DISPLAY 'COMBINED:  ' WS-VAR-OUT.
gives me this output:
Code:
 VENDOR:    FIRST DATA
 LOCATION:  BOMBAY
 COMBINED:  FIRST DATA BOMBAY
However if the vendor field has 19 characters in it there's an extra space between the fields. This could be checked for via reference modification; it depends on how critical the spacing is for you.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 15, 2009 7:31 pm
Reply with quote

Hi,

But after FIRST DATA iam getting 10 spaces and since VENDOR is of length 20
After BOMBAY also there are 14 bytes of space since LOCATION is of length 20

I want to remove the spaces after FIRST DATA and BOMBAY

Regards
Suneel
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 15, 2009 8:18 pm
Reply with quote

If you use DELIMITED BY SIZE the entire field is moved via STRING. SIZE refers to the variable PIC, not the actual number of non-blank characters in the variable.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Thu Jan 15, 2009 10:32 pm
Reply with quote

Hi,

But i want o/p should be FIRST DATA without spaces after FIRST DATA

same should be for LOCATION

without spaces after BOMBAY

Regards
Suneel
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Jan 15, 2009 10:44 pm
Reply with quote

How about:
Code:
STRING VENDOR DELIMITED BY x'4040'
     LOCATION DELIMITED BY x'4040'
  INTO W-OUTPUT-REC.

or:
Code:
STRING VENDOR DELIMITED BY x'4040'
        x'40' DELIMITED BY SIZE
     LOCATION DELIMITED BY x'4040'
  INTO W-OUTPUT-REC.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 15, 2009 11:55 pm
Reply with quote

Your recent post:
Quote:

But i want o/p should be FIRST DATA without spaces after FIRST DATA

same should be for LOCATION

without spaces after BOMBAY
conflicts with your original request, where you wanted a space after the vendor before the location. Furthermore, you need to be aware that you are stringing 2 20-bytes fields into a 60-byte field. A minimum of 20 bytes and a maximum of 57 bytes of the output variable will not be coming from the STRING variables. What do you want these 20 to 57 bytes to be? They are going to be something -- spaces, LOW-VALUES, HIGH-VALUES, periods, or anything else in the collating sequence. You can pick the character but you cannot opt for them not to exist as they will exist, period.

The code I provided you has output that matches precisely what your last post says you want -- so what's the problem with it?
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 16, 2009 12:10 am
Reply with quote

Hi,

Each field is of 20 bytes each and stringing into 60 bytes.

If the fields VENDOR or LOCATION contains less than 20 bytes the remaing are filled with spaces but i want to remove the spaces.

After 40 bytes stringing into 60 bytes ,still 20 bytes left they are filled with
dots.

I want to remove the dots in last 20 bytes from 41 to 60.

This is my requirement.


I tried the below code:

STRING VENDOR DELIMITED BY x'4040'
x'40' DELIMITED BY SIZE
LOCATION DELIMITED BY x'4040'
INTO W-OUTPUT-REC

but still 1 space is coming after VENDOR.

why 1 space is coming i am looking into this one.

Could any one help on this.

Regards
Suneel
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 16, 2009 12:14 am
Reply with quote

Remove the dots by
Code:
MOVE SPACES TO W-OUTPUT-REC
before your STRING statement. Have you tried the
Code:
DELIMITED BY '  '
instead of SIZE as I specified?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Jan 16, 2009 12:14 am
Reply with quote

Reread Robert's reply. He just explained the situation in detail.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Jan 16, 2009 12:21 am
Reply with quote

Quote:
why 1 space is coming i am looking into this one.

x'40' DELIMITED BY SIZE!
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 16, 2009 12:35 am
Reply with quote

Hi,


I moved spaces to W-OUPUT-REC before string statement but one space is removed after VENDOR and LOCATION.

Regards
Suneel
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 16, 2009 12:41 am
Reply with quote

Hi,

But dots are not removed after stringing vendor,location into W-output-rec. Dots are present from 41 to 60.

Regards
Suneel
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Jan 16, 2009 12:45 am
Reply with quote

Suneel,
I repeat: Reread Robert's post of 12:25 PM.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 16, 2009 1:30 am
Reply with quote

Post exactly what your code looks like (with BBCode) and the output as it is generated by this code, and also post what you want done differently.
Back to top
View user's profile Send private message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 16, 2009 6:36 pm
Reply with quote

Hi,

WS varibles:

77 VENDOR PIC X(20).
77 LOCATION PIC X(20).
77 W-OUTPUT-REC PIC X(60).

Code:

MOVE SPACES TO W-OUTPUT-REC.

STRING C-QUOTE DELIMITED BY SIZE
VENDOR DELIMITED BY X'4040'
X'40' DELIMITED BY " "
INTO W-OUTPUT-REC.

O/P generated by above code

FIRST DATABOMBAY..........................................

o/p should be : FIRST DATABOMBAY

Regards
Suneel
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 16, 2009 11:41 pm
Reply with quote

Hello,

Did you copy/paste the generated output or did you type it? Have you ensured that BOMBAY is actually followed by spaces, not some strange hex value?

What is in this field (C-QUOTE)? Make sure it is not blank and run again. When doing this, also display the individual input fields in hex and post that.

As requested earlier, use the "Code" tag for readability (do not use screenshots).
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Tue Jan 20, 2009 6:41 pm
Reply with quote

Hi,
Please find below one solution for your query.
I have not considered the C-QUOTE in the below code.
Below code is for the values:
VENDOR : FIRST DATA
LOCATION : BOMBAY


STRING VENDOR DELIMITED BY X'4040'
LOCATION DELIMITED BY X'4040'
INTO W-OUTPUT-REC.

Inspect W-OUTPUT-REC REPLACING all LOW-VALUES by SPACES.


OUTPUT:FIRST DATABOMBAY

Second inspect will remove all the low values from the string.
I hope this will help you out from the problem. icon_smile.gif

If possible, also confirm to the post of Dick whether the code you have provided was the copy paste or you type it?
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
Search our Forums:

Back to Top