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: 

Create Materil with variant configuration data[characteristics] using ABAP code/FM/BAPI/BADI

Former Member
0 Kudos

Hi,

we can use the MM01 to create materials with variant configuration data with reference to configurable material.

My requirement is to create the same by using ABAP code/Function modules /BAPI/BADI. I know the function module MATERIL_MAINTAIN_DARK where i can provide the variant configuration data in tables [below]

 

ae1cucfg_ueb

ae1cuins_ueb

ae1cuval_ueb

ae1cucom_ueb

but this function module will accept variant configuration data while create the material using IDOC.

Please let me know how to create the material with variant configuration data. I dont what to use BDC/LSMW to MM01.

Regards,

Sreedhara.

7 REPLIES 7

Former Member
0 Kudos

Hi Sreedhara,

I have the same problem as you. ¿have you found any solution about it?

Thank you very much.

Regards,

Asier.

0 Kudos

Hi Martin,

Find the below code/Explanation. It creates the VC material when creating sales order.

In the function Module CUSE_TYPE_SEARCH.
Write the code [May be include program] after the function module CUSE_SELECT_MATERIAL_VARIANTS. This FM returns the sy-subrc = 2 when configurable material is not found.

Include Program:-
*-iv_instance have the internal instance number that used to generate
*-configuration and CUOBJ and CUOBF.
    CALL FUNCTION 'CUCB_STATUS_FROM_CONFIGURATION'
      EXPORTING
        instance                     = iv_instance " Internal Instance number of VC
        is_business_object           = ls_bo
      EXCEPTIONS
        invalid_input                = 1
        free                         = 2
        incomplete                   = 3
        locked                       = 4
        no_status                    = 5
        invalid_instance             = 6
        instance_is_a_classification = 7
        OTHERS                       = 8.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

*-Get the variant Configuration details of new material and old&new instance
*-numbers of configurations. New instance number will be used primary.
    CALL FUNCTION 'CUCB_COPY_CONFIGURATION'
      EXPORTING
        source_instance                    = iv_instance "Internal Instance number of VC
     IMPORTING
        configuration                      = lt_cfg
        et_match_instance                  = lt_match
*       ES_INSTANCE_REC                    =
     EXCEPTIONS
       invalid_instance                   = 1
       instance_is_a_classification       = 2
       OTHERS                             = 3
              .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

*-New instance number will be used further as root instance and primary number
    READ TABLE lt_cfg INTO ls_cfg INDEX 1.
    lv_root_inst = ls_cfg-instance.    "New instance number will the original INSTANCE of VC

*-By passing the Instance number get the configuration details in the format of
*-e1cu structures.
    CALL FUNCTION 'CUXM_GET_CONFIGURATION'
      EXPORTING
        instance                     = lv_root_inst
      TABLES
        t_e1cucfg                    = lt_e1cucfg
        t_e1cuins                    = lt_e1cuins
        t_e1cuval                    = lt_e1cuval
        t_e1cucom                    = lt_e1cucom
      EXCEPTIONS
        instance_not_found           = 1
        internal_error               = 2
        instance_is_a_classification = 3
        OTHERS                       = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.


1. Create material with variant configuration with FM MATERIAL_MAINTAIN_DARK.

Fill all Tables.
        CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'
          EXPORTING
            sperrmodus                      = 'E'
            max_errors                      = 0
            p_kz_no_warn                    = 'N'
            kz_prf                          = 'W'  "space
            kz_verw                         = 'X'
            kz_aend                         = 'X'
          IMPORTING
            matnr_last                      = gv_matnr_last
            number_errors_transaction       = gv_number_errors_transaction
          TABLES
            amara_ueb                       = gt_amara_ueb
            amakt_ueb                       = gt_amakt_ueb
            amarc_ueb                       = gt_amarc_ueb
            amard_ueb                       = gt_amard_ueb
*       AMFHM_UEB                       =
            amarm_ueb                       = gt_amarm_ueb
*       AMEA1_UEB                       =
            ambew_ueb                       = gt_ambew_ueb
            asteu_ueb                       = gt_asteu_ueb
            astmm_ueb                       = gt_astmm_ueb
            amlgn_ueb                       = gt_amlgn_ueb
            amlgt_ueb                       = gt_amlgt_ueb
*       AMPGD_UEB                       =
*       AMPOP_UEB                       =
*       AMVEG_UEB                       =
*       AMVEU_UEB                       =
            amvke_ueb                       = gt_amvke_ueb
*       ALTX1_UEB                       =
*       AMPRW_UEB                       =
*        ae1cucfg_ueb                    = gt_e1cucfg_ueb
*        ae1cuins_ueb                    = gt_e1cuins_ueb
*        ae1cuval_ueb                    = gt_e1cuval_ueb
*        ae1cucom_ueb                    = gt_e1cucom_ueb
*        amfieldres                      = gt_mfieldres
            amerrdat                        = gt_amerrdat
         EXCEPTIONS
           kstatus_empty                   = 1
           tkstatus_empty                  = 2
           t130m_error                     = 3
           internal_error                  = 4
           too_many_errors                 = 5
           update_error                    = 6
           error_propagate_header          = 7
           OTHERS                          = 8 .
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

2. Save Configuration with FM MATERIAL_SAVE_CONFIGURATION at client and Plant level.
*---------- Client-specific configuration--------------------------------------

    CALL FUNCTION 'MATERIAL_SAVE_CONFIGURATION'
      EXPORTING
        material       = znew_matnr
        conf_matl      = lv_matnr
      TABLES
        e1cucfg        = lt_e1cucfg
        e1cuins        = lt_e1cuins
        e1cuval        = lt_e1cuval
        e1cucom        = lt_e1cucom
        returnmessages = gt_returnmessages.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
*-----------Plant-specific configuration-----------------------------------------
*---Save the configuration for each plant


    LOOP AT gt_marc INTO gs_marc.

      CALL FUNCTION 'MATERIAL_SAVE_CONFIGURATION'
        EXPORTING
          material        = znew_matnr
          plant           = gs_marc-werks     "iv_plant
          conf_matl_plant = lv_matnr
        TABLES
          e1cucfg_w       = lt_e1cucfg
          e1cuins_w       = lt_e1cuins
          e1cuval_w       = lt_e1cuval
          e1cucom_w       = lt_e1cucom
          returnmessages  = gt_returnmessages.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
endloop.

0 Kudos

Hi Sreedhara,

Thank you very much for your help.

I have a doubt when I'm filling data in the FM  'MATERIAL_MAINTAIN_DARK'. In the field "matnr",  inside tables like "gt_amara_ueb,gt_amakt_ueb"...¿what is value that  i have to put in? If I don´t put nothing, I always get the same error:  " The material cannot be maintained since no maintainable data transferred " and those data are filled.

Regards,

Asier.

0 Kudos

Hi ,

You need to pass Material Number in the field "MATNR" ,either Internal Material Number(i.e. Leading with Zero) or External Number as per Material type and Industry Sector .

Use this "BAPI_STDMATERIAL_GETINTNUMBER"  to Get One Current Material Number Range ..and this number you pass gt_amara_ueb-matnr and gt_amakt_ueb-matnr .

Regard's

Smruti

0 Kudos

Hi Martin,

Hope your problem solved. Please provide points if it solved the problem.

Thnaks.

Sreedhara

Former Member
0 Kudos

I solved the problem. I can create material with variant configuration.

Thanks Sreedhara.

0 Kudos

Hello Asier Martin,

could you please explain your solution for creating material with variant configuration via fm/bapi etc. please?

Thank you!