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

[SAP ABAP] CALL FUNCTION ์ด๋ž€? (CALL FUNCTION ์ƒ์„ฑ ๋ฐฉ๋ฒ•, ์˜ˆ์ œ ํฌํ•จ)

by Jay Din 2024. 7. 19.
728x90
๋ฐ˜์‘ํ˜•

CALL FUNCTION ์ด๋ž€?

` CALL FUNCTION ` ์€ ๋‹ค๋ฅธ ํ•จ์ˆ˜ ๋ชจ๋“ˆ์„ ํ˜ธ์ถœํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ช…๋ น๋ฌธ์ž…๋‹ˆ๋‹ค.

ํ•จ์ˆ˜ ๋ชจ๋“ˆ์€ SAP ์‹œ์Šคํ…œ์—์„œ ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋„๋ก ์ •์˜๋œ ๋…๋ฆฝ์ ์ธ ์ฝ”๋“œ ๋ธ”๋ก์ž…๋‹ˆ๋‹ค.

์ด๋ฅผ ํ†ตํ•ด ABAP ํ”„๋กœ๊ทธ๋žจ์€ ๋‹ค๋ฅธ ํ•จ์ˆ˜ ๋ชจ๋“ˆ์˜ ๊ธฐ๋Šฅ์„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

CALL FUNCTION ๊ธฐ๋ณธ ๊ตฌ์กฐ

CALL FUNCTION 'ํ•จ์ˆ˜ ๋ชจ๋“ˆ ์ด๋ฆ„'
  EXPORTING
    ํŒŒ๋ผ๋ฏธํ„ฐ1 = ๊ฐ’1
    ํŒŒ๋ผ๋ฏธํ„ฐ2 = ๊ฐ’2
  IMPORTING
    ๊ฒฐ๊ณผ ํŒŒ๋ผ๋ฏธํ„ฐ1 = ๋ณ€์ˆ˜1
    ๊ฒฐ๊ณผ ํŒŒ๋ผ๋ฏธํ„ฐ2 = ๋ณ€์ˆ˜2
  TABLES
    ๋‚ด๋ถ€ ํ…Œ์ด๋ธ”1 = itab1
    ๋‚ด๋ถ€ ํ…Œ์ด๋ธ”2 = itab2
  CHANGING
    ๋ณ€์ˆ˜1 = ๋ณ€์ˆ˜1
    ๋ณ€์ˆ˜2 = ๋ณ€์ˆ˜2
  EXCEPTIONS
    ์˜ˆ์™ธ1 = ๋ฒˆํ˜ธ1
    ์˜ˆ์™ธ2 = ๋ฒˆํ˜ธ2.

 

  • FUNCTION_MODULE_NAME: ํ˜ธ์ถœํ•  ํ•จ์ˆ˜ ๋ชจ๋“ˆ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  • EXPORTING: ํ˜ธ์ถœํ•  ํ•จ์ˆ˜์— ์ „๋‹ฌ๋˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜(Parameter)๋“ค์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • IMPORTING: ํ˜ธ์ถœ๋œ ํ•จ์ˆ˜๋กœ๋ถ€ํ„ฐ ๋ฐ˜ํ™˜๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์„ ๋ณ€์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • TABLES: ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์„ ํ•จ์ˆ˜ ๋ชจ๋“ˆ์— ์ „๋‹ฌํ•˜๊ฑฐ๋‚˜ ํ•จ์ˆ˜ ๋ชจ๋“ˆ์—์„œ ๋ฐ˜ํ™˜๋œ ํ…Œ์ด๋ธ”์„ ์ˆ˜์‹ ํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • CHANGING: ํ•จ์ˆ˜ ๋ชจ๋“ˆ์— ์ „๋‹ฌ๋œ ๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
  • EXCEPTIONS: ํ˜ธ์ถœ๋œ ํ•จ์ˆ˜๊ฐ€ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ์˜ˆ์™ธ ์ƒํ™ฉ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
  • OTHERS: ` EXCEPTIONS ` ์„น์…˜์—์„œ ์ •์˜ํ•œ ์˜ˆ์™ธ ์ค‘์—์„œ ๋‹ค๋ฅธ ๋ชจ๋“  ์˜ˆ์™ธ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

 

CALL FUNCTION ์˜ˆ์ œ

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋กœ ๋ง์…ˆ Function Module์„ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

1. CALL FUNCTION ํ•จ์ˆ˜ ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

๋จผ์ € SAP GUI์—์„œ Function Module์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

se37 ์˜ˆ์‹œ ํ™”๋ฉด

  1. ํŠธ๋žœ์žญ์…˜ ์ฝ”๋“œ SE37 ์‹คํ–‰
  2. Function Module ์ด๋ฆ„ ์ž…๋ ฅ: Z_ADD_NUMBERS
  3. Create ํด๋ฆญ

 

Create Function Module ์˜ˆ์‹œ ํ™”๋ฉด

  1. Function Group ์ž…๋ ฅ: ์˜ˆ๋ฅผ๋“ค์–ด,  ZFUNCTION_GROUP
  2. Short Text ์ž…๋ ฅ: Add two numbers

 

Import, Export ๋งค๊ฐœ๋ณ€์ˆ˜ ์ •์˜
Exceptions ์ •์˜

  1. Import Parameters
    • I_NUM1: ํƒ€์ž… I (์ •์ˆ˜ํ˜•)
    • I_NUM2: ํƒ€์ž… I (์ •์ˆ˜ํ˜•)
  2. Export Parameters
    • E_SUM: ํƒ€์ž… I (์ •์ˆ˜ํ˜•)
  3. Exceptions
    1. INVALID_INPUT: ์˜ˆ์™ธ์ฒ˜๋ฆฌ

Source code ์˜ˆ์‹œ

  1. ํ•จ์ˆ˜ ๋ชจ๋“ˆ Z_ADD_NUMBERS ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  2. I_NUM1 ๋˜๋Š” I_NUM2๊ฐ€ ์ดˆ๊ธฐ ๊ฐ’(๋นˆ ๊ฐ’)์ด๋ฉด INVALID_INPUT ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.
  3. ํ•ด๋‹น ํ•จ์ˆ˜ ๋ชจ๋“ˆ์€ Active ํ•ด์ค๋‹ˆ๋‹ค.

 

2. Function Module ํ˜ธ์ถœ ์˜ˆ์ œ

์ด์ œ ์ƒ์„ฑํ•œ ํ•จ์ˆ˜ ๋ชจ๋“ˆ์„ ํ˜ธ์ถœํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

DATA: lv_num1 TYPE i,
      lv_num2 TYPE i,
      lv_sum  TYPE i.

lv_num1 = 5.
lv_num2 = 10.

CALL FUNCTION 'Z_ADD_NUMBERS'
  EXPORTING
    i_num1 = lv_num1
    i_num2 = lv_num2
  IMPORTING
    e_sum  = lv_sum
  EXCEPTIONS
    invalid_input = 1
    others = 2.

IF sy-subrc = 0.
  WRITE: / 'Answer:', lv_num1, '+', lv_num2, '=', lv_sum.
ELSEIF sy-subrc = 1.
  WRITE: / 'Error: Invalid input provided.'.
ELSE.
  WRITE: / 'Error occurred:', sy-subrc.
ENDIF.

 

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

์ถœ๋ ฅํ™”๋ฉด

  • ํ•จ์ˆ˜ ๋ชจ๋“ˆ ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด ๋‘ ์ˆซ์ž์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

*lv_num1 = 5.		" ์ฃผ์„์œผ๋กœ lv_num1 ๋นˆ๊ฐ’ ์ฒ˜๋ฆฌ

์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ™”๋ฉด

  • lv_num1 ์„ ์ฃผ์„์ฒ˜๋ฆฌํ•˜๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ์— ๋”ฐ๋ผ ์œ„์™€ ๊ฐ™์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•