Need help in using HWTJPARS in COBOL for parsing JSON data



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Need help in using HWTJPARS in COBOL for parsing JSON data

Postby hariharan_bk » Fri Oct 14, 2016 1:19 pm

Hi All,
Based on my project requirements, I need to parse the JSON string into a COBOL copybook and do the functional processing on them.

For parsing this JSON data (which is in textpad now, and we can FTP to MF), we do have the required modules HWTJPARS/HWTJINIT in our library. But i have no clue how to use this in the cobol program.
Could you please advise with some program examples?
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby hariharan_bk » Fri Oct 14, 2016 1:31 pm

I have referred the following link and learnt some details, but not sure how to implement the same in a cobol program for parsing JSON. Hence please advise on the procedure with some examples.

http://www.ibm.com/support/knowledgecen ... e-json.htm
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby Robert Sample » Fri Oct 14, 2016 6:58 pm

In the link you posted, the HWTJPARS information in the manual tells you PRECISELY what you need to know. The syntax for COBOL is
SET WS-JSON-ADDRESS TO ADDRESS OF WS-JSON-TEXT
CALL 'HWTJPARS' USING WS-RETURN-CODE
                      WS-PARSER-HANDLE
                      WS-JSON-ADDRESS
                      WS-JSON-LENGTH
                      WS-DIAG-AREA
with these WORKING-STORAGE (or LINKAGE) SECTION variables:
05  WS-RETURN-CODE   PIC S9(09) COMP-5.
05  WS-PARSER-HANDLE PIC X(12).
05  WS-JSON-ADDRESS  POINTER.
05  WS-JSON-LENGTH   PIC S9(09) COMP-5.
05  WS-DIAG-AREA     PIC X(132).
although I would probably go ahead and define WS-DIAG-AREA as a group with the 4-byte reason code and 128-byte error text variables under it.

For that matter, I'd probably use the HWTJICOB copybook member in SYS1.MACLIB, rather than coding up my own variables. That gives you more diagnostic information in your code.

These users thanked the author Robert Sample for the post:
hariharan_bk (Fri Oct 14, 2016 8:41 pm)
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby hariharan_bk » Fri Oct 14, 2016 8:40 pm

Thanks Robert, for your sample and explanation.

1) Can we right away call this module - HWTJPARS without making any other prerequisites?

2) Consider the following as JSON data. How will i locate the name/apt_nb? In general, we will address these fields in a copybook/WS- variable, but not sure how can we address all JSON fields in the program?

"bldg_nb": "12",
"apt_nb": null,
"po_box_nb": "5555",
"st_abbr_cd": "IL",
"name": "Harry"
 


Requirement:
I do have 50+ fields in my JSON, which i need to put them into a WS- variable and then compare them with DB2 extracted values to determine a match/mismatch between JSON and DB2 data.
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby enrico-sorichetti » Fri Oct 14, 2016 8:44 pm

1) Can we right away call this module - HWTJPARS without making any other prerequisites?


we do not know Your system setup

the content of the link You looked at should be discussed with Your support
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
hariharan_bk (Mon Oct 17, 2016 8:12 pm)
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby Robert Sample » Fri Oct 14, 2016 9:03 pm

How would I know the answers to your questions? I've NEVER coded anything to parse JSON data, and do not foresee any need to do so in the future. I was pointing out that the manual YOU referenced by a link contained the answers to your questions, so if you had merely kept reading you would not have needed to post anything.

I found HWTJPARS in SYS1.CSSLIB on my system. That data set may -- or may not -- exist on your site with that data set name. And if it exists with that name on your site, it may -- or may not -- be part of the default COBOL linkage editor / binder processing. Only someone working at your site -- such as your site support group -- could possibly answer your questions about it. If it is not part of the default or if the name has been changed at your site, you'll need to use linkage editor / binder statements to INCLUDE the module (or have SYS1.CSSLIB as part of your batch execution JCL STEPLIB concatenation if you use DYNAM as a COBOL compiler option).

You need to learn how to take independent action and try some of this on your own. Once you have transmitted JSON data to your mainframe, then you can start running your COBOL program to figure out what happens when you call HWTJPARS and what results you get back from each call. And unless you -- and nobody else -- does this, you're not likely to get much further. There have not been many JSON questions on this forum so you're not likely to get much more help here (or on any other forum, for that matter).

This is a HELP forum, not a WRITE-THE-CODE-FOR-YOU forum. If you want somebody to give you code, you need to be prepared to pay the going rate for consulting time (typical charges on this forum that have been quoted run from $500 US dollars per day to over 1000 euros per day) for someone to write your code for you.

EDIT: SYS1.CSSLIB is defined as part of the LNKLST concatenation, so you won't need it in your STEPLIB and using DYNAM as a COBOL compile option is recommended.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby hariharan_bk » Mon Oct 17, 2016 8:11 pm

Yes, I understand that.

With regard to setup, I have mentioned earlier that required libraries are available in our SYS1.* libraries.
Our support team is working on - gathering knowledge on this JSON PARSER. We need special permission to test the JSON parser in our system which will not be granted in the near future.Hence have requested for help in this forum.

Since this is new area for us, I was looking for someone who have actually got experience on this and dint have any intention to get my code written here and just use it as a cake piece.

Apologies !!

Thanks again for the earlier help on calling HWTJPARS.
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby Robert Sample » Mon Oct 17, 2016 8:55 pm

I searched this forum a minute ago for JSON. There were 8 hits (there will be 9 after I post this), and only 1 of them is not this thread. For that one post, someone did not get an answer to their issue on a stored procedure's return values. So with only 1 post on the subject, why would you think you're going to find any JSON experts in this forum? If you have questions, we'll answer if we can (as a volunteer forum, responses tend to be made when people have time and knowledge to be able to respond) but don't expect a whole lot of JSON expertise.
Can we right away call this module - HWTJPARS without making any other prerequisites?
This implies you did not know that the module is in a system library -- if that is not what you meant, you need to be clearer about what you are asking (such as WHAT prerequisites would be needed?) when you post.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby hariharan_bk » Tue Oct 18, 2016 2:13 pm

okay sure. Will take care of framing queries in the future.

(not sure though) I thought we need to call some initialization modules like HWTJINIT and few others like this, before calling HWTJPARS. Hence stated that question.

Thanks for the help !!
Many Thanks,
Harry
hariharan_bk
 
Posts: 73
Joined: Thu Mar 29, 2012 11:13 am
Has thanked: 5 times
Been thanked: 0 time

Re: Need help in using HWTJPARS in COBOL for parsing JSON da

Postby enrico-sorichetti » Tue Oct 18, 2016 2:38 pm

a quick search with IBM REDBOOKS HWTJPARS returned

http://www.redbooks.ibm.com/iea/v2r2/pd ... oolkit.pdf

not much but it is a starting point

z/OS Client Toolkit JSON Language Support
• Include files and sample programs provided in: • C/C++
• COBOL
• PL/I
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post