Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Reading the CSV data in COBOL and move it to PACKED-DECIMAL

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

New User


Joined: 13 Jul 2018
Posts: 8
Location: Nederlands

PostPosted: Tue Dec 03, 2019 5:13 pm    Post subject: Reading the CSV data in COBOL and move it to PACKED-DECIMAL
Reply with quote

Hi Team,

In my one of the code, I am reading the data from CSV file and assigning to working fields by Unstrung function delimited by ';'.

Issue:
When I am reading the file for the decimal values (like 2.33 / 11.03 .. etc) data is not populating properly if i define working field as 9(2)V9(2)
So i had define as X(5) and doing the data population.
Code:

01-Working.
03 CSV-EE-WRDE1                 PIC 9(02)V9(2).
03 CSV-EE-WRDE2                 PIC S9(02)V9(2)

01 CSV-FILE
03 CSV-EE-ST-DATUM           PIC X(10).  
03 CSV-EE-WRDE                 PIC X(05).       <--- which is decimal like 2.33  
03 CSV-KOOPSOM                PIC X(13).

Procedure:
UNSTRING CSV-RECORD            
    DELIMITED BY C-DELIMITER    
              OR  ALL LOW-VALUES
    INTO CSV-EE-ST-DATUM,      
            CSV-EE-WRDE
            CSV-KOOPSOM
    TALLYING IN H-NO-OF-FIELDS
END-UNSTRING.                




But later below steps, i need to insert the data to table field
Code:


Move  CSV-EE-WRDE  to CSV-EE-WRDE1      <---- move is not populating as expected
Move  CSV-EE-WRDE1  to CSV-EE-WRDE2    <---- move is not populating as expected

Table Move

Move  SV-EE-ST-DATUM   TO   EINDLABEL-LABEL
Move   CSV-EE-WRDE2      TO  CONTRACTValue
Move CSV-KOOPSOM       TO   RUBRIEK              

INSERT INTO Table-Name (field1, field2, field3) from (EINDLABEL-LABEL,CONTRACTValue ,RUBRIEK      )

 




Code:

Table field declaration ( which is already existed, alter not possible ) 
10 EINDLABEL-LABEL      PIC X(10).                        
10 CONTRACTValue        PIC 9(02)V9(02) USAGE PACKED-DECIMAL.
10 RUBRIEK                    PIC X(13).

 


Could any one help me getting proper values for the decimal part.


Thanks in advance.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


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

PostPosted: Tue Dec 03, 2019 7:27 pm    Post subject: Reply to: Reading the CSV data in COBOL and move it to PACKED-DECIMAL
Reply with quote

You apparently do not understand that a V in a PICTURE clause (like 9(2)V9(2) for example) means that the decimal point does NOT appear -- it is implied. And an actual decimal point in the data will cause problems since it is NOT implied.

If you are sure that your data will ALWAYS be 2 digits followed by a decimal point followed by 2 digits, use PIC 9(2).9(2) so the decimal point is explicit. If there is a chance of the data not being 2 digits followed by a decimal point followed by 2 digits, use the FUNCTION NUMVAL to convert an X(5) into numeric data.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 630
Location: Maryland

PostPosted: Wed Dec 04, 2019 5:58 pm    Post subject:
Reply with quote

Besides of already mentioned problem with COBOL format including 'V' marker, there is another, more serious problem, particularly with CSV data: the length, and position of each field are not fixed (otherwise it wouldn't be a CSV, but fixed format records).

The TS did not give any example of his input data. For CSV we might assume
Code:
 1234 , 56 , 789 , 10 , 5 , .....

or
Code:
 1234 ; 56 ; 789 ; 10 ; 5 ; .....

or
Code:
 1234 | 56 | 789 | 10 | 5 | .....

or
Code:
"1234";"56";"789";"10";"5"; .....

or
Code:
"1.34";"-5.6";"+78.9";"-1.0";"+.5"; .....

etc, etc, etc.

In general case it might be a sophisticated task, especially in COBOL, to parse free text of any possible CSV version.
If input data was better formalyzed, it would be much easier to process it.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


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

PostPosted: Wed Dec 04, 2019 8:45 pm    Post subject:
Reply with quote

Quote:
But later below steps, i need to insert the data to table field


Easiest way is to use DB2 DEC (Decimal) function during the INSERT or prior and move the value to corresponding field in DCLGEN. This is code is clean and no convoluted COBOL logic for such numeric conversions.

Code:
03 CSV-EE-WRDE                 PIC X(05).

changes to
Code:
DEC(:CSV-EE-WRDE,4,2)


If you don't have DB2 then use DFSORT to achieve this.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 630
Location: Maryland

PostPosted: Wed Dec 04, 2019 9:05 pm    Post subject:
Reply with quote

Rohit Umarjikar wrote:
If you don't have DB2 then use DFSORT to achieve this.

I agree. If the author is not afraid of SORT tools, the easiest way would be: first to convert CSV data to flat file with fixed fields of desired format, and then to read this normalized file without problems straightforward into COBOL variables with matching definition.
It might be much more simple rather than parsing free-text CSV data in COBOL code, unless some ready-to-use service procedure is available for this conversion.
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 Identifying Packed Decimal data in a ... sojivarkey TSO/ISPF 4 Sat Dec 07, 2019 5:36 am
No new posts Extract data from n DB2 Views automat... esmeraldo All Other Mainframe Topics 5 Wed Nov 13, 2019 12:32 am
No new posts adrdssu for copy all data robyjhl JCL & VSAM 5 Tue Nov 12, 2019 11:17 pm
No new posts Convert mainframe data to .csv format... karan_reddy DFSORT/ICETOOL 10 Sat Nov 02, 2019 2:09 am
No new posts COBOL -DB2 SQL code to have GROUP BY ... vinu78 DB2 21 Wed Oct 23, 2019 7:00 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us