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

Create Material With BAPI_MATERIAL_SAVEDATA

hawkvicky91
Explorer
0 Likes
2,433

Hi,

I New To SAP I'm Trying To Create Material With BAPI_MATERIAL_SAVEDATA . When I Execute The Code I am Getting Message That ' Bytes Transfered' But When I Checking The MARA Table I Cannot Find The Enteries..

*************************************************************CODE*********************************************************************************

TABLES: bapimathead,

              bapi_mara,

              bapi_marax,

              bapiret2.

TYPES: BEGIN OF lsmw_material_master,

             matnr TYPE mara-matnr,

             mtart  TYPE mara-mtart,

             mbrsh TYPE mara-mbrsh,

             maktx TYPE makt-maktx,

             meins TYPE mara-meins,

             END   OF  lsmw_material_master.

DATA: it_master        TYPE TABLE OF lsmw_material_master,

            wa_master     TYPE  lsmw_material_master,

            it_materialdesc TYPE TABLE OF bapi_makt WITH HEADER LINE,

            it_return            LIKE bapiret2.

     

SELECTION-SCREEN: BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.

           PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN: END OF BLOCK a1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

   DATA: it_tab   TYPE filetable,

             iv_subrc LIKE sy-subrc.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

     EXPORTING

            window_title            = 'Select Source File'

    CHANGING

            file_table              = it_tab

            rc                      = iv_subrc

           .

   IF sy-subrc <> 0.

*             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

   ENDIF.

   LOOP AT it_tab INTO p_file.

   ENDLOOP.

 

CALL FUNCTION 'UPLOAD'

    EXPORTING

           filename                    = p_file

           filetype                      = 'DAT'

   TABLES

           data_tab                      = it_master

             .

   IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

   ENDIF.

LOOP AT it_master INTO wa_master.

     bapimathead-material        = wa_master-matnr.

     bapimathead-ind_sector    = wa_master-mtart.

     bapimathead-matl_type     = wa_master-mbrsh.

     bapimathead-basic_view    = 'X'.

     bapi_mara-base_uom        = wa_master-meins.

     bapi_marax-base_uom       = 'X'.

     it_materialdesc-matl_desc = wa_master-maktx.

     APPEND it_materialdesc.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

   EXPORTING

          headdata                    = bapimathead

          clientdata                    = bapi_mara

          CLIENTDATAX             = bapi_marax

  IMPORTING

          return                          = it_return

  TABLES

          materialdescription       = it_materialdesc

               .

ENDLOOP.

  IF  sy-subrc = 0.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

*     EXPORTING

*       WAIT          =

*     IMPORTING

*       RETURN        =

               .

* ELSE.

   WRITE:/ 'Error'.

*   CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

*   IMPORTING

*     RETURN        =

               .

  ENDIF.

*************************************************************FILE >>>>>check.text.********************************************************************************

Cooinfl_FanEFERTFANSPC
Bathing_FanEFERTFANSPC
1 ACCEPTED SOLUTION
Read only

former_member188827
Active Contributor
0 Likes
2,303

The message you are getting is from Function module "UPLOAD", please check if it_master contains data.Also, check it_return after " BAPI_MATERIAL_SAVEDATA" and see if it contains any errors.

Call commit within loop and endloop.

Regards

14 REPLIES 14
Read only

former_member188827
Active Contributor
0 Likes
2,304

The message you are getting is from Function module "UPLOAD", please check if it_master contains data.Also, check it_return after " BAPI_MATERIAL_SAVEDATA" and see if it contains any errors.

Call commit within loop and endloop.

Regards

Read only

0 Likes
2,303

Thanks,   When I'm Trying To Print it_master , It Giving Error 'Internal Unit PC, Language EN Is Not Maintained.. However,Is Language Is Must?

Read only

0 Likes
2,303

Then you need to check unit of measure. Check table "MARM" for unit of measure and use appropriate one. You might need conversion exit  FM "CONVERSION_EXIT_CUNIT_INPUT" to first convert unit of measure "PC" to internal format and then pass this to BAPI.

Regards

Read only

0 Likes
2,303

Ok, After Applying FM "CONVERSION_EXIT_CUNIT_INPUT" . it_master Displaying The Data. But it-return

Returning Error 'E'

Read only

0 Likes
2,303

What is the message in it_return?

Regards

Read only

0 Likes
2,303

it_return-type Returning 'E.

Read only

0 Likes
2,303

Please share the message text, not just the type. List all the messages you are getting in it_return.

Regards

Read only

0 Likes
2,303

Message Type:E

Message Id:    MG

Message no:   171.

Message:        You have Not fully maintained the Descriptoin.

Read only

0 Likes
2,303

Please pass following values:

  it_materialdesc-matl_desc = wa_master-maktx.

  it_materialdesc-langu  = 'E'.

  it_materialdesc-langu_iso = 'EN'.

     APPEND it_materialdesc.

Regards

Read only

0 Likes
2,302

Thanks It Working. But Can you Please Explain The Last Step, Why We Pass "lang" And ''lang-iso" Field.

Read only

0 Likes
2,302

Because texts are language dependent in SAP. Almost all text tables in SAP have language field as key field.

Regards

Read only

0 Likes
2,302

Ok, But Then Why If We Create Material Through MM01 ,Then It will Not Ask for Language field?

Read only

0 Likes
2,302

Because then system uses log on language of user to save text.

Regards

Read only

0 Likes
2,302

Thanks. Thanks A Lot