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

Read UTF-8 file in Cobol


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

New User


Joined: 02 Mar 2006
Posts: 35
Location: Chennai

PostPosted: Wed May 12, 2021 5:12 pm
Reply with quote

I have input file which transferred to Mainframe using FTP from Windows. this is comma separated text file. while transferring, i have used FTP commands as (QUOTE SITE ENCODING=MBCS QUOTE SITE MBDATACONN=(UTF-8,UTF-8). in mainframe i have stored as variable block file

Input file from Windows
9992,王清, ID card,1123233

in mainframe, it showed input as below
Õ]×......Xþ»W½eVýþ.+/ÈÑ?>/%.ñà.Ä/ÊÀ...................

in hex format
FIN-OWNER-RECORD =Õ]×......Xþ»W½eVýþ.+/ÈÑ?>/%.ñà.Ä/ÊÀ...................
4CCD6DEDCD6DCCDDC47EBB333332E88EB8E88246766666244266762333333333333333333
069506655909536940EFBF80012C7EB6855DECE149FE1C09403124C220102196301073331

Could you please help me how to locate comma delimiter(,) in cobol, i was trying as below codes, none of them worked.
IF FIN-OWNER-RECORD(1:INDEX-VAL) = N","
IF FIN-OWNER-RECORD(3:INDEX-VAL) = X'2C'
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1201

PostPosted: Wed May 12, 2021 5:51 pm
Reply with quote

To avoid a lot of headaches in the future, any (text) file transmitted from Windows environment to mainframe needs to be translated from ASCII to EBCDIC.
Otherwise endless series of tricks and gimmicks shall be required at each step while working with this dataset in mainframe environment. Your example is only the first problem in this way out of hundreds or thousands of further problems with this approach.

P.S.
First of all, learn how to use code tags when posting your code
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 12, 2021 7:43 pm
Reply with quote

Quote:
IF FIN-OWNER-RECORD(1:INDEX-VAL) = N","
IF FIN-OWNER-RECORD(3:INDEX-VAL) = X'2C'
You did not bother to tell us the value of INDEX-VAL so to some degree we can only guess what you're doing here. However, I don't think either of these statements is doing what you think it is. The first one looks at FIN-OWNER-RECORD starting at position 1 for a length of INDEX-VAL and attempts to match a single National comma to that string. If INDEX-VAL is not 1, then the comparison fails because you're comparing multiple bytes of FIN-OWNER-RECORD to a single byte. And if INDEX-VAL is one, the only time the comparison works is when there is a comma in the first position of FIN-OWNER-RECORD. The second statement does exactly the same thing, but looking at FIN-OWNER-RECORD starting in position 3 instead of 1, and using hex '2C' instead of a National comma. Since the record you posted doesn't have a comma (X'2C') until position 10, neither of your IF statements will be true for that record.

And I have to agree -- unless you have specific reasons (such as binary or packed decimal data), you should ALWAYS translate to EBCDIC on the mainframe. This makes everything much easier for you.
Back to top
View user's profile Send private message
sathyajes

New User


Joined: 02 Mar 2006
Posts: 35
Location: Chennai

PostPosted: Thu May 13, 2021 2:16 pm
Reply with quote

Thanks for your reply

As suggested, i have moved file to mainframe as EBCDIC file

during FTP, i have used as below
QUOTE SITE MBDATACONN=(UTF-8,IBM-937)

now in mainframe, the file looks as below
80012,g..f8.e..,National ID card,220102196301073331

Actual file as below from windows
80012,王清华,National ID card,220102196301073331

In cobol program, i have used the below code to convert
MOVE FUNCTION NATIONAL-OF(WS-CONTACT-NM,937) TO
WS-CONTACT-NM-NA --> national type variable
MOVE FUNCTION DISPLAY-OF(WS-CONTACT-NM-NA,937) TO
WS-CONTACT-NM-UTF8

Still chinse characters are not inserted in table correctly, it is showing as below
gÚÚÚÚÚÚÚÚ

Please help on this
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1201

PostPosted: Thu May 13, 2021 8:48 pm
Reply with quote

sathyajes wrote:
Thanks for your reply

As suggested, i have moved file to mainframe as EBCDIC file

during FTP, i have used as below
QUOTE SITE MBDATACONN=(UTF-8,IBM-937)

now in mainframe, the file looks as below
80012,g..f8.e..,National ID card,220102196301073331

Actual file as below from windows
80012,王清华,National ID card,220102196301073331

In cobol program, i have used the below code to convert
MOVE FUNCTION NATIONAL-OF(WS-CONTACT-NM,937) TO
WS-CONTACT-NM-NA --> national type variable
MOVE FUNCTION DISPLAY-OF(WS-CONTACT-NM-NA,937) TO
WS-CONTACT-NM-UTF8

Still chinse characters are not inserted in table correctly, it is showing as below
gÚÚÚÚÚÚÚÚ

Please help on this

Your Windows file is a mixture of text, and binary data. It cannot be transmitted in a simple manner - neither as translated text file, nor as non-translated binary file.
Transmittal of binary fields from Windows file to mainframe dataset doesn’t make sense at all in 99.99% of cases, because binary data representation is completely different on different hardware platforms.
Typical method of data transfer in ETL tasks:
1) unpack all non-text fields of Windows file to their character presentation
2) transfer Windows full-text file to mainframe dataset, with conversion ASCII->EBCDIC
3) handle mainframe text-only dataset in normal manner...

These are the basics of any typical and standard IT job.
Unless you started to learn the major methods used in IT, it doesn’t make sense to start working on any real task, besides of some training, or playing computer games.

P.S.
It’s a pity you cannot learn even: how to use the code tags in your posts.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10801
Location: italy

PostPosted: Thu May 13, 2021 9:50 pm
Reply with quote

when people ask these question

I wonder how the application design was done
requirements VS architecture VS implementation
with a bit of prototyping to confirm the approach for critical items

or not done as in this case

since we know nothing about the application requirements and architecture
the proper answer IMO should be ...
talk to the application analysts to find out
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 IDCAMS listcat service using cobol JCL & VSAM 1
No new posts Convert PS to TXT file using jcl JCL & VSAM 7
No new posts Make cobol variable value a variable COBOL Programming 3
No new posts how to convert and use 1 bit hex-numb... COBOL Programming 10
This topic is locked: you cannot edit posts or make replies. Sort to include records of file 2 int... Java & MQSeries 1
Search our Forums:

Back to Top