Hitachi

JP1 Version 12 JP1/IT Desktop Management 2 - Asset Console Creating an Access Definition File Guide


[IF] (conditionally execute a group of statements)

[IF] conditionally executes a group of statements based on specified conditions.

If the first condition is true, the processing beginning with [THEN] is executed. If the first condition is false, the[ELSEIF] tag can be used to conditionally execute another group of statements. If neither of the conditions is true, processing beginning with [ELSE] is executed; if [ELSE] is not defined, no processing is executed.

Although you can specify any number of [ELSEIF] tags, it is better to use the [SWITCH] tag to specify constants when you need to compare a condition value to a large number of constants, because you do not need to nest the condition branches so deeply, thus producing code that is easier to read. For a coding example of the [SWITCH] tag, see [SWITCH] (conditionally execute a group of statements).

Organization of this page

Syntax

[IF]
  condition-1
  [THEN]
    processing-if-condition-1-is-true
([ELSEIF])
    condition-2
  ([THEN])
    processing-if-condition-1-is-false-and-condition-2-is-true
   ([ELSE])
    processing-if-all-conditions-are-false
[IF_END]

Values

Example

Example 1

The following example searches for the asset information for asset number 10000. If data is found ([THEN]), that data is deleted; if no data is found ([ELSE]), the termination status is displayed.

[CLASS_FIND]
  AssetInfo
[FIND_DATA]
  (AssetInfo.AssetNo  = '10000')
[GET_VALUE]
  AssetID = AssetInfo.AssetID
 
[SET_VALUE]
  STATUS = $GETSTATUS()
[IF]
  STATUS = NORMAL
  [THEN]
    [DELETE]
      AssetInfo
    [DATA]
      AssetInfo.AssetID = AssetID
    [SET_VALUE]
      MSG = 'CLASS_FIND (' + STATUS + ')'
      $ECHO(MSG)
 
  [ELSE]
    [SET_VALUE]
      MSG = 'CLASS_FIND (' + STATUS + ')'
      $ECHO(MSG)
[IF_END]
Example 2

The example below performs the following processing:

  • If the data is updated normally ([THEN]), the termination status is displayed.

  • If the data has already been updated by another control process ([ELSEIF], [THEN]), a message is output.

  • If no data exists ([ELSE]), data is added.

    [UPDATE]
      AssetInfo
    [DATA]
      AssetInfo.AssetID = '10000'
      AssetInfo.AssetNo = '10000'
      AssetInfo.AssetKind = '001'
      AssetInfo.AssetBranchNo = 0
      AssetInfo.UpdateTime = _UpdateTime
    [SET_VALUE]
      STATUS = $GETSTATUS()
    [IF]
      STATUS = NORMAL
        [THEN]
          [SET_VALUE]
            MSG = 'UPDATE (' +STATUS+ ')'
            $ECHO(MSG)
        [ELSEIF]
          STATUS = MULTI
            [THEN]
              [SET_VALUE]
                MSG = 'Asset number [10000] is updated already.'
                $ECHO(MSG)
        [ELSE]
          [APPEND]
            AssetInfo
          [DATA]
            AssetInfo.AssetID = '10000'
            AssetInfo.AssetNo = '10000'
            AssetInfo.AssetKind = '001'
            AssetInfo.AssetBranchNo = 0
          [SET_VALUE]
            MSG = 'UPDATE (' +STATUS+ ')'
            $ECHO(MSG)
    [IF_END]