Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SQL TOOL

Former Member
0 Likes
511

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.

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
459

No, there is no tool exactly like that, but you could probably write a utility program to do this quite easily.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
459

Hi,

If you want to do SQL analysis..Try Explain SQL in ST05..

Thanks,

Naren

Read only

former_member186741
Active Contributor
0 Likes
459

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. .

Read only

0 Likes
459

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?

Read only

0 Likes
459

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.