Sunday, 8 April 2012

SET CURSOR FIELD

Sometimes there is a requirement to place the cursor on the field having a wrong value in the selection screen.

OUTPUT:


On pressing “ENTER” button or executing (F8) the program, it can be seen that the entry was wrong for customer number field but the cursor gets placed in company code field.

 









If such are the cases then modify the program as:


MODIFIED PROGRAM:

REPORT ztest.

TABLES:bsid.

DATA: temp_hkont TYPE bsid-hkont,
temp_kunnr TYPE bsid-kunnr,
temp_bukrs TYPE bsid-bukrs.

SELECT-OPTIONS: s_bukrs FOR bsid-bukrs.
PARAMETERS: s_hkont LIKE bsid-hkont.
PARAMETERS: s_kunnr LIKE bsid-kunnr.

AT SELECTION-SCREEN.
CLEAR: temp_hkont.
IF s_hkont IS NOT INITIAL.
SELECT SINGLE hkont FROM bsid INTO temp_hkont
WHERE hkont = s_hkont.

IF sy-subrc <> 0.
SET CURSOR FIELD 'S_HKONT' DISPLAY OFFSET 0.
MESSAGE 'Enter a valid G/L Account' TYPE 'E'.
ENDIF.
ENDIF.

CLEAR: temp_kunnr.
IF s_hkont IS NOT INITIAL.
SELECT SINGLE kunnr FROM bsid INTO temp_kunnr
WHERE kunnr = s_kunnr.

IF sy-subrc <> 0.
SET CURSOR FIELD 'S_KUNNR' DISPLAY OFFSET 0.
MESSAGE 'Enter a valid G/L Account' TYPE 'E'.
ENDIF.
ENDIF.


CLEAR: temp_bukrs.
IF s_bukrs IS NOT INITIAL.
SELECT SINGLE bukrs FROM bsid INTO temp_bukrs
WHERE bukrs = s_bukrs-low.

IF sy-subrc = 0.
   SELECT SINGLE bukrs FROM bsid INTO temp_bukrs
                   WHERE bukrs = s_bukrs-high.

   IF sy-subrc <> 0.
       SET CURSOR FIELD 'S_BUKRS' DISPLAY OFFSET 0.
       MESSAGE 'Enter a Valid Company Code' TYPE 'E'.
   ENDIF.

ELSE.
       SET CURSOR FIELD 'S_BUKRS' DISPLAY OFFSET 0.
       MESSAGE 'Enter a Valid Company Code' TYPE 'E'.

ENDIF.
ENDIF.

OUTPUT:

In this case, the user enters correct company code and G/L account values, but the user gives a wrong value in customer Number field.

On pressing “ENTER” button or executing (F8) the program, it can be seen that the cursor gets placed in G/L account field correctly.