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 Customer-Master Info record (VD51).

0 Kudos
1,365

Hi All,

Have a requirement in which I need to create a customer-Master Info record (VD51). Want a suggestion, what is the best way to create a customer-Master Info record via program.

Is there a BAPI or a FM which create a customer-Master Info record?

Thanks in advance.

Kind Regards,

Abhi...

3 REPLIES 3

Former Member
0 Kudos
172

Hi,

There is an FM which is used by standard transaction

'RV_CUSTOMER_MATERIAL_UPDATE' .

Ex Code -

CALL FUNCTION 'RV_CUSTOMER_MATERIAL_UPDATE'

IN UPDATE TASK

TABLES

XKNMT_TAB = XKNMT

YKNMT_TAB = YKNMT

TCATALOG_TAB = LT_CATALOG.

commit work.

Just pass the info in table XKNMT and check it. It will work.

Thanks,

Rajinikanth G

Former Member
0 Kudos
172

Hi,

here below a sample code for doing that

REPORT Z_knmt.

tables : knmt.

data : begin of it_data occurs 0,

kunnr like knmt-kunnr,

vkorg like knmt-vkorg,

vtweg like knmt-vtweg,

matnr like knmt-matnr,

kdmat like knmt-kdmat,

end of it_data.

data : begin of st_data,

kunnr like knmt-kunnr,

vkorg like knmt-vkorg,

vtweg like knmt-vtweg,

matnr like knmt-matnr,

kdmat like knmt-kdmat,

end of st_data.

parameters p_file like RFPDO1-FEBAUSZF.

selection-screen skip.

parameters : p_group(12) default 'BATCH_VD51' obligatory.

data w_lines type i.

data : w_kunnr(10) type n.

include Z_IN_BATCH_INPUT.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

MASK = ',,.txt'

STATIC = 'X'

CHANGING

FILE_NAME = p_file.

start-of-selection.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_file

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_data

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

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

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

ENDIF.

sort it_data.

loop at it_data.

w_kunnr = it_data-kunnr.

it_data-kunnr = w_kunnr.

select single * from knmt where vkorg = it_data-vkorg

and vtweg = it_data-vtweg

and kunnr = it_data-kunnr

and matnr = it_data-matnr.

if sy-subrc = 0.

delete it_data.

endif.

endloop.

describe table it_data lines w_lines.

if w_lines is initial.

stop.

endif.

perform open_group using p_group.

loop at it_data.

st_data = it_data.

condense st_data-kdmat no-gaps.

at new vtweg.

perform dynpro USING : 'X' 'SAPMV10A' '0100' ,

' ' 'BDC_OKCODE' '/00' ,

' ' 'MV10A-KUNNR' st_data-kunnr,

' ' 'MV10A-VKORG' st_data-vkorg,

' ' 'MV10A-VTWEG' st_data-vtweg.

perform dynpro USING : 'X' 'SAPMV10A' '0200' ,

' ' 'BDC_OKCODE' '/00' ,

' ' 'MV10A-MATNR(01)' st_data-matnr,

' ' 'MV10A-KDMAT(01)' st_data-kdmat.

perform dynpro USING : 'X' 'SAPMV10A' '0200' ,

' ' 'BDC_CURSOR' 'MV10A-MATNR(01)',

' ' 'BDC_OKCODE' '/00' .

continue.

endat.

perform dynpro USING : 'X' 'SAPMV10A' '0200' ,

' ' 'BDC_OKCODE' '/00' ,

' ' 'MV10A-MATNR(02)' st_data-matnr,

' ' 'MV10A-KDMAT(02)' st_data-kdmat.

perform dynpro USING : 'X' 'SAPMV10A' '0200' ,

' ' 'BDC_CURSOR' 'MV10A-MATNR(01)',

' ' 'BDC_OKCODE' '/00' .

at end of vtweg.

perform dynpro USING : 'X' 'SAPMV10A' '0200' ,

' ' 'BDC_OKCODE' '=SICH'.

perFORM insert USING 'VD51'.

endat.

endloop.

perform close_group.

end-of-selection.

***INCLUDE Z_IN_BATCH_INPUT .

DATA : ti_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

&----


*& Form OPEN_GROUP *

&----


*& *

*& group -> Folder name *

*& *

&----


FORM open_group USING group.

FREE ti_bdcdata.

CLEAR ti_bdcdata.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = group

keep = ' '

user = sy-uname

EXCEPTIONS

client_invalid = 1

destination_invalid = 2

group_invalid = 3

group_is_locked = 4

holddate_invalid = 5

internal_error = 6

queue_error = 7

running = 8

system_lock_error = 9

user_invalid = 10

OTHERS = 11.

ENDFORM.

----


  • FORM close_group *

----


  • ........ *

----


FORM close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'

  • EXCEPTIONS

  • NOT_OPEN = 1

  • QUEUE_ERROR = 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.

ENDFORM.

&----


*& Form DYNPRO *

&----


*& *

*& dynbegin -> Parameters for screen begin ( 'X' ) or not ( ' ' ) *

*& name -> Field or Screen name to treat *

*& value -> Field value or screen number *

*& *

&----


FORM dynpro USING dynbegin name value.

CLEAR ti_bdcdata.

ti_bdcdata-dynbegin = dynbegin.

CASE dynbegin.

WHEN 'X'.

ti_bdcdata-program = name.

ti_bdcdata-dynpro = value.

WHEN OTHERS.

ti_bdcdata-fnam = name.

ti_bdcdata-fval = value.

ENDCASE.

APPEND ti_bdcdata.

CLEAR ti_bdcdata.

ENDFORM. " DYNPRO

&----


*& Form INSERT *

&----


*& t_code : transaction code *

*& *

&----


FORM insert USING t_code.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = t_code

TABLES

dynprotab = ti_bdcdata

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

printing_invalid = 5

posting_invalid = 6

OTHERS = 7.

CHECK sy-subrc EQ 0.

FREE ti_bdcdata.

CLEAR ti_bdcdata.

ENDFORM. " INSERT

0 Kudos
172

used 'RV_CUSTOMER_MATERIAL_UPDATE' to update, insert data in Knmt table.