500 Internal Server Error when saving SAP PLM project

created at 02-10-2022 views: 13

problem

  • ST22 gets the error message as DBSQL_DUPLICATE_KEY_ERROR
  • WebDynpro component involved: FPM_OIF_COMPONENT

Solution

  • Create a custom program: Z_PROJECT_GUID
  • Run the program to input Project Code correction
*&---------------------------------------------------------------------*
*& Report Z_PROJECT_GUID        Z_CORRECT_PD_PROJECT_GUID
*&---------------------------------------------------------------------*
*&  Please check with author of this report
*&  This report changes project_guid of header according it's tasks for
*&  the case, that ALL tasks have same project_guid. !!!
*&  Depends on situation, other way around is also possible.
*&---------------------------------------------------------------------*
REPORT Z_PROJECT_GUID.
*
DATA: lv_num_dpr         TYPE sy-tabix,

      lv_num_proj        TYPE sy-tabix,
      lv_proj_guid       LIKE dpr_project-guid,
      lv_s4_task_project LIKE dpr_project-guid.
DATA: ls_s4_project LIKE /s4ppm/project,
      ls_s4_pd_task LIKE /s4ppm/task.

DATA: lt_hier_proj  LIKE cgpl_hierarchy OCCURS 0 WITH HEADER LINE,
      lt_hier_task  LIKE cgpl_hierarchy  OCCURS 0 WITH HEADER LINE,
      lt_cgpl_nodes LIKE cgpl_hierarchy OCCURS 0 WITH HEADER LINE,
      lt_s4_task    LIKE /s4ppm/task OCCURS 0 WITH HEADER LINE.
*      lt_dpr_task   LIKE dpr_task OCCURS 0 WITH HEADER LINE.



PARAMETERS: proj_id LIKE dpr_project-project_id,
            test    TYPE c AS CHECKBOX DEFAULT 'X'.

SELECT SINGLE guid INTO lv_proj_guid FROM dpr_project WHERE project_id = proj_id AND
                                                        version_number EQ space.
IF NOT sy-subrc IS INITIAL.
  WRITE 'Project ID not found.'.  EXIT.
ENDIF.

SELECT SINGLE * FROM /s4ppm/task INTO ls_s4_pd_task WHERE guid =  lv_proj_guid.
IF NOT sy-subrc IS INITIAL.
  WRITE 'Project ID not found.'.  EXIT.
ENDIF.

SELECT * FROM cgpl_hierarchy INTO TABLE lt_hier_proj WHERE up = lv_proj_guid.

* We donot need project guid to retrieve the dpr_part, which is irrelevant for s4ppm.
* SELECT * FROM cgpl_hierarchy APPENDING TABLE   lt_hier_proj WHERE guid = lv_proj_guid.

IF lt_hier_proj[] IS INITIAL.
  WRITE 'Exception case, contact SAP.'.  EXIT.
ELSE.
  SELECT * FROM cgpl_hierarchy INTO TABLE lt_hier_task
    FOR ALL ENTRIES IN lt_hier_proj WHERE project_guid = lt_hier_proj-guid.
ENDIF.

* we have now guids of  DPR phases + tasks in lt_cgpl_nodes.
APPEND LINES OF lt_hier_task TO lt_cgpl_nodes.
APPEND LINES OF lt_hier_proj TO lt_cgpl_nodes.


SELECT * FROM /s4ppm/task
  INTO TABLE lt_s4_task
  FOR ALL ENTRIES IN lt_cgpl_nodes
  WHERE guid = lt_cgpl_nodes-guid.

SORT lt_s4_task BY project_guid.
DELETE ADJACENT DUPLICATES FROM lt_s4_task COMPARING project_guid .

DESCRIBE TABLE lt_s4_task LINES lv_num_proj.

* Do all other tasks have the same project_guid.
IF lv_num_proj NE 1.
  WRITE 'unexpected siutation for this report'.
  EXIT.
ENDIF.

READ TABLE lt_s4_task INDEX 1.

* is to be used project_guid valid?
SELECT SINGLE * FROM /s4ppm/project INTO ls_s4_project
  WHERE guid = lt_s4_task-project_guid.
IF NOT  sy-subrc IS INITIAL.
  WRITE 'unexpected siutation for this report'.
  EXIT.
ENDIF.

IF ls_s4_pd_task-project_guid  NE lt_s4_task-project_guid.
  IF NOT test IS INITIAL.
    WRITE : 'Only root element has different project_guid as tasks. You can repair it'.
  ENDIF.
ELSE.
  WRITE: 'Root element and tasks have same project_guid, nothing to repair. '. EXIT.
ENDIF.

IF test IS  INITIAL.
  WRITE: 'Project_guid of Root object updated: old ',   ls_s4_pd_task-project_guid, '  new ',  lt_s4_task-project_guid.
  ls_s4_pd_task-project_guid = lt_s4_task-project_guid.
  MODIFY  /s4ppm/task FROM ls_s4_pd_task.

ENDIF.

unexpected siutation for this report exception handling:

An exception unexpected siutation for this report may be thrown when running Z_PROJECT_GUID:

exception

Debug found that the final deduplication data has one more line GUID = 0050568748021EEA97E95BCD6A7C3629:

deduplication

Lookup table: /S4PPM/TASK-PROJECT GUID = 0050568748021EEA97E95BCD6A7C3629 It is found that the Task of Phase3 is missing one item. The problem may be due to data misalignment resulting in a read error

Lookup table

According to the increasing rules of GUID, TECHNICAL_ID, EXTERNAL_ID, etc., calculate the ID and add a piece of data, the abnormality is repaired, and the program runs normally as follows:

success

created at:02-10-2022
edited at: 02-10-2022: