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: 

How to set focus?

Former Member
0 Kudos

Hi,

I have 3 input field in an ABAP program and need to do validation on these 3 mandatory fields. When the user click on the submit pushbutton, the code behind will need to validate the 3 mandatory fields, if one of the field is empty, the validation code must set focus on that particular field and prompt a message to alert the user. How to do that?

Best Regards

Rayden

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos

Use

SET CURSOR

DATA: flag TYPE c LENGTH 1,

inp TYPE c LENGTH 10.

SET BLANK LINES ON.

WRITE: / flag AS CHECKBOX, inp INPUT.

SET CURSOR FIELD 'inp' LINE sy-linno.

17 REPLIES 17

former_member223537
Active Contributor
0 Kudos

Use

SET CURSOR

DATA: flag TYPE c LENGTH 1,

inp TYPE c LENGTH 10.

SET BLANK LINES ON.

WRITE: / flag AS CHECKBOX, inp INPUT.

SET CURSOR FIELD 'inp' LINE sy-linno.

0 Kudos

Hi,

I try but it seem like it cannot set focus.

Code here:

=================================================================

REPORT ZNEW_UI_ZSTUD00 MESSAGE-ID ZMSG.

&----


*& Global Declarations

&----


TABLES ZSTUD00.

&----


*& Processing Blocks called by the Runtime Environment

&----


START-OF-SELECTION.

CALL SCREEN 100.

"PBO.

MODULE STATUS_0100 OUTPUT.

ENDMODULE.

"PAI.

MODULE USER_COMMAND_0100 INPUT.

CASE sy-ucomm.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'INST'.

IF ZSTUD00-ADMNO <> ''.

"Do other stuff

ELSE.

SET CURSOR FIELD 'ZSTUD00-EYEAR'.

MESSAGE e001.

ENDIF.

ENDCASE.

ENDMODULE.

===============================================================

Regards,

Rayden

Message was edited by:

Rayden Goh

0 Kudos

Hello Rayden,

Have you tried my logic ? if not then try now ,it should work.

Write the code after PAI

field fieldname1 module mod . -> double click on module.

field fieldname2 module mod1. -> double click on mod1

write the simple logic there.

This is mod code

if fieldname1 is initial.

message e000(z01).

endif.

This is mod1 code

if fieldname1 is initial.

message e000(z01).

endif.

if you do not enter any value on field ,then you get message ,cursor will stop there.

Thanks

Seshu

0 Kudos

Is the name of the field in screen 100 definitely 'ZSTUD00-EYEAR'...? try the sample report down the bottom - it shows how the set cursor should work for you. But remember that in dynpro programming you need to keep the relevant fields open for input using the:

CHAIN. 
  FIELD: 
    ZSTUD00-EYEAR. 
    module USER_COMMAND_0100.
ENDCHAIN.

in the screen flow.

Jonathan

report zlocal_jc_validate.

parameters:
  p_empty               like sy-datum,
  p_date                like sy-datum,
  p_time                like sy-uzeit.

at selection-screen.
  perform at_selection_screen.

form at_selection_screen.

  if p_date is initial.
    set cursor field 'P_DATE'. "move cursor to problem field
    message e398(00) with 'Enter a date'
      space space space.
  endif.

  if p_time is initial.
    set cursor field 'P_TIME'. "move cursor to problem field
    message e398(00) with 'Enter a time'
      space space space.
  endif.

endform.

0 Kudos

Hi Seshu,

Great to hear from you. I have try the code. I add the code " field fieldname1 module mod . "

and double click on the mod. it prompted me to create the object. I created it as a Global Data Type and it generate the code "DATA mod." in my declaration area. When i do a check on the syntax. It highlight the code added and prompt an error stated : "Statement "Field" is not defined. Check your spelling. spelling. spelling. spelling."

How do i go about it? Please kindly advise. Thanks

Regards,

Rayden

0 Kudos

Hi Rayden,

First declare three variables :

I guess you are using module pool program :

Data declaration :

data : l_matnr like mara-matnr,

l_kunnr like kna1-kunnr,

l_lifnr like lfa1-lifnr.

Now goto Layout -> click on dictinary fields -> enter one by one -> select from program.

Once you done -> save and activate screen.

Come to PAI :

PROCESS AFTER INPUT.

field l_matnr module mod2. -> double click on mod2

field l_kunnr module mod. -> double click on mod

field l_lifnr module mod1. -> double click on mod1

MODULE USER_COMMAND_9000.

&----


*& Module mod INPUT

&----


  • text

----


MODULE mod INPUT.

if l_kunnr is initial.

message e001(z01).

endif.

ENDMODULE. " mod INPUT

&----


*& Module mod1 INPUT

&----


  • text

----


MODULE mod1 INPUT.

if l_lifnr is initial.

message e002(z01).

endif.

ENDMODULE. " mod1 INPUT

&----


*& Module mod2 INPUT

&----


  • text

----


MODULE mod2 INPUT.

if l_matnr is initial.

message e002(z01).

endif.

ENDMODULE. " mod2 INPUT

Please activate all areas of module pool.

Please uncomment the PBO and creates pf status here.

use case sy-ucomm.

case sy-ucomm.

when 'BACK'.

leave to screen 0.

when 'CANC'.

leave to screen 0.

WHEN 'EXIT'.

leave to screen 0.

endcase.

now create transaction and now run .

if you do not enter data on any field ,then it gives message ,cursor will stop on exact field.

Hope you got it.

Thanks

Seshu

0 Kudos

Hi Jonathon,

Thank for the feedback. I'm a bit close to what i want. I try to create a program with your code in it, it work fine. It will set focus on the respective field and able to enter the data.

I add the code in my program. It able to set the cursor on the particular field but it seem to become a read-only field after i click on the pushbutton, which i cannot enter any data in the field. How to solve this problem?

Code Here:

=================================================================

&----


*& Report ZNEW_UI_ZSTUD00

*&

&----


*&

*&

&----


REPORT ZNEW_UI_ZSTUD00.

&----


*& Global Declarations

&----


TABLES ZSTUD00.

&----


*& Processing Blocks called by the Runtime Environment

&----


START-OF-SELECTION.

CALL SCREEN 100.

"PBO.

MODULE STATUS_0100 OUTPUT.

ENDMODULE.

"PAI.

MODULE USER_COMMAND_0100 INPUT.

CASE sy-ucomm.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'INST'.

IF ZSTUD00-CONTACT is initial.

set cursor field 'ZSTUD00-CONTACT'. "move cursor to problem field

message e398(00) with 'Enter a Contact'

space space space.

endif.

ENDCASE.

ENDMODULE.

===============================================================

Regards,

Rayden

0 Kudos

Have you included all the fields you want to remain open for input inside the "chain." "endchain." in the screen flow?

Jonathan

0 Kudos

Hi Jonathan,

Include the "Chain. Endchain." right after the START-OF-SELECTION statement?

I have add in, but the error state : Statement "CHAIN" is not defined. Check your spelling. spelling. spelling. spelling.

How tdo i go about it?

Regards,

Rayden

0 Kudos

Hi Seshu,

I try the code, but it return the same error. "Statement "Field" is not defined. Check your spelling. spelling. spelling. spelling."

It seem like don't recognize the FIELD statement. Why is that so? Is it obsolete?

Regards,

Rayden

0 Kudos

Hi Raydon,

Please share how to resolved the error ' Statement "Chain" is not defined. check spelling. spelling.'

I have tried everything & not much information is available on the internet to research on this topic.

Thanks!

Former Member
0 Kudos

You can write simple code in PAI

PROCESS AFTER INPUT.

<b>field l_kunnr module mod. -> double click on mod

field l_lifnr module mod1. -> double click on mod1</b>

MODULE USER_COMMAND_9000.

&----


*& Module mod INPUT

&----


  • text

----


MODULE mod INPUT.

if l_kunnr is initial.

message e001(z01).

endif.

ENDMODULE. " mod INPUT

&----


*& Module mod1 INPUT

&----


  • text

----


MODULE mod1 INPUT.

if l_lifnr is initial.

message e002(z01).

endif.

ENDMODULE. " mod1 INPUT

<b>If you use field statement ,cursor will stop at exact field</b>

Thanks

Seshu

Former Member
0 Kudos

Hi,

In PAI module,

PROCESS AFTER INPUT.

FIELD <field1> MODULE <module_name> "Dblclick on the moduel name and inside it code for checking if field is empty.

Module <module_name>

If <field1> is initial.

MESSAGE E001.

Else.

Leave to screen <next screen>

EndIf.

End Module.

I think this could solve ur problem.If it was helpful reward points

Regards,

Krithika

Former Member
0 Kudos

Hi,

Keep all the field statements inside the CHAIN.....ENDCHAIN (for all the fields that u want to keep open).This would definitely solve the issue.

Regards,

Krithika

Former Member
0 Kudos

Hi,

Thanks guys for the support. After doing some research. I mange to solve it. Marks is rewarded for the effort.

Regards,

Rayden

0 Kudos

Thanks for keeping the info for yourself.

0 Kudos

Hi Glen,

Well, the solution provided by Seshu Maramreddy & Jonathan Coleman is workable. Refer to the post that they posted, it very useful. As a beginner in ABAP, it really took me some time to understand.

Regards,

Rayden