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

Field Symbol Problem

Former Member
0 Likes
1,389

Hi All,

I want to select the data of a standard table directly into an internal table but I am not able to get that.

Note : I am working 4.6C version of SAP

Please see the below code :

REPORT zdwnld_tabl_data .

PARAMETERS : p_tabl1 TYPE dd02v-tabname.

DATA : ddobtype TYPE dd02v-tabclass.

DATA : ref TYPE REF TO data.

FIELD-SYMBOLS : <data_tab> TYPE ANY.

CALL FUNCTION 'DDIF_NAMETAB_GET'
     EXPORTING
          tabname   = p_tabl1
          all_types = ' '
     IMPORTING
          ddobjtype = ddobtype
     EXCEPTIONS
          OTHERS    = 2.
IF sy-subrc <> 0 OR ddobtype = 'INTTAB'.
  RAISE tabl_not_found.
ENDIF.

CREATE DATA ref type (p_tabl1).

ASSIGN ref->* TO <data_tab>.


SELECT * FROM (p_tabl1) INTO <data_tab>.
ENDSELECT.

Here if I dont want SELECT....ENDSELECT but want the data directly into an internal table. When I change the select statement as follows :

 SELECT * FROM (p_tabl1) INTO table <data_tab>.

it throws error saying <data_tab> is not an internal table. I understand the error.

To resolve this error when I change the FIELD SYMBOL declaration as

FIELD-SYMBOLS : <data_tab> TYPE TABLE. OR FIELD-SYMBOLS : <data_tab> TYPE ANY TABLE. , the program dumps on ASSIGN ref-> statement saying error as Type conflict with ASSIGN in program.

Any idea how this can be resolved.

Regards

Abhii

Hi All,

I want to select the data of a standard table directly into an internal table but I am not able to get that.

Note : I am working 4.6C version of SAP

Please see the below code :

REPORT zdwnld_tabl_data .

PARAMETERS : p_tabl1 TYPE dd02v-tabname.

DATA : ddobtype TYPE dd02v-tabclass.

DATA : ref TYPE REF TO data.

FIELD-SYMBOLS : <data_tab> TYPE ANY.

CALL FUNCTION 'DDIF_NAMETAB_GET'
     EXPORTING
          tabname   = p_tabl1
          all_types = ' '
     IMPORTING
          ddobjtype = ddobtype
     EXCEPTIONS
          OTHERS    = 2.
IF sy-subrc <> 0 OR ddobtype = 'INTTAB'.
  RAISE tabl_not_found.
ENDIF.

CREATE DATA ref type (p_tabl1).

ASSIGN ref->* TO <data_tab>.


SELECT * FROM (p_tabl1) INTO <data_tab>.
ENDSELECT.

Here if I dont want SELECT....ENDSELECT but want the data directly into an internal table. When I change the select statement as follows :

 SELECT * FROM (p_tabl1) INTO table <data_tab>.

it throws error saying <data_tab> is not an internal table. I understand the error.

To resolve this error when I change the FIELD SYMBOL declaration as

FIELD-SYMBOLS : <data_tab> TYPE TABLE. OR FIELD-SYMBOLS : <data_tab> TYPE ANY TABLE. , the program dumps on ASSIGN ref-> statement saying error as Type conflict with ASSIGN in program.

Any idea how this can be resolved.

Regards

Abhii

10 REPLIES 10
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,344

Hello,

Has been discussed many a times in the forum:

REPORT zdwnld_tabl_data .
 
PARAMETERS : p_tabl1 TYPE dd02v-tabname.
 
DATA : ddobtype TYPE dd02v-tabclass.
 
DATA : ref TYPE REF TO data.
 
FIELD-SYMBOLS : <data_tab> TYPE STANDARD TABLE.
 
CALL FUNCTION 'DDIF_NAMETAB_GET'
     EXPORTING
          tabname   = p_tabl1
          all_types = ' '
     IMPORTING
          ddobjtype = ddobtype
     EXCEPTIONS
          OTHERS    = 2.
IF sy-subrc NE 0 OR ddobtype = 'INTTAB'.
  RAISE tabl_not_found.
ENDIF.
 
CREATE DATA ref TYPE STANDARD TABLE OF (p_tabl1).
 
ASSIGN ref->* TO <data_tab>.
 
 
SELECT * FROM (p_tabl1) INTO TABLE <data_tab>.

BR,

Suhas

Read only

Former Member
0 Likes
1,344

Hello Dada,

I have even tried using CREATE DATA ref type standard table of (p_tabl1) before posting ths question, it still says Unable to interpret "TABLE". Possible causes of error: Incorrect spelling or comma error

Regards

Abhii

Read only

brad_bohn
Active Contributor
0 Likes
1,344

Can't vouch for the 4.6C compatibility (it's been too long), but try 'TYPE TABLE OF' instead:


CREATE DATA lr_dref TYPE TABLE OF (lv_tabname).

Read only

Former Member
0 Likes
1,344

Hi Brad,

I tried even using TYPE TABLE OF but it still says The type specification of "TABLE" is incomplete before posting the question.

Regards

Read only

brad_bohn
Active Contributor
0 Likes
1,344

Like I said, I could not vouch for 4.6C compatibility; it's been too long since I used that version. You may have to append the entries line by line then to a field symbol that has TYPE ANY TABLE. 4.6C was very limited in its dynamic capabilities.

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,344

REPORT zdwnld_tabl_data .

PARAMETERS : p_tabl1 TYPE dd02v-tabname.

DATA : ddobtype TYPE dd02v-tabclass.

DATA : ref TYPE REF TO data.

FIELD-SYMBOLS : <data_tab> TYPE ANY.

CALL FUNCTION 'DDIF_NAMETAB_GET'

EXPORTING

tabname = p_tabl1

all_types = ' '

IMPORTING

ddobjtype = ddobtype

EXCEPTIONS

OTHERS = 2.

IF sy-subrc ne 0 OR ddobtype = 'INTTAB'.

RAISE tabl_not_found.

ENDIF.

CREATE DATA ref TYPE (p_tabl1).

ASSIGN ref->* TO <data_tab>.

SELECT * FROM (p_tabl1) INTO <data_tab>.

ENDSELECT.

Read only

Former Member
0 Likes
1,344

Hi,

Instead of


CREATE DATA ref type (p_tabl1).

try


CREATE DATA ref TYPE TABLE OF (p_tabl1).

Thanks,

Anmol.

Read only

Former Member
0 Likes
1,344

I once had the same problem in 4.6C, and I used method CREATE_DYNAMIC_TABLE from class CL_ALV_TABLE_CREATE. You just need to create a field catalog using the well known function module LVC_FIELDCATALOG_MERGE, and use that field catalog in the method.

This way you can dynamically create an internal table with having to use CREATE DATA ... TYPE TABLE OF (which does not exist in 4.6C).

Please let me know if this was helpful.

Edited by: Koen De Ruyck on Oct 28, 2010 4:09 PM

Read only

0 Likes
1,344

Hi Koen De Ruyck,

Your answer was very very helpful. I have come to a conclusion that, in 4.6 C we can get the data into an internal dynamic table only by using the method create_dynamic_table of class cl_alv_table_create.

All the above methods suggested didnt work.

 

REPORT zdwnld_tabl_data .

PARAMETERS : p_tabl1 TYPE dd02v-tabname.

DATA: dy_table TYPE REF TO data,
      dy_line  TYPE REF TO data.

DATA : it_fcat TYPE lvc_t_fcat.

FIELD-SYMBOLS : <data_tab> TYPE STANDARD TABLE,
                <dyn_wa>.


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
 EXPORTING
*       I_BUFFER_ACTIVE              =
   i_structure_name             = p_tabl1
*       I_CLIENT_NEVER_DISPLAY       = 'X'
*       I_BYPASSING_BUFFER           =
  CHANGING
    ct_fieldcat                  = it_fcat
*     EXCEPTIONS
*       INCONSISTENT_INTERFACE       = 1
*       PROGRAM_ERROR                = 2
*       OTHERS                       = 3
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
*        I_STYLE_TABLE             =
    it_fieldcatalog           = it_fcat
  IMPORTING
    ep_table                  = dy_table
*        E_STYLE_FNAME             =
*      EXCEPTIONS
*        GENERATE_SUBPOOL_DIR_FULL = 1
*        others                    = 2
        .
IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ASSIGN dy_table->* TO <data_tab>.


SELECT * FROM (p_tabl1) INTO TABLE <data_tab>.

However I have tested this with some tables, its working fine but its giving dump for MARA table, the dump says output table is too small , any idea on how we can overcome this error.

Regards

Abhii

Read only

0 Likes
1,344

Hi

You should check the catalog table returned by LVC_FIELDCATALOG_MERGE, probably some definition could miss if the dictionary table has certain defination.

And you should consider the method cl_alv_table_create=>create_dynamic_table works in this way:

It creates a pool routine where it write the defination of an internal table based on ALV catalog table, then it defines the dynamic table arranged on that defination, but I remember that certain field definitions were not supported while writing the defination, so certain fields could miss in defination, so in the internal table.

That could explain your problem

Max