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

Data elements used in Z Program

Former Member
0 Likes
2,258

Hi All,

I have to create a Z Program which has the Program name as input (Selection Screen) and i need to display the data elements (and details ex: data type , length) used in the program .

Can anyone help me out ..

Thanks,

Pradeep.

13 REPLIES 13
Read only

andreas_mann3
Active Contributor
0 Likes
1,846

read F1 to SCAN ABAP-SOURCE

grx. A.

Read only

marcin_cholewczuk
Active Contributor
0 Likes
1,846

Hi,

Maybe 'SCAN ABAP-SOURCE' would be of any use. However it's meant only for internal use. You could also check function group SEDA.

BR

Marcin Cholewczuk

Read only

Former Member
0 Likes
1,846

One way would be to read the source code of the program into an internal table. Then loop over the table and find your DATA statements. Try finding them by Regex or string operations...

parameters: pa_prog type c length 30.
 
data: begin of source_code,
      line(300) type c,
      end of source_code.
 
read report pa_prog into source_code.         
loop at source_code.
  "Search for data elements ..
endloop.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,846

Enjoy

Had a very tough time debugging the standard functionality


DATA:environment_types TYPE envi_types,
     output_list TYPE TABLE OF senvi,
     source_searched TYPE TABLE OF rsfind,
     lv_dtel TYPE ddobjname,
     dd04v TYPE dd04v,
     para TYPE tpara,
     state TYPE ddgotstate,
     wa_output TYPE senvi.

PARAMETERS:pa_prog TYPE tadir-obj_name.

START-OF-SELECTION.

  environment_types-dtel = 'X'.

  CALL FUNCTION 'REPOSITORY_ENVIRONMENT_SET_RFC'
       EXPORTING
            obj_type          = 'PROG'
            environment_types = environment_types
            object_name       = pa_prog
       TABLES
            environment       = output_list
            source_objects    = source_searched.

  LOOP AT output_list INTO wa_output.
    lv_dtel = wa_output-object.
    CALL FUNCTION 'DDIF_DTEL_GET'
         EXPORTING
              name     = lv_dtel
              state    = 'A'
              langu    = sy-langu
         IMPORTING
              gotstate = state
              dd04v_wa = dd04v
              tpara_wa = para.
  ENDLOOP.

The table dd04v will have the type and length and the table output_list holds the data element in the program.

Read only

0 Likes
1,846

Hi

Thanks for your reply... I tried that code and the output is not displaying all the variables . Its randomly displaying the few.

I need what are all the variables i declared in a Program should be displayed in the output.

Thanks,

Pradeep.

Read only

0 Likes
1,846

In your first post, you mentioned "data elements", which is a specific DDIC development object, thus Keshav's reply. Now you actually seem to mean data declarations in general.

Please clarify what you really want, so people can save some time.

Thomas

Read only

0 Likes
1,846

Your actual question was "Data elements" and now you ask for "Variables". Please be sure before asking the question. Its meaningless answering a wrong quesiton.

Read only

0 Likes
1,846

Dear Thomos,

Sorry for confusing .

For Ex :

data : gv_conv_gamng TYPE char15,

gv_scrap_qty TYPE zsrem_conf-gsmng,

gv_matnr TYPE matnr,

gv_matkl TYPE matkl,

lv_matnr TYPE matnr,

gv_plaf_pwwrk TYPE pwwrk,

gv_maktx TYPE maktx.

These are the local variables i used in a Z Progam. I need the data elemnt detials of these.

Ex : For gv_matkl :

data element is maktl

data type is CHAR

lenth is 9.

Thanks,

Pradeep.

Read only

0 Likes
1,846

OK, and what output would you expect for let's say

gf_saknr like ska1-saknr,
gf_date type d,
gf_char type c length 10,
gf_long type string,
gr_alv type ref to cl_salv_table,
gt_list type ty_output_tt,
...

Thomas

Read only

0 Likes
1,846

Hi,

gf_saknr like ska1-saknr,

gf_date type d,

gf_char type c length 10,

gf_long type string,

gr_alv type ref to cl_salv_table,

gt_list type ty_output_tt,

The Expected Output is :

1. The data type of gf_saknr

2. Length of gf_saknr.

Read only

0 Likes
1,846

Dear Moderator,

Please Kindly help me out in solving this Issue..

I have already given an example of my requirement.

Thanks,

Pradeep.

Read only

0 Likes
1,846

Hi,

Then you'll have to deal with READ REPORT and SCAN ABAP-SOURCE... and probably use the keyword 'DATA' with the SCAN statement. Never used this, but it seems you could use the table of tokens or statements returned.


  READ REPORT 'ZREPORT" INTO abap_source.

  MOVE lc_data    TO l_keyword. APPEND l_keyword.   "= 'DATA'
  MOVE lc_include TO l_keyword. APPEND l_keyword.
  
  SCAN ABAP-SOURCE abap_source
       TOKENS     INTO l_token_analysis
       STATEMENTS INTO l_statements
       KEYWORDS   FROM l_keyword
       WITH ANALYSIS
       WITH INCLUDES
       WITHOUT TRMAC.

Kr,

Manu.

Read only

former_member76372
Participant
0 Likes
1,846

As much as we like to spoonfeed you with this basic solution, but it is already in ABAP Help F1 (Processing Internal Data). nevertheless, try optimizing your search options you might be able to get a solution for this in some existing forums.