Current Position:Home > Logical Expression

Logical Expression

Update:10-11Source: network consolidation
Advertisement
Hi,
I have an internal table contains field for logical expression EQ, GE, GT etc.
I would like to use this logical expression in my ABAP code.
For example
READ TABLE INTAB INDEX 1.
Comparing the value of a and b based on the logical expression from the INTAB.
How can i achieve this ?
Thanks.
Regards,
Jon

The Best Answer

Advertisement
Hi,
    The required code has to be declared in the Macro defination, it is define between the statement DEFINE and END-OF-DEFINATION, with the help of CASE statement you can code for all the possible Options. Just check the below example.
DATA : v_aaa TYPE i VALUE 50,
       v_bbb TYPE i VALUE 100.
TYPES : BEGIN OF ty_ztab,
          field  TYPE c LENGTH 5,
          option TYPE c LENGTH 2,
        END OF ty_ztab.
DATA : i_ztab  TYPE TABLE OF ty_ztab,
       wa_ztab TYPE ty_ztab.
DEFINE macro.
  case &1.
    when 'GT'.
      if v_aaa gt v_bbb.
        write :/ v_aaa, 'Greater than', v_bbb.
      else.
        write :/ v_aaa, 'Less than', v_bbb.
      endif.
    when 'EQ'.
      if v_aaa eq v_bbb.
        write :/ 'Equal'.
      endif.
    when 'LT'.
    when 'NE'.
    when others.
  endcase.
END-OF-DEFINITION.
START-OF-SELECTION.
  wa_ztab-field = 'abc'.
  wa_ztab-option = 'GT'.
  APPEND wa_ztab TO i_ztab.
  CLEAR : wa_ztab.
  wa_ztab-field = 'cef'.
  wa_ztab-option = 'EQ'.
  APPEND wa_ztab TO i_ztab.
  CLEAR : wa_ztab.
  READ TABLE i_ztab INTO wa_ztab WITH KEY
                    field = 'abc'.
  IF sy-subrc = 0.
    macro wa_ztab-option.
  ENDIF.
Output will be :-  50 Less than 100, which is written in ELSE condition of the CASE condition GT.
Regards
Bala Krishna.