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: 

in table maintainance generator

Former Member
0 Kudos

hi

in table maintainance generator, how to validate the data entered in the table. If it is only with the events, how?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

you can validate the data in tables, after generating a table maintanance generator.

Environment->Modification->Events.

After providing the subroutine name you can go to editor( click on icon provided just besides the form routine) and write the logic for validation.

for example, if changes are to be made to the data of particular controlling area, a check has to be made if the user is authorised to make changes. Below is a sample code that would give you an idea.

Sample code:

&----


*& Form auth_check_save

&----


  • Checks that the user has the correct authorisations to Change

  • details of Controlling Area. If not error message is to be

  • displayed on the screen.

----


form auth_check_save.

  • Data Declaration

  • Types

types: begin of ty_valtab,

kokrs(4) type c,

actvt(2) type c,

end of ty_valtab,

begin of ty_fieldtab,

fieldname(10) type c,

end of ty_fieldtab.

  • Internal Tables

data: lt_valtab type standard table of ty_valtab,

lt_fieldtab type standard table of ty_fieldtab,

  • Structures

ls_valtab type ty_valtab,

ls_fieldtab type ty_fieldtab,

ls_costele type ztf_costele,

  • Variables

l_status type zss_rfc_status,

l_st(1) type c.

  • Constants

constants : c_0(1) type c value '0',

c_01(2) type c value '01',

c_02(2) type c value '02',

c_06(2) type c value '06',

c_authobj(10) type c value 'Z_KOKRS',

c_error(5) type c value 'ERROR',

c_partial(7) type c value 'PARTIAL',

c_kokrs(5) type c value 'KOKRS',

c_actvt(5) type c value 'ACTVT'.

clear l_status.

ls_fieldtab-fieldname = c_kokrs.

append ls_fieldtab to lt_fieldtab.

clear ls_fieldtab.

ls_fieldtab-fieldname = c_actvt.

append ls_fieldtab to lt_fieldtab.

clear ls_fieldtab.

loop at total.

if <action> eq neuer_eintrag.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_01.

append ls_valtab to lt_valtab.

clear ls_valtab.

elseif <action> eq aendern.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_02.

append ls_valtab to lt_valtab.

clear ls_valtab.

elseif <action> eq geloescht.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_06.

append ls_valtab to lt_valtab.

clear ls_valtab.

endif.

endloop.

  • Authorization Check

call function 'ZAUTH_CHECK'

exporting

  • PIM_REPID =

pim_auth_obj = c_authobj

  • PIM_FIELD_TABNAME =

  • PIM_CHECKALL =

importing

pex_status = l_status

tables

pex_val_tab = lt_valtab

pim_field_tab = lt_fieldtab

exceptions

no_input = 1

others = 2.

if l_status = c_error. "Authorization Check

  • message under class: zmessclass

message e000(zmessclass) with text-e02. "You have no authorization

"for table maintenance

elseif l_status = c_partial.

loop at total.

if <action> ne space.

move total to ls_costele.

read table lt_valtab with key kokrs = ls_costele-kokrs

transporting no fields.

if sy-subrc <> c_0.

delete table total.

delete table extract.

endif.

endif.

endloop.

message e400(zmessclass). "All the entries could not be saved

"because of restricted authorization

endif. "End of Authorization Check

endform. "auth_check_save

The above code should be written in event 01 : Before saving the data in the database

Regards,

Farheen

3 REPLIES 3

FredericGirod
Active Contributor
0 Kudos

depends off what you would like to validate.

if it's a format problem, you could use field-exit (maintain in the domain level)

Former Member
0 Kudos

hi,

you can validate the data in tables, after generating a table maintanance generator.

Environment->Modification->Events.

After providing the subroutine name you can go to editor( click on icon provided just besides the form routine) and write the logic for validation.

for example, if changes are to be made to the data of particular controlling area, a check has to be made if the user is authorised to make changes. Below is a sample code that would give you an idea.

Sample code:

&----


*& Form auth_check_save

&----


  • Checks that the user has the correct authorisations to Change

  • details of Controlling Area. If not error message is to be

  • displayed on the screen.

----


form auth_check_save.

  • Data Declaration

  • Types

types: begin of ty_valtab,

kokrs(4) type c,

actvt(2) type c,

end of ty_valtab,

begin of ty_fieldtab,

fieldname(10) type c,

end of ty_fieldtab.

  • Internal Tables

data: lt_valtab type standard table of ty_valtab,

lt_fieldtab type standard table of ty_fieldtab,

  • Structures

ls_valtab type ty_valtab,

ls_fieldtab type ty_fieldtab,

ls_costele type ztf_costele,

  • Variables

l_status type zss_rfc_status,

l_st(1) type c.

  • Constants

constants : c_0(1) type c value '0',

c_01(2) type c value '01',

c_02(2) type c value '02',

c_06(2) type c value '06',

c_authobj(10) type c value 'Z_KOKRS',

c_error(5) type c value 'ERROR',

c_partial(7) type c value 'PARTIAL',

c_kokrs(5) type c value 'KOKRS',

c_actvt(5) type c value 'ACTVT'.

clear l_status.

ls_fieldtab-fieldname = c_kokrs.

append ls_fieldtab to lt_fieldtab.

clear ls_fieldtab.

ls_fieldtab-fieldname = c_actvt.

append ls_fieldtab to lt_fieldtab.

clear ls_fieldtab.

loop at total.

if <action> eq neuer_eintrag.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_01.

append ls_valtab to lt_valtab.

clear ls_valtab.

elseif <action> eq aendern.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_02.

append ls_valtab to lt_valtab.

clear ls_valtab.

elseif <action> eq geloescht.

move total to ls_costele.

ls_valtab-kokrs = ls_costele-kokrs.

ls_valtab-actvt = c_06.

append ls_valtab to lt_valtab.

clear ls_valtab.

endif.

endloop.

  • Authorization Check

call function 'ZAUTH_CHECK'

exporting

  • PIM_REPID =

pim_auth_obj = c_authobj

  • PIM_FIELD_TABNAME =

  • PIM_CHECKALL =

importing

pex_status = l_status

tables

pex_val_tab = lt_valtab

pim_field_tab = lt_fieldtab

exceptions

no_input = 1

others = 2.

if l_status = c_error. "Authorization Check

  • message under class: zmessclass

message e000(zmessclass) with text-e02. "You have no authorization

"for table maintenance

elseif l_status = c_partial.

loop at total.

if <action> ne space.

move total to ls_costele.

read table lt_valtab with key kokrs = ls_costele-kokrs

transporting no fields.

if sy-subrc <> c_0.

delete table total.

delete table extract.

endif.

endif.

endloop.

message e400(zmessclass). "All the entries could not be saved

"because of restricted authorization

endif. "End of Authorization Check

endform. "auth_check_save

The above code should be written in event 01 : Before saving the data in the database

Regards,

Farheen

Former Member
0 Kudos

Hi

There are 2 methods for validating the data.

One is by using events and the other chnaging the function group includes.

These function group is the group which is entered in SE54 Transaction.

If you see the function group, you see

  • include-files generated by view maintenance tool

PBO

PAI

  • User-defined Include-files (if necessary). *

Decide where you want to validate, i mean in PBO or PAI.

Then comment out the corresponding PBO or PAI and copy the code to user defined includes. Then make the necessary changes..

Note: there is a big disadvantage of using this technique. When any one regenerates the table maintainenace, then all the changes which you made will be lost.. Hence always use Events.

If this is what you are looking for, please reward.

Best Regards

Sree