Complex queries in ABAP / SAP

This query joins VBRP and VBRK, selecting fields that might be of historical interest to a company. After the query, I have included the selection screen and work areas (ITABs or internal tables) created to hold the information

ABAP query

select p~wavwr k~vkorg
p~eannr k~fkart k~erdat
k~kunag k~spart k~vbeln
p~netwr p~kostl p~prctr
p~stafo p~aubel p~vgbel
k~waerk k~erdat p~kursk
into (ws_vbrp-wavwr, ws_vbrp-vkorg,
ws_vbrp-eannr, ws_vbrp-fkart, ws_vbrp-erdat,
ws_vbrp-kunag, ws_vbrp-spart, ws_vbrp-bill,
ws_vbrp-netwr, ws_vbrp-pkostl, ws_vbrp-pprctr,
ws_vbrp-stafo, ws_vbrp-vbel2, ws_vbrp-vbeln,
ws_vbrp-waerk, ws_vbrp-erdat, ws_vbrp-kursk)
from vbrk as k join vbrp as p
on k~vbeln eq p~vbeln
where k~vkorg in sk_vkorg
and k~spart in sk_spart
and p~eannr in sp_eannr
and k~fksto in sk_fksto
and k~fkart in sk_fkart
and k~vbeln in sk_vbeln
and p~posnr in sp_posnr
and k~erdat in sk_erdat
and p~fkimg in sp_fkimg
and p~netwr in sp_netwr
and p~wavwr in sp_wavwr
and p~matnr in sp_matnr
and p~pstyv in sp_pstyv
and p~spart in sp_spart
and p~werks in sp_werks
and p~kostl in sp_kostl
and p~prctr in sp_prctr
and p~stafo in sp_stafo
and p~aubel in sp_aubel.

Selection criteria

You will need to adjust your block number and add title text ( Goto >> Text elements >> Selection Texts ) for the selection block.

selection-screen begin of block 1 with frame title text-1.
select-options:
sk_vkorg for vbrk-vkorg, " Sales Organization
sk_spart for vbrk-spart, " Header Divsion
sp_eannr for vbrp-eannr, " Sales Document Type
sk_fksto for vbrk-fksto, " Billing document is cancelled
sk_fkart for vbrk-fkart, " Billing Type
sk_vbeln for vbrk-vbeln, " Billing document
sp_posnr for vbrp-posnr, " Billing item
sk_erdat for vbrk-erdat, " Date created
sp_fkimg for vbrp-fkimg, " Actual billed quantity
sp_netwr for vbrp-netwr, " Net value
sp_wavwr for vbrp-wavwr, " Cost
sp_matnr for vbrp-matnr, " Material number
sp_pstyv for vbrp-pstyv, " Item category
sp_spart for vbrp-spart, " Line Division
sp_werks for vbrp-werks, " Plant
sp_kostl for vbrp-kostl, " Cost Center
sp_prctr for vbrp-prctr, " Profit center
sp_stafo for vbrp-stafo, " Update group
sp_aubel for vbrp-aubel. " Sales Document
selection-screen: end of block 1.

Work Structures

types: begin of t_vbrp,
vbel2 type bseg-vbel2, " Sales document
vbeln type bseg-vbeln, " Delivery/Billing document
bill type vbrk-vbeln, " Billing document
join2 type bseg-vbeln, " Join Field
wavwr type vbrp-wavwr, " Cost
vkorg type vbrk-vkorg, " Sales Organization
eannr type vbrp-eannr, " Sales Document Type
fkart type vbrk-fkart, " Billing Type
erdat type vbrk-erdat, " Date created
kunag type vbrk-kunag, " Sold-to party
spart type vbrk-spart, " Header Divsion
netwr type vbrp-netwr, " Net value
pkostl type vbrp-kostl, " Cost Center
pprctr type vbrp-prctr, " Profit center
stafo type vbrp-stafo, " Update group
vcheck(1),
waerk type vbrk-waerk, " currency
kursk type vbrp-kursk, " exchange rate
end of t_vbrp.

data: ws_vbrp type t_vbrp.


[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network


In Association with Amazon.com