Two Tables in alv

381 views Asked by At

I am having two tables BKPF and TOA01.

  1. Report should have the following selection screen fields. Company code(BUKRS), Document Number(BELNR), Fiscal Year(GJAHR)
  2. For ALV report following field should be available in the layout.

    BKPF-BUKRS

    BKPF-BELNR

    BKPF-GJAHR

    BKPF-USNAM

    TOA01-ARCHIV_ID

    TOA01-ARC_DOC_ID

    **Link between BKPF and TOA01: TOA01-SAP_OBJECT = 'BKPF' AND TOA01-OBJECT_ID = concatenate -> BKPF-BUKRS + BKPF-BELNR + BKPF-GJAHR.

I want the logic to display (the alv) using two given tables using the link between them (given above).

Please help me with the answer.

1

There are 1 answers

0
J.Gerbershagen On

If you familiar with ABAP-CDS, you can define two CDS-views. The first one contains the data from table BKPF:

define view zbooking_doc as select from bkpf {
  key bukrs,
  key belnr,
  key gjahr,
  usnam,
  concat(bukrs, belnr, gjahr) as archiv_object_id

}

The second CDS-View joins BKPF with table TOA01 (according to your condition TOA01-SAP_OBJECT = 'BKPF' AND TOA01-OBJECT_ID = concatenate -> BKPF-BUKRS + BKPF-BELNR + BKPF-GJAHR.):

define view zbooking_doc_and_archiv as select from zbooking_doc
  left outer join toa01 on toa01.object_id = zbooking_doc.archiv_object_id {
  key bukrs,
  key belnr,
  key gjahr,
  usnam,
  archiv_id,
  arc_doc_id
} where toa01.sap_object = 'BKPF'

The tables shown in the ALV can be filled with a select-statement on view zbooking_doc_and_archiv.