Skip to Content
author's profile photo Former Member
Former Member

Methods

Hi,

I have written a method which will ask the values in the runtime and it will work as per the values..

For example :

If a query is there like---

SELECT * from ekko into table itab where ebeln = 3000000004.

Now I will give the table name ,internal table name and the value in the selectiuon screen..

How to put the that values in the query like]

SELECT * from <Tablename> into <Int table> where ebeln = <Value name>

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 31, 2007 at 06:45 AM

    Hi

    You have to use a dynamic select in this case:

    Try the Code below.. you will get the Solution

    REPORT ZSEL_BGJOB.

    DATA: L_TABNAME TYPE DD02L-TABNAME VALUE 'EKPO'.

    DATA : REF_TAB TYPE REF TO DATA.

    FIELD-SYMBOLS: <FTAB> TYPE TABLE.

    **Create the ITAB dynamically and Assign to Field symbol

    CREATE DATA REF_TAB TYPE TABLE OF (L_TABNAME).

    ASSIGN REF_TAB->* TO <FTAB>.

    **Construct the Select statement dynamically..

    SELECT * FROM (L_TABNAME) INTO TABLE <FTAB>.

    DESCRIBE TABLE <FTAB>.

    WRITE:/ SY-TFILL.

    <b>Reward if Helpful</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 31, 2007 at 06:49 AM

    Hello Mahesh,

    Its not at all possible. Why because, control will consider the word after <b>from</b> as a table name. and with that table name it will search in datadictionary. So you have to pass only valid table names.

    You can not give table name dynamically for select statement.

    Reward If Useful.

    Regards

    --

    Sasidhar Reddy Matli.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 31, 2007 at 10:03 AM

    Hi,

    Just one idea:

    Why don't u create 2 reports? The first one (the one that collects information from selection screen) creates another report that selects and outputs the selection, and then call the new report (with submit statement)?

    You can allways delete (on the first report) the new report (2nd one)...

    It works, but is it worth the effort?

    Regards,

    Carlos Constantino

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      try the following code:

      *&---------------------------------------------------------------------*
      *& Report  ZCAC_TRETA_DYN_SELECT                                       *
      *&                                                                     *
      *&---------------------------------------------------------------------*
      *&                                                                     *
      *&                                                                     *
      *&---------------------------------------------------------------------*
      
      REPORT  ZCAC_TRETA_DYN_SELECT         .
      
      SELECTION-SCREEN BEGIN OF BLOCK B1.
        PARAMETER P_TABLE TYPE CHAR32 DEFAULT 'SFLIGHT'.
      SELECTION-SCREEN END OF BLOCK B1.
      
      DATA: G_LINE TYPE CHAR255,
            GT_REPORT TYPE STANDARD TABLE OF CHAR255,
            G_FIELD TYPE STRING.
      
        CONCATENATE 'gt_' P_TABLE INTO G_FIELD.
      
      *create new report:
        MOVE 'REPORT TRETA.' TO G_LINE.
        APPEND G_LINE TO GT_REPORT.
        CLEAR G_LINE.
        CONCATENATE 'Data:' G_FIELD
                    ' type standard table of ' P_TABLE
                    ' with header line.' INTO G_LINE SEPARATED BY SPACE.
        APPEND G_LINE TO GT_REPORT.
        CLEAR G_LINE.
        CONCATENATE 'select * from ' P_TABLE ' into table' G_FIELD '.'
                    INTO G_LINE SEPARATED BY SPACE.
        APPEND G_LINE TO GT_REPORT.
        CLEAR G_LINE.
        CONCATENATE 'loop at' G_FIELD '.' INTO G_LINE SEPARATED BY SPACE.
        APPEND G_LINE TO GT_REPORT.
        CLEAR G_LINE.
        CONCATENATE 'write:/,' G_FIELD'.' INTO G_LINE SEPARATED BY SPACE.
        APPEND G_LINE TO GT_REPORT.
        CLEAR G_LINE.
        MOVE 'endloop.' TO G_LINE.
        APPEND G_LINE TO GT_REPORT.
      
        INSERT REPORT 'ZCAC_TRETA_DYN_TRETA' FROM GT_REPORT.
        SUBMIT ZCAC_TRETA_DYN_TRETA.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.