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

Unstring to split COBOL fields


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

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Mar 28, 2012 8:33 pm
Reply with quote

Hi ALL

I have a record in my input file as :-

'VEH001|VEH2|PART1234|LASTPART..'

Last 2 dots (..) are X'02D5' i.e. for representing end of line.

Now I am using Unstring to split these 4 fields as :

UNSTRING INPUT-FILE-RECORD
DELIMITED BY '|'
INTO
LR-FIELD1
LR-FIELD2
LR-FIELD3
LR-FIELD4
END-UNSTRING.

Now LR-FIELD1,2 and 3 is containing proper values in it. But LR-FIELD4 is containing 'LASTPART..' i.e. X'02D5' value also.

I want to remove this. I tried giving DELIMITED BY '|' OR 'X02D5'
but again LR-FIELD is containing those 2 bytes of data.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Mar 28, 2012 8:39 pm
Reply with quote

try DELIMITED BY 'X02D5' OR '|'
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Mar 28, 2012 8:42 pm
Reply with quote

Forgot to mention the length of given variables:

LR-FIELD1 PIC X(10)
LR-FIELD2 PIC X(10)
LR-FIELD3 PIC X(10)
LR-FIELD4 PIC X(20).

So LR-FIELD4 may contain spaces as well which i need to remove tht too.
Like 'LASTPART.. '
So I want only value 'LASTPART' in LR-FIELD4 variable.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 28, 2012 8:46 pm
Reply with quote

You'll have to explain what you mean by "removing" spaces from LR4. You've been through that before. If the field is 20, it is going to hold 20 bytes of "whatever". If you "remove" space it will have to be something else.

So, describe more accurately what you want, please.
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Mar 28, 2012 8:47 pm
Reply with quote

Hi Dick

I tried that just now but again its coming in tht variable.
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Mar 28, 2012 8:56 pm
Reply with quote

Hi Bill

LR-FIELD4 is of 20 bytes. but it may contain actual data of 10 bytes and
remaining spaces.
Like above it contains actual data 'LASTPART' of 8 bytes + 2 bytes of 'X02D5' but what abt remaining 10 bytes.
I am not able to show spaces here.
So I want to truncate all values after 2 dots (..) X'02D5' including this too.
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: Wed Mar 28, 2012 9:08 pm
Reply with quote

Dick's code change works for me:
Code:
       77  INPUT-FILE-RECORD           PIC X(50) VALUE
           'VEH001|VEH2|PART1234|LASTPART N' .
       77  LR-FIELD1                   PIC X(10).
       77  LR-FIELD2                   PIC X(10).
       77  LR-FIELD3                   PIC X(10).
       77  LR-FIELD4                   PIC X(20).
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           UNSTRING INPUT-FILE-RECORD
               DELIMITED BY X'02D5' OR '|'
               INTO LR-FIELD1
                    LR-FIELD2
                    LR-FIELD3
                    LR-FIELD4
           END-UNSTRING.
           DISPLAY 'INPUT-FILE-RECORD <' INPUT-FILE-RECORD '>'.
           DISPLAY 'LR-FIELD1 <' LR-FIELD1 '>'.
           DISPLAY 'LR-FIELD2 <' LR-FIELD2 '>'.
           DISPLAY 'LR-FIELD3 <' LR-FIELD3 '>'.
           DISPLAY 'LR-FIELD4 <' LR-FIELD4 '>'.
produces expected output of
Code:
 INPUT-FILE-RECORD <VEH001|VEH2|PART1234|LASTPART.N                   >
 LR-FIELD1 <VEH001    >
 LR-FIELD2 <VEH2      >
 LR-FIELD3 <PART1234  >
 LR-FIELD4 <LASTPART            >
So what are you expecting to be different in this output?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 28, 2012 9:13 pm
Reply with quote

apandey wrote:
Hi Bill

LR-FIELD4 is of 20 bytes. but it may contain actual data of 10 bytes and
remaining spaces.
Like above it contains actual data 'LASTPART' of 8 bytes + 2 bytes of 'X02D5' but what abt remaining 10 bytes.
I am not able to show spaces here.
So I want to truncate all values after 2 dots (..) X'02D5' including this too.


OK, so make up your mind about how it is valid to define a hexadecimal literal. Try that as part of your solution.

If UNSTRING does not fill a field, the remaining bytes are the value which was in the field at the time the UNSTRING stared. So, it is always "excellent practice" to set your fields which are the target of your UNSTRING to some initial value. I like "MOVE SPACE TO ...." but I'm sure there are less rigorous ways to attempt it.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Wed Mar 28, 2012 9:17 pm
Reply with quote

seems that there is a consistent tpyogarphical error here
'x02D5' instead of x'02D5'
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Mar 29, 2012 11:56 am
Reply with quote

Hi Robert/Dick,
I tried same but its not working. Pls see actual code below.
Code:
2000-PROCESS-LR951.                                         
-------------------------------------------------------------
                                                             
    INITIALIZE               INCOMING-EMAIL                 
    MOVE WS-TIMESTAMP        TO  LR-KEY OF INCOMING-EMAIL   
                                                             
    UNSTRING WS-INPUT-RECORD                                 
             DELIMITED BY X'02D5' OR '|'                     
    INTO                                                     
           LR-TO-FIELD-TEXT                                 
           LR-CC-FIELD-TEXT                                 
           LR-SUB-FIELD                                     
           LR-SUB1-FIELD-TEXT                               
           LR-TEXT-FIELD-TEXT                               
           LR-USER-DATE-TEXT                                 
           LR-USRTXT1-FIELD-TEXT                             
           LR-USRTXT2-FIELD-TEXT                             
           LR-USRTXT3-FIELD-TEXT                             
           LR-USRTXT4-FIELD-TEXT                             
                                                             
    END-UNSTRING.                                           
    DISPLAY 'LR-USRTXT4-FIELD-TEXT: ' LR-USRTXT4-FIELD-TEXT 


Sysout is:
Code:
 -------------------------------------------------
LR-USRTXT4-FIELD-TEXT: HELLO BOSS THIS IS TEXT4::
DD6EEDEEEF6CCCDC6ECEE74CCDDD4CDEE4ECCE4CE4ECEEF020
390429373406953403573A0853360262203892092035734D50
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Mar 29, 2012 12:10 pm
Reply with quote

You are, finally, showing us X'02D5'. Now you show the data, and it is x'0D25'.
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Mar 29, 2012 12:25 pm
Reply with quote

Bill,
I didnt get you icon_sad.gif
You mean to say there is difference between X'02D5' and x'02D5'.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Mar 29, 2012 12:37 pm
Reply with quote

It looks like what I mean is that you are not reading the hex display properly.

Code:
 -------------------------------------------------
LR-USRTXT4-FIELD-TEXT: HELLO BOSS THIS IS TEXT4::
DD6EEDEEEF6CCCDC6ECEE74CCDDD4CDEE4ECCE4CE4ECEEF020
390429373406953403573A0853360262203892092035734D50


Have a look at the first letter of your display. L. Find the EBCDIC code for L. Look at the hex values in your example. Where does x'D3' occur? Vertically, underneath the L.

So, what value are the last three bytes X'0D2500'.

If you correct your delimeter to X'0D25' it should work, including not piicking up that X'00'.

I knew you'd use INITIALIZE, even with me steering you from it :-)

Did you ever go back and let us know about that SORT question you had the other day... after all that talk about feedback..
Back to top
View user's profile Send private message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Mar 29, 2012 2:07 pm
Reply with quote

Bill ..Extremely sorry abt this. Earlier I was using X'02D5' thats why it was not working. Very silly mistake icon_sad.gif

Now I tried with X'0D25', so now its working well ..!

Thanks everyone for all ur effort.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Mar 29, 2012 3:20 pm
Reply with quote

Usually when I see hex at the end of something, I check with yellow/green card. Because the X was first part of the literal itsef, I didn't :-)

X'0D25' is Carriage-Return, Line-Feed. A common combination for the "end" of a text line.

You might want to look at how to remove it from the transfer from the server. It can usually be done, then your Cobol program wouldn't even have to know about 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 COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Pull data using date difference betwe... DB2 6
No new posts Compile Sp Cobol base COBOL Programming 1
Search our Forums:

Back to Top