由于您的 doc1 优先级值实际上是六个,因此应该可以。
SELECT b~client,
coalesce( p1~doc1, p2~doc1, p3~doc1, p4~doc1, p5~doc1, p6~doc1 ),
coalesce( p1~doc2, p2~doc2, p3~doc2, p4~doc2, p5~doc2, p6~doc2 )
FROM /bi0/pdoctax AS b
LEFT OUTER JOIN /bi0/pdoctax AS p1
ON p1~client = b~client
AND p1~doc1 = 'ITCI'
LEFT OUTER JOIN /bi0/pdoctax AS p2
ON p2~client = b~client
AND p2~doc1 = 'ITPS'
LEFT OUTER JOIN /bi0/pdoctax AS p3
ON p3~client = b~client
AND p3~doc1 = 'ITPT'
LEFT OUTER JOIN /bi0/pdoctax AS p4
ON p4~client = b~client
AND p4~doc1 = 'ITPT'
LEFT OUTER JOIN /bi0/pdoctax AS p5
ON p4~client = b~client
AND p4~doc1 = 'P5'
LEFT OUTER JOIN /bi0/pdoctax AS p6
ON p4~client = b~client
AND p4~doc1 = 'P6'
WHERE b~client = @<result_fields>-client
INTO @DATA(ls_doctax).
我假设您正在寻找在单个 SELECT 语句中执行此操作的答案,否则您可以循环:
DATA lt_priorities TYPE STANDARD TABLE OF /bi0/pdoctax-doc1.
lt_priorities = VALUE #( ( 'ITCI' ) ( 'ITPS' ) ( 'ITPT' ) ( 'ITPP' ) ( 'P500' ) ( 'P600' ) ).
SELECT b~client,
doc1,
doc2
FROM /bi0/pdoctax AS b
WHERE b~client = @<result_fields>-client
ORDER BY doc1 ASCENDING
INTO TABLE @DATA(lt_doctax).
DATA ls_doctax_filtered LIKE LINE OF lt_doctax.
LOOP AT lt_priorities ASSIGNING FIELD-SYMBOL(<fs_priority>).
READ TABLE lt_doctax ASSIGNING FIELD-SYMBOL(<fs_doctax>)
WITH KEY doc1 = <fs_priority> BINARY SEARCH.
IF sy-subrc = 0.
ls_doctax_filtered = <fs_doctax>.
* --->
EXIT.
ENDIF.
ENDLOOP.