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

Updating Z fields using BAPI_MATERIAL_SAVEDATA

0 Kudos

I am having 6 Custom fields from MARC table to update in Material master if I use the structure BAPIPAREX I can fill only 4 custom fields as it is containing STRUCTURE, VALUEPART1, VALUEPART2, VALUEPART1,VALUEPART4.

And in OMSR also 6custom fields are maintained from MARC table.

How we can add more than 4 custom fields to the material master.

Please suggest any other way of adding more than custom fields.

Please help me with this issue ASAP.

Thanks in advance.

8 REPLIES 8

raymond_giuseppi
Active Contributor

Don't use the VALUEPARTn with only one field, you must append your fields in structures BAPI_TE_MARC (actual character fields) and BAPI_TE_MARCX (update flags) and move those structures in EXTENSIONIN, for example

ls_extensionin-structure = 'BAPI_TE_MARC'.
cl_abap_container_utilities=>fill_container_c(
  EXPORTING
    im_value               = ls_bapi_te_marc " structure of type bapi_te_marc
  IMPORTING
    ex_container           = ls_extensionin+30 " values 1-4
  EXCEPTIONS
    illegal_parameter_type = 1
    OTHERS                 = 2 ).
<br>

In case of problem check my answer to this other post.

0 Kudos

We we need to maintain the new Z fields in the BAPI Structures

0 Kudos

Yes append your fields in structures BAPI_TE_MARC and BAPI_TE_MARCX (and read documentation of EXTENSIONI parameter)

thkolz
Contributor

I have an abstract method for this:

  METHOD fill_extension.

    DATA:
      r_type_desc TYPE REF TO cl_abap_typedescr,
      s_value     TYPE REF TO data,
      s_extension TYPE bapiparex,
      v_value     TYPE c LENGTH 960,
      v_type      TYPE string.

    FIELD-SYMBOLS:
      <fs_any>              TYPE any.


*   Create output structure
    IF i_value IS SUPPLIED.
*     Structure
      r_type_desc = cl_abap_typedescr=>describe_by_data( i_value ).
    ELSEIF it_value IS SUPPLIED.
*     Table
      CREATE DATA s_value LIKE LINE OF it_value.

      ASSIGN s_value->* TO FIELD-SYMBOL(<fs_value>).
      CHECK sy-subrc IS INITIAL.
      r_type_desc = cl_abap_typedescr=>describe_by_data( <fs_value> ).
    ENDIF.

*   Get type
    CHECK r_type_desc IS BOUND.
    v_type = r_type_desc->absolute_name.
    REPLACE '\TYPE=' IN v_type WITH space.

    s_extension-structure = v_type.

    IF i_value IS NOT INITIAL.
      CLASS cl_abap_container_utilities DEFINITION LOAD.

      CALL METHOD cl_abap_container_utilities=>fill_container_c
        EXPORTING
          im_value               = i_value
        IMPORTING
          ex_container           = v_value
        EXCEPTIONS
          illegal_parameter_type = 1
          OTHERS                 = 2.

      s_extension-valuepart1 = v_value(240).
      s_extension-valuepart2 = v_value+240(240).
      s_extension-valuepart3 = v_value+480(240).
      s_extension-valuepart4 = v_value+720(240).
      APPEND s_extension TO et_extension.
    ELSE.
*     Add all values to the extension table
      LOOP AT it_value ASSIGNING <fs_any>.
        CALL METHOD cl_abap_container_utilities=>fill_container_c
          EXPORTING
            im_value               = <fs_any>
          IMPORTING
            ex_container           = v_value
          EXCEPTIONS
            illegal_parameter_type = 1
            OTHERS                 = 2.

        DESCRIBE FIELD v_value LENGTH DATA(lv_length) IN CHARACTER MODE.

        IF lv_length LE 240.
          s_extension-valuepart1 = v_value+0(lv_length).
        ENDIF.

        IF lv_length GT 240 AND lv_length LE 480.
          s_extension-valuepart1 = v_value+0(240).
          DATA(lv_max) = lv_length - 240.
          s_extension-valuepart2 = v_value+240(lv_max).
        ENDIF.

        IF lv_length GT 480 AND lv_length LE 720.
          s_extension-valuepart1 = v_value+0(240).
          s_extension-valuepart2 = v_value+240(240).
          lv_max = lv_length - 480.
          s_extension-valuepart3 = v_value+480(lv_max).
        ENDIF.

        IF lv_length GT 720 AND lv_length LE 960.
          s_extension-valuepart1 = v_value+0(240).
          s_extension-valuepart2 = v_value+240(240).
          s_extension-valuepart3 = v_value+480(240).
          lv_max = lv_length - 720.
          s_extension-valuepart4 = v_value+720(lv_max).

        ELSEIF lv_length GT 960.

          s_extension-valuepart1 = v_value+0(240).
          s_extension-valuepart2 = v_value+240(240).
          s_extension-valuepart3 = v_value+480(240).
          s_extension-valuepart4 = v_value+720(240).
        ENDIF.
        APPEND s_extension TO et_extension.
      ENDLOOP.
    ENDIF.
  ENDMETHOD.

This can be passed like this:

    DATA:
       t_extension    TYPE bapiparex_tab.

    zcl_bc_util=>fill_extension(
      EXPORTING
*       i_structure  = 'BAPI_TE_AUFK'
        i_value      = s_bapi_te_aufk
      IMPORTING
        et_extension = t_extension
    ).

Make sure to just use CHAR fields in your extension (this is recommended by SAP).
I once had major issues when using numeric values.

0 Kudos

Can you pls explain me end to end process of adding zfilds to the material master

Sandra_Rossi
Active Contributor
0 Kudos

The signature of the method is missing.

0 Kudos

Sorry, saw your comment just now...

Here's the signature:

    CLASS-METHODS fill_extension
IMPORTING
i_value TYPE any OPTIONAL
it_value TYPE table OPTIONAL
EXPORTING
et_extension TYPE bapiparex_t .