managed implementation in class zbp_i_blg_inspectionplantp unique;
strict;
with draft;
define behavior for ZI_BLG_INSPECTIONPLANTP alias InspectionPlan
// persistent table ZBLG_T_INSP_TSP
draft table zblg_d_insp_tsp
with unmanaged save
lock master
total etag LastChangeDateTime
authorization master ( instance )
etag master LocalLastChangedDateTime
{
field ( readonly, numbering : managed ) InspectionPlanUUID;
field ( readonly ) InspectionPlanId;
field ( mandatory ) InspectionPlanName, InspectionPlanStartdate, InspectionPlanEnddate;
create;
update;
delete;
association _InspectionPlanChecks { create; with draft; }
determination setInspectionPlanID on save { create; }
draft action Edit;
draft action Activate;
draft action Discard;
draft action Resume;
draft determine action Prepare;
mapping for zblg_t_insp_tsp control ZBLG_X_INSP_TSP corresponding
{
InspectionPlanUUID = uuid;
InspectionPlanId = id;
InspectionPlanName = name;
InspectionPlanStartdate = startdate;
InspectionPlanEnddate = enddate;
InspectionPlanText = text;
Purchasinggroup = purchasinggroup;
MaterialGroup = materialgroup;
DueDate = duedate;
InspectionPlanIsdeleted = isdeleted;
}
}
define behavior for ZI_BLG_INSPECTIONPLANCHECKSTP alias InspectionPlanChecks
persistent table zblg_t_insp_chks
draft table zblg_d_insp_chks
lock dependent by _InspectionPlan
authorization dependent by _InspectionPlan
etag dependent by _InspectionPlan
{
field ( readonly, numbering : managed ) InspectionPlanCheckUUID;
field ( readonly ) InspectionPlanUUID;
update;
delete;
association _InspectionPlan { with draft; }
mapping for ZBLG_T_INSP_CHKS corresponding
{
InspectionPlanCheckUUID = uuid;
InspectionPlanUUID = inspection_uuid;
QCategory = q_category;
InspectionPlanCheckText = text;
InspectionPlanCheckEnabled = enabled;
}
}
CLASS lsc_zi_blg_inspectionplantp DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.
METHODS save_modified REDEFINITION.
ENDCLASS.
CLASS lsc_zi_blg_inspectionplantp IMPLEMENTATION.
METHOD save_modified.
"Data Declaration
DATA : lt_inspectionplan TYPE STANDARD TABLE OF zblg_t_insp_tsp.
DATA : lr_inspectionplan_uuid TYPE RANGE OF zblg_t_insp_tsp-uuid.
DATA : lt_inspectionplan_controlflag TYPE STANDARD TABLE OF zblg_x_insp_tsp.
DATA : lt_inspectionplan_upd TYPE STANDARD TABLE OF zblg_t_insp_tsp.
"Implement Logic for all possible Save Operations - Create / Update / Delete
IF create IS NOT INITIAL.
"Populate the values
lt_inspectionplan = CORRESPONDING #( create-inspectionplan MAPPING FROM ENTITY ).
"Insert record into DB
INSERT zblg_t_insp_tsp FROM TABLE lt_inspectionplan.
ENDIF.
IF update IS NOT INITIAL.
"Populate the values
lt_inspectionplan_upd = CORRESPONDING #( update-inspectionplan MAPPING FROM ENTITY ).
lt_inspectionplan_controlflag = CORRESPONDING #( update-inspectionplan MAPPING FROM ENTITY USING CONTROL ).
"Fill range value for all the updated Inspections
lr_inspectionplan_uuid = VALUE #( FOR ls_inspectionplan_u IN update-inspectionplan
( sign = 'I' option = 'EQ' low = ls_inspectionplan_u-inspectionplanuuid )
).
IF lr_inspectionplan_uuid IS NOT INITIAL.
"Get Old DB Values
SELECT *
FROM zblg_t_insp_tsp
INTO TABLE @DATA(lt_inspectionplan_old)
WHERE uuid IN @lr_inspectionplan_uuid.
ENDIF.
"Prepare DB Table to update
lt_inspectionplan = VALUE #(
FOR x = 1 WHILE x <= lines( lt_inspectionplan_upd )
LET
ls_controlflag = VALUE #( lt_inspectionplan_controlflag[ x ] OPTIONAL )
ls_inspectionplan_upd = VALUE #( lt_inspectionplan_upd[ x ] OPTIONAL )
ls_inspectionplan_old = VALUE #( lt_inspectionplan_old[ uuid = ls_inspectionplan_upd-uuid ] OPTIONAL )
IN
(
"Do not update cannonical, semantical keys, administrative fields
uuid = ls_inspectionplan_old-uuid
id = ls_inspectionplan_old-id
createdbyuser = ls_inspectionplan_old-createdbyuser
creationdatetime = ls_inspectionplan_old-creationdatetime
"Update other columns, if found controlflag as X - else pass DB values
name = COND #( WHEN ls_controlflag-name IS NOT INITIAL THEN ls_inspectionplan_upd-name ELSE ls_inspectionplan_old-name )
startdate = COND #( WHEN ls_controlflag-startdate IS NOT INITIAL THEN ls_inspectionplan_upd-startdate ELSE ls_inspectionplan_old-startdate )
enddate = COND #( WHEN ls_controlflag-enddate IS NOT INITIAL THEN ls_inspectionplan_upd-enddate ELSE ls_inspectionplan_old-enddate )
text = COND #( WHEN ls_controlflag-text IS NOT INITIAL THEN ls_inspectionplan_upd-text ELSE ls_inspectionplan_old-text )
materialgroup = COND #( WHEN ls_controlflag-materialgroup IS NOT INITIAL THEN ls_inspectionplan_upd-materialgroup ELSE ls_inspectionplan_old-materialgroup )
duedate = COND #( WHEN ls_controlflag-duedate IS NOT INITIAL THEN ls_inspectionplan_upd-duedate ELSE ls_inspectionplan_old-duedate )
lastchangedatetime = COND #( WHEN ls_controlflag-lastchangedatetime IS NOT INITIAL THEN ls_inspectionplan_upd-lastchangedatetime ELSE ls_inspectionplan_old-lastchangedatetime )
lastchangedbyuser = COND #( WHEN ls_controlflag-lastchangedbyuser IS NOT INITIAL THEN ls_inspectionplan_upd-lastchangedbyuser ELSE ls_inspectionplan_old-lastchangedbyuser )
lastchangedat = COND #( WHEN ls_controlflag-lastchangedat IS NOT INITIAL THEN ls_inspectionplan_upd-lastchangedat ELSE ls_inspectionplan_old-lastchangedat )
)
).
"Update DB table
MODIFY zblg_t_insp_tsp FROM TABLE lt_inspectionplan.
ENDIF.
IF delete IS NOT INITIAL.
"Fill range value for all the deleted Inspections
lr_inspectionplan_uuid = VALUE #( FOR ls_inspectionplan_d IN delete-inspectionplan
( sign = 'I' option = 'EQ' low = ls_inspectionplan_d-inspectionplanuuid )
).
IF lr_inspectionplan_uuid IS NOT INITIAL.
"Delete the record from DB
DELETE FROM zblg_t_insp_tsp WHERE uuid IN lr_inspectionplan_uuid.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS lhc_InspectionPlan DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR InspectionPlan RESULT result.
METHODS setinspectionplanid FOR DETERMINE ON SAVE
IMPORTING keys FOR inspectionplan~setinspectionplanid.
ENDCLASS.
CLASS lhc_InspectionPlan IMPLEMENTATION.
METHOD get_instance_authorizations.
ENDMETHOD.
METHOD setInspectionPlanID.
"
DATA : lv_inspectionplanid TYPE zblg_t_insp_tsp-id.
"For external Scenario
READ ENTITIES OF ZI_BLG_InspectionPlanTP
IN LOCAL MODE
ENTITY InspectionPlan
FIELDS ( InspectionPlanId ) WITH CORRESPONDING #( keys )
RESULT DATA(lt_inspectionplan)
FAILED DATA(lt_failed).
"Do not generate Id, if already provided
IF lt_inspectionplan[ 1 ]-InspectionPlanId IS NOT INITIAL.
RETURN.
ENDIF.
"Get new number from number range
TRY.
cl_numberrange_runtime=>number_get(
EXPORTING
nr_range_nr = '01'
object = 'ZBLG_INSP'
quantity = '1'
IMPORTING
number = DATA(lv_nr_number) ).
CATCH cx_number_ranges INTO DATA(lx_number_ranges). " TODO: variable is assigned but never used (AbapCleaner)
" exit
ENDTRY.
UNPACK lv_nr_number TO lv_inspectionplanid.
LOOP AT lt_inspectionplan INTO DATA(ls_inspectionplan).
MODIFY ENTITIES OF ZI_BLG_InspectionPlanTP IN LOCAL MODE
ENTITY InspectionPlan
UPDATE
FIELDS ( InspectionPlanId )
WITH VALUE #( ( %tky = ls_inspectionplan-%tky
InspectionPlanId = lv_inspectionplanid ) )
REPORTED DATA(lt_update_reported).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |