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

Get Selection text

Former Member
0 Likes
4,999

Hi,

I need to read the text present in selection text of a report (which is displayed with the parameters and select-options present on the selection screen). I used the READ TEXTPOOL statement for the same. It returns the text that has been explicitly specified but does not return the text which has been selected to be picked up from the DDIC.

Is there any way to pick that up?

Anything using RTTI?

Thanks.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
3,337

Anything using RTTI?

Yup. Like the one below:


DATA: pernr TYPE persno.
PARAMETERS pa_bukrs TYPE pa0001-bukrs.
SELECT-OPTIONS so_pernr FOR pernr.

PERFORM get_rolltext USING pa_bukrs.
PERFORM get_rolltext USING so_pernr-low.

FORM get_rolltext USING item.
  DATA: it_ddic TYPE dd_x031l_table WITH HEADER LINE.
  DATA: r_datadescr TYPE REF TO cl_abap_datadescr.
  DATA ls_roll_info TYPE rpy_dtel.

  r_datadescr ?= cl_abap_typedescr=>describe_by_data( item ).
  it_ddic[] = r_datadescr->get_ddic_object( ).
  READ TABLE it_ddic INDEX 1.

  CALL FUNCTION 'RPY_DATAELEMENT_READ'
    EXPORTING
      dataelement_name = it_ddic-fieldname
    IMPORTING
      dtel_inf         = ls_roll_info
    EXCEPTIONS
      cancelled        = 1
      not_found        = 2
      permission_error = 3
      illegal_type     = 4
      OTHERS           = 5.

  CHECK sy-subrc = 0.
  WRITE: / 'Medium text for this component is', ls_roll_info-SCRTEXT_M.
ENDFORM.

Regards

Marcin

9 REPLIES 9
Read only

Former Member
0 Likes
3,337

Hi,

I am not sure whether this helps you or not.

Dictionary Texts can be get from table DDFTX.

Regards,

Raghava Channooru.

Read only

MarcinPciak
Active Contributor
3,338

Anything using RTTI?

Yup. Like the one below:


DATA: pernr TYPE persno.
PARAMETERS pa_bukrs TYPE pa0001-bukrs.
SELECT-OPTIONS so_pernr FOR pernr.

PERFORM get_rolltext USING pa_bukrs.
PERFORM get_rolltext USING so_pernr-low.

FORM get_rolltext USING item.
  DATA: it_ddic TYPE dd_x031l_table WITH HEADER LINE.
  DATA: r_datadescr TYPE REF TO cl_abap_datadescr.
  DATA ls_roll_info TYPE rpy_dtel.

  r_datadescr ?= cl_abap_typedescr=>describe_by_data( item ).
  it_ddic[] = r_datadescr->get_ddic_object( ).
  READ TABLE it_ddic INDEX 1.

  CALL FUNCTION 'RPY_DATAELEMENT_READ'
    EXPORTING
      dataelement_name = it_ddic-fieldname
    IMPORTING
      dtel_inf         = ls_roll_info
    EXCEPTIONS
      cancelled        = 1
      not_found        = 2
      permission_error = 3
      illegal_type     = 4
      OTHERS           = 5.

  CHECK sy-subrc = 0.
  WRITE: / 'Medium text for this component is', ls_roll_info-SCRTEXT_M.
ENDFORM.

Regards

Marcin

Read only

0 Likes
3,337

Hi Marcin,

Thanks a lot for the help. I think it will do the job.

Just an addition to this (to enhance the reusablity), what if i want to implement this in a function module. i.e. I want to call a function module from my program which will do this for me. In such a case, the function module must also have the run-time attributes of the select-options. How can this be achieved?

Thanks.

Swapnil.

Read only

0 Likes
3,337

I think you don't need to have select-options parameter in function module. Just look closer to code above


PERFORM get_rolltext USING pa_bukrs.
PERFORM get_rolltext USING so_pernr-low.

Here I am passing only one value (paramater or the low value of select options). So this works for single data object. Later this one is evaluated in subroutine. So if you want to use that in FM, then just type the parameter as ANY (or leave the typing empty). This way you can pass any sel.screen parameter you want or even any other data object from the program.

It will be checked if it is a valid data object. If so then you should get the corresponding text in the DDIC for it. Note, however that this data object or sel.screen parameter (or value of select options) must be typed with DDIC reference (i.e. type field of table or type of data element). So you should not pass fields which have custom typings defined in the program.

Also there have to be some additional checks in the FM itself added. I just assumed we are passing correct type to this subroutine. So basically you should consider of handling errors in case someone passes not a data object but some other entity.

Regards

Marcin

Read only

0 Likes
3,337

Hi Marcin,

My objective of having a FM is to make it reusable such that the developer will not have to worry about the different select-options that are present in different programs. The developer should just call a single FM which will fetch the texts for all the select options in the selection screen for the program. I tried using the FM 'RS_REFRESH_FROM_SELECTOPTIONS' which gets the select options along with the value that they have, but if i pass selection_table-selname to the perform, it is interpreted as a string and not as a select-option. So, how do I pass all the select-options to a FM or is there a different way of achieving this?

Thanks.

Swapnil.

Read only

0 Likes
3,337

In FM you can either

1) create two imporitng paramenter, one would be for regular sel.screen parameter, another one would be for select-options. Make them both optional so the user will provide any he wants. Inside do a check if is supplied and if so then for parameter use the above code and for select-options you have to extract one of its value (i.e LOW or HIGH). Then just proceed as with normal parameter

2) make one parameter of type any and inside fm check what type of parameter is it. If structure (select options line) then use class cl_abap_structdescr to get its strcutrue, then get its low component and use same approach as above for sinlge field

if parameter (single field) then use above coding without additional checks.

That should help

Marcin

Read only

0 Likes
3,337

Hi Marcin,

I think we are not on the same page yet. I do not intend to call the FM using individual parameter / select-option name because this way the whole objective of reusability will be lost. In different programs, there will be different select-options which will call for different code for each program. I need something like

CALL FUNCTION 'Z_SEL_SCR_TEXT'

EXPORTING program = sy-repid

TABLES text = sel_scr_text.

I can pass the names of the select options to the FM (which i get from the FM RS_REFRESH_FROM_SELECTOPTIONS), but those will go in char format and get_ddic_object( ) will return char. How do I pass select-options to this function module?

Swapnil.

Read only

0 Likes
3,337

Ok, I get you. You can use FM RS_REPORTSELECTSCREEN_INFO to get info about selection screen parameters/sel options and then use method describe_by_name to get that information. Refer the below


DATA: pernr TYPE persno.
PARAMETERS pa_bukrs TYPE pa0001-bukrs.
SELECT-OPTIONS so_pernr FOR pernr.

*PERFORM get_rolltext USING
*PERFORM get_rolltext USING s

DATA: it_fieldnames TYPE TABLE OF RSDYNPAR WITH HEADER LINE,
      it_fieldinfo  type table of RSEL_INFO WITH HEADER LINE.

CALL FUNCTION 'RS_REPORTSELECTSCREEN_INFO'
  EXPORTING
    report                    = sy-repid
  tables
    field_info                = it_fieldinfo[]
    field_names               = it_fieldnames[].


LOOP AT it_fieldinfo.

  DATA: it_ddic TYPE dd_x031l_table WITH HEADER LINE.
  DATA: r_datadescr TYPE REF TO cl_abap_datadescr.
  DATA ls_roll_info TYPE rpy_dtel.

  r_datadescr ?= cl_abap_typedescr=>describe_by_name( it_fieldinfo-DBFIELD ).
  it_ddic[] = r_datadescr->get_ddic_object( ).
  ...
ENDLOOP.

Just encapsulate the above into FM and collect the texts in the table which you retrun from that fm.

Regards

Marcin

Read only

0 Likes
3,337

The question is solved.

Thanks a lot Marcin. You are simply awesome!