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

structure dynamic

former_member423024
Participant
0 Likes
468

Hi,

I have a small requirement. I need to create a structure with fields MATNR,BUKRS,KOKRS and populate some values to it.

so that the name of the internal table should vary like "CEO" + "the value of a field ERKRS(which will be populated in the loop IT_TKA01-erkrs)"

if the value of field ERKRS = 101. The name of the structure should be CEO101.

if the value of field ERKRS = 102.The name of the structure should be CEO102.

Then it should be populated with some values and pass it to an function module.

Could anyone let me know how to handle this situation.

Thanks

Natasha.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
435

Hi Natasha,

If structure fields are same or you are inserting records into same database table then no need to implement this logic,just make an extra field in your table and structure as identifier.

Also, as you need to populate different internal tables , then just use IF statement and then insert record based on this and pass the internal table to FM in same IF body.

Hope it help you.

Edited by: Harsh Bhalla on Nov 21, 2009 9:03 PM

4 REPLIES 4
Read only

Former Member
0 Likes
436

Hi Natasha,

If structure fields are same or you are inserting records into same database table then no need to implement this logic,just make an extra field in your table and structure as identifier.

Also, as you need to populate different internal tables , then just use IF statement and then insert record based on this and pass the internal table to FM in same IF body.

Hope it help you.

Edited by: Harsh Bhalla on Nov 21, 2009 9:03 PM

Read only

0 Likes
435

Hi harsha,

Thanks for the reply. But you didn't get me.

I have to create a data object whose name varies with in a loop, I have to pass always 3 values to it. It will hold always 3 values only as a record. But the name should vary accordingly in the loop

(as explained in the previous query)

Please do reply about this.

Thanks

Natasha.

Read only

0 Likes
435

Hello,

If I understand it correctly you would like to use dynamic structures names (which can change during the loop).

Take a look at following example how to use dynamic variables in ABAP.

[https://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable|https://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]

It is an example for a dynamic internal table, try to analyse the statements and map it to dynamic structures.

Maybe this is too complicated, in your case you can also use a simple IF statement and based on the result fill structure 1 or 2.

I hope this can help.

Wim

Read only

Former Member
0 Likes
435

Halo Natasha,

you can make use of the RTTS services in ABAP to create dynamic internal tables

DATA: lineType TYPE REF TO cl_abap_structdescr,

tableType TYPE REF TO cl_abap_tabledescr,

key TYPE abap_keydescr_tab.

lineType ?=cl_abap_typedescr=>describe_by_name( 'SPFLI' ).

APPEND 'CARRID' TO key. APPEND 'CONNID' TO key.

tableType = cl_abap_tabledescr=>create(

p_line_type = lineType

p_table_kind = cl_abap_tabledescr=>tablekind_sorted

p_unique = abap_true

p_key = key ).