Application Development 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: 

SELECT fdl1 fld2* FROM TAB1 APPENDING TABLE itab WHERE fld3 = SFLD1

Former Member
0 Kudos

Hi,

I have used the below code and is giving an error " GDT_TAB1 IS NOT DEFINED IN DICTIONARY"

Please help me to solve this 

TABLES: LIPS.
PARAMETER: SFLD1 TYPE LIPS-VBELN.
TYPES: BEGIN OF GTS_TAB1,
       FLD1 TYPE LIPS-WERKS,
       FLD2 TYPE LIPS-MATNR,
      END OF GTS_TAB1,

      BEGIN OF GTS_ITAB,
      FLD3 TYPE MAKT-MAKTX,
       FLD4 TYPE MAKT-MAKTG,
      END OF GTS_ITAB.

DATA: GDT_TAB1 TYPE TABLE OF GTS_TAB1,
      GDS_TAB1 TYPE GTS_TAB1,
      GDT_ITAB TYPE  TABLE OF GTS_ITAB,
      GDS_ITAB TYPE GTS_ITAB.

SELECT WERKS MATNR FROM LIPS INTO TABLE GDT_TAB1 WHERE VBELN = SFLD1.
LOOP AT GDT_TAB1 INTO GDS_TAB1.
SELECT MAKTX MAKTG FROM MAKT INTO TABLE GDT_ITAB WHERE MATNR = GDS_TAB1-FLD2.
ENDLOOP.

SELECT 
  MAKTX   MAKTG FROM  GDT_TAB1 APPENDING TABLE gdt_itab
WHERE vbeln = SFLD1.

Moderator Message: Basic question. Thread locked & all points unassigned.

Message was edited by: Suhas Saha

10 REPLIES 10

former_member16553
Active Participant
0 Kudos

Hi

    you can not pass an internal table in select query, you have select data from a database table..

your gdt_tab1 is a internal table , it's not a database table

0 Kudos

Hi Riya,

Instead of following code,

""

LOOP AT GDT_TAB1 INTO GDS_TAB1.

SELECT MAKTX MAKTG FROM MAKT INTO TABLE GDT_ITAB WHERE MATNR = GDS_TAB1-FLD2.

ENDLOOP.

SELECT    MAKTX   MAKTG FROM  GDT_TAB1 APPENDING TABLE gdt_itab
WHERE vbeln = SFLD1.

"".

You can use

"

SELECT WERKS MATNR FROM LIPS INTO TABLE GDT_TAB1 WHERE VBELN = SFLD1.

IF sy-subrc EQ 0.

SELECT  MAKTX MAKTG

    FROM MAKT

    INTO TABLE GDT_ITAB

    WHERE MATNR = GDS_TAB1-FLD2

    FOR ALL ENTRIES IN GDT_TAB1.

IF sy-subrc EQ 0.

ENDIF.

ENDIF.

Former Member
0 Kudos

Hi,

Your code is not correct.

Just Define

DATA: GDT_TAB1 TYPE STANDARD TABLE OF GTS_TAB1 WITH HEADER LINE.

Regards

Ajit

Kartik2
Contributor
0 Kudos

Dear Riya,

Here are a few comments i would like to make -

1. I do not see why you have used the tables statement. Understand the use of statements first. Tables statement declares an internal table with header line. In your case you do not need one. And please keep in mind that internal tables with header lines are obselete now.

2. In you types declaration you have declared some fields as

FLD1 TYPE LIPS-WERKS.

Instead an efficient way would be to directly refer the data element used all you have to do is double click on the type and see the data element.

FLD1 TYPE WERKS_D.

3. you have used select query inside a loop. It will make a huge difference in performance my dear. If you hit the data base every time then deffinitely the time taken will be huge. Instead you can use the statement -

SELECT... FOR ALL ENTRIES IN...

4. Select statement is for data fetching from data base tables only.

Hope you incorporate these best practices in your coding. Thank you.

Regards,

kartik

Former Member
0 Kudos

Hi,

Thanks for the response.

My question is whether the query SELECT fdl1 fld2* FROM  TAB1 APPENDING TABLE itab WHERE fld3 = SFLD1 correct or not?

Former Member
0 Kudos

Hi,

This query is correct.problem is with your declaration.

Regards

Ajit

Former Member
0 Kudos

Hi,

I have seen in the SDN that the below query will append rows to itab.

SELECT fld1 fld2 FROM   GDT_TAB1 APPENDING TABLE itab

WHERE fld1 IN sfld1.

Hence I was trying out the same, but when i used the above query i am getting error that the internal table gdt_tab1 is not defined even though i have defined as

data:   GDT_TAB1 type standard table of gts_tab1 with header line.

Former Member
0 Kudos

Dear Riya,

     Code has error at last statement .

SELECT    MAKTX   MAKTG FROM  GDT_TAB1 APPENDING TABLE gdt_itab
WHERE vbeln = SFLD1.

Here GDT_TAB1 is not data dictionary table.

This statement is wrong.


regards

ajit

Former Member
0 Kudos

thanks Ajit.

Former Member
0 Kudos

Hi better way to declare the internal table and work area seprately and then try.

TYPES: BEGIN OF GTS_TAB1,
       FLD1 TYPE LIPS-WERKS,
       FLD2 TYPE LIPS-MATNR,
      END OF GTS_TAB1,

      BEGIN OF GTS_ITAB,
      FLD3 TYPE MAKT-MAKTX,
       FLD4 TYPE MAKT-MAKTG,
      END OF GTS_ITAB.

DATA: ITGTS_TAB1 TYPE STANDARD TABLE OF GTS_TAB1,

             WAGTS_TAB1 TYPE   GTS_TAB1,

   
    
      ITGTS_ITAB TYPE STANDARD  TABLE OF GTS_ITAB,
      WAGTS_ITAB TYPE GTS_ITAB.

Loop AT ITGTS_TAB1 into  WAGTS_TAB1.

SELECT WERKS MATNR FROM LIPS INTO TABLE GDT_TAB1 WHERE VBELN = SFLD1.

ENDLOOP.



LOOP AT ITGTS_TAB1 INTO WAGTS_TAB1.
SELECT MAKTX MAKTG FROM MAKT INTO TABLE GDT_ITAB WHERE MATNR = GDS_TAB1-FLD2.
ENDLOOP.