cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Flexible workflow for Supplier Invoice SWF_WORKFLOW_CONDITION_EVAL don't work

ruthoyos
Discoverer
0 Likes
256

Hi experts,

I am using Flexible workflow for Supplier Invoice and for that I am implementing the custum logics  SWF_WORKFLOW_CONDITION_DEF and SWF_WORKFLOW_CONDITION_EVAL because we need create a new condition criteria for document type.  
This is my code for SWF_WORKFLOW_CONDITION_DEF  I think it's working correctly because the new condition appearing as an additional option in the Start Conditions dropdown in the Flexible Workflow app:

CONSTANTS co_id TYPE if_swf_flex_ifs_condition_def=>ty_condition_id VALUE 'DTP' ##NO_TEXT.

ct_condition = VALUE #(
  ( id = co_id
     subject = 'Accounting Document Type is'(001) " Texto traducible (mantén 001 en TEXT ELEMENTS)
    type = if_swf_flex_ifs_condition_def=>cs_condtype-start_step )
).

" Define Parameters
ct_parameter = VALUE #(
   ( id = co_id
     name = 'AccountingDocumentType' ##NO_TEXT " No traducir (clave técnica)
     shorttext = 'Document Type'(002) " Texto corto traducible
     xsd_type = if_swf_flex_ifs_condition_def=>cs_xstype-string
     mandatory = abap_true )
).

I think the problem is SWF_WORKFLOW_CONDITION_EVAL because when I create a workflow with this condition and post an invoice that meets the condition, the workflow doesn't trigger. However, if I use the workflow with the default configured conditions, it works.

This is my code for SWF_WORKFLOW_CONDITION_EVAL. If you could help me evaluate it to see if there are any errors, I would appreciate it.

CONSTANTS co_id TYPE if_swf_flex_ifs_condition_def=>ty_condition_id VALUE 'DTP' ##NO_TEXT.

cv_is_true = abap_false.

IF is_condition-condition_id <> co_id.
RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

IF iv_is_draft = abap_true.
RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

READ TABLE it_parameter_value INTO DATA(ls_param_value) INDEX 1.
IF sy-subrc <> 0 OR ls_param_value-value IS INITIAL.

RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

DATA(lv_expected_doc_type) = ls_param_value-value.

DATA: lv_bukrs TYPE string,
lv_belnr TYPE string,
lv_gjahr TYPE string.

CLEAR: lv_bukrs, lv_belnr, lv_gjahr.

DATA lt_parts TYPE STANDARD TABLE OF string WITH EMPTY KEY.
FIELD-SYMBOLS <p> TYPE string.

DO 6 TIMES.
ASSIGN COMPONENT |sont_key_part_{ sy-index }| OF STRUCTURE is_sap_object_node_type TO <p>.
IF sy-subrc = 0 AND <p> IS ASSIGNED AND <p> IS NOT INITIAL.
APPEND <p> TO lt_parts.
ENDIF.
ENDDO.

LOOP AT lt_parts ASSIGNING <p>.
DATA(lv_key) = <p>.
CONDENSE lv_key NO-GAPS.

IF lv_gjahr IS INITIAL
AND strlen( lv_key ) = 4
AND lv_key CO '0123456789'.
lv_gjahr = lv_key.
CONTINUE.
ENDIF.

IF lv_belnr IS INITIAL
AND strlen( lv_key ) = 10
AND lv_key CO '0123456789'.
lv_belnr = lv_key.
CONTINUE.
ENDIF.

IF lv_bukrs IS INITIAL
AND strlen( lv_key ) = 4
AND lv_key <> lv_gjahr.
lv_bukrs = lv_key.
ENDIF.
ENDLOOP.

IF lv_belnr IS INITIAL OR lv_gjahr IS INITIAL.
RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

lv_belnr = |{ lv_belnr ALPHA = IN }|.

DATA lv_actual_doc_type TYPE string.
CLEAR lv_actual_doc_type.

TRY.
IF lv_bukrs IS INITIAL.
SELECT SINGLE CompanyCode, AccountingDocumentType
FROM I_SupplierInvoiceAPI01
WHERE SupplierInvoice = @LV_belnr
AND FiscalYear = @LV_gjahr
INTO (@lv_bukrs, @LV_actual_doc_type).
ELSE.
SELECT SINGLE AccountingDocumentType
FROM I_SupplierInvoiceAPI01
WHERE CompanyCode = @LV_bukrs
AND SupplierInvoice = @LV_belnr
AND FiscalYear = @LV_gjahr
INTO @LV_actual_doc_type.
ENDIF.
CATCH cx_root INTO DATA(lx_supinv) ##CATCH_ALL.
CLEAR: lv_bukrs, lv_actual_doc_type.
ENDTRY.

IF lv_actual_doc_type IS INITIAL.
TRY.
SELECT SINGLE AccountingDocumentType
FROM I_JournalEntry
WHERE AccountingDocument = @LV_belnr
AND FiscalYear = @LV_gjahr
INTO @LV_actual_doc_type.
CATCH cx_root INTO DATA(lx_je) ##CATCH_ALL.
CLEAR lv_actual_doc_type.
ENDTRY.
ENDIF.

IF lv_actual_doc_type IS INITIAL.
RAISE EXCEPTION TYPE cx_ble_runtime_error.
ENDIF.

DATA(lv_up_expected) = lv_expected_doc_type.
DATA(lv_up_actual) = lv_actual_doc_type.

TRANSLATE: lv_up_expected TO UPPER CASE,
lv_up_actual TO UPPER CASE.

IF lv_up_actual = lv_up_expected.
cv_is_true = abap_true.
ENDIF.

Accepted Solutions (0)

Answers (0)