Sorted Internal Table

Sorted table is another kind of index table which has unique / non unique key. It also can be accessed via index or key. For sorted table the key must be specified. The declaration is as follows:

DATA: it_mat TYPE SORTED TABLE OF ty_mat WITH UNIQUE KEY matnr,
it_mat TYPE SORTED TABLE OF ty_mat WITH NON-UNIQUE KEY matnr.

Unique key means the MATNR (material no) will must be unique. If same material number is inserted then a run time error will happen. However we can declare the sorted table with non unique key also. In this case same material number can be entered but it will be sorted after entering the number. Here the sorted table behaves similar to sorted standard table. We use INSERT statement to enter any records to the sorted table.

INSERT wa_mat INTO TABLE it_mat.

Here is an example of sorted table by using unique key concept.
REPORT  zabap_gui.

* Declaring the local structure of internal table
TYPES:
      BEGIN OF ty_tab,
        item     TYPE char10,
        quantity TYPE i,
        price    TYPE i,
      END OF ty_tab.

* Declaring the Sorted internal table with non unique key
DATA:
      itab TYPE SORTED TABLE OF ty_tab WITH UNIQUE KEY item,
      wtab TYPE ty_tab.

* Entering records to each field
wtab-item = 'Rice'. wtab-quantity = 2. wtab-price = 80.

* Now one single row has been fulfilled with data
* Next inserting one single row data into the table
INSERT wtab INTO TABLE itab.

wtab-item = 'Suger'. wtab-quantity = 1. wtab-price = 90.
INSERT wtab INTO TABLE itab.

wtab-item = 'Tea'. wtab-quantity = 1. wtab-price = 100.
INSERT wtab INTO TABLE itab.

wtab-item = 'Rice'. wtab-quantity = 3. wtab-price = 150.
INSERT wtab INTO TABLE itab.

wtab-item = 'Horlicks'. wtab-quantity = 1. wtab-price = 200.
INSERT wtab INTO TABLE itab.

wtab-item = 'Suger'. wtab-quantity = 2. wtab-price = 70.
INSERT wtab INTO TABLE itab.

WRITE:  /3 'Item',
        13 'Quantity (KG)',
        28 'Price (Rs)'.
WRITE / '=========================================='.
SKIP" Skipping one single line

LOOP AT itab INTO wtab.

  WRITE:  /3 wtab-item,
          12 wtab-quantity,
          25 wtab-price.
ENDLOOP.

SKIP.
WRITE '=========================================='.


















Since the key is unique the similar entries are ignored by the system.

Here is an example of sorted table by using non unique key concept.

REPORT  zabap_gui.

* Declaring the local structure of internal table
TYPES:
      BEGIN OF ty_tab,
        item     TYPE char10,
        quantity TYPE i,
        price    TYPE i,
      END OF ty_tab.

* Declaring the Standard internal table with non unique key
DATA:
      itab TYPE SORTED TABLE OF ty_tab WITH NON-UNIQUE KEY item,
      wtab TYPE ty_tab.

* Entering records to each field
wtab-item = 'Rice'. wtab-quantity = 2. wtab-price = 80.

* Now one single row has been fulfilled with data
* Next inserting one single row data into the table
INSERT wtab INTO TABLE itab.

wtab-item = 'Suger'. wtab-quantity = 1. wtab-price = 90.
INSERT wtab INTO TABLE itab.

wtab-item = 'Tea'. wtab-quantity = 1. wtab-price = 100.
INSERT wtab INTO TABLE itab.

wtab-item = 'Rice'. wtab-quantity = 3. wtab-price = 150.
INSERT wtab INTO TABLE itab.

wtab-item = 'Horlicks'. wtab-quantity = 1. wtab-price = 200.
INSERT wtab INTO TABLE itab.

wtab-item = 'Suger'. wtab-quantity = 2. wtab-price = 70.
INSERT wtab INTO TABLE itab.

WRITE:  /3 'Item',
        13 'Quantity(KG)',
        28 'Price(Rs)'.
WRITE / '=========================================='.
SKIP" Skipping one single line

LOOP AT itab INTO wtab.

  WRITE:  /3 wtab-item,
          12 wtab-quantity,
          25 wtab-price.
ENDLOOP.

SKIP.
WRITE '=========================================='.



'SAP Program > ABAP' 카테고리의 다른 글

병렬처리 예제  (0) 2018.04.18
권한 check & is supplied  (0) 2018.04.05
amount를 currency에 맞게 conversion input/output  (0) 2018.03.21
Number range 관련 재미있는 coding  (0) 2018.02.20
Dialog 화면에서 debugging  (0) 2018.02.06

설정

트랙백

댓글

CURRENCY_AMOUNT_DISPLAY_TO_SAP 이 펑션을 태우면


USD인경우  1을     반환하고


KRW인경우  0.01을 반환합니다.


 


CURRENCY_AMOUNT_SAP_TO_IDOC 이 펑션을 태우면


USD는 1.00D을 반환하고


KRW는 100을 반환합니다.



예를 들어 excel로 금액을 입력받아 DB에 저장해야 하는 경우에


Excel 작성자는 currency에 상관없이 1000원이면 1000으로 excel에 입력하지만


DB에 입력될때는 currency를 감안하여 저장해야 하기 때문에


CURRENCY_AMOUNT_DISPLAY_TO_SAP  이 펑션을 사용해서 금액을 currency에 맞게 변환한 후


DB에 저장하면 됩니다.


excel에 1000으로 입력되어 있고, 저장될 currency가 KRW일 경우 실제 DB에는 10으로 저장이 됩니다.

'SAP Program > ABAP' 카테고리의 다른 글

권한 check & is supplied  (0) 2018.04.05
sorted table 선언  (0) 2018.03.23
Number range 관련 재미있는 coding  (0) 2018.02.20
Dialog 화면에서 debugging  (0) 2018.02.06
LEAVE LIST-PROCESSING  (0) 2018.02.02

설정

트랙백

댓글

바탕화면

지니꺼 2018. 2. 22. 16:50

Wallpaper_lt.z01

Wallpaper_lt.z02

Wallpaper_lt.z03

Wallpaper_lt.z04

Wallpaper_lt.z05

Wallpaper_lt.z06

Wallpaper_lt.z07

Wallpaper_lt.z08

Wallpaper_lt.z09

Wallpaper_lt.z10

Wallpaper_lt.z11

Wallpaper_lt.z12

Wallpaper_lt.z13

Wallpaper_lt.zip


'지니꺼' 카테고리의 다른 글

abap Text 언어 변환 프로그램  (0) 2017.08.22
스타크래프트 무료 받는곳  (0) 2017.04.20
gva 2000 student 2355  (0) 2017.04.14
sap online help document  (0) 2017.04.06
XML Viewer  (0) 2017.03.03

설정

트랙백

댓글