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

UNSTRING monthyear into month and year


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

New User


Joined: 04 Oct 2007
Posts: 10
Location: chennai

PostPosted: Thu Oct 11, 2007 10:13 am
Reply with quote

i am have monthyear x(6) as a variable. how can i unstring this into month x(2) and year x(4). what delimited phrase sould i use ?
help needed !
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Thu Oct 11, 2007 10:35 am
Reply with quote

Hi Ravi,

Instead of unstring, Just move monthyear x(6) to other variable like this.


Code:
01 WS-MONTHYEAR.
    05 WS-MONTH  PIC X(2) VALUES SPACES.
    05 WS-YEAR     PIC X(4) VALUES SPACES.


In working storage Move month year to working storage variable.

Code:
MOVE MONTHYEAR TO WS-MONTHYEAR.


If you need to do it in Unstring only let us know..

Thanks & Regards
Back to top
View user's profile Send private message
ravi30
Currently Banned

New User


Joined: 04 Oct 2007
Posts: 10
Location: chennai

PostPosted: Thu Oct 11, 2007 10:38 am
Reply with quote

thanks a lot but cant we do this with unstring just delimiting it by the first 2 pic as date and the next 4 as year! i just wanna know if it is possible or not? as im a newbie pl advice.
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Thu Oct 11, 2007 10:49 am
Reply with quote

Hi Ravi,

Yep ,You can do it in many ways, I mean By reference modification, Unstring, Move command.

As you are new to mainframe, I advice to read COBOL book By ROY & DASTIDHAR.


Thanks & Regards
Back to top
View user's profile Send private message
hemanth.nandas

Active User


Joined: 18 Aug 2007
Posts: 120
Location: India

PostPosted: Thu Oct 11, 2007 10:55 am
Reply with quote

Hi Ravi,

Quote:
In working storage Move month year to working storage variable



Sorry, Plse correct it as In procedure Division Move monthyear to other WS-variable.

Thanks & Regards
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: Thu Oct 11, 2007 11:21 am
Reply with quote

Hello,

Quote:
thanks a lot but cant we do this with unstring just delimiting it by the first 2 pic as date and the next 4 as year! i just wanna know if it is possible or not? as im a newbie pl advice.
UNSTRING is probably not what you want to use. If you use the first 2 bytes as a delimiter, this could cause problems because all valid "month" values could be valid values of the 2 low-order positions of "year".

I believe the suggestions above (multi-field ws-monthyear or reference modification) would be better choices.
Back to top
View user's profile Send private message
rajaherein

New User


Joined: 11 Jan 2007
Posts: 23
Location: chennai

PostPosted: Wed Oct 24, 2007 11:46 am
Reply with quote

Use Redefines like below,

01 MonthYear Pic X(06).

01 Month-Year Redefines MonthYear.
05 Month Pic X(02).
05 Year Pic X(04).

Hope this Helps.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Oct 24, 2007 3:27 pm
Reply with quote

I don't think UNSTRING can be used, because you would need to have a constant value as delimiter between the 2 values
For example, if you had "mm-yyyy" then you could use:
Code:
UNSTRING monthyear DELIMITED BY '-' INTO month year

without that '-' constant, what would you use ?

The best option is to use reference modification:
Code:
MOVE monthyear (1:2) TO month
MOVE monthyear (3:4) TO year
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: Wed Oct 24, 2007 7:36 pm
Reply with quote

Hello,

One might use "delimited by size". . . if one was totally detemiined to use UNSTRING.

As mentioned previously, unstring is not a good choice for this particular situation.

If is almost always a good idea to do a "thing" the simplest way. . .
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Oct 24, 2007 9:04 pm
Reply with quote

Quote:
One might use "delimited by size". . . if one was totally detemined to use UNSTRING

Dick, I was about to write this too, but it didn't sound right so I checked in the manual:
no "delimited by size" with UNSTRING.
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: Wed Oct 24, 2007 9:18 pm
Reply with quote

Hi Marso,

Must only be for STRING - that'll teach me once again to post without first testing icon_smile.gif

I do hate when that happens icon_redface.gif
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 Populate last day of the Month in MMD... SYNCSORT 2
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts replace word 'MONTH' with current mon... SYNCSORT 11
No new posts How to extract the data for current y... DFSORT/ICETOOL 8
No new posts Help, trying to use OVERLAY to get a ... DFSORT/ICETOOL 3
Search our Forums:

Back to Top