*&---------------------------------------------------------------------*
*& Report ZLQT_SQL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLQT_SQL.
SELECT BUKRS ,
BELNR ,
GJAHR ,
BUZEI ,
CASE WHEN SHKZG = 'S'THEN DMBTR ELSE 0 END AS JFJE , "借贷标识是S金额放在借方
CASE WHEN SHKZG = 'H'THEN DMBTR ELSE 0 END AS DFJE "借贷标识是H金额放在贷方
FROM BSEG
INTO TABLE @DATA(LT_BSEG)
UP TO 10 ROWS .
DATA ALV TYPE REF TO CL_SALV_TABLE.
TRY.
CL_SALV_TABLE=>FACTORY(
IMPORTING R_SALV_TABLE = ALV
CHANGING T_TABLE = LT_BSEG ).
ALV->DISPLAY( ).
CATCH CX_SALV_MSG.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
运行结果如下
在需要判断情况来取不同的值的时候,如果不想在内表中处理,可以在sql中用CASE WHEN处理,上面的代码意思是如果借贷标识为S金额字段存到借方金额,如果借贷标识是H金额存到贷方金额