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

Currency problem in BAPI_MATERIAL_SAVEDATA while uploading valuation class

Former Member
0 Likes
653

Hello Experts,

I am uploading valuation class using BAPI_MATERIAL_SAVEDATA.

While uploading it is showing runtime error "Unable to interpret KG as a number".

I have used the FM CONVERSION_EXIT_CUNIT_INPUT to convert the UOM from the file to Field symbol.

still the same. please guide me.

I have pasted my code below.

Kindly go through and help would be highly appreciated.


*&---------------------------------------------------------------------*
*& Report  ZPRI_MAT_PRICE_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZPRI_MAT_PRICE_UPLOAD no standard page heading line-size 150.


tables : mbew,      " Material valuation
         makt,      " Material description
         mara.      " General material master


data : begin of t_matvclass occurs 0,
       material type matnr,     " Material
       ind_sec type mbrsh,      " Industry sector
       mat_typ type mtart,      " Material type
       val_class type BKLAS,    " Valuation class
       MOV_PR TYPE VERPR,       " MOVING PRISE
       STD_PR TYPE STPRS,       " STANDARD PRISE
       base_uom like mara-meins,     " Material unit
       mat_desc type maktx,     " Material description - MAKTX
       plant type werks,        " Plant
       langu(2),
       end of t_matvclass.
data : wa like line of t_matvclass.

data: begin of it_makt occurs 0.
      include structure bapi_makt.
      data end of it_makt.


data :bapi_head like bapimathead,     " Header Segment with Control Info
      bapi_clientdata like bapi_mara,    " Material Data at Client Level
      bapi_clientdatax like bapi_marax,  "Checkbox Structure
      bapi_valclass like BAPI_MBEW,      " Valuation class
      bapi_valclassx like BAPI_MBEWX,    " Checkbox Structure
*      BAPI_MOVING_PR LIKE BAPI_MBEW,     "MOVING PRISE
*      BAPI_MOVING_PRX LIKE BAPI_MBEWX,   "MOVING PRISE
*      BAPI_STD_PRISE LIKE BAPI_MBEW,     "STANDARD PRISE
*      BAPI_STD_PRISEX LIKE BAPI_MBEWX,   "STANDARD PRISE
      bapi_return like bapiret2,         " Bapi return structrue
      returnm type table of bapi_matreturn2 with header line.

data : it_excel type alsmex_tabline occurs 0 with header line.

data: begin of it_ret occurs 0.
       include structure bapiret2.
      data end of it_ret.


* Data objects for exception handling.
data : lv_converr type ref to CX_SY_CONVERSION_ERROR,
       lv_dynerr type ref to CX_SY_DYN_CALL_ERROR.
data : txt_converr type string,
       txt_converr_l type string,
       txt_dynerr type string,
       txt_dynerr_l type string.

data : char_uom(4) type c.    " Global UOM after conversion


* Declaring selection screen for selecting a data file
* for uploading valuation class

selection-screen begin of block b1 with frame title text-001.
parameter : file_nam type rlgrap-filename obligatory default
              'C:\master data UPDATED_test.xls'.
parameter : p_begcol type i default 1,        " no-display,
            p_begrow type i default 2,        "   no-display,
            p_endcol type i default 9,        " no-display,
            p_endrow type i default 267.      " no-display.
*parameters: p_valare type mbew-bwkey obligatory.    " Valuation area
selection-screen end of block b1.

at selection-screen on value-request for file_nam.
perform F_get_file using file_nam.

start-of-selection.
perform F_xls_itab using file_nam changing it_excel.
perform F_move_data.
*perform F_get_data.
perform F_Display_data.

*&---------------------------------------------------------------------*
*&      Form  F_xls_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILE_NAM  text
*      <--P_IT_EXCEL  text
*----------------------------------------------------------------------*
form F_xls_itab  using    p_file_nam changing p_it_excel.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    filename                      = file_nam
    i_begin_col                   = p_begcol
    i_begin_row                   = p_begrow
    i_end_col                     = p_endcol
    i_end_row                     = p_endrow
  tables
    intern                        = it_excel
 EXCEPTIONS
   INCONSISTENT_PARAMETERS       = 1
   UPLOAD_OLE                    = 2
   OTHERS                        = 3.
endform.                    " F_xls_itab

*&---------------------------------------------------------------------*
*&      Form  F_get_file
*&---------------------------------------------------------------------*
*     Subroutine to get the file on F4
*----------------------------------------------------------------------*
*      -->P_FILE_NAM  text
*----------------------------------------------------------------------*
form F_get_file  using    p_file_nam.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
 EXPORTING
   PROGRAM_NAME        = SYST-REPID
   DYNPRO_NUMBER       = SYST-DYNNR
*   FIELD_NAME          = ' '
*   STATIC              = ' '
*   MASK                = ' '
  CHANGING
    file_name           = file_nam
 EXCEPTIONS
   MASK_TOO_LONG       = 1
   OTHERS              = 2.

endform.                    " F_get_file

*&---------------------------------------------------------------------*
*&      Form  F_Display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_Display_data .

skip 2.
*write:/2 'Valuation area :', p_valare.
*write:/2 'Standard price :', p_stdprc.
skip 2.

  write:/29 sy-uline(120).
  write:/29 sy-vline,
         30 'Material' color 1,               " Material - MATNR
         50 sy-vline, 'Ind_sector' color 1,   " Industry sector  - MBRSH
         62 sy-vline, 'Mat_typ' color 1,   " Material type - MTART
         75 sy-vline, 'Valuation class' color 1,  " Valuation class
         85 sy-vline, 'Base UOM' color 1,          " Base UOM
         95 sy-vline, 'Material Decp' color 1,     " Material descp
         120 sy-vline, 'Mov Price',                 " Moving price
         130 sy-vline, 'Std Price',                 " Standard price
         140 sy-vline, 'Plant',                     " Plant
         150 sy-vline.


  write:/29 sy-uline(120).


loop at t_matvclass into wa.
  write:/29 sy-vline,
         30 wa-material color 2,               " Material - MATNR
         50 sy-vline,
         55 wa-ind_sec color 2 right-justified, " Industry sector
         62 sy-vline,
         66 wa-mat_typ color 2,                " Material type - MTART
         75 sy-vline,
         78 wa-val_class color 2 right-justified, " Valuation class
         85 sy-vline,
         88 wa-base_uom color 2 right-justified,  " Base UOM
         95 sy-vline,
         98 wa-mat_desc color 2 left-justified,  " Material Desc
         120 sy-vline, wa-MOV_PR,                 " Standard price
         130 sy-vline, wa-STD_PR,                 " Moving price
         140 sy-vline, wa-plant,                     " Plant

         150 sy-vline.

endloop.
write:/29 sy-uline(64).
endform.                    " F_Display_data

*&---------------------------------------------------------------------*
*&      Form  F_move_data
*&---------------------------------------------------------------------*
*      Subroutine to move data from excel to internal table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_move_data .

data : lv_index type i.
field-symbols <fs>.

* Sorting the internal table
sort it_excel by row col.
clear it_excel.

loop at it_excel.
  move it_excel-col to lv_index.
* Assigning each record to the internal table row.
  assign component lv_index of structure wa to <fs>.

* Assigning the field value to a field symbol
if lv_index eq 5.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
  EXPORTING
    INPUT                = it_excel-value
   LANGUAGE             = SY-LANGU
 IMPORTING
   OUTPUT               = char_uom.
** Moving the converted UOM to  field symbol
 move char_uom to <fs>.

 else.
   move it_excel-value to <fs>.
 endif.

  at end of row.
  append wa to t_matvclass.
  clear wa.
  endat.

endloop.
endform.                    " F_move_data
*&---------------------------------------------------------------------*
*&      Form  F_get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_get_data .

loop at t_matvclass into wa.
try.

* BAPIHEAD --- > Header Segment with Control Information
bapi_head-material = wa-material.
bapi_head-ind_sector = wa-ind_sec.
bapi_head-matl_type = wa-mat_typ.
bapi_head-account_view = 'X'.


* For Clien Data
 bapi_clientdata-BASE_UOM = wa-base_uom.
 bapi_clientdatax-base_uom = 'X'.
 bapi_clientdatax-base_uom_iso = 'X'.

* For Valuation Class.

bapi_valclass-val_area = wa-plant.
bapi_valclass-val_class = wa-val_class.
bapi_valclass-std_price = wa-STD_PR.
bapi_valclass-MOVING_PR = wa-MOV_PR.

* For Valuation Class control checkbox.

bapi_valclassx-val_area = wa-plant.
bapi_valclassx-val_class = 'X'.
bapi_valclassx-std_price = 'X'.
bapi_valclass-MOVING_PR = 'X'.


refresh it_makt.
wa-langu = SY-LANGU.
it_makt-langu = wa-langu.
it_makt-matl_desc = wa-mat_desc.
append it_makt.

clear it_ret.
refresh it_ret.

if t_matvclass[] is initial.
  write:/ 'Cannot be updated'.
else.
perform F_call_bapi.
endif.

catch CX_SY_CONVERSION_ERROR into lv_converr.
   txt_converr = lv_converr->get_text( ).
   txt_converr_l = lv_converr->get_longtext( ).
   write:/ 'Error:', txt_converr color 5.
   write:/ 'Error:', txt_converr_l color 3.
endtry.

endloop.
endform.                    " F_get_data

*&---------------------------------------------------------------------*
*&      Form  F_bapi_commit
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_bapi_commit.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
.

if sy-subrc eq 0.
  write:/2 ' Transaction commited' color 4.
else.
  write:/2 'Unable to commit the transaction' color 4.
endif.
endform.                    " F_bapi_commit

*&---------------------------------------------------------------------*
*&      Form  F_call_bapi
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_call_bapi .

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata                  = bapi_head
    CLIENTDATA                 = bapi_clientdata
    CLIENTDATAX                = bapi_clientdatax
    VALUATIONDATA              = bapi_valclass
    VALUATIONDATAX             = bapi_valclassx
 IMPORTING
   RETURN                     = it_ret
 TABLES
   MATERIALDESCRIPTION        =  it_makt
   RETURNMESSAGES        =  returnm.

   IF it_ret-type eq 'E' or it_ret-TYPE eq 'S'.
     Write:/1 it_ret-type,
            8 it_ret-id,
            30 it_ret-number,
            38 it_ret-message,
            190 it_ret-parameter,
            210 it_ret-row,
            220 it_ret-field.
   endif.

endform.                    " F_call_bapi

Regards,

Ranjith N

Hello Experts,

I am uploading valuation class using BAPI_MATERIAL_SAVEDATA.

While uploading it is showing runtime error "Unable to interpret KG as a number".

I have used the FM CONVERSION_EXIT_CUNIT_INPUT to convert the UOM from the file to Field symbol.

still the same. please guide me.

I have pasted my code below.

Kindly go through and help would be highly appreciated.


*&---------------------------------------------------------------------*
*& Report  ZPRI_MAT_PRICE_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZPRI_MAT_PRICE_UPLOAD no standard page heading line-size 150.


tables : mbew,      " Material valuation
         makt,      " Material description
         mara.      " General material master


data : begin of t_matvclass occurs 0,
       material type matnr,     " Material
       ind_sec type mbrsh,      " Industry sector
       mat_typ type mtart,      " Material type
       val_class type BKLAS,    " Valuation class
       MOV_PR TYPE VERPR,       " MOVING PRISE
       STD_PR TYPE STPRS,       " STANDARD PRISE
       base_uom like mara-meins,     " Material unit
       mat_desc type maktx,     " Material description - MAKTX
       plant type werks,        " Plant
       langu(2),
       end of t_matvclass.
data : wa like line of t_matvclass.

data: begin of it_makt occurs 0.
      include structure bapi_makt.
      data end of it_makt.


data :bapi_head like bapimathead,     " Header Segment with Control Info
      bapi_clientdata like bapi_mara,    " Material Data at Client Level
      bapi_clientdatax like bapi_marax,  "Checkbox Structure
      bapi_valclass like BAPI_MBEW,      " Valuation class
      bapi_valclassx like BAPI_MBEWX,    " Checkbox Structure
*      BAPI_MOVING_PR LIKE BAPI_MBEW,     "MOVING PRISE
*      BAPI_MOVING_PRX LIKE BAPI_MBEWX,   "MOVING PRISE
*      BAPI_STD_PRISE LIKE BAPI_MBEW,     "STANDARD PRISE
*      BAPI_STD_PRISEX LIKE BAPI_MBEWX,   "STANDARD PRISE
      bapi_return like bapiret2,         " Bapi return structrue
      returnm type table of bapi_matreturn2 with header line.

data : it_excel type alsmex_tabline occurs 0 with header line.

data: begin of it_ret occurs 0.
       include structure bapiret2.
      data end of it_ret.


* Data objects for exception handling.
data : lv_converr type ref to CX_SY_CONVERSION_ERROR,
       lv_dynerr type ref to CX_SY_DYN_CALL_ERROR.
data : txt_converr type string,
       txt_converr_l type string,
       txt_dynerr type string,
       txt_dynerr_l type string.

data : char_uom(4) type c.    " Global UOM after conversion


* Declaring selection screen for selecting a data file
* for uploading valuation class

selection-screen begin of block b1 with frame title text-001.
parameter : file_nam type rlgrap-filename obligatory default
              'C:\master data UPDATED_test.xls'.
parameter : p_begcol type i default 1,        " no-display,
            p_begrow type i default 2,        "   no-display,
            p_endcol type i default 9,        " no-display,
            p_endrow type i default 267.      " no-display.
*parameters: p_valare type mbew-bwkey obligatory.    " Valuation area
selection-screen end of block b1.

at selection-screen on value-request for file_nam.
perform F_get_file using file_nam.

start-of-selection.
perform F_xls_itab using file_nam changing it_excel.
perform F_move_data.
*perform F_get_data.
perform F_Display_data.

*&---------------------------------------------------------------------*
*&      Form  F_xls_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILE_NAM  text
*      <--P_IT_EXCEL  text
*----------------------------------------------------------------------*
form F_xls_itab  using    p_file_nam changing p_it_excel.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    filename                      = file_nam
    i_begin_col                   = p_begcol
    i_begin_row                   = p_begrow
    i_end_col                     = p_endcol
    i_end_row                     = p_endrow
  tables
    intern                        = it_excel
 EXCEPTIONS
   INCONSISTENT_PARAMETERS       = 1
   UPLOAD_OLE                    = 2
   OTHERS                        = 3.
endform.                    " F_xls_itab

*&---------------------------------------------------------------------*
*&      Form  F_get_file
*&---------------------------------------------------------------------*
*     Subroutine to get the file on F4
*----------------------------------------------------------------------*
*      -->P_FILE_NAM  text
*----------------------------------------------------------------------*
form F_get_file  using    p_file_nam.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
 EXPORTING
   PROGRAM_NAME        = SYST-REPID
   DYNPRO_NUMBER       = SYST-DYNNR
*   FIELD_NAME          = ' '
*   STATIC              = ' '
*   MASK                = ' '
  CHANGING
    file_name           = file_nam
 EXCEPTIONS
   MASK_TOO_LONG       = 1
   OTHERS              = 2.

endform.                    " F_get_file

*&---------------------------------------------------------------------*
*&      Form  F_Display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_Display_data .

skip 2.
*write:/2 'Valuation area :', p_valare.
*write:/2 'Standard price :', p_stdprc.
skip 2.

  write:/29 sy-uline(120).
  write:/29 sy-vline,
         30 'Material' color 1,               " Material - MATNR
         50 sy-vline, 'Ind_sector' color 1,   " Industry sector  - MBRSH
         62 sy-vline, 'Mat_typ' color 1,   " Material type - MTART
         75 sy-vline, 'Valuation class' color 1,  " Valuation class
         85 sy-vline, 'Base UOM' color 1,          " Base UOM
         95 sy-vline, 'Material Decp' color 1,     " Material descp
         120 sy-vline, 'Mov Price',                 " Moving price
         130 sy-vline, 'Std Price',                 " Standard price
         140 sy-vline, 'Plant',                     " Plant
         150 sy-vline.


  write:/29 sy-uline(120).


loop at t_matvclass into wa.
  write:/29 sy-vline,
         30 wa-material color 2,               " Material - MATNR
         50 sy-vline,
         55 wa-ind_sec color 2 right-justified, " Industry sector
         62 sy-vline,
         66 wa-mat_typ color 2,                " Material type - MTART
         75 sy-vline,
         78 wa-val_class color 2 right-justified, " Valuation class
         85 sy-vline,
         88 wa-base_uom color 2 right-justified,  " Base UOM
         95 sy-vline,
         98 wa-mat_desc color 2 left-justified,  " Material Desc
         120 sy-vline, wa-MOV_PR,                 " Standard price
         130 sy-vline, wa-STD_PR,                 " Moving price
         140 sy-vline, wa-plant,                     " Plant

         150 sy-vline.

endloop.
write:/29 sy-uline(64).
endform.                    " F_Display_data

*&---------------------------------------------------------------------*
*&      Form  F_move_data
*&---------------------------------------------------------------------*
*      Subroutine to move data from excel to internal table
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_move_data .

data : lv_index type i.
field-symbols <fs>.

* Sorting the internal table
sort it_excel by row col.
clear it_excel.

loop at it_excel.
  move it_excel-col to lv_index.
* Assigning each record to the internal table row.
  assign component lv_index of structure wa to <fs>.

* Assigning the field value to a field symbol
if lv_index eq 5.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
  EXPORTING
    INPUT                = it_excel-value
   LANGUAGE             = SY-LANGU
 IMPORTING
   OUTPUT               = char_uom.
** Moving the converted UOM to  field symbol
 move char_uom to <fs>.

 else.
   move it_excel-value to <fs>.
 endif.

  at end of row.
  append wa to t_matvclass.
  clear wa.
  endat.

endloop.
endform.                    " F_move_data
*&---------------------------------------------------------------------*
*&      Form  F_get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_get_data .

loop at t_matvclass into wa.
try.

* BAPIHEAD --- > Header Segment with Control Information
bapi_head-material = wa-material.
bapi_head-ind_sector = wa-ind_sec.
bapi_head-matl_type = wa-mat_typ.
bapi_head-account_view = 'X'.


* For Clien Data
 bapi_clientdata-BASE_UOM = wa-base_uom.
 bapi_clientdatax-base_uom = 'X'.
 bapi_clientdatax-base_uom_iso = 'X'.

* For Valuation Class.

bapi_valclass-val_area = wa-plant.
bapi_valclass-val_class = wa-val_class.
bapi_valclass-std_price = wa-STD_PR.
bapi_valclass-MOVING_PR = wa-MOV_PR.

* For Valuation Class control checkbox.

bapi_valclassx-val_area = wa-plant.
bapi_valclassx-val_class = 'X'.
bapi_valclassx-std_price = 'X'.
bapi_valclass-MOVING_PR = 'X'.


refresh it_makt.
wa-langu = SY-LANGU.
it_makt-langu = wa-langu.
it_makt-matl_desc = wa-mat_desc.
append it_makt.

clear it_ret.
refresh it_ret.

if t_matvclass[] is initial.
  write:/ 'Cannot be updated'.
else.
perform F_call_bapi.
endif.

catch CX_SY_CONVERSION_ERROR into lv_converr.
   txt_converr = lv_converr->get_text( ).
   txt_converr_l = lv_converr->get_longtext( ).
   write:/ 'Error:', txt_converr color 5.
   write:/ 'Error:', txt_converr_l color 3.
endtry.

endloop.
endform.                    " F_get_data

*&---------------------------------------------------------------------*
*&      Form  F_bapi_commit
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_bapi_commit.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
.

if sy-subrc eq 0.
  write:/2 ' Transaction commited' color 4.
else.
  write:/2 'Unable to commit the transaction' color 4.
endif.
endform.                    " F_bapi_commit

*&---------------------------------------------------------------------*
*&      Form  F_call_bapi
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form F_call_bapi .

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata                  = bapi_head
    CLIENTDATA                 = bapi_clientdata
    CLIENTDATAX                = bapi_clientdatax
    VALUATIONDATA              = bapi_valclass
    VALUATIONDATAX             = bapi_valclassx
 IMPORTING
   RETURN                     = it_ret
 TABLES
   MATERIALDESCRIPTION        =  it_makt
   RETURNMESSAGES        =  returnm.

   IF it_ret-type eq 'E' or it_ret-TYPE eq 'S'.
     Write:/1 it_ret-type,
            8 it_ret-id,
            30 it_ret-number,
            38 it_ret-message,
            190 it_ret-parameter,
            210 it_ret-row,
            220 it_ret-field.
   endif.

endform.                    " F_call_bapi

Regards,

Ranjith N

2 REPLIES 2
Read only

Former Member
0 Likes
547

resloved.

issue with the internal table structrue.

Read only

Former Member
0 Likes
547

answered