SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Select с заранее неизвестными полями



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
den
Старший специалист
Старший специалист



Joined: 11 Oct 2007
Posts: 103

PostPosted: Mon Oct 22, 2007 10:14 am    Post subject: Select с заранее неизвестными полями Reply with quote

Есть задача выбрать из таблицы knc1 поля umsav um01s um02s um03s umXXs в зависимости от заданного периода и просуммировать баланс. Как это правильнее сделать?
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Oct 22, 2007 2:48 pm    Post subject: Reply with quote

Например, так:

Code:

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.