Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BDC for PU01 Mass Payroll Deletion using Pernr(Personnel Number) in PRD System

Former Member
0 Kudos

Hi Experts,

I have a requirement where I need mass deletion of HR payroll in PRD. Since tcode PU01 is used for single payroll entries i generated a BDC to delete using range of Personnel Number in the DEV system. But when I run the BDC in background it stop at the screen 0120 in the BDC recorded steps.

REPORT zbdc_sh_pu01_prg

        NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES: pa0001.

INCLUDE zbdcrecx.

*DATA: r_pu01_tbl TYPE RANGE OF pa0001-pernr,  "range table

*      wa_pu01_tbl LIKE LINE OF r_pu01_tbl.     "work area for range table

DATA: it_pa0001 TYPE TABLE OF pa0001,

       wa_pa0001 LIKE LINE OF it_pa0001.

SELECT-OPTIONS pernr FOR pa0001-pernr.

START-OF-SELECTION.

   SELECT * FROM pa0001 INTO CORRESPONDING FIELDS OF TABLE it_pa0001 WHERE pernr IN pernr.

*  PERFORM open_group.

*

   LOOP AT it_pa0001 INTO wa_pa0001.

     PERFORM bdc_dynpro      USING 'RPCDPU01' '1000'.

     PERFORM bdc_field       USING 'BDC_CURSOR'

                                   'RP50G-PERNR'.

     PERFORM bdc_field       USING 'BDC_OKCODE'

                                   '=STAR'.

     PERFORM bdc_field       USING 'RP50G-PERNR'

                                   wa_pa0001-pernr.

     perform bdc_dynpro      using 'SAPMSSY0' '0120'.

     perform bdc_field       using 'BDC_OKCODE'

                                   '=DELE'.

     perform bdc_dynpro      using 'SAPLSPO1' '0300'.

     perform bdc_field       using 'BDC_OKCODE'

                               '=YES'.

     PERFORM bdc_transaction USING 'PU01'.

   ENDLOOP.

*  PERFORM close_group.






This is my INCLUDE ZBDCRECX code

In this I have commented those fields that are not needed:

****INCLUDE BDCRECX1.

*  for programs doing a data transfer by creating a batch-input session

*  and

*  for programs doing a data transfer by CALL TRANSACTION USING

*

*SELECTION-SCREEN BEGIN OF LINE.

*  PARAMETERS SESSION RADIOBUTTON GROUP CTU.  "create session

*  SELECTION-SCREEN COMMENT 3(20) TEXT-S07 FOR FIELD SESSION.

*  selection-screen position 45.

*  PARAMETERS CTU RADIOBUTTON GROUP  CTU.     "call transaction

*  SELECTION-SCREEN COMMENT 48(20) TEXT-S08 FOR FIELD CTU.

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 3(20) TEXT-S01 FOR FIELD GROUP.

*  selection-screen position 25.

*  PARAMETERS GROUP(12).                      "group name of session

*  SELECTION-SCREEN COMMENT 48(20) TEXT-S05 FOR FIELD CTUMODE.

*  selection-screen position 70.

*  PARAMETERS CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.

*                                      "A: show all dynpros

*                                      "E: show dynpro on error only

*                                      "N: do not display dynpro

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 3(20) TEXT-S02 FOR FIELD USER.

*  selection-screen position 25.

*  PARAMETERS: USER(12) DEFAULT SY-UNAME.     "user for session in batch

*  SELECTION-SCREEN COMMENT 48(20) TEXT-S06 FOR FIELD CUPDATE.

*  selection-screen position 70.

*  PARAMETERS CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'L'.

*                                      "S: synchronously

*                                      "A: asynchronously

*                                      "L: local

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 3(20) TEXT-S03 FOR FIELD KEEP.

*  selection-screen position 25.

*  PARAMETERS: KEEP AS CHECKBOX.       "' ' = delete session if finished

*                                      "'X' = keep   session if finished

*  SELECTION-SCREEN COMMENT 48(20) TEXT-S09 FOR FIELD E_GROUP.

*  selection-screen position 70.

*  parameters E_GROUP(12).             "group name of error-session

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 3(20) TEXT-S04 FOR FIELD HOLDDATE.

*  selection-screen position 25.

*  PARAMETERS: HOLDDATE LIKE SY-DATUM.

*  SELECTION-SCREEN COMMENT 51(17) TEXT-S02 FOR FIELD E_USER.

*  selection-screen position 70.

*  PARAMETERS: E_USER(12) DEFAULT SY-UNAME.    "user for error-session

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 51(17) TEXT-S03 FOR FIELD E_KEEP.

*  selection-screen position 70.

*  PARAMETERS: E_KEEP AS CHECKBOX.     "' ' = delete session if finished

*                                      "'X' = keep   session if finished

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 51(17) TEXT-S04 FOR FIELD E_HDATE.

*  selection-screen position 70.

*  PARAMETERS: E_HDATE LIKE SY-DATUM.

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN SKIP.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 1(33) TEXT-S10 FOR FIELD NODATA.

*  PARAMETERS: NODATA DEFAULT '/' LOWER CASE.          "nodata

*SELECTION-SCREEN END OF LINE.

*

*SELECTION-SCREEN BEGIN OF LINE.

*  SELECTION-SCREEN COMMENT 1(33) TEXT-S11 FOR FIELD SMALLLOG.

*  PARAMETERS: SMALLLOG as checkbox.  "' ' = log all transactions

*                                     "'X' = no transaction logging

*SELECTION-SCREEN END OF LINE.

*----------------------------------------------------------------------*

*   data definition

*----------------------------------------------------------------------*

*       Batchinputdata of single transaction

DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.

*       messages of call transaction

DATA:   MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

*       error session opened (' ' or 'X')

DATA:   E_GROUP_OPENED.

*       message texts

TABLES: T100.

*----------------------------------------------------------------------*

*   at selection screen                                                *

*----------------------------------------------------------------------*

AT SELECTION-SCREEN.

* group and user must be filled for create session

*  IF SESSION = 'X' AND

*     GROUP = SPACE OR USER = SPACE.

*    MESSAGE E613(MS).

*  ENDIF.

*----------------------------------------------------------------------*

*   open dataset                                                       *

*----------------------------------------------------------------------*

FORM OPEN_DATASET USING P_DATASET.

   OPEN DATASET P_DATASET

                FOR INPUT IN TEXT MODE

                ENCODING DEFAULT.

   IF SY-SUBRC <> 0.

     WRITE: / TEXT-E00, SY-SUBRC.

     STOP.

   ENDIF.

ENDFORM.

*----------------------------------------------------------------------*

*   close dataset                                                      *

*----------------------------------------------------------------------*

FORM CLOSE_DATASET USING P_DATASET.

   CLOSE DATASET P_DATASET.

ENDFORM.

*----------------------------------------------------------------------*

*   create batchinput session                                          *

*   (not for call transaction using...)                                *

*----------------------------------------------------------------------*

FORM OPEN_GROUP.

*  IF SESSION = 'X'.

*    SKIP.

*    WRITE: /(20) 'Create group'(I01), GROUP.

*    SKIP.

**   open batchinput group

*    CALL FUNCTION 'BDC_OPEN_GROUP'

*         EXPORTING  CLIENT   = SY-MANDT

*                    GROUP    = GROUP

*                    USER     = USER

*                    KEEP     = KEEP

*                    HOLDDATE = HOLDDATE.

*    WRITE: /(30) 'BDC_OPEN_GROUP'(I02),

*            (12) 'returncode:'(I05),

*                 SY-SUBRC.

*  ENDIF.

ENDFORM.

*----------------------------------------------------------------------*

*   end batchinput session                                             *

*   (call transaction using...: error session)                         *

*----------------------------------------------------------------------*

FORM CLOSE_GROUP.

*  IF SESSION = 'X'.

**   close batchinput group

*    CALL FUNCTION 'BDC_CLOSE_GROUP'.

*    WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),

*            (12) 'returncode:'(I05),

*                 SY-SUBRC.

*  ELSE.

*    IF E_GROUP_OPENED = 'X'.

*      CALL FUNCTION 'BDC_CLOSE_GROUP'.

*      WRITE: /.

*      WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).

*      E_GROUP_OPENED = ' '.

*    ENDIF.

*  ENDIF.

ENDFORM.

*----------------------------------------------------------------------*

*        Start new transaction according to parameters                 *

*----------------------------------------------------------------------*

FORM BDC_TRANSACTION USING TCODE.

   DATA: L_MSTRING(480).

   DATA: L_SUBRC LIKE SY-SUBRC.

* batch input session

*  IF SESSION = 'X'.

*    CALL FUNCTION 'BDC_INSERT'

*         EXPORTING TCODE     = TCODE

*         TABLES    DYNPROTAB = BDCDATA.

*    IF SMALLLOG <> 'X'.

*      WRITE: / 'BDC_INSERT'(I03),

*               TCODE,

*               'returncode:'(I05),

*               SY-SUBRC,

*               'RECORD:',

*               SY-INDEX.

*    ENDIF.

** call transaction using

*  ELSE.

     REFRESH MESSTAB.

     CALL TRANSACTION TCODE USING BDCDATA

                      MODE   'N'             " CTUMODE   In Background

                      UPDATE 'A'         "CUPDATE

                      MESSAGES INTO MESSTAB.

     L_SUBRC = SY-SUBRC.

*    IF SMALLLOG <> 'X'.

       WRITE: / 'CALL_TRANSACTION',

                TCODE,

                'returncode:'(I05),

                L_SUBRC,

                'RECORD:',

                SY-INDEX.

       LOOP AT MESSTAB.

         MESSAGE ID     MESSTAB-MSGID

                 TYPE   MESSTAB-MSGTYP

                 NUMBER MESSTAB-MSGNR

                 INTO L_MSTRING

                 WITH MESSTAB-MSGV1

                      MESSTAB-MSGV2

                      MESSTAB-MSGV3

                      MESSTAB-MSGV4.

         WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).

       ENDLOOP.

       SKIP.

*    ENDIF.

** Erzeugen fehlermappe ************************************************

*    IF L_SUBRC <> 0 AND E_GROUP <> SPACE.

*      IF E_GROUP_OPENED = ' '.

*        CALL FUNCTION 'BDC_OPEN_GROUP'

*             EXPORTING  CLIENT   = SY-MANDT

*                        GROUP    = E_GROUP

*                        USER     = E_USER

*                        KEEP     = E_KEEP

*                        HOLDDATE = E_HDATE.

*         E_GROUP_OPENED = 'X'.

*      ENDIF.

*      CALL FUNCTION 'BDC_INSERT'

*           EXPORTING TCODE     = TCODE

*           TABLES    DYNPROTAB = BDCDATA.

*    ENDIF.

*  ENDIF.

   REFRESH BDCDATA.

ENDFORM.

*----------------------------------------------------------------------*

*        Start new screen                                              *

*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

   CLEAR BDCDATA.

   BDCDATA-PROGRAM  = PROGRAM.

   BDCDATA-DYNPRO   = DYNPRO.

   BDCDATA-DYNBEGIN = 'X'.

   APPEND BDCDATA.

ENDFORM.

*----------------------------------------------------------------------*

*        Insert field                                                  *

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAM FVAL.

*  IF FVAL <> NODATA.

     CLEAR BDCDATA.

     BDCDATA-FNAM = FNAM.

     BDCDATA-FVAL = FVAL.

   SHIFT bdcdata-fval LEFT DELETING LEADING space.

     APPEND BDCDATA.

*  ENDIF.

ENDFORM.

12 REPLIES 12

nabheetscn
Active Contributor
0 Kudos

Hi Shubharaj

First of all you can add your whole code as attachment rather than pasting it in thread. Seconldy did you try to execute this stuff in A mode and check yourself what is the issue. Compare your BDCDATA internal table with sucessfully recorded BDC in SHDB.

Nabheet

0 Kudos

Hi Nabheet,

Yeah I will do that next time. I checked the BDCDATA internal table there is no fault in it and I executed it  A mode to check if the recording step were proper in BDC .  Check the image below the image where the BDC program stops                                 And the screen below is the actual tcode PU01.Please check how the table entries are displayed in the two screen shots

                                Please advice.

Regards,

Shubharaj.

0 Kudos

Hi Shubharaj

You have a ALV/List display right. Basically having a BDC on it is bit tricky. Please make another recording and check the checkbox simulate background.

I would have preferred to copy the logic of RPCDPU01(PU01 tcode) how it delete at the place shown below and use in my report.

Nabheet

0 Kudos

Hi Nabheet,

Thanks for the screen shot i will try this and provide you with the feedback asap.

Regards,

Shubharaj.

thangam_perumal
Contributor
0 Kudos

Hi Shubharaj,

                      why not you tried LSMW .. it wiil be easy compare than BDC.

0 Kudos

Hi Thangam,

I didnt try LSMW as BDC was simpler I have read threads on this same discussion in that they have mentioned both LSMW and BDC doesnt works but I will try and provide feedback.

Regards

Shubharaj.

former_member227140
Active Participant
0 Kudos

hey i think we can use HR_INFOTYPE_OPERATION as well with delete operation. this FM updates as well as deletes records .

just check in case if you are not getting any success with LSMW or BDC.

0 Kudos

Hi Abhijeet,

I tried that, it has too many fields that are needed to be entered, I just want only pernr, fpend and fpbeg fields.

Regards,

Shubharaj

0 Kudos

Check this sample code this needs only pernr , begda , endda and record as input.

select pernr subty begda endda usrid_long

     from pa0105

      into table it_pa0105

       where pernr = '00001451'

         and subty = '0010'

          and begda ge '19000101'

           and endda le '20080503'.

if sy-subrc eq 0.

loop at it_pa0105.

CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'

  EXPORTING

    NUMBER        =  it_pa0105-pernr.

CALL FUNCTION 'HR_INFOTYPE_OPERATION'

  EXPORTING

    INFTY                      = '0105'

    NUMBER                 = it_pa0105-pernr

   SUBTYPE                 = it_pa0105-subty

   VALIDITYEND            = it_pa0105-endda

   VALIDITYBEGIN         = it_pa0105-begda

    RECORD                   = P0105

    OPERATION              = 'DEL'

   TCLAS                        = 'A'

   DIALOG_MODE            = '0'

IMPORTING

   RETURN                 =  return.

  •   KEY                    =

          .

if return is INITIAL.

'deleted successfully'.

ENDIF.

CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'

  EXPORTING

    NUMBER        = it_pa0105-pernr.

endloop.

endif.

0 Kudos

Hi Abhi,

I would like to clarify a few things in this above sample code.

what is the value should be passed to record in FM HR_INFOTYPE_OPERATION..?

and the return.??

Please help.


Regards,

Shubharaj.

0 Kudos

i dont have system here , please execute this in se37 and check..look for some sample codes here on scn . you will find the answer. but i will advice to first try to do it through se37 and if it works for you . use it in your data transfer program.

0 Kudos

Hi Abhi

Ok I will try and provide feedback..

Regards

Shubharaj.