Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

help needed for report on tables vbak and vbap

Hello,

I needed help in one of my work issues, this is my first project and Iam still learning. kindly help.

I was asked to take erdat,vbeln,posnr from selection screen and compare it with the data already in tables vbap,vbak. If the data

already exists and exception needs to be raised saying that the 'data exists',but if the data is not present in the tables the

tables have to be updated. This has to be done using function module only.

Then I have to write a REPORT calling the above function module and finally displaying the number of records updated and the

list of them.

I have started writing a function module:

FUNCTION z_tableupdate.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(DATE) LIKE VBAK-ERDAT DEFAULT SY-DATUM

*" VALUE(SALESORDERNO) LIKE VBAK-VBELN

*" VALUE(ITEMNO) LIKE VBAP-POSNR

*" EXPORTING

*" VALUE(EX_VBAP) LIKE VBAP STRUCTURE VBAP

*" VALUE(SYS) LIKE SY-SYSID

*" VALUE(EX_VBAK) LIKE VBAK STRUCTURE VBAK

*" EXCEPTIONS

*" DATA_UPDATED

*" DATA_EXISTS

*"----


SELECT * FROM vbak INTO vbak_wa WHERE erdat = date

AND vbeln = salesorderno.

ENDSELECT.

SELECT * FROM vbap INTO vbap_wa WHERE posnr = itemno.

ENDSELECT.

IF sy-subrc EQ 0.

ex_vbap = vbap_wa.

ex_vbak = vbak_wa.

ELSE.

RAISE data_exists.

ENDIF.

sys = sy-sysid.

ENDFUNCTION.

_______________________________________________________________________________________________________________________________________

How is the above code for function module, will this work??

Now can I write a report to call the above function module and update the record?? if so, how to update ??? please help...Lots of thanks in advance.

Tags:
Former Member
Former Member replied

Hi,

Use the following code to get an idea.

Put following code in ur program

report ztest17.

parameters: p_vbeln like vbak-vbeln,

p_posnr like vbap-posnr,

p_erdat like sy-datum.

DATA: begin of i_vbap occurs 0.

include structure vbap.

DATA: end of i_vbap.

DATA: begin of i_vbak occurs 0.

include structure vbak.

DATA: end of i_vbak.

data : v_sysid like sy-sysid.

call function 'z_tableupdate'

exporting DATE =

SALESORDERNO = p_vbeln

ITEMNO = p_posnr

importing EX_VBAP = i_vbap

SYS = v_sysid

EX_VBAK = i_vbak

exceptions

DATA_EXISTS = 1.

if sy-subrc = 1.

WRITE: / 'No data found'.

elseif sy-subrc = 0.

  • write your update statement

endif.

Cheers,

Vikram

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question