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

[SAP ABAP] string ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ

by Jay Din 2023. 8. 14.
728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๊ฐ€๋ณ€ ๊ธธ์ด๋ฅผ ๊ฐ–๋Š” Predefined ABAP Type

์‹คํ–‰ ์‹œ์ ๊นŒ์ง€ ๊ณ ์ • ๊ธธ์ด๋ฅผ ์•Œ ์ˆ˜ ์—†๋Š” ๊ฐ€๋ณ€ ๊ธธ์ด์˜ Data Type์œผ๋กœ, String์ด ๋Œ€ํ‘œ์ ์ž…๋‹ˆ๋‹ค.

String์€ ๊ฐ€๋ณ€ ๊ธธ์ด๋ฅผ ๊ฐ€์ง€๋Š” Data Type C์™€ ์œ ์‚ฌํ•˜๋ฉฐ, ์•„์ฃผ ๊ธด ๋ฌธ์ž์—ด์„ ํ‘œํ˜„ํ•  ๊ฒฝ์šฐ String์„ ์‚ฌ์šฉํ•˜๋ฉด ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

STRING ํƒ€์ž…๊ณผ Data Type C์™€์˜ ์ฐจ์ด์ ์€ ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋œ ํ™˜๊ฒฝ์—์„œ Dynamic Memory(๋™์  ๋ฉ”๋ชจ๋ฆฌ)๊ฐ€ ํ• ๋‹น๋œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.

 

String ๋˜๋Š” TYPE c ๋ฌธ์ž์—ด ๋ช…๋ น์–ด

  • ๊ณตํ†ต์กฐ๊ฑด
DATA : gv_str   TYPE string,
      gv_chr(4) TYPE c.

 

  • FIND: ABAP์ด๋ž€ ๊ธ€์ž ์•ˆ์— B๊ฐ€ ์žˆ์œผ๋ฉฐ, ์‹œ์Šคํ…œ ๋ณ€์ˆ˜ SY-SUBRC = 0 ๋ฐ˜ํ™˜
* FIND.
gv_str = 'ABAP'.
gv_chr = 'B'.
FIND gv_chr In gv_str.
IF sy-subrc EQ 0.
  WRITE 'B found'.
ENDIF.

* ์‹คํ–‰๊ฒฐ๊ณผ
B found

 

  • REPLACE: ๋ฌธ์ž์—ด์—์„œ ํŠน์ • ํŒจํ„ด์„ ์ฐพ์•„ ๋‹ค๋ฅธ ํŒจํ„ด์œผ๋กœ ๋ฐ”๊ฟˆ
* REPLACE () IN () WITH ().
gv_str = 'ABAP is fun and ABAP is powerful'.
gv_chr = REPLACE 'ABAP' IN gv_str with 'SAP'.
WRITE / gv_chr.

* ์‹คํ–‰๊ฒฐ๊ณผ
SAP is fun and SAP is powerful

 

  • TRANSLATE: ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๋ณ€๊ฒฝ ex) ABAP -> abap
* TRANSLATE.
gv_str = 'ABAP'.
TRANSLATE gv_str TO LOWER CASE.
WRITE / gv_str.

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

 

  • SHIFT: ABAP๋ฅผ ์™ผ์ชฝ์œผ๋กœ ํ•œ์นธ์”ฉ ์˜ฎ๊น€
* SHIFT
gv_str = 'ABAP'.
SHIFT gv_str.
WRITE / gv_str.

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

 

  • CONDENSE: ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜์—ฌ ์™ผ์ชฝ์œผ๋กœ ์ •๋ ฌ NO-GAPS์™€ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜์–ด SPACE๋ฅผ ์ œ๊ฑฐ
*CONDENSE () NO-GAPS.
gv_str = 'AB       AP'.
CONDENSE gv_str NO-GAPS.
WRITE / gv_str.

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

 

  • OVERLAY: character์˜ ๋นˆ ๊ณณ์„ ์ฑ„์šฐ๊ณ , ์ฑ„์›Œ์ ธ ์žˆ๋Š” ๊ณณ์„ ๋ฎ์–ด์“ฐ์ง€ ์•Š์Œ
* OVERLAY
gv_str = ' B P'.
gv_chr = 'AAAA'.
OVERLAY gv_str WITH gv_chr.
WRITE / gv_str.

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

 

  • CONCATENATE: AB+AP์„ ํ•ฉ์ณ์„œ ABAP์œผ๋กœ ์—ฐ๊ฒฐ
* CONCATENATE
gv_str = 'AB'.
gv_chr = 'AP'.
CONCATENATE gv_str gv_chr INTO gv_str.
WRITE / gv_str.

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

 

  • SPLIT: ๊ธฐ์ค€ ๋ฌธ์ž๋ฅผ ์ค‘์‹ฌ์œผ๋กœ AB์™€ AP๋กœ ๋‚˜๋ˆ”
* SPLIT
gv_str = 'AB,AP'.
SPLIT gv_str AT ',' INTO gv_str gv_chr.
WRITE : / gv_str, gv_chr.

* ์‹คํ–‰๊ฒฐ๊ณผ
AB AP

 

 


์ฐธ๊ณ 

[๋„์„œ] Easy ABAP 2.0 - ๊น€์„ฑ์ค€

728x90
๋ฐ˜์‘ํ˜•