Search help for PCHOBJID in PNP raport

February 3, 2010, SAP.


Lately I went through a problem in SAP HR program, HR-PA to be precise. I write an application, which uses PNP database, but one of its functionality uses organizational management, that means PCH usage. Generating selection screen fields from PCH application is quite easy. The problem shows off, when we want to add search help for object ID – common for PCH selection screen.
Pomoc wyszukiwania dla obiektu OBJID z ekranu selekji PCH


After quick googling the answer is found for instance in this post. In brief you have to use a macro called rhxmacro by adding these four lines:


At top of the report…

INCLUDE rhxmacro.


…in INITIALIZATION section…

rhx-f4-objid-data.


…and finally…

AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_obj_o-low.

rhx-f4-objid-low pchplvar pchotype so_obj_o ” ”.


Everything would be perfect, if only there wasn’t an error in rhxmacro, which causes the code not to compile (it’s SAP, indeed). Last change provided by SAP comes from March 2009 and it looks like someone started doing some corrections in the macro, but didn’t finish his work. Later on, this ‘correction’ went to users with one of the notes. The error, which makes macro not compiling is very common – to solve it you should delete one line of code, which tries to clear non-existing parameter (deleted during ‘correction’ of the macro).


So taking everything into account, to have beautiful search help you should create new client macro (unfortunatelly), which is a corrected (definietly) and shortend for our needs version of rhxmacro. Code below. Enjoy.
*INCLUDE ZRHXMACRO

DEFINE RHX-F4-OBJID-DATA.
TABLES PLOGI.
DATA : %F4_REPID LIKE SY-REPID.
DATA : %F4_DYNNR LIKE SY-DYNNR.
DATA : %F4_LINES TYPE I.
DATA : %F4_SUBRC LIKE SY-SUBRC. “XMK E-MSG
DATA : %F4_T77EO LIKE T77EO.    “XMK #431960
DATA : BEGIN OF %F4_MACO_TAB OCCURS 1,
PLVAR LIKE PLOG-PLVAR,
OTYPE LIKE PLOG-OTYPE,
OBJID LIKE OBJEC-REALO,
END   OF %F4_MACO_TAB.
DATA : %F4_PCHOBJID_LINES TYPE I.
DATA : %F4_PLVAR LIKE WPLOG-PLVAR.
DATA : %F4_OTYPE LIKE WPLOG-OTYPE.
DATA : %F4_OLD_OTYPE LIKE WPLOG-OTYPE.
DATA : %F4_SEL_OBJECTS    LIKE OBJEC   OCCURS 10 WITH HEADER LINE.
DATA : %F4_MARKED_OBJECTS LIKE HRSOBID OCCURS 10 WITH HEADER LINE.
END-OF-DEFINITION.

DEFINE RHX-F4-OBJID-LOW.

SET EXTENDED CHECK OFF.

%F4_REPID = SY-REPID.
%F4_DYNNR = SY-DYNNR.
DESCRIBE TABLE &3 LINES %F4_LINES.
IF &4 EQ SPACE.
PERFORM CHECK_PLVAR_F4(RHXCHK00) USING &1 %F4_SUBRC.
CHECK %F4_SUBRC = 0.
ENDIF.
IF &5 EQ SPACE.
IF &2 IS INITIAL.
CALL FUNCTION ‘ASK_OTYPE’
EXPORTING
D_OTYPE         = &2
IMPORTING
OTYPE           = &2
EXCEPTIONS
NO_OTYPE_SET    = 2
WRONG_OTYPE_SET = 4.
ENDIF.
ENDIF.
IF SY-DYNNR EQ ’1000′.
%F4_OLD_OTYPE = &2.
CLEAR:   %F4_MARKED_OBJECTS.
REFRESH: %F4_MARKED_OBJECTS.
%F4_MARKED_OBJECTS-PLVAR = &1.
%F4_MARKED_OBJECTS-OTYPE = &2.
CLEAR %F4_T77EO.
SELECT SINGLE * FROM T77EO INTO %F4_T77EO.
LOOP AT &3 WHERE SIGN = ‘I’.
CASE &3-OPTION.
WHEN ‘EQ’.
%F4_MARKED_OBJECTS-SOBID = &3-LOW.
APPEND %F4_MARKED_OBJECTS.
WHEN ‘BT’.
IF %F4_T77EO IS INITIAL.
SELECT * FROM PLOGI
WHERE OBJID >= &3-LOW  AND
OBJID <= &3-HIGH AND
OTYPE EQ &2      AND
PLVAR EQ &1.
%F4_MARKED_OBJECTS-SOBID = PLOGI-OBJID.
APPEND %F4_MARKED_OBJECTS.
ENDSELECT.
ENDIF.
ENDCASE.

ENDLOOP.
CALL FUNCTION ‘RH_OBJID_REQUEST’
EXPORTING
PLVAR             = &1
OTYPE             = &2
DYNPRO_REPID      = %F4_REPID
DYNPRO_DYNNR      = %F4_DYNNR
DYNPRO_PLVARFIELD = &4
DYNPRO_OTYPEFIELD = &5
SET_MODE          = ‘X’
IMPORTING
SEL_PLVAR         = %F4_PLVAR
SEL_OTYPE         = %F4_OTYPE
TABLES
SEL_OBJECTS       = %F4_SEL_OBJECTS
MARKED_OBJECTS    = %F4_MARKED_OBJECTS
EXCEPTIONS
CANCELLED         = 1
WRONG_CONDITION   = 2
NOTHING_FOUND     = 3
ILLEGAL_MODE      = 4
INTERNAL_ERROR    = 5
OTHERS            = 6.
IF &5 NE SPACE AND
%F4_OLD_OTYPE NE %F4_OTYPE.
REFRESH &3.
ENDIF.
IF SY-SUBRC EQ 0.
REFRESH: &3.
CLEAR:   &3.
LOOP AT %F4_SEL_OBJECTS.

&3-LOW    = %F4_SEL_OBJECTS-REALO.
&3-OPTION = ‘EQ’.
&3-SIGN = ‘I’.
APPEND &3.

ENDLOOP.
CLEAR:   %F4_SEL_OBJECTS.
REFRESH: %F4_SEL_OBJECTS.
else.                                             “Note1265523
clear: %f4_sel_objects, %f4_sel_objects[].
clear: %f4_marked_objects, %f4_marked_objects[].
clear: &3-low, &3[].
ENDIF.
ELSE.
PERFORM OBJID_REQUEST_PLVAR_OTYPE
USING SPACE &1   &2
%F4_REPID  %F4_DYNNR
SPACE      SPACE
%F4_PLVAR  %F4_OTYPE
&3-LOW.
IF &4 NE SPACE.
&1 = %F4_PLVAR.
ENDIF.
IF &5 NE SPACE.
&2 = %F4_OTYPE.
ENDIF.
EXIT.
ENDIF.
DESCRIBE TABLE &3 LINES %F4_PCHOBJID_LINES.
IF %F4_PCHOBJID_LINES GT %F4_LINES.
IF %F4_LINES EQ 0.
MESSAGE S026(PP).
ELSE.
MESSAGE S027(PP).
ENDIF.
ELSE.
ENDIF.
******CLEAR : SUBRC. <— this is the line we need to remove from original macro
READ TABLE &3 INDEX 1.
IF SY-SUBRC GT 0.
CLEAR &3.
ENDIF.
IF &4 NE SPACE.
&1 = %F4_PLVAR.
ENDIF.
IF &5 NE SPACE.
&2 = %F4_OTYPE.
ENDIF.
SET SCREEN SY-DYNNR.
LEAVE SCREEN.

SET EXTENDED CHECK ON.

END-OF-DEFINITION.


Anyway, that should be reported to SAP.

Komentarze