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

Rfc error

Former Member
0 Likes
914

hi,

can any body Debug this code.

Customer record is not inserting into table KNA1.

FUNCTION ZRFC_CUSTOMER_UPDATE.

*"----


""Global Interface:

*" EXPORTING

*" VALUE(RFCRC) LIKE SY-SUBRC

*" VALUE(ERROR_TEXT) LIKE T100-TEXT

*" TABLES

*" CUSTOMER_T STRUCTURE BRFCKNA1

*" EXCEPTIONS

*" UPDATE_ERROR

*"----


DATA UPDATE_VIA_CALL_TRANSACTION VALUE 'X'.

LOOP AT CUSTOMER_T.

IF UPDATE_VIA_CALL_TRANSACTION = 'X'.

  • update via CALL TRANSACTION

  • PERFORM BDC_INIT.

PERFORM BDC_NEXT_DYNPRO USING 'SAPMF02D' 101.

PERFORM BDC_SET_FIELD USING 'RF02D-KUNNR' CUSTOMER_T-KUNNR.

PERFORM BDC_SET_FIELD USING 'RF02D-D0110' 'X'.

PERFORM BDC_NEXT_DYNPRO USING 'SAPMF02D' 110.

PERFORM BDC_SET_FIELD USING 'KNA1-ANRED' CUSTOMER_T-ANRED.

PERFORM BDC_SET_FIELD USING 'KNA1-NAME1' CUSTOMER_T-NAME1.

PERFORM BDC_SET_FIELD USING 'KNA1-PFACH' CUSTOMER_T-PFACH.

PERFORM BDC_SET_FIELD USING 'KNA1-STRAS' CUSTOMER_T-STRAS.

PERFORM BDC_SET_FIELD USING 'KNA1-PSTLZ' CUSTOMER_T-PSTLZ.

PERFORM BDC_SET_FIELD USING 'KNA1-ORT01' CUSTOMER_T-ORT01.

PERFORM BDC_SET_FIELD USING 'KNA1-TELF1' CUSTOMER_T-TELF1.

PERFORM BDC_SET_FIELD USING 'KNA1-TELFX' CUSTOMER_T-TELFX.

PERFORM BDC_SET_FIELD USING 'BDC_OKCODE' '=UPDA'.

PERFORM BDC_CALL USING 'XD02' CHANGING ERROR_TEXT.

ELSE.

  • update via SAP SQL

UPDATE KNA1 SET

ANRED = CUSTOMER_T-ANRED

NAME1 = CUSTOMER_T-NAME1

PFACH = CUSTOMER_T-PFACH

STRAS = CUSTOMER_T-STRAS

PSTLZ = CUSTOMER_T-PSTLZ

ORT01 = CUSTOMER_T-ORT01

TELF1 = CUSTOMER_T-TELF1

TELFX = CUSTOMER_T-TELFX

WHERE KUNNR = CUSTOMER_T-KUNNR.

ENDIF.

  • exception handling

IF SY-SUBRC NE 0.

RFCRC = SY-SUBRC.

  • raise update_error.

ENDIF.

ENDLOOP.

ENDFUNCTION.

*----


*

  • Start new screen

*

*----


*

FORM BDC_NEXT_DYNPRO USING program dynpro.

CLEAR BDC_CALL.

BDC_CALL-program = program.

BDC_CALL-dynpro = dynpro.

BDC_CALL-dynbegin = 'X'.

APPEND BDC_CALL.

ENDFORM. "BDC_NEXT_DYNPRO

*----


*

  • Insert field

*

*----


*

FORM BDC_SET_FIELD USING fnam fval.

IF fval <> space.

CLEAR BDC_CALL.

BDC_CALL-fnam = fnam.

BDC_CALL-fval = fval.

APPEND BDC_CALL.

ENDIF.

ENDFORM. "BDC_SET_FIELD

7 REPLIES 7
Read only

Former Member
0 Likes
858

I will not even bother as you are using a direct update to KNA1. Which is a big huge NO NO.

Read only

Former Member
0 Likes
858

If you are calling this FM from Portal, then after getting error message check ST22, you might get error details there.

Read only

Former Member
0 Likes
858

Hi Chandan,

Its not a good practice to update tables directly. It will lead to many problems. Dont update KNA1 directly.

Regards

Aneesh.

Read only

ferry_lianto
Active Contributor
0 Likes
858

Hi,

Have you looked BAPI BAPI_CUSTOMER_CHANGEFROMDATA1?

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
858

Also if the record does not exist. UPDATE will not work. You need to either INSERT or MODIFY.

But still, DO NOT DO DIRECT UPDATES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Read only

Former Member
0 Likes
858

Hi Das,

is this part of the code is not working..

  • update via SAP SQL

<b>UPDATE KNA1 SET

ANRED = CUSTOMER_T-ANRED

NAME1 = CUSTOMER_T-NAME1

PFACH = CUSTOMER_T-PFACH

STRAS = CUSTOMER_T-STRAS

PSTLZ = CUSTOMER_T-PSTLZ

ORT01 = CUSTOMER_T-ORT01

TELF1 = CUSTOMER_T-TELF1

TELFX = CUSTOMER_T-TELFX

WHERE KUNNR = CUSTOMER_T-KUNNR.</b>

if this is the case there could be 2 reasons.

1) Kna1 may not have the kunnr that you are trying to update.

2) The format of KUNNR is not same as in KNA1.. Use the function module Converstion_exit_alpha_input before the update statment and get the converted format of the kunnar and pass that in the where kunnr = customer_t-kunnar...

cheer's

Mahesh

Read only

0 Likes
858

So there of two of us who pointed out not to do direct updates.

HOORAY FOR THE TWO OF US THEN!!!!!!!!!!!!!!!!!!!!!!