Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Select Case Statement

Former Member
0 Likes
8,528

With transact SQL I can do the following:

SELECT
SUM(CASE WHEN pstyv = 'KEN' THEN newtr) AS KENsales,
SUM(CASE WHEN pstyv <> 'KEN' THEN newtr) AS OTHERsales etc

Is there anyway this can be done in ABAP in the same way?

Kind Regards

Carly

6 REPLIES 6
Read only

Former Member
0 Likes
1,428

Hi,

It would be fine if you describe your requirement in brief in words.

Message was edited by: Palak Limbachiya

Read only

Former Member
0 Likes
1,428
data: kensales like vrp-netwr,
      OTHERsales like vbrp-netwr.

data: begin of itab occurs 0,
      pstyv type pstyv,
      netwr type netwr,
      end of itab.
     

select pstyv netwr into table itab from dbtab where cond.

loop at itab.
if itab-pstyv = 'KEN'.
kensales = kensales + itab-netwr.
else.
OTHERsales = OTHERsales + itab-netwr.
endif.
endloop.

Read only

Former Member
0 Likes
1,428

Hi Carl,

select sum( pstyv ) as kensales

where pstyv = 'KEN'.

select sum( pstyv ) as othersales

where pstyv ne 'KEN'.

CASE PSTYV.

WHEN KEN.

WRITE:/ KENSALES.

WHEN OTHERS.

WRITE:/OTHERSALES.

ENDCASE.

regards,

VIjay.

Read only

Former Member
0 Likes
1,428

Hi,

select pstyv netwr into table it_kensales from <table> where pstyv = 'KEN'.

select pstyv netwr into table it_othersales from <table> where pstyv <> 'KEN'.

Regards

vijay

Read only

Former Member
0 Likes
1,428

The select statement I currently have is:

SELECT a~kunnr b~vkbur c~pernr a~name1 a~name2 a~name3 a~name4
       a~stras a~ort01 a~pstlz
       SUM( e~netwr ) AS sa_sales
       SUM( e~wavwr ) AS sa_cost
  INTO TABLE it_list
  FROM kna1 AS a
      JOIN knvv AS b
        ON a~kunnr = b~kunnr
      JOIN knvp AS c
        ON a~kunnr = c~kunnr
      JOIN vbrk AS d
        ON a~kunnr = d~kunag
      JOIN vbrp AS e
        ON d~vbeln = e~vbeln
      UP TO 1000 ROWS
  WHERE parvw = 'VE'
    AND a~kunnr IN so_cust
    AND d~erdat IN so_date
  GROUP BY a~kunnr b~vkbur c~pernr a~name1 a~name2 a~name3 a~name4
           a~stras a~ort01 a~pstlz.

But I want 2 columns for sales & 2 columns for cost, 1 for just KEN and 1 for all others.

Would I have to extract pstyv in my select statement and loop at the internal table to format them in the way I want?

Regards

Carly

Read only

Former Member
0 Likes
1,428

Yeah u need to extract PSTYV into ur itab .

once u secure

u can apply the conditions ..

regards

VIjay.