심심해서 한번 만들어봤습니다.
5를 입력하시면 5 * 5 마방진을 출력합니다.
사용자가 9를 입력하면 9개의 필드가 있는 itab을 만들수 있는 방법이 혹시 있나요?
PARAMETERS: SIZE TYPE N OBLIGATORY.
DATA: BEGIN OF ITAB OCCURS 0,
F1 TYPE I,
F2 TYPE I,
F3 TYPE I,
F4 TYPE I,
F5 TYPE I,
F6 TYPE I,
F7 TYPE I,
F8 TYPE I,
F9 TYPE I,
F10 TYPE I,
END OF ITAB.
DATA: I TYPE I, J TYPE I, MOD TYPE I, TOTAL TYPE I, COUNT TYPE I.
FIELD-SYMBOLS: <FS>.
* init
DO SIZE TIMES.
APPEND ITAB.
ENDDO.
I = SIZE / 2.
J = 1.
TOTAL = SIZE * SIZE.
* Fill
DO TOTAL TIMES.
ADD 1 TO COUNT.
READ TABLE ITAB INDEX J.
ASSIGN COMPONENT I OF STRUCTURE ITAB TO <FS>.
<FS> = COUNT.
MODIFY ITAB INDEX J.
MOD = COUNT MOD SIZE.
IF MOD = 0.
J = J + 1.
ELSE.
I = I + 1.
J = J - 1.
ENDIF.
IF I < 1.
I = I + SIZE.
ELSEIF I > SIZE.
I = I - SIZE.
ENDIF.
IF J < 1.
J = J + SIZE.
ELSEIF J > SIZE.
J = J - SIZE.
ENDIF.
ENDDO.
* Display
LOOP AT ITAB.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE ITAB TO <FS>.
IF SY-SUBRC = 0 AND SY-INDEX <= SIZE.
WRITE: <FS>.
ELSE.
WRITE:/.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.