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

Using components of unknown table

Former Member
0 Likes
774

Hi,

I have a form where I work with an unknown table. What I know is, that every table that is given to the function has i.e. the component PERNR. I want to do some things with these components (sorting the table, putting into another table etc.) but whether I use field symbols or data references I get the error that it has no structure (which is right).

For more specific information:

My tables are P2001 - P2012 (which is nice to work with, hence the numbers).

I want to pass a specific table of these to the form, but the form should treat them all the same (only in some special cases where I use a case on the string which contains the table).

If you have a solution please help me. I read most of the stuff about field symbols and data references so a short answer would help too.

Thanks in advance, Christopher

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
703

you can try like this -


PARAMETERS: dbtab TYPE c LENGTH 10, 
            rows  TYPE i DEFAULT 100. 

DATA dref TYPE REF TO data. 

FIELD-SYMBOLS: TYPE ANY TABLE, 
               <wa>    TYPE ANY, 
                 TYPE ANY. 

TRY. 
    CREATE DATA dref TYPE STANDARD TABLE OF (dbtab) 
                          WITH NON-UNIQUE DEFAULT KEY. 
    ASSIGN dref->* TO  . 
    SELECT * 
           FROM (dbtab) UP TO rows ROWS 
           INTO TABLE  . 
    LOOP AT  ASSIGNING <wa>. 
      DO. 
        ASSIGN COMPONENT sy-index 
               OF STRUCTURE <wa> TO . 
        IF sy-subrc = 0. 
          WRITE / . 
        ELSE. 
          EXIT. 
        ENDIF. 
      ENDDO. 
      ULINE. 
    ENDLOOP. 
  CATCH cx_sy_create_data_error. 
    WRITE 'Wrong Database!'. 
ENDTRY. 
 

Hope it helps.

Hi,

I have a form where I work with an unknown table. What I know is, that every table that is given to the function has i.e. the component PERNR. I want to do some things with these components (sorting the table, putting into another table etc.) but whether I use field symbols or data references I get the error that it has no structure (which is right).

For more specific information:

My tables are P2001 - P2012 (which is nice to work with, hence the numbers).

I want to pass a specific table of these to the form, but the form should treat them all the same (only in some special cases where I use a case on the string which contains the table).

If you have a solution please help me. I read most of the stuff about field symbols and data references so a short answer would help too.

Thanks in advance, Christopher

2 REPLIES 2
Read only

Former Member
0 Likes
704

you can try like this -


PARAMETERS: dbtab TYPE c LENGTH 10, 
            rows  TYPE i DEFAULT 100. 

DATA dref TYPE REF TO data. 

FIELD-SYMBOLS: TYPE ANY TABLE, 
               <wa>    TYPE ANY, 
                 TYPE ANY. 

TRY. 
    CREATE DATA dref TYPE STANDARD TABLE OF (dbtab) 
                          WITH NON-UNIQUE DEFAULT KEY. 
    ASSIGN dref->* TO  . 
    SELECT * 
           FROM (dbtab) UP TO rows ROWS 
           INTO TABLE  . 
    LOOP AT  ASSIGNING <wa>. 
      DO. 
        ASSIGN COMPONENT sy-index 
               OF STRUCTURE <wa> TO . 
        IF sy-subrc = 0. 
          WRITE / . 
        ELSE. 
          EXIT. 
        ENDIF. 
      ENDDO. 
      ULINE. 
    ENDLOOP. 
  CATCH cx_sy_create_data_error. 
    WRITE 'Wrong Database!'. 
ENDTRY. 
 

Hope it helps.

Read only

0 Likes
703

Thanks, this helps a lot.

In addition I will need the function 'DDIF_NAMETAB_GET' because I recognized that the component names are only similiar, not equal.