Andrea Checchia, [05/08/22 08:36]
final String sql = ""
        + "SELECT COUNT(*) "
        + "FROM "
        + "( "
        + "SELECT SUM(mt.movementqty) AS movementqty, "
        + "       mt.M_Locator_ID, "
        + "       mt.M_Product_ID, "
        + "       COALESCE(mt.M_AttributeSetInstance_ID, 0) AS M_AttributeSetInstance_ID, "
        + "       mt.AD_Client_ID, "
        + "       mt.AD_Org_ID "
        + "FROM   M_Transaction mt "
        + "WHERE  mt.m_product_ID "+((p_m_product_id>0)?("="+p_m_product_id):"> 0 ")
        + "       AND mt.AD_Client_ID = ? "
        + "GROUP  BY mt.M_Locator_ID, "
        + "          mt.M_Product_ID, "
        + "          COALESCE(mt.M_AttributeSetInstance_ID, 0), "
        + "          mt.AD_Client_ID, "
        + "          mt.AD_Org_ID "
        + ") y ";

Andrea Checchia, [05/08/22 08:36]
final String ins = ""
          + "INSERT INTO M_StorageOnHand "
          + "            (QtyOnHand, "
          + "             M_Locator_ID, "
          + "             M_Product_ID, "
          + "             M_AttributeSetInstance_ID, "
          + "        DateMaterialPolicy, "
          + "             AD_Client_ID, "
          + "             AD_Org_ID, "
          + "             Created, "
          + "             CreatedBy, "
          + "             Updated, "
          + "             UpdatedBy, "
          + "             IsActive, "
          + "             M_StorageOnHand_UU) "
          + "SELECT SUM(mt.movementqty) AS movementqty, "
          + "       mt.M_Locator_ID, "
          + "       mt.M_Product_ID, "
          + "       COALESCE(mt.M_AttributeSetInstance_ID, 0), "
          + "       getDate(), "
          + "       mt.AD_Client_ID, "
          + "       mt.AD_Org_ID, "
          + "       getDate(), "
          + "       ?, "
          + "       getDate(), "
          + "       ?, " 
          + "       'Y', "
          + "       generate_uuid() "
          + "FROM   M_Transaction mt "
          + "WHERE  mt.m_product_ID "+((p_m_product_id>0)?("="+p_m_product_id):"> 0 ")
          + "       AND mt.AD_Client_ID = ? "
          + "GROUP  BY mt.M_Locator_ID, "
          + "       mt.M_Product_ID, "
          + "       COALESCE(mt.M_AttributeSetInstance_ID, 0), "
          + "       mt.AD_Client_ID, "
          + "       mt.AD_Org_ID";
