2

I am working on ABAP program - user input is to query column ANLAGE and output is to get all records from table EADZ (and only fields of EADZ) based on ANLAGE.

Statement and joins should work like this:

  • Input ANLAGE, find in table EASTL, gets LOGIKNR
  • Input LOGIKNR, find in table EGERR, gets EQUNR
  • Input EQUNR, find in table ETDZ, gets LOGIKZW
  • Input LOGIKZW, find in table EADZ, gets all records (this is the final output)

Here is the code I tried:

DATA: gt_cas_rezy   TYPE STANDARD TABLE OF eadz,
      lv_dummy_eanl LIKE eanl-anlage.
SELECT-OPTIONS: so_anl FOR lv_dummy_eanl NO INTERVALS NO-EXTENSION.

SELECT * FROM eadz 
INNER JOIN etdz ON eadz~logikzw EQ etdz~logikzw
INNER JOIN egerr ON etdz~equnr EQ egerr~equnr
INNER JOIN eastl ON egerr~logiknr EQ eastl~logiknr
INTO CORRESPONDING FIELDS OF TABLE @gt_cas_rezy
WHERE eastl~anlage IN @so_anl.

I got the records from table EADZ except that the date fields are empty (even though, they are filled in database table). I am assuming there is a problem with JOINs since in statement like this I join all the fields of all 4 tables into one "record" and then to corresponding fields of internal table.

How to get the values of date fields?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
PeterP
  • 23
  • 4
  • 1
    With7.40, SP5 there was a new sql parser. ~* is one new feature. If you use it, you must use the new open sql syntax (all host variables must be prefixed with @, comma seperated columns possible). It is recommended to do that anyways, as it reduces errors. Kindly mark the answer as correct. – peterulb Aug 28 '19 at 12:29
  • Hey @PeterP: Welcome to StackOverflow. I "accidentially" solved your problem, simply by editing your post/question such that it contains a minimal working example that includes declarations for all variables used. Please try this yourself next time ;) – koks der drache Aug 29 '19 at 08:33

1 Answers1

2

You can find the answer in the documentation.

If a column name appears multiple times and no alternative column name was granted, the last column listed is assigned.

In your case, at least two tables share the same column name. Therefore the values from the last mentioned table are used in the join.

You can solve this by listing the columns explicitly (or eadz~* in your case), giving an alias if required.

SELECT EADZ~* FROM EADZ INNER JOIN ETDZ ON EADZ~LOGIKZW = ETDZ~LOGIKZW
INNER JOIN EGERR ON ETDZ~EQUNR = EGERR~EQUNR
INNER JOIN EASTL ON EGERR~LOGIKNR = EASTL~LOGIKNR
INTO CORRESPONDING FIELDS OF TABLE @gt_cas_rezy
WHERE EASTL~ANLAGE IN @SO_ANL.

If you require additional fields, you can add them explicily with e.g. EADZ~*, EASTL~A.

peterulb
  • 2,869
  • 13
  • 20