View previous topic :: View next topic
|
Author |
Message |
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
thnks for your reply..can u explain it little more..
any suggestions. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
k.junaid83
New User
Joined: 19 Apr 2006 Posts: 22 Location: bangalore
|
|
|
|
Another option is
STRING a-3 DELIMITED BY SPACES,
a-4 DELIMITED BY SPACES,
INTO HS
END-STRING. |
|
Back to top |
|
|
k.junaid83
New User
Joined: 19 Apr 2006 Posts: 22 Location: bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Dick: BTDTGTTS? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
took me a couple of times but finally learned how and when to use UNSTRING |
|
Back to top |
|
|
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dchristensen
New User
Joined: 26 Jul 2006 Posts: 30 Location: Des Moines, Iowa
|
|
|
|
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 |
|
|
|