How to return a value when the fields don't match in SAP Infoset

626 views Asked by At

I have the main table EKPO joined to tables MLGN and MLGT as outer joins.

I have created an extra field BINALOC in the infoset and want it to return a value from table MLGT under certain conditions:

  1. If the fields MLGN-LTKZE and MLGT-LGTYP match then return the associated MLGT-LGPLA field.
  2. If MLGN-LTKZE = 'R1', then only return relevant MLGT-LGPLA where MLGT-LGTYP = '006'.
  3. If MLGN-LTKZE <> MLGT-LGTYP return blank.

Currently I can do the first 2 conditions but unable to fit in the 3rd as it conflicts with the number 2.

I have tried a variety of IF statements and various orders for the IF conditions, and different join types.

This the current code I have in the extra field BINALOC coding section:

IF MLGN-LTKZE = 'R1'.
  select LGPLA as LGPLA
   from *MLGT into BINALOC
   where *MLGT~LGTYP eq '006'.
  ENDSELECT.    
else.
  select LGPLA as LGPLA
    from *MLGT into BINALOC
    where *MLGT~LGTYP eq MLGN-LTKZE.
  endselect.
endif.

I want the field to return blank when the fields I mentioned before do not match.

Currently it returns a copy of the field above it.

2

There are 2 answers

1
I.B.N. On BEST ANSWER

this?

IF MLGN-LTKZE = 'R1'.
  select LGPLA as LGPLA
    from *MLGT into BINALOC
    where *MLGT~LGTYP eq '006'.
  ENDSELECT.
else.
  select LGPLA as LGPLA
    from *MLGT into BINALOC
    where *MLGT~LGTYP eq MLGN-LTKZE.
  endselect.
  if sy-subrc ne 0.
    select LGPLA as LGPLA
      from *MLGT into BINALOC
      where *MLGT~LGTYP ne MLGN-LTKZE.
    endselect.
  endif.
endif.
0
Sandra Rossi On

First of all, it's difficult to answer because the 3 functional rules are subject to interpretation because they have overlapping conditions.

If they correspond to this truth table:

MLGN-LTKZE  Exists MLGN-LTKZE/MLGT-LGTYP  BINALOC
----------  ----------------------------  -------------------------------
=R1         true or false                 MLGT-LGPLA for LGTYP='006'
<>R1        true                          MLGT-LGPLA for LGTYP=MLGN-LTKZE
<>R1        false                         blank

Then the program should be like this:

if MLGN-LTKZE = 'R1'.
  select LGPLA as LGPLA
    from *MLGT into BINALOC
    where *MLGT~LGTYP eq '006'.
  endselect.
else.
  select LGPLA as LGPLA
    from *MLGT into BINALOC
    where *MLGT~LGTYP eq MLGN-LTKZE.
  endselect.
  if sy-subrc ne 0.
    clear BINALOC.
  endif.
endif.

The issue you had is probably that if one line matched the 3rd condition, then BINALOC was not cleared, and so kept the value calculated during the processing of the previous line.