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 Internal table Problem

Former Member
0 Likes
1,559

Hi friends,

My program is using this method frequently.But after few executions it is throwing excpetion of generate_subpool_dir_full . Since i am catching these exception so that error dump is gone but the result which should come in table t_newtable is not coming.

I gone through this method and found that upto 36 times,this method can be used.But my program can go upto any limit. I am really badly stuck at this point. Please help me out.

CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = t_fldcat
    IMPORTING
      ep_table                  = t_newtable
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.

Thanks and Regards,

Gaurav

7 REPLIES 7
Read only

Former Member
0 Likes
1,126

hi,

get try clearing the table before the method.

(or free the memory for table)

Atul

Read only

0 Likes
1,126

Hi Atul,

I am clearing the table before the method.

i am writing this 'clear t_newtable' before the method execution.

Thanks,

Gaurav

Read only

0 Likes
1,126

Hi,

You will not be able to generate table this way more that 36 times. This is beacuse internally this method create subroutine pool and here is the restriction as in the system you can create 36 of such at max in one session.

But there is other way around, using real dynamic programming and achieving the same - RTTS.

Look at this code, it generates table and returns reference to it at the end. I placed it in loop to prove that you can create it any number of times.


TYPE-POOLS: abap.

DATA: gs_comp TYPE abap_componentdescr,
      gt_comp TYPE abap_component_tab.

"data references
DATA: r_type_struct TYPE REF TO cl_abap_structdescr,
      r_type_table  TYPE REF TO cl_abap_tabledescr,
      r_data_tab    TYPE REF TO data,
      r_data_str    TYPE REF TO data.

" 1. ------------ first create components of strcture
gs_comp-name = 'PERNR'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'PERSNO' ).
APPEND gs_comp TO gt_comp.

gs_comp-name = 'KOSTL'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'KOSTL' ).
APPEND gs_comp TO gt_comp.

gs_comp-name = 'BEGDA'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'BEGDA' ).
APPEND gs_comp TO gt_comp.

" 2. ------------- then create structure type based on these components
TRY.
    r_type_struct = cl_abap_structdescr=>create(
                              p_components = gt_comp ).
  CATCH cx_sy_struct_creation .
ENDTRY.

" 3. ------------- create table type
TRY.
    r_type_table = cl_abap_tabledescr=>create( r_type_struct ).

  CATCH cx_sy_table_creation .
ENDTRY.

" 4. -------------- create table based on RTTS types
DO 100 TIMES.
  CREATE DATA: r_data_tab TYPE HANDLE r_type_table,
               r_data_str TYPE HANDLE r_type_struct.
  WRITE: / 'table created ', sy-index, 'times'.
ENDDO.

After that you can work with r_data_tab as dynamic table (reference to it) and r_data_str as work area for that table (reference).

Regards

Marcin

Read only

0 Likes
1,126

Hi Marcin,

Thanks for the reply..I am using SAP 4.7 and i think this approach is not permissible in it.Please suggest some approach which can be used in 4.7.

Thanks,

Gaurav

Read only

0 Likes
1,126

Ok, there is another way, but gives some restrictions. You need to create an RFC enabled function module. Inside, place your code

to create dynamic table, then call that FM using addtion STARTING NEW TASK.

- go to SE37 -> create FM -> in Attributes tab select Remote Enabled Module

- go to Import tab -> type in


FIELDCAT	TYPE	LVC_T_FCAT   "we will pass field catalog each time here

also select Pass value as no references can be passed in RFC module

- in Changing tab


SUBRC	TYPE	I "and select 'Pass Value' - this one will notify the result of the call

- in Source code


  data: r_newtab type ref to data.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
   EXPORTING
      it_fieldcatalog           = FIELDCAT
    IMPORTING
      ep_table                  = r_newtab
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
    subrc = sy-subrc.

   "here unfortunatelly must go your coding which handles R_NEWTAB, you can't pass it back to the calling program
   "as references are not allowed as parameters

- in ABAP program write


DATA: it_fieldcat TYPE lvc_t_fcat,
      r_newtab TYPE REF TO data.

DATA: rest TYPE i,
      subrc LIKE sy-subrc.

DATA: task(8) TYPE c.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name = 'SFLIGHT'
  CHANGING
    ct_fieldcat      = it_fieldcat.

DO 250 TIMES.
  rest = sy-index MOD 36.

  IF rest = 0.
    task = task + 1.
  ENDIF.

  CALL FUNCTION 'ZTEST_NEW_TASK' STARTING NEW TASK task
    EXPORTING
      fieldcat = it_fieldcat
    CHANGING
      subrc    = subrc.
  IF subrc = 0.
    WRITE: / 'Table created ', sy-index, 'times, in task ', task.
  ENDIF.
ENDDO.

This way you call FM starting new task (new session) each time it raises 36 times (max per internal session).

That should work in 4.7, works fine in ECC 5.0, but strong disadvange is as I said, restrcition to do the coding inside FM, because you can't pass

reference back to the program.

Regards

Marcin

Read only

Former Member
0 Likes
1,126

Dear Gaurav,

If the Function module returns the same result everytime then u can do as follows.

in the following code create one more dummy internal table it_dummy which is of same type as t_newtable

CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = t_fldcat
    IMPORTING
      ep_table                  = it_dummy 
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.

if it_dummy is not initial. 
 t_newtable[] = it_dummy[].
endif.

Regards

Sajid

Read only

Former Member
0 Likes
1,126

Dear Gaurav,

If the Function module returns the same result everytime then u can do as follows.

in the following code create one more dummy internal table it_dummy which is of same type as t_newtable

CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = t_fldcat
    IMPORTING
      ep_table                  = it_dummy 
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.

if it_dummy is not initial. 
 t_newtable[] = it_dummy[].
endif.

Regards

Sajid