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

material number velidation

Former Member
0 Likes
997

hi experts,

the users here sometines by mistake upload wrong material number. now i want to make a velidation in my material master upload BDC, so that it allows just character types . like there should be nospace ( leading , trailing, in between), or any special character ( leading , trailing, in between).

can anyone please tell me the same.

thanx in advance

hi experts,

the users here sometines by mistake upload wrong material number. now i want to make a velidation in my material master upload BDC, so that it allows just character types . like there should be nospace ( leading , trailing, in between), or any special character ( leading , trailing, in between).

can anyone please tell me the same.

thanx in advance

6 REPLIES 6
Read only

Former Member
0 Likes
964

hi

first take data in an internal table and check there only what validation you want to make

Read only

Former Member
0 Likes
964

Hello,

If you going to change the Material number then, Validate the Mat. no with the table MARA.

If u r going to create new Materials any only you should allow characters they check like this.


IF MATNR CA SY-ABCDE.
" It is a Valid Mat no.
" Delete other mat from the table.
endif.

Cheers,

Vasanth

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
964

Loop at itab.

select single matnr into (mara-matnr) from mara where

matnr = itab-matnr and lvorm = space.

if sy-subrc <> 0.

Invalid material No.

endif.

endloop.

Hope u got it

Read only

Former Member
0 Likes
964

Hi Akansksha,

One method to ensure the material is valid is to use the BAPI BAPI_MATERIAL_EXISTENCECHECK.

Just before you call the BDC for updating the uploaded record into MM** transaction, you check the material code using thsi BAPI. If it is not valid or is deleted you would receive either an eror in RETURN parameter or DELETION_FLAG would be set.

You can then display the error to the user.

Cheers,

Aditya

Read only

Former Member
0 Likes
964

Hi akansha,

To check for Special characters, Check like

IF ztest-matnr CA ' '.

Give Error Message.

ENDIF

" Between the Single Quotes,give the Special Characters whichever you want to check.

Thanks,

Karthik

Read only

Former Member
0 Likes
964

Hi..

if you r doing BDC prgram, then no need of this validation.

In call transaction or session method these errors will be handled.

here I am giving you the sample code how to handle the errors.

CODE:

***********************************************************************

  • Report : Z50871MM_BDCP_ASSIGNMENT3 *

  • Title : BDC PROGRAM TO UPLOAD VENDOR DATA *

  • Author : SANDEEP REDDY *

  • Date of Creation : November 30, 2007 *

***********************************************************************

  • Modification Log *

  • Author : *

  • Date of Change : *

  • Functional Specs # : *

  • Correction Request # : *

  • Description of Change : *

***********************************************************************

REPORT z50871mm_bdcp_assignment3 NO STANDARD PAGE HEADING

LINE-SIZE 255.

----


  • STRUCTURE DECLARATION

----


TYPES : BEGIN OF st_vendor,

ktokk TYPE rf02k-ktokk, "account group

anred TYPE lfa1-anred, "title

name1 TYPE lfa1-name1, "vendor name

sortl TYPE lfa1-sortl, "search term

pstlz TYPE lfa1-pstlz, "postal code

land1 TYPE lfa1-land1, "country

banks TYPE lfbk-banks,

bankl TYPE lfbk-bankl, "bank key

bankn TYPE lfbk-bankn, "account number

END OF st_vendor.

TYPES : BEGIN OF st_success,

lifnr TYPE lfa1-lifnr, "vendor number

name TYPE lfa1-name1, "vendor name

END OF st_success.

TYPES: BEGIN OF st_error,

linno TYPE i, "line number

message TYPE string, "error message

END OF st_error.

----


  • INTERNAL TABLE DECLARATIONS

  • WORK AREA DECLARATIONS

----


DATA : it_vendor TYPE STANDARD TABLE OF st_vendor,

wa_vendor TYPE st_vendor,

it_success TYPE STANDARD TABLE OF st_success,

wa_success TYPE st_success,

it_error TYPE STANDARD TABLE OF st_error,

wa_error TYPE st_error,

it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

it_message LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

----


  • DATA DECLARATION

----


DATA : v_file TYPE string,

v_tcode(4) VALUE 'XK01',

v_index LIKE sy-tabix,

v_totalrec TYPE i,

v_errrec TYPE i,

v_succrec TYPE i.

----


  • SELECTION SCREEN

----


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

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-010.

PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N' .

"A: show all dynpros

"E: show dynpro on error only

"N: do not display dynpro

PARAMETERS p_update LIKE ctu_params-updmode DEFAULT 'S'.

"S: synchronously

"A: asynchronously

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-011.

PARAMETERS : p_group(12) DEFAULT '50871'. "group name for error session

SELECTION-SCREEN END OF BLOCK b3.

----


  • AT SELECTION SCREEN ON VALUE-REQUEST

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ' '

IMPORTING

file_name = p_file.

----


  • START-OF-SELECTION

----


START-OF-SELECTION.

v_file = p_file.

*gui upload

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = it_vendor

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*loadind data into it_bdcdata

LOOP AT it_vendor INTO wa_vendor.

v_index = sy-tabix.

PERFORM load_bdcdata.

----


  • CALL TRANSACTION

----


CALL TRANSACTION v_tcode USING it_bdcdata

MODE p_mode

UPDATE p_update

MESSAGES INTO it_message.

*reading success

IF sy-subrc = 0.

READ TABLE it_message WITH KEY msgtyp = 'S'.

IF sy-subrc = 0.

wa_success-lifnr = it_message-msgv1.

wa_success-name = wa_vendor-name1.

APPEND wa_success TO it_success.

ENDIF.

ELSE.

*reading errors

READ TABLE it_message WITH KEY msgtyp = 'E'.

IF sy-subrc = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

no = it_message-msgnr

v1 = it_message-msgv1

v2 = it_message-msgv2

v3 = it_message-msgv3

v4 = it_message-msgv4

IMPORTING

msg = wa_error-message.

wa_error-linno = v_index.

APPEND wa_error TO it_error.

CLEAR wa_error.

ENDIF.

*session opening

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_group

holddate = sy-datum

keep = 'X'

user = sy-uname.

*inserting into session

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'XK01'

TABLES

dynprotab = it_bdcdata.

*closing session

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDIF.

CLEAR: it_bdcdata, it_message.

REFRESH: it_bdcdata, it_message.

ENDLOOP.

----


  • SUMMARY DISPLAY

----


DESCRIBE TABLE it_vendor LINES v_totalrec.

DESCRIBE TABLE it_error LINES v_errrec.

v_succrec = v_totalrec - v_errrec .

WRITE : /1 text-004 COLOR 1.

WRITE : /2 'Total Records Processed :', 25 v_totalrec,

/2 'Error Records :', 25 v_errrec,

/2 'Successful Records :', 25 v_succrec.

SKIP 2.

WRITE : /1 text-005 COLOR 1.

LOOP AT it_error INTO wa_error.

WRITE:/2 wa_error-linno,

wa_error-message.

ENDLOOP.

SKIP 2.

WRITE : /1 text-009 COLOR 1.

ULINE AT : /2(46).

WRITE :/2 sy-vline ,(10) 'VENDOR NUM' , 15 sy-vline , 17 'VENDOR NAME' , 47 sy-vline.

ULINE AT : /2(46).

LOOP AT it_success INTO wa_success.

WRITE:/2 sy-vline , wa_success-lifnr, 15 sy-vline , 17 wa_success-name , 47 sy-vline.

ENDLOOP.

ULINE AT : /2(46).

&----


*& Form append_bdcdata

&----


FORM append_bdcdata USING p_flag p_fname p_fval.

CLEAR it_bdcdata.

IF p_flag = 'X'.

it_bdcdata-program = p_fname.

it_bdcdata-dynpro = p_fval.

it_bdcdata-dynbegin = 'X'.

APPEND it_bdcdata.

ELSEIF NOT p_fval IS INITIAL.

it_bdcdata-fnam = p_fname.

it_bdcdata-fval = p_fval.

APPEND it_bdcdata.

ENDIF.

ENDFORM. "append_bdcdata

&----


*& Form load_bdcdata

&----


FORM load_bdcdata .

PERFORM append_bdcdata USING : 'X' 'SAPMF02K' '0100',

' ' 'BDC_OKCODE' '/00',

' ' 'RF02K-KTOKK' wa_vendor-ktokk,

'X' 'SAPMF02K' '0110',

' ' 'BDC_OKCODE' '/00',

' ' 'LFA1-ANRED' wa_vendor-anred,

' ' 'LFA1-NAME1' wa_vendor-name1,

' ' 'LFA1-SORTL' wa_vendor-sortl,

' ' 'LFA1-PSTLZ' wa_vendor-pstlz,

' ' 'LFA1-LAND1' wa_vendor-land1,

'X' 'SAPMF02K' '0120',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

' ' 'LFBK-BANKS(01)' wa_vendor-banks,

' ' 'LFBK-BANKL(01)' wa_vendor-bankl,

' ' 'LFBK-BANKN(01)' wa_vendor-bankn,

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPLSPO1' '0300',

' ' 'BDC_OKCODE' '=YES'.

ENDFORM. " load_bdcdata

Regards

Sandeep