DATA-GEN (trim all option for string variable)

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

DATA-GEN (trim all option for string variable)

Post by kathan.p@gmail.com »

Code: Select all

dcl-ds jsonDoc qualified;                        
  dcl-ds conversation;                           
    dcl-subf subject varchar(1) inz(' ');        
    dcl-subf external_id varchar(1) inz(' ');    
    dcl-subf is_group_chat ind inz('0');         
    dcl-subf read_only ind inz('0');             
  end-ds;                                        
  dcl-subf message varchar(2000);                
  dcl-subf priority varchar(6) inz('normal');    
  dcl-subf fleet ind inz('1');                   
  dcl-subf recipients varchar(10) dim(1);        
  dcl-subf timestamp varchar(24);                
end-ds;                                          


jsonDoc.message = "TESTING";                                          
jsonDoc.recipients(1) = '*N/A*';                                   
jsonDoc.timestamp = %char(%timestamp());                           
                                                                   
DATA-GEN jsonDoc %DATA(myJson) %GEN('YAJLDTAGEN');            
[text]
Out of that DATA-GEN is below
why message variable showing in such a way? i tried using %Trim on variable itself but that didn't help...
any advise..
[/text]

Code: Select all

{
  "conversation": {
    "subject": "",
    "external_id": "",
    "is_group_chat": false,
    "read_only": false
  },
  "message": "TESTRING             \u0001TESTRING                                    \u0000\u0000\u0000\u0000\u0000\t*NONE",
  "priority": "normal",
  "fleet": true,
  "recipients": [
    "*N/A*"
  ],
  "timestamp": "2021-11-30-12.17.52.4505"
}
Scott Klement
Site Admin
Posts: 655
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-GEN (trim all option for string variable)

Post by Scott Klement »

There is no problems with the code you posted. When I ran it, this was the output (from the debugger):

Code: Select all

MYJSON =                                                               
          ....5...10...15...20...25...30...35...40...45...50...55...60 
     1   '{"conversation":{"subject":"","external_id":"","is_group_cha'
    61   't":false,"read_only":false},"message":"TESTING","priority":"'
   121   'normal","fleet":true,"recipients":["*N/A*"],"timestamp":"202'
   181   '1-11-30-13.38.35.6835"}                                     '
Most likely, the problem is with the way you are populating 'message' in the actual program. The problem in your JSON document is typical of mismatched parameters.
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: DATA-GEN (trim all option for string variable)

Post by kathan.p@gmail.com »

I am receiving this parameter from other program and it's length is 2000 same as declared in above DS

i am passing "TEST" as value and when it moves into DS it is going as

Code: Select all

JSONDOC.MESSAGE =                                                           
          ....5...10...15...20...25...30...35...40...45...50...55...60      
     1   'TESTT                                                       '     
    61   ' NE                    ?*NONE                               '     
   121   '                                                            '     
   181   '                                                            '     
[\code]
Scott Klement
Site Admin
Posts: 655
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-GEN (trim all option for string variable)

Post by Scott Klement »

What does this parameter look like in the program that is calling it? It also needs to be varchar(2000).
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: DATA-GEN (trim all option for string variable)

Post by kathan.p@gmail.com »

it is resolved now! It seems passing the parameter from command line was causing the issue but when i called it using program and pass the parameter it is working as expected.

Thank you
Scott Klement
Site Admin
Posts: 655
Joined: Sun Jul 04, 2021 5:12 am

Re: DATA-GEN (trim all option for string variable)

Post by Scott Klement »

The only way this would work reliably from the command-line would be if you had a CMD interface calling it. The CALL command always passes character parameters as CHAR(32) unless you pass more than 32 charactrs, at which point it passes CHAR(length-of-your-data), but I don't see how you could type 2000 characters in the command line.
Post Reply