๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿง‘‍๐Ÿ’ผ SAP/ABAP

[SAP ABAP] MOVE TO ๋ž€? MOVE-CORRESPONDING ๋ž€? (์˜ˆ์ œ ํฌํ•จ)

by Jay Din 2023. 12. 5.
728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

1. MOVE์™€ MOVE-CORRESPONDING

ABAP/4 ์—์„œ๋Š” ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ฑฐ๋‚˜ ์‹ค์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ฒ˜๋ฆฌ๋˜๋Š” ๊ตฌ๋ฌธ์—์„œ Data Object ์— ๊ฐ’์„ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•  ๋•Œ VALUE ๊ตฌ๋ฌธ์„ ํ†ตํ•˜์—ฌ ์ดˆ๊นƒ๊ฐ’์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๊ณ , ์‹ค์ œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ๊ตฌ๋ฌธ ๋‚ด์—์„œ๋Š” MOVE ๋˜๋Š” WRITE TO ๊ตฌ๋ฌธ์„ ์ด์šฉํ•˜์—ฌ ๋ถ„์‚ฌ์— ๊ฐ’์„ ํ• ๋‹นํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

<f2> = <f1>.
MOVE <f1> TO <f2>.
MOVE-CORRESPONDING <STRING1> TO <STRING2>.
WRITE <f1> TO <f2> [<option>].

 

2. MOVE ๋ž€?

MOVE๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ํ•œ ๋ณ€์ˆ˜์—์„œ ๋‹ค๋ฅธ ๋ณ€์ˆ˜๋กœ ์ง์ ‘ ๋ณต์‚ฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.๋ฐ์ดํ„ฐ๋ฅผ ํ• ๋‹นํ•  ๋•Œ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜๊ณผ ๊ธธ์ด ์กฐ์ •์ด ์ž๋™์œผ๋กœ ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํŠน์ง•

  1. ๊ฐœ๋ณ„ ๋ณ€์ˆ˜ ๊ฐ„์˜ ๊ฐ’ ๋ณต์‚ฌ
    • MOVE๋Š” ๋ณ€์ˆ˜ ๊ฐ„์˜ ๊ฐ’ ๋ณต์‚ฌ์— ์‚ฌ์šฉ๋˜๋ฉฐ, ๊ตฌ์กฐ์ฒด๋‚˜ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ๊ฐ„์˜ ๋ณต์‚ฌ๋Š” ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  2. ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜
    • ๋ฐ์ดํ„ฐ ์œ ํ˜•์ด ๋‹ค๋ฅด๋”๋ผ๋„ MOVE๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค.
    • ์˜ˆ: ์ •์ˆ˜ํ˜•์—์„œ ๋ฌธ์ž์—ดํ˜•์œผ๋กœ ๋ณ€ํ™˜ ์‹œ, ๊ฐ’์ด ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜๋จ.
  3. ๋ช…์‹œ์  ํ• ๋‹น
    • ๋ณต์‚ฌํ•  ๋Œ€์ƒ๊ณผ ์›๋ณธ์„ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

 

MOVE ์‚ฌ์šฉ ์˜ˆ์ œ

DATA: source_variable TYPE i,      " ์ •์ˆ˜ํ˜• ๋ณ€์ˆ˜ ์„ ์–ธ
      destination_variable TYPE i. " ์ •์ˆ˜ํ˜• ๋ณ€์ˆ˜ ์„ ์–ธ

source_variable = 10.            " ๊ฐ’์„ ํ• ๋‹น

MOVE source_variable TO destination_variable. " ๊ฐ’ ๋ณต์‚ฌ

WRITE: / 'Source Variable:', source_variable,
       / 'Destination Variable:', destination_variable.

์‹คํ–‰ํ™”๋ฉด

 

์˜ˆ์ œ ์„ค๋ช…

  1. source_variable ์ด๋ผ๋Š” ์ •์ˆ˜ํ˜• ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ฐ’์„ 10์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  2. MOVE ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ source_variable ์˜ ๊ฐ’์„ destination_variable ๋กœ ์ด๋™์‹œํ‚ต๋‹ˆ๋‹ค.
  3. ์ด ์˜ˆ์ œ์—์„œ๋Š” source_variable ์— ํ• ๋‹น๋œ ๊ฐ’์ด 10์ด destination_variable ๋กœ ๋ณต์‚ฌ๋˜์–ด, ๋‘ ๋ณ€์ˆ˜๋Š” ๋™์ผํ•œ ๊ฐ’์„ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ฃผ์˜ ํ•ด์•ผ ํ•  ์ค‘์š”ํ•œ ์ ์€ MOVE ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ABAP์€ ์ž๋™์œผ๋กœ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ฆ‰, ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๊ฐ„์—๋„ MOVE ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ’์„ ์ด๋™์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋ฐ์ดํ„ฐ ์œ ํ˜•์ด ๋‹ค๋ฅธ ๊ฐ’ MOVE ์˜ˆ์‹œ

i_int ๋Š” i(์ •์ˆ˜) ํƒ€์ž…์ด๊ณ , s_str ์€ string(๋ฌธ์ž์—ด) ํƒ€์ž…์ž…๋‹ˆ๋‹ค.

i_int ์— 10์„ ํ• ๋‹นํ•œ ํ›„, s_str ์— ๊ฐ’์„ ํ• ๋‹นํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

DATA: i_int TYPE i,
      s_str TYPE string.

i_int = 10.

MOVE i_int TO s_str.

WRITE: / 'i_int: ', i_int,
      / 's_str:', s_str.

์‹คํ–‰ํ™”๋ฉด

 

์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๊ฐ„์—๋„ ์ž๋™์œผ๋กœ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ๋ณ€ํ™˜ํ•˜์—ฌ ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

 

3. MOVE-CORRESPONDING ๋ž€?

MOVE-CORRESPONDING ์€ ๋‘ ๊ตฌ์กฐ์ฒด(Structure) ๋˜๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ๊ฐ„์— ํ•„๋“œ ์ด๋ฆ„์ด ๋™์ผํ•œ ๊ฒฝ์šฐ ํ•ด๋‹น ํ•„๋“œ๋“ค ๊ฐ„์— ๊ฐ’์„ ๋ณตํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.

 

ํŠน์ง•

  1. ํ•„๋“œ ์ด๋ฆ„ ๊ธฐ๋ฐ˜ ๋ณต์‚ฌ
    • ๊ตฌ์กฐ์ฒด๋‚˜ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์—์„œ ํ•„๋“œ ์ด๋ฆ„์ด ๋™์ผํ•œ ํ•„๋“œ๋งŒ ๋ณต์‚ฌ๋ฉ๋‹ˆ๋‹ค.
    • ํ•„๋“œ ์ด๋ฆ„์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ ๊ฐ’์ด ๋ณต์‚ฌ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  2. ์„ ํƒ์  ๋ณต์‚ฌ
    • ๋™์ผํ•œ ์ด๋ฆ„์˜ ํ•„๋“œ๋งŒ ์ž๋™ ๋งคํ•‘๋˜๋ฏ€๋กœ, ๋ณต์‚ฌ ๋Œ€์ƒ ํ•„๋“œ๊ฐ€ ์ œํ•œ์ ์ž…๋‹ˆ๋‹ค.
  3. ๊ตฌ์กฐ์ฒด ๊ฐ„ ๋ณต์‚ฌ
    • ํ•œ ๊ตฌ์กฐ์ฒด์—์„œ ๋‹ค๋ฅธ ๊ตฌ์กฐ์ฒด๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์‰ฝ๊ฒŒ ์ด๋™ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  4. ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜ ์ง€์›
    • MOVE์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜์ด ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

 

MOVE-CORRESPONDING  ์‚ฌ์šฉ ์˜ˆ์ œ

DATA: BEGIN OF SOURCE_STRUCTURE,
        FIELD1 TYPE I,
        FIELD2 TYPE STRING,
      END OF SOURCE_STRUCTURE,

      BEGIN OF DESTINATION_STRUCTURE,
        FIELD1 TYPE I,
        FIELD2 TYPE STRING,
      END OF DESTINATION_STRUCTURE.

SOURCE_STRUCTURE-FIELD1 = 100.
SOURCE_STRUCTURE-FIELD2 = 'ABAP Move-Corresponding Example'.

MOVE-CORRESPONDING SOURCE_STRUCTURE TO DESTINATION_STRUCTURE.

WRITE: / 'Source Structure:',  SOURCE_STRUCTURE-FIELD1, ',', SOURCE_STRUCTURE-FIELD2,
       / 'Destination Structure:', DESTINATION_STRUCTURE-FIELD1, ',', DESTINATION_STRUCTURE-FIELD2.

์‹คํ–‰ํ™”๋ฉด

์˜ˆ์ œ ์„ค๋ช…

  1. ๋‘ ๊ฐœ์˜ ๊ตฌ์กฐ์ฒด( source_structure ์™€ destination_structure )๋ฅผ ์ •์˜ํ•˜๊ณ  ๊ฐ๊ฐ์˜ ํ•„๋“œ์— ๊ฐ’์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.
  2. MOVE-CORRESPONDING ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ source_structure ์˜ ๊ฐ’์„ destination_structure ์— ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ๋ฐฉ์‹์œผ๋กœ ๊ตฌ์กฐ์ฒด๋‚˜ ํ…Œ์ด๋ธ” ๋ผ์ธ์˜ ํ•„๋“œ ์ด๋ฆ„์ด ์ผ์น˜ํ•  ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ๊ฐ’์ด ๋ณต์‚ฌ๋˜๋ฏ€๋กœ ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

MOVE_CORRESPONDING ๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜ ์˜ˆ์ œ

๊ตฌ์กฐ์ฒด GS_REN ๊ณผ GS_INFO ๋Š” ํ•„๋“œ ๊ตฌ์กฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

GS_REN ๊ตฌ์กฐ์ฒด์—์„œ GS_INFO ๊ตฌ์กฐ์ฒด๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ํ• ๋‹นํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” MOVE GS_REN-NAME TO GS_INFO-NAME. ๊ณผ ๊ฐ™์€ ๊ตฌ๋ฌธ์„ ์—ฌ๋Ÿฌ ๋ฒˆ ์‚ฌ์šฉํ•˜์—ฌ์•ผ ํ•˜๋‚˜ MOVE-CORRESPONDING ๊ตฌ๋ฌธ์œผ๋กœ ํ•œ๋ฒˆ์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

MOVE-CORRESPONDING์€ ํ•„๋“œ๋ช…์ด ๊ฐ™์€ ๊ฐ’๋งŒ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

REPORT ZABAP001 .

DATA : BEGIN OF GS_REN,
  NAME(20)  VALUE 'Jay Din',
  CITY(20)  VALUE'SEOUL',
  COUNTRY(10) VALUE 'KOREA',
  END OF GS_REN.

DATA : BEGIN OF GS_INFO,
  NAME(20),
  CITY(20),
  PHONE(10) VALUE '1521001234',
  END OF GS_INFO.

MOVE-CORRESPONDING GS_REN TO GS_INFO.
WRITE: / GS_INFO-NAME, GS_INFO-CITY, GS_INFO-PHONE.
๋ฐ˜์‘ํ˜•

 

์‹คํ–‰๊ฒฐ๊ณผ

 

gs_ren์ด gs_info๋กœ ๊ฐ’์„ ๋ณต์‚ฌํ•  ๋•Œ,

gs_info์˜ ํ•„๋“œ๋ช…์ด ๊ฐ™์€ name, city ๊ฐ’๋งŒ ๋ณต์‚ฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

4. MOVE์™€ MOVE-CORRESPONDING์˜ ๋น„๊ตํ‘œ

๊ตฌ๋ถ„ MOVE ๊ตฌ๋ฌธ MOVE-CORRESPONDING ๊ตฌ๋ฌธ
๊ธฐ๋ณธ ๊ฐœ๋… ํ•œ ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ๋‹ค๋ฅธ ๋ณ€์ˆ˜์— ๋ณต์‚ฌ ๋™์ผํ•œ ํ•„๋“œ๋ช…์„ ๊ฐ€์ง„ ๋‘ ๊ตฌ์กฐ์ฒด ๊ฐ„ ๊ฐ’ ๋ณต์‚ฌ
์šฉ๋„ ๋‹จ์ผ ๋ณ€์ˆ˜ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ ์ด๋™ ๊ตฌ์กฐ์ฒด ๋˜๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ” ๊ฐ„ ๋ฐ์ดํ„ฐ ์ด๋™
๋ณต์‚ฌ ๋Œ€์ƒ ๊ฐœ๋ณ„ ๋ณ€์ˆ˜ ๊ตฌ์กฐ์ฒด๋‚˜ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”
ํ•„๋“œ ๋งคํ•‘ ์ง์ ‘ ์ง€์ •๋œ ๋ณ€์ˆ˜์— ๊ฐ’ ๋ณต์‚ฌ ๋™์ผํ•œ ์ด๋ฆ„์˜ ํ•„๋“œ๋งŒ ์ž๋™์œผ๋กœ ๋งคํ•‘๋˜์–ด ๋ณต์‚ฌ
์ž‘๋™ ๋ฐฉ์‹ ์™ผ์ชฝ ๋ณ€์ˆ˜์— ์˜ค๋ฅธ์ชฝ ๋ณ€์ˆ˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ ๊ตฌ์กฐ์ฒด์˜ ๋™์ผ ํ•„๋“œ๋ผ๋ฆฌ ๋ณต์‚ฌ
๋ฐ์ดํ„ฐ ์œ ํ˜• ๋ณ€ํ™˜ ์ง€์› ์ง€์›
์œ ์—ฐ์„ฑ ๋ชจ๋“  ํ•„๋“œ ๋˜๋Š” ๋‹จ์ผ ํ•„๋“œ ๋ณต์‚ฌ ๊ฐ€๋Šฅ ํ•„๋“œ ์ด๋ฆ„์ด ๋™์ผํ•œ ํ•„๋“œ๋งŒ ์„ ํƒ์ ์œผ๋กœ ๋ณต์‚ฌ
์ฃผ์š” ์‚ฌ์šฉ ์‹œ๋‚˜๋ฆฌ์˜ค ๊ฐœ๋ณ„ ๋ณ€์ˆ˜ ๊ฐ„ ๊ฐ’ ์ด๋™ ๊ตฌ์กฐ์ฒด๋‚˜ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์˜ ๊ณตํ†ต ํ•„๋“œ ๋ณต์‚ฌ
์„ฑ๋Šฅ ์ผ๋ฐ˜์ ์œผ๋กœ ๋น ๋ฆ„ ๋ณต์‚ฌ ๋Œ€์ƒ ํ•„๋“œ๋ฅผ ํƒ์ƒ‰ํ•ด์•ผ ํ•˜๋ฏ€๋กœ ์•ฝ๊ฐ„ ๋Š๋ฆผ

 

5. ์ถ”๊ฐ€ ๋ฌธ๋ฒ•: INTO CORRESPONDING FIELDS OF

ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’ ๋ณต์‚ฌ INTO CORRESPONDING FIELDS OF ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด?

https://jay-din.tistory.com/248

 

[SAP ABAP] INTO CORRESPONDING FIELDS OF ๋ž€? (์˜ˆ์ œ ํฌํ•จ)

INTO CORRESPONDING FIELDS OF ๋ž€? ABAP์—์„œ `SELECT` ๋ฌธ์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•  ๋•Œ `INTO CORRESPONDING FIELDS OF` ์ ˆ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์˜ ํ•„๋“œ์™€ ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์˜ ํ•„๋“œ๋ฅผ ์‰ฝ๊ฒŒ ๋งค

jay-din.tistory.com

 

 

728x90
๋ฐ˜์‘ํ˜•