‎2013 Oct 15 12:16 PM
Hi,
I have a custom table with 10 fields.
Some are mandatory and some are optional. Some will become mandatory based on other fields.
I know there is a wizard where we can generate table maintenance. How to generate these business rules?
Do i need create normal report program and push the data into table or is there any additional functionality where i can add the business rules in the wizard itself?
The rules are like if field1 is present, then field2 becomes mandatory like that.
Regards
Sam
‎2013 Oct 15 4:08 PM
Hi,
You could use the events on the table maintenace generator . Please refer below link for more details
http://wiki.scn.sap.com/wiki/display/ABAP/TABLE+MAINTENANCE+GENERATOR+and+ITS+EVENTS
‎2013 Oct 15 2:39 PM
Hi Sam.
Try to use this:
SE11 transaction -> Your DB table -> Change:
Menu: Utitities(M) -> Table Maintenance Generator.
When maintenance is generated go to menu: Environment -> Modification -> Events -> New Entries:
Then, create event and appropriate form:
In that way you can handle custom events for standard generated table maintenance.
-----
Best regards,
George Shlyahov
‎2013 Oct 15 2:45 PM
Hello Sam,
1) One way is to use database events as mentioned earlier.
2) The second option is using Programming logic in Module pool. Let's say, you created a Table Maintenance named "ZTAB_MAINT" using tables maintanance generator, having columns, FLD1,FLD2,FLD3 & FLD4.
i) Go to SE80
ii) Make Function Group = ZTAB_MAINT
iii) Select the screen number that you have created in Table Maintanace
iv) Double click on the Screen Number
v) in "Process After Input", you would get Loop at extract..... Endloop, Within this loop, and just before Endloop, you can create a module "Module FIELD_CHECK". In this module you can write the suitable logic.
Now, whenever you enter any data using SM30, the PAI module would be triggered and your validations would be checked.
‎2013 Oct 15 3:14 PM
Hello All
Thanks for the replies. We are not allowed to provide SM30 to business users. So we would need to provide them with some Z transaction. In this case, do i need to go for dialog programming only or the above approaches can be used.
Regards
Sam Anderson
‎2013 Oct 15 3:55 PM
Hi,
you can use a parameter Transaction (se93) and call the sm30 from there. Therefore the business doesn't need SM30 itself and you can use the Table Maintenace.
However you still have to do the above mentioned to get your business logic in.
regards
‎2013 Oct 15 4:08 PM
Hi,
You could use the events on the table maintenace generator . Please refer below link for more details
http://wiki.scn.sap.com/wiki/display/ABAP/TABLE+MAINTENANCE+GENERATOR+and+ITS+EVENTS
‎2013 Oct 16 11:20 AM
Hello Jino,
Thanks for the link.
I am still struggling to write the form routine code. All I need is if field 1 is entered with value '311' then field 3 and field 5 is mandatory.
Please help the same as I am not sure which event to be triggered and what form routine that I need to write.
Regards
Sam
‎2013 Oct 16 11:32 AM
Choose event 05 and enter subroutine name-->Press save--> click on source code editor button infront of routine let lt create-> In include enter FORM <Subroutine name> ENDFORM. then you can put a check their.
The values will be availble in <TABLE_NAME>-<FIELD_NAME>
‎2013 Oct 16 3:37 PM
Hi Sam!
As I wrote earlier, you have to create subroutine form:
So, you can use the following code as an example for it:
FORM new_entry.
DATA:
dynpfields TYPE STANDARD TABLE OF dynpread,
wa_dynpfields TYPE dynpread,
dyname TYPE sy-repid,
dynum TYPE sy-dynnr.
IF z_your_db_table-field1 = '311'.
dyname = sy-repid.
dynum = sy-dynnr.
wa_dynpfields-fieldname = 'Z_YOUR_DB_TABLE-FIELD3'.
APPEND wa_dynpfields TO dynpfields.
wa_dynpfields-fieldname = 'Z_YOUR_DB_TABLE-FIELD5'.
APPEND wa_dynpfields TO dynpfields.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = dyname
dynumb = dynum
TABLES
dynpfields = dynpfields
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.
IF sy-subrc = 0.
READ TABLE dynpfields INTO wa_dynpfields
WITH KEY fieldname = 'Z_YOUR_DB_TABLE-FIELD3'.
IF wa_dynpfields-fieldvalue IS NOT INITIAL.
z_your_db_table-field3 = wa_dynpfields-fieldvalue.
ENDIF.
READ TABLE dynpfields INTO wa_dynpfields
WITH KEY fieldname = 'Z_YOUR_DB_TABLE-FIELD5'.
IF wa_dynpfields-fieldvalue IS NOT INITIAL.
z_your_db_table-field5 = wa_dynpfields-fieldvalue.
ENDIF.
ENDIF.
IF z_your_db_table-field3 IS INITIAL.
LOOP AT SCREEN.
IF screen-name = 'Z_YOUR_DB_TABLE-FIELD3'.
screen-required = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
vim_abort_saving = 'X'.
MESSAGE 'Field 3 is mandatory!' TYPE 'E'.
ENDIF.
IF z_your_db_table-field5 IS INITIAL.
LOOP AT SCREEN.
IF screen-name = 'Z_YOUR_DB_TABLE-FIELD5'.
screen-required = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
MESSAGE 'Field 5 is mandatory!' TYPE 'E'.
vim_abort_saving = 'X'.
ENDIF.
ENDIF.
ENDFORM.
It works like this:
I hope this will be helpful.
-----
Best regards,
George Shlyahov
‎2013 Oct 18 2:41 PM
Hello George,
The code works perfectly.
I need the same set of rules for another field.
In nutshell if field 1 is 311 field 3 and field 5 are mandatory.
If field 2 has some values, then field 4 and field 6 are mandatory.
I inserted another if condition but the issue is only one set of rules works at a time since the traversing of if condition is already gone through.
I even tried giving one set of rules while creating an entry and another while saving the entry. But does not seem to work.
Any idea on how to do this?
Regards
Sam
‎2013 Oct 21 6:29 AM
Hi Sam!
Please, be guided by the following code:
FORM new_entry.
* Field 3 check:
PERFORM check_mandatory_field USING 'Z_TEST-FIELD3'
z_test-field1
'EQ'
'311'
'Field 3 is mandatory!'
CHANGING z_test-field3.
* Field 4 check:
PERFORM check_mandatory_field USING 'Z_TEST-FIELD4'
z_test-field2
'NE'
''
'Field 4 is mandatory!'
CHANGING z_test-field4.
* Field 5 check:
PERFORM check_mandatory_field USING 'Z_TEST-FIELD5'
z_test-field1
'EQ'
'311'
'Field 5 is mandatory!'
CHANGING z_test-field5.
* Field 6 check:
PERFORM check_mandatory_field USING 'Z_TEST-FIELD6'
z_test-field2
'NE'
''
'Field 6 is mandatory!'
CHANGING z_test-field6.
ENDFORM. "new_entry
FORM check_mandatory_field USING uv_fieldname TYPE dynfnam
uv_rel_field_val_1 TYPE any
uv_condition TYPE any
uv_rel_field_val_2 TYPE any
uv_message_text TYPE string
CHANGING cv_value TYPE any.
DATA:
dynpfields TYPE dynpread_tty,
wa_dynpfields TYPE dynpread,
dyname TYPE sy-repid,
dynum TYPE sy-dynnr.
dyname = sy-repid.
dynum = sy-dynnr.
wa_dynpfields-fieldname = uv_fieldname.
APPEND wa_dynpfields TO dynpfields.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = dyname
dynumb = dynum
TABLES
dynpfields = dynpfields
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.
IF sy-subrc = 0.
READ TABLE dynpfields INTO wa_dynpfields
WITH KEY fieldname = uv_fieldname.
IF wa_dynpfields-fieldvalue IS NOT INITIAL.
cv_value = wa_dynpfields-fieldvalue.
ENDIF.
ENDIF.
IF cv_value IS INITIAL.
LOOP AT SCREEN.
IF screen-name = uv_fieldname.
CASE uv_condition.
WHEN 'EQ'.
IF uv_rel_field_val_1 EQ uv_rel_field_val_2.
screen-required = 1.
ELSE.
screen-required = 0.
ENDIF.
WHEN 'NE'.
IF uv_rel_field_val_1 NE uv_rel_field_val_2.
screen-required = 1.
ELSE.
screen-required = 0.
ENDIF.
ENDCASE.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
CASE uv_condition.
WHEN 'EQ'.
IF uv_rel_field_val_1 EQ uv_rel_field_val_2.
vim_abort_saving = 'X'.
MESSAGE uv_message_text TYPE 'E'.
ENDIF.
WHEN 'NE'.
IF uv_rel_field_val_1 NE uv_rel_field_val_2.
vim_abort_saving = 'X'.
MESSAGE uv_message_text TYPE 'E'.
ENDIF.
ENDCASE.
ENDIF.
ENDFORM.
The code is colored by ABAP code lighter for SCN.sap.com
Result:
-----
Best regards,
George Shlyahov