Enhcnaced SQL

 Case Statement

"disbable returns which are have active audit case, @field selectable, and pre select eligible returns @a_chkbox

  CONSTANTS: lc_check      TYPE boolean VALUE abap_true,
             lc_uncheck    TYPE boolean VALUE abap_false,                                        lc_open       TYPE fbsta_ps VALUE 'IP014',
             lc_no_case    TYPE fbsta_ps   VALUE IS INITIAL.

  SELECT taxpayer AS a_tp_tin,
         rt_fbnum  AS a_rt_fbnum ,
    CASE a_case_status
        WHEN @lc_open THEN @lc_check
        WHEN @lc_no_case THEN @lc_check
                  END AS a_chkbox,
          risk_score  AS a_risk_score,
          rev_type    AS a_rev_type,
          taxp_name   AS a_rt_taxp_name,
          rt_period   AS a_rt_period,
          rt_fromdate AS a_rt_fromdate,
          rt_todate   AS a_rt_todate,
          rt_duedate  AS a_rt_duedate,
          bu_activity AS a_bu_activity,
          ad_case_id,
          ad_case_status,
          rt_period_text AS a_rt_period_txt,
          a_audit_case,
          a_case_status,
          a_case_status_text,
          a_bu_actvt_desc,
    CASE a_case_status
      WHEN @lc_open THEN @lc_uncheck
      WHEN @lc_no_case THEN @lc_uncheck
        ELSE @lc_check
          END AS a_selectable
    FROM  @lt_return_plan AS return

    INTO TABLE @DATA(lt_return).

In the above scenario, cases with IP Status 'IP014' or no status are autoselected placed in field A_CHECK. At the same time,  the ALV fields readonly attribute is bond to A_SELECTABLE. So if the status is IP014 or blank then the line item is not read only, i.e it is available for selection. 

Sum( ) & Group By Clause

SELECT sf~carrid,
       sf~connid,
  SUM( sf~price ) AS cost
  FROM sflight AS sf
  INNER JOIN sbook AS sb
  ON sf~carrid = sb~carrid
  INTO TABLE @DATA(lt_final)
  GROUP BY sf~carrid,  sf~connid.

 The fields before the SUM function should be in the group by clause. 

UNION


SELECT 'I' AS mark, carrid, connid, fldate, seatsocc
  FROM sflight
  WHERE carrid = @( to_upper( carrid ) )
UNION SELECT 'T' AS mark,
                    carrid,
                    connid,
                    CAST( '00000000' AS DATS ) AS fldate,
                    SUM(  seatsocc ) AS seatsocc
                    FROM sflight
       WHERE carrid = @( to_upper( carrid ) )
       GROUP BY carrid, connid
       ORDER BY carrid, connid, mark, fldate, seatsocc
        INTO TABLE @DATA(lt_result).


Output






Comments

Popular posts from this blog

CDS Views