๐Ÿ’ ์กฐ์ธ (JOIN) + ITAB, text table, DB View

ํ™์˜ˆ๋ฆผยท2023๋…„ 7์›” 20์ผ
0

SAP ABAP(๊ฐœํŽธ์ค‘...)

๋ชฉ๋ก ๋ณด๊ธฐ
33/55
post-thumbnail
  • ๋ฆด๋ ˆ์ด์…˜ ์„ค์ •๊ณผ JOIN์„ ์œ„ํ•ด ๊ฐ ํ…Œ์ด๋ธ”์˜ PK๋ฅผ ๋น„๊ตํ•œ๋‹ค.
  • PK๊ฐ€ ๊ฐ€์žฅ ์ ์€ ํ…Œ์ด๋ธ”์„ ์ฃผํ…Œ์ด๋ธ”๋กœ ์„ค์ •ํ•œ๋‹ค.
    • Key๊ฐ€ ์ ์€ ํ•„๋“œ๋ฅผ ํฌํ•จํ• ์ˆ˜๋ก ๋ฐ์ดํ„ฐ๋ฅผ ๋” ํฌ๊ด„์ ์œผ๋กœ ๋‹ด์„ ์ˆ˜ ์žˆ๋‹ค.

๐ŸŸขABAP

JOIN ~ ON ...

SELECT A.<ํ•„๋“œ> A.<ํ•„๋“œ>
	   B.<ํ•„๋“œ> B.<ํ•„๋“œ> B.<ํ•„๋“œ>
       C.<ํ•„๋“œ>
  FROM <์ฃผํ…Œ์ด๋ธ”> AS A
 INNER
  JOIN <์—ฐ๊ฒฐํ…Œ์ด๋ธ”1> AS B
    ON A~<A์™€B์˜๊ณตํ†ตPKํ•„๋“œ> = B~<A์™€B์˜๊ณตํ†ตPKํ•„๋“œ>
   AND <JOIN๋Œ€์ƒ์„ ์ •์กฐ๊ฑด๋ฌธ>

  JOIN <์—ฐ๊ฒฐํ…Œ์ด๋ธ”2> AS C
    ON B~<B์™€C์˜๊ณตํ†ตPKํ•„๋“œ1> = C~<B์™€C์˜๊ณตํ†ตPKํ•„๋“œ1>
   AND B~<B์™€C์˜๊ณตํ†ตPKํ•„๋“œ2> = C~<B์™€C์˜๊ณตํ†ตPKํ•„๋“œ2>
   
 WHERE <์กฐ๊ฑด๋ฌธ>
   AND <์กฐ๊ฑด๋ฌธ>.
  • ๋‘ ํ…Œ์ด๋ธ” ์‚ฌ์ด์— ๊ณตํ†ต๋œ PK ํ•„๋“œ ๋ชจ๋‘ JOIN ON์— AND๋กœ ๋ฆด๋ ˆ์ด์…˜์„ ์ž…๋ ฅํ•œ๋‹ค.
  • AS๋กœ ํ…Œ์ด๋ธ” ๋˜๋Š” ํ•„๋“œ์˜ ๋ณ„์นญ์„ ์„ค์ •ํ•œ๋‹ค. ์ž์„ธํ•œ ๊ฐœ๋…์€ SQL Alias๋ฅผ ์ฐธ๊ณ .

ABAP์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” JOIN

INNER ๐Ÿ†š OUTER

INNER JOINLEFT OUTER JOIN
์—ฐ์‚ฐANDOR
์—ฐ๊ฒฐ ๋Œ€์ƒITABTEXT Table
๊ฒฐ๊ณผ์ฃผํ…Œ์ด๋ธ”๊ณผ ์—ฐ๊ฒฐํ…Œ์ด๋ธ”์˜ ๊ต์ง‘ํ•ฉ์ฃผํ…Œ์ด๋ธ”๊ณผ ์—ฐ๊ฒฐํ…Œ์ด๋ธ”์˜ ํ•ฉ์ง‘ํ•ฉ
๋นˆ ๋ ˆ์ด๋ธ”์—†์Œ์—ฐ๊ฒฐํ…Œ์ด๋ธ”์—์„œ ๋ฐœ์ƒ
  • ์‚ฌ์šฉ์ž๊ฐ€ ์กฐํšŒ ์‹œ ์ฃผ ๋ฐ์ดํ„ฐ๋Š” ์™ผ์ชฝ์— ์œ„์น˜ํ•˜๋ฏ€๋กœ RIGHT JOIN์€ ๊ฑฐ์˜ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

๐Ÿ”– SELECTION-SCREEN ๊ณผ OUTER JOIN

  • ์ฃผํ…Œ์ด๋ธ”์˜ ํ•„๋“œ์ด๋ฉฐ ์…€๋ ‰์…˜ ์Šคํฌ๋ฆฐ์—์„œ SO ๋˜๋Š” PA๋กœ ์„ ์–ธ๋˜์—ˆ์ง€๋งŒ, ์—ฐ๊ฒฐํ…Œ์ด๋ธ”์—๋Š” ํ•„๋“œ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ.
  • INNER JOIN ์‹œ WHERE๋ฌธ์—์„œ ์…€๋ ‰์…˜ ์Šคํฌ๋ฆฐ์— ์„ ์–ธ๋œ ๋ชจ๋“  ๊ฐ์ฒด๋“ค์„ ์ž‘์„ฑํ•ด์•ผ ํ•˜๋ฉฐ, ์ด๋•Œ ์ž‘์„ฑ๋œ ๋ชจ๋“  ๊ฐ์ฒด๋“ค์€ ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅํ•ด์•ผํ•˜๋Š” ๋ฐ์ดํ„ฐ๋กœ ์—ฌ๊ฒจ์ง„๋‹ค.
    • ์…€๋ ‰์…˜์—์„œ ํ•„์ˆ˜์ž…๋ ฅ๊ฐ’์ธ ๊ฒฝ์šฐ
      : JOIN ON ์— <์…€๋ ‰์…˜> NE ''๋ฌธ์„ ๋„ฃ๋Š”๋‹ค.
    • ์…€๋ ‰์…˜์—์„œ ํ•„์ˆ˜์ž…๋ ฅ๊ฐ’์ด ์•„๋‹Œ ๊ฒฝ์šฐ
      : WHERE ์— ํ•ด๋‹น ์…€๋ ‰์…˜์˜ ์กฐ๊ฑด์„ ์ž…๋ ฅํ•˜์ง€ ์•Š๋Š”๋‹ค.
<* SELECTION SCREEN ์„ ์–ธ>
<* ITAB ์„ ์–ธ>

SELECT a~bukrs a~bstyp a~bsart a~lifnr a~ekorg a~ekgrp
       b~ebeln b~ebelp b~matnr b~ematn b~werks b~lgort b~menge b~meins b~netpr
       c~maktx d~maktg
  INTO CORRESPONDING FIELDS OF TABLE gt_po
  FROM ekko AS a
 INNER   <---------------- ์กฐ์ธ 1 ------>
  JOIN ekpo AS b
    ON a~ebeln EQ b~ebeln
  LEFT OUTER   <---------- ์กฐ์ธ 2 ------>
  JOIN makt AS c
    ON b~matnr EQ c~matnr
   AND c~spras EQ sy-langu
  LEFT OUTER
  JOIN makt AS d   <------ ์กฐ์ธ 3 ------>
    ON b~ematn EQ d~matnr
   AND d~spras EQ sy-langu
 WHERE a~bukrs EQ pa_bukr
   AND b~ebeln IN so_ebel
   AND a~bsart EQ pa_bsar.

Text Table์˜ JOIN

  • ์ฃผํ…Œ์ด๋ธ”์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ํ…Œ์ด๋ธ”์„ ํ…์ŠคํŠธ ํ…Œ์ด๋ธ” ์ด๋ผ๊ณ  ํ•œ๋‹ค.
  • ํ…์ŠคํŠธํ…Œ์ด๋ธ”์˜ ํ•„๋“œ ์ค‘์—๋Š” ์ฃผํ…Œ์ด๋ธ”์˜ ํŠน์ • ํ•„๋“œ๋ฅผ ์„ค๋ช…ํ•˜๋Š” Discribe ํ•„๋“œ๊ฐ€ ์žˆ์œผ๋ฉฐ, ๊ธ€๋กœ๋ฒŒ ํ”„๋กœ๊ทธ๋žจ์ธ SAP๋Š” ํ•„๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์–ธ์–ด ๋ณ„๋กœ ์ œ๊ณตํ•œ๋‹ค. ๋”ฐ๋ผ์„œ JOIN ์‹œ ์‚ฌ์šฉ์ž ์–ธ์–ด์— ํ•ด๋‹นํ•˜๋Š” ์ •๋ณด๋งŒ ๊ฐ€์ ธ์˜ค๋„๋ก ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด JOIN ํ›„ 1๊ฐœ์˜ ์ฃผํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด ์˜์–ด, ํ•œ๊ตญ์–ด, ๋…์ผ์–ด ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฒ„์ „์˜ ์„ค๋ช…์ด ์ „๋ถ€ ๋ณด์ด๋Š” ๋ฌธ์ œ์ ์ด ์ƒ๊ธด๋‹ค.

SPRAS = SY-langu

  • ์–ธ์–ด ์ฝ”๋“œ Language code
    • ๊ฐ ํ•„๋“œ๋งˆ๋‹ค ๋„๋ฉ”์ธ-ํ…์ŠคํŠธํ…Œ์ด๋ธ”-Language Key ํ•„๋“œ์— ์ž…๋ ฅ๋˜์–ด ์žˆ๋‹ค.
    • ๋™์ผํ•œ ๋„๋ฉ”์ธ์„ ์‚ฌ์šฉํ•˜๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ•„๋“œ๋Š” Language Key ํ•„๋“œ๊ฐ€ ๊ฐ™๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
  • ํ…์ŠคํŠธํ…Œ์ด๋ธ”์˜ SPRAS๊ฐ€ ์–ธ์–ด์ฝ”๋“œ๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” Key ํ•„๋“œ์ด๋‹ค.
  • sy-langu : ์‚ฌ์šฉ์ž์˜ ์‹œ์Šคํ…œ ์–ธ์–ด ์„ค์ •์„ ๋‹ด๋Š” ์‹œ์Šคํ…œ ๋ณ€์ˆ˜์ด๋‹ค.

ํ…์ŠคํŠธํ…Œ์ด๋ธ” ์ฐพ์•„ JOIN ์ฟผ๋ฆฌ๋ฌธ ์ž‘์„ฑํ•˜๊ธฐ

๐Ÿ”– ํ•œ ํ…์ŠคํŠธํ…Œ์ด๋ธ”๊ณผ ๋‹ค์‹œ ์กฐ์ธํ•˜๊ธฐ

  • ํ•„๋“œ์˜ Description์„ ์ฝ๊ณ  ๊ณตํ†ต ์ •๋ณด๋ฅผ ๋‹ด์€ ํ•„๋“œ๋ฅผ ์ฐพ์•„๋‚ธ ํ›„ JOIN ON ๋ฆด๋ ˆ์ด์…˜์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
SELECT a~bukrs a~bstyp a~bsart a~lifnr a~ekorg a~ekgrp
       b~ebeln b~ebelp b~matnr b~ematn b~werks b~lgort
       b~menge b~meins b~netpr c~maktx d~maktg
  INTO CORRESPONDING FIELDS OF TABLE gt_po
  FROM ekko AS a
 INNER
  JOIN ekpo AS b
    ON a~ebeln EQ b~ebeln
    
  LEFT OUTER
  JOIN makt AS c  <" ๊ฐ™์€ ํ…Œ์ด๋ธ” ์—ฌ๋Ÿฌ๋ฒˆ JOIN >
    ON b~matnr EQ c~matnr
   AND c~spras EQ sy-langu
   
  LEFT OUTER
  JOIN makt AS d  <" ๊ฐ™์€ ํ…Œ์ด๋ธ” ์—ฌ๋Ÿฌ๋ฒˆ JOIN >
    ON b~ematn EQ d~matnr <" ematn๋„ matnr์™€ ๊ฐ™์€ Material Number ์ด๋‹ค.>
 					      <" ๋”ฐ๋ผ์„œ ํ…์ŠคํŠธํ…Œ์ด๋ธ”์˜ ํ•„๋“œ๊ฐ€ ๊ฐ™๋‹ค.>
   AND d~spras EQ sy-langu.

๐ŸŸขGUI

๐Ÿ“ŒDatabase View

  • ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ…Œ์ด๋ธ”์„ ํ•œ ๋ฒˆ์— ๋ณด๊ณ ์ž ํ•  ๋•Œ, ๊ฐ ํ…Œ์ด๋ธ”์„ ์กฐ์ธํ•ด์„œ ํ•„์š”ํ•œ ํ•„๋“œ๋งŒ ๋ฝ‘์•„ ํ•œ ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“  ํ™”๋ฉด
    • ๋ทฐ์˜ ์ข…๋ฅ˜๋Š” 4๊ฐ€์ง€์ด๋‹ค.
  • ์ฃผ ํ…Œ์ด๋ธ”(Main Table)์€ PK ๋ฅผ ๊ฐ€์žฅ ์ ๊ฒŒ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ…Œ์ด๋ธ”.
  • ๋„ค์ด๋ฐ๋ฃฐ : Z ์ž์ฒด์ƒ์„ฑ + C5 ๋ชจ๋“ˆ + V ๋ทฐ + ...

DB View ๋งŒ๋“ค๊ธฐ

  • ์œ ์ง€๋ณด์ˆ˜๋ทฐ์™€ ๋‹ค๋ฅด๊ฒŒ ๋ฐ์ดํ„ฐ ์กฐํšŒ๋งŒ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ, ๋ฆด๋ ˆ์ด์…˜ ์„ค์ • ์‹œ ์ฃผํ…Œ์ด๋ธ”-์ฒดํฌํ…Œ์ด๋ธ”-ํ…์ŠคํŠธํ…Œ์ด๋ธ”์ด ์•„๋‹ˆ๋ผ ์ฃผํ…Œ์ด๋ธ”-ํ…์ŠคํŠธํ…Œ์ด๋ธ”๋กœ ๋ฐ”๋กœ ์—ฐ๊ฒฐ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

2๊ฐœ ํ…Œ์ด๋ธ”

Table/Join Conditions ํƒญ

์ง์ ‘ ํƒ€์ดํ•‘ํ•ด๋„ ๋˜์ง€๋งŒ, Realationships์„ ํ™œ์šฉํ•ด๋ณด์ž.
์—ฐ๊ฒฐํ•  ํ…Œ์ด๋ธ”๋ช… ์ž…๋ ฅ ํ›„, Realationships์„ ํด๋ฆญํ•ด ํ…Œ์ด๋ธ”์— ์—ฐ๊ฒฐ๋˜์–ด์žˆ๋Š” ํ…Œ์ด๋ธ” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋„์šด๋‹ค
CTRL+F ๋กœ ์›ํ•˜๋Š” ํ…Œ์ด๋ธ”์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ๋”๋ธ”ํด๋ฆญ
์ฐพ์€ ํ…Œ์ด๋ธ”์„ ์ฒดํฌํ•˜๊ณ  COPY ํด๋ฆญ
์ž๋™์œผ๋กœ ์กฐ์ธ ์กฐ๊ฑด์— ์ž…๋ ฅ๋œ๋‹ค


View Fields ํƒญ

  • ๋ทฐ์—์„œ ๋ณด๊ณ ์‹ถ์€ ํ•„๋“œ๋“ค์„ ๊ฐ ํ…Œ์ด๋ธ”์—์„œ ์„ ํƒํ•ด ๊ฐ€์ ธ์˜จ๋‹ค.
  • Table Fields ํด๋ฆญ.
  • ํ–‰์˜ ์ˆœ์„œ๋Š” ๋ณต๋ถ™์œผ๋กœ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

Selection Conditions ํƒญ

  • ํŠน์ • ์กฐ๊ฑด์„ ์ถฉ์กฑํ•˜๋Š” ๋ฐ์ดํ„ฐ๋งŒ ๋ณด๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ
    • ์˜ˆ์‹œ๋Š” CARRID๊ฐ€ AZ์ธ ๋ฐ์ดํ„ฐ๋งŒ ๋ณด์ด๋„๋ก ์„ค์ •.

์™„์„ฑ


3๊ฐœ ํ…Œ์ด๋ธ”

๊ฐ ํ…Œ์ด๋ธ”์˜ ๋””์Šคํ”Œ๋ ˆ์ด๋ฅผ ๋ชจ๋‘ ์—ด์–ด๋†“๋Š”๋‹ค. ์šฐ์„  2๊ฐœ๋ฅผ ์กฐ์ธํ•œ๋‹ค. 3๋ฒˆ์งธ ํ…Œ์ด๋ธ”๊ณผ ์กฐ์ธํ•  ๋•Œ, ์•ž์„œ ๋จผ์ € ์กฐ์ธ๋œ 2๊ฐœ์˜ ํ…Œ์ด๋ธ” ์ค‘ 3๋ฒˆ์งธ ํ…Œ์ด๋ธ”๊ณผ Primery Key ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์ด ๊ฒน์น˜๋Š” ํ…Œ์ด๋ธ” ํ•œ ๊ฐœ๋ฅผ ๊ณจ๋ผ ์กฐ์ธํ•œ๋‹ค.

  • PK ์ˆ˜๊ฐ€ ์ ๋‹ค๋Š” ๊ฒƒ์€ ๊ทธ๋งŒํผ ํฌ๊ด„์ ์ธ ํ…Œ์ด๋ธ”์ด๋ผ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

Table/Join Conditions ํƒญ

  • Primery Key ๊ฐ€ ๊ฐ€์žฅ ๋งŽ์ด ๊ฒน์น˜๋Š” ํ…Œ์ด๋ธ”๊ณผ ์กฐ์ธํ•œ๋‹ค.

  • ๋ทฐํ•„๋“œ์™€ ์…€๋ ‰์…˜ ์ปจ๋””์…˜์€ ์œ„์™€ ๋™์ผํ•˜๊ฒŒ ์ง„ํ–‰ํ•˜๋ฉด ๋œ๋‹ค.


์™„์„ฑ

profile
SYNC 3๊ธฐ 5๋ฐ˜ 2023.07 - 2023.12

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 20์ผ

์ข‹์€ ๊ธ€ ์ž˜ ์ฝ์—ˆ์Šต๋‹ˆ๋‹ค, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ