Application Development 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: 

Dynamic Bapi call - Problem with field symbols (challenging)

Former Member
0 Kudos

Hi guys, I'm trying to implement a method that calls a bapi dynamically.

I try to create a type structure using RTTS and them fill each field dinamically... unfortunaly when I assign a data reference to a field symbol, casting it, it keeps giving me an error that the field symbol has no structure.

Please see the code above and give me ideias.

method CALLBAPI.

type-pools ABAP.

DATA: l_exceptionsTable TYPE ABAP_FUNC_EXCPBIND_TAB,

L_ParameterType TYPE REF TO cl_abap_structdescr,

L_ParameterTab TYPE STANDARD TABLE OF REF TO cl_abap_structdescr,

L_CompTab TYPE cl_abap_structdescr=>component_table,

L_Component TYPE CHAR30.

DATA: dref TYPE REF TO DATA.

FIELD-SYMBOLS: <l_parametersTable> TYPE ABAP_FUNC_PARMBIND,

<L_Struct_Components> TYPE abap_componentdescr,

<fs> TYPE ANY.

  • Get exporting Structures

LOOP AT L_PARAMETERSTABLE ASSIGNING <l_parametersTable> WHERE kind =

abap_func_exporting.

L_ParameterType ?= cl_abap_typedescr=>describe_by_name(

<l_parametersTable>-name ).

L_CompTab = L_ParameterType->get_components( ).

CREATE DATA dref TYPE HANDLE L_ParameterType.

ASSIGN dref->* TO <fs> CASTING TYPE HANDLE L_ParameterType.

LOOP AT L_CompTab ASSIGNING <L_Struct_Components>.

L_Component = <L_Struct_Components>-name.

*

  • number '1' is for tests purpose.

  • ****!!!!!!!!!*****!!!!!****THIS LINE GIVES AN ERROR:

*The data object "<FS>" has no structure and therefore no component

*called "" .

<fs>-(L_Component) = '1'.

ENDLOOP.

ENDLOOP.

*... need some code here...

call function l_bapi_name

PARAMETER-TABLE

l_parametersTable

EXCEPTION-TABLE

l_exceptionsTable.

endmethod.

Message was edited by:

Luis Pereira

Message was edited by:

Luis Pereira

Message was edited by:

Luis Pereira

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try something like this..

field-symbols : <FS> type standard stable. " change the declaration.

data : l_value(20).

Field-symbols : <FS1> type any.

l_value = (L_Component).

Assign component l_value of structure <FS> to <FS1>.

<FS1> = '1'.

2 REPLIES 2

Former Member
0 Kudos

try something like this..

field-symbols : <FS> type standard stable. " change the declaration.

data : l_value(20).

Field-symbols : <FS1> type any.

l_value = (L_Component).

Assign component l_value of structure <FS> to <FS1>.

<FS1> = '1'.

Former Member
0 Kudos

Hi

The <FS> is defined TYPE ANY so you can't indicate the name of a possible field of <FS>, because the system see <FS> like a structure only at run time:

<b><fs>-(L_Component) = '1'. <----


</b>

Try to use another field-symbols:

ASSIGN COMPONENT L_COMPONENT OF STRUCTURE <FS> TO <COMP>.
IF SY-SUBRC = 0.
  <COMP> = '1'.
ENDIF.

Max