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: 

Get Screen element name at runtime

Former Member
0 Kudos

Hi all,

I have 120 fields on the screen. My query, how can I get the screen element(Suppose Button) name at runtime.Is there any system field or any FM which returns the Screen element name.

I do not want to use Loop at screen due to a lot of screen fields.

Please suggest.

Thanks

Sanket sethi

6 REPLIES 6

Former Member
0 Kudos

Hi,

You can use the GET CURSOR statement.

0 Kudos

I want to check the name of Range Icon. How it works.

Former Member
0 Kudos

Hi,

this is the sample code with using get cursor


TABLES : LFA1, LFB1.


TYPES : BEGIN OF VENDOR,
        LIFNR LIKE LFA1-LIFNR,
        NAME1 LIKE LFA1-NAME1,
        ORT01 LIKE LFA1-ORT01,
        END OF VENDOR,

        BEGIN OF VENDOR1,
        LIFNR LIKE LFA1-LIFNR,
        LAND1 LIKE LFA1-LAND1,
        BUKRS LIKE LFB1-BUKRS,
        END OF VENDOR1.



DATA : VENDOR_TAB TYPE STANDARD TABLE OF VENDOR INITIAL SIZE 20 WITH HEADER LINE,
       VENDOR1_TAB TYPE STANDARD TABLE OF VENDOR1 INITIAL SIZE 20 WITH HEADER LINE,
       FLDNAME(25),
       FLDVALUE(25).



TOP-OF-PAGE DURING LINE-SELECTION.
  WRITE 😕 'SECONDART LIST FOR VENDOR ID:', VENDOR_TAB-LIFNR COLOR 3.
  ULINE.

START-OF-SELECTION.

  SELECT LIFNR NAME1 ORT01
  FROM LFA1
  INTO CORRESPONDING FIELDS OF TABLE VENDOR_TAB.


AT LINE-SELECTION.

  GET CURSOR FIELD FLDNAME VALUE FLDVALUE.

  CASE FLDNAME.

    WHEN 'VENDOR_TAB-LIFNR' OR 'VENDOR_TAB-NAME1' OR 'VENDOR_TAB-ORT01'.

      IF SY-LSIND EQ 1.
        SELECT A~LIFNR A~LAND1 B~BUKRS
          FROM LFA1 AS A
          INNER JOIN LFB1 AS B
          ON A~LIFNR = B~LIFNR
          INTO CORRESPONDING FIELDS OF TABLE VENDOR1_TAB
          WHERE A~LIFNR = VENDOR_TAB-LIFNR.

        WRITE : /1 TEXT-001, 13 TEXT-004, 46 TEXT-005.
        ULINE.
        LOOP AT VENDOR1_TAB.

          WRITE : /1 VENDOR1_TAB-LIFNR, 13 VENDOR1_TAB-LAND1, 46 VENDOR1_TAB-BUKRS.

        ENDLOOP.
        ULINE.
        IF SY-SUBRC <> 0.
          MESSAGE E005.
        ENDIF.

      ENDIF.

    WHEN OTHERS.

      MESSAGE " any message that you want.

  ENDCASE.

END-OF-SELECTION.

  WRITE : /1 TEXT-001, 13 TEXT-002, 46 TEXT-003.
  ULINE.

  FORMAT HOTSPOT.

  LOOP AT VENDOR_TAB.

    WRITE : /1 VENDOR_TAB-LIFNR, 13 VENDOR_TAB-NAME1, 46 VENDOR_TAB-ORT01.

    HIDE : VENDOR_TAB-LIFNR.

  ENDLOOP.
  ULINE.

hope it will help you.

Thanks

Arun kayal

Former Member
0 Kudos

hi,

see this

thanks

faisal_altaf2
Active Contributor
0 Kudos

Hi,

Test the following Code Sample hope will solve out your problem,

TABLES: kna1, vbrp.
TYPES: BEGIN OF t_test,
  name(50),
END OF t_test.
DATA: it TYPE STANDARD TABLE OF t_test WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.
SELECT-OPTIONS: sodate FOR sy-datum NO-EXTENSION,
                sokunnr FOR kna1-kunnr NO INTERVALS,
                sopack FOR vbrp-mvgr1 NO INTERVALS.
SELECTION-SCREEN END OF BLOCK a.


LOOP AT it INTO it.
  WRITE: / it-name.
ENDLOOP.


AT SELECTION-SCREEN OUTPUT.
  CLEAR: it, it[].
  LOOP AT SCREEN.
    it-name = screen-name.
    APPEND it TO it.
  ENDLOOP.

Please Reply if any else issue.

Kind Regards,

Faisal

Former Member
0 Kudos

HI Sanket,

There are two function modules - DYNP_VALUES_READ and DYNP_VALUES_UPDATE - that can read the

values of screen fields and return values to them during the POV event.

Please try-out with the following code, perhaps that can help you solve your problem.

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

Function Modules to Read Screen Fields

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

Sometimes it is required to read the screen field values before they get

transferred into programme variables.

To achive the same the following steps may be carried out.

Create an internal table to hold the fields names that you want to read.

This internal table is a standard table of dynpread type.

For ex. :

T_DF LIKE STANDARD TABLE OF DYNPREAD

INITIAL SIZE 0 WITH HEADER LINE.

Also, declare two local variables to pass the programme name and

screen number to the function module

For ex. :

Variable to hold the program name

l_repid LIKE d020s-prog

Variable to hold the screen number

l_scrnr LIKE d020s-dnum

Populate the internal table with the field names that is to be read.

For ex. :

T_DF-FIELDNAME = 'KNA1-KUNNR'

APPEND T_DF

Take extra care when populating the field name of table control.

In that we will have to find out the line number where the cursor

is placed. To archive this the following piece of code may be used.

For ex. :

Declare the following variables.

l_cline(2) TYPE c "Holds the current line no

l_fld LIKE dynpread-fieldname "Holds the field name

l_lno TYPE i "Holds the current line no

Fetch the line number the cursor is

GET CURSOR LINE l_cline .

The following peice of code may be used to concatenate extra zero(0)

if the line number is less than 2 digits.

l_lno = strlen( l_cline ).

IF l_lno <= 1.

CONCATENATE '0' l_cline INTO l_cline.

ENDIF.

Then concatenate the line number along with a pair of parathesises

CONCATENATE 'T_ENLINES-MATNR(' l_cline ')' INTO l_fld.

CONDENSE l_fld NO-GAPS.

Then populate the internal table with field names

t_df-fieldname = l_fld.

APPEND t_df.

Assign the SY-REPID to the local variable. This step is required

otherwise it will give a warning message.

For ex. :

l_repid = sy-repid

l_scrnr = 9010

Call the function module, DYNP_VALUES_READ, to read the screen fields.

Export the programme name and screen number to the function module. Supply the internal table as parameter. This internal table will be

populated by the function module with the field values.

By trapping the value of sy-subrc, we can find out whether any error

occured or not.

CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING

dyname = l_repid

dynumb = l_scrnr

    • TRANSLATE_TO_UPPER = ' '*

    • REQUEST = ' '*

    • PERFORM_CONVERSION_EXITS = ' '*

    • PERFORM_INPUT_CONVERSION = ' '*

    • DETERMINE_LOOP_INDEX = ' '*

TABLES

dynpfields = T_DF

EXCEPTIONS

invalid_abapworkarea = 1

invalid_dynprofield = 2

invalid_dynproname = 3

invalid_dynpronummer = 4

invalid_request = 5

no_fielddescription = 6

invalid_parameter = 7

undefind_error = 8

double_conversion = 9

stepl_not_found = 10

OTHERS = 11

.

After successful execution of function module , we may read the

internal with the key field name, and find out the value by reading

the FIELDVALUE.

For ex.:

READ TABLE T_DF WITH KEY FIELDNAME = 'KNA1-KUNNR'.

*TDF-FIELDVALUE, will hold the value of the field 'KNA1-KUNNR'.*_

Thank & Regards,

Zahack