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

Query on Database table update after input validation

former_member699182
Participant
0 Likes
996

Hello All,

I have a report program in which I am taking  p_dest, p_ipaddr,  p_instno as parameters and checking in the below code for invalid input. I want to update the db table after the below check is done. I am doing it below but what check do i do before update? Should i set a flag or something?   I am just stuck with this simple logic.

Please help.

IF ( p_ipaddr <> space ) OR ( p_instno <> space ).

    IF p_dest = space.

      SET CURSOR FIELD 'p_dest'.

      MESSAGE 'Invalid Destination' TYPE 'S'.

    ENDIF.

  ELSE.

    EWOSS-SR1NAME = p_dest.

  ENDIF.

  IF ( p_dest <> space ) OR ( p_instno <> space ).

    IF ( p_ipaddr CN '0123456789. ' ) OR ( p_ipaddr = space ).

      SET CURSOR FIELD 'p_ipaddr'.

      MESSAGE 'Invalid IP Address' TYPE 'S'.

    ENDIF.

  ELSE.

    EWOSS-SR1IP = p_ipaddr.

  ENDIF.

  IF ( p_dest <> space ) OR ( p_ipaddr <> space ).

    IF ( p_instno CN '0123456789' ).

      SET CURSOR FIELD 'p_instno'.

      MESSAGE 'Invalid Instance Number' TYPE 'S'.

    ENDIF.

  ELSE.

    EWOSS-SR1INST = p_instno.

  ENDIF.

?????

UPDATE ewoss.

  IF sy-subrc = 0.

    WRITE: 'OK'.

  ELSE.

    WRITE: 'NG'.

  ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
948

Hi

i think no need of flag

before update you can check whether  EWOSS is initial or not.

if not initial then update.

just try with MODIFY key word.

NOTE:  if you want to stop the program execution when the wrong values entered then you should use MESSAGE TYPE 'E', otherwise it wont stop the execution it will execute with wrong values.

regards

laxman

8 REPLIES 8
Read only

former_member699182
Participant
0 Likes
945

Also when i try to update the EWOSS table as per the above code, it deletes the values in the other fields apart from the 3 fields that are given as parameters. Anyone got any idea on why this happens?

Thanks.

Read only

0 Likes
945

hi gita,

set a flag for every check.

before updating if any one check fails then don't update it.

Read only

0 Likes
945

Thanks for the input Abdul.

I used a flag to set it as below. It works fine. But is there any other clean way of doing it? I seem to have a lot of IF ENDIF already and my code appears messy.

IF ( flag_dest = 'X' AND flag_ip = 'X' AND flag_inst = 'X' ).

  UPDATE ewoss.

  IF sy-subrc = 0.

    WRITE: 'OK'.

  ELSE.

    WRITE: 'NG'.

  ENDIF.

ELSE.

  MESSAGE 'Invalid Input' TYPE 'S'.

ENDIF.

Also have you got any idea on why the other fields of table EWOSS gets deleted on performing an update?

Read only

Former Member
0 Likes
949

Hi

i think no need of flag

before update you can check whether  EWOSS is initial or not.

if not initial then update.

just try with MODIFY key word.

NOTE:  if you want to stop the program execution when the wrong values entered then you should use MESSAGE TYPE 'E', otherwise it wont stop the execution it will execute with wrong values.

regards

laxman

Read only

0 Likes
945

Thanks a lot Laxman.

Modify instead of Update is a good suggestion and it works fine now.

However, coming to the Message Type, if i use the type E, control moves to the next screen and displays the error message, whereas if i use S, control remains in the same screen.

How do i use E and still remain in the same screen?
FYI, below is how i changed.

MESSAGE 'Invalid Instance Number' TYPE 'E'.

Is there something wrong in how i am using E?

Need your suggestion.

Thanks.

Read only

0 Likes
945

You can also try to give message like this

MESSAGE 'Invalid Instance Number' TYPE 'I' display like 'E'.

Read only

0 Likes
945

Nothing is wrong.

type 'E' works like that only becaus after error msg it will come out.

So once try what abdul said.

Read only

0 Likes
945

Thanks a lot Abdul and Laxman.

I too found out the answer from the below link while searching

http://scn.sap.com/thread/1258307

I used

MESSAGE 'Invalid Instance Number' TYPE 'S' display like 'E'.

LEAVE LIST-PROCESSING.

Now it works fine.

Thanks again. You were so helpful.