Application Development 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: 

Dynamic program generation problem

Former Member
0 Kudos

Hi guys,

Does subroutine in dynamically generated program can't be be invoked with parameter?

If perform dyn subroutine without any parameters, it's run well, anybody can tell me why?

REPORT z_test.

TYPES: BEGIN OF tp_sflight,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

fldate TYPE sflight-fldate,

price TYPE sflight-price,

END OF tp_sflight.

DATA: BEGIN OF fld_list OCCURS 0,

fld_name(20),

END OF fld_list.

DATA: gt_outtab TYPE TABLE OF tp_sflight WITH HEADER LINE.

DATA: source_line(72).

DATA:

gi_source LIKE STANDARD TABLE OF source_line,

l_prog_name(30) TYPE c,

l_msg(120) TYPE c,

l_line(10) TYPE c,

l_word(10) TYPE c,

l_off(3) TYPE c.

START-OF-SELECTION.

SELECT * FROM sflight

INTO CORRESPONDING FIELDS OF TABLE gt_outtab

UP TO 10 ROWS.

fld_list-fld_name = 'connid'.

APPEND fld_list.

fld_list-fld_name = 'price'.

APPEND fld_list.

APPEND 'PROGRAM MY_SUBPOOL.' TO gi_source.

APPEND 'FORM WRITE_DYN_CONTENT USING wa TYPE sflight.' TO gi_source.

LOOP AT fld_list.

CLEAR source_line.

CONCATENATE 'WRITE wa-' fld_list-fld_name '.' INTO source_line.

APPEND source_line TO gi_source.

ENDLOOP.

APPEND 'ENDFORM.' TO gi_source.

GENERATE SUBROUTINE POOL gi_source

NAME l_prog_name MESSAGE l_msg LINE l_line

WORD l_word OFFSET l_off.

IF sy-subrc <> 0.

WRITE : / 'Error', l_msg.

ENDIF.

WRITE l_prog_name.

LOOP AT gt_outtab.

PERFORM write_dyn_content <b>USING gt_outtab </b> IN PROGRAM (l_prog_name).

ENDLOOP.

Regards,

Tim

Message was edited by: jingen tang

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

I can work fine, but you have to define the parameter using the same type:

See these pieces of your code:

DATA: gt_outtab TYPE TABLE OF tp_sflight WITH HEADER LINE.

APPEND 'FORM WRITE_DYN_CONTENT USING wa TYPE sflight.' TO gi_source.

So gt_outtab and wa are of different types:

Try to use this declaration:

DATA: gt_outtab TYPE TABLE OF sflight WITH HEADER LINE.

and your subroutine'll work fine

Max

5 REPLIES 5

Former Member
0 Kudos

Hi

I can work fine, but you have to define the parameter using the same type:

See these pieces of your code:

DATA: gt_outtab TYPE TABLE OF tp_sflight WITH HEADER LINE.

APPEND 'FORM WRITE_DYN_CONTENT USING wa TYPE sflight.' TO gi_source.

So gt_outtab and wa are of different types:

Try to use this declaration:

DATA: gt_outtab TYPE TABLE OF sflight WITH HEADER LINE.

and your subroutine'll work fine

Max

0 Kudos

Hi Max,

Thanks for your reply.

I have changed the code as you said, but it still can't work. when I check the program it reports that:

Field "IN" is unknown. It is neighter in one of the specified tables nor defined by a "DATA" statement.

Tim

0 Kudos

Hi

Make this change:

LOOP AT gt_outtab.

<b>*PERFORM write_dyn_content USING gt_outtab IN PROGRAM

*(l_prog_name).</b>

PERFORM write_dyn_content IN PROGRAM (l_prog_name) USING gt_outtab.

ENDLOOP.

Anyway you can create max 36 temporary subroutine pools, then a dump'll occurs.

So you should check to have max 36 records in table gt_outtab, or you transfer it once:

<b>PERFORM write_dyn_content IN PROGRAM (l_prog_name) TABLES gt_outtab.</b>

Max

0 Kudos

Hi Max,

It's run well now, thks for your help.

<b>You said:</b>

Anyway you can create max 36 temporary subroutine pools, then a dump'll occurs.

So you should check to have max 36 records in table gt_outtab, or you transfer it once

<b>Do you mean:</b>

in a program if itab contains more than 36 records, we should transfer data once, otherwise it will affect the program performance?

Since I select more than 36 records and transfer them one by one, and not find any questions.

Regards,

Tim

Message was edited by: jingen tang

0 Kudos

Hi

From SAP help:

Notes

1- Temporary subroutine pools belong to the runtime context of the generating program, i.e. to the roll area of the internal mode from which the generation is performed. They may therefore be addressed only within this context, i.e. the generated FORM routines can only be called from within the generating mode.

2- Up to 36 temporary subroutine pools can currently be managed for each roll area.

So it means you can generate max 36 subroutine, but your code generate a subroutine for every record of GT_OUTTAB, so if this table has more 36 records, the program try'll to generate more than 36 subroutine, but a dump'll occurs at 37th record.

So if you want to prevent this you should generate the subroutine once and moreover you'll improve the performance because generate subroutine only once.

You can prevent an eventual dump using CATCH/ENDCATCH

LOOP AT GT_OUTTAB.

CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 1.

PERFORM WRITE_DYN_CONTENT IN PROGRAM (L_PROG_NAME) USING GT_OUTTAB.

ENDCATCH.

IF SY-SUBRC <> 0.

  • Other subroutines can't be called

EXIT.

ENDIF.

ENDLOOP.

Max