Skip to end of metadata
Go to start of metadata

List of all pages

Pages at first level

Author: Puneeta Parnami

Submitted: 23-July-2010

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
"Upload budget using Excel
REPORT  zuploadbudget.

"Excel sheet upload
TYPE-POOLS: truxs.

"Types Declaration
TYPES: BEGIN OF t_datatab2,
       wbslevel   TYPE n,
       wbs_element(100)    TYPE c,
       description(100)    TYPE c,
       blank  TYPE c,
       projecttype    TYPE c,
       priority    TYPE n,
       END OF t_datatab2.

TYPES : BEGIN OF t_datatab,
            col1(30)    TYPE c,
            col2(100)    TYPE c,
            col3(150)    TYPE c,
            col4(30)    TYPE c,
            col5(30)    TYPE c,
            col6(30)    TYPE c,
        END OF t_datatab.

"for excel filename
DATA :filename TYPE rlgrap-filename,
      fileupload TYPE rlgrap-filename.

"Data Declaration for function Module.
DATA :w_errors TYPE oax,
      it_bpak  TYPE  TABLE OF bpak,
      wa_bpak  TYPE bpak,
      it_ret   TYPE TABLE OF bapiret2,
      wa_ret   TYPE bapiret2.

DATA :  it_datatab TYPE STANDARD TABLE OF t_datatab,
       wa_datatab TYPE t_datatab,
       it_prps  TYPE STANDARD TABLE OF prps,
       wa_prps  TYPE prps,
       it_bpge TYPE TABLE OF bpge.

DATA : it_raw TYPE truxs_t_text_data.

"variable declartaion
DATA : v_num(8) TYPE n,
       v_num1(8) TYPE n,
       rad_budget(1) TYPE c,
       rad_plan(1)  TYPE c.

"calling screen for Excel Upload
CALL SCREEN  200.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0200 OUTPUT.
  SET PF-STATUS 'STAT'.
  SET TITLEBAR 'TIT'.
ENDMODULE.                 " STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
  CASE  sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'EXECUTE'.
      IF filename IS NOT INITIAL.
        PERFORM budgetupload.
      ELSE.
        MESSAGE  'Please enter the Filename'(001)  TYPE 'I'.
        REFRESH it_ret.
        LEAVE SCREEN.
      ENDIF.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*&      Module  VALUE_HELP  INPUT
*&---------------------------------------------------------------------*
MODULE value_help INPUT.
  IF fileupload IS INITIAL .
    CALL FUNCTION 'F4_FILENAME'
      EXPORTING
        field_name = 'FILENAME'
      IMPORTING
        file_name  = filename.
  ENDIF.
  IF filename IS INITIAL.
    CALL FUNCTION 'F4_FILENAME'
      EXPORTING
        field_name = 'FILEUPLOAD'
      IMPORTING
        file_name  = fileupload.
  ENDIF.
ENDMODULE.                 " VALUE_HELP  INPUT
*&---------------------------------------------------------------------*
*&      Form  BUDGETUPLOAD
*&---------------------------------------------------------------------*
FORM budgetupload .
  filename = filename.
  REFRESH it_datatab.
  IF filename IS NOT INITIAL.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_line_header        = 'X'
        i_tab_raw_data       = it_raw       " WORK TABLE
        i_filename           = filename
      TABLES
        i_tab_converted_data = it_datatab[]  "ACTUAL DATA
      EXCEPTIONS
        conversion_failed    = 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.

    "to fill the table for all budget values
    PERFORM filltable.

    "FM is used for transferring the budgeting
    " Original budget - KBUD
    " Budget supplement - KBN0
    " Budget return - KBR0
    "Budget release - KBFR

    CALL FUNCTION 'KBPP_EXTERN_UPDATE_CO'
      EXPORTING
        i_budget_activity      = 'KBUD'
        i_budget_activ_sup_ret = ' '
        i_delta_amounts        = 'X'
        i_rollup_data          = 'X'
        i_check_plan_data      = 'X'
        i_commit_all           = 'X'
      IMPORTING
        e_errors_found         = w_errors
      TABLES
        it_bpak                = it_bpak
        it_return              = it_ret
      EXCEPTIONS
        no_update              = 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.
    READ TABLE it_ret INTO wa_ret  WITH KEY type = 'E'.
    IF sy-subrc = 0.
      MESSAGE 'Error in upload of WBS'(004) TYPE 'I'.
      REFRESH it_ret.
      LEAVE SCREEN.
      "stop.
    ELSE.
      MESSAGE 'Budget Successfully Uploaded'(005)  TYPE 'I'.
      filename = ''.
      fileupload = ''.
      REFRESH it_ret.
      LEAVE SCREEN.
      "  stop.
    ENDIF.

  ENDIF.
ENDFORM.                    " BUDGETUPLOAD
*&---------------------------------------------------------------------*
*&      Form  FILLTABLE
*&---------------------------------------------------------------------*
FORM filltable .
  CLEAR wa_datatab.
  READ TABLE it_datatab INTO wa_datatab INDEX 1.
  CALL FUNCTION 'CONVERSION_EXIT_KONPD_INPUT'
    EXPORTING
      input     = wa_datatab-col2
    IMPORTING
      output    = v_num1
    EXCEPTIONS
      not_found = 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.
  SELECT *  FROM prps 
    INTO CORRESPONDING FIELDS OF TABLE it_prps
    WHERE psphi  =  v_num1.
  SELECT * FROM bpge INTO CORRESPONDING FIELDS OF TABLE it_bpge
    FOR ALL ENTRIES IN it_prps
    WHERE objnr = it_prps-objnr.

  IF it_bpge IS INITIAL.
    REFRESH it_bpak.
    LOOP AT it_datatab INTO wa_datatab.
      CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
        EXPORTING
          input     = wa_datatab-col2
        IMPORTING
          output    = v_num
        EXCEPTIONS
          not_found = 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.
      CLEAR wa_prps.
      READ TABLE it_prps INTO wa_prps
      WITH  KEY pspnr  =  v_num.

      wa_bpak-e_objnr = wa_prps-objnr.
      wa_bpak-wert = wa_datatab-col3.
      wa_bpak-twaer = 'INR'.
      APPEND wa_bpak TO it_bpak.
    ENDLOOP.
  ELSE.
    MESSAGE 'The Project is Already Budgeted.No changes allowed'(006)
    TYPE  'I'.
    REFRESH it_ret.
    LEAVE SCREEN.

  ENDIF.
ENDFORM.                    " FILLTABLE

Author: Ajoy Chakraborty
Submitted: 14/12/2011

DESCRIPTION: Automation Of WBS Creation (2nd/ 3rd/ 4th Levels).

REQUIREMENT: User will create the project definition and first level WBS elements manually. Then, they will provide all the WBS elements which needs to be created in excel sheet. Program should automatically create all the required second, third and fourth level WBS'.

PREREQUISITES
(1) Project definition and 1st level WBS Element should be created manually using CJ20N transaction.

(2) Parent WBS should exist before creating a child WBS.

_Ex. Let 1st level WBS be AJ11.00001. To create 3rd level WBS (AJ11.00001.01.01), 2nd level WBS element (AJ11.00001.01) should exist in the system.

FILE FORMAT
(1) First level Project Definition
(2) New WBS Element which is to be created
(3) Description
(4) Costing Sheet
(5) Requested Controlling Area
(6) Requested Cost Center
(7) Investment Profile
(8) WBS Up (WBS element under which new WBS Element will be created)
(9) Text1
(10) Text2
(11) Text3
(12) Text4

*NOTE: Text1, Text2, Text3 and Text4 are displayed under "USER FIELDS" tab.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Purpose           :  Automated WBS creation                         *
*& Program Name      :  ZAJ_WBS_UPLOAD                                 *
*& Author            :  AJOY CHAKRABORTY                               *
*&---------------------------------------------------------------------*

REPORT zaj_wbs_upload NO STANDARD PAGE HEADING.

*---------------------------------------------------------------------*
* INCLUDE
*---------------------------------------------------------------------*
INCLUDE: zaj_wbs_upload_top,
         zaj_wbs_upload_frm.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*-Fetch file name
  PERFORM upload_data.

*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
*-Create new level WBS Element
  PERFORM create_new_level.

*---------------------------------------------------------------------*
* END-OF-SELECTION
*---------------------------------------------------------------------*
END-OF-SELECTION.
*-Display list of WBSs' which are in error
  IF NOT it_error[] IS INITIAL.
    WRITE:/25     'WBS Elements In Error',
          /15(40) sy-uline.
    CLEAR wa_error.

    LOOP AT it_error INTO wa_error.
      WRITE:/23 wa_error-pspnr.
      CLEAR wa_error.
    ENDLOOP.
  ELSE.
    MESSAGE 'WBS elements created' TYPE 'I'.
  ENDIF.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*&  Include           ZAJ_WBS_UPLOAD_TOP
*&---------------------------------------------------------------------*

TYPE-POOLS: truxs.

*&---------------------------------------------------------------------*
*&  INTERNAL TABLE DECLARATION
*&---------------------------------------------------------------------*
DATA: BEGIN OF itab OCCURS 0,
        prj_def(24)   TYPE c,
        new_wbs(24)   TYPE c,
        desc(40)      TYPE c,
        cstg_sheet(6) TYPE c,
        cntrl_area(4) TYPE c,
        req_cc(10)    TYPE c,
        ccode(4)      TYPE c,
        inv_prf(6)    TYPE c,
        wbs_up(24)    TYPE c,
        text1(20)     TYPE c,
        text2(20)     TYPE c,
        text3(10)     TYPE c,
        text4(10)     TYPE c,
        location(10)  TYPE c,
      END OF itab.

TYPES: BEGIN OF ty_error,
         pspnr(24) TYPE c,
       END OF ty_error.

DATA: it_proj_def  TYPE TABLE OF bapi_project_definition_ex
                                                  WITH HEADER LINE,
      it_ret       TYPE TABLE OF bapireturn1      WITH HEADER LINE,
      it_wbs_elmnt TYPE TABLE OF bapi_bus2054_new WITH HEADER LINE,
      it_ret1      TYPE TABLE OF bapiret2         WITH HEADER LINE,
      it_ret2      TYPE TABLE OF bapiret2         WITH HEADER LINE,
      it_raw       TYPE truxs_t_text_data,
      it_error     TYPE STANDARD TABLE OF ty_error,
      wa_error     TYPE ty_error.

*&---------------------------------------------------------------------*
*&  VARIABLE
*&---------------------------------------------------------------------*
DATA: v_len(3)  TYPE i,
      v_val(2)  TYPE i,
      v_val1(2) TYPE c.

*&---------------------------------------------------------------------*
*&  PARAMETERS
*&---------------------------------------------------------------------*
PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*&  Include           ZAJ_WBS_UPLOAD_FRM
*&---------------------------------------------------------------------*
FORM upload_data.
*-File name
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.
*-Upload data from XLS
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = itab[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
*-Delete column headers
  READ TABLE itab INDEX 1.
  DELETE itab INDEX 1.

*-Sort the internal table and delete any duplicate entries
  SORT itab BY prj_def new_wbs.
  DELETE ADJACENT DUPLICATES FROM itab COMPARING prj_def new_wbs.

ENDFORM.                    " UPLOAD_DATA

*&---------------------------------------------------------------------*
*&      Form  CREATE_NEW_LEVEL
*&---------------------------------------------------------------------*
FORM create_new_level.

  CLEAR itab.
  REFRESH: it_wbs_elmnt,
           it_proj_def,
           it_ret,
           it_ret1,
           it_ret2,
           it_error.

  LOOP AT itab.
*-BAPIs to lock the project and create new element.
    CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

*-Get project details (already created projects only!)
    CALL FUNCTION 'BAPI_PROJECT_GETINFO'
      EXPORTING
        project_definition   = itab-prj_def
      IMPORTING
        e_project_definition = it_proj_def
        return               = it_ret.

*-Populate data into internal table for automated WBS creation
    it_wbs_elmnt-wbs_element       = itab-new_wbs.
    it_wbs_elmnt-description       = itab-desc.
    it_wbs_elmnt-responsible_no    = it_proj_def-responsible_no.
    it_wbs_elmnt-applicant_no      = it_proj_def-applicant_no.
    it_wbs_elmnt-company_code      = it_proj_def-comp_code.
    it_wbs_elmnt-business_area     = it_proj_def-bus_area.
    it_wbs_elmnt-controlling_area  = it_proj_def-controlling_area.
    it_wbs_elmnt-profit_ctr        = it_proj_def-profit_ctr.
    it_wbs_elmnt-wbs_account_assignment_element = 'X'.
    it_wbs_elmnt-cstg_sheet        = itab-cstg_sheet.

*-For 3rd level creation, controlling area should be blank. For 4th
*-level creation, it should be populated
    IF STRLEN( itab-new_wbs ) GT 16.
      it_wbs_elmnt-request_cctr_controlling_area  = itab-cntrl_area.
    ELSE.
      it_wbs_elmnt-request_cctr_controlling_area  = ' '.
    ENDIF.

    it_wbs_elmnt-request_cctr      = itab-req_cc.
    it_wbs_elmnt-calendar          = it_proj_def-calendar.
    it_wbs_elmnt-currency          = it_proj_def-project_currency.
    it_wbs_elmnt-currency_iso      = it_proj_def-project_currency_iso.
    it_wbs_elmnt-plant             = it_proj_def-plant.
    it_wbs_elmnt-user_field_key    = '0000001'.
    it_wbs_elmnt-wbs_summarization = 'X'.
    it_wbs_elmnt-objectclass       = it_proj_def-objectclass.
    it_wbs_elmnt-interest_prof     = '0000001'.
    it_wbs_elmnt-invest_profile    = itab-inv_prf.
    it_wbs_elmnt-request_comp_code = itab-ccode.
    it_wbs_elmnt-user_field_char20_1  = itab-text1.
    it_wbs_elmnt-user_field_char20_2  = itab-text2.
    it_wbs_elmnt-user_field_char10_1  = itab-text3.
    it_wbs_elmnt-user_field_char10_2  = itab-text4.
    it_wbs_elmnt-location             = itab-location.

*-To populate WBS_LEFT: it signifies the level under which new WBS to
*-be created. If it is new 3rd level creation- you need not populate
*-WBS_LEFT. ELSE, it should be equal to the previous 4th level WBS,
*-which is already created
    v_len = STRLEN( itab-new_wbs ) - 2.

    IF itab-new_wbs+v_len(2) NE '01'.
      v_val = itab-new_wbs+v_len(2) - 1.
      v_val1 = v_val.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = v_val1
        IMPORTING
          output = v_val1.

*-If this is not populated, the newly created WBS will be displayed in
*-descending order instead of acsending order in CJ20N transaction
      CONCATENATE itab-new_wbs+0(v_len) v_val1 INTO it_wbs_elmnt-wbs_left.
    ENDIF.

    it_wbs_elmnt-wbs_up = itab-wbs_up.

*-Internal table to be passed to BAPI for WBS creation.
    APPEND it_wbs_elmnt.

*-BAPI for automated WBS creation
    CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
      EXPORTING
        i_project_definition = itab-prj_def
      TABLES
        it_wbs_element       = it_wbs_elmnt
        et_return            = it_ret1.

    CALL FUNCTION 'BAPI_PS_PRECOMMIT'
      TABLES
        et_return = it_ret2.

    READ TABLE it_ret2 WITH KEY type = 'E'.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
*-Populate error log
      CLEAR wa_error.

      wa_error-pspnr = itab-new_wbs.
      APPEND wa_error TO it_error.
    ENDIF.

*-Create long text for WBS Element created
    IF sy-subrc EQ 0.
*-Insert delay
      WAIT UP TO 2 SECONDS.
    ENDIF.

*-Clearing all headers and internal tables
    CLEAR: itab,
           it_wbs_elmnt.

    REFRESH: it_wbs_elmnt,
             it_proj_def,
             it_ret,
             it_ret1,
             it_ret2.
  ENDLOOP.

ENDFORM.                    " CREATE_NEW_LEVEL

Author: Ajoy Chakraborty
Submitted: 14/12/2011

DESCRIPTION: Automation Of WBS Creation (2nd/ 3rd/ 4th Levels).

REQUIREMENT: User will create the project definition and first level WBS elements manually. Then, they will provide all the WBS elements which needs to be created in excel sheet. Program should automatically create all the required second, third and fourth level WBS'.

PRE-REQUISITES
(1) Project defination and 1st level WBS Element should be created manually using CJ20N transaction.

(2) Parent WBS should exist before creating a child WBS.

_Ex. Let 1st level WBS be AJ11.00001. To create 3rd level WBS (AJ11.00001.01.01), 2nd level WBS element (AJ11.00001.01) should exist in the system.

FILE FORMAT
(1) First level Project Definition
(2) New WBS Element which is to be created
(3) Description
(4) Costing Sheet
(5) Requested Controlling Area
(6) Requested Cost Center
(7) Investment Profile
(8) WBS Up (WBS element under which new WBS Element will be created)
(9) Text1
(10) Text2
(11) Text3
(12) Text4

*NOTE: Text1, Text2, Text3 and Text4 are displayed under "USER FIELDS" tab.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Purpose           :  Automated WBS creation                         *
*& Program Name      :  ZAJ_WBS_UPLOAD                                 *
*& Author            :  AJOY CHAKRABORTY                               *
*&---------------------------------------------------------------------*

REPORT zaj_wbs_upload NO STANDARD PAGE HEADING.

*---------------------------------------------------------------------*
* INCLUDE
*---------------------------------------------------------------------*
INCLUDE: zaj_wbs_upload_top,
         zaj_wbs_upload_frm.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*-Fetch file name
  PERFORM upload_data.

*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.
*-Create new level WBS Element
  PERFORM create_new_level.

*---------------------------------------------------------------------*
* END-OF-SELECTION
*---------------------------------------------------------------------*
END-OF-SELECTION.
*-Display list of WBSs' which are in error
  IF NOT it_error[] IS INITIAL.
    WRITE:/25     'WBS Elements In Error',
          /15(40) sy-uline.
    CLEAR wa_error.

    LOOP AT it_error INTO wa_error.
      WRITE:/23 wa_error-pspnr.
      CLEAR wa_error.
    ENDLOOP.
  ELSE.
    MESSAGE 'WBS elements created' TYPE 'I'.
  ENDIF.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*&  Include           ZAJ_WBS_UPLOAD_TOP
*&---------------------------------------------------------------------*

TYPE-POOLS: truxs.

*&---------------------------------------------------------------------*
*&  INTERNAL TABLE DECLARATION
*&---------------------------------------------------------------------*
DATA: BEGIN OF itab OCCURS 0,
        prj_def(24)   TYPE c,
        new_wbs(24)   TYPE c,
        desc(40)      TYPE c,
        cstg_sheet(6) TYPE c,
        cntrl_area(4) TYPE c,
        req_cc(10)    TYPE c,
        ccode(4)      TYPE c,
        inv_prf(6)    TYPE c,
        wbs_up(24)    TYPE c,
        text1(20)     TYPE c,
        text2(20)     TYPE c,
        text3(10)     TYPE c,
        text4(10)     TYPE c,
        location(10)  TYPE c,
      END OF itab.

TYPES: BEGIN OF ty_error,
         pspnr(24) TYPE c,
       END OF ty_error.

DATA: it_proj_def  TYPE TABLE OF bapi_project_definition_ex
                                                  WITH HEADER LINE,
      it_ret       TYPE TABLE OF bapireturn1      WITH HEADER LINE,
      it_wbs_elmnt TYPE TABLE OF bapi_bus2054_new WITH HEADER LINE,
      it_ret1      TYPE TABLE OF bapiret2         WITH HEADER LINE,
      it_ret2      TYPE TABLE OF bapiret2         WITH HEADER LINE,
      it_raw       TYPE truxs_t_text_data,
      it_error     TYPE STANDARD TABLE OF ty_error,
      wa_error     TYPE ty_error.

*&---------------------------------------------------------------------*
*&  VARIABLE
*&---------------------------------------------------------------------*
DATA: v_len(3)  TYPE i,
      v_val(2)  TYPE i,
      v_val1(2) TYPE c.

*&---------------------------------------------------------------------*
*&  PARAMETERS
*&---------------------------------------------------------------------*
PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*&  Include           ZAJ_WBS_UPLOAD_FRM
*&---------------------------------------------------------------------*
FORM upload_data.
*-File name
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.
*-Upload data from XLS
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = itab[]
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.
*-Delete column headers
  READ TABLE itab INDEX 1.
  DELETE itab INDEX 1.

*-Sort the internal table and delete any duplicate entries
  SORT itab BY prj_def new_wbs.
  DELETE ADJACENT DUPLICATES FROM itab COMPARING prj_def new_wbs.

ENDFORM.                    " UPLOAD_DATA

*&---------------------------------------------------------------------*
*&      Form  CREATE_NEW_LEVEL
*&---------------------------------------------------------------------*
FORM create_new_level.

  CLEAR itab.
  REFRESH: it_wbs_elmnt,
           it_proj_def,
           it_ret,
           it_ret1,
           it_ret2,
           it_error.

  LOOP AT itab.
*-BAPIs to lock the project and create new element.
    CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

*-Get project details (already created projects only!)
    CALL FUNCTION 'BAPI_PROJECT_GETINFO'
      EXPORTING
        project_definition   = itab-prj_def
      IMPORTING
        e_project_definition = it_proj_def
        return               = it_ret.

*-Populate data into internal table for automated WBS creation
    it_wbs_elmnt-wbs_element       = itab-new_wbs.
    it_wbs_elmnt-description       = itab-desc.
    it_wbs_elmnt-responsible_no    = it_proj_def-responsible_no.
    it_wbs_elmnt-applicant_no      = it_proj_def-applicant_no.
    it_wbs_elmnt-company_code      = it_proj_def-comp_code.
    it_wbs_elmnt-business_area     = it_proj_def-bus_area.
    it_wbs_elmnt-controlling_area  = it_proj_def-controlling_area.
    it_wbs_elmnt-profit_ctr        = it_proj_def-profit_ctr.
    it_wbs_elmnt-wbs_account_assignment_element = 'X'.
    it_wbs_elmnt-cstg_sheet        = itab-cstg_sheet.

*-For 3rd level creation, controlling area should be blank. For 4th
*-level creation, it should be populated
    IF STRLEN( itab-new_wbs ) GT 16.
      it_wbs_elmnt-request_cctr_controlling_area  = itab-cntrl_area.
    ELSE.
      it_wbs_elmnt-request_cctr_controlling_area  = ' '.
    ENDIF.

    it_wbs_elmnt-request_cctr      = itab-req_cc.
    it_wbs_elmnt-calendar          = it_proj_def-calendar.
    it_wbs_elmnt-currency          = it_proj_def-project_currency.
    it_wbs_elmnt-currency_iso      = it_proj_def-project_currency_iso.
    it_wbs_elmnt-plant             = it_proj_def-plant.
    it_wbs_elmnt-user_field_key    = '0000001'.
    it_wbs_elmnt-wbs_summarization = 'X'.
    it_wbs_elmnt-objectclass       = it_proj_def-objectclass.
    it_wbs_elmnt-interest_prof     = '0000001'.
    it_wbs_elmnt-invest_profile    = itab-inv_prf.
    it_wbs_elmnt-request_comp_code = itab-ccode.
    it_wbs_elmnt-user_field_char20_1  = itab-text1.
    it_wbs_elmnt-user_field_char20_2  = itab-text2.
    it_wbs_elmnt-user_field_char10_1  = itab-text3.
    it_wbs_elmnt-user_field_char10_2  = itab-text4.
    it_wbs_elmnt-location             = itab-location.

*-To populate WBS_LEFT: it signifies the level under which new WBS to
*-be created. If it is new 3rd level creation- you need not populate
*-WBS_LEFT. ELSE, it should be equal to the previous 4th level WBS,
*-which is already created
    v_len = STRLEN( itab-new_wbs ) - 2.

    IF itab-new_wbs+v_len(2) NE '01'.
      v_val = itab-new_wbs+v_len(2) - 1.
      v_val1 = v_val.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = v_val1
        IMPORTING
          output = v_val1.

*-If this is not populated, the newly created WBS will be displayed in
*-descending order instead of acsending order in CJ20N transaction
      CONCATENATE itab-new_wbs+0(v_len) v_val1 INTO it_wbs_elmnt-wbs_left.
    ENDIF.

    it_wbs_elmnt-wbs_up = itab-wbs_up.

*-Internal table to be passed to BAPI for WBS creation.
    APPEND it_wbs_elmnt.

*-BAPI for automated WBS creation
    CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
      EXPORTING
        i_project_definition = itab-prj_def
      TABLES
        it_wbs_element       = it_wbs_elmnt
        et_return            = it_ret1.

    CALL FUNCTION 'BAPI_PS_PRECOMMIT'
      TABLES
        et_return = it_ret2.

    READ TABLE it_ret2 WITH KEY type = 'E'.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
*-Populate error log
      CLEAR wa_error.

      wa_error-pspnr = itab-new_wbs.
      APPEND wa_error TO it_error.
    ENDIF.

*-Create long text for WBS Element created
    IF sy-subrc EQ 0.
*-Insert delay
      WAIT UP TO 2 SECONDS.
    ENDIF.

*-Clearing all headers and internal tables
    CLEAR: itab,
           it_wbs_elmnt.

    REFRESH: it_wbs_elmnt,
             it_proj_def,
             it_ret,
             it_ret1,
             it_ret2.
  ENDLOOP.

ENDFORM.                    " CREATE_NEW_LEVEL

Author: Yajuvendrasinh Raulji & Jeet Bhatt*

Submitted: 06/05/2007
Related Links:

  • Adding WBS Element in Proper Hierarchy from a Text File.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Include ZBAPIWBS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Report Z_BAPI_CJ20N
*&---------------------------------------------------------------------*

REPORT z_bapi_cj20n.

INCLUDE zbapicj20ntop.

INCLUDE zbapicj20nfileup.

INCLUDE zbapicj20nlogic.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NTOP
*&---------------------------------------------------------------------*

DATA: BEGIN OF itmain OCCURS 0,
        project_definition TYPE ps_pspid,
        description TYPE ps_post1,
        project_profile TYPE profidproj,
        bus_area TYPE gsber,
        wbs_element TYPE ps_posid,
        wbs_description TYPE ps_post1,
      END OF itmain,
      wa_main LIKE LINE OF itmain,
      itwbs LIKE STANDARD TABLE OF itmain WITH HEADER LINE,
      itmain2 LIKE STANDARD TABLE OF itmain.

DATA: itprjdef TYPE STANDARD TABLE OF bapi_project_definition WITH HEADER LINE,
      wa_prjdef LIKE LINE OF itprjdef.

DATA: itprjdefup TYPE STANDARD TABLE OF bapi_project_definition_up WITH HEADER LINE,
      wa_prjdefup LIKE LINE OF itprjdefup.

DATA: itmetprj TYPE STANDARD TABLE OF bapi_method_project,
      wa_metprj LIKE LINE OF itmetprj.

DATA: return TYPE bapireturn1,msg TYPE STANDARD TABLE OF bapi_meth_message WITH HEADER LINE.

DATA: lines TYPE i,refno TYPE i VALUE 0.
DESCRIBE TABLE itmain LINES lines.
DATA: mettype TYPE string VALUE 'Create'.

DATA: wa_dupli LIKE LINE OF itmain.
wa_dupli-project_definition = 'JB'.

DATA: split1(50) TYPE c.
DATA: prevwbs TYPE ps_posid VALUE ' ',
      leftwbs TYPE ps_posid VALUE ' '.
DATA: pos TYPE i VALUE 1.
DATA: off TYPE i VALUE 0,mode TYPE i,index1 TYPE i VALUE 0,
      index2 TYPE i VALUE 0,index3 TYPE i VALUE 0,
      index4 TYPE i VALUE 0,index5 TYPE i VALUE 0,
      pos2 TYPE i VALUE 0,flag TYPE i VALUE 0.

DATA: itbus TYPE STANDARD TABLE OF bapi_bus2054_new,
      wa_bus LIKE LINE OF itbus, ret TYPE STANDARD TABLE OF bapiret2,
      wa_ret LIKE LINE OF ret, itbus2 LIKE STANDARD TABLE OF bapi_bus2054_new,
      wa_bus2 LIKE LINE OF itbus, wa_bus3 LIKE LINE OF itbus.

DATA: bapiret TYPE bapireturn1,
      projex TYPE bapi_project_definition_ex.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NFILEUP
*&---------------------------------------------------------------------*

CALL FUNCTION 'UPLOAD'
  EXPORTING
    filename = ' '
    filetype = 'DAT'
  TABLES
    data_tab = itmain.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NLOGIC
*&---------------------------------------------------------------------*

SORT itmain BY project_definition wbs_element.

LOOP AT itmain INTO wa_main.

  IF wa_dupli-project_definition <> wa_main-project_definition.

    wa_prjdef-project_definition = wa_main-project_definition.
    wa_prjdef-description = wa_main-description.
    wa_prjdef-project_profile = wa_main-project_profile.
    wa_prjdef-bus_area = wa_main-bus_area.

    wa_prjdefup-project_definition = 'X'.
    wa_prjdefup-description = 'X'.
    wa_prjdefup-project_profile = 'X'.
    wa_prjdefup-bus_area = 'X'.

    wa_metprj-refnumber = refno + 1 .
    wa_metprj-objecttype = 'ProjectDefinition'.
    wa_metprj-method = mettype.
    wa_metprj-objectkey = wa_main-project_definition.
    APPEND wa_metprj TO itmetprj.

    wa_metprj-refnumber = ''.
    wa_metprj-objecttype = ''.
    wa_metprj-method = 'Save'.
    wa_metprj-objectkey = ''.
    APPEND wa_metprj TO itmetprj.

    CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'
      EXPORTING
        i_project_definition     = wa_prjdef
        i_project_definition_upd = wa_prjdefup
      IMPORTING
        return                   = return
      TABLES
        i_method_project         = itmetprj
        e_message_table          = msg.

    IF sy-subrc = 0.
      flag = 1.
    ENDIF.
    wa_dupli-project_definition = wa_main-project_definition.

    COMMIT WORK.
    DELETE itmetprj FROM 1 TO 2.

    INCLUDE zbapiwbs_all.

  ENDIF.
ENDLOOP.

*&---------------------------------------------------------------------*
*& Include ZBAPIWBS_ALL
*&---------------------------------------------------------------------*
LOOP AT itmain INTO wa_main WHERE project_definition = wa_dupli-project_definition.
  APPEND wa_main TO itwbs.
ENDLOOP.

*Sort the table
LOOP AT itwbs INTO wa_main.
  split1 = wa_main-wbs_element.
  pos = 0.
  LOOP AT itwbs WHERE wbs_element <> split1.

    IF strlen( itwbs-wbs_element ) = strlen( split1 ).
      IF pos = 0.
        APPEND wa_main TO itmain2.
      ENDIF.
      APPEND itwbs TO itmain2.
      DELETE itwbs WHERE wbs_element EQ itwbs-wbs_element.
      pos = 1.
    ELSE.
      IF pos = 0.
        APPEND wa_main TO itmain2.
        DELETE itwbs WHERE wbs_element EQ wa_main.
      ENDIF.
      pos = 1.
    ENDIF.

  ENDLOOP.
  index1 = index1 + 1.
ENDLOOP.

*Define UP element
LOOP AT itmain2 INTO wa_main.

  wa_bus-wbs_element = wa_main-wbs_element.
  wa_bus-description = wa_main-wbs_description.
  wa_bus-wbs_up = ''.
  wa_bus-wbs_left = ''.
  split1 = wa_main-wbs_element.
  LOOP AT itmain2 INTO wa_main WHERE wbs_element <> split1.
    IF strlen( wa_main-wbs_element ) < strlen( split1 ) .
      FIND wa_main-wbs_element IN split1.
      IF sy-subrc = 0.
        wa_bus-wbs_up = wa_main-wbs_element.
        prevwbs = wa_main-wbs_element.
      ENDIF.
    ENDIF.
  ENDLOOP.
  APPEND wa_bus TO itbus.
  index2 = index2 + 1.
ENDLOOP.

prevwbs = ''.
leftwbs = ''.

* Define LEFT ELEMENT.
LOOP AT itmain2 INTO wa_main.

  pos = 0.
  split1 = wa_main-wbs_element.
  READ TABLE itbus INTO wa_bus2 WITH KEY wbs_element = wa_main-wbs_element.
  wa_bus-wbs_element = split1.
  wa_bus-description = wa_main-wbs_description.
  wa_bus-wbs_up = wa_bus2-wbs_up.
  off = sy-tabix.

  LOOP AT itmain2 INTO wa_main WHERE wbs_element <> split1.

    READ TABLE itbus INTO wa_bus3 WITH KEY wbs_element = wa_main-wbs_element.

    IF strlen( wa_bus2-wbs_element ) = strlen( wa_bus3-wbs_element ) AND
    wa_bus2-wbs_up = wa_bus3-wbs_up AND pos = 0.

      IF strlen( leftwbs ) <> strlen( split1 ).
        leftwbs = ''.
      ENDIF.

      IF strlen( leftwbs ) = strlen( split1 ).
        FIND wa_bus2-wbs_up IN leftwbs.
        IF sy-subrc <> 0.
          leftwbs = ''.
        ENDIF.
      ENDIF.

      wa_bus-wbs_left = leftwbs.
      leftwbs = split1.
      pos = 1.
      MODIFY itbus INDEX off FROM wa_bus.
    ENDIF.
  ENDLOOP.

ENDLOOP.

wa_bus-wbs_element = ''.
APPEND wa_bus TO itbus.

* Store WBS ELEMENTS.
LOOP AT itbus INTO wa_bus.
  split1 = wa_bus-wbs_element.
  APPEND wa_bus TO itbus2.
  index3 = 1.
  pos = 0.

  LOOP AT itbus INTO wa_bus WHERE wbs_element <> split1.

    IF strlen( wa_bus-wbs_element ) <> strlen( split1 ) AND pos = 0.
      pos = 1.
      index4 = index3.

      CALL FUNCTION 'BAPI_PS_INITIALIZATION' .

      CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
        EXPORTING
          i_project_definition = wa_dupli-project_definition
        TABLES
          it_wbs_element       = itbus2
          et_return            = ret.

      CALL FUNCTION 'BAPI_PS_PRECOMMIT'
        TABLES
          et_return = ret.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait   = 'X'
        IMPORTING
          return = wa_ret.

    ENDIF.
    APPEND wa_bus TO itbus2.
    index3 = index3 + 1.
  ENDLOOP.

  DELETE itbus2 FROM 1 TO index3.
  DELETE itbus FROM 1 TO index4.

ENDLOOP.

DELETE itwbs FROM 1 TO index1.
CLEAR itwbs.
DELETE itmain2 FROM 1 TO index2.

*At the end of all projects' processing
IF flag = 1.

  CALL FUNCTION 'POPUP_FOR_INTERACTION'
    EXPORTING
      headline = 'PS Project & WBS Creation'
      text1    = 'All the Projects have been created.Please check......'
      ticon    = 'I'
      button_1 = 'OK'.

ELSE.

  CALL FUNCTION 'POPUP_FOR_INTERACTION'
    EXPORTING
      headline = 'Jeet Program'
      text1    = 'No Projects were created...'
      ticon    = 'I'
      button_1 = 'CANCEL'.
ENDIF.

Author: Sujeet Mishra
Submitted: 19/08/2013
Description: Displays the List of Due in the current week

TABLES: sscrfields,proj,prps,mlst.
RANGES s_pspid FOR proj-pspid.
RANGES s_pspnr FOR prps-pspnr.
RANGES s_tedat FOR mlst-tedat.
DATA:
BEGIN OF i_final_line,
pspid TYPE proj-pspid,
pspnr TYPE prps-pspnr,
psphi TYPE prps-psphi,
tedat TYPE mlst-tedat,
lst_fertg TYPE mlst-lst_fertg,
lst_actdt TYPE mlst-lst_actdt,
fproz TYPE mlst-fproz,
END OF i_final_line,
i_final LIKE TABLE OF i_final_line INITIAL SIZE 0.
INITIALIZATION.
 s_pspid-low = 'ES*'.
s_pspid-option = 'CP'.
 s_pspid-sign = 'I'.
 APPEND s_pspid.
START-OF-SELECTION.
 SELECT proj~pspid prps~pspnr prps~psphi mlst~tedat mlst~lst_fertg mlst~lst_actdt mlst~fproz
 FROM ( proj INNER JOIN prps
 ON prps~psphi = proj~pspnr &nbsp;INNER JOIN mlst
 ON mlst~pspnr = prps~pspnr )
 INTO TABLE i_final
WHERE proj~pspid IN s_pspid
AND prps~pspnr IN s_pspnr
AND mlst~tedat IN s_tedat.
DELETE i_final WHERE lst_actdt IS INITIAL.
IF i_final\[\] IS INITIAL.
 WRITE / 'No Due milestones found'.
 ELSE.
 WRITE : / 'Please find the below list of MileStones due for the period',
s_tedat-low, 'to', s_tedat-high.
SKIP.
LOOP AT i_final INTO i_final_line.
AT FIRST.
WRITE : /2 'Project Definition', 27 'WBS Element', 53 'Schedule Date',
70 '% of completion', 90 '% of value to be Invoiced'.
ULINE.
ENDAT.
 WRITE : /2 i_final_line-pspid, 27 i_final_line-pspnr, 53 i_final_line-tedat,
65 i_final_line-lst_fertg, 85 i_final_line-fproz.
ENDLOOP.
&nbENDIF.

I have been working for an implementation project in PS. While developing codes for various requirements, I had to access the WBS attached to  a project

   again and again. So i went ahead to make a Function module for it in order to save efforts.

function ZFM_TEST .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(WBS_NO) TYPE  PRPS-PSPNR
*"  TABLES
*"      WBS_TAB STRUCTURE  PRHI
*"  EXCEPTIONS
*"      WBS_NOT_FOUND
*"----------------------------------------------------------------------
  data : l_prhi like prhi.

  data : cur_wbs like prhi-posnr,
         sub_wbs like prhi-down.

  refresh it_wbs.
  clear it_wbs.

  refresh wbs_tab.

  select single * from prps where pspnr = wbs_no.
  if sy-subrc <> 0.
    select single * from prps where posid = wbs_no.
    if sy-subrc <> 0.
      raise wbs_not_found.
    endif.
  endif.

  select single * from prhi where posnr = prps-pspnr.

  move prhi to wbs_tab.
  append wbs_tab.

  check not prhi-down is initial. "subordinate exists

  refresh wbs_tab.

  move prhi to it_wbs.
  append it_wbs.

  cur_wbs = prhi-posnr.
  select * into l_prhi from prhi where up = cur_wbs.
    move l_prhi to it_wbs.
    append it_wbs.

    if not l_prhi-down is initial.
      perform get_sub_wbs using l_prhi-posnr.
    endif.
  endselect.

  wbs_tab[] = it_wbs[].

endfunction.

*&---------------------------------------------------------------------*
*&      Form  get_sub_wbs
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_PRHI_DOWN  text
*----------------------------------------------------------------------*
form get_sub_wbs using    p_wbs1.
  data : l_prhi like prhi.

  select * into l_prhi from prhi where up = p_wbs1.
    move l_prhi to it_wbs.
    append it_wbs.
    if not l_prhi-down is initial.
      perform get_sub_wbs using l_prhi-posnr.
    endif.
  endselect.

endform.                    "get_sub_wbs

User Status 'GR' to set automatically.

No actual cost should be allowed to be booked after complete GR of FERT. At the time of complete GR , user status 'GR' should be set automatically at WBS, Network and activity level.

Code Snippet is as follows :

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CALL FUNCTION 'BAPI_PROJECT_GETINFO'
  EXPORTING
    project_definition   = v_proj
    with_activities      = 'X'
  IMPORTING
    e_project_definition = wa_e_project_definition
  TABLES
    e_wbs_element_table  = it_e_wbs_element
    e_activity_table     = it_e_activity.

SELECT * FROM prps INTO TABLE it_wbs
                   FOR ALL ENTRIES IN it_prhi
                   WHERE pspnr = it_prhi-posnr.

REFRESH : wbsusrstat,
          wbsstatres,
          precomm.

CLEAR : wbsusrstat,
        wbsstatret,
        wbsstatres,
        precomm.

SELECT aufnr objnr FROM aufk
  INTO CORRESPONDING FIELDS OF TABLE it_aufk
  FOR ALL ENTRIES IN it_prhi
  WHERE pspel = it_prhi-posnr.

LOOP AT it_prhi INTO  wa_prhi.

  CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
    EXPORTING
      input  = wa_prhi-posnr
    IMPORTING
      output = wa_wbsusr-wbs_element.

  wa_wbsusr-set_user_status = 'GR'.
  APPEND wa_wbsusr TO wbsusrstat  .
ENDLOOP.

CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
  EXPORTING
    i_initialized = 'X'.

CALL FUNCTION 'BAPI_BUS2054_SET_STATUS'
  IMPORTING
    return            = wbsstatret
  TABLES
    i_wbs_user_status = wbsusrstat
    e_result          = wbsstatres.

LOOP AT wbsstatres INTO wa_wbsstatres WHERE message_type = 'E'.
  MESSAGE wa_wbsstatres-message_text TYPE 'E'.
  errorflag = 'X'.
ENDLOOP.

IF errorflag NE 'X'.
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = precomm.
  LOOP AT precomm INTO wa_precomm WHERE type = 'E'.
    WRITE :/ wa_precomm-message.
  ENDLOOP.
  CALL FUNCTION 'DEQUEUE_ALL'.

ENDIF.

* Select Data from AUFK to capture all network related OBJNR
IF it_prhi IS NOT INITIAL.
  SELECT aufnr objnr FROM aufk INTO CORRESPONDING FIELDS OF TABLE it_aufk
               FOR ALL ENTRIES IN it_prhi
               WHERE pspel = it_prhi-posnr.
ENDIF.

* Select Data from AFVC to capture all activity related OBJNR
IF it_prhi IS NOT INITIAL.
  SELECT objnr FROM afvc
                INTO CORRESPONDING FIELDS OF TABLE it_afvc
                FOR ALL ENTRIES IN it_prhi
                WHERE projn = it_prhi-posnr.
ENDIF.

*Capture all the status from jest for network
IF it_aufk IS NOT INITIAL.
  SELECT objnr stat inact FROM jest INTO CORRESPONDING FIELDS OF TABLE it_jest
                          FOR ALL ENTRIES IN it_aufk
                         WHERE objnr = it_aufk-objnr.
ENDIF.

*Capture all the status from jest for activities
IF it_afvc IS NOT INITIAL.
  SELECT objnr stat inact FROM jest INTO CORRESPONDING FIELDS OF TABLE it_jest_afvc
                          FOR ALL ENTRIES IN it_afvc
                         WHERE objnr = it_afvc-objnr.
ENDIF.

*Update GR status of WBS in Jest for status E0013
SORT it_jest_prps BY objnr.
it_jest_prps1[] = it_jest_prps[].

LOOP AT it_jest_prps INTO wa_jest_prps.
  READ TABLE it_jest_prps1 INTO wa_jest_prps1 WITH KEY objnr  = wa_jest_prps-objnr
                                               stat = 'E0013'.
  IF sy-subrc = 0 AND wa_jest_prps1-inact = 'X'.
    wa_jest_prps-inact = ' '.
    MODIFY it_jest_prps FROM wa_jest_prps INDEX sy-tabix TRANSPORTING inact.
    MODIFY it_jest_prps1 FROM wa_jest_prps INDEX sy-tabix TRANSPORTING inact.
  ELSEIF sy-subrc = 0 AND wa_jest_prps1-inact = ' '.
    CONTINUE.
  ELSEIF sy-subrc <> 0.
    MOVE wa_jest_prps TO wa_jest_prps1.
    wa_jest_prps1-stat = 'E0013'.
    wa_jest_prps1-inact = ' '.
    APPEND  wa_jest_prps1 TO it_jest_prps.
    APPEND  wa_jest_prps1 TO it_jest_prps1.
    CLEAR wa_jest_prps1.
  ENDIF.
  CLEAR: wa_jest_prps.
ENDLOOP.

MODIFY jest FROM TABLE it_jest_prps.

*Update GR status of network in Jest for status E0008
SORT it_jest BY objnr.
it_jest1[] = it_jest[].

LOOP AT it_jest INTO wa_jest.
  READ TABLE it_jest1 INTO wa_jest1 WITH KEY objnr  = wa_jest-objnr
                                               stat = 'E0008'.
  IF sy-subrc = 0 AND wa_jest1-inact = 'X'.
    wa_jest-inact = ' '.
    MODIFY it_jest FROM wa_jest INDEX sy-tabix TRANSPORTING inact.
    MODIFY it_jest1 FROM wa_jest INDEX sy-tabix TRANSPORTING inact.
  ELSEIF sy-subrc = 0 AND wa_jest1-inact = ' '.
    CONTINUE.
  ELSEIF sy-subrc <> 0.
    MOVE wa_jest TO wa_jest1.
    wa_jest1-stat = 'E0008'.
    wa_jest1-inact = ' '.
    APPEND  wa_jest1 TO it_jest.
    APPEND  wa_jest1 TO it_jest1.
    CLEAR wa_jest1.
  ENDIF.
  CLEAR: wa_jest.
ENDLOOP.

MODIFY jest FROM TABLE it_jest.

*Update GR status of activity in Jest for status E0008
SORT it_jest_afvc BY objnr.
it_jest_afvc1[] = it_jest_afvc[].

LOOP AT it_jest_afvc INTO wa_jest_afvc.
  READ TABLE it_jest_afvc1 INTO wa_jest_afvc1 WITH KEY objnr  = wa_jest_afvc-objnr
                                               stat = 'E0008'.
  IF sy-subrc = 0 AND wa_jest_afvc1-inact = 'X'.
    wa_jest_afvc-inact = ' '.
    MODIFY it_jest_afvc FROM wa_jest_afvc INDEX sy-tabix TRANSPORTING inact.
    MODIFY it_jest_afvc1 FROM wa_jest_afvc INDEX sy-tabix TRANSPORTING inact.
  ELSEIF sy-subrc = 0 AND wa_jest_afvc1-inact = ' '.
    CONTINUE.
  ELSEIF sy-subrc <> 0.
    MOVE wa_jest_afvc TO wa_jest_afvc1.
    wa_jest_afvc1-stat = 'E0008'.
    wa_jest_afvc1-inact = ' '.
    APPEND  wa_jest_afvc1 TO it_jest_afvc.
    APPEND  wa_jest_afvc1 TO it_jest_afvc1.
    CLEAR wa_jest_afvc1.
  ENDIF.
  CLEAR: wa_jest_afvc.
ENDLOOP.

MODIFY jest FROM TABLE it_jest_afvc.

Write this code in TOP include of the Fuction Group

DATA : GS_BDCDATA TYPE BDCDATA, "Table type for BDCDATA
             GS_MESSTAB TYPE BDCMSGCOLL, "Table type to hold messages
             GT_BDCDATA TYPE STANDARD TABLE OF BDCDATA, "Int Table for BDC Data
             GT_MESSTAB TYPE STANDARD TABLE OF BDCMSGCOLL, "Int Table for Messages
             GV_OPTION TYPE CTU_PARAMS.

CONSTANTS : C_DISMODE VALUE 'N', "Mode in which BDC runs
                        C_UPDMODE VALUE 'S'. "Mode in which data loads into SAP
                        

 This code should be write in another include of Function Group

*&---------------------------------------------------------------------*
*& Include LZBAPI_DELETE_WBSF01
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Begin New Screen*
*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
   CLEAR GS_BDCDATA.
   GS_BDCDATA-PROGRAM = PROGRAM.
   GS_BDCDATA-DYNPRO = DYNPRO.
   GS_BDCDATA-DYNBEGIN = 'X'.
   APPEND GS_BDCDATA TO GT_BDCDATA.
ENDFORM. "BDC_DYNPRO

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
   CLEAR GS_BDCDATA.
  GS_BDCDATA-FNAM = FNAM.
  GS_BDCDATA-FVAL = FVAL.
  APPEND GS_BDCDATA TO GT_BDCDATA.
ENDFORM. "BDC_FIELD

 

Code for BAPI / FM

FUNCTION ZBAPI_DELETE_WBS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_PROJECT) TYPE ZBAPI_INCLUDE_WBS-PROJECT
*" VALUE(I_WBS) TYPE ZBAPI_INCLUDE_WBS-WBS
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*" EXCEPTIONS
*" INVALID_PROJECT
*" INVALID_WBS
*" OTHER
*"----------------------------------------------------------------------


DATA : GT_WBS TYPE STANDARD TABLE OF BAPI_WBS_ELEMENT_EXP,
GS_WBS TYPE BAPI_WBS_ELEMENT_EXP.

DATA : GV_POS TYPE I VALUE 0,
GV_SELPOS TYPE I VALUE 0,
GV_PGDN TYPE I VALUE 0,
GV_POSITION TYPE STRING,
GV_FOUND TYPE CHAR1,
GV_OTH TYPE CHAR1.

CONSTANTS : C_ROW TYPE I VALUE 12.

**Clearing variables

REFRESH : RETURN, GT_BDCDATA, GT_MESSTAB, GT_WBS.
CLEAR : GV_OPTION, GV_POS, GV_SELPOS, GV_PGDN,
GV_POSITION, GV_FOUND, GS_WBS, GS_BDCDATA, GS_MESSTAB.

**Convert WBS as output

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
      EXPORTING
            INPUT = I_WBS
      IMPORTING
            OUTPUT = I_WBS.

**Get existing project structure
CALL FUNCTION 'BAPI_PROJECT_GETINFO'
      EXPORTING
            PROJECT_DEFINITION = I_PROJECT
      TABLES
            E_WBS_ELEMENT_TABLE = GT_WBS.

 

**raise error when invalid project entered

IF GT_WBS IS INITIAL.
      RAISE INVALID_PROJECT.
ENDIF.

**Aplpy conversion exit on project

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
      EXPORTING
            INPUT = I_PROJECT
      IMPORTING
            OUTPUT = I_PROJECT.

 

**check for invalid wbs
CLEAR : GV_FOUND.
LOOP AT GT_WBS INTO GS_WBS.
      GV_POS = GV_POS + 1.
      IF GS_WBS-WBS_ELEMENT = I_WBS.
            GV_FOUND = 'X'.
            EXIT.
      ENDIF.
ENDLOOP.

IF GV_FOUND IS INITIAL.
      RAISE INVALID_WBS.
ENDIF.

 

**calculate the wbs position in project structure

GV_SELPOS = GV_POS MOD C_ROW.
GV_PGDN = GV_POS / C_ROW.

IF ( GV_PGDN * C_ROW ) > GV_POS.
      GV_PGDN = GV_PGDN - 1.
ENDIF.

IF GV_SELPOS = 0 AND GV_POS NE 0.
      GV_PGDN = GV_PGDN - 1.
      GV_SELPOS = C_ROW.
ENDIF.

 

**Apply BDC options

GV_OPTION-DEFSIZE = 'X'.
GV_OPTION-DISMODE = C_DISMODE.
GV_OPTION-UPDMODE = C_UPDMODE.

GV_POSITION = GV_SELPOS.

 

**Call BDC of CJ20 Trasaction

CONCATENATE 'RCJ_MARKL-MARK(' GV_POSITION ')' INTO GV_POSITION.

PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0108'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'TCJ41-ALL_ACT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=STTR'.
PERFORM BDC_FIELD USING 'PROJ-PSPID'
                                                I_PROJECT.
PERFORM BDC_FIELD USING 'PRPS-POSID'
                                                ''.
PERFORM BDC_FIELD USING 'TCJ41-ALL_ACT'
                                                 ''.

DO GV_PGDN TIMES.
      PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
      PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                        '=P+'.
      PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                        'RCWBS-IDENT(01)'.
ENDDO.

PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                 '=X314'.
PERFORM BDC_FIELD USING GV_POSITION "'RCJ_MARKL-MARK(04)'
                                                                              'X'.

PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                  '=YES'.
PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                  '=YES'.
PERFORM BDC_DYNPRO USING 'SAPLSPO2' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                  '=OPT1'.
PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                   '=BUTV'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWBT-VRGNG_IC(08)'.
CALL TRANSACTION 'CJ20'
      USING GT_BDCDATA
      MESSAGES INTO GT_MESSTAB
      OPTIONS FROM GV_OPTION.

**Tracking messages of BDC

LOOP AT GT_MESSTAB INTO GS_MESSTAB.
      CLEAR : RETURN.
      CALL FUNCTION 'FORMAT_MESSAGE'
            EXPORTING
                  ID = GS_MESSTAB-MSGID
                  LANG = SY-LANGU
                  NO = GS_MESSTAB-MSGNR
                  V1 = RETURN-MESSAGE_V1
                  V2 = RETURN-MESSAGE_V2
                  V3 = RETURN-MESSAGE_V3
                  V4 = RETURN-MESSAGE_V4
            IMPORTING
                  MSG = RETURN-MESSAGE
            EXCEPTIONS
                  NOT_FOUND = 1
            OTHERS = 2.

      RETURN-ID = GS_MESSTAB-MSGID.
      RETURN-NUMBER = GS_MESSTAB-MSGNR.
      RETURN-TYPE = GS_MESSTAB-MSGTYP.
      RETURN-FIELD = GS_MESSTAB-FLDNAME.
      IF RETURN-TYPE <> 'S'.
            GV_OTH = 'X'.
      ENDIF.
      APPEND RETURN.
ENDLOOP.

**raise error when BDC got errors

IF GV_OTH = 'X'.
      RAISE OTHER.
ENDIF.
ENDFUNCTION.

Author: Yajuvendrasinh Raulji & Jeet Bhatt
Submitted: 06/05/2007

Adding WBS Element in Proper Hierarchy from a Text File.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Include ZBAPIWBS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Report Z_BAPI_CJ20N
*&---------------------------------------------------------------------*

REPORT z_bapi_cj20n.

INCLUDE zbapicj20ntop.

INCLUDE zbapicj20nfileup.

INCLUDE zbapicj20nlogic.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NTOP
*&---------------------------------------------------------------------*

DATA: BEGIN OF itmain OCCURS 0,
  project_definition TYPE ps_pspid,
  description TYPE ps_post1,
  project_profile TYPE profidproj,
  bus_area TYPE gsber,
  wbs_element TYPE ps_posid,
  wbs_description TYPE ps_post1,
END OF itmain,
wa_main LIKE LINE OF itmain,
itwbs LIKE STANDARD TABLE OF itmain WITH HEADER LINE,
itmain2 LIKE STANDARD TABLE OF itmain.

DATA: itprjdef TYPE STANDARD TABLE OF bapi_project_definition WITH HEADER LINE,
      wa_prjdef LIKE LINE OF itprjdef.

DATA: itprjdefup TYPE STANDARD TABLE OF bapi_project_definition_up WITH HEADER LINE,
      wa_prjdefup LIKE LINE OF itprjdefup.

DATA: itmetprj TYPE STANDARD TABLE OF bapi_method_project,
      wa_metprj LIKE LINE OF itmetprj.

DATA: return TYPE bapireturn1,msg TYPE STANDARD TABLE OF
        bapi_meth_message WITH HEADER LINE.

DATA: lines TYPE i,refno TYPE i VALUE 0.
DESCRIBE TABLE itmain LINES lines.
DATA: mettype TYPE string VALUE 'Create'.

DATA: wa_dupli LIKE LINE OF itmain.
wa_dupli-project_definition = 'JB'.

DATA: split1(50) TYPE c.
DATA: prevwbs TYPE ps_posid VALUE ' ',
      leftwbs TYPE ps_posid VALUE ' '.
DATA: pos TYPE i VALUE 1.
DATA: off TYPE i VALUE 0,mode TYPE i,index1 TYPE i VALUE 0,
      index2 TYPE i VALUE 0,index3 TYPE i VALUE 0,
      index4 TYPE i VALUE 0,index5 TYPE i VALUE 0,
      pos2 TYPE i VALUE 0,flag TYPE i VALUE 0.

DATA: itbus TYPE STANDARD TABLE OF bapi_bus2054_new,
      wa_bus LIKE LINE OF itbus, ret TYPE STANDARD TABLE OF bapiret2,
      wa_ret LIKE LINE OF ret, itbus2 LIKE STANDARD TABLE OF bapi_bus2054_new,
      wa_bus2 LIKE LINE OF itbus, wa_bus3 LIKE LINE OF itbus.

DATA: bapiret TYPE bapireturn1,
      projex TYPE bapi_project_definition_ex.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NFILEUP
*&---------------------------------------------------------------------*

CALL FUNCTION 'UPLOAD'
  EXPORTING
    filename = ' '
    filetype = 'DAT'
  TABLES
    data_tab = itmain.

*&---------------------------------------------------------------------*
*& Include ZBAPICJ20NLOGIC
*&---------------------------------------------------------------------*

SORT itmain BY project_definition wbs_element.

LOOP AT itmain INTO wa_main.

  IF wa_dupli-project_definition <> wa_main-project_definition.

    wa_prjdef-project_definition = wa_main-project_definition.
    wa_prjdef-description = wa_main-description.
    wa_prjdef-project_profile = wa_main-project_profile.
    wa_prjdef-bus_area = wa_main-bus_area.

    wa_prjdefup-project_definition = 'X'.
    wa_prjdefup-description = 'X'.
    wa_prjdefup-project_profile = 'X'.
    wa_prjdefup-bus_area = 'X'.

    wa_metprj-refnumber = refno + 1 .
    wa_metprj-objecttype = 'ProjectDefinition'.
    wa_metprj-method = mettype.
    wa_metprj-objectkey = wa_main-project_definition.
    APPEND wa_metprj TO itmetprj.

    wa_metprj-refnumber = ''.
    wa_metprj-objecttype = ''.
    wa_metprj-method = 'Save'.
    wa_metprj-objectkey = ''.
    APPEND wa_metprj TO itmetprj.

    CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'
      EXPORTING
        i_project_definition     = wa_prjdef
        i_project_definition_upd = wa_prjdefup
      IMPORTING
        return                   = return
      TABLES
        i_method_project         = itmetprj
        e_message_table          = msg.

    IF sy-subrc = 0.
      flag = 1.
    ENDIF.
    wa_dupli-project_definition = wa_main-project_definition.

    COMMIT WORK.
    DELETE itmetprj FROM 1 TO 2.

    INCLUDE zbapiwbs_all.

  ENDIF.
ENDLOOP.

*&---------------------------------------------------------------------*
*& Include ZBAPIWBS_ALL
*&---------------------------------------------------------------------*
LOOP AT itmain INTO wa_main WHERE project_definition = wa_dupli-project_definition.
  APPEND wa_main TO itwbs.
ENDLOOP.

*Sort the table
LOOP AT itwbs INTO wa_main.
  split1 = wa_main-wbs_element.
  pos = 0.
  LOOP AT itwbs WHERE wbs_element <> split1.

    IF strlen( itwbs-wbs_element ) = strlen( split1 ).
      IF pos = 0.
        APPEND wa_main TO itmain2.
      ENDIF.
      APPEND itwbs TO itmain2.
      DELETE itwbs WHERE wbs_element EQ itwbs-wbs_element.
      pos = 1.
    ELSE.
      IF pos = 0.
        APPEND wa_main TO itmain2.
        DELETE itwbs WHERE wbs_element EQ wa_main.
      ENDIF.
      pos = 1.
    ENDIF.

  ENDLOOP.
  index1 = index1 + 1.
ENDLOOP.

*Define UP element
LOOP AT itmain2 INTO wa_main.

  wa_bus-wbs_element = wa_main-wbs_element.
  wa_bus-description = wa_main-wbs_description.
  wa_bus-wbs_up = ''.
  wa_bus-wbs_left = ''.
  split1 = wa_main-wbs_element.
  LOOP AT itmain2 INTO wa_main WHERE wbs_element <> split1.
    IF strlen( wa_main-wbs_element ) < strlen( split1 ) .
      FIND wa_main-wbs_element IN split1.
      IF sy-subrc = 0.
        wa_bus-wbs_up = wa_main-wbs_element.
        prevwbs = wa_main-wbs_element.
      ENDIF.
    ENDIF.
  ENDLOOP.
  APPEND wa_bus TO itbus.
  index2 = index2 + 1.
ENDLOOP.

prevwbs = ''.
leftwbs = ''.

* Define LEFT ELEMENT.
LOOP AT itmain2 INTO wa_main.

  pos = 0.
  split1 = wa_main-wbs_element.
  READ TABLE itbus INTO wa_bus2 WITH KEY wbs_element = wa_main-wbs_element.
  wa_bus-wbs_element = split1.
  wa_bus-description = wa_main-wbs_description.
  wa_bus-wbs_up = wa_bus2-wbs_up.
  off = sy-tabix.

  LOOP AT itmain2 INTO wa_main WHERE wbs_element <> split1.

    READ TABLE itbus INTO wa_bus3 WITH KEY wbs_element = wa_main-wbs_element.

    IF strlen( wa_bus2-wbs_element ) = strlen( wa_bus3-wbs_element ) AND
    wa_bus2-wbs_up = wa_bus3-wbs_up AND pos = 0.

      IF strlen( leftwbs ) <> strlen( split1 ).
        leftwbs = ''.
      ENDIF.

      IF strlen( leftwbs ) = strlen( split1 ).
        FIND wa_bus2-wbs_up IN leftwbs.
        IF sy-subrc <> 0.
          leftwbs = ''.
        ENDIF.
      ENDIF.

      wa_bus-wbs_left = leftwbs.
      leftwbs = split1.
      pos = 1.
      MODIFY itbus INDEX off FROM wa_bus.
    ENDIF.
  ENDLOOP.

ENDLOOP.

wa_bus-wbs_element = ''.
APPEND wa_bus TO itbus.

* Store WBS ELEMENTS.
LOOP AT itbus INTO wa_bus.
  split1 = wa_bus-wbs_element.
  APPEND wa_bus TO itbus2.
  index3 = 1.
  pos = 0.

  LOOP AT itbus INTO wa_bus WHERE wbs_element <> split1.

    IF strlen( wa_bus-wbs_element ) <> strlen( split1 ) AND pos = 0.
      pos = 1.
      index4 = index3.

      CALL FUNCTION 'BAPI_PS_INITIALIZATION' .

      CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
        EXPORTING
          i_project_definition = wa_dupli-project_definition
        TABLES
          it_wbs_element       = itbus2
          et_return            = ret.

      CALL FUNCTION 'BAPI_PS_PRECOMMIT'
        TABLES
          et_return = ret.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait   = 'X'
        IMPORTING
          return = wa_ret.

    ENDIF.
    APPEND wa_bus TO itbus2.
    index3 = index3 + 1.
  ENDLOOP.

  DELETE itbus2 FROM 1 TO index3.
  DELETE itbus FROM 1 TO index4.

ENDLOOP.

DELETE itwbs FROM 1 TO index1.
CLEAR itwbs.
DELETE itmain2 FROM 1 TO index2.

*At the end of all projects' processing
IF flag = 1.

  CALL FUNCTION 'POPUP_FOR_INTERACTION'
    EXPORTING
      headline = 'PS Project & WBS Creation'
      text1    = 'All the Projects have been created.Please check......'
      ticon    = 'I'
      button_1 = 'OK'.

ELSE.

  CALL FUNCTION 'POPUP_FOR_INTERACTION'
    EXPORTING
      headline = 'Jeet Program'
      text1    = 'No Projects were created...'
      ticon    = 'I'
      button_1 = 'CANCEL'.
ENDIF.

Write this code in TOP include of the Fuction Group

DATA : GS_BDCDATA TYPE BDCDATA, "Table type for BDCDATA
             GS_MESSTAB TYPE BDCMSGCOLL, "Table type to hold messages
             GT_BDCDATA TYPE STANDARD TABLE OF BDCDATA, "Int Table for BDC Data
             GT_MESSTAB TYPE STANDARD TABLE OF BDCMSGCOLL, "Int Table for Messages
             GV_OPTION TYPE CTU_PARAMS.

CONSTANTS : C_DISMODE VALUE 'N', "Mode in which BDC runs
                        C_UPDMODE VALUE 'S'. "Mode in which data loads into SAP
                        

 This code should be write in another include of Function Group

*&---------------------------------------------------------------------*
*& Include LZBAPI_INCLUDE_WBSF01
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Begin New Screen*
*----------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
   CLEAR GS_BDCDATA.
   GS_BDCDATA-PROGRAM = PROGRAM.
   GS_BDCDATA-DYNPRO = DYNPRO.
   GS_BDCDATA-DYNBEGIN = 'X'.
   APPEND GS_BDCDATA TO GT_BDCDATA.
ENDFORM. "BDC_DYNPRO

*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
   CLEAR GS_BDCDATA.
  GS_BDCDATA-FNAM = FNAM.
  GS_BDCDATA-FVAL = FVAL.
  APPEND GS_BDCDATA TO GT_BDCDATA.
ENDFORM. "BDC_FIELD

 

Code for BAPI / FM

FUNCTION ZBAPI_INCLUDE_WBS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_PROJECT) TYPE ZBAPI_INCLUDE_WBS-PROJECT
*" VALUE(I_WBS) TYPE ZBAPI_INCLUDE_WBS-WBS
*" VALUE(I_NEW_WBS) TYPE ZBAPI_INCLUDE_WBS-NEW_WBS
*" VALUE(I_NEW_DESC) TYPE ZBAPI_INCLUDE_WBS-NEW_DESC OPTIONAL
*" TABLES
*" RETURN STRUCTURE BAPIRET2
*" EXCEPTIONS
*" INVALID_PROJECT
*" INVALID_WBS
*" DUPLICATE_WBS
*" OTHER
*"----------------------------------------------------------------------

*Data Declaration

DATA : GT_WBS TYPE STANDARD TABLE OF BAPI_WBS_ELEMENT_EXP,
GS_WBS TYPE BAPI_WBS_ELEMENT_EXP.

DATA : GV_POS TYPE I VALUE 0,
GV_SELPOS TYPE I VALUE 0,
GV_PGDN TYPE I VALUE 0,
GV_POSITION TYPE STRING,
GV_FOUND TYPE CHAR1.

CONSTANTS : C_ROW TYPE I VALUE 12.

*Refresh internal tables and variables

REFRESH : RETURN, GT_BDCDATA, GT_MESSTAB, GT_WBS.
CLEAR : GV_OPTION, GV_POS, GV_SELPOS, GV_PGDN,
GV_POSITION, GV_FOUND, GS_WBS, GS_BDCDATA, GS_MESSTAB.

*Call conversion exit for WBS

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
    EXPORTING
            INPUT = I_WBS
    IMPORTING
            OUTPUT = I_WBS.


CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
    EXPORTING
            INPUT = I_NEW_WBS
    IMPORTING
            OUTPUT = I_NEW_WBS.

*BAPI to get existing structure of PD

CALL FUNCTION 'BAPI_PROJECT_GETINFO'
    EXPORTING
        PROJECT_DEFINITION = I_PROJECT
    TABLES
        E_WBS_ELEMENT_TABLE = GT_WBS.
 

*Check for Invalid PD entered

IF GT_WBS IS INITIAL.
    RAISE INVALID_PROJECT.
ENDIF.

*Call conversion exit for PD

CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
   EXPORTING
          INPUT = I_PROJECT
   IMPORTING
          OUTPUT = I_PROJECT.

*Check for new WBS is already exist

CLEAR : GV_FOUND.
LOOP AT GT_WBS INTO GS_WBS.
    IF GS_WBS-WBS_ELEMENT = I_NEW_WBS.
        GV_FOUND = 'X'.
        EXIT.
    ENDIF.
ENDLOOP.

IF GV_FOUND = 'X'.
    RAISE DUPLICATE_WBS.
ENDIF.

*Get the position of WBS in PD structure

CLEAR : GV_FOUND.
LOOP AT GT_WBS INTO GS_WBS.
    GV_POS = GV_POS + 1.
    IF GS_WBS-WBS_ELEMENT = I_WBS.
        GV_FOUND = 'X'.
        EXIT.
    ENDIF.
ENDLOOP.

*Check for Invalid WBS enterd

IF GV_FOUND IS INITIAL.
    RAISE INVALID_WBS.
ELSE.
     I_NEW_DESC = GS_WBS-DESCRIPTION.
ENDIF.

*Get the page down number and position of WBS in CJ20 Transaction

GV_SELPOS = GV_POS MOD C_ROW.
GV_PGDN = GV_POS / C_ROW.

IF ( GV_PGDN * C_ROW ) > GV_POS.
    GV_PGDN = GV_PGDN - 1.
ENDIF.

IF GV_SELPOS = 0 AND GV_POS NE 0.
   GV_PGDN = GV_PGDN - 1.
   GV_SELPOS = C_ROW.
ENDIF.

*set parameters for BDC

GV_OPTION-DEFSIZE = 'X'.
GV_OPTION-DISMODE = C_DISMODE.
GV_OPTION-UPDMODE = C_UPDMODE.

GV_POSITION = GV_SELPOS.

CONCATENATE 'RCJ_MARKL-MARK(' GV_POSITION ')' INTO GV_POSITION.

*Call BDC for CJ20 Transaction

PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0108'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'TCJ41-ALL_ACT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=STTR'.
PERFORM BDC_FIELD USING 'PROJ-PSPID'
                                                I_PROJECT.
PERFORM BDC_FIELD USING 'PRPS-POSID'
                                                ''.
PERFORM BDC_FIELD USING 'TCJ41-ALL_ACT'
                                                ''.

DO GV_PGDN TIMES.
    PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
    PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                    '=P+'.
    PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                    'RCWBS-IDENT(01)'.
ENDDO.

PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=NETB'.
PERFORM BDC_FIELD USING GV_POSITION "'RCJ_MARKL-MARK(04)'
                                                                           'X'.
PERFORM BDC_DYNPRO USING 'SAPLCJWB' '1544'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=LETV'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWKP-DANEBEN'.
PERFORM BDC_FIELD USING 'RCWKP-INCL_ROOT'
                                                'X'.
PERFORM BDC_FIELD USING 'RCWKP-DANEBEN'
                                                I_WBS.
PERFORM BDC_FIELD USING 'RCWKP-POSIT_RI'
                                                'X'.
PERFORM BDC_FIELD USING 'RCWBT-INCLA'
                                                'X'.
PERFORM BDC_DYNPRO USING 'SAPLCJWB' '0900'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWBS-IDENT(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=NUM2'.
PERFORM BDC_DYNPRO USING 'SAPLCJWB' '0560'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWKP-ERSETZEN'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=NUM2'.
PERFORM BDC_FIELD USING 'RCWKP-SUCHEN'
                                                I_WBS.
PERFORM BDC_FIELD USING 'RCWKP-ERSETZEN'
                                                I_NEW_WBS.
PERFORM BDC_DYNPRO USING 'SAPLCJWB' '0900'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWBS-IDENT(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=NUMC'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWBS-IDENT(01)'.
PERFORM BDC_FIELD USING 'PRPS-POST1(01)'
                                                I_NEW_DESC.
PERFORM BDC_DYNPRO USING 'SAPLCJWB' '0900'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '/ENEB'.
PERFORM BDC_DYNPRO USING 'SAPLCJTR' '0230'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
                                                '=BUTV'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
                                                'RCWBT-VRGNG_IC(04)'.
CALL TRANSACTION 'CJ20'
USING GT_BDCDATA
MESSAGES INTO GT_MESSTAB
OPTIONS FROM GV_OPTION.

*Convert Message from Message Tab

LOOP AT GT_MESSTAB INTO GS_MESSTAB.
      CLEAR : RETURN.
      CALL FUNCTION 'FORMAT_MESSAGE'
            EXPORTING
                  ID = GS_MESSTAB-MSGID
                  LANG = SY-LANGU
                  NO = GS_MESSTAB-MSGNR
                   V1 = RETURN-MESSAGE_V1
                  V2 = RETURN-MESSAGE_V2
                  V3 = RETURN-MESSAGE_V3
                  V4 = RETURN-MESSAGE_V4
            IMPORTING
                  MSG = RETURN-MESSAGE
            EXCEPTIONS
                  NOT_FOUND = 1
            OTHERS = 2.
      

      RETURN-ID = GS_MESSTAB-MSGID.
      RETURN-NUMBER = GS_MESSTAB-MSGNR.
      RETURN-TYPE = GS_MESSTAB-MSGTYP.
      RETURN-FIELD = GS_MESSTAB-FLDNAME.
      APPEND RETURN.
ENDLOOP.

*raise error if BDC give error message
CLEAR : RETURN.

LOOP AT RETURN WHERE TYPE NE 'S'.
      RAISE OTHER.
      ENDLOOP.
ENDFUNCTION.

 

 

Hello Friends

This Snippet Will help you to know how you can set user status in CJ20n TCode automatically. In this we have considered the duration, RAK Key and calculation of POC. CJ20n TCode is related to project Systems. 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-030.
SELECT-OPTIONS : s_date FOR prps-erdat.
PARAMETERS _set LIKE it_wbs_user_status-set_user_status DEFAULT 'RCOG'.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  SELECT pspnr posid tadat
            FROM prps
            INTO TABLE it_project_wbs
            WHERE erdat IN s_date.

*Delete Records where POSID is Zero

  LOOP AT it_project_wbs INTO wa_project_wbs WHERE posid = ' '.
    DELETE it_project_wbs INDEX sy-tabix.
    CLEAR wa_project_wbs.
  ENDLOOP.

*Delete Records which are technically Completed

  LOOP AT it_project_wbs INTO wa_project_wbs WHERE tadat = ' '.
    DELETE it_project_wbs INDEX sy-tabix.
    CLEAR wa_project_wbs.
  ENDLOOP.

  LOOP AT it_project_wbs INTO wa_project_wbs.
    CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT'
      EXPORTING
        input  = wa_project_wbs-posid
      IMPORTING
        output = l_var1.

*Populate the internal table which has to be passed to BAPI

    REFRESH : it_wbs_user_status[], it_bapiret[].
    MOVE l_var1 TO it_wbs_user_status-wbs_element.
    MOVE 'RCOG' TO it_wbs_user_status-set_user_status.
    APPEND it_wbs_user_status.

*To get the WBS element of the finished material

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
      EXPORTING
        input  = wa_project_wbs-posid
      IMPORTING
        output = l_var2.
    WRITE l_var2 TO l_var3.
    IF NOT l_var2 IS INITIAL.
      CALL FUNCTION 'Z_PS_WBS_FAMILY_TREE'
        EXPORTING
          wbs_no        = l_var3
        TABLES
          wbs_tab       = it_prhi
        EXCEPTIONS
          wbs_not_found = 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.

      ELSE.
        REFRESH it_wbs.
        SELECT * FROM prps INTO TABLE it_wbs
                     FOR ALL ENTRIES IN it_prhi
                     WHERE pspnr = it_prhi-posnr.
      ENDIF.

* Collect wbs objects

      LOOP AT it_wbs.
        MOVE it_wbs-pspnr TO it_objnr-ps_psp_pnr.
        MOVE it_wbs-objnr TO it_objnr-objnr.
        APPEND it_objnr.
      ENDLOOP.

* Collect network activities
      SELECT a~aufnr
             a~projn
             b~aufpl
             c~objnr
      APPENDING CORRESPONDING FIELDS OF TABLE it_objnr
      FROM afpo AS a
      INNER JOIN afko AS b
        ON b~aufnr = a~aufnr
      INNER JOIN afvc AS c
        ON c~aufpl = b~aufpl
      FOR ALL ENTRIES IN it_wbs
      WHERE a~projn = it_wbs-pspnr.

* Collect Network & production orders
      SELECT a~aufnr
             b~objnr
      APPENDING CORRESPONDING FIELDS OF TABLE it_objnr
      FROM afpo AS a
      INNER JOIN aufk AS b
        ON b~aufnr = a~aufnr
      FOR ALL ENTRIES IN it_wbs
      WHERE a~projn = it_wbs-pspnr.
      SORT it_objnr BY objnr.
      DELETE ADJACENT DUPLICATES FROM it_objnr COMPARING objnr.
    ENDIF.

*Check Billing Element Indicator and RAK

    SELECT pspnr fakkz objnr abgsl
           FROM prps
           INTO TABLE it_prps
            WHERE posid = wa_project_wbs-posid.
    READ TABLE it_prps INTO wa_prps INDEX 1.

*To Check whether WBS is Technically Complete

    SELECT objnr stat
           FROM jest
           INTO TABLE it_jest
           WHERE objnr = wa_prps-objnr
           AND stat = 'I0045'.
    IF sy-subrc NE 0.

*Check Duration

      SELECT posnr pdaur
             FROM prte
             INTO TABLE it_prte
             WHERE posnr = wa_prps-pspnr.

* Selection of Planned Cost

      SELECT objnr wrttp wlp00
             FROM rpsco
             INTO TABLE it_rpsco
             WHERE objnr = wa_prps-objnr
             AND wrttp = '01'.

*Selection of Actual Cost

      PERFORM calculate_cost_booked.

* Calculation of POC

      IF NOT in_tab-mc_nprei IS INITIAL.
        READ TABLE it_rpsco INTO wa_rpsco INDEX 1.
        IF sy-subrc = 0.
          IF wa_rpsco-wlp00 NE 0.
            poc = ( in_tab-mc_nprei / wa_rpsco-wlp00 ) * 100.
          ENDIF.
        ENDIF.
      ENDIF.
      READ TABLE it_prps INTO wa_prps INDEX 1.
      READ TABLE it_prte INTO wa_prte INDEX 1.
      IF ( wa_prps-fakkz = 'X' AND wa_prps-abgsl = 'EBG007' ).
        IF ( wa_prte-pdaur LT 730 AND poc GE 50 ) OR ( wa_prte-pdaur GT 730 AND poc GE 25 ).
          CLEAR l_return.
          REFRESH lt_e_result.

*Call BAPI

          CALL FUNCTION 'BAPI_PS_INITIALIZATION' .
          CALL FUNCTION 'BAPI_PS_PRECOMMIT'
            TABLES
              et_return = it_bapiret.
          CALL FUNCTION 'BAPI_BUS2054_SET_STATUS'
            IMPORTING
              return            = l_return
            TABLES
              i_wbs_user_status = it_wbs_user_status
              e_result          = lt_e_result.
          IF l_return-type EQ 'E'.
            gv_flg_error = 'X'.
          ENDIF.
          CALL FUNCTION 'BAPI_PS_PRECOMMIT'
            TABLES
              et_return = it_bapiret.
          READ TABLE it_bapiret INTO it_bapiret WITH KEY type = 'E'.
          IF sy-subrc <> 0.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
          ENDIF.
          IF NOT lt_e_result[] IS INITIAL.
            PERFORM send_status_messages TABLES lt_e_result
                                         USING  con_wbs_intern
                                                l_status
                                                'user'.
          ELSEIF NOT l_return IS INITIAL.
            READ TABLE gt_wbs_element
                 WITH KEY wbs_element = it_wbs_user_status-wbs_element.
            l_object_guid = gt_wbs_element-object_guid.
            MESSAGE ID l_return-id
                    TYPE l_return-type
                    NUMBER l_return-number.
            PERFORM send_message USING
                    space space l_object_guid space space l_return-message.
          ENDIF.
        ENDIF.
        WRITE: /5 sy-vline.
        WRITE : l_var1 UNDER text-031.
        WRITE:  30 sy-vline.
        WRITE :  poc UNDER text-032.
        WRITE : 60 sy-vline.
        ULINE /5(56).
      ENDIF.
      CLEAR : temp, wa_rpsco, wa_mseg, wa_project_wbs, it_wbs_user_status.  " poc.
    ENDIF.
    REFRESH it_objnr.
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  send_status_messages
*&---------------------------------------------------------------------*
FORM send_status_messages TABLES it_status_result TYPE
                                                    gt_status_result
                          USING  i_obj_type TYPE c
                                 i_status LIKE
                                          gt_status-business_transaction
                                 i_status_type TYPE c.
  DATA: ls_messages LIKE gt_messages,
        l_activity LIKE gt_activity-activity,
        l_network LIKE gt_activity-network,
        l_network_ext LIKE gt_activity-network,
        l_objnr_ext LIKE it_status_result-objectkey.
  IF i_status_type EQ 'sys'.
    ls_messages-status = i_status.
  ELSEIF i_status_type EQ 'user'.
    ls_messages-user_status = i_status.
  ENDIF.

  LOOP AT it_status_result.
    MOVE-CORRESPONDING it_status_result TO ls_messages.
    CASE i_obj_type.
      WHEN con_act_intern.
        l_network = it_status_result-objectkey(12).
        l_activity = it_status_result-objectkey+12(4).
        IF NOT l_activity IS INITIAL.
          READ TABLE gt_activity WITH KEY network = l_network
                                          activity = l_activity.
          IF sy-subrc IS INITIAL.
            ls_messages-source_type = gt_activity-source_type.
            ls_messages-object_guid = gt_activity-object_guid.
          ENDIF.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
            EXPORTING
              input  = l_network
            IMPORTING
              output = l_network_ext.
          CONCATENATE l_network_ext '/' l_activity
                      INTO l_objnr_ext.
        ELSE.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
            EXPORTING
              input  = l_network
            IMPORTING
              output = l_objnr_ext.
        ENDIF.
        IF NOT l_objnr_ext IS INITIAL.
          ls_messages-ext_object_id = l_objnr_ext.
        ELSE.
          ls_messages-ext_object_id = it_status_result-objectkey.
        ENDIF.
      WHEN con_wbs_intern.
        READ TABLE gt_wbs_element
             WITH KEY wbs_element = it_status_result-objectkey.
        IF sy-subrc IS INITIAL.
          ls_messages-source_type = gt_wbs_element-source_type.
          ls_messages-object_guid = gt_wbs_element-object_guid.
        ELSE.
          READ TABLE gt_project_definition
               WITH KEY project_definition = it_status_result-objectkey.
          IF sy-subrc IS INITIAL.
            ls_messages-source_type = gt_project_definition-source_type.
            ls_messages-object_guid = gt_project_definition-object_guid.
          ENDIF.
        ENDIF.
        ls_messages-ext_object_id = it_status_result-objectkey.
      WHEN con_pd_intern.
        READ TABLE gt_project_definition
             WITH KEY project_definition = it_status_result-objectkey.
        IF sy-subrc IS INITIAL.
          ls_messages-source_type = gt_project_definition-source_type.
          ls_messages-object_guid = gt_project_definition-object_guid.
        ENDIF.
        ls_messages-ext_object_id = it_status_result-objectkey.
    ENDCASE.
    APPEND ls_messages TO gt_messages.
  ENDLOOP.
ENDFORM.                    " send_status_messages
*&---------------------------------------------------------------------*
*&      Form  send_message
*&---------------------------------------------------------------------*
FORM send_message USING i_action LIKE gt_messages-action
                        i_source_type LIKE gt_messages-source_type
                        i_object_guid LIKE gt_messages-object_guid
                        i_ext_object_id LIKE gt_messages-ext_object_id
                        i_int_object_id LIKE gt_messages-int_object_id
                        i_text LIKE bapiret2-message.
  gt_messages-action = i_action.
  gt_messages-source_type = i_source_type.
  gt_messages-object_guid = i_object_guid.
  gt_messages-ext_object_id = i_ext_object_id.
  gt_messages-int_object_id = i_int_object_id.
  gt_messages-message_type = sy-msgty.
  gt_messages-message_id = sy-msgid.
  gt_messages-message_number = sy-msgno.
  gt_messages-message_v1 = sy-msgv1.
  gt_messages-message_v2 = sy-msgv2.
  IF sy-msgty EQ 'S' AND
   sy-msgid EQ 'CNIF_PI'.
    IF sy-msgv1 EQ con_pd_intern OR
       sy-msgv1 EQ con_wbs_intern.
      CALL FUNCTION 'CJPN_PROJEKTNUMMER_UNEDIT'
        EXPORTING
          input  = gt_messages-message_v2
        IMPORTING
          output = gt_messages-message_v2.
    ENDIF.
  ENDIF.
  gt_messages-message_v3 = sy-msgv3.
  gt_messages-message_v4 = sy-msgv4.
  gt_messages-message_text = i_text.
  APPEND gt_messages.
ENDFORM.                    " send_message
*&---------------------------------------------------------------------*
*&      Form  calculate_cost_booked
*&---------------------------------------------------------------------*
FORM calculate_cost_booked.
  DATA : lit_rpsco LIKE rpsco OCCURS 0 WITH HEADER LINE.
  DATA : lv_tot_val LIKE rpsco-wlp00.
  DATA : lv_str(11) TYPE c.
  DATA : lv_counter(2) TYPE n.
  FIELD-SYMBOLS : <wlp> TYPE rpsco-wlp00.
  CLEAR in_tab-mc_nprei.
  LOOP AT it_objnr.
    CLEAR lv_tot_val.
    SELECT * FROM rpsco WHERE objnr = it_objnr-objnr AND
                               lednr = v_lednr AND
                              ( wrttp = '04' OR wrttp = '11' ) AND
                              beltp = '1'.
      DO 17 TIMES.
        lv_counter = sy-index - 1.
        CONCATENATE 'RPSCO-WLP' lv_counter INTO lv_str.
        ASSIGN (lv_str) TO <wlp>.
        lv_tot_val = lv_tot_val + <wlp>.
      ENDDO.
    ENDSELECT.
    IF lv_tot_val > 0.
      MOVE it_objnr-ps_psp_pnr TO it_items-ps_psp_pnr.
      MOVE it_objnr-objnr TO it_items-objnr.
      it_items-stprs = lv_tot_val.
      SELECT SINGLE matnr INTO it_items-matnr FROM vbap
                 WHERE ps_psp_pnr = it_objnr-ps_psp_pnr.
      APPEND it_items.
    ENDIF.
    in_tab-mc_nprei = in_tab-mc_nprei + lv_tot_val.
  ENDLOOP.
ENDFORM.                    " calculate_cost_booked
*&---------------------------------------------------------------------*
*&      Form  get_ledger
*&---------------------------------------------------------------------*
FORM get_ledger .
  CALL FUNCTION 'CATT_KBPS_FIND_LEDGER'
    EXPORTING
      kokrs     = '0003'
    IMPORTING
      ledger    = v_lednr
    EXCEPTIONS
      no_ledger = 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.
ENDFORM.                    " get_ledger

  • No labels