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

Execute code that is stored in a variable

Former Member
0 Likes
3,698

Hi,

I have a variable that reads, like >> SBOOK-CONNID TYPE C LENGTH 30, SBOOK-CARRID TYPE C LENGTH 4, ... << and so on - a series of field_declarations that should make up the line_type of an internal table.

Declaring an internal table is simple, there is only one dynamic part about it, that's the line_type.

How can I now have the code, which should commonly look like

- TYPES: BEGIN OF line, [field_decl1], [field_decl2], ..., END OF line

executed, using the individual parts of that long variable as individual field_declarations?

I have tried splitting that variable and assigning field-symbols all over, but I always ended up either with an error message or with a proper internal table - that had only one field named like my variable - or 12 fields named comp1, comp2 etc.

Can anyone aid me here? I cannot imagine that should be so complex, actually, since all the info I need is available at that point.

Thanks a lot!

Best regards,

Sapperdapper

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
3,047

One way could be to generate a (temporary) include using INSERT REPORT.

However, please explain what you are actually trying to achieve, e.g. what you are planning to do with such declared TYPES definition.

Often there are alternative routes that don't come to mind initially.

Thomas

21 REPLIES 21
Read only

ThomasZloch
Active Contributor
0 Likes
3,048

One way could be to generate a (temporary) include using INSERT REPORT.

However, please explain what you are actually trying to achieve, e.g. what you are planning to do with such declared TYPES definition.

Often there are alternative routes that don't come to mind initially.

Thomas

Read only

0 Likes
3,047

Hi Thomas,

what I am trying to do is declaring an internal table, the fields (incl. datatype, length and decimals) of which are only identified at runtime.

In a LOOP, I fill an internal table i_fcat with all that information that I was up to now passing to the method cl_alv_table_create=>create_dynamic_table. That method was actually working fine - the problem is that I end up with an internal table that has no clearly defined structure and which I cannot access to use commands like SORT. That is why I'm trying to replace that method and just create a standard internal table. Since I have all the information I need to do that at that point, I was surprised that it turned out to be quite tricky.

INSERT REPORT, however, seems to be a good idea since I actually need to do two things: Write the contents of that variable and execute the code I get that way.

Apparently, I cannot insert the variable (which actually holds all the field_declarations, separated by ',' already) into a linetype_declaration just like that - it works, but the table then has only one field, named like my variable.

Thanks a lot!

Best regards,

Sapperdapper

P.S.: That seems to work - I have declared a table for the sourcecode (one complete line per record) and split up the variable into that table, it looks all right. Then I have executed that INSERT REPORT, specifying PROGRAM TYPE 'I' for an INCLUDE. Can I somehow open that INCLUDE and look at its code?

Read only

0 Likes
3,047

Hi Thomas,

yippidieh! That seems to have worked - I didn't look at it yesterday, I only saw that it executed without error - I was still unsure whether our old system supports that command. It seems it does, somehow I have just opened that INCLUDE I have created - well, the syntax-check opened it because the syntax is not complete. I create that itab by using SPLIT with the ',' as a separator - and all the ','s are missing from the code. Never mind, I'll fix that.

I know how the code must look like when it's error-free, so I don't have to see it. Only, how can I then execute it right away? I tried yesterday the usual command > INCLUDE ZFH_tab <, but then ABAP asked me if I wanted to create that, so that can't be right?

In this instance, I don't want an INCLUDE in the directory long-term, I only want to execute it right away and that's that.

Thanks so much! I spent all yesterday searching, but your hint was just the right one.

Best regards,

Sapperdapper

Read only

0 Likes
3,047

Thanks for your feedback. For temporary, executable code also look at the GENERATE SUBROUTINE POOL statement.

Please keep in mind that such dynamic code generation is complex, can be difficult to trouble-shoot, and also represents a security issue. With malicious motives you could inject all sorts of code.

IT revision and auditors love to scan for such stuff...

Thomas

Read only

0 Likes
3,047

Hi Thomas,

right now, I don't care: This is only for having something to show short-term. It is not what (I begin to see more clearly now) I will have to do long-term - though I will probably need that INSERT REPORT or other statements, so learning about that is not a waste of time and I'm grateful for any guidance in that process for there is not much room for errors here.

Like I said, with PROGRAM TYPE 'I' for an INCLUDE it doesn't seem to work whereas when I create an executable program (no PROGRAM TYPE stated) it works and that report declares my table, but then the calling report doesn't know about it.

Thus I think GENERATE SUBROUTINE POOL is more likely what I need. I have also found another thread with a link to some help.sap sites, I will have a look. Nevertheless knowing about that INSERT REPORT is a good thing, I might be able to use that later.

Needless to say, if that PROGRAM TYPE 'I' was feasible somehow, that would be easier, the code in the INCLUDE would create the table like a global variable and I could use it further on. Still, I will see where that GENERATE SUBROUTINE POOL takes me.

Best regards,

Sapperdapper

P.S.: What I don't see on those sites - what does the code in that table have to look like when I use that GENERATE SUBROUTINE POOL? Would that have to be in the form you commonly use for subroutines (FORM ... ENDFORM)?

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Hi Friedrich,

As Thomas Said such Dynamic code generations are complex.

We used to write this kind of code earlier in olden days around 2001-05

now we use the method Create_dynamic_tables from the ALV for create a Table Dynamically with a Field Cat as you said earlier in this post.

But for a example you can check the below mentioned code which will give you an Idea on the use of GENERATE SUBROUTINE POOL.

Example Program

    REFRESH pgmtab.
* Report name.
  GET TIME.
  CONCATENATE 'ZOPT' sy-uname sy-datum sy-uzeit INTO report_name.
  CONCATENATE 'REPORT' report_name '.' INTO pline SEPARATED BY space.
  APPEND pline TO pgmtab.

* Start of form.
  pline = 'FORM BUILD_RANGES_TYPES TABLES'.---------------------------------------->
  APPEND pline TO pgmtab.
  pline = 'T_DDICTAB STRUCTURE ZREPAIR_DDICTAB_STRUCTURE'.
  APPEND pline TO pgmtab.
  pline = 'T_SELOPTS STRUCTURE RSPARAMS'.
  APPEND pline TO pgmtab.
  pline = 'T_STAB STRUCTURE ZREPAIR_STAB_STRUCTURE.'.
  APPEND pline TO pgmtab.

* Data declarations.
  pline = 'DATA: WA_DDICTAB TYPE ZREPAIR_DDICTAB_STRUCTURE.'.
  APPEND pline TO pgmtab.
  pline = 'DATA: WA_SELOPTS TYPE RSPARAMS.'.
  APPEND pline TO pgmtab.
  pline = 'DATA: WA_STAB TYPE CHAR100.'.
  APPEND pline TO pgmtab.

  pline = 'REFRESH T_STAB.'.
  APPEND pline TO pgmtab.
  pline = 'SORT T_DDICTAB BY SEL_OPTION.'.
  APPEND pline TO pgmtab.

* Build data statements and append to T_STAB.
  pline = 'LOOP AT T_SELOPTS INTO WA_SELOPTS.'.
  APPEND pline TO pgmtab.
  pline = 'READ TABLE T_DDICTAB INTO WA_DDICTAB'.
  APPEND pline TO pgmtab.
  pline = 'WITH KEY SEL_OPTION = WA_SELOPTS-SELNAME'.
  APPEND pline TO pgmtab.
  pline = 'BINARY SEARCH.'.
  APPEND pline TO pgmtab.

  pline = ''' TYPEXRANGEXOF '''. CONDENSE pline NO-GAPS.
  pline+5(1) = space.
  pline+11(1) = space.
  CONCATENATE 'CONCATENATE WA_SELOPTS-SELNAME' pline
              'WA_DDICTAB-ROLLNAME'
               INTO pline SEPARATED BY space.
  APPEND pline TO pgmtab.
  pline = 'INTO WA_STAB SEPARATED BY SPACE.'.
  APPEND pline TO pgmtab.
  pline = 'APPEND WA_STAB TO T_STAB.'.
  APPEND pline TO pgmtab.

  pline = 'ENDLOOP.'.
  APPEND pline TO pgmtab.

  pline = 'SORT T_STAB.'.
  APPEND pline TO pgmtab.
  pline = 'DELETE ADJACENT DUPLICATES FROM T_STAB COMPARING CHAR100.'.
  APPEND pline TO pgmtab.

* Endform statement.
  pline = 'ENDFORM.'. APPEND pline TO pgmtab.

* Generate code.
  GENERATE SUBROUTINE POOL pgmtab
                      NAME gen_subroutine
                      LINE gen_line
                      MESSAGE gen_msg.
* Execute new subroutine.
  PERFORM build_ranges_types IN PROGRAM (gen_subroutine)
                      TABLES ddictab
                             selopts
                             stab.

This Subroutine name which is BOLD can be seen at the Top where I mentioned .------------------------->

So this is how the GENERATE SUBROUTINE POOL Works.

But this is complex coding. Better go for a dynamic_table option

Hope this helps

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Tbh i was wondering if GENERATE SUBROUTINE POOL would be more apt than INSERT REPORT

BR,

Suhas

Read only

0 Likes
3,047

Hi Venkat,

yes, it helps. It remains - well, complex, as you say.

I used to have that method - I actually thought this would be easier in the long run because using that method I ended up with a table - the table was just as it should be and I could fit in the data without trouble - but I tried to then do certain things (calculations, running totals here, which requires sorting) on the table and I couldn't, the syntax-check said the table had no structure and thus no element of the name I specified for the sorting.

When you say that nowadays, this is not so common anymore, maybe it is too complex to implement this week - which doesn't say I won't be using it in the long run - but if there was a way to turn that dynamically created table into some sort of table that I could work on, maybe that would be a better idea.

Would it be okay if I post or attach that specific INCLUDE where build up i_fcat and declare this table and ask you to tell me what I'd have to do to enable things like SORT and READ on that?

Best regards,

Sapperdapper

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Hi Friedrich

Instead of posting all the code. you can put your include code here so that every one in this forum will get a better chance of understanding the requirement and giving a better quality solution.

Please post the code.

thanks.

Read only

0 Likes
3,047

Hi Venkat,

I don't quite understand what you mean by "put your include code here", since in your last sentence you again tell me to post it, but thanks a lot anyway!

I will post it, before I will just clean it up a bit - there's a lot of rubbish there now as I've spent a lot of time trying out different methods - and leave only the code that was there, with that method to create a dynamic table.

Best regards,

Sapperdapper

P.S.: Here it comes:

*&---------------------------------------------------------------------*

*&  Include           ZFH_INTTAB_DX_WORK_DECL_TAB                      *

*&---------------------------------------------------------------------*

* We declare DD03L_int once already, in the pre-GUI program. Now we can make it still smaller,

* holding only the info for all the tables the user has actually selected in the GUI.

* There might still be potential

TYPES: BEGIN OF DD03L_int_line,

       TABNAME TYPE C LENGTH 30,

       FIELDNAME TYPE C LENGTH 30,

       INTTYPE TYPE STRING,

       INTLEN TYPE STRING,

       DECIMALS TYPE STRING,

       END OF DD03L_int_line.

TYPES DD03L_int_type TYPE STANDARD TABLE OF DD03L_int_line.

DATA DD03L_int TYPE DD03L_int_type.

DATA wa_DD03L_int TYPE DD03L_int_line.

SELECT

     DD03L~TABNAME

     DD03L~FIELDNAME

     DD03L~INTTYPE

     DD03L~INTLEN

     DD03L~DECIMALS

FROM DD03L

INTO TABLE DD03L_int

FOR ALL ENTRIES IN Tables_tab3

WHERE TABNAME = Tables_tab3-TABNAME

AND   DD03L~FIELDNAME NOT LIKE '.%'.

DATA TAB_REF TYPE REF TO DATA.

* Field-symbols are just placeholders; They reserve physical memory+

* space for something still to come.

FIELD-SYMBOLS <F_TABLE> TYPE ANY TABLE.    "STANDARD TABLE.

FIELD-SYMBOLS <F_LINE> TYPE ANY.

* Before using the internal table i_fcat in the method called,

* it has to be declared.

*********** Declaration of the internal table i_fcat *******************

DATA i_fcat TYPE LVC_T_FCAT.

DATA wa_fcat TYPE LVC_S_FCAT.

************ Population of internal table i_fcat *******************

* This has to be done in a WHILE-clause lateron so that we can have

* as many rows here as the user has selected fields.

* The variable v_tabctr exists already, we just have to reset it.

v_tabctr = 1.

v_fieldctr = 1.

DATA Flds_new TYPE i.

* DATA v_currTab TYPE STRING. "Exists already

DATA Flds_currTab TYPE STRING.

*DATA v_currFld TYPE STRING. "Exists already

* Several necessary field-symbols (as placeholders):

* a) One for the table name

FIELD-SYMBOLS <Tb>.

* b) One for the fiel dname

FIELD-SYMBOLS <Fd>.

* c) One for the number of fields in a table

FIELD-SYMBOLS <Ft>.

* d) One for the INTTYPE.

FIELD-SYMBOLS <DT>.

* e) One for the INTLEN.

FIELD-SYMBOLS <LEN>.

* f) One for DECIMALS_O.

FIELD-SYMBOLS <DEC>.

* g) One for the fieldlist, first version

FIELD-SYMBOLS <Tf1>.

* h) One for the fieldlist, second version

FIELD-SYMBOLS <Tf2>.

* We need variables to hold the concatenation of a table and a field

* (two versions of it, one with the `-` and one with the `~`

DATA Tabfld1 TYPE STRING.

DATA Tabfld2 TYPE STRING.

* We also need a STRING variable to hold any info

* we need from table DD03L.

DATA v_Inttype TYPE STRING.

DATA v_Intlen TYPE STRING.

DATA v_Dec TYPE STRING.

DATA FIELDNAME TYPE C LENGTH 30.

DATA TABLE_NAME TYPE C LENGTH 30.

* Here comes a construct of two nested WHILE loops, the purpose of which

* is to dynamically fill the int. table i_fcat for the method

* create_dynamic_table belonging to ABAP class cl_alv_table_create.

* The three basic infos we need to be able to run this loop are

* a) how many tables are there? - Tablenames

* b) how many fields (in total) are there? - Fieldnames

* c) how many fields are there in each table (can be different)?

************************ BEGIN OF LOOP *******************************

* The outer WHILE-loop will run as many times as there are tables.

WHILE v_tabctr <= NrTabs.

* We now have an internal table with the names of the tables we need to

* join to query all the data we want, so we just have to read that.

READ TABLE Tables_tab3 INTO wa_Tables3 INDEX v_tabctr.

v_currTab = wa_Tables3-TABNAME.

* We assign the value of v_currTab (the actual table-name) to the

* field-symbol (thus the brackets, otherwise we would end up with

* 'Tab1' instead of 'KNC1'.

  ASSIGN v_currTab TO <Tb>.

* Same story as above: We change the datatype of v_tabctr from i to

* STRING.

  READ TABLE Nr_flds2 INTO wa_flds2 INDEX v_tabctr.

* We assign the actual value (a number) to a field-symbol...

  Flds_currTab = wa_flds2-Nr.

  ASSIGN Flds_currTab TO <Ft>.

* so that we can use it in this calculation which is necessary

* since the fields are all numbered continuously.

  Flds_new = v_fieldctr + <ft> - 1.

* The inner loop will run as many times as there are fields to the

* current table.

  WHILE v_fieldctr <= flds_new.

* Same story as above: Datatype i cannot be used in a CONCATENATE,

* so we fill the value into an existing variable of type STRING.

*    MOVE v_fieldctr to v_currFld.

*    CONCATENATE 'F' v_currFld INTO v_currFld.

  READ TABLE SPLIT_tab2 INTO wa_SPLIT2 index v_fieldctr.

    v_currFld = wa_SPLIT2-FIELDNAME.

* We assign the actual field_name (thus the brackets) to a field-symbol.

    ASSIGN v_currFld TO <Fd>.

*   Now we have one field-symbol each for the table and the field.

*   We now need some more for INTLEN, INTTYPE and DECIMALS to make

*   sure the target field in the internal table has the correct

*   attributes for the actual SELECT fetching the data from the DB.

*   Instead of doing three SELECTs from the rather large-ish table

*   DD03L, we deal only with a much smaller internal table here.

  LOOP AT DD03L_int INTO wa_DD03L_int

       WHERE FIELDNAME = <Fd>

       AND   TABNAME = <Tb>.

  v_Inttype = wa_DD03L_int-INTTYPE.

  v_Intlen  = wa_DD03L_int-INTLEN.

  v_Dec     = wa_DD03L_int-DECIMALS.

  ENDLOOP.

* We must assign the Inttype we have now determined to another

* field-symbol.

ASSIGN v_Inttype TO <DT>.

ASSIGN v_Intlen TO <LEN>.

ASSIGN v_Dec TO <DEC>.

* This CONCATENATE is necessary since the method we will apply further

* on cannot work with duplicate field_names.

*     CONCATENATE <Tb> <Fd> INTO Tabfld2 SEPARATED BY '-'.

** We assign that concatenation to a field-symbol.

*     ASSIGN Tabfld2 TO <Fd>.

** Now we can go about filling i_fcat (for that method) via a Workarea.

     wa_fcat-FIELDNAME = <Fd>.

     wa_fcat-TABNAME   = <Tb>.

     wa_fcat-INTTYPE   = <DT>.

     wa_fcat-INTLEN    = <LEN>.

     wa_fcat-DECIMALS  = <DEC>.

     APPEND wa_fcat TO i_fcat.

     CLEAR wa_fcat.

     v_fieldctr = v_fieldctr + 1.

   ENDWHILE.

*

   v_tabctr = v_tabctr + 1.

ENDWHILE.

**************************  END OF LOOP  ************************

** Using the method create_dynamic_table (method of class

** cl_alv_table_create) it is possible to create a dynamic

** internal table based on a field_catalog i_fcat.

*

*

*BREAK-POINT.

*

*CALL METHOD cl_alv_table_create=>create_dynamic_table

*     EXPORTING

*       it_fieldcatalog = i_fcat

*     IMPORTING

*       ep_table = TAB_REF.

* Lastly, the table generated by this method is assigned to

* the FIELD-SYMBOL we have declared as a placeholder before.

ASSIGN TAB_REF->* to <F_TABLE>.

************************************************************************************

You see, now I have the field-symbol <F_TABLE> with a dynamically built table "inside". I can access that table by naming the field-symbol and I can fill it by way of a SELECT statement. What I cannot do is e.g. sort it since I cannot specify its individual components.

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Hi Friedrich,

What I mean to say this..

Lets say I have a Program with 3 includes like

INCLUDE YV_TOP

INCLUDE YV_SELECTION.

INCLUDE YV_ALV.----> Lets say in this include I am writing the dynamic code stuff and all.

I said instead of posting all the Include codes..

Just post the Code whatever that is in the INCLUDE YV_ALV.

Hope this helps Sorry If I confuse you .

Thnx

Read only

0 Likes
3,047

Hi,

you're quite welcome - I'm the one asking for help.

However, that's just what I've done: All the code I've posted is from just one INCLUDE and that's just the one where I use that method. The LOOP construct in the middle is where I fill up i_fcat with the data I have, so that's not so critical here, it works. All the declarations necessary for that method are in that code.

Best regards,

Sapperdapper

P.S.: I could, however, put it all into an easier order - currently, some of the necessary declarations are before the LOOP and some after it.

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Hi Friedrich

I was just reviewing the code which is too complex now.

Better I would just paste my code what i can do in your case if you can tell me what exactly the requirement is for building a Dynamic table.

Lets say i have something like this.

I have a note pad file where I can have data entries.

These data entries are from different tables.

Note: You should atleast know what fields you will have. or what table/structure you will have.

then in this case i have a code dynamically that will work to build a ITAB.

Please tell me your requirement so that I can help writing the code dynamically the way you want.

thnx

Read only

0 Likes
3,047

Hi Venkat,

here is my requirement:

- The user (not me) selects a set of fields from n DB_tables (a sensible scenario, so all the tables are
  related somehow)

=> I do not know how many fields, I do not know which field_names and thus I do not know the necessary datatype and length.

- At the core of my program is a SELECT statement working on a fieldlist (all the fields selected, prepared in OpenSQL-syntax ([table]~[field]) in an INCLUDE), dynamically joining the tables using a join_statement I have prepared beforehand in another INCLUDE and using a filter I have beforehand prepared in yet another INCLUDE.

=> From that results my requirement for this table: The table must have exactly those fields selected by the user, with the correct datatype and length - all of which I can get from table DD03L as I have at that point only fields from transparent tables. Only if the table meets those requirements, the SELECT statement will work, populating the table with the required fields.

- All of this info (field_name, length, datatype, decimals) I get in that LOOP construct and use to populate i_fcat.

P.S.: At that point of the program execution, you see, I have all the information of how many and which fields I need to be in that table.

P.P.S.: I hope it is clear enough what my requirement is, but just in case I say it once more: The function DOES generate that table all right - only in a form which I cannot use. I need to perform some standard operations on the table which I cannot currently do, I guess it's because of the type REF TO DATA or so - the table has no static structure and without that it seems some things cannot be done.

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Hi Friedrich

Here is the code which I can give you developed in just 10mins

This is a hint got break thru.. check the FM used.

TABLES : dd03l.
SELECT-OPTIONS : s_tab FOR dd03l-tabname,
                 s_fields FOR dd03l-fieldname.
DATA : gv_line TYPE i,
       gv_string type string,
       gw_dfies TYPE dfies,
       gt_dfies_tmp TYPE STANDARD TABLE OF dfies,
       gt_dfies TYPE STANDARD TABLE OF dfies.
gv_line = LINES( s_tab ).
IF NOT gv_line > 1.
  READ TABLE s_tab INDEX 1.
  IF sy-subrc = 0.
    CALL FUNCTION 'CYPP08_GET_DFIES_TAB'
      EXPORTING
        tabname   = s_tab-low
        langu     = sy-langu
      TABLES
        dfies_exp = gt_dfies_tmp.
    LOOP AT gt_dfies_tmp INTO gw_dfies WHERE fieldname NOT IN s_fields.
      DELETE Table gt_dfies_tmp FROM gw_dfies.
    ENDLOOP.
    APPEND LINES OF gt_dfies_tmp TO gt_dfies.
    REFRESH gt_dfies_tmp.
  ENDIF.
ELSE.
  LOOP AT s_tab.
    CALL FUNCTION 'CYPP08_GET_DFIES_TAB'
      EXPORTING
        tabname   = s_tab-low
        langu     = sy-langu
      TABLES
        dfies_exp = gt_dfies_tmp.
    APPEND LINES OF gt_dfies_tmp TO gt_dfies.
  ENDLOOP.
  LOOP AT gt_dfies_tmp INTO gw_dfies WHERE fieldname NOT IN s_fields.

  ENDLOOP.
ENDIF.
Loop At GT_DFIES Into GW_DFIES.
* this Class method is for just showing the data with a write stmt with string
* instead of writing all the fields in the write statement. for time being i wrote it
* you can use ALV or some to display
  CALL METHOD cl_abap_container_utilities=>fill_container_c
    EXPORTING
      im_value               = GW_DFIES
    IMPORTING
      EX_CONTAINER           = GV_STRING
    EXCEPTIONS
      ILLEGAL_PARAMETER_TYPE = 1
      others                 = 2.
  IF sy-subrc <> 0.
   MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  Write 😕 GV_STRING.
Endloop.

Hope this helps

Read only

0 Likes
3,047

Wow!

I will try to work through and understand what you're doing in this code. That FM you use there has a funny name - how on earth is anyone supposed to find something like that? Well, you found it, so it must be possible. Awesome. Many thanks!

Talk to you!

Best regards,

Sapperdapper

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,047

Yeah That is true Friedrich,

Long back ago I used some function module with DFIES so I searched with that and found it which will give the table field attributes like data lenght and its type and all etc....

Hope this helps for your requirement. Good Day!

Read only

0 Likes
3,047

Thanks!

I just pasted that code into a new report and now I'm testing it. If I can get it to work, I can build it into my existing code and pass all the table_names and field_names I have, where you have the SELECT-OPTIONS.

Best regards,

Sapperdapper

Read only

0 Likes
3,047

Hi Venkat,

something is strange. maybe our system does not support all you have used in that code?

I'm getting a curious dump

(at a line > LOOP AT gt_dfies_tmp INTO gw_dfies WHERE fieldname NOT IN s_fields. <)

saying "<%_L002> is not an internal table. Statement OCCURS n is missing".

There is no table called that; Something strange is happening there.

Best regards,

Sapperdapper

P.S.: I think I know an alternative, good enough for now since I'm going to do things differently in the long run anyway, I will try to keep to things I know, to keep it as simple as possible: That INSERT REPORT worked when I made it an executable report. It then creates the table I need, only that table is then known only to that report, not the calling one - so instead of returning to the calling one, I have to put all the remainder of my program into that temporary report and finish that. As all the code in the remainder of the program is organized in INCLUDEs, that is not too much, I only have to append the commands to call those INCLUDEs to the table from which I create that report. I will have to export and import some data to do that since all the INCLUDEs after that one rely on data I have calculated before, but it is a possibility.

Read only

0 Likes
3,047

Hi Venkat,

it is working. I'm now using that INSERT REPORT. I'm still grateful for your help, I'm just trying to keep things as simple as possible and to keep, as much as possible, to the things I know. I have now ex- and imported all necessary data - I'm calling this dynamic report as late as possible to minimize the number of things I need to transport - and it's executing fine, creating a regular table and filling in the data. I can now do all I want with that table, I only have to put it into an INCLUDE or a FORM and append the command to call that to the table from which I generate the new code.

I will definitely be able to put this method to use in the long run. That will be far more complex:

Since an existing ABAP program can be so complex that I stand near to no chance of getting all the data out of it, I have to dynamically execute it and modify it a bit, so I'll have to READ it into a table and then generate a program from that table again.

Thanks for the help!

Best regards,

Sapperdapper

Read only

Former Member
0 Likes
3,047

Hi,

Sample Code.

______________you can create code dynamically___________

DATA: code TYPE TABLE OF rssource-line.

APPEND  'REPORT ZDYN1.'  TO code.

APPEND  'WRITE / ''Hello, I am dynamically created!''.'   TO code.

INSERT REPORT 'demo_special_tech_ZDYN1' FROM code.

WRITE: text-001, 'demo_special_tech_ZDYN1'.

___________even you can change code dynamically___________

DATA: code TYPE TABLE OF rssource-line.

READ REPORT 'demo_special_tech_ZSTRUC1' INTO code.

APPEND 'SKIP.' TO code.

APPEND 'WRITE / ''And I am a dynamic extension!''.' TO code.

INSERT REPORT 'demo_special_tech_ZDYN2' FROM code.

WRITE: text-001, 'demo_special_tech_ZDYN2'.

_____________________________________________

then you can run program by

submit statement.

Avirat