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: 

call transaction BDC

Former Member
0 Kudos

Hi SAPians,

I have a text file with data of the document number and the PO number and checking whether the document number is an order or a quote the PO number should be updated accordingly in VA02 and VA22 transactions.

Here the data is been uploaded but no values are been passed and updated into the PO field. Below is my code. Could u please check and let me know whether that works or not and if possible please do let me know where i need to correct the code.

Thanks and regards,

TABLES: vbak,

vbap,

vbkd.

DATA: BEGIN OF t_vbak OCCURS 0,

vbeln LIKE vbak-vbeln,

vbtyp LIKE vbak-vbtyp,

END OF t_vbak.

DATA: BEGIN OF str_itab OCCURS 0,

str(255),

END OF str_itab.

DATA: BEGIN OF t_input OCCURS 0,

vbeln LIKE vbak-vbeln,

bstkd LIKE vbkd-bstkd,

END OF t_input.

DATA: bdcdata TYPE TABLE OF bdcdata. "BDC Data Table

DATA: wa_bdcdata TYPE bdcdata. "BDC Data Work Area

DATA: itab TYPE TABLE OF bdcmsgcoll. "BDC Message Collection table

DATA: wa_itab TYPE bdcmsgcoll. "BDC Message Collect work area

DATA: messagetext(256) TYPE c. "Message text variable

DATA: msgno LIKE sy-msgno. "Message number variable

DATA: date(10) TYPE c. "Text form or MAD Date

DATA: zbeln(10) TYPE n.

DATA: zbtyp TYPE c.

DATA: tcode LIKE sy-tcode VALUE 'VA22', "Transaction Code

tcode1 LIKE sy-tcode VALUE 'VA02', "Transaction Code

g_mode(1) TYPE c VALUE 'N'.

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

PARAMETERS: p_file LIKE rlgrap-filename. "File Name

SELECTION-SCREEN END OF BLOCK blk1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get filename

CALL FUNCTION '/SAPDMC/LSM_F4_FRONTEND_FILE'

EXPORTING

pathname = p_file

CHANGING

pathfile = p_file

EXCEPTIONS

canceled_by_user = 1

system_error = 2

OTHERS = 3.

START-OF-SELECTION.

  • Check input parameters

IF p_file IS INITIAL.

MESSAGE i020.

LEAVE LIST-PROCESSING.

ENDIF.

  • Get input file

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

silent = 'S'

TABLES

data_tab = str_itab

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 i021.

LEAVE LIST-PROCESSING.

ELSE.

  • Delete Column Headers

CLEAR t_input.

DELETE t_input INDEX 1.

ENDIF.

LOOP AT str_itab.

SPLIT str_itab-str AT ' ' INTO

t_input-vbeln t_input-bstkd.

APPEND t_input.

ENDLOOP.

  • Process input file

LOOP AT t_input.

  • Process main

PERFORM sub_process_main.

ENDLOOP.

FORM sub_process_main .

SELECT SINGLE vbtyp FROM vbak

INTO zbtyp

WHERE vbeln = t_input-vbeln.

  • Call proper transaction

IF zbtyp = 'B'.

tcode = 'VA22'.

PERFORM va22.

ELSEIF zbtyp = 'C'.

tcode = 'VA02'.

PERFORM va02.

ENDIF.

ENDFORM.

FORM bdc_field USING value(p_program)

value(p_dynpro)

value(p_dynbegin)

value(p_fnam)

value(p_fval).

  • Populate BDC table

CLEAR wa_bdcdata.

wa_bdcdata-program = p_program.

wa_bdcdata-dynpro = p_dynpro.

wa_bdcdata-dynbegin = p_dynbegin.

wa_bdcdata-fnam = p_fnam.

wa_bdcdata-fval = p_fval.

APPEND wa_bdcdata TO bdcdata.

ENDFORM.

FORM va22 .

  • Create BDC table

CLEAR bdcdata.

REFRESH bdcdata.

    • Loop at item table

  • LOOP AT t_vbak.

  • Change PO number

PERFORM bdc_field USING:

'SAPMV45A' '4001' 'X' space space,

space space space 'VBKD-BSTKD(01)' t_input-bstkd,

space space space 'BDC_OKCODE' 'ITEMS'.

  • ENDLOOP.

  • Save changes

PERFORM bdc_field USING

  • 'SAPVB45A' '4001' 'X' space space,

space space space 'BDC_OKCODE' '=SICH'.

  • Call VA22

CALL TRANSACTION tcode USING bdcdata MODE g_mode

MESSAGES INTO itab.

LOOP AT t_input.

IF sy-subrc = 0.

WRITE: / 'PO Numbers', t_input-vbeln, 'have been changed!'.

ELSE.

WRITE: / 'Quotation number', t_input-vbeln, 'has NOT been changed!'.

LOOP AT itab INTO wa_itab.

CLEAR msgno.

msgno = wa_itab-msgnr.

CALL FUNCTION '/SAPTRX/GET_MESSAGE_TEXT'

EXPORTING

msgid = wa_itab-msgid

msgno = msgno

msgv1 = 'X'

msgv2 = 'X'

msgv3 = 'X'

msgv4 = 'X'

IMPORTING

messagetext = messagetext

EXCEPTIONS

no_message_retrieved = 1

OTHERS = 2.

WRITE / messagetext.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM.

FORM va02 .

  • Create BDC table

CLEAR bdcdata.

REFRESH bdcdata.

    • Loop at item table

  • LOOP AT t_vbak.

  • Change PO number

PERFORM bdc_field USING:

'SAPMV45A' '4001' 'X' space space,

space space space 'VBKD-BSTKD(01)' t_input-bstkd,

space space space 'BDC_OKCODE' 'ITEMS'.

  • ENDLOOP.

  • Save changes

PERFORM bdc_field USING

  • 'SAPVB45A' '4001' 'X' space space,

space space space 'BDC_OKCODE' '=SICH'.

  • Call VA22

CALL TRANSACTION tcode1 USING bdcdata MODE g_mode

MESSAGES INTO itab.

LOOP AT t_input.

IF sy-subrc = 0.

WRITE: / 'PO Numbers for:', t_input-vbeln, ' Order number have been changed!'.

ELSE.

WRITE: / 'PO Numbers for:', t_input-vbeln, 'Quotation number has NOT been changed!'.

LOOP AT itab INTO wa_itab.

CLEAR msgno.

msgno = wa_itab-msgnr.

CALL FUNCTION '/SAPTRX/GET_MESSAGE_TEXT'

EXPORTING

msgid = wa_itab-msgid

msgno = msgno

msgv1 = 'X'

msgv2 = 'X'

msgv3 = 'X'

msgv4 = 'X'

IMPORTING

messagetext = messagetext

EXCEPTIONS

no_message_retrieved = 1

OTHERS = 2.

WRITE / messagetext.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM.

2 REPLIES 2

Former Member
0 Kudos

Hi,

Check ur BDC recording. When have not passed VBELN when populating the BDC table for VA22 as well as VA02. If u not pass the document no (VBELN) then how can be PO get updated for it?

If required then do ur recording for va22 and va02 again from SHDB.

FORM va22 .

  • Create BDC table

CLEAR bdcdata.

REFRESH bdcdata.

*

o Loop at item table

  • LOOP AT t_vbak.

  • Change PO number

PERFORM bdc_field USING:

'SAPMV45A' '4001' 'X' space space,

space space space 'VBKD-BSTKD(01)' t_input-bstkd,

space space space 'BDC_OKCODE' 'ITEMS'.

  • ENDLOOP.

  • Save changes

PERFORM bdc_field USING

  • 'SAPVB45A' '4001' 'X' space space,

space space space 'BDC_OKCODE' '=SICH'.

  • Call VA22

CALL TRANSACTION tcode USING bdcdata MODE g_mode

MESSAGES INTO itab.

LOOP AT t_input.

IF sy-subrc = 0.

WRITE: / 'PO Numbers', t_input-vbeln, 'have been changed!'.

ELSE.

WRITE: / 'Quotation number', t_input-vbeln, 'has NOT been changed!'.

LOOP AT itab INTO wa_itab.

CLEAR msgno.

msgno = wa_itab-msgnr.

CALL FUNCTION '/SAPTRX/GET_MESSAGE_TEXT'

EXPORTING

msgid = wa_itab-msgid

msgno = msgno

msgv1 = 'X'

msgv2 = 'X'

msgv3 = 'X'

msgv4 = 'X'

IMPORTING

messagetext = messagetext

EXCEPTIONS

no_message_retrieved = 1

OTHERS = 2.

WRITE / messagetext.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM.

FORM va02 .

  • Create BDC table

CLEAR bdcdata.

REFRESH bdcdata.

*

o Loop at item table

  • LOOP AT t_vbak.

  • Change PO number

PERFORM bdc_field USING:

'SAPMV45A' '4001' 'X' space space,

space space space 'VBKD-BSTKD(01)' t_input-bstkd,

space space space 'BDC_OKCODE' 'ITEMS'.

  • ENDLOOP.

  • Save changes

PERFORM bdc_field USING

  • 'SAPVB45A' '4001' 'X' space space,

space space space 'BDC_OKCODE' '=SICH'.

  • Call VA22

CALL TRANSACTION tcode1 USING bdcdata MODE g_mode

MESSAGES INTO itab.

LOOP AT t_input.

IF sy-subrc = 0.

WRITE: / 'PO Numbers for:', t_input-vbeln, ' Order number have been changed!'.

ELSE.

WRITE: / 'PO Numbers for:', t_input-vbeln, 'Quotation number has NOT been changed!'.

LOOP AT itab INTO wa_itab.

CLEAR msgno.

msgno = wa_itab-msgnr.

CALL FUNCTION '/SAPTRX/GET_MESSAGE_TEXT'

EXPORTING

msgid = wa_itab-msgid

msgno = msgno

msgv1 = 'X'

msgv2 = 'X'

msgv3 = 'X'

msgv4 = 'X'

IMPORTING

messagetext = messagetext

EXCEPTIONS

no_message_retrieved = 1

OTHERS = 2.

WRITE / messagetext.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDFORM.

Regards,

Joy.

0 Kudos

I have made the changes but now the records are been updated only in the database by creating another line item, whereas i need the data(PO number) to overwrite the existing one and even the data is not been displayed in the transaction screen..

Could u please help me with that