project BLF > class XML > method SetFieldValue

Description

Set a field value in a buffer for a table.


Parameters


ihNodeinputhandleNode that has an element with the value
ihFieldinputhandleBuffer field handle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method XML.ConvertXmlToTableDetail


program code (program1/xml.p)

if ihNode:num-children = 0
then assign vcText = "":U.
else do:
    create x-noderef vhText in widget-pool "non-persistent".
    ihNode:get-child (vhText, 1) no-error.
    
    assign vcText = if error-status:num-messages = 0                                             and
                       can-do ("+>text,+>cdata-section":U, replace (vhText:name, "#":U, "+>":U)) and
                       can-do ("TEXT,CDATA-SECTION":U, vhText:subtype)
                    then trim (vhText:node-value)
                    else ?.
                    
    delete object vhText.
end.

if vcText = ?
then do:
    assign oiReturnStatus = -3.
    return.
end.

if vcText = "?":U
then do:
    assign oiReturnStatus       = 0
           ihField:buffer-value = ?.
           
    return.
end.

if vcText = "":U
then do:
    assign oiReturnStatus = 0.
    return.
end.

if ihField:data-type = "character":U
then do:
    if vcText begins "~"'":U
    then assign vcText = substring(vcText, 2, length(vcText,"CHARACTER":U) - 2,"CHARACTER":U).
    
     /* ================================================================================ */
     /* A problem exists in putting chr(2) and chr(3) characters to the XML file.        */
     /* They are not recognized by the parser, so we have to replace them by something   */
     /* else :                                                                           */
     /* Chr(2) is replaced by "chr[2]".                                                  */
     /* ================================================================================ */
     assign vcText = replace(vcText,"chr[2]":U,chr(2)).
            
    assign oiReturnStatus = 0
           ihField:buffer-value = vcText.
    return.
end.
else if vcText = "":U and ihField:data-type <> "logical":U
then do:
    assign oiReturnStatus = -3.
    return.
end.

assign vcValue = ?.
case ihField:data-type:
    when "logical":U
    then assign vcValue = (if lookup(vcText, "1,-1,yes,true":U) > 0
                           then "yes":U
                           else if lookup(vcText, "0,no,false":U) > 0
                                then "no":U
                                else ?).
    when "date":U
    then assign vcTemp = session:date-format
                session:date-format = "ymd":U /* to support ISO8601 */
                vtDate = date(vcText)
                session:date-format = vcTemp
	        vcValue = string(vtDate) no-error.
    when "decimal":U
    then vcValue = string(decimal(vcText)) no-error.
    when "integer":U
    then vcValue = string(integer(vcText)) no-error.
end.

if vcValue = ?
then do:
    assign oiReturnStatus = -3.
    return.
end.

assign ihField:buffer-value  = vcValue no-error.
if error-status:error
then do:
    assign oiReturnStatus = -3.
    return.
end.

if ihField:data-type = "decimal":U and
   ihField:buffer-value <> dec(vcValue)
then do:
    assign oiReturnStatus = -3.
    return.
end.

assign oiReturnStatus = 0.