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

Cobol code Firstnm*MI*Lastname to Lastname Firstname Middle


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

Global Moderator


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

PostPosted: Fri Mar 09, 2007 4:28 am
Reply with quote

The FM states: "One UNSTRING statement can take the place of a series of MOVE statements"
The rules for moving an alphanumeric elementary item are the same as those for the MOVE statement"
You might find this works better.
Code:

01  NAME.                       
05  L            PIC X(30).
05  F            PIC X(30).
05  M            PIC X(30).
* YOUR FORMAT IS L F M 
01  FINAL-NAME PIC X(30). 
PROCEDURE DIVISION.

MAIN-PARA.                                       
    MOVE SPACES TO NAME.     
    MOVE 'JOHN*ED*CAUSEY SATTELBERG*' TO WS-NAME.
    UNSTRING WS-NAME DELIMITED BY '*' INTO       
          F,M,L.                                 
                                                 
    DISPLAY 'F:' F.                             
    DISPLAY 'M:' M.                             
    DISPLAY 'L:' L.                             
                                                 
    STRING                                       
        L      DELIMITED BY X'4040'
        ', '   DELIMITED BY SIZE 
        F      DELIMITED BY X'4040'
        SPACE  DELIMITED BY SIZE     
        M      DELIMITED BY X'4040'             
        INTO FINAL-NAME.                         
    DISPLAY FINAL-NAME. 

O/p:

F:JOHN                       
M:ED                         
L:CAUSEY SATTELBERG         
CAUSEY SATTELBERG, JOHN ED
So much for
cobolunni wrote:
good thus we got a practical model icon_wink.gif
icon_rolleyes.gif
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 Mar 09, 2007 8:06 am
Reply with quote

By jove, i think he's got it!icon_wink.gif
Back to top
View user's profile Send private message
vishwaroopa

New User


Joined: 08 Mar 2007
Posts: 8
Location: US

PostPosted: Fri Mar 09, 2007 9:18 am
Reply with quote

Thanks to Every body for your valuable inputs, this works.
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 Mar 09, 2007 10:30 am
Reply with quote

Cool icon_cool.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Mar 09, 2007 12:27 pm
Reply with quote

cobolunni wrote:
for your second problem from the code given by agkshirsagar the last string statement uses spaces to delimit the data in identifiers F M and L to avoid that you need to put some data for example VALUE ALL '#' to all your F M and L and replace the line in STRING statement as DELIMITED BY '#' hope that will solve your problem


This wont work.
Because after unstring you will get trailing spaces in the F,M,L.
I would suggest one change..
Code:

 ACCEPT WS-NAME.                                   
 INSPECT WS-NAME REPLACING ALL SPACES BY '@'   
 UNSTRING WS-NAME DELIMITED BY '*' INTO           
       F,M,L.                                     

i.e. Replacing spaces by @ immediately after you get the value in your variable. ( I am sure you are not using ACCEPT )

Optimize the code after you get exactly what you wanted icon_biggrin.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Mar 09, 2007 12:39 pm
Reply with quote

People, I did not see all the replies, Juse saw the page 1 discussion and posted. icon_neutral.gif
It seems you already got the solution. icon_cool.gif
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Sat Mar 10, 2007 4:20 pm
Reply with quote

agkshirsagar wrote:

Because after unstring you will get trailing spaces in the F,M,L.


i dont think so , any way we got the solution
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Mar 12, 2007 11:16 am
Reply with quote

Quote:

The UNSTRING copies characters from the source string, to the destination string, until a condition is encountered that terminates data movement.

When data movement ends for a particular destination string, the next destination string becomes the receiving area and characters are copied into it until once again a terminating condition is encountered.

Characters are copied from the source string to the destination strings according to the rules for alphanumeric moves.
There is space filling.
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compile rexx code with jcl CLIST & REXX 6
Search our Forums:

Back to Top