Sunday, September 27, 2020

BAPI MATERIAL CREATE Example in SAP ABAP.

BAPI MATERIAL CREATE  Example in SAP ABAP.



BAPI_MATERIAL_SAVEDATA BAPI For material Create in SAP ABAP.

REPORT zbij_bapi_material.

*&---------------------------------------------------------------------*
*& INCLUES FOR ALL EVENTS                                              *
*&---------------------------------------------------------------------*
INCLUDE zbapi_mat_data_declaration.
INCLUDE zbapi_mat_data_selec_screen.
INCLUDE zbapi_mat_data_logic.

*&---------------------------------------------------------------------*
*& Start of Selection Event                                            *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  
PERFORM gui_upload.
  
PERFORM bapi.

 

TOP

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_DECLARATION
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& External Table Declaration                                          *
*&---------------------------------------------------------------------*
TABLES bapimatheadbapi_marabapi_maraxbapi_makt.

*&---------------------------------------------------------------------*
*& Internal Table Declaration                                          *
*&---------------------------------------------------------------------*
DATA BEGIN OF it_bapi OCCURS 0,
          material   
TYPE bapimathead-material,
          ind_sector 
TYPE bapimathead-ind_sector,
          matl_type  
TYPE bapimathead-matl_type,
          matl_group 
TYPE bapi_mara-matl_group,
          base_uom   
TYPE bapi_mara-base_uom,
          matl_desc  
TYPE bapi_makt-matl_desc,
        
END OF it_bapi,

       it_return 
LIKE bapiret2,
       it_makt_bapi 
like bapi_makt OCCURS WITH HEADER LINE.

 

SELECTION SCREEN

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_SELEC_SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
"IBIPPARMS-PATH is a export structure of f4 help fm.
*PARAMETERS : p_file TYPE ibipparms-path OBLIGATORY.
PARAMETERS p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*&  At Selection Screen Event                                          *
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  
PERFORM f4_help.

SUB***************************************************

*&---------------------------------------------------------------------*
*&  Include           ZBAPI_MAT_DATA_LOGIC
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&  Form F4_HELP                                                       *
*&---------------------------------------------------------------------*

FORM f4_help.
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  
syst-cprog
      dynpro_number 
syst-dynnr
*     FIELD_NAME    = ' '
    
IMPORTING
      file_name     
p_file.
ENDFORM.                    "f4_help

*&---------------------------------------------------------------------*
*&  Form GUI_UPLOAD                                                    *
*&---------------------------------------------------------------------*
FORM gui_upload.
************************************************************************
***** For Notepad File

*  DATA:v_file TYPE string.
*  MOVE p_file TO v_file.

*  CALL FUNCTION 'GUI_UPLOAD'
*    EXPORTING
*     filename                      = v_file
*     filetype                      = 'DAT'
*     has_field_separator           = 'X'
**   HEADER_LENGTH                 = 0
**   READ_BY_LINE                  = 'X'
**   DAT_MODE                      = ' '
**   CODEPAGE                      = ' '
**   IGNORE_CERR                   = ABAP_TRUE
**   REPLACEMENT                   = '#'
**   CHECK_BOM                     = ' '
**   VIRUS_SCAN_PROFILE            =
**   NO_AUTH_CHECK                 = ' '
** IMPORTING
**   FILELENGTH                    =
**   HEADER                        =
*    TABLES
*      data_tab                      = it_bapi.

************************************************************************
***** For EXcel File
  
DATA lv_file TYPE rlgrap-filename,
         lv_raw  
TYPE truxs_t_text_data"truxs_xml_table.
  
MOVE   p_file TO lv_file.

  
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    
EXPORTING
      i_field_seperator    
'X'
*     I_LINE_HEADER        =
      i_tab_raw_data       
lv_raw
      i_filename           
lv_file
    
TABLES
      i_tab_converted_data 
it_bapi.
* EXCEPTIONS
*   CONVERSION_FAILED          = 1
*   OTHERS                     = 2

  
IF sy-subrc <> 0.
* Implement suitable error handling here
  
ENDIF.

ENDFORM.                    "gui_upload

*&---------------------------------------------------------------------*
*&      Form  bapi
*&---------------------------------------------------------------------*
FORM bapi.
  
LOOP AT it_bapi.
    bapimathead
-material   it_bapi-material.
    bapimathead
-ind_sector it_bapi-ind_sector.
    bapimathead
-matl_type  it_bapi-matl_type.
    bapimathead
-basic_view 'X'.

    bapi_mara
-matl_group   it_bapi-matl_group.
    bapi_mara
-base_uom     it_bapi-base_uom.
    bapi_marax
-matl_group  'X'.
    bapi_marax
-base_uom    'X'.

    it_makt_bapi
-matl_desc it_bapi-matl_desc.
    
APPEND it_makt_bapi.
    
CLEAR it_makt_bapi.

    
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      
EXPORTING
        headdata            
bapimathead
        clientdata          
bapi_mara
        clientdatax         
bapi_marax
      
IMPORTING
        
return              it_return
      
TABLES
        materialdescription 
it_makt_bapi.

    
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      
EXPORTING
        
wait 'X'.
    
WRITE / it_return-type.

  
ENDLOOP.
ENDFORM.                    "bapi

No comments:

Post a Comment