Skip to Content

Dynamic Declaration

Hi

I was looking into a poosibility of making a dynamic declaration refercing a formal parameter. is it possible. below is my code:

FORM WRITE_DATA  USING P_TYPE   P_SNAME.

  CREATE DATA p_type TYPE (P_SNAME).
.....
ENDFORM

Can you pls let me know on how to acheive it

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 02:08 PM

    Hi Prabhu,

    that works in my program.

    DATA: transtru TYPE dd03l-tabname.

    CREATE DATA fs_it_data_ref

    TYPE STANDARD TABLE OF (transtru)

    WITH DEFAULT KEY.

    So yes, it's possible.

    Kind Regards

    Henner

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 20, 2007 at 02:48 PM

    sorry.. i sound absurd in previous replies...

    can i ask you why so you want variable 'variable name' ? Hope my question is inline with your req.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      Please check this code, may this one will help you.

      report  z0002.
      
      parameters : p_field(40) type c default 'MARA_MATNR'.
      
      * The dynamic program source table
      data: begin of inctabl occurs 10,
      line(72),
      end of inctabl.
      
      data: lng type i, typesrting(6).
      
      * Create the dynamic internal table definition in the dyn. program
      inctabl-line = 'program zdynpro.'. append inctabl.
      concatenate 'data: p_type like ' p_field '.'into inctabl-line
                  separated by space.
      
      append inctabl.
      concatenate 'P_TYPE = 123.' SPACE into inctabl-line
                  separated by space.
      
      append inctabl.
      
      concatenate 'write : / P_TYPE.' SPACE into inctabl-line
                  separated by space.
      
      append inctabl.
      
      insert report 'zdynpro'(001) from inctabl.
      submit zdynpro and return.
      
      
      break-point.
      
      .
      

      aRs

  • Posted on Aug 20, 2007 at 01:52 PM

    Hi,

    Check for possibility to use GENERATE SUBROUTINE in your case

    aRs

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 20, 2007 at 02:18 PM
    CREATE DATA dref LIKE f.
    Add comment
    10|10000 characters needed characters exceeded

    • hi pawan

      my requirement is as below:

      FORM WRITE_DATA USING P_TYPE P_SNAME.

      CREATE DATA p_type TYPE (P_SNAME).

      ...

      ENDFORM

      PS: P_TYPE is a formal parameter which can take some input value like street. and i need to create a variable called street dyncamically. is it possible?

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 03:06 PM

    Hi Prabhu,

    if i understood you correctly, it's not possible what you like to do, because

    create data just gives you a pointer like for the above example, then you can assign the pointer to

    a field symbol that takes over the type of s_name then.

    I'm not sure, but i think what you need is the class

    CL_APAP_TYPEDESCR and it's subclasses like

    CL_ABAP_TYPEDESCR

    --CL_ABAP_DATADESCR

    --CL_ABAP_ELEMDESCR

    --CL_ABAP_REFDESCR

    --CL_ABAP_COMPLEXDESCR

    --CL_ABAP_STRUCTDESCR

    --CL_ABAP_TABLEDESCR

    --CL_ABAP_OBJECTDESCR

    |--CL_ABAP_CLASSDESCR

    |--CL_ABAP_INTFDESCR

    I think it's able to make dynamic declarations like you need then, but i never

    needed it and never used it.

    Kind Regards

    Henner

    Add comment
    10|10000 characters needed characters exceeded