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

[SAP ABAP] ๋ฌธ์ž C(Character) ํƒ€์ž…๊ณผ MOVE๋ž€?

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

๋ฌธ์ž ํƒ€์ž… ์ข…๋ฅ˜

๋ฌธ์ž ํƒ€์ž…์€ ํฌ๊ฒŒ 4๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•˜๋ฉฐ Character Field๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค.

C ๋ฌธ์ž, ์ˆซ์ž, ํŠน์ˆ˜๋ฌธ์ž์— ์‚ฌ์šฉ.
N ์ˆซ์ž๋ฅผ C ํƒ€์ž…์œผ๋กœ ํ‘œํ˜„. Integer ํ˜•ํƒœ๋ฅผ ๋ฌธ์ž ํƒ€์ž…์œผ๋กœ ๋ณด์—ฌ์คŒ.
D ๋‚ ์งœ ํƒ€์ž…์„ ํ‘œํ˜„.
T ์‹œ๊ฐ„ ํƒ€์ž…์„ ํ‘œํ˜„

 

C ํƒ€์ž… ์˜ˆ์ œ

C ํƒ€์ž…์€ ๋ฐ์ดํ„ฐ ์„ ์–ธ ์‹œ์— ๋ฌธ์ž ๊ธธ์ด๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์„ ์–ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ž ๊ธธ์ด๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ Data Type์„ ์„ ์–ธํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ Character 1 ์ž๋ฆฌ๋กœ ์ •์˜๋ฉ๋‹ˆ๋‹ค.

TYPE c์˜ ๋ฌธ์ž ๊ธธ์ด๋ฅผ ์ง€์ •ํ•  ๊ฒฝ์šฐ์—๋Š” ๋ณ€์ˆ˜ ๋’ค์— ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜, LENGTH ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

LENGTH ํ‚ค์›Œ๋“œ๋Š” C, N, X, P ํƒ€์ž…์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ ๋ณ€์ˆ˜ ๊ธธ์ด๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

REPORT TEST01 .

DATA gv_f0.
DATA gv_f1  TYPE c.
DATA gv_f2(1)  TYPE c.
DATA gv_f3(2) TYPE c.
DATA gv_f4 TYPE c LENGTH  2.
DATA gv_f5(5) .
DATA gv_len TYPE i.

MOVE : 'KOREA' TO gv_f0 ,
'KOREA' TO gv_f1 ,
'KOREA' TO gv_f2 ,
'KOREA' TO gv_f3 ,
'KOREA' TO gv_f4 ,
'KOREA' TO gv_f5 .

WRITE : / gv_f0,
/ gv_f1,
/ gv_f2,
/ gv_f3,
/ gv_f4,
/ gv_f5.

gv_len = STRLEN( gv_f5 ) .
WRITE / gv_len .

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

 

๋ฐ˜์‘ํ˜•

 

MOVE

MOVE ๋ช…๋ น์€ = ๊ธฐํ˜ธ์™€ ๋™์ผํ•˜๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.

์ด์™€ ์œ ์‚ฌํ•œ ์—ญํ• ์„ ํ•˜๋Š” MOVE-CORRESPONDING ๊ตฌ๋ฌธ์€ ๊ตฌ์กฐ์ฒด๋‚˜ ํ—ค๋”๋ผ์ธ์ด ์กด์žฌํ•˜๋Š” Internal Table์— ์‚ฌ์šฉ๋˜๋Š” ๊ตฌ๋ฌธ์ด๋ฉฐ ๋™์ผํ•œ ํ•„๋“œ๋ช…์— ๋ฐ์ดํ„ฐ๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค.

 

๊ธฐ๋Šฅ ์ •๋ฆฌ

Strlen ๋ฌธ์ž์˜ ๊ธธ์ด๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๊ธฐ๋Šฅ ์ˆ˜ํ–‰
WRITE ๋ฐ์ดํ„ฐ๋ฅผ LIST์— ์“ฐ๋Š” ์—ญํ•  ์ˆ˜ํ–‰
์Šฌ๋ž˜์‹œ (/) New Line ์˜๋ฏธ

 

N ํƒ€์ž… ์˜ˆ์ œ

TYPE N์€ ์ˆซ์ž๋ฅผ ๋ฌธ์ž๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.

REPORT ZABAP001 .

DATA : gv_num1 TYPE n LENGTH 4.
      
gv_num1 = 89.
WRITE : / gv_num1.

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

TYPE N ํƒ€์ž…์˜ ๋ณ€์ˆ˜์—์„œ ๊ณต๋ฐฑ์€ 0์œผ๋กœ ํ‘œํ˜„๋˜์–ด ๋ฌธ์ž ๊ธธ์ด๋งŒํผ LIST์— ์กฐํšŒ๋ฉ๋‹ˆ๋‹ค.

 

๋‚ ์งœ ํƒ€์ž… D ์˜ˆ์ œ

์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ์ €์žฅํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์‹œ์Šคํ…œ ๋ณ€์ˆ˜์ธ sy-datum ๊ฐ’์„ ํ• ๋‹นํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ, ๋‚ ์งœ ํƒ€์ž… ๋ณ€์ˆ˜์— ์ˆซ์ž๋ฅผ ์—ฐ์‚ฐ์ž์™€ ํ•จ๊ผ ์‚ฌ์šฉํ•˜๋ฉด ์ผ์ž(day)๋ฅผ ๊ณ„์‚ฐํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

REPORT ZABAP001 .

* ๋‚ ์งœ ๊ณ„์‚ฐ
DATA : gv_data TYPE d.

* ์˜ค๋Š˜ ๋‚ ์งœ
gv_data = sy-datum.
WRITE: / '์˜ค๋Š˜ ๋‚ ์งœ: ', gv_data.

* ๋‚ ์งœ ์—ฐ์‚ฐ
gv_data = gv_data + 31.
WRITE: / '31์ผ ๋’ค์— ๋‚ ์งœ: ', gv_data .

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

์ฐธ๊ณ ๋กœ ๊ธ€์„ ์ž‘์„ฑํ•˜๊ณ  ์žˆ๋Š” ์˜ค๋Š˜ ๋‚ ์งœ๋Š” 2023-08-11์ž…๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•

 

์‹œ๊ฐ„ ํƒ€์ž… T ์˜ˆ์ œ

์‹œ์Šคํ…œ ๋ณ€์ˆ˜ sy-uzeit์„ ํ†ตํ•ด ํ˜„์žฌ ์‹œ๊ฐ„์„ ํ• ๋‹น ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ๊ฐ„ ํƒ€์ž… ๋ณ€์ˆ˜๋Š” ์ดˆ ๋‹จ์œ„(second)๋กœ ์—ฐ์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ

REPORT ZABAP001 .

* ์‹œ๊ฐ„ ๊ณ„์‚ฐ
DATA : gv_time TYPE t.

* ํ˜„์žฌ ์‹œ๊ฐ„
gv_time = sy-uzeit.
WRITE: / 'ํ˜„์žฌ ์‹œ๊ฐ„: ', gv_time.

* ๋‚ ์งœ ์—ฐ์‚ฐ
gv_time = gv_time - 60.
WRITE: / '60์ดˆ ์ „์— ์‹œ๊ฐ„: ', gv_time .

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

 

 

728x90

 

728x90
๋ฐ˜์‘ํ˜•