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 function module call

Former Member
0 Likes
3,780

Hi all,

can anybody suggest me how to handle import, export and tables parameters in a dynamic function module call if they are associated with TABLE types.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,573

You might be interested in reading this [http://help.sap.com/abapdocu_702/en/abapcall_function_dynamic.htm].

39 REPLIES 39
Read only

former_member209703
Active Contributor
0 Likes
879

What do you mean by 'handle'? If you have a dynamic FM call, you have to specify all the parameters accordingly in the call, no matter what type the have.

Read only

0 Likes
879

Thanks for your reply.

Let me be clear enough about my question.I am developing a RFC Wrapper which can take inputs as Function module name and its parameters.

As of now its working fine if the input FM is not associated with Table Types.

What could be the reason?

can you please give the outline

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
879

As of now its working fine if the input FM is not associated with Table Types.

Can you elaborate what error you're getting if you use Table Types?

Read only

0 Likes
879

my input FM name is SWNC_GET_workload_snapshot

ERROR MESSAGE.

Short text:

Type conflict when calling a function module.

Error analysis

The function module interface allows you to specify only fields of a particular type under "READ_TRANSIDS".

The field " " specified here is a different field type.

>>>>> CALL FUNCTION name

607

608 PARAMETER-TABLE

609 ptab

Read only

0 Likes
879

And what type are you using instead of the correct one for that field SWNC_T_TRANSIDS ?

Read only

0 Likes
879

ok..for this FM (SWNC_GET_WORKLOAD_SNAPSHOT) we know that the parameter READ_TRANSIDS is associated with a table type , But if i pass another FM to the same Wrapper, how do i know the associated type and processing it accordingly

may be i am wrong , as of now i am using all character type in my import parameters.

Read only

0 Likes
879

Maybe I am not getting your point, but if you are trying to call a FM that already exists, all the parameter types you use, must match the ones defined in the FM interface, meaning you can not use generic types.

Read only

0 Likes
879

That's right. we are on the same page.you got it what i am trying to say.

I think i am almost there.

Initially my Wrapper was working for the FM's in which associated type is referred to a table field (example: RFC_READ_TABLE) . But i made the corrections in my code to get the TYPE dynamically from the structure(for FM's which are not referring to a database field).similarly how do i know whether it is associated with table type and what all the steps i have to take to populate my PTAB.

Read only

0 Likes
879

Maybe you can use this FM, FUNCTION_IMPORT_INTERFACE

Given an existing FM it gives you detailed information about all the interface parameters its got.

Read only

0 Likes
879

ya by using that FM i did up to now.

but the issue is , can we actually input the table type data at run-time if yes, how is it possible

My intention of calling a dynamic FM, which actually have to run as normal or standard FM but the output should be in CHAR data type

code snippet for your understanding..

IMPORT PARAMETERS

NAME TYPE TFDIR-FUNCNAME

PARAM1 TYPE CHAR30

PARAM2 TYPE CHAR30

EXPORT PARAMS

IT_EXPO1 TYPE THENV

IT_EXPO2 TYPE THENV

TABLES PARAMS

IT_DATA1 LIKE ZSCHAR4500

IT_DATA2 LIKE ZSCHAR4500

EXCEPTIONS

FUNCTION_NOT_FOUND FUNCTION MODULE NOT FOUND

FUNCTION_MODULE_FOUND FUNCTION MODULE FOUND

*CODE

LOOP AT it_import1 INTO wa_import.

ptab_line-name = wa_import-parameter.

ptab_line-kind = abap_func_exporting.

if wa_import-dbfield is not initial.

CREATE DATA dyn_ref TYPE (wa_import-dbfield).

endif.

if wa_import-dbfield is initial.

data w_type1 type c length 30.

w_type1 = wa_import-typ.

CREATE DATA dyn_ref TYPE (w_type1).

endif.

Edited by: sam_samuel on Aug 11, 2011 4:24 PM

Edited by: sam_samuel on Aug 11, 2011 4:30 PM

Read only

0 Likes
879

Hi,

The issue is that when you use CREATE DATA dyn_ref TYPE (wa_import-dbfield) when it's about a TABLES parameter which refers to a structure, you only create a structured data object, not a table type. So, you should use CREATE DATA dyn_ref TYPE TABLE OF (wa_import-dbfield)

Be careful, a TABLES parameter may also refer to a table type, then you shouldn't create a "table type of table type", but continue using CREATE DATA dyn_ref TYPE (wa_import-dbfield)

Now, it seems you have 2 other questions??

- can we actually input the table type data at run-time if yes, how is it possible

- the output should be in CHAR data type

What do you mean? (do you want something like the SE37 test framework? But what exactly?)

BR

Sandra

Read only

0 Likes
879

Hi Rossi,

output should be in CHAR format means

-This wrapper RFC is triggered by third party system, which understands only char type data i.e the output tables associated type must be a char type (the abap defined packed, raw data types are not understandable)

- My wrapper should work as any standard FM but the only difference is, The output Export parameters,Tables parameters should be in char type

Table type means

- can we give the table values as input(in table format0 for a FM,if Yes can you suggest me

Edited by: sam_samuel on Aug 12, 2011 7:57 AM

Read only

0 Likes
879

but the issue is , can we actually input the table type data at run-time if yes, how is it possible

Actually we can. So given this, I stil don't know what you are missing in your code.


DATA: l_funcname TYPE c LENGTH  30,
      l_data TYPE swncdatum,
      l_time TYPE swncuzeit.

DATA: data TYPE REF TO data,
      l_type TYPE c LENGTH 30.
FIELD-SYMBOLS <fs> TYPE table.


l_data = '20110101'.
l_time = '121212'.

l_funcname = 'SWNC_GET_WORKLOAD_SNAPSHOT'.
l_type = 'SWNCGL_T_AGGTASKTYPE'.

CREATE DATA data TYPE (l_type).
ASSIGN data->* TO <fs>.


CALL FUNCTION l_funcname
  EXPORTING
    read_start_date = l_data
    read_start_time = l_time
    read_end_date   = l_data
    read_end_time   = l_time
  IMPORTING
    tasktype        = <fs>.

Read only

0 Likes
879

This wrapper RFC is triggered by third party system, which understands only char type data i.e the output tables associated type must be a char type (the abap defined packed, raw data types are not understandable)

I guess you're looking for a dynamic way to access components. Well, this has been answered a ton of times in the forum. Here is the principle, and if you need more information, refer to the corresponding ABAP documentation. By the way, I assume/hope that your internal tables do not contain nested structures, internal tables... (it would be a little bit more complex to handle, for example using recursive processing)


FIELD-SYMBOLS <itab> TYPE STANDARD TABLE.
"<=== Here assign <itab>
FIELD-SYMBOLS <wa> TYPE ANY.
FIELD-SYMBOLS <field> TYPE ANY.
DATA type TYPE c LENGTH 1.
DATA char TYPE c LENGTH 100.
DATA string TYPE string.
LOOP AT <itab> ASSIGNING <wa>.
  DO.
    ASSIGN COMPONENT sy-index OF <wa> TO <field>.
    IF sy-subrc NE 0. EXIT. ENDIF.
    DESCRIBE FIELD <field> TYPE type.
    CASE type.
      WHEN 'P'.
        WRITE <field> TO char. "<=== Here, add the formatting options you want
      WHEN 'C' OR 'g'.
        char = <field>.
      WHEN OTHERS.
"<=== handle cases for all elementary data types
    ENDCASE.
  CONCATENATE string ';' char INTO string.
  ENDDO.
ENDLOOP.

Sandra

Read only

0 Likes
879

Hi sam,

for the dynamic function call, you can create whatever data type you need: Define a varfiable, i.e. lr_any type ref to data and a field-symbol type any table.

Then, according to FM interface description, you can

CREATE DATA lr_any TYPE TABLE OF (<structure type>) or
CREATE DATA lr_any TYPE  (<table type>) .

Then

assign lr_any->* to <field-symbol>.

and pass it to function module parameter.

For the pure-character data exchange with external system you may dynamically assign the components to field-symbol, put content into string and concatenate all the strings by tabulator, i.e.

FIELD-SYMBOLS:
  <record> TYPE ANY,
  <field>    TYPE any.
DATA:
  lv_field  TYPE string
  lv_record TYPE string,
  lt_output TYPE TABLE of STRING.

LOOP AT <any> ASSIGNING <record>.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <record> TO <field>.
    IF sy-subrc = 0.
      lv_field = <field>.
      IF lv_record IS INITIAL.
        lv_record = lv_field.
      ELSE. 
      CONCATENATE lv_record lv_field INTO lv_record
        SEPARATED BY cl_abap_char_utilities=>hoizontal_tab.
      ENDIF
    ELSE.  
      EXIT." DO
    ENDIF.
  ENDDO.
  APPEND lv_record TO lt_output.
  CLEAR lv_record.
ENDLOOP.

This is the way to return data to external call. If you want to receive data from external system, it would be the other way round.

Regards

Clemens

Read only

0 Likes
879

let me say that, i am declaring as table types for all the input parameters(say 10 parameters).At run time i got to know that i have five char type inputs and other five as table types.

How can i achieve this?

Read only

0 Likes
879

Hi sam,

after you got the info from FM FUNCTION_IMPORT_INTERFACE, you can

CREATE DATA lr_any TYPE (<type>).
ASSIGN lr_any to <any>. 

Then use describe (or any CL_ABAP_TYPE

_DESCR method) to find out if it is a table, structure, field or what ever.

Regards

Clemens

Read only

0 Likes
879

Hi,

thanks for your reply,i got what you are trying to say.

but i have a question.

How about my Local inteface of my FM. any way it is not accepting generic types, in the import parameters.

what would you suggest in this regard......

and let me know how to dump the internal data which is present in the field-symbol to my custom internal table(which is associated with CHAR type)

Read only

0 Likes
879

Hi sam,

you will have to establish some rules anyway. Everything still depends on INPUT OUTPUT CHANGING and TABLES parameters.

Think about it, try, test.

Regards

Clemens

Read only

0 Likes
879

hi,

i am almost there ............

the issue is when i am using the following statement the system variable SY-TABIX is becoming ZERO .

descr_ref ?= cl_abap_typedescr=>describe_by_data( w_type1 ).

can you suggest me how to increment SY-TABIX accordingly as per my requirement.

In fact, in the same loop i am assigning the input(import) parameters to PARAM-table.

Even if i use CASE-WHEN my SY-TABIX value holding 0 value

Read only

0 Likes
879

hi,

when i use the suggested code by you i am getting an output where i can't do further processing

CONCATENATE lv_record lv_field INTO lv_record

my expected output must be.......

01 36.119 17.08.2011 38.492 17.08.2011

02 29.645 17.08.2011 38.484 17.08.2011

03 29.647 17.08.2011 38.446 17.08.2011

But my output looks something like below

01 36119 20110817 38492 20110817

02 29645 20110817 38484 20110817

03 29647 20110817 38446 20110817

where do i go wrong?

i need to differentiate float values(.) as well

Read only

0 Likes
879

Hi Sam,

it always depends on what you want.

You expect external representation of data (decimal and thousand separator, date format) but you get internal data representation. If you have fields in appropriate dynamically created structure/table, you can CREATE DATA lr_OUT TYPE CHAR LENGTH <output length> and then use WRITE TO to convert to externasl representation.

Get the ouput length from describe field or CL_ABAP_TYPEDESCR.

But, honestly, isn't that obvious?

Regards

Clemens

Read only

0 Likes
879

hi Clemens,

thanks for your patience

When i print the dynamic internal table data using 'WRITE' i see it, what i was expecting.

can you please suggest me how to get the data in a table

i have declared a static table with maximum number of components (comp1,comp2,comp3........................)

could you explain me with coding ............with 'write to' statement ..................

Read only

0 Likes
879

Hi all,

Write statement would look something like this:


DATA: var1    TYPE char10,
      var2    TYPE char20,
      decimal TYPE p LENGTH 16 DECIMALS 3 VALUE '20000.987'.

WRITE sy-datum to var1.
WRITE decimal  to var2.

WRITE: / var1,
       / var2.

Igor.

Read only

0 Likes
879

hi

i am expecting something like 'WRITE TO' statement which actually populates my static internal table from dynamic table data (static internal table is defined with maximum number of components all of CHAR type (say comp1,comp2,comp3,................. )

Any inputs please..............

Read only

0 Likes
879

There are several ways of doing it.

I 'll pass You one that 'll do the work, but I 'm not sayin it's best practice.

And this logic is applyable only when mapping goes 1 on 1.


TYPES:
  BEGIN OF abap_type_struc,
   date    TYPE d                     ,
   decimal TYPE p LENGTH 16 DECIMALS 3,
  END   OF abap_type_struc,
  BEGIN OF char_type_struc,
   date    TYPE char10,
   decimal TYPE char20,
  END   OF char_type_struc.

FIELD-SYMBOLS:
  <a_field> TYPE ANY,
  <c_field> TYPE ANY.

DATA:
  a_struc   TYPE abap_type_struc,
  c_struc   TYPE char_type_struc,
  component TYPE i              .

a_struc-date    = sy-datum   .
a_struc-decimal = '20000.987'.

WHILE sy-subrc = 0.
  ADD 1 TO component.

  ASSIGN COMPONENT component OF STRUCTURE a_struc TO <a_field>.
  IF sy-subrc = 0.
    ASSIGN COMPONENT component OF STRUCTURE c_struc TO <c_field>.
    IF sy-subrc = 0.
      WRITE <a_field> TO <c_field>.
    ENDIF.
  ENDIF.
ENDWHILE.

WRITE: / c_struc.

Hope it'll wake up creativity in your development.

Igor.

Read only

0 Likes
879

thanks for your response.

There are several ways of doing it.

I have huge data in dynamic internal tables internal table

can you suggest any other procedure where i can automate the transfer of data into my static internal tables

the above mentioned code can be implemented if i have less data ....I guess...

Edited by: sam_samuel on Aug 18, 2011 8:31 AM

Edited by: sam_samuel on Aug 18, 2011 8:35 AM

Read only

0 Likes
879

Few issues to solve first:

1. I need entire code of program where you want to implement this logic!

2. How many records do you expect in that internal table?

3. We are talking about RFC module as I understand?

Igor.

Read only

0 Likes
879

Hi Igor Grbesa,

---I am working with FM- SWNC_GET_WORKLOAD_SNAPSHOT

SWNC_GET_SNAPSHOT_FRAME and some other.

so my RFC wrapper should actually accept any one FM of the above mentioned, FM and their import parameters as inputs

and must show me the output as standard FM output but with My custom defined CHAR type data in tables.

-


can u send me your E-mail ID so that i can send the code...

Read only

0 Likes
879

This message was moderated.

Read only

0 Likes
879

Hello,

SWNC_GET_WORKLOAD_SNAPSHOT

SWNC_GET_SNAPSHOT_FRAME and some other.

If it's only for, say, 10 function modules, it's not worth (loss of time) doing a generic program, it's just interesting for the intellectual effort (and for doing a quickly reusable tool maybe). If you create the RFC wrappers, it will take you only 1 hour to do it: copy the function modules, replace the code by a function call (using the "function module" pattern, with option to fill automatically the parameters from data objects with same name), I think the parameters already are passed by value and refer to DDIC data types.

can u send me your E-mail ID so that i can send the code...

I hope you'll continue to post in this thread, because a few people follow this thread.

Thank you for us

Sandra

Read only

0 Likes
879

Hi Sandra Rossi

it will take you only 1 hour to do it: copy the function modules, replace the code by a function call

i can't get you,

any contribution from your side will be really appreciable.........

i will be continuing to post..............

Read only

0 Likes
879

In fact, I was thinking that you wanted to create an RFC wrapper (one generic RFC-enabled function module that can be used to call any non-RFC-enabled function module), but I just saw these function modules are already RFC-enabled.

In fact, I still don't understand what you want to achieve, what is the advantage of doing all this?

Sandra

Read only

0 Likes
879

Hi Sandra Rossi

First of all , let me admit myself that i am bad in expressing..............

My actual task is ...

---i have to develop a generic RFC (Which can accept standard FM and import parameters as INPUT)which is called by a third party system which understands only CHAR type data .

All standard FM will give the output in different data types(say RAW,PACKED,etc...)

-


This RFC should work same as Standard RFC but the output must be in pure CHAR type(say my tables must be associated with pure CHAR or string type)

hope you are getting what i am trying to say...........

any inputs will be really appreciated...........

Regards

samuel

Read only

0 Likes
879

Hi Samuel,

Okay, you explained very well. Not easy at all, so I think you should discuss of the requirement with the teams involved. Are they sure they can't read these data at all? (the packing algorithm is rather simple, what language do they use?) Or instead of transmitting the whole data, can't you send only the required data? That requires more analysis on the "other" side. Last thing, I think XML would be rather easy to generate, could they read it? Otherwise, it will take a long time to develop in ABAP! (it doesn't seem reasonable)

Sandra

Read only

0 Likes
879

Hi Sam,

I don't see the problem of this code. I did not see your code except one line. I don't know why you are discussing instead of doing.

I think if really the last thing missing is putting data from dynamic created table to output table, what's the problem?

loop at dyntab assigning <dline>.
  append initial line to outtab assigning <out>.
  do.
  assign component sy-index of <line> to <source>.
    if sy-subrc <> 0.
      exit.
    endif.
  assign component sy-index of <out> to <dest>.
  write <source> to <dest>.
  enddo.
endloop.

Regards

Clemens

P.S. I'd love to see more than 2 lines of your code

Read only

0 Likes
879

Hi Clemens

THANK you for your answers.

can you be clear with the terms dyntab <dline> outtab <out> <line> <source> <dest>......

The following code displays the data in internal representation, but i want it in correct format say it should display float values,date,time ,etc...........

LOOP AT <fsepo1> ASSIGNING <record>.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <record> TO <field>.
    IF sy-subrc = 0.
      lv_field = <field>.
    IF lv_record IS INITIAL.
       lv_record = lv_field.
     ELSE.
     CONCATENATE lv_record lv_field INTO lv_record  SEPARATED BY '   '.
     ENDIF.
    ELSE.
      EXIT." DO
    ENDIF.
  ENDDO.
  APPEND lv_record TO lt_output.
  CLEAR lv_record.
ENDLOOP.

Read only

0 Likes
879

Sorry sam. I stop watching this thread.

Annoyed

Clemens

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,574

You might be interested in reading this [http://help.sap.com/abapdocu_702/en/abapcall_function_dynamic.htm].