Identify missing dependencies for Work Centers

Jimbo's picture

Wrong Tool for the JobWork Centers are one of the most complex objects that can be loaded using LSMW. The RCRAPDX2 program uses at least ten relational tables that end up knit together in order to form a single Work Center in SAP.

Typical best practices include identifying problems in the object before attempting to load. The problem may be in the source data or it may be the result of some deficiency in the system caused by a missing dependency or incorrect configuration. Work Centers have several dependencies that must be in the SAP system prior to a successful load.

A series of simple queries on a few tables in SAP is enough to identify most, if not all, issues to be resolved in order to load Work Centers. A short report enriched with this data can get the appropriate teams working with purpose.

Wrong Tool for the JobRather than perform a skip_transaction after every problem, a flag is set which will cause the failed transactions to be skipped later. Add this snippet of code to the GLOBAL_DATA area.

data: isDead(1) type c.

The isDead variable must be cleared at the beginning of each work center validation. Add this snippet to the BEGIN_OF_TRANSACTION area.

isDead = ''. 

The LSMW object is ready to start identifying issues and building the report. Add these snippets of ABAP code to the appropriate fields. The report is written as the LSMW code is executed.

 
translate CR01H-ARBPL to UPPER CASE.
select single ARBPL from CRHD into CRHD_DXI01-ARBPL
  where ARBPL eq CR01H-ARBPL and WERKS eq CR01H-WERKS.
if sy-subrc eq 0 and p_update ne 'X'.
  write: / CR01H-ARBPL, 'has already been created.'.
  isDead = 'X'.
else.
  CRHD_DXI01-ARBPL = CR01H-ARBPL.
endif.
CRHD_DXI02-VERAN = CR01B-VERAN.
select single VERAN from TC24 into CRHD_DXI02-VERAN
 where VERAN eq CR01B-VERAN and WERKS eq CR01H-WERKS.
if sy-subrc ne 0.
  write: / CR01H-ARBPL, CR01H-WERKS, CR01B-VERAN,
   'Invalid responsible person (VERAN).' color 6.
  isDead = 'X'.
endif.
select single PRVBE from PVBE into CRHD_DXI02-PRVBE
 where PRVBE eq CR01B-PRVBE and WERKS eq CR01H-WERKS.
if sy-subrc ne 0 and CR01B-PRVBE ne ''. "Missing Supply area
  write: / CR01H-ARBPL, CR01H-WERKS, CR01B-PRVBE,
   'Invalid Supply Area (PRVBE).' color col_negative.
  isDead = 'X'.
endif.
shift CR01CS-KOSTL right deleting trailing space.
overlay CR01CS-KOSTL with '0000000000'.
select single KOSTL from CSKS into CRCO_DXI01-KOSTL
 where KOSTL eq CR01CS-KOSTL.
if sy-subrc ne 0.
  write: / CR01H-ARBPL, CR01H-WERKS, CR01CS-KOSTL,
   'Cost Center does not exist.' color col_negative.
  isDead = 'X'.
endif.

The following snippet must be repeated three times for each of the Activity Types. The snippet checks for the existence of all three of the Activity Type, but only reports and fails the transaction when the activity type is referenced.

select single LSTAR from CSSL into CRCO_DXI01-LSTAR1
 where LSTAR eq CR01CS-LSTAR1 and KOSTL eq  CR01CS-KOSTL.
if sy-subrc ne 0 and CR01CS-LSTAR_REF1 eq 'X'. "Not found!!!
  write: / CR01H-ARBPL, CR01H-WERKS, CR01CS-KOSTL, CR01CS-LSTAR1,
   'Activity type does not exist in cost center.' color col_negative.
  isDead = 'X'.
endif.
select single LSTAR from CSSL into CRCO_DXI01-LSTAR2
 where LSTAR eq CR01CS-LSTAR2 and KOSTL eq  CR01CS-KOSTL.
if sy-subrc ne 0 and CR01CS-LSTAR_REF2 eq 'X'. "Not found!!!
  write: / CR01H-ARBPL, CR01H-WERKS, CR01CS-KOSTL, CR01CS-LSTAR2,
   'Activity type does not exist in cost center.' color col_negative.
  isDead = 'X'.
endif.
select single LSTAR from CSSL into CRCO_DXI01-LSTAR3
 where LSTAR eq CR01CS-LSTAR3 and KOSTL eq  CR01CS-KOSTL.
if sy-subrc ne 0 and CR01CS-LSTAR_REF3 eq 'X'. "Not found!!!
  write: / CR01H-ARBPL, CR01H-WERKS, CR01CS-KOSTL, CR01CS-LSTAR3,
   'Activity type does not exist in cost center.' color col_negative.
  isDead = 'X'.
endif.
select single PLANR from TC27 into KAPA_DXI02-PLANR
 where PLANR eq CR01CH-PLANR.
if sy-subrc ne 0.
  write: / CR01H-ARBPL, CR01H-WERKS, CR01cH-PLANR,
   'Missing Capacity Planner Group (PLANR)' color col_negative.
  isDead = 'X'.
endif.
translate CR01AC-SPROG to UPPER CASE.
select single SPROG from TC38A into KAZY_DXI01-SPROG
 where SPROG eq CR01AC-SPROG.
if sy-subrc ne 0 and CR01AC-SPROG ne ''. "Not found!
  write: / CR01H-ARBPL, CR01AC-SPROG, 'Missing shift sequence (SPROG).'.
  isDead = 'X'.
endif.

Finally, add this snippet to the END_OF_TRANSACTION rule. This causes the transaction for any failed Work Center to be skipped.

if isDead eq 'X'. skip_transaction. endif.
transfer_transaction.

Download the complete LSMW object.