메뉴 건너뛰기

SAP 한국 커뮤니티

collect 구문

sapjoy 2006.12.03 12:35 조회 수 : 27038 추천:33

COLLECT


Basic form
COLLECT [wa INTO] itab.

Addition


... SORTED BY f

Effect
COLLECT is used to create unique or compressed datsets. The key fields are the default key fields of the internal table itab .

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

Notes
COLLECT can create unique or compressed datasets and should be used precisely for this purpose. If uniqueness or compression are unimportant, or two values with identical default key field values could not possibly occur in your particular task, you should use APPEND instead. However, for a unique or compressed dataset which is also efficient, COLLECT is the statement to use.
If you process a table with COLLECT , you should also use COLLECT to fill it. Only by doing this can you guarantee that

the internal table will actually be unique or compressed, as described above and

COLLECT will run very efficiently.

If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.

Example
Compressed sales figures for each company


DATA: BEGIN OF COMPANIES OCCURS 10,
        NAME(20),
        SALES TYPE I,
      END   OF COMPANIES.
COMPANIES-NAME = 'Duck'.  COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'.  COMPANIES-SALES = 30.
COLLECT COMPANIES.


The table COMPANIES now has the following appearance:

NAME SALES

Duck 40

Tiger 20



Addition
... SORTED BY f

Effect
COLLECT ... SORTED BY f is obsolete and should no longer be used. Use APPEND ... SORTED BY f which has the same meaning.

Note
Performance

The cost of a COLLECT in terms of performance increases with the width of the default key needed in the search for table entries and the number of numeric fields with values which have to be added up, if an entry is found in the internal table to match the default key fields.
If no such entry is found, the cost is reduced to that required to append a new entry to the end of the table.

A COLLECT statement used on a table which is 100 bytes wide and has a key which is 60 bytes wide and seven numeric fields is about approx. 50 msn (standardized microseconds).

Note
Runtime errors

COLLECT_OVERFLOW : Overflow in integer field when calculating totals.


COLLECT_OVERFLOW_TYPE_P : Overflow in type P field when calculating totals.
번호 제목 글쓴이 날짜 조회 수
27 SAP GUI WINDOW TITLE BAR 정보 표시 설정 방법 / 색상 설정 [15] file 미소 2010.12.26 13452
26 텍스트파일 다운받을때 유니코드 문제 해결 [8] file 솔로몬 2007.06.28 13798
25 <img src=b.gif>Windows 7 에서 SAP GUI ALV 반응느림 해결방법 공유 (GUI720 기준)[추천:e-abap][추천:유리선율][추천:보나] [17] 점점 2010.07.02 14783
24 Dynamic Internal Table 생성 꿀꿀윤뚱67 2019.11.27 14857
23 BAPI_GOODSMVT_CREATE 입고/출고/재고이동시에 사용하세요. [5] 노름마치 2007.12.10 15107
22 Abap Dump Top 10 [5] 양키 2013.01.14 15746
21 data [2] sapjoy 2006.12.03 16722
20 프로그램 정보(프로그램 리스트, PROGRAM LIST, PROGRAM TABLE) [3] sapjoy 2007.02.23 16847
19 SYST 시스템 변수 정리 [5] 아밥뽀 2014.08.23 17014
18 FOR ALL ENTRIES IN 구문 사용시 select 필드 선택시 주의사항. [7] 나침반친구 2007.03.13 17035
17 ABAP 구문 총정리 [39] file Wise 멘토 2008.11.24 17171
16 인터널 테이블 라인수 lines [8] sapjoy 2014.01.20 17274
15 ABAP 핵심정리 [23] SARA 2007.03.14 17340
14 ALV LIST 진행시 LAYOUT 속성값 [18] kwon09 2007.04.11 17365
13 SDN -> SCN 변경되면서 Contents별로 바뀐 LINK 모음 [13] Wise 멘토 2012.07.06 19045
12 숫자입력 체크(Numeric character check) [1] 양키(이경환) 2014.01.28 19639
11 LIKE와 TYPE의 차이 [13] sapjoy 2006.12.06 19723
10 문자열에 있는 값이 숫자만으로 되어있는지 문자가 포함됐는지 체크하는 함수 [3] 꿀단지 2011.10.11 19907
9 SELECT statement D.Y.Kim 2007.07.20 23647
8 BAPI_PR_CREATE 구매요청 생성시에 사용하세요 [2] 노름마치 2007.12.10 23707