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 Declaration

prabhu_s2
Active Contributor
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

14 REPLIES 14

former_member194669
Active Contributor
0 Kudos

Hi,

Check for possibility to use GENERATE SUBROUTINE in your case

aRs

0 Kudos

how does it helps?

Former Member
0 Kudos

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

0 Kudos

hi henner

thks for ur reply. here the variable in my requirement <b>fs_it_data_ref</b> is a formal parameter in a form routine and the value present in the formal parameter should be referenced for dynamic declaration.

0 Kudos

Hi Prabhu,

additionally you have to call your form like this:

data: p_name type ref to data.

data: s_name type fieldname value 'LFDNR'.

perform abc using p_name s_name.

FORM abc USING p_name type ref to data

s_name type fieldname.

create data p_name type (s_name).

ENDFORM. " abc

0 Kudos

yeah. i had tried this too. but how to populate the variable p_name with values ,say item1, so that in the form routine a dynamic variable called item1 is created? i'm unable to acheive this.

Pawan_Kesari
Active Contributor
0 Kudos
CREATE DATA dref LIKE f.

0 Kudos

this should work


REPORT zpwtest .

START-OF-SELECTION .

  DATA :  v_i TYPE i ,
          v_c TYPE c .

  PERFORM check_data USING v_i v_c .

*---------------------------------------------------------------------*
*       FORM check_data                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  P_V_I                                                         *
*  -->  P_V_C                                                         *
*---------------------------------------------------------------------*
FORM check_data USING    p_v_i
                         p_v_c.

  DATA: p_i TYPE REF TO data .
  CREATE DATA p_i LIKE p_v_i .

ENDFORM.                    " check_data

0 Kudos

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?

Pawan_Kesari
Active Contributor
0 Kudos

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.

0 Kudos

its a kinda requirement which i thought of using. i have a meterial doc number to which P_ is prefixed and i need to create a variable say P_4500234 for each material doc number and process. i do have other woraround but thought if this would be feasible to implement in abap?

0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

thkx henner. maybe i need to check in those classes