Skip to Content
0
Former Member
Aug 30, 2007 at 12:49 PM

Correct me If i am Wrong !!!! Plzzz

49 Views

The requirment is:

Program Spec::

-


Program: For a set of selected material Read MARA-prdha and

update mvke-prodh and write out a success/fail report.

All error materials downloaded to a file.

Selection Screen:

Material (mvke-matnr)

Sales Org (mvke-vkorg)

Dis.Cha (mvke-vtweg)

Logic:

Use bapi for this update.

Material Selection logic: mara & mvke inner join where prodh

is blank + select options.

I have coded below: the <b>Problem is i am getting error like vkorg is inconsitent or blank for all Matnr i try to update plz help me with this.......</b>

ABLES : bapimathead, "HEADER DATA

bapi_mara, "CLIENT DATA

bapi_mvke, "Structure for BAPI_MVKE

bapi_mvkex, "CHECKBOX Structure for BAPI_MVKE

bapiret2,

mvke,

mara.

DATA :

BEGIN OF i_mara OCCURS 0,

matnr LIKE mara-matnr, "Material number

prdha LIKE mara-prdha, "Product hierarchy

END OF i_mara.

DATA :

BEGIN OF e_mara OCCURS 0,

matnr LIKE mara-matnr, "Material number

prdha LIKE mara-prdha, "Product hierarchy

END OF e_mara.

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

  • SELECTION SCREEN

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

SELECT-OPTIONS : material FOR mvke-matnr,

sale_og FOR mvke-vkorg,

dis_cha FOR mvke-vtweg.

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

  • START-OF-SELECTION

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

PERFORM 100_material_get.

PERFORM 200_bapi_upload.

PERFORM 300_download_error.

&----


*& Form 100_MATERIAL_GET

&----


  • TO GET MATNR AND PRDHA INTO INTERNAL TABLE

----


FORM 100_material_get .

SELECT DISTINCT amatnr aprdha INTO CORRESPONDING FIELDS OF TABLE i_mara

FROM ( mara AS a INNER JOIN mvke AS b

ON amatnr = bmatnr )

WHERE bprodh NE space AND bmatnr IN material AND b~vkorg IN sale_og

AND b~vtweg IN dis_cha.

ENDFORM. " 100_MATERIAL_GET

&----


*& Form 200_BAPI_UPLOAD

&----


  • BAPI OPERATION

----


FORM 200_bapi_upload .

LOOP AT i_mara.

IF i_mara IS INITIAL.

CONTINUE.

ENDIF.

CLEAR : bapimathead,

bapi_mara,

bapi_mvke,

bapi_mvkex,

bapiret2.

  • MATERIAL

bapimathead-material = i_mara-matnr.

  • CLIENT DATA

bapi_mvke-prod_hier = i_mara-prdha.

bapi_mvkex-prod_hier = 'X'.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = bapimathead

salesdata = bapi_mvke

salesdatax = bapi_mvkex

IMPORTING

return = bapiret2.

IF sy-subrc EQ 0.

IF bapiret2-type EQ 'E'.

e_mara-matnr = i_mara-matnr.

e_mara-prdha = i_mara-prdha.

APPEND e_mara.

ELSE.

COMMIT WORK.

WRITE:/02 i_mara-matnr,

15 'Update Successful'.

ENDIF.

ELSE.

COMMIT WORK.

e_mara-matnr = i_mara-matnr.

e_mara-prdha = i_mara-prdha.

APPEND e_mara.

ENDIF.

ENDLOOP.

ENDFORM. " 200_BAPI_UPLOAD

&----


*& Form 300_DOWNLOAD_ERROR

&----


  • DOWNLOAD ERROR FILE

----


FORM 300_download_error .

IF NOT e_mara[] IS INITIAL.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = 'D:\MATNR_ERROR_DATA.TXT'

filetype = 'DAT'

TABLES

data_tab = e_mara

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

OTHERS = 11.

IF sy-subrc <> 0.

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

ENDIF.

WRITE :/ 'ERROR FILE IN THE PATH D:\MATNR_ERROR_DATA.TXT' .

ENDIF.

ENDFORM. " 300_DOWNLOAD_ERROR