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

Problem with UNSTRING of CSV data


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

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 5:17 pm
Reply with quote

Hi All,

I have input file with Header,Detail and Trailer as below:
H,20151208,4400,61581,12400,00000820,
D,8201,DELI/Total purchased,038201,233.52,
D,13920,Charge to account,13920,,233.52

If we observe the data in 3rd line vendor is not sending "," because record ends here. When i do UNSTRING WS-RECORD DELIMITED BY ','
first and second records which are having "," at end is coming properly but the 3rd record is not getting correctly.

I searched in google and this site as well but did not get the exact answer so posting again. Please some one help me on this.
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: Tue Dec 15, 2015 5:32 pm
Reply with quote

Each of your D records has five commas. What, more exactly, is your problem?

Can you show the code?
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 5:48 pm
Reply with quote

Hi Bill,

Thanks for you quick reply. Actually I should 6 fields

Record # 1:
A --> D,
B --> 8201,
C --> DELI/Total purchased,
D --> 038201,
E --> 233.52,
F --> After comma no data will take it as spaces

Record # 2:
A --> D,
B --> 13920,
C --> Charge to account,
D --> 13920,
E -->
F -->

In record 2 E and F are getting spaces when i use UNSTRING WS-RECORD DELIMITED BY ','
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: Tue Dec 15, 2015 6:01 pm
Reply with quote

You haven't shown your code, so we can't tell what the problem is.
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 6:02 pm
Reply with quote

Hi Bill,

SYSOUT of my Job is as below:
Code:
*************** BEGINNING D E T A I L # 1 *********************
WS-DTL-REC-TYPE  : D                             
WS-DTL-TLZR-CODE : 8201                         
WS-DTL-TLZR-DESC : DELI/Total purchased         
WS-DTL-ACCT-NUM  : 038201                       
WS-DTL-DEBIT-NUM :   233.52                     
WS-DTL-CREDIT-NUM:                               
*************** END OF D E T A I L # 1*********************
*************** BEGINNING D E T A I L # 2*********************
WS-DTL-REC-TYPE  : D                             
WS-DTL-TLZR-CODE : 13920                         
WS-DTL-TLZR-DESC : Charge to account             
WS-DTL-ACCT-NUM  : 13920                         
WS-DTL-DEBIT-NUM :                               
WS-DTL-CREDIT-NUM:                               
*************** END OF D E T A I L # 2*********************

As per the record # 2 D,13920,Charge to account,13920,,233.52
This WS-DTL-DEBIT-NUM should be spaces and WS-DTL-CREDIT-NUM should have data as "233.52" but it is getting spaces in both the fileds.
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 6:04 pm
Reply with quote

Hi Bill,

Sorry for multiple posts:
Cobol code as below:

Code:
UNSTRING WS-DTL-RECORD DELIMITED BY ','       
    INTO WS-DTL-UNSTRG-TYPE                   
         WS-DTL-UNSTRG-TLZR-CODE               
         WS-DTL-UNSTRG-TLZR-DESC               
         WS-DTL-UNSTRG-ACCT-NUM               
         WS-DTL-UNSTRG-DEBIT-AMT               
         WS-DTL-UNSTRG-CREDIT-AMT.             


SYSOUT of my Job is as below:
*************** BEGINNING D E T A I L # 1 *********************
WS-DTL-REC-TYPE : D
WS-DTL-TLZR-CODE : 8201
WS-DTL-TLZR-DESC : DELI/Total purchased
WS-DTL-ACCT-NUM : 038201
WS-DTL-DEBIT-NUM : 233.52
WS-DTL-CREDIT-NUM:
*************** END OF D E T A I L # 1*********************
*************** BEGINNING D E T A I L # 2*********************
WS-DTL-REC-TYPE : D
WS-DTL-TLZR-CODE : 13920
WS-DTL-TLZR-DESC : Charge to account
WS-DTL-ACCT-NUM : 13920
WS-DTL-DEBIT-NUM :
WS-DTL-CREDIT-NUM:
*************** END OF D E T A I L # 2*********************


As per the record # 2 D,13920,Charge to account,13920,,233.52
This WS-DTL-DEBIT-NUM should be spaces and WS-DTL-CREDIT-NUM should have data as "233.52" but it is getting spaces in both the fileds.
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: Tue Dec 15, 2015 6:37 pm
Reply with quote

Well, your UNSTRING looks fine.

The names you later give are not those used in the UNSTRING. Is that your problem? Do the -NUM fields get anyting MOVEd to them?
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 7:27 pm
Reply with quote

Hi Bill,

These fileds i used just for Display.

Code:
WS-DTL-REC-TYPE :
WS-DTL-TLZR-CODE :
WS-DTL-TLZR-DESC :
WS-DTL-ACCT-NUM :
WS-DTL-DEBIT-NUM :
WS-DTL-CREDIT-NUM:

If i put "," at end of the record record then i'm getting the data properly.

For Example:
As per the record # 2 D,13920,Charge to account,13920,,233.52,

SYSOUT of my Job is as below:
Code:
*************** BEGINNING D E T A I L # 1 *********************
WS-DTL-REC-TYPE : D
WS-DTL-TLZR-CODE : 8201
WS-DTL-TLZR-DESC : DELI/Total purchased
WS-DTL-ACCT-NUM : 038201
WS-DTL-DEBIT-NUM : 233.52
WS-DTL-CREDIT-NUM:
*************** END OF D E T A I L # 1*********************
*************** BEGINNING D E T A I L # 2*********************
WS-DTL-REC-TYPE : D
WS-DTL-TLZR-CODE : 13920
WS-DTL-TLZR-DESC : Charge to account
WS-DTL-ACCT-NUM : 13920
WS-DTL-DEBIT-NUM :
WS-DTL-CREDIT-NUM:   [color=yellow]233.52[/color]
*************** END OF D E T A I L # 2*********************

Please suggest something how i can get the data in proper way.
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: Tue Dec 15, 2015 7:40 pm
Reply with quote

OK, show your field definitions please. In the mean time, change them to PIC X fields of the same size and re-run your code.

Also in your DiSPLAY put delmiters around each field (like > and <) so you can see for sure what is happening.

Look up the rules in the Language Reference for a MOVE from Alpha-numeric to Numeric.
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Tue Dec 15, 2015 7:56 pm
Reply with quote

Hi Bill,

Thanks a lot for looking into it.

All the fields are PIC X fields.

Code:
01 WS-DTL-UNSTRG-FIELDS.                                 
   03 WS-DTL-UNSTRG-TYPE             PIC X(01).           
   03 WS-DTL-UNSTRG-TLZR-CODE        PIC X(08).           
   03 WS-DTL-UNSTRG-TLZR-DESC        PIC X(40).           
   03 WS-DTL-UNSTRG-ACCT-NUM         PIC X(20).           
   03 WS-DTL-UNSTRG-DEBIT-AMT        PIC X(08) JUST RIGHT.
   03 WS-DTL-UNSTRG-CREDIT-AMT       PIC X(08) JUST RIGHT.


2200-UNSTRG-DETAIL-RECORD.                                     
                                                               
    INITIALIZE  WS-DTL-UNSTRG-FIELDS.                           
                                                               
    UNSTRING FRSHINP-RECORD DELIMITED BY ','                   
        INTO WS-DTL-UNSTRG-TYPE                                 
             WS-DTL-UNSTRG-TLZR-CODE                           
             WS-DTL-UNSTRG-TLZR-DESC                           
             WS-DTL-UNSTRG-ACCT-NUM                             
             WS-DTL-UNSTRG-DEBIT-AMT                           
             WS-DTL-UNSTRG-CREDIT-AMT.                         
                                                               
    DISPLAY '*************** D E T A I L *********************'.
    DISPLAY 'WS-DTL-REC-TYPE  : ' WS-DTL-UNSTRG-TYPE.           
    DISPLAY 'WS-DTL-TLZR-CODE : ' WS-DTL-UNSTRG-TLZR-CODE.     
    DISPLAY 'WS-DTL-TLZR-DESC : ' WS-DTL-UNSTRG-TLZR-DESC.     
    DISPLAY 'WS-DTL-ACCT-NUM  : ' WS-DTL-UNSTRG-ACCT-NUM.       
    DISPLAY 'WS-DTL-DEBIT-NUM : ' WS-DTL-UNSTRG-DEBIT-AMT.     
    DISPLAY 'WS-DTL-CREDIT-NUM: ' WS-DTL-UNSTRG-CREDIT-AMT.     
    DISPLAY '*************** D E T A I L *********************'.

I'm not doing any move statements before display.
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: Tue Dec 15, 2015 8:35 pm
Reply with quote

Well the same thing is happening. A numeric is right-justified.

That final field is, say 40 bytes long (from the start of that final piece of data to the end of the source field.

So, it is the eight right-most of those 40 bytes which will be processed by the UNSTRING. If you take off the JUST RIGHT (a Goldilocks Field) you'll see your data. In the wrong place.

Then with your new PIC X(8), UNSTRING delimited by SPACE INTO your-just-right-field.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue Dec 15, 2015 8:40 pm
Reply with quote

This must be happening because the length of WS-DTL-RECORD is greater than the length of the Value in that field.

So, If your input value is 39 bytes and the length of variable WS-DTL-RECORD is 60 bytes AND you haven't mentioned a delimiter for the last record; Then your last record will be counted till 60th byte.
Quote:
D,13920,Charge to account,13920,,233.52
And since you are using a 'JUST RIGHT' clause then you only get spaces.

You can see the value in this field if you use more bytes for the last field, say X(40) instead of X(8). Display and see.

.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 15, 2015 8:59 pm
Reply with quote

The issue isn't with the length but actually appears to be with the JUST RIGHT. I ran a test job with your data, with UNSTRING into the same fields you have and then the same fields WITHOUT the JUST RIGHT clause. With the JUST RIGHT clause, neither of the last two fields has any data for the second D record. Without the JUST RIGHT clause, the fifth variable for the second D record has spaces and the last variable has the 233.52 value.

Get rid of the JUST RIGHT on your UNSTRING variables. You can always use a MOVE to a JUST RIGHT variable (or at worst use reference modification to find the last byte of data and move the value to the rightmost positions of your end variable).
Back to top
View user's profile Send private message
chavinash2004

New User


Joined: 30 Jun 2010
Posts: 37
Location: hyderabad

PostPosted: Wed Dec 16, 2015 12:32 am
Reply with quote

Hi Bill and Robert,
If i remove the JUST RIGHT it is working fine.

Thanks a lot for your help and valuable time.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 16, 2015 2:26 am
Reply with quote

Glad to hear you got it working!
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 How to save SYSLOG as text data via P... All Other Mainframe Topics 4
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts SCOPE PENDING option -check data DB2 2
Search our Forums:

Back to Top