maandag 8 november 2010

shortdump GENERATE_SUBPOOL_DIR_FULL

There's a limit on the number of sub-routines that can be generated within a program. This limit is 36 and anythng over this will create a short-dump(GENERATE_SUBPOOL_DIR_FULL).

The reason why SAP has put this limitation on it is, is to avoid an overflow of the program memory. Changing this number is not possible because it is a kernel constant and therefore, not variable and removing memory segments from the PXA is currently not supported by the kernel...

So you need to look for another solution.
There are 2 main reasons why you would want to generate a subroutine:
1. To create a dynamic structure
2. To create a dynamic program

Let me give you the solution for those 2 types of creating subroutines.

1. Create a dynamic structure:

Old Code
  DATA: lt_code(100) TYPE c OCCURS 0 WITH HEADER LINE,
        lv_type(100),
        lv_repid LIKE sy-repid,
        lw_fcat TYPE lvc_s_fcat.


* DYNAMISCH TYPES GENEREREN IN PROGRAMMA'S
  lt_code = 'REPORT GENERATE_TYPES.'.
  APPEND lt_code.

  lt_code = 'TYPES: BEGIN OF T_DATA,'.
  APPEND lt_code.

  LOOP AT p_fcattab INTO lw_fcat.
    CONCATENATE lw_fcat-fieldname 

                '(' 
                lw_fcat-intlen 
                ') TYPE c,' 
           INTO lt_code.
    APPEND lt_code.
  ENDLOOP.

  lt_code = 'END OF T_DATA.'.
  APPEND lt_code.

  GENERATE SUBROUTINE POOL lt_code NAME lv_repid.
  CONCATENATE '\PROGRAM=' lv_repid '\TYPE=T_DATA' INTO p_type.



New Code
*&--------------------------------------------------------------*
*&      Form  CREATE_INTERNAL_STRUCTURE

*&--------------------------------------------------------------*
*       Create internal structure
*---------------------------------------------------------------*
FORM CREATE_INTERNAL_STRUCTURE TABLES p_fcattab TYPE lvc_t_fcat
                  CHANGING p_struc TYPE REF TO cl_abap_structdescr
                           p_struc_table TYPE REF TO cl_abap_tabledescr.

  DATA: ls_comp TYPE abap_componentdescr,
        lw_fcat TYPE lvc_s_fcat,
        lt_comp TYPE cl_abap_structdescr=>component_table,
        lv_integer TYPE i.

  LOOP AT p_fcattab INTO lw_fcat.
    ls_comp-name = lw_fcat-fieldname.
    lv_integer = lw_fcat-intlen.
    ls_comp-type = cl_abap_elemdescr=>get_c( lv_integer ).
    APPEND ls_comp TO lt_comp.
  ENDLOOP.

  TRY.
   p_struc = 

           cl_abap_structdescr=>create( p_components = lt_comp ).
  CATCH cx_sy_struct_creation .
  ENDTRY.

  TRY.
    p_struc_table = cl_abap_tabledescr=>create( p_struc ).
    CATCH cx_sy_table_creation .
  ENDTRY.

ENDFORM.                    " CREATE_INTERNAL_STRUCTURE


2. Create a dynamic program

Main Program
  ...
EXPORT <whatever is needed> TO MEMORY ID 'ABC'.
* Execute the code generation logic in new internal mode
SUBMIT <Sub Program> AND RETURN.

Sub Program
  ...
IMPORT <whatever is needed> FROM MEMORY ID 'ABC'.
* Logic to generate the internal table of ABAP code
...
GENERATE SUBROUTINE POOL <codetab> NAME gv_program.
IF SY-SUBRC EQ 0.
PERFORM <generated form> IN PROGRAM (gv_program).
ENDIF.