cancel
Showing results for 
Search instead for 
Did you mean: 

Function Module

Former Member
0 Kudos

HI.

I have got a function module with hashed table as a parameter.

When i press F8 to execute it says

"Error generating the test frame"

The error message is:

"ANY TABLE" expected, not "HASHED TABLE".

i have no code in inside the function module. Just defined it and tested it. its just failing

*" IMPORTING

*" REFERENCE(I_ZCONGRP_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZCOMP_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZFSITEM_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZMOV_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZFUNC_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZACTDISP_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZCOSTANAL_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZCONTDIS_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZPROCAT_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZPARTCOMP_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZINV_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZDOCTYPE_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZPOST_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZCURKEY4T_CHK) TYPE STRING OPTIONAL

*" REFERENCE(I_ZCURKEY_I_CHK) TYPE STRING OPTIONAL

*" EXPORTING

*" VALUE(E_T_DATA) TYPE HASHED TABLE

Edited by: Alvaro Tejada Galindo on Feb 8, 2008 10:40 AM

Accepted Solutions (0)

Answers (1)

Answers (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You will not be able to test this function in this way, as the framework can not generate a generic parameter, you must write a test report program which calls your function to test it completely.

Regards,

Rich Heilman

Former Member
0 Kudos

i have written a test program call this function module.

It is throwing exception "GETWA_NOT_ASSIGNED"

"You attempted to access an unassigned field symbol"

WHAT shall i do ?

FIELD-SYMBOLS: <t_Hashed> type HASHED TABLE.

CALL FUNCTION 'Z_RTTI_HASHEDTABLE'

EXPORTING

I_ZCONGRP_CHK = 'X'

  • I_ZCOMP_CHK = ZCOMP_CHK

  • I_ZFSITEM_CHK = ZFSITEM_CHK

  • I_ZMOV_CHK = ZMOV_CHK

  • I_ZFUNC_CHK = ZFUNC_CHK

  • I_ZACTDISP_CHK = ZACTDISP_CHK

  • I_ZCOSTANAL_CHK = ZCOSTANAL_CHK

  • I_ZCONTDIS_CHK = ZCONTDIS_CHK

  • I_ZPROCAT_CHK = ZPROCAT_CHK

  • I_ZPARTCOMP_CHK = ZPARTCOMP_CHK

  • I_ZINV_CHK = ZINV_CHK

  • I_ZDOCTYPE_CHK = ZDOCTYPE_CHK

  • I_ZPOST_CHK = ZPOST_CHK

  • I_ZCURKEY4T_CHK = ZCURKEY4T_CHK

  • I_ZCURKEY_I_CHK = ZCURKEY_I_CHK

IMPORTING

E_T_data = <t_Hashed>.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Well, I would say that you must first assign the field symbol before calling your function.

Regards,

RIch Heilman

Former Member
0 Kudos

Ok but where ? please tell me.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

To clarify, you are calling this function and trying to recieve a dynamic internal table, yes?

Regards,

Rich Heilman

Former Member
0 Kudos

thats right.

Former Member
0 Kudos

NO ONE KNOWS HOW TO DO IT ?

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

So I guess we don't know the structure of it before the call then, huh? This is what is making it a little tricky, we need to create a dynamic intenral table in your test program to receive the table coming from the function call.

Regards,

Rich Heilman

Former Member
0 Kudos

yes but whats the solution to this. ???

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Well, I believe there is a problem with using a hash table here, as I'm finding some issue when using it inside the function, it appears that it wants to force you to use a key when declaring it, if your table is truly generic, then this will not work. SO we need to use a standard table, but again we have the same problem with getting this table in our test program. Instead of trying to pass table itself, lets pass a data object. We are assuming that there is a data object inside the function module which was used to create the dynamic internal table.

Here was the code in my test FM.



FUNCTION z_test_table.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  EXPORTING
*"     REFERENCE(ET_TAB) TYPE REF TO  DATA
*"----------------------------------------------------------------------

  DATA: lv_tabname TYPE tabname VALUE 'T000'.
  DATA: lo_dataref    TYPE REF TO data.

  FIELD-SYMBOLS: <lt_tab> TYPE TABLE.

* Create the dynamic internal table
  TRY.
      CREATE DATA lo_dataref TYPE TABLE OF (lv_tabname).
      ASSIGN lo_dataref->* TO <lt_tab>.
    CATCH cx_sy_create_data_error .
  ENDTRY.

* fill the internal table
  SELECT * INTO TABLE <lt_tab> FROM (lv_tabname).

* get refence and pass internal table back as data object
GET REFERENCE OF <lt_tab> INTO et_tab.

ENDFUNCTION.


Now in your test program, you can do something like this.




REPORT  zrich_0001 .

DATA: oref TYPE REF TO data.

FIELD-SYMBOLS: <lt_tab> TYPE  table.

* import the data object
CALL FUNCTION 'Z_TEST_TABLE'
  IMPORTING
    et_tab = oref.

* assign to a field symbol, <LT_TAB> is now your internal table
ASSIGN oref->* TO <lt_tab>.

Regards,

Rich Heilman

matt
Active Contributor
0 Kudos

You're correct that the FM must pass a reference - not a field-symbol. ( I have to do stuff like this all the time in classes ). The way to define the hashed table is to use some nested types, as it is done in SEM BPS. So ALL the tables will have to be like this:

TYPES: begin of my_hashed_table_struc.
         begin of s_key,
           fld1,
           ....
         end of s_key,
         begin of s_others,
           val1,
           ...
         end of s_others,
      end of my_hashed_table_struc.

Then, when you define the hashed table, s_key is always the key.

If you don't do something like this, you are stuffed, because you simply don't know the key.

----please embed your code in

tabs so that it is readable.

cheers

matt

Former Member
0 Kudos

Thanks for excellent support.

What i have done is i made 2 function modules. 1st one creates the structure and returns back with keys + structure and 2nd one creates a dynamic internal table based on returned structure and keys and gives back the gs_tabledescriptor and then i make table out of that.

But are you trying to say that my code doesnt worked because the field symbols was declared as hashed table without keys ? What i thought that hashed table fieldsymbol didnt worked because at compile time structure is not known and my fieldsymbol never had any structure so the line type could not be created for hashed internal table as it is very generic.

1) One more thing MATT, is that when you said all table must be defined with nested structure(COMPILE TIME). But in my case we dont know the structure during compile time so how does your structure code fits in mine scenario. Please advice.

2) RICH, When you wrote :

 DATA: lv_tabname TYPE tabname VALUE 'T000'.
  DATA: lo_dataref    TYPE REF TO data.
 
  FIELD-SYMBOLS: <lt_tab> TYPE TABLE.
 
* Create the dynamic internal table
  TRY.
      CREATE DATA lo_dataref TYPE TABLE OF (lv_tabname).

In this case the structure is know that why you are dynamically passing T000 table. But what if the lv_tabname is also created dynamically ?

what do you think i must bear in mind before doing this.

Nice work Rich and Matt !!