Getting Opening and Closing quantities of Stock with accuracy of MB5B.
I was required to get the opening and closing stock of particular material at a particular date(Means calling mb5b report to get opening & closing issued stock) .
So the main logic behind is :
Just Declare this code in top decalaration part :
DATA : is_rspar TYPE rsparams,
it_rspar TYPE TABLE OF rsparams,
it_list TYPE STANDARD TABLE OF abaplist,
it_list1 TYPE STANDARD TABLE OF ty_list,
str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
str4 TYPE string,
str5 TYPE string,
str6 TYPE string,
str7 TYPE string,
str8 TYPE string,
str9 TYPE string,
str10 TYPE string,
str11 TYPE string,
str12 TYPE string,
str13 TYPE string,
str14 TYPE string,
str15 TYPE string,
str16 TYPE string,
str17 TYPE string.
it_rspar TYPE TABLE OF rsparams,
it_list TYPE STANDARD TABLE OF abaplist,
it_list1 TYPE STANDARD TABLE OF ty_list,
str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
str4 TYPE string,
str5 TYPE string,
str6 TYPE string,
str7 TYPE string,
str8 TYPE string,
str9 TYPE string,
str10 TYPE string,
str11 TYPE string,
str12 TYPE string,
str13 TYPE string,
str14 TYPE string,
str15 TYPE string,
str16 TYPE string,
str17 TYPE string.
----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
and in query F01 part where you have to call mb5b report use this logic to fetch the record.
LOOP AT lt_mara INTO DATA(wa_mara).
CLEAR : is_rspar,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str16,str17,wa_main.
REFRESH : it_rspar, it_list,it_list1.
is_rspar-selname = 'MATNR'.
is_rspar-kind = 'S'.
is_rspar-low = wa_mara-matnr."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
CLEAR : is_rspar.
is_rspar-selname = 'WERKS'.
is_rspar-kind = 'S'.
is_rspar-low = wa_mara-werks."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
CLEAR : is_rspar.
is_rspar-selname = 'DATUM'.
is_rspar-kind = 'S'.
is_rspar-low = p_date."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
*------Calling mb5b report from z-report -----------*
SUBMIT rm07mlbd WITH SELECTION-TABLE it_rspar EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = it_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = it_list1
listobject = it_list.
IF sy-subrc = 0.
READ TABLE it_list1 INTO DATA(ls_list) INDEX 4. "4 or 5 line it varies
SPLIT ls_list AT space INTO str1 str2 str3 str4 .
IF sy-subrc = 0 .
CONDENSE str4.
SPLIT str4 AT '|' INTO str5 str6 str7 str8 str9 str10 str11 str12 str13 str14 str15 str16 str17.
ENDIF.
ENDIF.
REPLACE ALL OCCURRENCES OF ',' IN str8 WITH space. "open qty
REPLACE ALL OCCURRENCES OF ',' IN str9 WITH space. "reciept qty
REPLACE ALL OCCURRENCES OF ',' IN str10 WITH space. "issued qty
REPLACE ALL OCCURRENCES OF ',' IN str11 WITH space. "closing qty
REPLACE ALL OCCURRENCES OF ',' IN str16 WITH space. "closing amt
CONDENSE str8.
CONDENSE str9.
CONDENSE str10.
CONDENSE str11.
CONDENSE str16.
*--------------------MB5B data -----------------------------------------------------*
wa_main-open_qty = str8.
wa_main-issued_qty = str10.
wa_main-recpt_qty = str9.
wa_main-closed_qty = str11.
* WA_MAIN-werks = wa_mara-werks.
wa_main-werks = wa_mara-werks.
wa_main-matnr = wa_mara-matnr.
wa_main-matkl = wa_mara-matkl.
wa_main-maktx = wa_mara-maktx.
wa_main-unit = str12.
wa_main-open_amt = str16.
CLEAR : is_rspar,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str16,str17,wa_main.
REFRESH : it_rspar, it_list,it_list1.
is_rspar-selname = 'MATNR'.
is_rspar-kind = 'S'.
is_rspar-low = wa_mara-matnr."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
CLEAR : is_rspar.
is_rspar-selname = 'WERKS'.
is_rspar-kind = 'S'.
is_rspar-low = wa_mara-werks."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
CLEAR : is_rspar.
is_rspar-selname = 'DATUM'.
is_rspar-kind = 'S'.
is_rspar-low = p_date."im_date.
is_rspar-sign = 'I'.
is_rspar-option = 'EQ'.
APPEND is_rspar TO it_rspar.
*------Calling mb5b report from z-report -----------*
SUBMIT rm07mlbd WITH SELECTION-TABLE it_rspar EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = it_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = it_list1
listobject = it_list.
IF sy-subrc = 0.
READ TABLE it_list1 INTO DATA(ls_list) INDEX 4. "4 or 5 line it varies
SPLIT ls_list AT space INTO str1 str2 str3 str4 .
IF sy-subrc = 0 .
CONDENSE str4.
SPLIT str4 AT '|' INTO str5 str6 str7 str8 str9 str10 str11 str12 str13 str14 str15 str16 str17.
ENDIF.
ENDIF.
REPLACE ALL OCCURRENCES OF ',' IN str8 WITH space. "open qty
REPLACE ALL OCCURRENCES OF ',' IN str9 WITH space. "reciept qty
REPLACE ALL OCCURRENCES OF ',' IN str10 WITH space. "issued qty
REPLACE ALL OCCURRENCES OF ',' IN str11 WITH space. "closing qty
REPLACE ALL OCCURRENCES OF ',' IN str16 WITH space. "closing amt
CONDENSE str8.
CONDENSE str9.
CONDENSE str10.
CONDENSE str11.
CONDENSE str16.
*--------------------MB5B data -----------------------------------------------------*
wa_main-open_qty = str8.
wa_main-issued_qty = str10.
wa_main-recpt_qty = str9.
wa_main-closed_qty = str11.
* WA_MAIN-werks = wa_mara-werks.
wa_main-werks = wa_mara-werks.
wa_main-matnr = wa_mara-matnr.
wa_main-matkl = wa_mara-matkl.
wa_main-maktx = wa_mara-maktx.
wa_main-unit = str12.
wa_main-open_amt = str16.
*--- this was main logic to fetch the data from mb5b ---------*
endloop.
Data from internal table ,please check whether you have data in 4th line or 5th line .
on basis of that please change read logic to 5th line and condense part logic .