why using join table doesn't get the the result intended

346 views Asked by At

I have an issue with my code ABAP and I can't figure out what it is.

I want to get 3 fields from EKKO and 1 field from EKPO after select-options:

SELECT-OPTIONS: s_ebeln FOR ekpo-ebeln.

SELECT  eko~ebeln eko~aedat ekp~elikz
  FROM ekko as eko
  JOIN ekpo as ekp
  ON eko~ebeln = ekp~ebeln
  into table it_eko2
  WHERE eko~ebeln in s_ebeln.

The issue is I'm getting nothing for ekp~elikz (if I remove the condition WHERE eko~ebeln in s_ebeln I get the fields needed).

I tried to get 4 fields eko~ebeln eko~aedat ekp~elikz from corresponding to the PO numbers range entered by the users but I'm getting the three fields from ekko only instead.

Any help please ?

1

There are 1 answers

0
AlexSchell On

Actully the select statement you provided should work.

There is the output from my sample data:

ebeln aedat ebelp elikz
0044686616 20220101 00001 X
0044686616 20220101 00002
0044686616 20220101 00003 X
0044686616 20220101 00004
0044686616 20220101 00005 X
0044686618 20220101 00001 X
0044686618 20220101 00002

And the program - I just selected additionally the ebelp (item number):

SELECT eko~ebeln, eko~aedat, ekp~ebelp, ekp~elikz
    FROM ekko AS eko
    JOIN ekpo AS ekp
    ON eko~ebeln = ekp~ebeln
    INTO TABLE @DATA(it_eko2)
    WHERE eko~ebeln IN @s_ebeln.
 
  IF sy-subrc IS INITIAL.
    LOOP AT it_eko2 ASSIGNING FIELD-SYMBOL(<fs_eko2>).
      WRITE: / |{ <fs_eko2>-ebeln }  { <fs_eko2>-aedat } { <fs_eko2>-ebelp } { <fs_eko2>-elikz }|.
    ENDLOOP.
  ENDIF.

Please note that every entry in the header table EKKO (EinKaufsbelegKOpf - Purchasing document header) table corresponds to 1 or more entries in the position table EKPO (EnKaufsbelegPOsition - Purchasing document item) table.

The field elikz (EndLIeferungsKennZeichen - Delivery completed indicator) has char(1) type, which is an indicator, and contais either ' ' (space) or 'X' symbol - maybe no item in your selection has 'X' set and it looks like as nothing was selected.

Try also to set a breakpoint and check in the debugger what data is actully present in s_ebeln range table - below is the sample from my case (selected two single values):

Table: S_EBELN[]

Row SIGN OPTION LOW HIGH
1 I EQ 0044686618
2 I EQ 0044686616

If the condition range table is empty - all entries from the db-tables will be selected, which could be a lot of data.

And one more step - try to use the transaction se16 / se16n to manually select the document(s) by ebeln and check wheather the documents in question exist and which values the fields have.