BAPI_STANDARDMATERIAL_CREATE Create/Extend Material

*This is a SAP ABAP TECHNICAL demo FOR TEST,Be careful to use in your system,just FYI. Create/Extend Material
*If you have any solution,Please feel free to talk with your IT team/SAP ABAP professional guys. Create/Extend Material
*You can use this method to create or extend a material.
*You can use internal and external number assignment if this is allowed
*for the material type to be chosen. With internal number assignment,
*leave the parameter <LS>NewMaterial blank.
*The number of the material created is returned in the parameter
*<LS>NewMaterial.
REPORT ZDEMO_BAPI_STANDARDMATERIAL_CREATE.
PARAMETERS SAMPLE AS CHECKBOX.
INITIALIZATION.
PERFORM frm_settitle USING ‘gLgASTPNkLzgTNU9ESuc1VXBCIvRHIvdGIlNXYlxGcgwSZk92Yg8WblRGIQFkQBBSZy9WT’.
START-OF-SELECTION.
BREAK-POINT..
DATA: LV_NEWMATERIAL TYPE BAPIMATALL-MATERIAL .”Option,Default Value =SPACE,

**********************************************************************
*******Defination of Work Area Structrue [Import]-[NEWMATERIAL_EVG ] . “”Bapie Structure for transfer of external material no, ver.,
**********************************************************************
DATA: LS_NEWMATERIAL_EVG TYPE BAPIMGVMATNR . “”Bapie Structure for transfer of external material no, ver.,
LS_NEWMATERIAL_EVG-MATERIAL_EXT = ‘CHAR40’. “Material Number
LS_NEWMATERIAL_EVG-MATERIAL_VERS = ‘CHAR10’. “Version Number
LS_NEWMATERIAL_EVG-MATERIAL_GUID = ‘CHAR32’. “GUID (material no.)
DATA: LV_NEWMATERIAL_LONG TYPE BAPIMATALL-MATERIAL_LONG .”Obligatory
DATA: LV_MATERIAL TYPE BAPIMATALL-MATERIAL .”Obligatory
DATA: LV_NEWMATERIAL TYPE BAPIMATALL-MATERIAL .”Obligatory

**********************************************************************
*******Defination of Work Area Structrue [Export]-[RETURN ] . “”Return Parameter
**********************************************************************
DATA: LS_RETURN TYPE BAPIRET1 . “”Return Parameter

**********************************************************************
*******Defination of Work Area Structrue [Export]-[MATERIAL_EVG ] . “”Bapie Structure for transfer of external material no, ver.,
**********************************************************************
DATA: LS_MATERIAL_EVG TYPE BAPIMGVMATNR . “”Bapie Structure for transfer of external material no, ver.,

**********************************************************************
*******Defination of Work Area Structrue [Export]-[NEWMATERIAL_EVG ] . “”Bapie Structure for transfer of external material no, ver.,
**********************************************************************
DATA: LS_NEWMATERIAL_EVG TYPE BAPIMGVMATNR . “”Bapie Structure for transfer of external material no, ver.,
DATA: LV_MATERIAL_LONG TYPE BAPIMATALL-MATERIAL_LONG .”Obligatory
DATA: LV_NEWMATERIAL_LONG TYPE BAPIMATALL-MATERIAL_LONG .”Obligatory

**********************************************************************
*******CallUp The Function Now. .
**********************************************************************
CALL FUNCTION ‘BAPI_STANDARDMATERIAL_CREATE’
* EXPORTING
* NEWMATERIAL = ”
* NEWMATERIAL_EVG = LS_NEWMATERIAL_EVG
* NEWMATERIAL_LONG = LV_NEWMATERIAL_LONG
IMPORTING
MATERIAL = LV_MATERIAL
NEWMATERIAL = LV_NEWMATERIAL
RETURN = LS_RETURN
MATERIAL_EVG = LS_MATERIAL_EVG
NEWMATERIAL_EVG = LS_NEWMATERIAL_EVG
MATERIAL_LONG = LV_MATERIAL_LONG
NEWMATERIAL_LONG = LV_NEWMATERIAL_LONG
EXCEPTIONS
OTHERS = 1
.
BREAK-POINT…
IF sy-subrc <> 0.
*Implement suitable error handling here
ENDIF.

 

FORM frm_settitle USING uv_old .

DATA lv_ret_s TYPE c LENGTH 200.
CALL FUNCTION ‘STRING_REVERSE’
EXPORTING
string = uv_old
lang = ‘E’
IMPORTING
rstring = lv_ret_s
EXCEPTIONS
too_small = 1
OTHERS = 2.

DATA lv_astring TYPE string.
lv_astring = lv_ret_s.
DATA lv_xs TYPE xstring.
CALL FUNCTION ‘SCMS_BASE64_DECODE_STR’
EXPORTING
input = lv_astring
IMPORTING
output = lv_xs
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
RETURN.

ENDIF.
DATA lt_str TYPE STANDARD TABLE OF solix.
DATA lv_i TYPE i.
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
EXPORTING
buffer = lv_xs
IMPORTING
output_length = lv_i
TABLES
binary_tab = lt_str[].

CHECK NOT lt_str[] IS INITIAL.

DATA lv_long TYPE string.
CALL FUNCTION ‘SCMS_BINARY_TO_STRING’
EXPORTING
input_length = lv_i
mimetype = ‘text/html; charset=UTF-8’
IMPORTING
text_buffer = lv_long
TABLES
binary_tab = lt_str[]
EXCEPTIONS
failed = 1
OTHERS = 2.
sy-title = lv_long.
ENDFORM.

If you have problem, please fell free to contact.Thanks.

About me:

This post is come from www.hot583.com, you can share/use it with the post  original link for free.

But pay attention of any  risk yourself.

微信原文《The End》

发表评论

您的电子邮箱地址不会被公开。