Skip to Content
0

How to upload multiple WBS for infotype 0027 from excel

Apr 20 at 04:03 PM

32

avatar image
Former Member
INCLUDE ZHR_PA0027_UPLOAD_TOP.

INCLUDE ZHR_PA0027_UPLOAD_FORM.

START-OF-SELECTION.
*  Initializing the class
  DATA : obj TYPE REF TO  lcl_upload.

  AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

create OBJECT obj.



*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.



call METHOD obj->file_upload.


 


*&---------------------------------------------------------------------*

*& Include          ZHR_PA0027_UPLOAD_TOP

*&---------------------------------------------------------------------*

* Internal tables declarations

TYPES : BEGIN OF ty_pa0027,

        pernr TYPE p0027-pernr,

        begda TYPE char10,

        endda TYPE char10,

        kbu01 TYPE p0027-kbu01,

        kst01 TYPE p0027-kst01,

        psp01 TYPE p0027-psp01,

        kpr01 TYPE p0027-kpr01,

        END OF ty_pa0027.

DATA : it_p0027 TYPE STANDARD TABLE OF ty_pa0027.

data: itab TYPE STANDARD TABLE OF  alsmex_tabline,

       wa_itab LIKE LINE OF itab.



* Work area declarations

DATA : wa_p0027 TYPE ty_pa0027.

DATA : p0027 TYPE p0027.

* Parameters declaration

PARAMETERS : P_FILE TYPE rlgrap-filename.

* Local date declarations

DATA : l_date1 TYPE sy-datum,

       l_date2 TYPE sy-datum,

       l_psp01 TYPE p0027-psp01.


*&---------------------------------------------------------------------*

*& Include          ZHR_PA0027_UPLOAD_FORM

*&---------------------------------------------------------------------*

*======================================================================*

*              L O C A L  C L A S S  D E F I N I T I O N               *

*======================================================================*

CLASS lcl_upload DEFINITION.

  PUBLIC SECTION.

    METHODS : file_upload.



ENDCLASS.



*======================================================================*

*              L O C A L  C L A S S  IMPLEMENTATION               *

*======================================================================*



CLASS lcl_upload IMPLEMENTATION.



METHOD file_upload.

*  AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

" F4 help for file.

  CALL FUNCTION 'F4_FILENAME'

* EXPORTING

*   PROGRAM_NAME        = SYST-CPROG

*   DYNPRO_NUMBER       = SYST-DYNNR

*   FIELD_NAME          = ' '

   IMPORTING

     file_name           =  p_file.



call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

       exporting

            filename                = p_file

            i_begin_col             = '1'

            i_begin_row             = '2'  "Do not require headings

            i_end_col               = '14'

            i_end_row               = '31'

       tables

            intern                  = itab

       exceptions

            inconsistent_parameters = 1

            upload_ole              = 2

            others                  = 3.

  if sy-subrc <> 0.

    message e010(zz) with text-001. "Problem uploading Excel Spreadsheet

  endif.



  LOOP AT itab INTO wa_itab.

  CASE wa_itab-col.

WHEN '1'.

wa_p0027-pernr = wa_itab-value.



WHEN '2'.

wa_p0027-begda = wa_itab-value.





 WHEN '3'.

wa_p0027-endda = wa_itab-value.





 WHEN '4'.

wa_p0027-kbu01 = wa_itab-value.



 WHEN '5'.

wa_p0027-kst01 = wa_itab-value.



 WHEN '6'.

* Converting external WBS element into internal WBS element



CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'

  EXPORTING

    input           = wa_itab-value

 IMPORTING

   OUTPUT          = l_psp01

* EXCEPTIONS

*   NOT_FOUND       = 1

*   OTHERS          = 2

          .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

* Passing the converted WBS element to the work area

wa_p0027-psp01 = l_psp01.



 WHEN '7'.

wa_p0027-kpr01 = wa_itab-value.

 ENDCASE.

AT END OF row.

 APPEND wa_p0027 to it_p0027.

 CLEAR wa_p0027.

 ENDAT.

 ENDLOOP.



  LOOP AT IT_p0027 INTO wa_p0027.



* Converting  begin date to internal format



    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'



EXPORTING



date_external = wa_p0027-begda



IMPORTING



DATE_INTERNAL = l_date1



EXCEPTIONS



DATE_EXTERNAL_IS_INVALID = 1



OTHERS = 2.



IF sy-subrc <> 0.



MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO



WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.



ENDIF.



*  Converting  end date to internal format





    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'



EXPORTING



date_external = wa_p0027-endda



IMPORTING



DATE_INTERNAL = l_date2



EXCEPTIONS



DATE_EXTERNAL_IS_INVALID = 1



OTHERS = 2.



IF sy-subrc <> 0.



MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO



WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.



ENDIF.



** Converting external WBS element into internal WBS element

*

*CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'

*  EXPORTING

*    input           = wa_p0027-psp01

* IMPORTING

*   OUTPUT          = l_psp01

** EXCEPTIONS

**   NOT_FOUND       = 1

**   OTHERS          = 2

*          .

*IF sy-subrc <> 0.

** Implement suitable error handling here

*ENDIF.







    CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'

      EXPORTING

        NUMBER        = wa_P0027-PERNR

*   IMPORTING

*     RETURN        =

              .



*    MOVE-CORRESPONDING WA_p0027 TO P0027.

p0027-pernr = wa_p0027-pernr.

p0027-begda = l_date1.

p0027-endda = l_date2.

p0027-kbu01 = wa_p0027-kbu01.

p0027-psp01 = wa_p0027-psp01.

p0027-kst01 = wa_p0027-kst01.

p0027-kpr01 = wa_p0027-kpr01.



    CALL FUNCTION 'HR_INFOTYPE_OPERATION'

      EXPORTING

        INFTY                  = '0027'

        NUMBER                 = wa_p0027-PERNR

       SUBTYPE                = '01'

*   OBJECTID               =

*   LOCKINDICATOR          =

       VALIDITYEND            = l_date2

       VALIDITYBEGIN          = l_date1

*   RECORDNUMBER           =

        RECORD                 = P0027

        OPERATION              = 'INS'

       TCLAS                  = 'A'

       DIALOG_MODE            = '2'

*   NOCOMMIT               =

*   VIEW_IDENTIFIER        =

*   SECONDARY_RECORD       =

* IMPORTING

*   RETURN                 =

*   KEY                    =

              .





    CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'

      EXPORTING

        NUMBER        = wa_p0027-PERNR.

* IMPORTING

*   RETURN        =



           .



  ENDLOOP.







 ENDMETHOD.

 ENDCLASS.

Hi friends,

I have written code for uploading PA0027 . It is working perfectly when there i am taking only one WBS element for one employee id. But, i am unable to write the code, when i need to upload multiple WBS elements for a single pernr. Please provide tips on how to write the code. I can't use BDC .

Regards,

Saurav Lahiry

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Raymond Giuseppi Apr 23 at 07:51 AM
0

Read first the whole data in an internal table, sorted by pernr.

Then loop at the itab, and fill your Infotype 0027 work area filling fields PSP01, PSP02... for a single value of pernr/dates with some AT NEW/AT END OF statements and a simple counter. Reset the counter in AT NEW bloc , move fields outside of the blocks, call the HR_INFOTYPE_OPERATION in the AT END OF block...

Share
10 |10000 characters needed characters left characters exceeded