1

I am required to create a custom report that bulk uploads the PROJ table, that has around 8 custom fields that have been created by a Fiori app, the data to be updated would be provided as a CSV file and would have the project id for which the data has to be created.

The fields as created are visible in transaction codes CJ20N and CJ02.

The issue is that despite having the data added, the BAPI is not giving any error and no data is getting updated.

Please help me resolve this issue or suggest an alternative solution to achieve the required.

Following is my code so far, based on BAPI_PS_INITIALIZATION, BAPI_BUS2001_CHANGE, BAPI_PS_PRECOMMIT and BAPI_TRANSACTION_COMMIT:

REPORT z_bulk_proj_upload.
TYPES: BEGIN OF ty_data,
         project          TYPE ps_pspnr,
         vip_id(18)       TYPE c, "VIP ID
         category(30)     TYPE c, "LA Category
         worktype(30)     TYPE c, "LA WorkType
         projtype(30)     TYPE c, "LA ProjectType
         region(30)       TYPE c, "Region
         alpharisk(20)    TYPE c, "AlphaRiskControl
         vipcontrol(3)    TYPE c, "VIP Control
         viprevised(3)    TYPE c, "VIP Revised Control
         majorproject(1)  TYPE c, "Major Project Threshold
         dateofinteg(10)  TYPE c, "Date of integration
         filenumber(16)   TYPE c, "File Number Regie
         decisiondate(10) TYPE c, "Decision Date Regie
         approval(10)     TYPE c, "Approval

       END OF ty_data,
       BEGIN OF lty_rawdata,
         rawdata(40000) TYPE c,
       END OF lty_rawdata.

DATA: it_data                   TYPE STANDARD TABLE OF ty_data,
      lwa_data                  TYPE ty_data,
      lv_file                   TYPE string,
      it_rawdata                TYPE STANDARD TABLE OF lty_rawdata,
      lwa_rawdata               TYPE lty_rawdata,
      lr_csv                    TYPE REF TO cl_rsda_csv_converter,
      lt_fichier                TYPE filetable,
      l_rc                      TYPE i,
      lv_length                 TYPE i,
      lv_size                   TYPE i,
      ls_proj                   TYPE proj,
      wa_custstr                TYPE bapi_te_project_definition,
      ls_project_definition     TYPE bapi_bus2001_chg,
      ls_project_definition_upd TYPE bapi_bus2001_upd,
      lt_return                 TYPE STANDARD TABLE OF bapiret2,
      lt_return1                TYPE bapiret2,
      lt_extensionin            TYPE STANDARD TABLE OF bapiparex INITIAL SIZE 0 WITH HEADER LINE.


INITIALIZATION.
  CLEAR: lv_size, it_data.

  SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE TEXT-b05.
  PARAMETERS: p_file  TYPE rlgrap-filename LOWER CASE,
              p_upld  RADIOBUTTON GROUP grz DEFAULT 'X',
              p_dwnld RADIOBUTTON GROUP grz.
  SELECTION-SCREEN END OF BLOCK b4.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE TEXT-b05.
  PARAMETERS: p_file  TYPE rlgrap-filename LOWER CASE,
              p_upld  RADIOBUTTON GROUP grz DEFAULT 'X',
              p_dwnld RADIOBUTTON GROUP grz.
  SELECTION-SCREEN END OF BLOCK b4.

START-OF-SELECTION.

  IF p_upld IS NOT INITIAL.
    lv_file = p_file.

    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename                = lv_file
      CHANGING
        data_tab                = it_rawdata[]
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        bad_data_format         = 8
        header_not_allowed      = 9
        separator_not_allowed   = 10
        header_too_long         = 11
        unknown_dp_error        = 12
        access_denied           = 13
        dp_out_of_memory        = 14
        disk_full               = 15
        dp_timeout              = 16
        not_supported_by_gui    = 17
        error_no_gui            = 18
        OTHERS                  = 19.
    IF sy-subrc <> 0.
      MESSAGE 'Error in Upload' TYPE 'E'.
    ELSE.
      DESCRIBE TABLE it_data LINES DATA(lv_line).
    ENDIF.

    CALL METHOD cl_rsda_csv_converter=>create
      RECEIVING
        r_r_conv = lr_csv.

    LOOP AT it_rawdata INTO lwa_rawdata.
      TRY.
          "Populate raw data into separate fields in structure
          CALL METHOD lr_csv->csv_to_structure
            EXPORTING
              i_data   = lwa_rawdata
            IMPORTING
              e_s_data = lwa_data.
        CATCH cx_root ##CATCH_ALL.
          "Error during data conversion
          MESSAGE TEXT-005 TYPE 'S' DISPLAY LIKE 'E'.
          LEAVE LIST-PROCESSING.
      ENDTRY.
      APPEND lwa_data TO it_data.
    ENDLOOP.
  ENDIF.

  IF it_data IS NOT INITIAL.
    LOOP AT it_data INTO lwa_data.
      SELECT SINGLE * INTO ls_proj FROM proj WHERE pspid = lwa_data-project.
      lt_extensionin-structure = 'BAPI_TE_PROJECT_DEFINITION'.
      lt_extensionin-valuepart1+0(24) = ls_proj-pspid.
      APPEND lt_extensionin.


      CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
      ls_project_definition-project_definition = ls_proj-pspid.
      ls_project_definition_upd-zz1_vipid_psd = lwa_data-vip_id.
      ls_project_definition_upd-zz1_lacategory_psd = lwa_data-category.
      ls_project_definition_upd-zz1_laworktype_psd = lwa_data-worktype.
      ls_project_definition_upd-zz1_laprojecttype_psd = lwa_data-projtype.
      ls_project_definition_upd-zz1_region_psd = lwa_data-region.
      ls_project_definition_upd-zz1_alphariskgrade1_psd = lwa_data-alpharisk.
      ls_project_definition_upd-zz1_vipcontrolnonc_psd = lwa_data-vipcontrol.
      ls_project_definition_upd-zz1_viprevisedcontroln_psd = lwa_data-viprevised.
      ls_project_definition_upd-zz1_majorprojectsthres_psd = lwa_data-project.
      ls_project_definition_upd-zz1_dateofintegrationi_psd = lwa_data-dateofinteg.
      ls_project_definition_upd-zz1_filenumberrgie_psd = lwa_data-filenumber.
      ls_project_definition_upd-zz1_decisiondatergie_psd = lwa_data-decisiondate.
      ls_project_definition_upd-zz1_approval_psd = lwa_data-approval.


      CALL FUNCTION 'BAPI_BUS2001_CHANGE'
        EXPORTING
          i_project_definition     = ls_project_definition
          i_project_definition_upd = ls_project_definition_upd
        TABLES
          et_return                = lt_return.
* extensionin = lt_extensionin.

      CALL FUNCTION 'BAPI_PS_PRECOMMIT'
        TABLES
          et_return = lt_return.

      REFRESH lt_return.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait   = 'X'
        IMPORTING
          return = lt_return1.
    ENDLOOP.
  ENDIF.
3
  • 1
    Please create a minimal reproducible example (also readable, dumping unformatted code will likely not encourage answerers to dig through it) Commented Jan 20, 2022 at 13:37
  • @JonasWilms this is the minimal reproducible example/formatted code in context to SAP ABAP, without the complete information, there is very little that u can perhaps do.
    – Bhanu
    Commented Jan 20, 2022 at 13:46
  • phil is correct, check how to pass custom fields to BAPI_BUS2001_CHANGE here
    – Suncatcher
    Commented Feb 3, 2022 at 17:38

1 Answer 1

2

i_project_definition is for the update flag not the actual value.

ls_project_definition-fieldxyz = 'SOME VALUE'.
ls_project_definition_upd-fieldxyz  = 'X'. "  should have the value 'X' !!!

the code you supplied suggests the interface was not called properly.

Furthermore for Z fields normally they are passed in via EXTENSIONIN not via BAPI_BUS2001_CHG and BAPI_BUS2001_UPD.

FUNCTION BAPI_BUS2001_CHANGE
  IMPORTING
    VALUE(I_PROJECT_DEFINITION) LIKE BAPI_BUS2001_CHG
    VALUE(I_PROJECT_DEFINITION_UPD) LIKE BAPI_BUS2001_UPD
  TABLES
    ET_RETURN LIKE BAPIRET2 OPTIONAL
    EXTENSIONIN LIKE BAPIPAREX OPTIONAL     "<<<<<<<<<<<<< HERE
    EXTENSIONOUT LIKE BAPIPAREX OPTIONAL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.