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: 

BAPI_MATERIAL_SAVEREPLICA | Z-fields cannot be updated

Weiskopf
Participant
0 Kudos
508

Dear Dev community

I am in an S/4HANA system (standard). I am trying to change a Z-field in the MARA table using the BAPI BAPI_MATERIAL_SAVEREPLICA. To do this, I have added the Z field to MARA and the enhancement structures BAPI_TE_E1MARA2 and BAPI_TE_E1MARA2X (here ZZMARKE). I also take into account the long material numbers (MATERIAL_LONG). The Z field is not used in the dialog (e.g. Fiori) and was therefore created as a classic Z-field (append).

See the following program.

report zkwe_material_create.

parameters: p_matnr  type matnr.

data:
  ls_return      type bapie1ret2,
  lt_return      type table of bapie1ret2,
  ls_headdata    type bapie1matheader,
  lt_headdata    type table of bapie1matheader,
  ls_clientdata  type bapie1mara,
  ls_clientdatax type bapie1marax,
  lt_clientdata  type table of bapie1mara,
  lt_clientdatax type table of bapie1marax,
  ls_description type bapie1makt,
  lt_description type table of bapie1makt,
  ls_extension   type bapie1parex,
  ls_extensionx  type bapie1parexx,
  lt_extension   type table of bapie1parex,
  lt_extensionx  type table of bapie1parexx,
  ls_ext_mara    type bapi_te_e1mara2,
  ls_ext_marax   type bapi_te_e1mara2x.

" General data needed for product creation
ls_headdata-material_long       = p_matnr.
ls_headdata-ind_sector     = 'O'.
ls_headdata-matl_type      = 'HAWA'.
ls_headdata-basic_view     = 'X'.

insert ls_headdata into table lt_headdata .

* Client data:
ls_clientdata-material_long = ls_headdata-material_long .
ls_clientdata-base_uom      = 'ST' .
insert ls_clientdata into table lt_clientdata .

* Client data x-fields:
ls_clientdatax-material_long = ls_headdata-material_long .
ls_clientdatax-base_uom      = 'X' .
insert ls_clientdatax into table lt_clientdatax .

* Description:
ls_description-material_long = ls_headdata-material_long .
ls_description-langu         = 'DE' .
ls_description-matl_desc     = 'Hello world!' .
insert ls_description into table lt_description .

* Extensions:
ls_ext_mara-material    = ls_headdata-material_long.
ls_ext_mara-zzmarke     = 'Content'.
ls_extension-material   = ls_headdata-material.
ls_extension-structure  = 'BAPI_TE_E1MARA2'.
ls_extension-valuepart1 = ls_ext_mara.
insert ls_extension into table lt_extension.

ls_ext_marax-material    = ls_headdata-material_long.
ls_ext_marax-zzmarke     = abap_true.
ls_extensionx-material   = ls_headdata-material_long.
ls_extensionx-structure  = 'BAPI_TE_E1MARA2X'.
ls_extensionx-valuepart1 = ls_ext_marax.
insert ls_extensionx into table lt_extensionx.

call function 'BAPI_MATERIAL_SAVEREPLICA'
  exporting
    noappllog           = abap_false
    nochangedoc         = abap_false
    testrun             = abap_false
    inpfldcheck         = abap_false
  importing
    return              = ls_return
  tables
    headdata            = lt_headdata
    clientdata          = lt_clientdata
    clientdatax         = lt_clientdatax
    materialdescription = lt_description
    extensionin         = lt_extension
    extensioninx        = lt_extensionx
    returnmessages      = lt_return.

commit work.

write: / ls_return-message, ls_return-message_v1.
loop at lt_return into ls_return.
  write: / ls_return-message, ls_return-message_v1.
endloop.

The program correctly creates or changes the material, but the Z field is not transferred.

Is there anything special to consider in the S/4HANA context?

Thank you very much in advance for your support.

Best regards, Kurt

4 REPLIES 4

NTeunckens
Active Contributor
391

Hello Kurt

I believe your custom fields need to be passed as CHARACTER-fields in the "EXTENSIONIN(X)"-structures and the exact length / position over the entire structure needs to be defined ... The ABAP-Utility "CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C" can be used to facilitate that.

Check the documentation on the "EXTENSIONIN"-table via Trx. "SE37" for "BAPI_MATERIAL_SAVEREPLICA" :
"Furthermore, the fields in the structures BAPI_TE_<NAME> can only be CHARACTER fields. ....
Parameters EXTENSIONIN and EXTENSIONINX are used for transferring data to the method. Field STRUCTURE contains the name of the structure (for example, BAPI_TE_MARA or BAPI_TE_MARAX). This names is used to identify the work area (for example,  WA_BAPI_TE_MARA or WA_BAPI_TE_MARAX) to which the data is transferred. The remaining fields in parameters EXTENSIONIN or EXTENSIONINX contain data for the key fields (for example, the material number) and the data for customer-specific fields. The number of characters reserved in both parameters for the contents of the customer-specific fields must match the number of characters for the relevant field in the work area. If the number of required characters is less, the remaining characters are left blank. Only when all characters have been filled can the contact for an additional field be transferred. Bear in mind that only data for which an appropriate indicator has been set in the work area can be updated to the database."

Another useful resource is SAP-Note 1650360 - BAPI: Length EXTENSION insufficient for cust-specific fields - SAP for Me

Hope this helps

Nic T.

0 Kudos
356

Hello Nic T.

Thank you for your reply and the detailed description of the procedure.

My example program above has filled the required parameters; the passed structures are all of type CHAR. Due to the long material number, I also used the S/4HANA structures BAPI_TE_E1MARA2/BAPI_TE_E1MARAX2.

When I go into debugging in BAPI_MATERIAL_SAVEREPLICA, I notice that in the form PROCESS_EXTENSION the internal table MARA_UEB has two entries, one from the HEADER and one from the CLIENT. The Z fields are filled only in the first MARA_UEB. Calling up the BAPI is actually easy - but I can't get the Z fields to be transferred.

What else could be the problem, that the Z-fields are not transferred to the MARA?

Thanks & best regards, Kurt

NTeunckens
Active Contributor
0 Kudos
321

Could you consider using code along the lines of :

 

ls_extension-valuepart1+0(40) = ls_ext_mara-material.    "Material should have leading zeros
ls_extension-valuepart1+40(7) = ls_ext_mara-zzmarke.     "Length of ZZMARKE = 7????
APPEND ls_extension TO lt_extension.

ls_extensionx-valuepart1+0(40) = ls_ext_mara-material.    "Material should have leading zeros
ls_extensionx-valuepart1+40(1) = abap_true.
APPEND ls_extensionx TO lt_extensionx.

 

(Just to be sure, it is the ONLY Z-field, right?)

As you rightly mention the form-routine "PROCESS_EXTENSION" but also "KUNDENFELDER_X_AUSWERTEN" from Include "L1001MASSUEBF01" are valuable routines to put a breakpoint, so you can check the structure and length of the fields there through debugging ...

Quite frankly, I'm not sure if you need to take the 18CHAR or the 40CHAR of Material / Product into account. I suggest you do some further exploring on that ... I haven't used this BAPI along with extensions before.

Keep us posted ...

Nic T.

0 Kudos
63

I am back to the topic; unfortunately there are many topics (sorted by priority).

So far the update of the Z-fields does not work. We are currently working on the basis of the current release status (latest S/4HANA release).

We are currently updating the Z fields directly via an update.

If you have any ideas, I would be very happy to hear them.

Thank you very much for your support.

Kind regards
Kurt