Posted: Mon Oct 22, 2007 10:14 am Post subject: Select с заранее неизвестными полями
Есть задача выбрать из таблицы knc1 поля umsav um01s um02s um03s umXXs в зависимости от заданного периода и просуммировать баланс. Как это правильнее сделать?
TABLES: knc1.
SELECT-OPTIONS:
s_kunnr FOR knc1-kunnr,
s_bukrs FOR knc1-bukrs,
s_gjahr FOR knc1-gjahr.
PARAMETER: p_poper TYPE poper DEFAULT 12.
DATA: it_knc1 TYPE TABLE OF knc1 WITH HEADER LINE.
DATA: balance TYPE knc1-umsav.
DATA: l_per(2) TYPE N.
DATA: FTAB(72) OCCURS 16 WITH HEADER LINE.
REFRESH FTAB.
FTAB = 'KUNNR'. APPEND FTAB.
FTAB = 'UMSAV'. APPEND FTAB.
FTAB = 'UM01S'.
DO p_poper TIMES.
ADD 1 TO l_per.
WRITE: l_per NO-GAP TO FTAB+2(2).
APPEND FTAB.
ENDDO.
SELECT (FTAB)
FROM knc1 INTO CORRESPONDING FIELDS OF TABLE it_knc1
WHERE kunnr IN s_kunnr
AND bukrs IN s_bukrs
AND gjahr IN s_gjahr.
IF sy-subrc IS INITIAL.
LOOP AT it_knc1.
CLEAR: balance.
ADD it_knc1-umsav FROM 1 TO p_poper GIVING balance.
WRITE: / it_knc1-kunnr, balance.
ENDLOOP.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.