‎2006 Oct 04 10:47 PM
Is there any tool in SAP, where we can write plain SQL (open or native) against any transparant tables, without having to write ABAP code? Just for read-only, analysis/debugging purposes. Thanks.
‎2006 Oct 04 10:49 PM
‎2006 Oct 04 10:54 PM
Hi,
If you want to do SQL analysis..Try Explain SQL in ST05..
Thanks,
Naren
‎2006 Oct 05 3:48 AM
here's a simple abap which may do the trick for you. It will dynamically run any abap statements you want but I usually use it to test out sql. The first parameter is expecting table names the others just raw abap.
It's fine for a few lines of code but the messaging isn't perfect so any complexity would mean you're better off writing a new abap.
Neil Woodruff
REPORT ZNRW_sql_tool MESSAGE-ID Z1.
PARAMETERS: P_TABLE LIKE DD02L-TABNAME.
PARAMETERS: P_CODE1(200) LOWER CASE.
PARAMETERS: P_CODE2(200) LOWER CASE.
PARAMETERS: P_CODE3(200) LOWER CASE.
PARAMETERS: P_CODE4(200) LOWER CASE.
PARAMETERS: P_CODE5(200) LOWER CASE.
PARAMETERS: P_CODE6(200) LOWER CASE.
PARAMETERS: P_CODE7(200) LOWER CASE.
PARAMETERS: P_CODE8(200) LOWER CASE.
PARAMETERS: P_CODE9(200) LOWER CASE.
PARAMETERS: P_CODE10(200) LOWER CASE.
PARAMETERS: P_CODE11(200) LOWER CASE.
PARAMETERS: P_CODE12(200) LOWER CASE.
PARAMETERS: P_CODE13(200) LOWER CASE.
PARAMETERS: P_CODE14(200) LOWER CASE.
PARAMETERS: P_CODE15(200) LOWER CASE.
PARAMETERS: P_CODE16(200) LOWER CASE.
PARAMETERS: P_CODE17(200) LOWER CASE.
PARAMETERS: P_CODE18(200) LOWER CASE.
PARAMETERS: P_CODE19(200) LOWER CASE.
PARAMETERS: P_CODE20(200) LOWER CASE.
PARAMETERS: P_CODE21(200) LOWER CASE.
PARAMETERS: P_CODE22(200) LOWER CASE.
PARAMETERS: P_CODE23(200) LOWER CASE.
PARAMETERS: P_CODE24(200) LOWER CASE.
PARAMETERS: P_CODE25(200) LOWER CASE.
PARAMETERS: P_CODE26(200) LOWER CASE.
PARAMETERS: P_CODE27(200) LOWER CASE.
PARAMETERS: P_CODE28(200) LOWER CASE.
PARAMETERS: P_CODE29(200) LOWER CASE.
PARAMETERS: P_CODE30(200) LOWER CASE.
PARAMETERS: P_CODE31(200) LOWER CASE.
DATA T_SOURCE_TAB(72) OCCURS 0 WITH HEADER LINE.
DATA G_PROGRAM_NAME LIKE SY-REPID.
DATA G_SYNTAX_MESSAGE(128).
DATA G_LINE_NO TYPE I.
AT SELECTION-SCREEN.
PERFORM CHECK_DYNAMIC_ABAP.
START-OF-SELECTION.
PERFORM DO_THE_BUSINESS IN PROGRAM (G_PROGRAM_NAME).
FORM CHECK_DYNAMIC_ABAP.
DATA T_ABAP(80) OCCURS 0 WITH HEADER LINE.
*set up a dynamic program
REFRESH T_SOURCE_TAB.
APPEND 'REPORT' TO T_SOURCE_TAB.
APPEND SY-REPID TO T_SOURCE_TAB.
APPEND '.' TO T_SOURCE_TAB.
APPEND 'tables:' TO T_SOURCE_TAB.
APPEND P_TABLE TO T_SOURCE_TAB.
APPEND '.' TO T_SOURCE_TAB.
APPEND 'DATA: begin of common part a,' TO T_SOURCE_TAB.
APPEND 'V_IN(5000),' TO T_SOURCE_TAB.
APPEND 'END OF COMMON PART.' TO T_SOURCE_TAB.
APPEND 'FORM do_the_business.' TO T_SOURCE_TAB.
*macro to separate line's contents into table
DEFINE UNRAVEL.
SPLIT &1 AT ' ' INTO TABLE T_ABAP.
LOOP AT T_ABAP.
SHIFT T_ABAP RIGHT BY 1 PLACES.
APPEND T_ABAP TO T_SOURCE_TAB.
ENDLOOP.
END-OF-DEFINITION.
FIELD-SYMBOLS <CODE>.
DATA L_ABAP LIKE P_CODE1.
DATA L_FIELD_NAME(30).
DATA L_CHAR_INDEX(2).
DO.
L_CHAR_INDEX = SY-INDEX.
CONCATENATE 'P_code' L_CHAR_INDEX INTO L_FIELD_NAME.
ASSIGN (L_FIELD_NAME) TO <CODE>.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
UNRAVEL <CODE>.
ENDDO.
APPEND '.' TO T_SOURCE_TAB.
APPEND 'ENDFORM.' TO T_SOURCE_TAB.
*Generate the dynamic program so that the form can be used subsequently.
GENERATE SUBROUTINE POOL T_SOURCE_TAB NAME G_PROGRAM_NAME
MESSAGE G_SYNTAX_MESSAGE LINE G_LINE_NO.
IF SY-SUBRC <> 0.
MESSAGE E999 WITH G_SYNTAX_MESSAGE.
ENDIF.
ENDFORM. .
‎2006 Oct 05 4:38 AM
Hi Neil, MAny thanks. I am really new to ABAP. So, this piece of code is not really simple for me CAn you please explain, how would you use this to test SQL? SAy, I want to run a query such as SELECT BUKRS,COUNT(*) FROM BSEG GROUP BY BUKRS. Would I still need to declare the necessary internal tables and structures? If so, what's different here?
‎2006 Oct 05 4:55 AM
The sql you have is not 'open' so you may need to put exec sql stements in but basically you just put abap statements into the parameters.
eg,
Create the program by cutting and pasting via transaction se38.
Run the program via se38.
In the top parameter put: BSEG
In the lines below put:
SELECT BUKRS FROM BSEG up to 10 rows.
endselect.
write:/ sy-dbcnt.