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

Dynamic internal table - using it in another select statement

Former Member
0 Likes
1,310

I have an internal table declared dynamic. I have selected data into this internal table and now I want to use this - either in a FOR ALL ENTRIES or in a LOOP. But i get "the data object .... has no structure and therefore no component called BELNR"

* Create a new dynamic Table from fieldcatalog
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_fieldcat
    IMPORTING
      ep_table        = gt_table.

* Now assign this to a fieldsymbol with type standard table (req. by ALV)
  ASSIGN gt_table->* TO <dyn_table>.

  SELECT belnr zslagtedata~matnr maktx zzslagtenr zzoremaerke
         zzdyre_kat zzform_char zzfedme zzalder zzlev_vaegt zzafr_vaegt
         zzvb_kode
    FROM zslagtedata
    JOIN makt
      ON zslagtedata~matnr = makt~matnr
    INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
   WHERE zslagtedata~matnr IN s_matnr.
* Now see if there is some data in table ZAFR_PRISTABEL for the selected records
  select * from zafr_pristabel
    for ALL ENTRIES IN <dyn_table>
  where belnr = <dyn_table>-belnr.

If not using the FOR ALL ENTRIES I would like to use :

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
    SELECT * FROM zafr_pristabel
      WHERE belnr EQ <dyn_wa>-belnr.
.......      
    ENDSELECT.
  ENDLOOP.

How do I do that ??

PS the code is used to display price conditions from a table. Each row in the table is 1 price condition (can be customized). The condition record has to be linked with 1 document and shown as 1 line in an ALV list (the dynamic part is to add each record as an field in an internal table, and fill this field with data from the records)

1 ACCEPTED SOLUTION
Read only

Subhankar
Active Contributor
0 Likes
766

Hi

If declare the dynamic internal table with static structure then you can use it in for all entries.

It make it as type table or any then you can not use the field name in the program.

If want do select inside the loop statement then there process.

1. Assign field value to 3rd variable using the statement assign component 'FIELD NAME' of structure to <3RD Variable>

2. Then use this 3rd variable in your select statement.

FIELD-SYMBOLs: <FS> type any.

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

Assign component 'belnr' of structure <dyn_wa> to <FS>.

if sy-subrc = 0.

SELECT * FROM zafr_pristabel

WHERE belnr EQ <FS>.

.......

ENDSELECT.

endif.

ENDLOOP.

Thanks

Subhankar

6 REPLIES 6
Read only

Former Member
0 Likes
766

Hi,

Try using gt_table.

Thanks

Pavan

Read only

0 Likes
766

Using the gt_table just result in an error message saying that the data object gt_table has no structure and therefore no component called BELNR

Read only

Subhankar
Active Contributor
0 Likes
767

Hi

If declare the dynamic internal table with static structure then you can use it in for all entries.

It make it as type table or any then you can not use the field name in the program.

If want do select inside the loop statement then there process.

1. Assign field value to 3rd variable using the statement assign component 'FIELD NAME' of structure to <3RD Variable>

2. Then use this 3rd variable in your select statement.

FIELD-SYMBOLs: <FS> type any.

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

Assign component 'belnr' of structure <dyn_wa> to <FS>.

if sy-subrc = 0.

SELECT * FROM zafr_pristabel

WHERE belnr EQ <FS>.

.......

ENDSELECT.

endif.

ENDLOOP.

Thanks

Subhankar

Read only

Former Member
0 Likes
766

I used this code :

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
   Assign component 'BELNR' of structure <dyn_wa> to <belnr>.
    SELECT * FROM zafr_pristabel
      WHERE belnr EQ <belnr>.
      ASSIGN COMPONENT 'KSCHL' of structure zafr_pristabel to <field>.
      assign COMPONENT <field> of STRUCTURE <dyn_wa> to <value>.
      <value> = zafr_pristabel-kbetr.
    ENDSELECT.
  ENDLOOP.

Thanks.

Additional question : How do i track changes in the ALV - it is editable. If not using dynamic table i would create a TEMP table as a copy of the ALV table, but this is not possible using the dynamic table. The table is a field symbol <dyn_table>, and creating another field symbol <temp_dyn_table> and assigning the first to the second would always result in the two tables are the same.

If the user changes the value of 1 condition, this new value has to be written down in table zafr_pristabel again - and only the changed records.

PS i'm using

* Get changed data from memory - if not called we can't see the changed fileds
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = p_ref1.
  CALL METHOD p_ref1->check_changed_data.

Read only

Former Member
0 Likes
766

Hi,

it is not possible with FOR ALL ENTRIES since the table has no structure. You must work with a loop:

DATA: l_fname TYPE char20.

FIELD-SYMBOLS: <f_wa>, <f_field>.

LOOP AT <it_table> ASSIGNING <f_wa>.

l_fname = '<f_wa>-your field here'.

ASSIGN (l_fname) TO <f_field>.

IF <f_field> = some value.

WRITE:/10 'Condition fulfilled'.

ENDIF.

ENDLOOP.

Read only

anup_deshmukh4
Active Contributor
0 Likes
766

hello Kim Ternstrøm ,

you very well know the offse structre of the table structre you can do it using OFFSET for the loop thing