Skip to Content
0
Former Member
Jul 15, 2008 at 12:26 AM

Duplicate value in Command extract report

20 Views

Hi Experts

I am getting a duplicate record when extracting the BOM which is so called Material Extract in my words

when running the report I am getting the duplicate value for the cost estimate. near the form extract_bom_details under select queries

Can anyone help me why I am getting so by seeing the coding please.

TYPES:

BEGIN OF ty_bom,

matnr(12) TYPE c, " Material #

werks(4) TYPE c, " Plant

stprs(10) TYPE c, " Quantity

meins(3) TYPE c, " Unit of Measure

END OF ty_bom,

it_ty_bom TYPE ty_bom OCCURS 0,

*Start of block of changes for JPC20061107

BEGIN OF ty_bom_sapfmt,

matnr TYPE MARC-MATNR, " Material #

werks TYPE MARC-WERKS, " Plant

stprs TYPE MBEW-STPRS, " Quantity

meins TYPE MARA-MEINS, " Unit of Measure

END OF ty_bom_sapfmt.

  • Report COMMAND_EXTRACT_D *

REPORT command_extract_d .

*CLASS cl_gui_control DEFINITION LOAD.

*CLASS cl_gui_frontend_services DEFINITION LOAD.

  • Tables

TABLES:

kna1,

knb1,

knvv,

mara,

mast, "JPC20061107

marc,

makt,mbew,

sscrfields.

CONSTANTS: BEGIN OF gc_status,

acc TYPE zcrstat1 VALUE ' ACC',

hol TYPE zcrstat1 VALUE ' HOL',

sto TYPE zcrstat1 VALUE ' STO',

ok TYPE zcrstat1 VALUE ' OK',

hold TYPE zcrstat1 VALUE 'HOLD',

END OF gc_status.

CONSTANTS: BEGIN OF gc_reason,

000 TYPE zreason VALUE '000',

001 TYPE zreason VALUE '001',

002 TYPE zreason VALUE '002',

003 TYPE zreason VALUE '003',

004 TYPE zreason VALUE '004',

005 TYPE zreason VALUE '005',

006 TYPE zreason VALUE '006',

007 TYPE zreason VALUE '007',

008 TYPE zreason VALUE '008',

010 TYPE zreason VALUE '010',

011 TYPE zreason VALUE '011',

021 TYPE zreason VALUE '021',

022 TYPE zreason VALUE '022',

023 TYPE zreason VALUE '023',

024 TYPE zreason VALUE '024',

025 TYPE zreason VALUE '025',

026 TYPE zreason VALUE '026',

999 TYPE zreason VALUE '999',

END OF gc_reason.

TYPES: BEGIN OF ty_kna1_fields,

kunnr TYPE kna1-kunnr,

sperr TYPE kna1-sperr,

aufsd TYPE kna1-aufsd,

lifsd TYPE kna1-lifsd,

faksd TYPE kna1-faksd,

loevm TYPE kna1-loevm,

END OF ty_kna1_fields.

TYPES: BEGIN OF ty_knb1_fields,

kunnr TYPE knb1-kunnr,

bukrs TYPE knb1-bukrs,

sperr TYPE knb1-sperr,

loevm TYPE knb1-loevm,

END OF ty_knb1_fields.

TYPES: BEGIN OF ty_knvv_fields,

kunnr TYPE knvv-kunnr,

vkorg TYPE knvv-vkorg,

vtweg TYPE knvv-vtweg,

spart TYPE knvv-spart,

aufsd TYPE knvv-aufsd,

lifsd TYPE knvv-lifsd,

faksd TYPE knvv-faksd,

END OF ty_knvv_fields.

TYPES: BEGIN OF ty_knkk_fields,

kunnr TYPE knkk-kunnr,

kkber TYPE knkk-kkber,

ctlpc TYPE knkk-ctlpc,

crblb TYPE knkk-crblb,

knkli TYPE knkk-knkli,

klimk TYPE knkk-klimk,

skfor TYPE knkk-skfor,

ssobl TYPE knkk-ssobl,

END OF ty_knkk_fields.

TYPES: BEGIN OF ty_cust_stat_output,

kunnr(10) TYPE c, "Customer #

stat(4) TYPE c, "Customer status

END OF ty_cust_stat_output.

TYPES:

BEGIN OF ty_customers,

kunnr(10) TYPE c, " Customer #

div1(1) TYPE c, " Pipe delimiter

name1(32) TYPE c, " Customer name

div2(1) TYPE c, " Pipe delimiter

altkn(8) TYPE c, " Old Customer #

div3(1) TYPE c, " Pipe delimiter

stras(30) TYPE c, " Street

div4(1) TYPE c, " Pipe delimiter

ort01(20) TYPE c, " City

div5(1) TYPE c, " Pipe delimiter

regio(3) TYPE c, " State

div6(1) TYPE c, " Pipe delimiter

pstlz(4) TYPE c, " Postcode

div7(1) TYPE c, " Pipe delimiter

telf1(14) TYPE c, " Phone 1

div8(1) TYPE c, " Pipe delimiter

telf2(14) TYPE c, " Phone 2

div9(1) TYPE c, " Pipe delimiter

erdat(10) TYPE c, " date

div10(1) TYPE c, " Pipe delimiter

splant(2) TYPE c, " plant

div11(1) TYPE c, " Pipe delimiter

END OF ty_customers,

it_ty_customers TYPE ty_customers OCCURS 0,

BEGIN OF ty_custstat,

kunnr(11) TYPE c, " Customer #

company(2) TYPE c, " #

status(3) TYPE c, " acc,cod,hol,

END OF ty_custstat,

it_ty_custstat TYPE ty_custstat OCCURS 0.

TYPES:

BEGIN OF ty_materialm,

matnr(12) TYPE c, " Material #

maktx2(40) TYPE c, " Command sales desc.

maktx(16) TYPE c, " Basic description

extwg(6) TYPE c, " External Material Group

flag1(1) TYPE c, "

flag2(1) TYPE c, "

flag3(1) TYPE c, "

flag4(1) TYPE c, "

END OF ty_materialm,

it_ty_materialm TYPE ty_materialm OCCURS 0,

BEGIN OF ty_materialp,

matnr(12) TYPE c, " Material #

werks(4) TYPE c, " plant

batch(1) TYPE c, " download to batch

END OF ty_materialp,

it_ty_materialp TYPE ty_materialp OCCURS 0.

TYPES:

BEGIN OF ty_bom,

matnr(12) TYPE c, " Material #

werks(4) TYPE c, " Plant

stprs(10) TYPE c, " Quantity

meins(3) TYPE c, " Unit of Measure

END OF ty_bom,

it_ty_bom TYPE ty_bom OCCURS 0,

*Start of block of changes for JPC20061107

BEGIN OF ty_bom_sapfmt,

matnr TYPE MARC-MATNR, " Material #

werks TYPE MARC-WERKS, " Plant

stprs TYPE MBEW-STPRS, " Quantity

meins TYPE MARA-MEINS, " Unit of Measure

END OF ty_bom_sapfmt.

  • Selection screen definition

SELECTION-SCREEN: BEGIN OF BLOCK bom WITH FRAME TITLE text-004.

PARAMETERS:

p_dbom LIKE filepath-pathintern DEFAULT 'Z_COMMAND_BOM_EXTRACT',

p_fbom LIKE rlgrap-filename.

SELECT-OPTIONS:

s_bmatnr FOR MARA-MATNR, "JPC20061107

s_bwerks FOR MAST-WERKS no-extension no intervals, "JPC20061107

s_bextwg FOR mara-extwg.

SELECTION-SCREEN: END OF BLOCK bom.

SELECT-OPTIONS:

s_kunnr FOR kna1-kunnr.

SELECTION-SCREEN: END OF BLOCK ccst.

DATA: clsdir TYPE REF TO cl_gui_frontend_services.

DATA: strfolder TYPE string.

DATA: folderln TYPE i.

DATA: gva_error(1) TYPE c VALUE ' '.

  • Initial procedure on START ***************

INITIALIZATION.

p_fcust = 'CUST.prn'.

p_fmatm = 'MATM.prn'.

p_fmatp = 'MATP.prn'.

p_fbom = 'BOM.prn'.

p_fccst = 'CCSTAT.prn'.

p_fccst2 = 'CCSTATC.prn'.

p_fccstl = 'CCSTATL.prn'.

s_dextwg-option = 'BT'.

s_dextwg-low = '1'.

s_dextwg-high = '8'.

APPEND s_dextwg.

s_bextwg-option = 'BT'.

s_bextwg-low = '1'.

s_bextwg-high = '1'.

APPEND s_bextwg.

AT SELECTION-SCREEN.

IF p_ccust EQ 'X' AND ( p_fcust IS INITIAL OR p_dcust IS INITIAL ).

MESSAGE s000(zppu)

WITH 'You must specify the file details for the customer data'.

gva_error = 'X'.

ENDIF.

IF p_cmatm EQ 'X' AND ( p_fmatm IS INITIAL OR

p_fmatp IS INITIAL OR

p_dmatm IS INITIAL ).

MESSAGE s001(zppu)

WITH 'You must specify the file details for the material data'.

gva_error = 'X'.

ENDIF.

IF p_cbom EQ 'X' AND ( p_fbom IS INITIAL OR p_dbom IS INITIAL ).

MESSAGE s002(zppu)

WITH 'You must specify the file details for the BOM data'.

gva_error = 'X'.

ENDIF.

IF p_cbom EQ 'X'.

IF s_bwerks-low is initial.

MESSAGE s002(zppu)

WITH 'You must specify a plant to run BOM extract for'.

gva_error = 'X'.

ENDIF.

IF LINES( s_bwerks ) > 1.

MESSAGE s002(zppu)

WITH 'You can only specify 1 plant for BOM extract'.

gva_error = 'X'.

ENDIF.

ENDIF.

IF p_ccst EQ 'X' AND ( p_fccst IS INITIAL OR

p_fccst2 IS INITIAL OR

p_fccstl IS INITIAL OR

p_dccst IS INITIAL ).

MESSAGE s002(zppu)

WITH 'You must specify the file details for the customer'

'status data'.

gva_error = 'X'.

ENDIF.

AT SELECTION-SCREEN OUTPUT.

PERFORM user_command.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fcust.

PERFORM get_gui_filename USING p_dcust p_fcust.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fmatm.

PERFORM get_gui_filename USING p_dmatm p_fmatm.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fmatp.

PERFORM get_gui_filename USING p_dmatm p_fmatp.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fbom.

PERFORM get_gui_filename USING p_dbom p_fbom.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fccst.

PERFORM get_gui_filename USING p_dccst p_fccst.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fccst2.

PERFORM get_gui_filename USING p_dccst p_fccst2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fccstl.

PERFORM get_gui_filename USING p_dccst p_fccstl.

END-OF-SELECTION.

  • Data selection execution.

DATA: lwa_kna1 TYPE kna1,

lwa_knb1 TYPE knb1,

lwa_knvv TYPE knvv.

DATA: lwa_marc TYPE marc,

lwa_mara TYPE marav,

lwa_makt TYPE makt.

DATA: lit_marav TYPE marav OCCURS 0.

DATA: lit_customers TYPE it_ty_customers,

lwa_customers TYPE ty_customers.

DATA: lit_custstat TYPE it_ty_custstat,

lwa_custstat TYPE ty_custstat.

DATA: lit_materialm TYPE it_ty_materialm,

lwa_materialm TYPE ty_materialm.

DATA: lit_materialp TYPE it_ty_materialp,

lwa_materialp TYPE ty_materialp.

*(del)DATA: lwa_bomlist TYPE ty_bomlist, "JPC20061107

*(del) lit_bomlist TYPE it_ty_bomlist. "JPC20061107

DATA: lwa_bom TYPE ty_bom_sapfmt,

lit_bom TYPE it_ty_bom WITH HEADER LINE. "JPC20061107

  • lit_bom TYPE it_ty_bom. "JPC20061107

DATA: output_file TYPE string.

DATA: lock_file TYPE string.

DATA: lva_mssage TYPE string.

DATA: lva_matnr(18) TYPE n.

DATA: lva_date TYPE datum.

DATA: txtper(3) TYPE c.

DATA: custper TYPE i.

DATA: custcount TYPE i.

DATA: itemnum TYPE i.

CHECK gva_error <> 'X'.

IF p_ccust EQ 'X'. " Do the customer file extract

PERFORM extract_customer_details.

ENDIF.

IF p_cmatm EQ 'X'. " Do the Material file extract

PERFORM extract_material_details.

ENDIF.

IF p_cbom EQ 'X'. " Do the BOM file extract

PERFORM extract_bom_details.

ENDIF.

IF p_ccst EQ 'X'. " Do the customer credit status file extract

PERFORM extract_credit_status_details.

ENDIF.

&----


*& Form extract_customer_details

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM extract_customer_details.

SELECT * FROM knb1

INTO lwa_knb1

WHERE bukrs = p_dcomp.

MOVE-CORRESPONDING lwa_knb1 TO lwa_customers.

MOVE-CORRESPONDING lwa_knb1 TO lwa_custstat.

MOVE '#' TO lwa_custstat-company.

MOVE p_dwerk TO lwa_customers-splant.

--


WG1K903075: Start Delete-

  • move: '|' to lwa_customers-div1,

  • '|' to lwa_customers-div2,

  • '|' to lwa_customers-div3,

  • '|' to lwa_customers-div4,

  • '|' to lwa_customers-div5,

  • '|' to lwa_customers-div6,

  • '|' to lwa_customers-div7,

  • '|' to lwa_customers-div8,

  • '|' to lwa_customers-div9,

  • '|' to lwa_customers-div10,

  • '|' to lwa_customers-div11.

--


WG1K903075: End Delete---

--


WG1K903075: Start Insert-

MOVE: ' ' TO lwa_customers-div1,

' ' TO lwa_customers-div2,

' ' TO lwa_customers-div3,

' ' TO lwa_customers-div4,

' ' TO lwa_customers-div5,

' ' TO lwa_customers-div6,

' ' TO lwa_customers-div7,

' ' TO lwa_customers-div8,

' ' TO lwa_customers-div9,

' ' TO lwa_customers-div10,

' ' TO lwa_customers-div11.

--


WG1K903075: End Insert---

APPEND lwa_customers TO lit_customers.

APPEND lwa_custstat TO lit_custstat.

ENDSELECT.

DESCRIBE TABLE lit_customers LINES custcount.

LOOP AT lit_customers INTO lwa_customers.

txtper = 100 * sy-tabix / custcount.

custper = txtper.

SELECT SINGLE * FROM kna1

INTO lwa_kna1

WHERE kunnr = lwa_customers-kunnr.

MOVE-CORRESPONDING lwa_kna1 TO lwa_customers.

lva_date = lwa_customers-erdat.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

date_internal = lva_date

IMPORTING

date_external = lwa_customers-erdat

EXCEPTIONS

date_internal_is_invalid = 1

OTHERS = 2.

REPLACE ALL OCCURRENCES OF '.'

IN lwa_customers-erdat WITH '/'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = lwa_customers-kunnr

IMPORTING

output = lwa_customers-kunnr.

WRITE: lwa_customers-kunnr RIGHT-JUSTIFIED TO lwa_customers-kunnr.

MODIFY lit_customers FROM lwa_customers.

  • Percentage indicator display

lva_mssage = 'Extracting customers'.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

percentage = custper

text = lva_mssage.

ENDLOOP.

IF p_gui IS INITIAL.

PERFORM get_file_path USING p_dcust p_fcust output_file.

OPEN DATASET output_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

LOOP AT lit_customers INTO lwa_customers.

TRANSFER lwa_customers TO output_file.

ENDLOOP.

CLOSE DATASET output_file.

ELSE.

MESSAGE s002(zppu)

WITH 'Dataset' output_file 'cannot be opened on the server'.

ENDIF.

ELSE.

MOVE p_fcust TO output_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = output_file

filetype = 'ASC'

TABLES

data_tab = lit_customers

EXCEPTIONS

OTHERS = 11.

ENDIF.

output_file = custcount.

CONCATENATE

output_file

' Customers extracted'

INTO

lva_mssage.

  • message lva_mssage type 'I'.

ENDFORM. " extract_customer_details

&----


*& Form extract_bom_details

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM extract_bom_details.

select MARAMATNR MBEWBWKEY MBEWSTPRS MARAMEINS "JPC20061220

into lwa_bom

from ( MARAV AS MARA

inner join MARC

ON MARAMATNR = MARCMATNR

INNER join MBEW

ON MARCMATNR = MBEWMATNR

AND MARCWERKS = MBEWBWKEY

)

where MARA~MATNR in s_bmatnr

and MBEW~BWKEY in s_bwerks

and MARA~EXTWG in s_bextwg.

clear lit_bom.

WRITE lwa_bom-matnr TO lit_bom-matnr.

MOVE lwa_bom-werks TO lit_bom-werks.

MOVE: lwa_bom-stprs TO lit_bom-stprs,

lwa_bom-meins TO lit_bom-meins.

APPEND lit_bom.

ENDSELECT.

SORT lit_bom ascending.

  • Ending for lines inserted for change 20061107

IF p_gui IS INITIAL. "write to server

PERFORM get_file_path USING p_dbom p_fbom output_file.

OPEN DATASET output_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

custcount = lines( lit_bom ).

LOOP AT lit_bom.

txtper = 100 * sy-tabix / custcount.

custper = txtper.

lva_mssage = 'Extracting material B.O.Ms'.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING percentage = custper

text = lva_mssage.

TRANSFER lit_bom TO output_file.

ENDLOOP.

CLOSE DATASET output_file.

ELSE.

MESSAGE s002(zppu)

WITH 'Dataset' output_file 'cannot be opened on the server'.

ENDIF.

ELSE.

MOVE p_fbom TO output_file.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = output_file

filetype = 'ASC'

write_field_separator = ' '

TABLES

data_tab = lit_bom

EXCEPTIONS

OTHERS = 11.

ENDIF.

ENDFORM. " extract_bom_details

output with duplicate values

MARA BWKEY STPRS MEINS

10004989 BN01 28.00 TO

10004989 BN01 28.00 TO

10005010 BN01 19.00 EA

10005010 BN01 19.00 EA

10005018 BN01 800.00 BAG

10005018 BN01 800.00 BAG

10005115 BN01 82.74 TO

10005115 BN01 82.74 TO

10005117 BN01 137.30 TO

10005117 BN01 137.30 TO

Regards

Piroz