REPORT zsql MESSAGE-ID zmco NO STANDARD PAGE HEADING.
INCLUDE <symbol>.
INCLUDE <line>.
TABLES: dd03l, " 테이블필드
dd01l, " 도메인
dd02t, " R/3-DD: SAP 테이블 텍스트
dd17s, " R/3 S_SECINDEX: 보조 인덱스, 필드
dd12t, " DD12L에 대한 텍스트 테이블
dd04t. " R/3 DD: Data element 텍스트
DATA: BEGIN OF itab_prog OCCURS 1,
code(120) TYPE c,
END OF itab_prog.
DATA: BEGIN OF itab_sql OCCURS 1,
code(120) TYPE c,
END OF itab_sql.
DATA: BEGIN OF itab_col OCCURS 1,
col(30) TYPE c,
alias(10) TYPE c,
END OF itab_col.
DATA: BEGIN OF itab_tab OCCURS 1,
tab(10) TYPE c,
alias(10) TYPE c,
END OF itab_tab.
DATA: BEGIN OF itab_write OCCURS 1,
data(120) TYPE c,
END OF itab_write.
DATA: BEGIN OF itab_into OCCURS 1,
code(120) TYPE c,
END OF itab_into.
DATA: BEGIN OF itab_del OCCURS 1,
tabix TYPE i,
code(120) TYPE c,
END OF itab_del.
DATA: BEGIN OF itab_index OCCURS 1,
tab(10) TYPE c,
index LIKE dd12l-dbindex,
index_text LIKE dd12t-ddtext,
index_field LIKE dd17s-fieldname,
field_text LIKE dd04t-ddtext,
plus TYPE c,
END OF itab_index.
DATA: BEGIN OF itab_len OCCURS 1,
len TYPE i,
END OF itab_len.
DATA: BEGIN OF itab_field OCCURS 1,
field LIKE dd03l-fieldname,
text(40) TYPE c,
END OF itab_field.
DATA: BEGIN OF itab_dist OCCURS 1,
code(120) TYPE c,
END OF itab_dist.
DATA: BEGIN OF fcode_tab OCCURS 10,
fcode(4),
END OF fcode_tab.
DATA: sql_tabix LIKE sy-tabix,
select_key(10) TYPE c,
etc(120) TYPE c.
DATA: temp_col(30) TYPE c,
temp_char TYPE c,
count1(3) TYPE n,
count2(2) TYPE n,
like_col(30) TYPE c,
col_lin TYPE i,
endlen(3) TYPE n VALUE 1.
DATA: from_flag TYPE c,
alias_flag TYPE c,
end_flag TYPE c,
update_flag TYPE c,
confirm_flag TYPE c.
DATA: col_length LIKE dd03l-leng.
DATA: prog(8) TYPE c,
msg(120) TYPE c,
msg_text(80) TYPE c,
subrc LIKE sy-subrc,
mark TYPE c VALUE 'X',
line_cnt TYPE i,
filesize TYPE i.
DATA: l_uname LIKE sy-uname.
INITIALIZATION.
START-OF-SELECTION.
l_uname = sy-uname.
CASE l_uname.
WHEN '권한허가자'. "추가
WHEN OTHERS.
MESSAGE s000 WITH '프로그램 실행권한없습니다'.
EXIT.
ENDCASE.
SET TITLEBAR '000'.
SET PF-STATUS 'YOSJSQL'.
*----------------------------------------------------------------------
* EXEC : SQL문 실행
* EDIT : SQL문 편집
* PLAN : SQL문 설명
* DOWN : SQL문 Download
* UPLD : SQL문 Upload
*----------------------------------------------------------------------
WRITE :/ 'Edit Your SQL ...' COLOR 5.
AT USER-COMMAND.
IF sy-ucomm = 'EDIT'.
PERFORM edit_sql.
PERFORM write_sql_report.
ELSEIF sy-ucomm = 'EXEC'.
IF update_flag = space.
PERFORM sql_generate USING 'Y' itab_col-col 'A'. "INIT FLAG ='Y'
IF sy-subrc <> 0.
EXIT.
ENDIF.
PERFORM check_sql_code.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Check your SQL statement!!!'.
EXIT.
ENDIF.
READ TABLE itab_col INDEX 1.
IF sy-subrc = 0.
PERFORM exec_sql.
ENDIF.
ELSE.
* IF SY-UNAME = 'WJCYR' or SY-UNAME = 'WJLDW'.
PERFORM confirm_update.
CASE confirm_flag.
WHEN 'N'. EXIT.
WHEN 'A'. EXIT.
WHEN 'J'. PERFORM exec_sql_update.
ENDCASE.
* ELSE.
* MESSAGE I315 WITH '당신에게는 그런 SQL을 쓸 권한이
*없습니다.'.
* EXIT.
* ENDIF.
ENDIF.
ELSEIF sy-ucomm = 'BBCK'.
sy-lsind = 0.
ELSEIF sy-ucomm = 'BCCK'.
REFRESH itab_index.
sy-lsind = sy-lsind - 3.
ELSEIF sy-ucomm = 'PLAN'.
PERFORM explain_sqltab(rsxplain) TABLES itab_sql
USING subrc.
ELSEIF sy-ucomm = 'INDX'.
PERFORM view_indx_tab.
ELSEIF sy-ucomm = 'TABL' OR sy-ucomm = 'DIST'.
IF sy-ucomm = 'TABL'.
SET TITLEBAR 'W03'.
ELSE.
SET TITLEBAR 'W05'.
ENDIF.
PERFORM view_field_tab.
ELSEIF sy-ucomm = 'CHOS'.
PERFORM chos_indx_tab.
ELSEIF sy-ucomm = 'CHSE'.
IF itab_tab-tab = space.
EXIT.
ENDIF.
IF sy-title = 'Choose Table for field search'.
PERFORM chse_view_field.
ELSEIF sy-title = 'Choose Table for field distribution'.
PERFORM chse_field_dist.
ELSEIF sy-title = 'Choose Field for distribution'.
PERFORM sel_field_dist.
ENDIF.
ELSEIF sy-ucomm = 'SASC'.
PERFORM exec_sasc.
ELSEIF sy-ucomm = 'SDES'.
PERFORM exec_sdes.
ELSEIF sy-ucomm = 'GRAF'.
PERFORM create_graf.
ELSEIF sy-ucomm = 'UPLD'.
PERFORM sql_upload.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Upload Error'.
EXIT.
ENDIF.
IF filesize <> 0.
PERFORM edit_sql.
PERFORM write_sql_report.
ENDIF.
ELSEIF sy-ucomm = 'DOWN'.
PERFORM sql_download.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Download Error'.
ENDIF.
ENDIF.
AT LINE-SELECTION.
IF sy-lsind >= 3 AND itab_index-index <> space.
PERFORM write_index_hier.
ELSEIF sy-pfkey = 'PFSTA04' AND itab_tab-tab <> space.
IF sy-title = 'Choose Table for field search'.
PERFORM chse_view_field.
ELSEIF sy-title = 'Choose Table for field distribution'.
PERFORM chse_field_dist.
ELSEIF sy-title = 'Choose Field for distribution'
AND itab_field-field <> space.
PERFORM sel_field_dist.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------
*& Form SQL_PARSING
*&---------------------------------------------------------------------
* SQL PARSING
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM sql_parsing.
DATA: aggr_flag TYPE c,
aggr_cnt TYPE i.
LOOP AT itab_sql.
IF sy-tabix = 1.
SHIFT itab_sql-code LEFT DELETING LEADING space.
ENDIF.
sql_tabix = sy-tabix + 1.
SPLIT itab_sql-code AT space INTO select_key etc.
* IF ETC(11) = '/*+ RULE */'.
* ETC(11) = ' '.
* ENDIF.
IF select_key = 'SELECT'.
CLEAR: temp_col, temp_char, count1, count2, from_flag, alias_flag
,
update_flag, end_flag.
DO.
temp_char = etc+count2(1).
IF temp_char = '('.
IF aggr_cnt = 0.
aggr_flag = 'Y'.
ENDIF.
aggr_cnt = aggr_cnt + 1.
ELSEIF temp_char = ')'.
aggr_cnt = aggr_cnt - 1.
IF aggr_cnt = 0.
aggr_flag = ' '.
ENDIF.
ENDIF.
IF temp_char = space OR temp_char = ','.
IF from_flag = 'Y'.
IF temp_col <> space AND temp_col <> 'WHERE'.
IF temp_char = space.
IF itab_tab-tab = space.
itab_tab-tab = temp_col.
alias_flag = 'Y'.
ELSE.
itab_tab-alias = temp_col.
ENDIF.
ELSEIF alias_flag <> 'Y'.
itab_tab-tab = temp_col.
APPEND itab_tab.
CLEAR itab_tab.
ELSEIF alias_flag = 'Y'.
itab_tab-alias = temp_col.
APPEND itab_tab.
CLEAR itab_tab.
CLEAR alias_flag.
ENDIF.
ELSEIF temp_col = 'WHERE'.
IF itab_tab-tab <> space.
COLLECT itab_tab.
ENDIF.
EXIT.
ENDIF.
CLEAR: temp_col, count1.
count2 = count2 + 1.
IF count2 >= 80.
PERFORM read_next_sql.
IF end_flag = 'Y'.
EXIT.
ENDIF.
ENDIF.
CONTINUE.
ELSE.
IF temp_col <> space AND temp_col <> 'FROM'
AND temp_col <> 'DISTINCT'
AND ( temp_char = ',' OR temp_char = ' ' )
AND aggr_flag = ' ' .
SEARCH temp_col FOR '('.
IF sy-fdpos = 0.
SPLIT temp_col AT '.' INTO itab_col-alias itab_col-col.
IF itab_col-col = space.
itab_col-col = itab_col-alias.
CLEAR itab_col-alias.
ENDIF.
ELSE.
itab_col-col = temp_col.
ENDIF.
APPEND itab_col.
ELSEIF temp_col = 'FROM'.
from_flag = 'Y'.
ENDIF.
IF aggr_flag <> 'Y'.
CLEAR: temp_col, count1.
ELSE.
IF temp_char <> '''' AND temp_char <> ','
AND count1 < 28.
temp_col+count1(1) = etc+count2(1).
count1 = count1 + 1.
ENDIF.
ENDIF.
count2 = count2 + 1.
IF count2 >= 80.
PERFORM read_next_sql.
IF end_flag = 'Y'.
EXIT.
ENDIF.
ENDIF.
CONTINUE.
ENDIF.
ELSE.
IF temp_char <> '''' AND temp_char <> ',' AND count1 < 28.
temp_col+count1(1) = etc+count2(1).
ENDIF.
ENDIF.
count1 = count1 + 1.
count2 = count2 + 1.
ENDDO.
IF itab_tab-tab <> space.
COLLECT itab_tab.
ENDIF.
ELSEIF select_key = 'DELETE' OR select_key = 'UPDATE'
OR select_key = 'INSERT'.
update_flag = 'Y'.
ENDIF.
ENDLOOP.
ENDFORM. " SQL_PARSING
*&---------------------------------------------------------------------
*& Form READ_NEXT_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM read_next_sql.
READ TABLE itab_sql INDEX sql_tabix.
IF sy-subrc <> 0.
end_flag = 'Y'.
EXIT.
ENDIF.
etc = itab_sql-code.
sql_tabix = sql_tabix + 1.
CLEAR: temp_col, count1, count2.
ENDFORM. " READ_NEXT_SQL
*&---------------------------------------------------------------------
*& Form DECLARE_HEADER
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM declare_header.
itab_prog-code = 'PROGRAM SUBPOOL.'.
APPEND itab_prog.
itab_prog-code = 'DATA REC_COUNT(7) TYPE N.'.
APPEND itab_prog.
itab_prog-code = 'DATA: BEGIN OF ITAB_DATA OCCURS 1,'.
APPEND itab_prog.
itab_write-data = 'WRITE: /1 '.
APPEND itab_write.
DESCRIBE TABLE itab_col LINES col_lin.
LOOP AT itab_col.
count1 = sy-tabix.
READ TABLE itab_tab WITH KEY alias = itab_col-alias.
CONCATENATE 'COL' count1 INTO temp_col.
SEARCH itab_col-col FOR '('.
IF sy-fdpos <> 0.
CONCATENATE 'COL' count1 '(15)' INTO itab_prog-code.
CONCATENATE itab_prog-code 'TYPE C,'
INTO itab_prog-code SEPARATED BY space.
ELSE.
CONCATENATE itab_tab-tab '-' itab_col-col INTO like_col.
CONCATENATE temp_col 'LIKE' like_col ','
INTO itab_prog-code SEPARATED BY space.
ENDIF.
APPEND itab_prog.
IF count1 = 1 AND count1 <> col_lin.
CONCATENATE 'INTO :ITAB_DATA-' temp_col ',' INTO itab_into-code.
APPEND itab_into.
CONCATENATE 'SY-VLINE, ITAB_DATA-' temp_col ','
INTO itab_write-data.
APPEND itab_write.
ELSEIF count1 < col_lin.
CONCATENATE ':ITAB_DATA-' temp_col ',' INTO itab_into-code.
APPEND itab_into.
CONCATENATE 'SY-VLINE, ITAB_DATA-' temp_col ','
INTO itab_write-data.
APPEND itab_write.
ELSE.
IF count1 = 1.
CONCATENATE 'INTO :ITAB_DATA-' temp_col INTO itab_into-code.
APPEND itab_into.
ELSE.
CONCATENATE ':ITAB_DATA-' temp_col INTO itab_into-code.
APPEND itab_into.
ENDIF.
CONCATENATE ' SY-VLINE,ITAB_DATA-' temp_col ', SY-VLINE.'
INTO itab_write-data.
APPEND itab_write.
ENDIF.
ENDLOOP.
itab_prog-code = ' END OF ITAB_DATA.'.
APPEND itab_prog.
itab_prog-code = 'FORM DYN1.'.
APPEND itab_prog.
ENDFORM. " DECLARE_HEADER
*&---------------------------------------------------------------------
*& Form WRITE_EXEC_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_exec_sql.
DATA: res_sql(80) TYPE c,
res_len TYPE i,
into_tabix LIKE sy-tabix,
order_flag TYPE c.
itab_prog-code = 'EXEC SQL PERFORMING WRITE_DATA.'.
APPEND itab_prog.
SEARCH itab_sql FOR 'FROM'.
READ TABLE itab_sql INDEX sy-tabix.
IF sy-fdpos <> 0 AND sy-fdpos <> 1.
res_sql = itab_sql-code+0(sy-fdpos).
res_len = 80 - sy-fdpos.
itab_sql-code = itab_sql-code+sy-fdpos(res_len).
MODIFY itab_sql INDEX sy-tabix.
itab_sql-code = res_sql.
INSERT itab_sql INDEX sy-tabix.
sy-tabix = sy-tabix + 1.
ENDIF.
into_tabix = sy-tabix.
LOOP AT itab_into.
itab_sql-code = itab_into-code.
INSERT itab_sql INDEX into_tabix.
into_tabix = into_tabix + 1.
ENDLOOP.
SEARCH itab_sql FOR 'ORDER BY'.
IF sy-subrc = 0.
order_flag = 'Y'.
READ TABLE itab_sql INDEX sy-tabix.
IF sy-fdpos <> 0 AND sy-fdpos <> 1.
res_sql = itab_sql-code+0(sy-fdpos).
res_len = 80 - sy-fdpos.
itab_sql-code = itab_sql-code+sy-fdpos(res_len).
MODIFY itab_sql INDEX sy-tabix.
itab_sql-code = res_sql.
INSERT itab_sql INDEX sy-tabix.
sy-tabix = sy-tabix + 1.
ENDIF.
ELSE.
order_flag = 'N'.
ENDIF.
LOOP AT itab_sql.
IF sy-tabix > 1 AND itab_sql-code+0(1) <> space.
itab_sql-code+1(79) = itab_sql-code+0(79).
itab_sql-code+0(1) = ' '.
MODIFY itab_sql INDEX sy-tabix.
ENDIF.
itab_prog-code = itab_sql-code.
APPEND itab_prog.
ENDLOOP.
* IF ORDER_FLAG = 'N'.
* READ TABLE ITAB_COL INDEX 1.
* SEARCH ITAB_SQL FOR '('.
* IF SY-SUBRC <> 0.
* CONCATENATE 'ORDER BY' ITAB_COL-COL
* INTO ITAB_PROG-CODE SEPARATED BY SPACE.
* APPEND ITAB_PROG.
* ENDIF.
* ENDIF.
itab_prog-code = 'ENDEXEC.'.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
APPEND itab_prog.
itab_prog-code = 'SET TITLEBAR ''001'' WITH REC_COUNT ''Records''.'.
APPEND itab_prog.
itab_prog-code = 'ENDFORM.'.
APPEND itab_prog.
ENDFORM. " WRITE_EXEC_SQL
*&---------------------------------------------------------------------
*& Form WRITE_DATA
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_data.
itab_prog-code = 'FORM WRITE_DATA.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT INTENSIFIED OFF.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT COLOR 2.'.
APPEND itab_prog.
LOOP AT itab_write.
itab_prog-code = itab_write-data.
APPEND itab_prog.
ENDLOOP.
itab_prog-code = 'REC_COUNT = REC_COUNT + 1.'.
APPEND itab_prog.
itab_prog-code = 'ENDFORM.'.
APPEND itab_prog.
ENDFORM. " WRITE_DATA
*&---------------------------------------------------------------------
*& Form WRITE_HEADER
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_header.
DATA: domname LIKE dd03l-domname,
uline_tabix LIKE sy-tabix.
itab_prog-code = 'FORMAT INTENSIFIED ON.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT COLOR 1.'.
APPEND itab_prog.
uline_tabix = sy-tabix + 1.
itab_prog = 'WRITE: /1 '.
APPEND itab_prog.
LOOP AT itab_col.
READ TABLE itab_tab WITH KEY alias = itab_col-alias.
SELECT SINGLE domname INTO domname
FROM dd03l
WHERE tabname = itab_tab-tab
AND fieldname = itab_col-col.
IF sy-subrc = 0.
SELECT SINGLE outputlen INTO col_length
FROM dd01l
WHERE domname = domname
AND as4local = 'A'.
CONCATENATE '(' col_length ')' INTO temp_col.
endlen = col_length + 3 + endlen.
ELSE.
CONCATENATE '(' '15' ')' INTO temp_col.
endlen = 18 + endlen.
ENDIF.
itab_len-len = endlen.
APPEND itab_len.
CONCATENATE '''' itab_col-col '''' INTO itab_col-col.
CONCATENATE 'SY-VLINE,' temp_col itab_col-col
'CENTERED,' INTO itab_prog SEPARATED BY space.
APPEND itab_prog.
ENDLOOP.
itab_prog = 'SY-VLINE.'.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
INSERT itab_prog INDEX uline_tabix.
CONCATENATE 'NEW-PAGE LINE-SIZE' endlen '.' INTO itab_prog-code
SEPARATED BY space.
INSERT itab_prog INDEX uline_tabix.
ENDFORM. " WRITE_HEADER
*&---------------------------------------------------------------------
*& Form TRANS_UPPER_ITAB_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM trans_upper_itab_sql.
DATA: save_tabix LIKE sy-tabix,
tabix_count TYPE i.
DATA: l_pos TYPE i, l_upper, l_flag,
l_abc(52) VALUE
'ABCDEFGHIJKLMNOPQRSTUVWXYZabdefghijklmnopqrstuvwxyz'.
REFRESH itab_del.
LOOP AT itab_sql.
save_tabix = sy-tabix.
tabix_count = tabix_count + 1.
IF itab_sql-code = space OR itab_sql-code+0(1) = '*'.
IF itab_sql-code+0(1) = '*'.
CLEAR itab_del.
itab_del-tabix = tabix_count.
itab_del-code = itab_sql-code.
APPEND itab_del.
ENDIF.
DELETE itab_sql INDEX save_tabix.
CONTINUE.
ENDIF.
CLEAR l_flag.
DO 80 TIMES.
l_pos = sy-index - 1.
l_upper = itab_sql-code+l_pos(1).
IF l_upper = '''' AND l_flag = ''.
l_flag = 'X'.
ELSEIF l_upper = '''' AND l_flag = 'X'.
CLEAR l_flag.
ENDIF.
IF l_flag = 'X'.
CONTINUE.
ENDIF.
IF l_abc NS l_upper.
CONTINUE.
ENDIF.
TRANSLATE l_upper TO UPPER CASE.
itab_sql-code+l_pos(1) = l_upper.
* TRANSLATE ITAB_SQL-CODE TO UPPER CASE.
ENDDO.
MODIFY itab_sql INDEX save_tabix.
ENDLOOP.
ENDFORM. " TRANS_UPPER_ITAB_SQL
*&---------------------------------------------------------------------
*& Form CLEAR_VAR
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM clear_var.
REFRESH: itab_prog, itab_col, itab_write, itab_into, itab_tab.
CLEAR: itab_prog, itab_col, itab_write, itab_into, itab_tab.
endlen = 1.
ENDFORM. " CLEAR_VAR
*&---------------------------------------------------------------------
*& Form EDIT_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM edit_sql.
DATA: changed LIKE s38e-buf_varied,
fcode LIKE sy-ucomm,
subrc LIKE sy-subrc.
LOOP AT itab_del.
itab_sql-code = itab_del-code.
INSERT itab_sql INDEX itab_del-tabix.
ENDLOOP.
CALL FUNCTION 'EDITOR_APPLICATION'
EXPORTING
application = 'BF'
display = ' '
name = 'Input Your SQL......'
IMPORTING
fcode = fcode
changed = changed
TABLES
content = itab_sql.
* CASE FCODE.
* WHEN 'BACK'. SUBRC = 4.
* WHEN 'UPD'. SUBRC = 0.
* WHEN OTHERS. SUBRC = 8.
* ENDCASE.
* IF SUBRC <> 0.
* PERFORM CLEAR_VAR.
* REFRESH ITAB_SQL.
* EXIT.
* ENDIF.
PERFORM clear_var.
PERFORM trans_upper_itab_sql.
PERFORM sql_parsing.
IF update_flag = 'Y'.
REFRESH fcode_tab.
fcode_tab = 'PLAN'.
APPEND fcode_tab.
fcode_tab = 'INDX'.
APPEND fcode_tab.
fcode_tab = 'TABL'.
APPEND fcode_tab.
fcode_tab = 'DIST'.
APPEND fcode_tab.
SET PF-STATUS 'YOSJSQL' EXCLUDING fcode_tab.
EXIT.
ENDIF.
SET PF-STATUS 'YOSJSQL'.
READ TABLE itab_col INDEX 1.
IF itab_col-col = '*'.
PERFORM get_itab_col_all.
ELSEIF itab_col-col = '/*+'.
DELETE itab_col FROM 1 TO 3.
ENDIF.
PERFORM declare_header.
PERFORM write_header.
PERFORM write_exec_sql.
PERFORM write_data.
SEARCH itab_sql FOR 'INTO'.
IF sy-subrc = 0.
LOOP AT itab_sql FROM sy-tabix.
IF itab_sql-code+1(4) <> 'FROM'.
DELETE itab_sql INDEX sy-tabix.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " EDIT_SQL
*&---------------------------------------------------------------------
*& Form GET_LINE_CHECK
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM get_line_check.
DATA: cur_line TYPE i.
cur_line = 1.
DO.
CLEAR mark.
READ LINE cur_line FIELD VALUE mark.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF mark = 'X'.
PERFORM get_primary_index.
CLEAR itab_index.
itab_index-plus = '4'.
itab_index-tab = itab_tab-tab.
SELECT * FROM dd17s
WHERE sqltab = itab_tab-tab
ORDER BY position.
itab_index-index = itab_tab-tab.
itab_index-index+10(3) = dd17s-indexname.
SELECT SINGLE * FROM dd12t
WHERE ddlanguage = 'E'
AND sqltab = itab_tab-tab
AND indexname = dd17s-indexname.
itab_index-index_text = dd12t-ddtext.
SELECT SINGLE * FROM dd03l
WHERE tabname = itab_tab-tab
AND fieldname = dd17s-fieldname.
IF sy-subrc = 0.
SELECT SINGLE ddtext FROM dd04t
INTO itab_index-field_text
WHERE rollname = dd03l-rollname
AND ddlanguage = 'E'.
ENDIF.
itab_index-index_field = dd17s-fieldname.
COLLECT itab_index.
ENDSELECT.
ENDIF.
cur_line = cur_line + 1.
ENDDO.
ENDFORM. " GET_LINE_CHECK
*&---------------------------------------------------------------------
*& Form WRITE_INDEX
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_index.
DATA: temp_index LIKE itab_index.
SET PF-STATUS 'PFSTA03'.
SET TITLEBAR 'W02'.
NEW-PAGE LINE-SIZE 100.
LOOP AT itab_index.
MOVE-CORRESPONDING itab_index TO temp_index.
AT NEW tab.
SKIP 2.
WRITE: /1 'List Index for Table.' COLOR 1,
' - ', itab_index-tab COLOR 4.
ULINE: /1(83).
ENDAT.
AT NEW index.
IF temp_index-plus = '4'.
WRITE: /3 sy-vline, /3(2) sy-uline,
sym_plus_folder AS SYMBOL HOTSPOT ON COLOR 7,
itab_index-index COLOR 3,
temp_index-index_text COLOR 2.
HIDE: itab_index-index.
ELSE.
WRITE: /3 sy-vline, /3(2) sy-uline,
sym_minus_folder AS SYMBOL HOTSPOT ON COLOR 7,
itab_index-index COLOR 3,
temp_index-index_text COLOR 2.
HIDE: itab_index-index.
LOOP AT itab_index WHERE index = temp_index-index.
IF sy-tabix = 1.
WRITE: /9 sy-vline, /9 line_bottom_left_corner AS LINE,
itab_index-index_field COLOR 2.
ELSE.
WRITE: /9 line_bottom_left_corner AS LINE,
itab_index-index_field COLOR 2.
ENDIF.
WRITE: itab_index-field_text
UNDER temp_index-index_text COLOR 2.
ENDLOOP.
ENDIF.
ENDAT.
ENDLOOP.
CLEAR itab_index-index.
ENDFORM. " WRITE_INDEX
*&---------------------------------------------------------------------
*& Form GET_PRIMARY_INDEX
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM get_primary_index.
CLEAR itab_index.
itab_index-plus = '4'.
itab_index-tab = itab_tab-tab.
itab_index-index = itab_tab-tab.
itab_index-index+10(1) = '0'.
itab_index-index_text = 'Primary Key'.
SELECT * FROM dd03l
WHERE tabname = itab_tab-tab
ORDER BY position.
SELECT SINGLE ddtext FROM dd04t
INTO itab_index-field_text
WHERE rollname = dd03l-rollname
AND ddlanguage = 'E'.
itab_index-index_field = dd03l-fieldname.
APPEND itab_index.
ENDSELECT.
ENDFORM. " GET_PRIMARY_INDEX
*&---------------------------------------------------------------------
*& Form EXEC-SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM exec_sql.
* SET TITLEBAR '001'.
SET PF-STATUS 'PFSTA01'.
PERFORM dyn1 IN PROGRAM (prog).
ENDFORM. " EXEC_SQL
*&---------------------------------------------------------------------
*& Form WRITE_SQL_REPORT
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_sql_report.
sy-lsind = 0.
DESCRIBE TABLE itab_sql LINES line_cnt.
IF line_cnt = 0 OR ( line_cnt = 1 AND itab_sql-code = space ).
WRITE: /1 'Edit Your SQL ................' COLOR 2.
ELSE.
LOOP AT itab_sql.
WRITE: /1 itab_sql-code.
ENDLOOP.
ENDIF.
ENDFORM. " WRITE_SQL_REPORT
*&---------------------------------------------------------------------
*& Form VIEW_INDX_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM view_indx_tab.
SET TITLEBAR 'W01'.
SET PF-STATUS 'PFSTA02'.
WINDOW STARTING AT 15 5 ENDING AT 75 15.
LOOP AT itab_tab.
SELECT SINGLE * FROM dd02t
WHERE tabname = itab_tab-tab
AND ddlanguage = sy-langu.
WRITE: /3 mark AS CHECKBOX, 7 itab_tab-tab, dd02t-ddtext.
HIDE: itab_tab-tab.
ENDLOOP.
CLEAR itab_tab-tab.
ENDFORM. " VIEW_INDX_TAB
*&---------------------------------------------------------------------
*& Form VIEW_FIELD_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM view_field_tab.
SET PF-STATUS 'PFSTA04' EXCLUDING 'GRAF'.
WINDOW STARTING AT 15 5 ENDING AT 75 15.
LOOP AT itab_tab.
SELECT SINGLE * FROM dd02t
WHERE tabname = itab_tab-tab
AND ddlanguage = sy-langu.
WRITE: /3 itab_tab-tab, dd02t-ddtext.
HIDE: itab_tab-tab.
ENDLOOP.
CLEAR itab_tab-tab.
ENDFORM. " VIEW_FIELD_TAB
*&---------------------------------------------------------------------
*& Form CHOS_INDX_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM chos_indx_tab.
PERFORM get_line_check.
DESCRIBE TABLE itab_index LINES line_cnt.
IF line_cnt > 0.
PERFORM write_index.
ELSE.
MESSAGE s315 WITH 'Not Choose any table'.
ENDIF.
ENDFORM. " CHOS_INDX_TAB
*&---------------------------------------------------------------------
*& Form CHSE_VIEW_FIELD
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*-------------------------
INCLUDE <symbol>.
INCLUDE <line>.
TABLES: dd03l, " 테이블필드
dd01l, " 도메인
dd02t, " R/3-DD: SAP 테이블 텍스트
dd17s, " R/3 S_SECINDEX: 보조 인덱스, 필드
dd12t, " DD12L에 대한 텍스트 테이블
dd04t. " R/3 DD: Data element 텍스트
DATA: BEGIN OF itab_prog OCCURS 1,
code(120) TYPE c,
END OF itab_prog.
DATA: BEGIN OF itab_sql OCCURS 1,
code(120) TYPE c,
END OF itab_sql.
DATA: BEGIN OF itab_col OCCURS 1,
col(30) TYPE c,
alias(10) TYPE c,
END OF itab_col.
DATA: BEGIN OF itab_tab OCCURS 1,
tab(10) TYPE c,
alias(10) TYPE c,
END OF itab_tab.
DATA: BEGIN OF itab_write OCCURS 1,
data(120) TYPE c,
END OF itab_write.
DATA: BEGIN OF itab_into OCCURS 1,
code(120) TYPE c,
END OF itab_into.
DATA: BEGIN OF itab_del OCCURS 1,
tabix TYPE i,
code(120) TYPE c,
END OF itab_del.
DATA: BEGIN OF itab_index OCCURS 1,
tab(10) TYPE c,
index LIKE dd12l-dbindex,
index_text LIKE dd12t-ddtext,
index_field LIKE dd17s-fieldname,
field_text LIKE dd04t-ddtext,
plus TYPE c,
END OF itab_index.
DATA: BEGIN OF itab_len OCCURS 1,
len TYPE i,
END OF itab_len.
DATA: BEGIN OF itab_field OCCURS 1,
field LIKE dd03l-fieldname,
text(40) TYPE c,
END OF itab_field.
DATA: BEGIN OF itab_dist OCCURS 1,
code(120) TYPE c,
END OF itab_dist.
DATA: BEGIN OF fcode_tab OCCURS 10,
fcode(4),
END OF fcode_tab.
DATA: sql_tabix LIKE sy-tabix,
select_key(10) TYPE c,
etc(120) TYPE c.
DATA: temp_col(30) TYPE c,
temp_char TYPE c,
count1(3) TYPE n,
count2(2) TYPE n,
like_col(30) TYPE c,
col_lin TYPE i,
endlen(3) TYPE n VALUE 1.
DATA: from_flag TYPE c,
alias_flag TYPE c,
end_flag TYPE c,
update_flag TYPE c,
confirm_flag TYPE c.
DATA: col_length LIKE dd03l-leng.
DATA: prog(8) TYPE c,
msg(120) TYPE c,
msg_text(80) TYPE c,
subrc LIKE sy-subrc,
mark TYPE c VALUE 'X',
line_cnt TYPE i,
filesize TYPE i.
DATA: l_uname LIKE sy-uname.
INITIALIZATION.
START-OF-SELECTION.
l_uname = sy-uname.
CASE l_uname.
WHEN '권한허가자'. "추가
WHEN OTHERS.
MESSAGE s000 WITH '프로그램 실행권한없습니다'.
EXIT.
ENDCASE.
SET TITLEBAR '000'.
SET PF-STATUS 'YOSJSQL'.
*----------------------------------------------------------------------
* EXEC : SQL문 실행
* EDIT : SQL문 편집
* PLAN : SQL문 설명
* DOWN : SQL문 Download
* UPLD : SQL문 Upload
*----------------------------------------------------------------------
WRITE :/ 'Edit Your SQL ...' COLOR 5.
AT USER-COMMAND.
IF sy-ucomm = 'EDIT'.
PERFORM edit_sql.
PERFORM write_sql_report.
ELSEIF sy-ucomm = 'EXEC'.
IF update_flag = space.
PERFORM sql_generate USING 'Y' itab_col-col 'A'. "INIT FLAG ='Y'
IF sy-subrc <> 0.
EXIT.
ENDIF.
PERFORM check_sql_code.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Check your SQL statement!!!'.
EXIT.
ENDIF.
READ TABLE itab_col INDEX 1.
IF sy-subrc = 0.
PERFORM exec_sql.
ENDIF.
ELSE.
* IF SY-UNAME = 'WJCYR' or SY-UNAME = 'WJLDW'.
PERFORM confirm_update.
CASE confirm_flag.
WHEN 'N'. EXIT.
WHEN 'A'. EXIT.
WHEN 'J'. PERFORM exec_sql_update.
ENDCASE.
* ELSE.
* MESSAGE I315 WITH '당신에게는 그런 SQL을 쓸 권한이
*없습니다.'.
* EXIT.
* ENDIF.
ENDIF.
ELSEIF sy-ucomm = 'BBCK'.
sy-lsind = 0.
ELSEIF sy-ucomm = 'BCCK'.
REFRESH itab_index.
sy-lsind = sy-lsind - 3.
ELSEIF sy-ucomm = 'PLAN'.
PERFORM explain_sqltab(rsxplain) TABLES itab_sql
USING subrc.
ELSEIF sy-ucomm = 'INDX'.
PERFORM view_indx_tab.
ELSEIF sy-ucomm = 'TABL' OR sy-ucomm = 'DIST'.
IF sy-ucomm = 'TABL'.
SET TITLEBAR 'W03'.
ELSE.
SET TITLEBAR 'W05'.
ENDIF.
PERFORM view_field_tab.
ELSEIF sy-ucomm = 'CHOS'.
PERFORM chos_indx_tab.
ELSEIF sy-ucomm = 'CHSE'.
IF itab_tab-tab = space.
EXIT.
ENDIF.
IF sy-title = 'Choose Table for field search'.
PERFORM chse_view_field.
ELSEIF sy-title = 'Choose Table for field distribution'.
PERFORM chse_field_dist.
ELSEIF sy-title = 'Choose Field for distribution'.
PERFORM sel_field_dist.
ENDIF.
ELSEIF sy-ucomm = 'SASC'.
PERFORM exec_sasc.
ELSEIF sy-ucomm = 'SDES'.
PERFORM exec_sdes.
ELSEIF sy-ucomm = 'GRAF'.
PERFORM create_graf.
ELSEIF sy-ucomm = 'UPLD'.
PERFORM sql_upload.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Upload Error'.
EXIT.
ENDIF.
IF filesize <> 0.
PERFORM edit_sql.
PERFORM write_sql_report.
ENDIF.
ELSEIF sy-ucomm = 'DOWN'.
PERFORM sql_download.
IF sy-subrc <> 0.
MESSAGE i315 WITH 'Download Error'.
ENDIF.
ENDIF.
AT LINE-SELECTION.
IF sy-lsind >= 3 AND itab_index-index <> space.
PERFORM write_index_hier.
ELSEIF sy-pfkey = 'PFSTA04' AND itab_tab-tab <> space.
IF sy-title = 'Choose Table for field search'.
PERFORM chse_view_field.
ELSEIF sy-title = 'Choose Table for field distribution'.
PERFORM chse_field_dist.
ELSEIF sy-title = 'Choose Field for distribution'
AND itab_field-field <> space.
PERFORM sel_field_dist.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------
*& Form SQL_PARSING
*&---------------------------------------------------------------------
* SQL PARSING
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM sql_parsing.
DATA: aggr_flag TYPE c,
aggr_cnt TYPE i.
LOOP AT itab_sql.
IF sy-tabix = 1.
SHIFT itab_sql-code LEFT DELETING LEADING space.
ENDIF.
sql_tabix = sy-tabix + 1.
SPLIT itab_sql-code AT space INTO select_key etc.
* IF ETC(11) = '/*+ RULE */'.
* ETC(11) = ' '.
* ENDIF.
IF select_key = 'SELECT'.
CLEAR: temp_col, temp_char, count1, count2, from_flag, alias_flag
,
update_flag, end_flag.
DO.
temp_char = etc+count2(1).
IF temp_char = '('.
IF aggr_cnt = 0.
aggr_flag = 'Y'.
ENDIF.
aggr_cnt = aggr_cnt + 1.
ELSEIF temp_char = ')'.
aggr_cnt = aggr_cnt - 1.
IF aggr_cnt = 0.
aggr_flag = ' '.
ENDIF.
ENDIF.
IF temp_char = space OR temp_char = ','.
IF from_flag = 'Y'.
IF temp_col <> space AND temp_col <> 'WHERE'.
IF temp_char = space.
IF itab_tab-tab = space.
itab_tab-tab = temp_col.
alias_flag = 'Y'.
ELSE.
itab_tab-alias = temp_col.
ENDIF.
ELSEIF alias_flag <> 'Y'.
itab_tab-tab = temp_col.
APPEND itab_tab.
CLEAR itab_tab.
ELSEIF alias_flag = 'Y'.
itab_tab-alias = temp_col.
APPEND itab_tab.
CLEAR itab_tab.
CLEAR alias_flag.
ENDIF.
ELSEIF temp_col = 'WHERE'.
IF itab_tab-tab <> space.
COLLECT itab_tab.
ENDIF.
EXIT.
ENDIF.
CLEAR: temp_col, count1.
count2 = count2 + 1.
IF count2 >= 80.
PERFORM read_next_sql.
IF end_flag = 'Y'.
EXIT.
ENDIF.
ENDIF.
CONTINUE.
ELSE.
IF temp_col <> space AND temp_col <> 'FROM'
AND temp_col <> 'DISTINCT'
AND ( temp_char = ',' OR temp_char = ' ' )
AND aggr_flag = ' ' .
SEARCH temp_col FOR '('.
IF sy-fdpos = 0.
SPLIT temp_col AT '.' INTO itab_col-alias itab_col-col.
IF itab_col-col = space.
itab_col-col = itab_col-alias.
CLEAR itab_col-alias.
ENDIF.
ELSE.
itab_col-col = temp_col.
ENDIF.
APPEND itab_col.
ELSEIF temp_col = 'FROM'.
from_flag = 'Y'.
ENDIF.
IF aggr_flag <> 'Y'.
CLEAR: temp_col, count1.
ELSE.
IF temp_char <> '''' AND temp_char <> ','
AND count1 < 28.
temp_col+count1(1) = etc+count2(1).
count1 = count1 + 1.
ENDIF.
ENDIF.
count2 = count2 + 1.
IF count2 >= 80.
PERFORM read_next_sql.
IF end_flag = 'Y'.
EXIT.
ENDIF.
ENDIF.
CONTINUE.
ENDIF.
ELSE.
IF temp_char <> '''' AND temp_char <> ',' AND count1 < 28.
temp_col+count1(1) = etc+count2(1).
ENDIF.
ENDIF.
count1 = count1 + 1.
count2 = count2 + 1.
ENDDO.
IF itab_tab-tab <> space.
COLLECT itab_tab.
ENDIF.
ELSEIF select_key = 'DELETE' OR select_key = 'UPDATE'
OR select_key = 'INSERT'.
update_flag = 'Y'.
ENDIF.
ENDLOOP.
ENDFORM. " SQL_PARSING
*&---------------------------------------------------------------------
*& Form READ_NEXT_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM read_next_sql.
READ TABLE itab_sql INDEX sql_tabix.
IF sy-subrc <> 0.
end_flag = 'Y'.
EXIT.
ENDIF.
etc = itab_sql-code.
sql_tabix = sql_tabix + 1.
CLEAR: temp_col, count1, count2.
ENDFORM. " READ_NEXT_SQL
*&---------------------------------------------------------------------
*& Form DECLARE_HEADER
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM declare_header.
itab_prog-code = 'PROGRAM SUBPOOL.'.
APPEND itab_prog.
itab_prog-code = 'DATA REC_COUNT(7) TYPE N.'.
APPEND itab_prog.
itab_prog-code = 'DATA: BEGIN OF ITAB_DATA OCCURS 1,'.
APPEND itab_prog.
itab_write-data = 'WRITE: /1 '.
APPEND itab_write.
DESCRIBE TABLE itab_col LINES col_lin.
LOOP AT itab_col.
count1 = sy-tabix.
READ TABLE itab_tab WITH KEY alias = itab_col-alias.
CONCATENATE 'COL' count1 INTO temp_col.
SEARCH itab_col-col FOR '('.
IF sy-fdpos <> 0.
CONCATENATE 'COL' count1 '(15)' INTO itab_prog-code.
CONCATENATE itab_prog-code 'TYPE C,'
INTO itab_prog-code SEPARATED BY space.
ELSE.
CONCATENATE itab_tab-tab '-' itab_col-col INTO like_col.
CONCATENATE temp_col 'LIKE' like_col ','
INTO itab_prog-code SEPARATED BY space.
ENDIF.
APPEND itab_prog.
IF count1 = 1 AND count1 <> col_lin.
CONCATENATE 'INTO :ITAB_DATA-' temp_col ',' INTO itab_into-code.
APPEND itab_into.
CONCATENATE 'SY-VLINE, ITAB_DATA-' temp_col ','
INTO itab_write-data.
APPEND itab_write.
ELSEIF count1 < col_lin.
CONCATENATE ':ITAB_DATA-' temp_col ',' INTO itab_into-code.
APPEND itab_into.
CONCATENATE 'SY-VLINE, ITAB_DATA-' temp_col ','
INTO itab_write-data.
APPEND itab_write.
ELSE.
IF count1 = 1.
CONCATENATE 'INTO :ITAB_DATA-' temp_col INTO itab_into-code.
APPEND itab_into.
ELSE.
CONCATENATE ':ITAB_DATA-' temp_col INTO itab_into-code.
APPEND itab_into.
ENDIF.
CONCATENATE ' SY-VLINE,ITAB_DATA-' temp_col ', SY-VLINE.'
INTO itab_write-data.
APPEND itab_write.
ENDIF.
ENDLOOP.
itab_prog-code = ' END OF ITAB_DATA.'.
APPEND itab_prog.
itab_prog-code = 'FORM DYN1.'.
APPEND itab_prog.
ENDFORM. " DECLARE_HEADER
*&---------------------------------------------------------------------
*& Form WRITE_EXEC_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_exec_sql.
DATA: res_sql(80) TYPE c,
res_len TYPE i,
into_tabix LIKE sy-tabix,
order_flag TYPE c.
itab_prog-code = 'EXEC SQL PERFORMING WRITE_DATA.'.
APPEND itab_prog.
SEARCH itab_sql FOR 'FROM'.
READ TABLE itab_sql INDEX sy-tabix.
IF sy-fdpos <> 0 AND sy-fdpos <> 1.
res_sql = itab_sql-code+0(sy-fdpos).
res_len = 80 - sy-fdpos.
itab_sql-code = itab_sql-code+sy-fdpos(res_len).
MODIFY itab_sql INDEX sy-tabix.
itab_sql-code = res_sql.
INSERT itab_sql INDEX sy-tabix.
sy-tabix = sy-tabix + 1.
ENDIF.
into_tabix = sy-tabix.
LOOP AT itab_into.
itab_sql-code = itab_into-code.
INSERT itab_sql INDEX into_tabix.
into_tabix = into_tabix + 1.
ENDLOOP.
SEARCH itab_sql FOR 'ORDER BY'.
IF sy-subrc = 0.
order_flag = 'Y'.
READ TABLE itab_sql INDEX sy-tabix.
IF sy-fdpos <> 0 AND sy-fdpos <> 1.
res_sql = itab_sql-code+0(sy-fdpos).
res_len = 80 - sy-fdpos.
itab_sql-code = itab_sql-code+sy-fdpos(res_len).
MODIFY itab_sql INDEX sy-tabix.
itab_sql-code = res_sql.
INSERT itab_sql INDEX sy-tabix.
sy-tabix = sy-tabix + 1.
ENDIF.
ELSE.
order_flag = 'N'.
ENDIF.
LOOP AT itab_sql.
IF sy-tabix > 1 AND itab_sql-code+0(1) <> space.
itab_sql-code+1(79) = itab_sql-code+0(79).
itab_sql-code+0(1) = ' '.
MODIFY itab_sql INDEX sy-tabix.
ENDIF.
itab_prog-code = itab_sql-code.
APPEND itab_prog.
ENDLOOP.
* IF ORDER_FLAG = 'N'.
* READ TABLE ITAB_COL INDEX 1.
* SEARCH ITAB_SQL FOR '('.
* IF SY-SUBRC <> 0.
* CONCATENATE 'ORDER BY' ITAB_COL-COL
* INTO ITAB_PROG-CODE SEPARATED BY SPACE.
* APPEND ITAB_PROG.
* ENDIF.
* ENDIF.
itab_prog-code = 'ENDEXEC.'.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
APPEND itab_prog.
itab_prog-code = 'SET TITLEBAR ''001'' WITH REC_COUNT ''Records''.'.
APPEND itab_prog.
itab_prog-code = 'ENDFORM.'.
APPEND itab_prog.
ENDFORM. " WRITE_EXEC_SQL
*&---------------------------------------------------------------------
*& Form WRITE_DATA
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_data.
itab_prog-code = 'FORM WRITE_DATA.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT INTENSIFIED OFF.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT COLOR 2.'.
APPEND itab_prog.
LOOP AT itab_write.
itab_prog-code = itab_write-data.
APPEND itab_prog.
ENDLOOP.
itab_prog-code = 'REC_COUNT = REC_COUNT + 1.'.
APPEND itab_prog.
itab_prog-code = 'ENDFORM.'.
APPEND itab_prog.
ENDFORM. " WRITE_DATA
*&---------------------------------------------------------------------
*& Form WRITE_HEADER
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_header.
DATA: domname LIKE dd03l-domname,
uline_tabix LIKE sy-tabix.
itab_prog-code = 'FORMAT INTENSIFIED ON.'.
APPEND itab_prog.
itab_prog-code = 'FORMAT COLOR 1.'.
APPEND itab_prog.
uline_tabix = sy-tabix + 1.
itab_prog = 'WRITE: /1 '.
APPEND itab_prog.
LOOP AT itab_col.
READ TABLE itab_tab WITH KEY alias = itab_col-alias.
SELECT SINGLE domname INTO domname
FROM dd03l
WHERE tabname = itab_tab-tab
AND fieldname = itab_col-col.
IF sy-subrc = 0.
SELECT SINGLE outputlen INTO col_length
FROM dd01l
WHERE domname = domname
AND as4local = 'A'.
CONCATENATE '(' col_length ')' INTO temp_col.
endlen = col_length + 3 + endlen.
ELSE.
CONCATENATE '(' '15' ')' INTO temp_col.
endlen = 18 + endlen.
ENDIF.
itab_len-len = endlen.
APPEND itab_len.
CONCATENATE '''' itab_col-col '''' INTO itab_col-col.
CONCATENATE 'SY-VLINE,' temp_col itab_col-col
'CENTERED,' INTO itab_prog SEPARATED BY space.
APPEND itab_prog.
ENDLOOP.
itab_prog = 'SY-VLINE.'.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
APPEND itab_prog.
CONCATENATE 'ULINE /1' '(' endlen ')' '.' INTO itab_prog-code.
INSERT itab_prog INDEX uline_tabix.
CONCATENATE 'NEW-PAGE LINE-SIZE' endlen '.' INTO itab_prog-code
SEPARATED BY space.
INSERT itab_prog INDEX uline_tabix.
ENDFORM. " WRITE_HEADER
*&---------------------------------------------------------------------
*& Form TRANS_UPPER_ITAB_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM trans_upper_itab_sql.
DATA: save_tabix LIKE sy-tabix,
tabix_count TYPE i.
DATA: l_pos TYPE i, l_upper, l_flag,
l_abc(52) VALUE
'ABCDEFGHIJKLMNOPQRSTUVWXYZabdefghijklmnopqrstuvwxyz'.
REFRESH itab_del.
LOOP AT itab_sql.
save_tabix = sy-tabix.
tabix_count = tabix_count + 1.
IF itab_sql-code = space OR itab_sql-code+0(1) = '*'.
IF itab_sql-code+0(1) = '*'.
CLEAR itab_del.
itab_del-tabix = tabix_count.
itab_del-code = itab_sql-code.
APPEND itab_del.
ENDIF.
DELETE itab_sql INDEX save_tabix.
CONTINUE.
ENDIF.
CLEAR l_flag.
DO 80 TIMES.
l_pos = sy-index - 1.
l_upper = itab_sql-code+l_pos(1).
IF l_upper = '''' AND l_flag = ''.
l_flag = 'X'.
ELSEIF l_upper = '''' AND l_flag = 'X'.
CLEAR l_flag.
ENDIF.
IF l_flag = 'X'.
CONTINUE.
ENDIF.
IF l_abc NS l_upper.
CONTINUE.
ENDIF.
TRANSLATE l_upper TO UPPER CASE.
itab_sql-code+l_pos(1) = l_upper.
* TRANSLATE ITAB_SQL-CODE TO UPPER CASE.
ENDDO.
MODIFY itab_sql INDEX save_tabix.
ENDLOOP.
ENDFORM. " TRANS_UPPER_ITAB_SQL
*&---------------------------------------------------------------------
*& Form CLEAR_VAR
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM clear_var.
REFRESH: itab_prog, itab_col, itab_write, itab_into, itab_tab.
CLEAR: itab_prog, itab_col, itab_write, itab_into, itab_tab.
endlen = 1.
ENDFORM. " CLEAR_VAR
*&---------------------------------------------------------------------
*& Form EDIT_SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM edit_sql.
DATA: changed LIKE s38e-buf_varied,
fcode LIKE sy-ucomm,
subrc LIKE sy-subrc.
LOOP AT itab_del.
itab_sql-code = itab_del-code.
INSERT itab_sql INDEX itab_del-tabix.
ENDLOOP.
CALL FUNCTION 'EDITOR_APPLICATION'
EXPORTING
application = 'BF'
display = ' '
name = 'Input Your SQL......'
IMPORTING
fcode = fcode
changed = changed
TABLES
content = itab_sql.
* CASE FCODE.
* WHEN 'BACK'. SUBRC = 4.
* WHEN 'UPD'. SUBRC = 0.
* WHEN OTHERS. SUBRC = 8.
* ENDCASE.
* IF SUBRC <> 0.
* PERFORM CLEAR_VAR.
* REFRESH ITAB_SQL.
* EXIT.
* ENDIF.
PERFORM clear_var.
PERFORM trans_upper_itab_sql.
PERFORM sql_parsing.
IF update_flag = 'Y'.
REFRESH fcode_tab.
fcode_tab = 'PLAN'.
APPEND fcode_tab.
fcode_tab = 'INDX'.
APPEND fcode_tab.
fcode_tab = 'TABL'.
APPEND fcode_tab.
fcode_tab = 'DIST'.
APPEND fcode_tab.
SET PF-STATUS 'YOSJSQL' EXCLUDING fcode_tab.
EXIT.
ENDIF.
SET PF-STATUS 'YOSJSQL'.
READ TABLE itab_col INDEX 1.
IF itab_col-col = '*'.
PERFORM get_itab_col_all.
ELSEIF itab_col-col = '/*+'.
DELETE itab_col FROM 1 TO 3.
ENDIF.
PERFORM declare_header.
PERFORM write_header.
PERFORM write_exec_sql.
PERFORM write_data.
SEARCH itab_sql FOR 'INTO'.
IF sy-subrc = 0.
LOOP AT itab_sql FROM sy-tabix.
IF itab_sql-code+1(4) <> 'FROM'.
DELETE itab_sql INDEX sy-tabix.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " EDIT_SQL
*&---------------------------------------------------------------------
*& Form GET_LINE_CHECK
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM get_line_check.
DATA: cur_line TYPE i.
cur_line = 1.
DO.
CLEAR mark.
READ LINE cur_line FIELD VALUE mark.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF mark = 'X'.
PERFORM get_primary_index.
CLEAR itab_index.
itab_index-plus = '4'.
itab_index-tab = itab_tab-tab.
SELECT * FROM dd17s
WHERE sqltab = itab_tab-tab
ORDER BY position.
itab_index-index = itab_tab-tab.
itab_index-index+10(3) = dd17s-indexname.
SELECT SINGLE * FROM dd12t
WHERE ddlanguage = 'E'
AND sqltab = itab_tab-tab
AND indexname = dd17s-indexname.
itab_index-index_text = dd12t-ddtext.
SELECT SINGLE * FROM dd03l
WHERE tabname = itab_tab-tab
AND fieldname = dd17s-fieldname.
IF sy-subrc = 0.
SELECT SINGLE ddtext FROM dd04t
INTO itab_index-field_text
WHERE rollname = dd03l-rollname
AND ddlanguage = 'E'.
ENDIF.
itab_index-index_field = dd17s-fieldname.
COLLECT itab_index.
ENDSELECT.
ENDIF.
cur_line = cur_line + 1.
ENDDO.
ENDFORM. " GET_LINE_CHECK
*&---------------------------------------------------------------------
*& Form WRITE_INDEX
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_index.
DATA: temp_index LIKE itab_index.
SET PF-STATUS 'PFSTA03'.
SET TITLEBAR 'W02'.
NEW-PAGE LINE-SIZE 100.
LOOP AT itab_index.
MOVE-CORRESPONDING itab_index TO temp_index.
AT NEW tab.
SKIP 2.
WRITE: /1 'List Index for Table.' COLOR 1,
' - ', itab_index-tab COLOR 4.
ULINE: /1(83).
ENDAT.
AT NEW index.
IF temp_index-plus = '4'.
WRITE: /3 sy-vline, /3(2) sy-uline,
sym_plus_folder AS SYMBOL HOTSPOT ON COLOR 7,
itab_index-index COLOR 3,
temp_index-index_text COLOR 2.
HIDE: itab_index-index.
ELSE.
WRITE: /3 sy-vline, /3(2) sy-uline,
sym_minus_folder AS SYMBOL HOTSPOT ON COLOR 7,
itab_index-index COLOR 3,
temp_index-index_text COLOR 2.
HIDE: itab_index-index.
LOOP AT itab_index WHERE index = temp_index-index.
IF sy-tabix = 1.
WRITE: /9 sy-vline, /9 line_bottom_left_corner AS LINE,
itab_index-index_field COLOR 2.
ELSE.
WRITE: /9 line_bottom_left_corner AS LINE,
itab_index-index_field COLOR 2.
ENDIF.
WRITE: itab_index-field_text
UNDER temp_index-index_text COLOR 2.
ENDLOOP.
ENDIF.
ENDAT.
ENDLOOP.
CLEAR itab_index-index.
ENDFORM. " WRITE_INDEX
*&---------------------------------------------------------------------
*& Form GET_PRIMARY_INDEX
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM get_primary_index.
CLEAR itab_index.
itab_index-plus = '4'.
itab_index-tab = itab_tab-tab.
itab_index-index = itab_tab-tab.
itab_index-index+10(1) = '0'.
itab_index-index_text = 'Primary Key'.
SELECT * FROM dd03l
WHERE tabname = itab_tab-tab
ORDER BY position.
SELECT SINGLE ddtext FROM dd04t
INTO itab_index-field_text
WHERE rollname = dd03l-rollname
AND ddlanguage = 'E'.
itab_index-index_field = dd03l-fieldname.
APPEND itab_index.
ENDSELECT.
ENDFORM. " GET_PRIMARY_INDEX
*&---------------------------------------------------------------------
*& Form EXEC-SQL
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM exec_sql.
* SET TITLEBAR '001'.
SET PF-STATUS 'PFSTA01'.
PERFORM dyn1 IN PROGRAM (prog).
ENDFORM. " EXEC_SQL
*&---------------------------------------------------------------------
*& Form WRITE_SQL_REPORT
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM write_sql_report.
sy-lsind = 0.
DESCRIBE TABLE itab_sql LINES line_cnt.
IF line_cnt = 0 OR ( line_cnt = 1 AND itab_sql-code = space ).
WRITE: /1 'Edit Your SQL ................' COLOR 2.
ELSE.
LOOP AT itab_sql.
WRITE: /1 itab_sql-code.
ENDLOOP.
ENDIF.
ENDFORM. " WRITE_SQL_REPORT
*&---------------------------------------------------------------------
*& Form VIEW_INDX_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM view_indx_tab.
SET TITLEBAR 'W01'.
SET PF-STATUS 'PFSTA02'.
WINDOW STARTING AT 15 5 ENDING AT 75 15.
LOOP AT itab_tab.
SELECT SINGLE * FROM dd02t
WHERE tabname = itab_tab-tab
AND ddlanguage = sy-langu.
WRITE: /3 mark AS CHECKBOX, 7 itab_tab-tab, dd02t-ddtext.
HIDE: itab_tab-tab.
ENDLOOP.
CLEAR itab_tab-tab.
ENDFORM. " VIEW_INDX_TAB
*&---------------------------------------------------------------------
*& Form VIEW_FIELD_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM view_field_tab.
SET PF-STATUS 'PFSTA04' EXCLUDING 'GRAF'.
WINDOW STARTING AT 15 5 ENDING AT 75 15.
LOOP AT itab_tab.
SELECT SINGLE * FROM dd02t
WHERE tabname = itab_tab-tab
AND ddlanguage = sy-langu.
WRITE: /3 itab_tab-tab, dd02t-ddtext.
HIDE: itab_tab-tab.
ENDLOOP.
CLEAR itab_tab-tab.
ENDFORM. " VIEW_FIELD_TAB
*&---------------------------------------------------------------------
*& Form CHOS_INDX_TAB
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
FORM chos_indx_tab.
PERFORM get_line_check.
DESCRIBE TABLE itab_index LINES line_cnt.
IF line_cnt > 0.
PERFORM write_index.
ELSE.
MESSAGE s315 WITH 'Not Choose any table'.
ENDIF.
ENDFORM. " CHOS_INDX_TAB
*&---------------------------------------------------------------------
*& Form CHSE_VIEW_FIELD
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
* --> p1 text
* <-- p2 text
*-------------------------
긁어서 실행해봤는데 Form이 몇가지 빠진게 있습니다. ㅠ