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 Help

Former Member
0 Likes
788

Hey ABAPers,

I'm trying to write a function to where I can input a data element and it'll output the table of values for the config/F4 table with values. Please don't tell me of a function like SCTM_GET_TAB_FROM_DATA_ELEMENT or some other such function because it does not meet my specifications.

I can't seem to grasp the field symbols and object declaration assignings. I've looked through dozens of articles and can't seem to figure it out.

So far I have:

(skipping some data declarations and about my 10th iteration of this code so it's not pretty)

*import parameter = data_element

*export parameter = i_value_table

[code]

SELECT SINGLE ENTITYTAB

   INTO VALUE_TABLE

   FROM DD01L

   WHERE DOMNAME = DATA_ELEMENT.

IF VALUE_TABLE IS NOT INITIAL.

   TAB_NAME = VALUE_TABLE.

   DATA: WA_REF TYPE REF TO DATA,

         VT TYPE REF TO DATA.

   CREATE DATA WA_REF TYPE (TAB_NAME).

   ASSIGN WA_REF->* TO <WA>.

   SELECT *

     INTO <WA>

     FROM (TAB_NAME).

     APPEND <WA> TO ????.

   ENDSELECT.

[/code]

* export parameter

*  I_VALUE_TABLE = ???[].

Thank you in advance for your help.

Brian

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
705

Hi Brian,

data : lo_data_tmp        TYPE REF TO data.

field-symbols: <lt_data_tmp> TYPE STANDARD TABLE.



* Create internal table from structure

CREATE DATA lo_data_tmp TYPE TABLE OF (TAB_NAME).

.

   ASSIGN lo_data_tmp->* TO <lt_data_tmp>.

   SELECT *

     INTO TABLE <lt_data_tmp>

     FROM (TAB_NAME).

  

in the Export parameter

iv_value_table  type standard table 

Regards,

Vikram

4 REPLIES 4
Read only

Former Member
0 Likes
705

DATA: WA_REF TYPE REF TO DATA,
         VT TYPE REF TO DATA.

FIELD-SYMBOLS:<wa> type any TABLE.


   CREATE DATA WA_REF TYPE TABLE OF (TAB_NAME).

   ASSIGN WA_REF->* TO <WA>.

  SELECT *
     INTO table <WA>
     FROM (TAB_NAME)

Read only

Former Member
0 Likes
706

Hi Brian,

data : lo_data_tmp        TYPE REF TO data.

field-symbols: <lt_data_tmp> TYPE STANDARD TABLE.



* Create internal table from structure

CREATE DATA lo_data_tmp TYPE TABLE OF (TAB_NAME).

.

   ASSIGN lo_data_tmp->* TO <lt_data_tmp>.

   SELECT *

     INTO TABLE <lt_data_tmp>

     FROM (TAB_NAME).

  

in the Export parameter

iv_value_table  type standard table 

Regards,

Vikram

Read only

0 Likes
705

Vikram,

I followed up and the data flowed correctly and gave me what I was looking for. However, for anyone else reading this later on, I was having a problem with the export parameter. I declared it as ANY TABLE instead of STANDARD TABLE because when I put STANDARD TABLE it errors out on execution saying that it expects "ANY TABLE". This is funny because when I put ANY TABLE it still errors out and says that I cannot have a generic type. The error I receive each time is "Error generating test frame". After reviewing this and trying it outside of the SE37 it works perfectly, I guess I just wont be able to 'test' it via SE37 which is a small price to pay.

FUNCTION Z_GET_VALUE_TABLE.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(DATA_ELEMENT) TYPE  FIELD_TYPE

*"  EXPORTING

*"     VALUE(I_VAL) TYPE  ANY TABLE

Thanks,

Brian

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
705

Hi,  Check this.. In case of fixed values yo can use the itab lt_fixed_values

report abc.

data:lf_ref type ref to data.

field-symbols:<fs_tab> type standard table.

parameters:p_elem type ddobjname.

start-of-selection.

  call function 'YTEST_FUNCTION'

    exporting

      i_element = p_elem

    changing

      cf_ref    = lf_ref.

  if lf_ref is bound.

    assign lf_ref->* to <fs_tab>.

  endif.

Function

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(I_ELEMENT) TYPE  DDOBJNAME

*"  CHANGING

*"     REFERENCE(CF_REF) TYPE REF TO  DATA

*"  EXCEPTIONS

*"      ERROR

*"----------------------------------------------------------------------

  data:ls_dtel_header type dd04v,

       ls_doma_header type dd01v,

       lt_fixed_values type re_t_rsdomaval,

       lv_domain type ddobjname.

  data:lr_dyn_sql type ref to cx_sy_dynamic_osql_syntax,

       lv_msg     type string.

  field-symbols:<fs_tab> type any table.

  call method cl_reca_ddic_dtel=>get_complete

    exporting

      id_name   = i_element

      id_langu  = sy-langu

    importing

      es_header = ls_dtel_header

    exceptions

      not_found = 1

      others    = 2.

  if sy-subrc <> 0.

    message id sy-msgid type sy-msgty number sy-msgno

               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  endif.

  lv_domain = ls_dtel_header-domname.

  call method cl_reca_ddic_doma=>get_complete

    exporting

      id_name      = lv_domain

      id_langu     = sy-langu

    importing

      es_header    = ls_doma_header

      et_rsdomaval = lt_fixed_values

    exceptions

      not_found    = 1

      others       = 2.

  if sy-subrc <> 0.

    message id sy-msgid type sy-msgty number sy-msgno

               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  endif.

  create data cf_ref type table of (ls_doma_header-entitytab).

  check cf_ref is bound.

  assign cf_ref->* to <fs_tab>.

  check <fs_tab> is assigned.

  try .

      select * from (ls_doma_header-entitytab) into table <fs_tab>.

    catch cx_sy_dynamic_osql_syntax into lr_dyn_sql.

      lv_msg = lr_dyn_sql->get_text( ).

      message lv_msg type 'E' raising error.

  endtry.