Skip to Content
0
Sep 09, 2021 at 11:48 AM

BEHAVIOR_ILLEGAL_STATEMENT

2210 Views

Hi all,

We are trying to call BAPI_EXCHANGERATE_CREATE in the create method in the behavior class implementation. The entity is defined as follows:

define root custom entity YFIN_I_FxRate
{
  key ExchangeRateType           : kurst_curr;
  key FromCurrency               : fcurr_curr;
  key ToCurrency                 : tcurr_curr;
  key ValidFrom                  : gdatu_cur;
      QuotedExchangeRate         : ukursp;
      FromFactorCurrency         : ffact_curr;
      ToFactorCurrency           : tfact_curr;
      IndirectQuotedExchangeRate : ukursm;
      IndirectFromFactorCurrency : ffact_curr;
      IndirectToFactorCurrency   : tfact_curr;
}

and the behavior declaration:

unmanaged implementation in class ybp_fin_i_fxrate unique;
define behavior for YFIN_I_FxRate alias FxRate
//late numbering
//lock master
//etag master <field_name>
{
  create;
}

in the class ybp_fin_i_fxrate we have the following implementation:

CLASS lhc_YFIN_I_FxRate DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.
    METHODS create FOR MODIFY
      IMPORTING entities FOR CREATE FxRate.
    METHODS read FOR READ
      IMPORTING keys FOR READ FxRate RESULT result.
ENDCLASS.
CLASS lhc_YFIN_I_FxRate IMPLEMENTATION.
  METHOD create.
   DATA ls_return TYPE bapiret2.
   LOOP AT entities REFERENCE INTO DATA(ls_entity).
   DATA(ls_data) = VALUE bapi1093_0(
      rate_type = ls_entity->ExchangeRateType
      from_curr = ls_entity->FromCurrency
      to_currncy = ls_entity->ToCurrency
      valid_from = ls_entity->ValidFrom
      exch_rate = ls_entity->QuotedExchangeRate
      from_factor = ls_entity->FromFactorCurrency
      to_factor = ls_entity->ToFactorCurrency
      exch_rate_v = ls_entity->IndirectQuotedExchangeRate
      from_factor_v = ls_entity->IndirectFromFactorCurrency
      to_factor_v = ls_entity->IndirectToFactorCurrency
   ).
    CALL FUNCTION 'BAPI_EXCHANGERATE_CREATE'
      EXPORTING
        exch_rate        = ls_data
     IMPORTING
       return            = ls_return.
 IF ls_return IS NOT INITIAL.
        reported-fxrate = VALUE #(
          BASE reported-fxrate
          ( ExchangeRateType = ls_entity->ExchangeRateType
          FromCurrency = ls_entity->FromCurrency
          ToCurrency = ls_entity->ToCurrency
          ValidFrom  = ls_entity->ValidFrom
          %msg = NEW ycl_fin_fx_reported(
                   severity   = CONV #( ls_return-type )
                   textid     = VALUE #(
                     msgid = ls_return-id
                     msgno = ls_return-number
                     attr1 = ls_return-message_v1
                     attr2 = ls_return-message_v2
                     attr3 = ls_return-message_v3
                     attr4 = ls_return-message_v4
                   )
                 )
          )
        ).
     ENDIF.
      IF ls_return-type = 'E' OR ls_return-type = 'A'.
        failed-fxrate = VALUE #( BASE failed-fxrate (
          ExchangeRateType = ls_entity->ExchangeRateType
          FromCurrency = ls_entity->FromCurrency
          ToCurrency = ls_entity->ToCurrency
          ValidFrom  = ls_entity->ValidFrom
          %fail = VALUE #(
            cause = if_abap_behv=>cause-not_found
          )
        ) ).
        CONTINUE.
     ENDIF.
      mapped-fxrate = VALUE #( BASE mapped-fxrate (
        ExchangeRateType           = ls_entity->ExchangeRateType
        FromCurrency               = ls_entity->FromCurrency
        ToCurrency                 = ls_entity->ToCurrency
        ValidFrom                  = ls_entity->ValidFrom
      ) ).
   ENDLOOP.
  ENDMETHOD.
  METHOD read.
    ....
  ENDMETHOD.
ENDCLASS.

consider the create method. When it gets called with

MODIFY ENTITIES OF YFIN_I_FxRate
      ENTITY FxRate
      CREATE
        SET FIELDS WITH value #( ( ExchangeRateType = 'M' FromCurrency = 'AUD' ToCurrency = 'USD' ValidFrom = '20210906' QuotedExchangeRate = '0.5555' ToFactorCurrency = '1' FromFactorCurrency = '1'  )
                                )
      MAPPED DATA(lt_fxrate_create)
      FAILED DATA(lt_failed_create)
      REPORTED DATA(lt_reported_create).

it dumps with the error message:

There is probably an error in the program
"SAPLBUS1093".
A BEHAVIOR implementation is active for "YFIN_I_FXRATE". While this is the
 case,
the following ABAP statements are illegal:
- COMMIT
- ROLLBACK
- SUBMIT
- CALL TRANSACTION
- LEAVE
all DYNPRO-related statements, such as MESSAGE, CALL DIALOG, and CALL
SCREEN
The following statement is only allowed in the "Save” phase: - CALL
FUNCTION IN UPDATE TASK
The following statement is not allowed In the "Save” phage and during
processing of the "UPDATE TASK": - MODIFY ENTITIES
Quitting the BEHAVIOR implementation with RAISE EXCEPTION is not
allowed.

It seems, somewhere in the function module BAPI_EXCHANGERATE_CREATE it calls:

CALL FUNCTION 'MODIFY_TCURR' IN UPDATE TASK  
  TABLES
    t_tcurr = itcurr. 

This is not allowed in rap. What is the workaround for such as scenario?

Thanks