Scenario: Provide two radio button - Insert and Update in the selection screen. On selecting the insert button, Data will be inserted in the table and on selecting the update the data will be updated.
Solution:
Expected Output:
When Insert is selected the New Employee ID should come automatically & it should be non editable |
When Update is selected, the employee ID that needs to be updated will be displayed |
On entering the Employee ID, the records has to be displayed in the selection screen for editing |
Solution:
*&---------------------------------------------------------------------* *& *& INSERT AND UPDATE IN TABLE ZEMP *&---------------------------------------------------------------------* REPORT zdemo. TABLES: zemp. DATA: gs_zemp TYPE zemp, gv_last_id TYPE zdt_id. SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. "RADIO BUTTON FOR - INSERT OR UPDATE PARAMETERS: rb_in RADIOBUTTON GROUP rb1 USER-COMMAND c1 DEFAULT 'X' MODIF ID b1, rb_up RADIOBUTTON GROUP rb1 MODIF ID b1. SELECTION-SCREEN: END OF BLOCK b1. SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002. "INSERT RECORD BLOCK PARAMETERS: p_id TYPE zdt_id MODIF ID b2i, p_name TYPE zemp_n MODIF ID b2, p_des TYPE zemp_d MODIF ID b2, p_yr TYPE zemp_y MODIF ID b2, p_ph TYPE zemp_p MODIF ID b2. SELECTION-SCREEN: END OF BLOCK b2. SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-003. "UPDATE BLOCK: EMP ID PARAMETERS: p_u_id TYPE zdt_id MODIF ID b3. SELECTION-SCREEN: END OF BLOCK b3. SELECTION-SCREEN: BEGIN OF BLOCK b4 WITH FRAME TITLE text-004. "UPDATE BLOCK PARAMETERS: p_u_name TYPE zemp_n MODIF ID b4, p_u_des TYPE zemp_d MODIF ID b4, p_u_yr TYPE zemp_y MODIF ID b4, p_u_ph TYPE zemp_p MODIF ID b4. SELECTION-SCREEN: END OF BLOCK b4. INITIALIZATION. SELECT MAX( emp_id ) FROM zemp INTO gv_last_id . "GETTING THE LAST EMPID FOR GENERATING THE NEW EMPID IF sy-subrc EQ 0. p_id = gv_last_id + 1. ELSE. * IMPLEMENT SUITABLE HANDLER ENDIF. AT SELECTION-SCREEN OUTPUT. IF rb_in EQ 'X' . "IF INSERT IS SELECTED CLEAR: p_u_id. LOOP AT SCREEN. IF screen-group1 = 'B3' OR screen-group1 = 'B4'. screen-active = 0. ELSEIF screen-group1 = 'B2I'. screen-input = 0. ELSE. screen-active = 1. ENDIF. MODIFY SCREEN. ENDLOOP. ELSEIF rb_up EQ 'X' AND p_u_id IS INITIAL. LOOP AT SCREEN. IF screen-group1 = 'B2' OR screen-group1 = 'B2I' OR screen-group1 = 'B4'. screen-active = 0. ELSE. screen-active = 1. ENDIF. MODIFY SCREEN. ENDLOOP. ELSEIF rb_up EQ 'X' AND p_u_id IS NOT INITIAL. SELECT SINGLE * FROM zemp INTO gs_zemp WHERE emp_id = p_u_id. IF sy-subrc EQ 0. LOOP AT SCREEN. IF screen-group1 = 'B2' OR screen-group1 = 'B2I'. screen-active = 0. ELSE. screen-active = 1. ENDIF. MODIFY SCREEN. ENDLOOP. p_u_name = gs_zemp-emp_name. p_u_des = gs_zemp-designation. p_u_yr = gs_zemp-yr_of_exp. p_u_ph = gs_zemp-phone_no. ELSE. MESSAGE 'Invalid ID' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. ENDIF. START-OF-SELECTION. IF rb_up EQ 'X'. "UPDATE gs_zemp-emp_name = p_u_name. gs_zemp-designation = p_u_des. gs_zemp-yr_of_exp = p_u_yr. gs_zemp-phone_no = p_u_ph. UPDATE zemp FROM gs_zemp . IF sy-subrc EQ 0. MESSAGE 'Record Updated' TYPE 'S'. ELSE. MESSAGE 'Record Not Updated' TYPE 'E'. ENDIF. ELSE. "INSERT CLEAR: gs_zemp. gs_zemp-mandt = sy-mandt. "'115'. gs_zemp-emp_id = p_id. gs_zemp-emp_name = p_name. gs_zemp-designation = p_des. gs_zemp-yr_of_exp = p_yr. gs_zemp-phone_no = p_ph. INSERT zemp FROM gs_zemp. IF sy-subrc EQ 0. MESSAGE 'Record Inserted' TYPE 'S'. ELSE. MESSAGE 'Record Not Inserted' TYPE 'E'. ENDIF. CLEAR: gs_zemp. ENDIF.
No comments:
Post a Comment