Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query on Splitting up a file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Wed Apr 20, 2016 3:26 pm    Post subject: Query on Splitting up a file
Reply with quote

Hi,

I do have a CSV file as shown below.

I have to import it to mainframe and place every value in its respective fields.

For eg: Here I do have "AL,AR,...,TX". You could see 10 occurences inside the quotes. Even after the quotes you can see another set too like "ED,EE". At times I can receive even 5, but the maximum occurences can be 16. If I get only 5 occurences, its difficult for me to figure out if the next comma belongs to the same variable or to a different variable. I used delimited by comma but the values went to different fields.

Could you please help me with a logic on how I can get the values exactly populated to respective fields. If there are 5 occurences, rest of 11 occurences should be spaces considering the max is 16.

the attachments were deleted,
repost the data using the code tags
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Apr 20, 2016 3:35 pm    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Post the code you are using, including the definitions of all relevant fields.

Post sample data and expected output and the output you get.

All of these inside the Code tags.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Apr 20, 2016 5:34 pm    Post subject:
Reply with quote

please follow Bill's advise to get more options.
my understanding says: i try to avoid reference modifications so see if this is what you want.
step1: use inspect and replace ',"' by '|'
step2 : use another inspect and replace '"' by ''
step3: unstrung delimited by '|' into your 10 fields and use a pointer adnavced by 1 to get data into next occurance .
step4: move each occurance into seaparate variable as you want
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Wed Apr 20, 2016 6:06 pm    Post subject:
Reply with quote

As its a image given in a requirement document, I am unable to post it using code tag. I have just started to code and hence I was checking with delimited by or inspect verb to segregate the values.

Please help. [/code]
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Apr 20, 2016 6:11 pm    Post subject:
Reply with quote

My internet got off for some time so could not edit the earlier post.
Step3 : you get the values in 1 variable instead of 10.
Step5:After that you still want to have AL OR AR and so on then perform another unstrung delimited by , into 10 different variable.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Apr 20, 2016 6:22 pm    Post subject:
Reply with quote

What more Help you need, Did you try what I have suggested?
You can show us the sample input and what output you want and use a code tags. You don't have to post the original requirement to us or tell us what do you mean by split the files in above context as you may get dfsort solution as well.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Wed Apr 20, 2016 6:43 pm    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Quote:
As its a image given in a requirement document, I am unable to post it using code tag. I have just started to code and hence I was checking with delimited by or inspect verb to segregate the values.



help people who spend their time helping You...
not everybody can download see attachments
post info in system independent formats ==> TEXT

You posted TWO attachments with unreadable info
for around 800K bytes, thats an unacceptable waste of resources

posting the same info in text format would have taken no more than 4K bytes

posting info in proprietary format will also reduce the number of people willing to help

many of us use Linux or OSX
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Thu Apr 21, 2016 11:10 am    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Thanks Rohit. I shall try it and see.

Sorry Enrico if I had wasted much of time.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 11:35 am    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Code:

       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.     TESTPROG.                                       
       ENVIRONMENT DIVISION.                                           
       CONFIGURATION SECTION.                                           
       SOURCE-COMPUTER. IBM-370.                                       
       OBJECT-COMPUTER. IBM-370.                                       
                                                                       
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
       01 WS-VALUE         PIC X(107)  VALUE                           
                'N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CH
      -        'ANNEL GUIDE,2016,1,N,"AL, AR, FL, GA, LA",O,"ED, EE"'. 
                                                                       
       PROCEDURE DIVISION.                                             
                                                                       
             INSPECT WS-VALUE REPLACING ALL ',"' BY '|'.               
             DISPLAY 'WS-VALUE = ' WS-VALUE.                           
                                                                       
             STOP RUN.                                                 




This is my code. But it throws error when using REPLACING telling
Code:
16  IGYPA3098-S   "REPLACING" operand "',"'" was not the same length as the "BY" operand "'|'".


I read the INSPECT verb. It tells it can replace only one character with one character. So I gave replace '"' with '|' and it went fine.


Output I got:

Code:
 WS-VALUE = N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,26,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,2016,1,N |AL, AR, FL, GA, LA",O |ED, EE"


Is there a way to neglect the space between N and | (which is shown in the output above ?.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Apr 22, 2016 11:56 am    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Your output does not match what you say you have done. INSPECT ... REPLACING ... can change character-sequences (not just single bytes), they just have to be the same length. You have "lost" some commas, so it looks like you've discovered that already.
Back to top
View user's profile Send private message
Abid Hasan

New User


Joined: 25 Mar 2013
Posts: 65
Location: India

PostPosted: Fri Apr 22, 2016 12:01 pm    Post subject: Re: Reply to: Query on Splitting up a file
Reply with quote

Hello,

abdulrafi wrote:
I read the INSPECT verb. It tells it can replace only one character with one character. So I gave replace '"' with '|' and it went fine.

Output I got:

Code:
 WS-VALUE = N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,26,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,2016,1,N |AL, AR, FL, GA, LA",O |ED, EE"


Is there a way to neglect the space between N and | (which is shown in the output above ?.


Are you sure, the output you've shown is the output received after replacing only- '"' with '|' ?

Here is a quick test run result of this same code:

Code:

*                                                                 
 01 WS-VALUE         PIC X(107)  VALUE                           
          'N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CH
-        'ANNEL GUIDE,2016,1,N,"AL, AR, FL, GA, LA",O,"ED, EE"'. 
*                                                                 
----
----
*                                                       
             INSPECT WS-VALUE REPLACING ALL '"' BY '|'.
             DISPLAY 'WS-VALUE = ' WS-VALUE.           
*         
---
---                                             


Output:

Code:

 WS-VALUE = N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,26,1/1/2001,GLOVEBOX XM CHANNEL GUIDE,2016,1,N,|AL, AR, FL, GA, LA|,O,|ED, EE|


Can you please re-validate your code and the output you've shown.

Hth.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 12:13 pm    Post subject:
Reply with quote

I again changed it as below in the code and hence I got that output,

Code:
INSPECT WS-VALUE REPLACING ALL ',"' BY ' |'.


I am trying to see if I am getting the correct values in the correct fields without any truncation.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 2:19 pm    Post subject:
Reply with quote

Hi,

I need one another help. I have written the code and executed and I am getting the output as expected except for one field.

In my file I have values as "ED, EE". When I delimit and pass the variable to PIX X(02), one holds value as ED and other has E because of the space after comma.

Is there anyway I can remove the spaces and make it sit in PIC X(02) bytes. ?.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 2:35 pm    Post subject:
Reply with quote

Output :
ws-var =ED
ws-var1=E

Expected output:
ws-var=ED
ws-var1=EE
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Apr 22, 2016 3:02 pm    Post subject: Reply to: Query on Splitting up a file
Reply with quote

"ED, EE" is data, not two fields. It is data containing a comma, which is why whatever created the CSV in the first place put quotes around it.

You can treat it is two fields. However, you need to be very sure of the source of the data. If it is user-input, then it could just as easily come as "ED,EE", even if that is by typo.

If it is fixed-format and always will have a leading space you could define a three-byte field but only use the last two to pick up the data, or you could use a second delimiter of ", ". Which may be better depends on your code.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Apr 22, 2016 3:29 pm    Post subject:
Reply with quote

Yes Bill. I tried moving the 2 bytes field to a 3 byte field.
Then Check if the first byte is spaces and if its YES I do move the 2nd and 3rd byte only. If first byte is not spaces then move the 1st and 2nd byte only.

its sure that it will have only 2 bytes and not more than that.

Instead of going by my logic which I felt its quite ugly, thought if I could use INSPECT verb to strip the spaces and move only the bytes which have values.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Apr 22, 2016 3:51 pm    Post subject: Reply to: Query on Splitting up a file
Reply with quote

Because the original and new values for the INSPECT must be the same size, you can't make your data "shorter" or "longer" than it is with INSPECT.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Fri Apr 22, 2016 4:51 pm    Post subject:
Reply with quote

You can still do with inspect. try doing a reverse of a field and tally for leading spaces and the use that vaue +1 for your reference mod as a starting offset.
Do you have a DB2? if yes then instead of all this you can do everything in in one shot using REPLACE function.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Tue May 03, 2016 4:39 pm    Post subject:
Reply with quote

Need one more help. I have the input records as below.

Current input file,

Code:
 01 WS-VALUE2        PIC X(107)  VALUE                           
          'N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM C
-        'ANNEL GUIDE,2016,,,,O,"ED, EE"'.                       



Earlier input file,

Code:
 01 WS-VALUE         PIC X(107)  VALUE                           
          'N,88320,00254XMT03GUIDE,6U,6156,1/1/2001,GLOVEBOX XM CH
-        'ANNEL GUIDE,2016,1,N,"AL, AR, FL, GA, LA",O,"ED, EE"'. 


Instead of "AL,AR,FL....." I have one comma now. I need to identify this position now. I used UNSTRING variable but I could not get the correct values to the correct fields. It got jumbled.

Could you please help me if I could achieve it using reference modification or by any other means ?.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Tue May 03, 2016 10:02 pm    Post subject:
Reply with quote

1.scan the input field byte by byte and as soon as you hit the '"' then replace ',' by ';' till you hit ending '"' and continue this till the end of the string.
2.Do a inspect and replace ',' by '|'
N|88320|00254XMT03GUIDE|6U|6156|1/1/2001|GLOVEBOX XM C
ANNEL GUIDE|2016||||O|"ED; EE"'.
3. Unstring delimited by '|'
4. Now you will have "ED; EE"' value in one of the variable.
5. Work in this now , use unstring delimited by ';' into 10 variables.
6. You will get "ED in one of the variable from step5, now remove '"' by any method you want ( e.g. use byte by byte check and get rid of '"')
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us