COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.


#Programminglanguages
 View Only
  • 1.  JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/17/24 01:32 PM

    Hello!

    I have begun to investigate the use of JSON GENERATE to solve for an API use case. 

    Assuming that I cannot change the NODBCS compiling option, is there any way to utilize the JSON GENERATE statement? Ideally, I'd be able to create a JSON payload to be sent via zConnect (2.0). (I recognize that's what zconnect is for already).

    Following the examples given from the documentation, anytime I try to establish a national (PIC N(100)) or UTF-8 (PIC U(100)) field, I receive an error at compile time re: the NODBCS.

    IGYSC1105-E   The "NODBCS" option was in effect but the program contained national data.  Execution results are unpredictable.             

    For example, if I use this in my system:
    *                                      
     01 payload.                           
       02 data-a PIC X.                    
       02 data-b PIC X.                    
    *                                      
     01 myJSONpayload      PIC  X(50).     
     01 myJSONpayload-len  PIC S9(04) COMP.
    *                                      
        MOVE 'Y' TO data-a                                    
        MOVE 'N' TO data-b                                    
        JSON GENERATE myJSONpayload FROM payload              
                COUNT myJSONpayload-len                       
        END-JSON                                              
       DISPLAY 'DJWPEP : ' myJSONpayload (1:myJSONpayload-len)

    Display: DJWPEP : #  /`%?/   #  / / /        / /     + ''   


    Local log (just first 30 bytes)

    The same (but 50 bytes) after pushing into the (outbound) request and logged there:
    "#?ø/`%?/À??#?À/È/\u0005/???ß???À/È/\u0005Â???+?''"

    I am not sure if that makes sense, and happy to follow-up.

    Thanks for any help.


                         



    ------------------------------
    Derek Williamson
    ------------------------------


  • 2.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 08:42 AM

    Can you not use a PROCESS(DBCS) at the front of the source code to change the compiler option?



    ------------------------------
    Jon Butler
    ------------------------------



  • 3.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 01:04 PM

    Can't you just add a first line in your source program in column 8:

    CBL DBCS

    That would solve the NATIONAL and UTF-8 problem.

    Tom

    :



    ------------------------------
    Tom Ross
    ------------------------------



  • 4.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 02:22 PM

    Yes, you both might be right. However, I'm not certain if it is allowable in my org. I'm also using 6.2 version of COBOL as if that matters. I will give it a shot.

    Would doing so though, still create a readable JSON format, if I have to move it to a non-national defined field?

    e.g. json generate creates JSONpayload from payload but I have to send JSONpayload out through zConnect which is a PIC X. Is that even feasible?



    ------------------------------
    Derek Williamson
    ------------------------------



  • 5.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 02:49 PM
    Derek,

    DBCS has been around for a while, long before JSON I believe, as I used it for Japanese characters around 30 years ago.

    You should be able to add the PROCESS/CBL statement starting in column 8 as the first statement in your source.  Unless DBCS has been defined as a non-modifiable option  when the compiler was installed, it should work.







  • 6.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 03:12 PM

    Hello Derek, if you absolutely have to use NODBCS you can still use JSON GENERATE with PIC X items, but you cannot use anything that involves PIC N or N literals anywhere in your program.  But yes JSON GENERATE will work and it will produce valid UTF-8 JSON in the receiving PIC X item.   Here's a small program that compiles with NODBCS but uses JSON GENERATE

           CBL NODBCS NSYMBOL(DBCS) CODEPAGE(1140)
           IDENTIFICATION DIVISION.
             PROGRAM-ID. MYPROG.
           DATA DIVISION.
            WORKING-STORAGE SECTION.
             1 JSON-TEXT PIC X(100).
             1 JSON-TEXT-LEN PIC 9(4) COMP.
             1 PAYLOAD.
               02 DATA-A PIC X.
               02 DATA-B PIC X.
           PROCEDURE DIVISION.
               MOVE 'Y' TO DATA-A
               MOVE X'FB' TO DATA-B
               JSON GENERATE JSON-TEXT FROM PAYLOAD
                 COUNT JSON-TEXT-LEN
               END-JSON
               DISPLAY JSON-TEXT-LEN
               DISPLAY FUNCTION HEX-OF(JSON-TEXT(1:JSON-TEXT-LEN))
               GOBACK
               .
           END PROGRAM MYPROG.

    (NOTE: 6.2 might not have the HEX-OF function...that function is useful for printing non-EBCDIC to the terminal)



    ------------------------------
    Jeffery Shimoda
    ------------------------------



  • 7.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 04:30 PM
    Edited by Derek Williamson 10/18/24 04:32 PM

    Thanks, Jeff.

    I was able to see in the terminal log the Hex values, which means that the Springboot layer I'm sending this to will be able to convert to useable json?


    Update: this was a question



    ------------------------------
    Derek Williamson
    ------------------------------



  • 8.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/18/24 04:32 PM


    ------------------------------
    Derek Williamson
    ------------------------------



  • 9.  RE: JSON GENERATE - Blocked by NODBCS setting?

    Posted 10/21/24 08:50 AM

    Looks good to me.



    ------------------------------
    Jeffery Shimoda
    ------------------------------