SQL tool for SAP – Open & Native Sql

Be carefulll!!!!! These version of SQL Tool is modified by me to permit also UPDATE and DELETE!!!!

1.jpg

Read “SAP Table and Field search strategies” in http://sapabap.iespana.es/sapabap/sap/info/search_fields_tables.htm
Use SAP_TABLES.exe in http://mysapmynavision.myblog.it/archive/2008/03/28/sap-tables.html and many other excellent resources to navigate the cryptic tables & Colums of SAP

SE16 is the best for 1 table inspection & you can open several sessions if you have more than 1 table. You may “hate joins” and prefer looping matches on Internal Tables. However if you wish to see the relationships in DATA VISIBLE format NOTHING succeeds like JOINs I came in with a Strong Oracle TOAD background and feel comfortable in seeing DATA together.

The decision to use JOIN or use iterative Internal Table match with single select does not detract from the visibility of tracking relationships

SQL Must be SELECT (Not in this modified version!!!!)
List of Columns Selected before 1st FROM Must Have
1 Column per line in format TABLE~COLUMN if Open SQL
1 Column per line in format TABLE.COLUMN if Native SQL

Naturally tables & Columns must exist as this used to dynamically create Internal Table for ALV Grid.

Count( ) is NOT SUPPORTED but you could Use Native COUNT( any NOT NULL NUMERIC COLUMN )

SUM MIN MAX AVG supported.
SUM( table~COLUMN ) or SUM( table.COLUMN ) but there must be 1 space as indicated after ( and before ) — even for native.

If you use NATIVE SQL make sure you have :SY-MANDT filter in WHERE Clause.

You CAN pick 2 COLUMNS having same name – this is important for inspection.

Program creates right aliases as you can see in c:jnc.ab4. jnc.ab4 is the generated ABAP program for diagnostics and possible reuse.

JOINs and SUBQUERIES are NOT ALLOWED for
Pooled Tables, Clustered Tables & Projection Views
Even AGGREGATE Functions are NOT ALLOWED! — thse restrictions are inherent in SAP

So this tool is useful for TRANSPARENT TABLES only!

Download here the source code and the screen (be careful becouse you could destroy data)

Here the code to show changes:

REPORT zyes4sql.

************************************************************************
* UPDATE & DELETE functions added by Pedrocchi Dario
* http://mysapmynavision.myblog.it/sap/
************************************************************************

*in http://sapabap.iespana.es/sapabap/sap/info/search_fields_tables.htm

*The decision to use JOIN or use iterative Internal Table match with
*single select
* does not detract from the visibility of tracking relationships

* SQL Must be SELECT
* List of Columns Selected before 1st FROM Must Have
* 1 Column per line in format TABLE~COLUMN if Open SQL
* 1 Column per line in format TABLE.COLUMN if Native SQL

* Naturally tables & Columns must exist
* as this used to dynamically create Internal Table for ALV Grid
*
*Count( * ) is NOT SUPPORTED but you could Use Native COUNT( any NOT
*NULL NUMERIC COLUMN )

* SUM MIN MAX AVG supported
* SUM( table~COLUMN ) or SUM( table.COLUMN )
*but there must be 1 space as indicated after ( and before ) — even for
*native

*If you use NATIVE SQL make sure you have :SY-MANDT filter in WHERE
*Clause

*You CAN pick 2 COLUMNS having same name – this is important for
*inspection
* Program creates right aliases as you can see in c:jnc.ab4
*jnc.ab4 is the generated ABAP program for diagnostics and possible
*reuse

* JOINs and SUBQUERIES are NOT ALLOWED for
* Pooled Tables, Clustered Tables & Projection Views
*Even AGGREGATE Functions are NOT ALLOWED! — thse restrictions are
*inherent in SAP

* So this tool is useful for TRANSPARENT TABLES only!

DATA : BEGIN OF int_tab OCCURS 0,
wfld1
LIKE mard-matnr,
wfld2
LIKE makt-maktx.
DATA : END OF int_tab.

************************ START MODIFY ************************
DATA del.
DATA upd.
************************* END MODIFY *************************

DATA:
* reference to wrapper class of control based on OO Framework
g_editor
TYPE REF TO cl_gui_textedit,
* reference to custom container: necessary to bind TextEdit Control
g_editor_container
TYPE REF TO cl_gui_custom_container,
* other variables
g_ok_code
LIKE sy-ucomm, ” return code from screen
g_repid
LIKE sy-repid.

DATA: rows TYPE i VALUE 9999,
isopen
TYPE c VALUE ,
delim
TYPE c,
************************ START MODIFY ************************
pbp
TYPE c.
************************* END MODIFY *************************

DATA: code TYPE TABLE OF rssource-line,
prog(
8) TYPE c,
msg(
120) TYPE c,
lin(
3) TYPE c,
wrd(
10) TYPE c,
off(
3) TYPE c.

DATA: onelinecode LIKE LINE OF code.

TYPE-POOLS : slis.

DATA : fcat TYPE slis_t_fieldcat_alv.
DATA : wcat LIKE LINE OF fcat.

CONSTANTS: c_line_length TYPE i VALUE 80.

* define table type for data exchange
TYPES: BEGIN OF mytable_line,
line(c_line_length) TYPE c,
END OF mytable_line.

* table to exchange text
DATA g_mytable TYPE TABLE OF mytable_line.

DATA: myline LIKE LINE OF g_mytable.

* necessary to flush the automation queue
CLASS cl_gui_cfw DEFINITION LOAD.

START-OF-SELECTION.

************************ START MODIFY ************************
CLEAR: del, upd.
************************* END MODIFY *************************

AUTHORITY-CHECK OBJECT ‘ZCRM_SQL’
ID ‘ACTVT’ FIELD ’16’.

IF sy-subrc <> 0.
MESSAGE e000(/vwk/crm_yes4sql).
* No authorization for transaction YES4SQL.
ENDIF.

CALL SCREEN 100.

************************************************************************
* P B O
************************************************************************
MODULE pbo OUTPUT.

SET PF-STATUS ‘MAIN100’.
SET TITLEBAR ‘TITLEYES4SQL’.

IF g_editor IS INITIAL.

* initilize local variable with sy-repid, since sy-repid doesn’t work
* as parameter directly.
g_repid = sy-repid.

* create control container
CREATE OBJECT g_editor_container
EXPORTING
container_name =
‘MYEDIT’
EXCEPTIONS
cntl_error =
1
cntl_system_error =
2
create_error =
3
lifetime_error =
4
lifetime_dynpro_dynpro_link =
5.
IF sy-subrc NE 0.
* add your handling
ENDIF.

* create calls constructor, which initializes, creats and links
* a TextEdit Control
CREATE OBJECT g_editor
EXPORTING
parent = g_editor_container
wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_to_linebreak_mode = cl_gui_textedit=>true
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Create Object Failed’
txt1 =
‘to make TextEditor Control’.
LEAVE PROGRAM.
ENDIF.

ENDIF. ” Editor is initial

* remember: there is an automatic flush at the end of PBO!

ENDMODULE. ” PBO

************************************************************************
* P A I
************************************************************************
MODULE pai INPUT.

CASE g_ok_code.

WHEN ‘EXIT’.
PERFORM exit_program.

WHEN ‘EXEC’.
* retrieve table from control
CLEAR g_mytable.

CALL METHOD g_editor->get_text_as_r3table
IMPORTING
table = g_mytable
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Get_Text_As_R3Table Failed’
txt1 =
‘Unable to Store SQL’.
LEAVE PROGRAM.
ENDIF.

* if you would like to work with the table contents
* perform a explicit flush here allthough the method
* flushes internally (at least up to release 4.6D).
* The reason: don’t rely on internal flushes of control
* wrappers. These might vanish in the future leading to a
* malfunction of your transaction. The additional flush here
* does no harm. The autmation queue is empty and NO additional
* roundtrip to the frontend will be triggered.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘cl_gui_cfw=>flush Failed’
txt1 =
‘Exiting Program’.
LEAVE PROGRAM.
ENDIF.

PERFORM f_runsql.

ENDCASE.

CLEAR g_ok_code.
ENDMODULE. ” PAI

************************************************************************
* F O R M S
************************************************************************

*&———————————————————————*
*& Form EXIT_PROGRAM
*&———————————————————————*
FORM exit_program.
* Destroy Control.
IF NOT g_editor IS INITIAL.
CALL METHOD g_editor->free
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘g_editor->free Failed’
txt1 =
‘Exiting Program’.
LEAVE PROGRAM.
ENDIF.
* free ABAP object also
FREE g_editor.
ENDIF.

* destroy container
IF NOT g_editor_container IS INITIAL.
CALL METHOD g_editor_container->free
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
* MESSAGE E002 WITH F_RETURN.
ENDIF.
* free ABAP object also
FREE g_editor_container.
ENDIF.

* finally flush
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘cl_gui_cfw=>flush Failed’
txt1 =
‘Exiting Program’.
LEAVE PROGRAM.
ENDIF.

LEAVE PROGRAM.

ENDFORM. ” EXIT_PROGRAM

*&———————————————————————*
*& Form F_RUNSQL
*&———————————————————————*
FORM f_runsql.

DATA: first TYPE i,
numcols
TYPE i,
aggfun
TYPE i,
pos
TYPE i,
off
TYPE i,
len
TYPE i,
numrows
TYPE i,
rownum
TYPE i,
mystring
TYPE string,
mystring2
TYPE string,
crows(
10) TYPE c.

DATA : BEGIN OF tblcol_tab OCCURS 0,
tbl
TYPE string,
col
TYPE string.
DATA : END OF tblcol_tab.

IF rows IS INITIAL.
MOVE 100 TO rows.
ENDIF.

CLEAR: code, tblcol_tab.
REFRESH: tblcol_tab.

MOVE 0 TO : first, numcols, aggfun.

LOOP AT g_mytable INTO myline.
CONCATENATE ‘ ‘ myline ‘ ‘ INTO myline SEPARATED BY space..

IF STRLEN( myline ) = 0.
CONTINUE.
ENDIF.

IF first = 0.
************************ START MODIFY ************************
FIND ‘ Delete ‘ IN myline IGNORING CASE.
IF sy-subrc = 0.
del =
‘X’.
ENDIF.

FIND ‘ Update ‘ IN myline IGNORING CASE.
IF sy-subrc = 0.
upd =
‘X’.
ENDIF.

IF del IS INITIAL AND upd IS INITIAL.
************************* END MODIFY *************************

FIND ‘ Select ‘ IN myline IGNORING CASE.
IF sy-subrc <> 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘SELECT DMLs Only Please!’
txt1 =
‘Correct & Retry’.
RETURN.
ENDIF.
************************ START MODIFY ************************
ENDIF.
************************* END MODIFY *************************
MOVE 1 TO first.
ENDIF.

************************ START MODIFY ************************
IF del IS INITIAL AND upd IS INITIAL.
************************* END MODIFY *************************
FIND ‘ From ‘ IN myline IGNORING CASE.
IF sy-subrc = 0.
EXIT.
ENDIF.
************************ START MODIFY ************************
ENDIF.
************************* END MODIFY *************************
IF isopen = ‘X’.
MOVE ‘~’ TO delim.
ELSE.
MOVE ‘.’ TO delim.
ENDIF.

FIND delim IN myline MATCH OFFSET off.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.

ADD 1 TO numcols.

COMPUTE pos = off – 1.

DO.
IF myline+pos(1) = space.
EXIT.
ENDIF.
SUBTRACT 1 FROM pos.
ENDDO.

ADD 1 TO pos.
COMPUTE len = off – pos.
MOVE myline+pos(len) TO tblcol_tab-tbl.
MOVE myline+pos(len) TO mystring.

COMPUTE pos = off + 1.

DO.
IF myline+pos(1) = space OR myline+pos(1) = ‘,’.
EXIT.
ENDIF.
ADD 1 TO pos.
ENDDO.

SUBTRACT 1 FROM pos.
COMPUTE len = pos – off.
COMPUTE pos = off + 1.
MOVE myline+pos(len) TO tblcol_tab-col.
APPEND tblcol_tab.

CONCATENATE mystring delim myline+pos(len) INTO mystring.

WRITE numcols TO crows.
CONCATENATE ‘WFLD’ crows INTO mystring2.
CONDENSE mystring2 NO-GAPS.

FIND ‘)’ IN myline.
IF sy-subrc = 0.
MOVE 1 TO aggfun.
CONCATENATE ‘) as’ mystring2 INTO mystring2 SEPARATED BY space.
REPLACE ‘)’ IN myline WITH mystring2.
ELSE.
CONCATENATE mystring ‘as’ mystring2 INTO mystring2 SEPARATED BY
space.
REPLACE mystring IN myline WITH mystring2.
ENDIF.

MODIFY g_mytable FROM myline.

ENDLOOP.

************************ START MODIFY ************************
IF del IS INITIAL AND upd IS INITIAL.
************************* END MODIFY *************************
IF LINES( tblcol_tab ) = 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Table~Column Open SQL is MUST’
txt1 =
‘Table.Column Native SQL is MUST’.
RETURN.
ENDIF.
************************ START MODIFY ************************
ELSE.
* for ALV compatibility but not used – NO ALV RESULT*
tblcol_tab-tbl =
‘KNA1’.
tblcol_tab-col =
‘KUNNR’.
APPEND tblcol_tab.
ENDIF.
************************* END MODIFY *************************

APPEND ‘Program SubPool.’ TO code.
APPEND TO code.

APPEND ‘data : begin of I_TAB occurs 0,’ TO code.

numrows = LINES( tblcol_tab ).

MOVE 0 TO rownum.

LOOP AT tblcol_tab.
ADD 1 TO rownum.
WRITE rownum TO crows.
CONCATENATE ‘WFLD’ crows INTO mystring.
CONDENSE mystring NO-GAPS.

CONCATENATE mystring ‘Like’ tblcol_tab-tbl INTO mystring SEPARATED
BY space.

IF rownum = numrows.
CONCATENATE mystring ‘-‘ tblcol_tab-col ‘.’ INTO mystring.
ELSE.
CONCATENATE mystring ‘-‘ tblcol_tab-col ‘,’ INTO mystring.
ENDIF.
APPEND mystring TO code.
ENDLOOP.
APPEND ‘data : end of I_TAB.’ TO code.

GENERATE SUBROUTINE POOL code NAME prog
MESSAGE msg
LINE lin
WORD wrd
OFFSET off.

APPEND TO code.
APPEND ‘DATA : R_TAB LIKE LINE OF I_TAB,’ TO code.
APPEND ‘ L_KOUNT type I.’ TO code.
APPEND TO code.

APPEND ‘DATA : MyString type STRING.’ TO code.
APPEND ‘DATA : MyTitle type LVC_TITLE.’ TO code.
APPEND TO code.

APPEND ‘Data: ROWS type I.’ TO code.
APPEND TO code.

************************ START MODIFY ************************
APPEND ‘Data: txt(120).’ TO code.
APPEND TO code.
************************* END MODIFY *************************

APPEND ‘Form DoSQL.’ TO code.
APPEND TO code.
WRITE rows TO crows.
REPLACE ALL OCCURRENCES OF ‘.’ IN crows WITH .
CONCATENATE ‘Move’ crows ‘to ROWS.’ INTO mystring SEPARATED BY space.
APPEND mystring TO code.
APPEND TO code.

MOVE 0 TO rownum.
LOOP AT tblcol_tab.
ADD 1 TO rownum.
IF rownum = 1.
CONCATENATE ‘ Move ”’ tblcol_tab-col ”’ to MyString.’ INTO
mystring.
APPEND mystring TO code.
ELSE.
CONCATENATE ‘ Concatenate MyString ”,” ”’ tblcol_tab-col
”’ Into MyString.’ INTO mystring.
APPEND mystring TO code.
ENDIF.
APPEND ‘ Move MyString to MyTitle.’ TO code.
APPEND TO code.
ENDLOOP.

APPEND TO code.
APPEND ‘Try.’ TO code.
APPEND TO code.

************************ START MODIFY ************************
IF del IS INITIAL AND upd IS INITIAL.
************************* END MODIFY *************************
IF isopen <> ‘X’.
APPEND ‘Move 0 to L_KOUNT.’ TO code.
APPEND ‘EXEC SQL.’ TO code.
APPEND ‘ open c1 for ‘ TO code.
ENDIF.

MOVE 0 TO first.
LOOP AT g_mytable INTO myline.
IF isopen = ‘X’ AND first = 0.
FIND ‘ From ‘ IN myline IGNORING CASE.
IF sy-subrc = 0.
APPEND ‘Into Table I_TAB’ TO code.
IF aggfun = 0.
APPEND ‘Up To ROWS rows’ TO code.
ENDIF.
MOVE 1 TO first.
ENDIF.
ENDIF.
APPEND myline TO code.
ENDLOOP.


IF isopen = ‘X’.
IF first = 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Open SQL Without a FROM’
txt1 =
‘Correct & retry’.
RETURN.
ENDIF.
APPEND ‘.’ TO code.
ELSE.
APPEND ‘ENDEXEC.’ TO code.
APPEND TO code.
APPEND ‘DO.’ TO code.
APPEND ‘ EXEC SQL.’ TO code.
APPEND ‘ fetch next c1 INTO :R_TAB ‘ TO code.
APPEND ‘ ENDEXEC.’ TO code.
APPEND ‘ IF sy-subrc <> 0.’ TO code.
APPEND ‘ EXIT.’ TO code.
APPEND ‘ ENDIF.’ TO code.
APPEND ‘ Append R_TAB to I_TAB.’ TO code.
APPEND ‘ Add 1 to L_KOUNT.’ TO code.
APPEND ‘ If L_KOUNT >= ROWS.’ TO code.
APPEND ‘ Exit.’ TO code.
APPEND ‘ EndIf.’ TO code.
APPEND ‘ENDDO.’ TO code.
APPEND TO code.
APPEND ‘EXEC SQL.’ TO code.
APPEND ‘ close c1’ TO code.
APPEND ‘ENDEXEC.’ TO code.
APPEND TO code.
ENDIF.
APPEND ‘PERFORM zjnc_dump_list USING ”I_TAB[]” ”I_TAB” MyTitle.’
TO code.
APPEND ‘Catch CX_ROOT.’ TO code.
IF isopen <> ‘X’.
APPEND ‘EXEC SQL.’ TO code.
APPEND ‘ close c1’ TO code.
APPEND ‘ENDEXEC.’ TO code.
ENDIF.

************************ START MODIFY ************************
* update and delete – no cursor
ELSE.
MOVE 0 TO first.
APPEND ‘ EXEC SQL.’ TO code.
LOOP AT g_mytable INTO myline.
IF isopen = ‘X’.
MESSAGE ‘Supported only native for Update & Delete’ TYPE ‘I’.
EXIT.
ENDIF.
APPEND myline TO code.
ENDLOOP.
APPEND ‘ ENDEXEC.’ TO code.
APPEND ‘ IF sy-subrc = 0.’ TO code.
APPEND ‘ MESSAGE ”SQL executed” type ”I”.’ TO code.
APPEND ‘ ELSE.’ TO code.
APPEND ‘ MESSAGE ”No record affected” type ”I”.’ TO code.
APPEND ‘ EXIT.’ TO code.
APPEND ‘ ENDIF.’ TO code.
APPEND TO code.
APPEND ‘Catch CX_ROOT.’ TO code.
IF isopen <> ‘X’.
APPEND ‘MESSAGE ”Error during sql” type ”I”.’ TO code.
ENDIF.
ENDIF.

APPEND ‘EndTry.’ TO code.
APPEND ‘EndForm. “DoSQL.’ TO code.

APPEND TO code.
APPEND
‘*&——————————————————————‘ &
‘–*’
TO code.
APPEND
‘*& Form ZJNC_DUMP_LIST Our Good Old ALV list – RECOMMENDED!’
TO code.
APPEND
‘*&——————————————————————‘ &
‘–*’
TO code.
APPEND ‘FORM zjnc_dump_list USING value(p_it_name) TYPE c’ TO code.
APPEND ‘ value(p_wa_name) TYPE c’ TO code.
APPEND ‘ value(p_heading) TYPE c.’ TO code.
APPEND TO code.
APPEND ‘ TYPE-POOLS: slis.’ TO code.
APPEND TO code.
APPEND ‘ DATA:’ TO code.
APPEND ‘ stru_ref TYPE REF TO cl_abap_structdescr,’ TO code.
APPEND ‘ comp_tab TYPE abap_compdescr_tab,’ TO code.
APPEND ‘ one_comp TYPE abap_compdescr,’ TO code.
APPEND ‘ one_name TYPE string,’ TO code.
APPEND ‘ type_ref TYPE REF TO cl_abap_typedescr,’ TO code.
APPEND ‘ is_ddic TYPE abap_bool,’ TO code.
APPEND ‘ lt_ddic TYPE dd_x031l_table,’ TO code.
APPEND ‘ wa_ddic TYPE x031l,’ TO code.
APPEND ‘ lt_fcat TYPE slis_t_fieldcat_alv,’ TO code.
APPEND ‘ wa_fcat TYPE slis_fieldcat_alv,’ TO code.
APPEND ‘ ls_layo TYPE slis_layout_alv,’ TO code.
APPEND ‘ l_alv TYPE REF TO cl_gui_alv_grid.’ TO code.
APPEND TO code.
APPEND ‘ FIELD-SYMBOLS: <fs_type> TYPE ANY,’ TO code.
APPEND ‘ <fs_table> TYPE STANDARD TABLE,’ TO code.
APPEND ‘ <fs_line> TYPE ANY.’ TO code.
APPEND TO code.
APPEND ‘ ASSIGN (p_it_name) TO <fs_table>.’ TO code.
APPEND TO code.
APPEND ‘ ASSIGN (p_wa_name) TO <fs_line>.’ TO code.
APPEND TO code.
APPEND ‘ ls_layo-colwidth_optimize = ”X”.’ TO code.
APPEND ‘ ls_layo-zebra = ”X”.’ TO code.
APPEND ‘ ls_layo-window_titlebar = p_heading.’ TO code.
APPEND ‘ ls_layo-box_tabname = p_it_name.’ TO code.
APPEND TO code.
APPEND
‘ stru_ref ?= cl_abap_structdescr=>describe_by_data( <fs_line> ).’ TO
code.
APPEND TO code.
APPEND ‘ comp_tab = stru_ref->components.’ TO code.
APPEND TO code.
APPEND ‘ LOOP AT comp_tab INTO one_comp.’ TO code.
APPEND ‘ CLEAR wa_fcat.’ TO code.
APPEND ‘ wa_fcat-tabname = p_it_name.’ TO code.
APPEND ‘ wa_fcat-fieldname = one_comp-name.’ TO code.
APPEND TO code.
APPEND ‘ CONCATENATE p_wa_name ”-” one_comp-name INTO one_name.’
TO code.
APPEND TO code.
APPEND ‘ ASSIGN (one_name) TO <fs_type>.’ TO code.
APPEND TO code.
APPEND
‘ type_ref ?= cl_abap_typedescr=>describe_by_data( <fs_type> ).’ TO
code.
APPEND TO code.
APPEND ‘ is_ddic = type_ref->is_ddic_type( ).’ TO code.
APPEND TO code.
APPEND ‘ IF is_ddic = abap_true.’ TO code.
APPEND ‘ lt_ddic = type_ref->get_ddic_object( ).’ TO code.
APPEND TO code.
APPEND ‘ LOOP AT lt_ddic INTO wa_ddic.’ TO code.
APPEND ‘ CLEAR wa_ddic-tabname.’ TO code.
APPEND ‘ SELECT SINGLE’ TO code.
APPEND ‘ dd03l~tabname’ TO code.
APPEND ‘ INTO wa_ddic-tabname’ TO code.
APPEND ‘ FROM dd03l’ TO code.
APPEND ‘ WHERE dd03l~fieldname = wa_ddic-fieldname’ TO code.
APPEND
‘ AND dd03l~tabname NOT LIKE ”#%”. ” only normal namespace’
TO code.
APPEND TO code.
APPEND TO code.
APPEND ‘ wa_fcat-ref_tabname = wa_ddic-tabname.’ TO code.
APPEND ‘ wa_fcat-ref_fieldname = wa_ddic-fieldname.’ TO code.
APPEND TO code.
APPEND ‘ SELECT SINGLE’ TO code.
APPEND ‘ dd04t~scrtext_s’ TO code.
APPEND ‘ dd04t~scrtext_m’ TO code.
APPEND ‘ dd04t~scrtext_l’ TO code.
APPEND
‘ INTO (wa_fcat-seltext_s, wa_fcat-seltext_m, wa_fcat-seltex’ &
‘t_l)’
TO code.
APPEND ‘ FROM dd04t’ TO code.
APPEND ‘ WHERE dd04t~rollname = wa_ddic-fieldname’ TO code.
APPEND ‘ AND dd04t~ddlanguage = sy-langu.’ TO code.
APPEND TO code.
APPEND ‘ ENDLOOP.’ TO code.
APPEND ‘ ELSE.’ TO code.
APPEND
‘ MOVE one_comp-name TO: wa_fcat-seltext_s, wa_fcat-seltext_m,’
TO code.
APPEND ‘ wa_fcat-seltext_l.’ TO code.
APPEND ‘ ENDIF.’ TO code.
APPEND TO code.
APPEND ‘ APPEND wa_fcat TO lt_fcat.’ TO code.
APPEND TO code.
APPEND ‘ ENDLOOP.’ TO code.
APPEND TO code.
APPEND ‘ CALL FUNCTION ”REUSE_ALV_GRID_DISPLAY”’ TO code.
APPEND ‘ EXPORTING’ TO code.
APPEND ‘ is_layout = ls_layo’ TO code.
APPEND ‘ it_fieldcat = lt_fcat’ TO code.
APPEND ‘ TABLES’ TO code.
APPEND ‘ t_outtab = <fs_table>.’ TO code.
APPEND TO code.
APPEND ‘ENDFORM. “ZJNC_DUMP_LIST’ TO code.

CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
filename =
‘C:YES4SQL.txt’
TABLES
data_tab =
code.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

GENERATE SUBROUTINE POOL code NAME prog
MESSAGE msg
LINE lin
WORD wrd
OFFSET off.

IF sy-subrc <> 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Generate SUBROUTINE POOL Failed’
txt1 =
‘Possible Nonconformant SQL – see YES4SQL.txt’.
ELSE.

PERFORM dosql IN PROGRAM (prog).

IF sy-subrc <> 0.
CALL FUNCTION ‘POPUP_TO_INFORM’
EXPORTING
titel = g_repid
txt2 =
‘Generate SUBROUTINE POOL Succeeded BUT Call failed’
txt1 =
‘Possible Wrong SQL – see YES4SQL.txt’.
ENDIF.
ENDIF.

ENDFORM. “F_RUNSQL

SQL tool for SAP – Open & Native Sqlultima modifica: 2009-09-01T21:40:00+02:00da pedroccda
Reposta per primo quest’articolo

Un pensiero su “SQL tool for SAP – Open & Native Sql

Lascia un commento