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 itab

Former Member
0 Likes
1,002

When I enclose an itab in (), it does not have the dynamic effect that enclosing a dbtable in ().

I can't do the following:

TABLES: DD02T.
DATA: BEGIN OF ITAB_TEST OCCURS 0,
      TEXT TYPE STRING,
      END OF ITAB_TEST.
DATA: ITAB_FILL LIKE DD02T-TABNAME.
MOVE 'SURF' TO ITAB_TEST-TEXT.
CONCATENATE 'ITAB_'
            'TEST'
            INTO ITAB_FILL.
READ ITAB_FILL WITH KEY TEXT = 'SURF'.
IF SY-SUBRC EQ 0.
   WRITE 'OK'.
ENDIF.

When I debug I can tell that ITAB_FILL's content is 'ITAB_TEST'. But when I do (ITAB_FILL) it is not regarded as ITAB_TEST.

Any way around this?

10 REPLIES 10
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
967

Hi Howard

READ TABLE does not support dynamic arguements as far as I know. The first solution that comes to my mind is using field sumbols.

<u>e.g.</u>

...
FIELD-SYMBOLS: <table> TYPE table ,
               <line> TYPE ANY .

ASSIGN (itab_fill) TO <table> .
IF sy-subrc = 0 .
READ TABLE <table> ASSIGNING <line>
     WITH KEY text = 'SURF' .
IF SY-SUBRC EQ 0.   
  WRITE 'OK'. 
ENDIF.

...
ENDIF .
...

Hope this helps...

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
967

I get the following error message:

the specified type has no structure and therefore has no component called TEXT.

I'm assuming this is referring to <table>.

But as my code shows, ITAB_TEST is an itab.

Any way around this?

Read only

Former Member
0 Likes
967

Hi Howard,

READ TABLE is very inflexible for this kind of manipulation. Can you tell us what is it that you want to achieve by this code, may be then someone can suggest an alternative?

Regards,

Srinivas

Read only

0 Likes
967

Sure thing.

The results of this Function module I'm using are a structure that identifies the <i>segment</i> type, and the <i>segment</i>.

i.e.

<u>STRUCTURE</u>    <u>SEGMENT</u>
1) BKPF      0020200010 USD101   E   .. ... ...
or
2) BSEG      0020   CALI  FI39S .... .... ... .... ...
or
3) BSEG      0011   NEWK  ..... .... .... ... .... ...

So I can't anticipate what the table will be- actually I can, but that would require hard-coding and I want to avoid that. So it's tough that these READS are inflexible, because I would like this variability.

The user enters in a value for BUKRS and KUNNR for example. BUKRS is contained in BKPF, but KUNNR is contained in BSEG.

Since I can't delete the db table for BSEG/BKPF, I create itab_bkpf and itab_bseg that mimic them. Then if the structure Identifier is BSEG, I put the segment in ITAB_BSEG and match the field value (BUKRS-as entered by the user) to the value in the segment. If it matches. success.

That field symbol that serdar mentioned is not manageable as a dynamic placeholder??

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
967

Hi again

So, try this:

...
FIELD-SYMBOLS: <table> TYPE table ,
               <line> TYPE ANY ,
               <fvalue> TYPE ANY.

ASSIGN (itab_fill) TO <table> .
IF sy-subrc = 0 .
LOOP AT <table> ASSIGNING <line> .
ASSIGN COMPONENT 'TEXT' OF STRUCTURE <line> TO <fvalue> .
IF SY-SUBRC EQ 0 AND
   <fvalue> = 'SURF'.   
  WRITE 'OK'. 
  EXIT .
ENDIF.
ENDLOOP .
...
ENDIF .
...

Hope this helps...

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
967

Yeah, I get this runtime error now though: can't assign a field to a typed field symbol when the field doesn't have the required type. Even though I aligned the types to match up.

It's occurring at ASSIGN (itab_fill) TO <table>.

all my code is below. Does anyone know why it is not respecting the assignment?

TABLES: DD02T, DD03T.
DATA: BEGIN OF ITAB_TEST OCCURS 0,
      TEXT TYPE STRING,
      END OF ITAB_TEST.
DATA: ITAB_FILL LIKE DD02T-TABNAME.
MOVE 'SURF' TO ITAB_TEST-TEXT.
CONCATENATE 'ITAB_'
            'TEST'
            INTO ITAB_FILL.

FIELD-SYMBOLS: <table> TYPE table ,
               <line> LIKE DD03T-FIELDNAME ,
               <fvalue> TYPE STRING.

ASSIGN (itab_fill) TO <table> .
IF sy-subrc = 0 .
  LOOP AT <table> ASSIGNING <line> .
  ASSIGN COMPONENT 'TEXT' OF STRUCTURE <line> TO <fvalue> .
  IF SY-SUBRC EQ 0 AND   <fvalue> = 'SURF'.
    WRITE 'OK'.
    EXIT .
   ENDIF.
ENDLOOP .
ENDIF .

Read only

0 Likes
967

Put brackets after the word TEST in this statment.

concatenate 'ITAB_' 'TEST<b>[]</b>' into itab_fill.

Regards,

Rich Heilman

Read only

0 Likes
967

The Loop is not working properly.

I do not think the field symbol <table> is being regarded as a table.

I put a WRITE:/ 'check'. inside the loop to see if that was outputted and it was not.

Is it because of the 'assigning <line>' addition?

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
967

Hi Howard

Are you sure that there is at least one record satisfying the condition "text = 'SURF'" ?

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

0 Likes
967

Hi Howard,

Perhaps you might be able to pick a point or two from this <a href="/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

Regards,

Subramanian V.