1. Sivaprakash BKR
  2. PowerBuilder
  3. Saturday, 5 August 2023 12:00 PM UTC

Hello,

Using PB 2022 B 1900 

Receiving data from as a json string.

[
  {
    "selection": "Y",
    "code": "001",
    "debit": "2878.89",
    "credit": "9878.00"
  }
]

Here all values received are string values.   Need to import the data into a datawindow, where column for debit and credit is numeric datatype and code is string datatype in datawindow.   Trying to import the data into a datawindow using ImportJSONByKey.  

Selection and code get imported as both datatype matches, but values for debit and credit fails to import due to mismatch in datatype.

ImportJSON and ImportJSONByKey gives the performance advantage.   

Inserting every row by reading the JSON by converting the required data.  It works, but slow.

Is there any way to use the ImportJSON that could convert the selected column's datatype [not all, column code should not be converted ]?
Or any other ways (methods) to modify the JSON values of a selected columns?  Result to be like this

[
  {
    "selection": "Y",
    "code": "001",
    "debit": 2878.89,               <-  No quote
    "credit": 9878.00               <-  No quote
  }
]

Happiness Always
BKR Sivaprakash

 

John Fauss Accepted Answer Pending Moderation
  1. Saturday, 5 August 2023 18:36 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Sivaprakash -

Not knowing what you are intending to do with the information in the DataWindow/DataStore, what I'm going to suggest may or may not be workable in your situation: Import the string values, but in that DataWindow also have computed fields whose expressions convert the values in the two string columns into decimal values using the Dec(string) DataWindow expression function.

Maybe also subsequently use dot notation to reference all of the values in a column/computed field and assign those values to another DW/DS that has the four columns that are defined with the correct data types:

// Copy values in column named "selection".
dw_good.Object.Data.selection = dw_import.Object.Data.selection

// Copy values in column named "code".
dw_good.Object.Data.code      = dw_import.Object.Data.code

// Copy values from computed field "c_debit" to column named "debit".
dw_good.Object.Data.debit     = dw_import.Object.Data.c_debit

// Copy values from computed field "c_credit" to column named "credit".
dw_good.Object.Data.credit    = dw_import.Object.Data.c_credit

Best regards, John

Comment
  1. Sivaprakash BKR
  2. Sunday, 6 August 2023 06:06 AM UTC
Thanks John.

Let me try this solution where it will fit.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 5 August 2023 12:39 PM UTC
  2. PowerBuilder
  3. # 2

Hi BKR;

  Can you get the source of the JSON data to send you the debit & credit fields as numeric so that you don't have to convert it?

Regards ... Chris 

Comment
  1. Sivaprakash BKR
  2. Saturday, 5 August 2023 12:49 PM UTC
Chris, that's our last option.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Saturday, 5 August 2023 13:27 PM UTC
Unfortunately without the key financial data in numeric format, you're going to loose performance due to data type conversation in whatever approach you choose. :-(
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.