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

space suppression


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

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Thu Nov 05, 2009 8:47 pm
Reply with quote

hi,

here is my query

01 HS PIC X(50)

MOVE a-3 TO HS(1:30)
MOVE a-4 TO HS(31:20)

O/P
203 E...............................114 ABCD.

But i need the o/p as

203 E, 114 ABCD.

if there are less than 30 characters i don't need spaces sometimes i'll get value for tht 30 characters also.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Thu Nov 05, 2009 8:56 pm
Reply with quote

Starting at the 30th character of HS and going backwards, find the first non-space AFTER you've done the MOVE a-3 statement. Add 1 to that location, then move in the comma, add 1 and use this as the starting location of HS for the MOVE a-4 statement.
Back to top
View user's profile Send private message
mf_karthik

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Fri Nov 06, 2009 9:24 am
Reply with quote

thnks for your reply..can u explain it little more..

any suggestions.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Nov 06, 2009 9:39 am
Reply with quote

Hello,

Quote:
any suggestions.

Suggest you write code such as Robert described. . .

What is not clear? What have you coded so far?

Move spaces to HS. Then, there should be a move (a-3), a loop to find the last position in the HS field, and another move (a-4) to the position that is one greater than the last position filled with a non-space by the first move.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Nov 06, 2009 3:46 pm
Reply with quote

This is a HELP forum, not a WRITE-THE-CODE-FOR-YOU forum. Once you post code that you're having a problem with, we can help you more. But unless you're showing some initiative in writing code, we won't write it for you.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 06, 2009 5:04 pm
Reply with quote

how many times have we seen this homework assignment?

tally reverse, move (xx:xx)

search the forum for 'reverse', there are many posts where the TS needed to concatenate strings that had spaces at the end.
Back to top
View user's profile Send private message
k.junaid83

New User


Joined: 19 Apr 2006
Posts: 22
Location: bangalore

PostPosted: Fri Nov 06, 2009 7:16 pm
Reply with quote

Another option is

STRING a-3 DELIMITED BY SPACES,
a-4 DELIMITED BY SPACES,
INTO HS
END-STRING.
Back to top
View user's profile Send private message
k.junaid83

New User


Joined: 19 Apr 2006
Posts: 22
Location: bangalore

PostPosted: Fri Nov 06, 2009 7:20 pm
Reply with quote

Oh I forgot the statement to add comma, My apologies

STRING a-3 DELIMITED BY SPACES,
',' DELIMITED BY SIZE,
a-4 DELIMITED BY SPACES,
INTO HS
END-STRING.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 06, 2009 8:16 pm
Reply with quote

k.junaid83,

problem with your solution is that the initial strings contain spaces.

203 E...............................114 ABCD

so, the end result of your solution would be:

203,114

instead of:
203 E, 114 ABCD

and before you step on yourself, and suggest that the delimiter be two spaces,

if the initial string were 29 chars, with intervening spaces, you would still end up with a 30 char move.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Nov 06, 2009 8:27 pm
Reply with quote

Dick: BTDTGTTS? icon_biggrin.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 06, 2009 9:13 pm
Reply with quote

took me a couple of times but finally learned how and when to use UNSTRING
Back to top
View user's profile Send private message
mf_karthik

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Sat Nov 07, 2009 3:23 pm
Reply with quote

robert,

i don't need the code,i asked for the explanation of reverse syntax..i know the basic commaon sense tht need to search the forum before posting the question..i searched but did'nt get the answer...

thanks for all the replies
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Sat Nov 07, 2009 6:21 pm
Reply with quote

Method 1:
FUNCTION REVERSE is documented in the COBOL Language Reference manual (link at the top of the page), coupled with INSPECT and moves using reference modification.

Method 2:
Run a loop from 30 to 1 checking each character (using reference modification) of HS to be spaces. Exit the loop when you find one that isn't. Add 1 to the position and that tells you where to move the comma (and the other data field).
Back to top
View user's profile Send private message
dchristensen

New User


Joined: 26 Jul 2006
Posts: 30
Location: Des Moines, Iowa

PostPosted: Mon Nov 09, 2009 9:54 pm
Reply with quote

If you would also include a WITH POINTER in the string statement, you would have a length you could use for a move that would strip off the trailing spaces.
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 Get RECORD LENGTH, allocated space of... CLIST & REXX 7
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
No new posts Allocated space calculation from DCOL... PL/I & Assembler 3
No new posts split a name based on space in ASM PL/I & Assembler 9
Search our Forums:

Back to Top