‎2005 Apr 01 8:59 PM
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?
‎2005 Apr 01 9:38 PM
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>
‎2005 Apr 01 9:57 PM
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?
‎2005 Apr 01 10:18 PM
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
‎2005 Apr 01 11:28 PM
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??
‎2005 Apr 02 1:02 AM
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>
‎2005 Apr 02 7:51 PM
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 .
‎2005 Apr 02 8:40 PM
‎2005 Apr 02 10:26 PM
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?
‎2005 Apr 03 12:35 AM
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>
‎2005 Apr 03 7:08 AM
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.