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: 

abap report - consignment stock

Former Member
0 Kudos

Hi Experts,

when i select special stock = 'w' at the selection screen ,

all stock with 'w' and with blank will appear.

when i select special stock = blank , all stock with blank appear.

but i dunwan it to be like this.

i want it to be,

when i select special stock = 'w'. only 'w' stock will appear.

when i select special stock = 'blank'

all 'w' stock and blank stock will appear.

Can anyone please advise on this ?

Thank you in advanced.

  • Selection screen for user to select the option/condition

SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-S01.

SELECT-OPTIONS: p_plant FOR MARC-WERKS, "Plant

p_mcode FOR MCHB-MATNR, "New Material code

p_ocode FOR MARA-BISMT, "Old Material Code

p_mtype FOR MARA-MTART, "Material Type

p_mgroup FOR MARA-MATKL, "Material Group

p_sloc FOR MCHB-LGORT, "Storage Location

p_spec FOR MSKU-SOBKZ. "Special Stock

PARAMETER: c_rzero AS CHECKBOX DEFAULT 'X', "Remove zero qty item

c_old AS CHECKBOX DEFAULT '',

c_new AS CHECKBOX DEFAULT ''.

SELECTION-SCREEN END OF BLOCK 1.

  • Retrieve Material details

select p~werks m~matnr m~bismt m~mtart

into corresponding fields of table it_mat

from ( marc as p inner join mara as m

on p~matnr = m~matnr )

where m~matnr in p_mcode

and m~bismt in p_ocode

and m~mtart in p_mtype

and p~werks in p_plant

and m~matkl in p_mgroup

and p~mmsta ne '01'

order by m~matnr ASCENDING.

DELETE ADJACENT DUPLICATES FROM it_mat.

if p_spec[] is not initial.

lv_special = '1'.

endif.

IF it_mat[] is not initial and lv_special = '1'.

SELECT werks matnr kulab sobkz charg FROM MSKU

INTO CORRESPONDING FIELDS OF TABLE it_msku

for all entries in it_mat

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND sobkz = 'W'.

CLEAR: it_resultt, wa_resultt.

endif.

if it_msku[] is not initial.

loop at it_msku.

it_collmsku-werks = it_msku-werks.

it_collmsku-matnr = it_msku-matnr.

it_collmsku-kulab = it_msku-kulab.

it_collmsku-sobkz = it_msku-sobkz.

collect it_collmsku.

endloop.

clear it_msku.

endif.

LOOP AT it_mat.

CLEAR: it_resultt, wa_resultt.

  • Retrieve related details from MARD/MCHB based on conditinos

IF it_mat-sobkz = space.

Select werks matnr FROM MARC

APPENDING CORRESPONDING FIELDS OF TABLE it_resultt

where matnr = it_mat-matnr

and werks in p_plant.

wa_resultt-ltab = 'MARC'.

MODIFY it_resultt FROM wa_resultt TRANSPORTING ltab

where matnr = it_mat-matnr

and werks in p_plant.

ENDIF.

IF it_mat-xchpf = SPACE.

SELECT werks matnr labst lgort lgpbe FROM MARD

APPENDING CORRESPONDING FIELDS OF TABLE it_resultt

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND lgort IN p_sloc.

wa_resultt-ltab = 'MARD'.

MODIFY it_resultt FROM wa_resultt TRANSPORTING ltab

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND lgort IN p_sloc.

ELSE.

SELECT werks matnr charg clabs lgort FROM MCHB

APPENDING CORRESPONDING FIELDS OF TABLE it_resultt

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND lgort IN p_sloc.

wa_resultt-ltab = 'MCHB'.

MODIFY it_resultt FROM wa_resultt TRANSPORTING ltab

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND lgort IN p_sloc.

ENDIF.

  • Combine all related data into a record and keep in it_results

LOOP AT it_resultt INTO wa_resultt.

IF ( c_rzero = 'X' AND

( wa_resultt-clabs <> 0 OR wa_resultt-labst <> 0 ) )

OR ( c_rzero <> 'X' ).

  • Preparing data needed.----------

l_count = l_count + 1.

SELECT SINGLE maktx FROM MAKT

INTO (l_maktx)

WHERE matnr = wa_resultt-matnr.

SELECT SINGLE umren umrez meinh FROM MARM

INTO (l_umren, l_umrez, l_meinh)

WHERE matnr = wa_resultt-matnr

AND MEINH <> it_mat-meins.

  • Alternative Qty

l_alqty = l_umren / l_umrez * wa_resultt-clabs.

  • retrieve stroge bin if it is not found, especially for MCHB

IF wa_resultt-lgpbe IS INITIAL OR wa_resultt-lgpbe = ''.

SELECT SINGLE lgpbe FROM MARD

INTO l_lgpbe

WHERE MATNR = wa_resultt-matnr

AND WERKS = wa_resultt-werks

AND LGORT = wa_resultt-lgort.

ENDIF.

  • Retrieve all details from MBEW & decide the qty

IF wa_resultt-ltab = 'MARD'.

SELECT SINGLE vprsv verpr stprs peinh salk3 FROM MBEW

INTO (l_vprsv, l_verpr, l_stprs, l_peinh, l_salk3)

WHERE MATNR = wa_resultt-matnr

AND BWKEY = wa_resultt-werks.

l_clabs = wa_resultt-labst.

ELSE.

IF it_mat-mtart = 'ROH'.

SELECT SINGLE vprsv verpr stprs peinh salk3 FROM MBEW

INTO (l_vprsv, l_verpr, l_stprs, l_peinh, l_salk3)

WHERE MATNR = wa_resultt-matnr

AND BWTAR = wa_resultt-charg.

ELSEIF it_mat-mtart = 'FERT'.

SELECT SINGLE vprsv verpr stprs peinh salk3 FROM MBEW

INTO (l_vprsv, l_verpr, l_stprs, l_peinh, l_salk3)

WHERE MATNR = wa_resultt-matnr

AND BWKEY = wa_resultt-werks.

ENDIF.

l_clabs = wa_resultt-clabs.

ENDIF.

  • Both l_vprsv and l_stprs are also price, based on price control

  • to decide which one to use

IF l_vprsv <> 'V'.

l_verpr = l_stprs.

ENDIF.

l_untpr = l_verpr / l_peinh.

*----


wa_resultt-BISMT = IT_MAT-BISMT.

wa_resultt-sobkz = it_msku-sobkz.

wa_resultt-kulab = it_msku-kulab.

wa_resultt-matnr = it_mat-matnr.

  • Insert data into work area

wa_results-lcnt = l_count.

wa_results-werks = wa_resultt-werks.

wa_results-matnr = wa_resultt-matnr.

wa_results-BISMT = wa_resultt-BISMT.

wa_results-maktx = l_maktx.

wa_results-mtart = it_mat-mtart.

wa_results-matkl = it_mat-matkl.

wa_results-charg = wa_resultt-charg.

wa_results-clabs = l_clabs.

wa_results-meins = it_mat-meins.

wa_results-alqty = l_alqty.

wa_results-meinh = l_meinh.

wa_results-lgort = wa_resultt-lgort.

wa_results-lgpbe = l_lgpbe.

wa_results-vprsv = l_vprsv.

wa_results-curr = 'MYR'.

wa_results-price = l_verpr.

wa_results-peinh = l_peinh.

wa_results-untpr = l_untpr.

wa_results-salk3 = l_salk3.

wa_results-sobkz = wa_resultt-sobkz.

wa_results-kulab = wa_resultt-kulab.

  • Append work area into it_results

APPEND wa_results TO it_results.

ENDIF.

CLEAR wa_results.

ENDLOOP.

IF lv_special = '1'. loop at it_results into wa_results. loop at it_collmsku where matnr = wa_results-matnr and werks = wa_results-werks. wa_results-sobkz = it_collmsku-sobkz. wa_results-kulab = it_collmsku-kulab. modify it_results from wa_results. clear wa_results. endloop. endloop. endif.

6 REPLIES 6

former_member585060
Active Contributor
0 Kudos

In ur Code as u r using SOBKZ = 'W' thats why always getting the data where SOBKZ = 'W' even with p_spec field blank.

so modify as below showed in block letters

IF it_mat[] is not initial and lv_special = '1'.

SELECT werks matnr kulab sobkz charg FROM MSKU

INTO CORRESPONDING FIELDS OF TABLE it_msku

for all entries in it_mat

WHERE matnr = it_mat-matnr

AND werks IN p_plant

AND sobkz = 'W'. '' Replace = with IN p_spec

Edited by: Bala Krishna on Aug 13, 2008 10:34 AM

Former Member
0 Kudos

Hello

Modify select :


SELECT werks matnr kulab sobkz charg FROM MSKU
INTO CORRESPONDING FIELDS OF TABLE it_msku
for all entries in it_mat
WHERE matnr = it_mat-matnr
AND werks IN p_plant
AND sobkz IN p_spec.

In this case if you select special stock = 'w' at the selection screen, only 'w' stock will be appear.

And if you select special stock blank (p_cpec is initial), all stock will be appear.

0 Kudos

Hi Bala Krishna , Dzed Maroz

your suggested solution is not work.

is there any alternatives?

Thank you.

0 Kudos

Hello

Try this:


SELECT werks matnr kulab sobkz charg FROM MSKU
INTO CORRESPONDING FIELDS OF TABLE it_msku
for all entries in it_mat
WHERE matnr = it_mat-matnr
AND werks IN p_plant.

if p_spec-low eq 'W'. delete it_msku where sobkz ne 'W'. endif.
if p_spec-low eq ' '. delete it_msku where sobkz ne 'W' or sobkz ne ' '. endif.

0 Kudos

Hi Dzed Maroz ,

it's still the same results, not work...

did i miss out add in any condition and cause the mistake?

please advise.

thank you

0 Kudos

Hi expert,

thank you.