ABAP——动态SQL
时间:2021-07-01 10:21:17
帮助过:4人阅读
***********************************************************************
* Program Name :
* Descriptions :
* T-Code :
* Updates Tables :
* Input Parameters :
* Output Parameters :
* Return Codes :
* Special Logic :
* Includes :
************************************************************************
* Modification Log
************************************************************************
* Date Ver. Programmer Descriptions
* -------- ---- ------------ -------------------------------------------
* 2020 3.9 xxx Create
*
************************************************************************
REPORT ZPPRTEST.
***********************************************************************
* Tables Definitions
************************************************************************
*TABLES:.
************************************************************************
* Data Definitions
************************************************************************
************************************************************************
* Includes Module
************************************************************************
************************************************************************
* Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1
WITH FRAME TITLE
TEXT-
b01.
PARAMETERS: p_num(
2)
TYPE n DEFAULT
‘6‘ OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
************************************************************************
* Initialization
************************************************************************
INITIALIZATION.
************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN.
************************************************************************
* At Selection Screen Output
************************************************************************
AT SELECTION-SCREEN OUTPUT.
************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.
END-OF-PAGE.
************************************************************************
* Main Process
************************************************************************
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
FORM get_data.
DATA: l_vgw
LIKE plpo-
vgw01,
l_sql(500)
TYPE c,
l_num TYPE i,
l_numc TYPE String.
* l_sql = ‘SUM( plpo~vgw01 + plpo~vgw02 )‘.
DO p_num
TIMES.
l_num = l_num +
1.
l_numc =
l_num.
IF l_num <
9.
CONCATENATE l_sql
‘ plpo~vgw0‘ l_numc
‘+‘ INTO l_sql.
ELSE.
CONCATENATE l_sql
‘ plpo~vgw‘ l_numc
‘+‘ INTO l_sql.
ENDIF.
ENDDO.
"去掉末尾+
l_sql = SUBSTRING( VAL = l_sql LEN = STRLEN( l_sql ) -
1 ) .
CONCATENATE ‘SUM(‘ l_sql
‘ )‘ INTO l_sql.
SELECT (l_sql)
INTO @l_vgw
FROM plpo
INNER JOIN plas ON plpo~plnnr =
plas~plnnr
AND plpo~plnkn =
plas~plnkn
WHERE plas~loekz =
@space
AND plpo~plnnr =
‘50033934‘
AND plpo~vornr =
‘0040‘.
ENDSELECT.
* SELECT SUM( plpo~vgw01 + plpo~vgw02 ) INTO @l_vgw
* FROM plpo
* INNER JOIN plas ON plpo~plnnr = plas~plnnr
* AND plpo~plnkn = plas~plnkn
* WHERE plas~loekz = @space
* AND plpo~plnnr = ‘50033934‘
* AND plpo~vornr = ‘0040‘.
cl_demo_output=>
write( l_sql ).
cl_demo_output=>
write( l_vgw ).
cl_demo_output=>
display( ).
ENDFORM.
"GET_DATA
ABAP——动态SQL
标签:output create -o upd update parameter star color string