Stock

Hi all,
   I have created a report for displaying stock details. if i give the material nos and date it should fetch the opening stock closing stock for that particular date and also for the first day of the given date month.  for the first day if there is no opening or closing stock it is giving the previus material no opening and closing stock. i cudn't correct this problem. i have attached the coding behind.. please help me in this regards,
karthi..
REPORT  ZMONTHLY_STOCKREPORT.
TABLES : mara,mkpf,mseg,mbew.
type-pools : slis.
DATA: it_sort         TYPE slis_t_sortinfo_alv,
      it_fieldcat     TYPE slis_t_fieldcat_alv,
      it_commentary   TYPE slis_t_listheader,
      it_events       TYPE slis_t_event,
      it_events_f     TYPE slis_t_event.
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_layout TYPE slis_layout_alv.
DATA: fieldcatalog1 TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_layout1 TYPE slis_layout_alv.
*WORK AREA
DATA: wa_fieldcat LIKE LINE OF it_fieldcat,
      wa_events   LIKE LINE OF it_events,
      wa_layout   TYPE slis_layout_alv,
      wa_print    TYPE slis_print_alv,
      wa_commentary   TYPE slis_listheader.
data : it_mara type table of mara with header line.
data : it_mkpf type table of mkpf with header line.
data : it_mseg type table of mseg with header line.
data : it_mbew type table of mbew with header line.
data : it_mkpft type table of mkpf with header line.
data : it_msegt type table of mseg with header line.
data : it_mbewt type table of mbew with header line.
DATA   : wrk_receipts TYPE mseg-menge,
         wrk_issues   TYPE mseg-menge,
         wrk_ret      TYPE mseg-menge.
DATA   : wrk_receipts1 TYPE mseg-menge,
         wrk_issues1   TYPE mseg-menge,
         wrk_ret1     TYPE mseg-menge.
DATA   : wrk_index TYPE i.
DATA   : wrk_index1 TYPE i.
DATA   : wa_mseg LIKE LINE OF it_mseg.
DATA   : wa_msegt LIKE LINE OF it_msegt.
data : begin of ts_output occurs 0 ,
         matnr   likE mara-matnr,
         opstock likE mbew-lbkum,
         clstock likE mbew-lbkum,
         rcpts   likE mseg-menge,
         issue   likE mseg-menge,
         rets    likE mseg-menge,
         rcpts1   likE mseg-menge,
         issue1   likE mseg-menge,
         rets1   likE mseg-menge,
         verpr   likE mbew-verpr,
         opstock1 likE mbew-lbkum,
         clstock1 likE mbew-lbkum,
        END OF ts_output.
data w_date(8) type c.
data w_date1(8) type c.
*data : begin of itab_output occurs 0,
      matnr type mara-matnr,
      opstock1 TYPE mbew-lbkum,
      clstock1 TYPE mbew-lbkum,
       rcpts1   TYPE mseg-menge,
        issue1   TYPE mseg-menge,
        rets1   TYPE mseg-menge,
*end of itab_output.
DATA : begin of it_output occurs 0,
       matnr   TYPE mara-matnr,
         opstock likE mbew-lbkum,
         clstock likE mbew-lbkum,
         rcpts   likE mseg-menge,
         issue   likE mseg-menge,
         rets    likE mseg-menge,
         verpr   likE mbew-verpr,
    end of it_output.
DATA : begin of itab_output occurs 0,
       matnr   TYPE mara-matnr,
         opstock1 likE mbew-lbkum,
         clstock1 likE mbew-lbkum,
         issue1 like mseg-menge,
         rets1 like mseg-menge,
         rcpts1 like mseg-menge,
         end of itab_output.
*DATA : it_output TYPE TABLE OF ts_output.
*DATA : itab_output TYPE TABLE OF ts_output.
DATA : wa_output LIKE LINE OF it_output.
DATA : wa_output1 LIKE LINE OF itab_output.
DATA : wa_itab LIKE LINE OF ts_output.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: MATNO  FOR MARA-MATNR,
                p_dat     FOR sy-datum   OBLIGATORY  NO-EXTENSION NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b1.
PERFORM data_retreival.
perform processdata.
PERFORM build_fieldcatalog.
PERFORM build_layout.
IF it_output[] IS NOT INITIAL.
  PERFORM display_alv_report.
ELSE.
  MESSAGE 'No data matches Selection' TYPE 'E'.
ENDIF.
*&      Form  build_fieldcatalog
      text
-->  p1        text
<--  p2        text
FORM build_fieldcatalog .
  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material No'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'OPSTOCK'.
  fieldcatalog-seltext_m   = 'Opening Stock'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'CLSTOCK'.
  fieldcatalog-seltext_m   = 'Closing Stock'.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'RCPTS'.
  fieldcatalog-seltext_m   = 'Receipts'.
  fieldcatalog-col_pos     =  4.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'ISSUE'.
  fieldcatalog-seltext_m   = 'Issue'.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'RETS'.
  fieldcatalog-seltext_m   = 'Returns'.
  fieldcatalog-col_pos     =  6.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'VERPR'.
  fieldcatalog-seltext_m   = 'Moving Avg Price'.
  fieldcatalog-col_pos     =  7.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'OPSTOCK1'.
  fieldcatalog-seltext_m   = 'Op month for Month'.
  fieldcatalog-col_pos     =  8.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'clstock1'.
  fieldcatalog-seltext_m   = 'Cl stock for month'.
  fieldcatalog-col_pos     =  9.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " build_fieldcatalog
*&      Form  build_layout
      text
-->  p1        text
<--  p2        text
FORM build_layout .
  gd_layout-no_input  = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-zebra = 'X'.
ENDFORM.                    " build_layout
*&      Form  display_alv_report
      text
-->  p1        text
<--  p2        text
FORM display_alv_report .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
  I_INTERFACE_CHECK                 = ' '
  I_BYPASSING_BUFFER                = ' '
  I_BUFFER_ACTIVE                   = ' '
     i_callback_program                = sy-repid
  I_CALLBACK_PF_STATUS_SET          = ' '
    i_callback_user_command           = 'USER_COMMAND'
  I_CALLBACK_TOP_OF_PAGE            = ' '
  I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
  I_CALLBACK_HTML_END_OF_LIST       = ' '
  I_STRUCTURE_NAME                  =
  I_BACKGROUND_ID                   = ' '
  I_GRID_TITLE                      =
  I_GRID_SETTINGS                   =
     is_layout                         = gd_layout
     it_fieldcat                       = fieldcatalog[]
  IT_EXCLUDING                      =
  IT_SPECIAL_GROUPS                 =
  IT_SORT                           =
  IT_FILTER                         =
  IS_SEL_HIDE                       =
     i_default                         = 'X'
     i_save                            = 'A'
  IS_VARIANT                        =
  it_events                         = v_events
  IT_EVENT_EXIT                     =
  IS_PRINT                          =
  IS_REPREP_ID                      =
  I_SCREEN_START_COLUMN             = 0
  I_SCREEN_START_LINE               = 0
  I_SCREEN_END_COLUMN               = 0
  I_SCREEN_END_LINE                 = 0
  I_HTML_HEIGHT_TOP                 = 0
  I_HTML_HEIGHT_END                 = 0
  IT_ALV_GRAPHICS                   =
  IT_HYPERLINK                      =
  IT_ADD_FIELDCAT                   =
  IT_EXCEPT_QINFO                   =
  IR_SALV_FULLSCREEN_ADAPTER        =
IMPORTING
  E_EXIT_CAUSED_BY_CALLER           =
  ES_EXIT_CAUSED_BY_USER            =
    TABLES
      t_outtab                          = ts_output
EXCEPTIONS
  PROGRAM_ERROR                     = 1
  OTHERS                            = 2
  IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " display_alv_report
*&      Form  data_retreival
      text
-->  p1        text
<--  p2        text
FORM data_retreival .
  SELECT   *
           FROM  MARA
           INTO  TABLE it_MARA
           WHERE matNR   IN MATNO.
  IF it_mara[] IS NOT INITIAL.
    SELECT *
           FROM
           mbew
           INTO TABLE
           it_mbew
           FOR ALL ENTRIES IN it_mara
           WHERE matnr EQ it_mara-matnr.
  ENDIF.
IF sy-subrc = 0.
    LOOP AT it_mbew.
      wa_output-matnr   = it_mbew-matnr.
      wa_output-clstock = it_mbew-lbkum.                 " * 1000.
      wa_output-opstock = it_mbew-lbkum .               "  * 1000.
      wa_output-verpr   = it_mbew-verpr.
      APPEND wa_output TO it_output.
      CLEAR : it_mbew,
              wa_output.
    ENDLOOP.
  ENDIF.
SELECT *
         FROM
         mkpf
         INTO TABLE it_mkpf
         WHERE
         budat LE sy-datum
         AND
         budat GE p_dat-low.
       and bwart in ('101','102','122','123','201','202').
  IF sy-subrc EQ 0.
    SELECT *
           FROM
           mseg
           INTO TABLE it_mseg
           FOR ALL ENTRIES IN it_mkpf
           WHERE mblnr EQ it_mkpf-mblnr
           AND   bwart IN ('101','102','122','123','201','202').
    IF sy-subrc EQ 0.
      SORT it_mseg BY matnr.
      LOOP AT it_mseg.
        wrk_index = sy-tabix + 1.
        READ TABLE it_mseg INTO wa_mseg INDEX wrk_index.
        IF it_mseg-matnr EQ wa_mseg-matnr.
*Adding up the Receipts and subtracting reversal of receipts
          IF it_mseg-bwart EQ '101'.
            wrk_receipts = wrk_receipts + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '102'.
            wrk_receipts = wrk_receipts - it_mseg-menge.
          ENDIF.
*Adding up the Issues and subtracting the reversals
          IF it_mseg-bwart EQ '201'.
            wrk_issues = wrk_issues + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '202'.
            wrk_issues = wrk_issues - it_mseg-menge.
          ENDIF.
*Adding up the Returns and subtracting the reversals
          IF it_mseg-bwart EQ '122'.
            wrk_ret = wrk_ret + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '123'.
            wrk_ret = wrk_ret - it_mseg-menge.
          ENDIF.
        ELSE."when last record or no
*Adding up the Receipts and subtracting reversal of receipts
          IF it_mseg-bwart EQ '101'.
            wrk_receipts = wrk_receipts + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '102'.
            wrk_receipts = wrk_receipts - it_mseg-menge.
          ENDIF.
*Adding up the Issues and subtracting the reversals
          IF it_mseg-bwart EQ '201'.
            wrk_issues = wrk_issues + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '202'.
            wrk_issues = wrk_issues - it_mseg-menge.
          ENDIF.
*Adding up the Returns and subtracting the reversals
          IF it_mseg-bwart EQ '122'.
            wrk_ret = wrk_ret + it_mseg-menge.
          ELSEIF it_mseg-bwart EQ '123'.
            wrk_ret = wrk_ret - it_mseg-menge.
          ENDIF.
          READ TABLE it_output INTO wa_output WITH KEY matnr = it_mseg-matnr.
          IF sy-subrc EQ 0.
            wa_output-rcpts = wrk_receipts.
            wa_output-issue = wrk_issues.
            wa_output-rets  = wrk_ret.
            wa_output-opstock = wa_output-clstock + wa_output-issue + wa_output-rets -  wa_output-rcpts.
            modify it_output FROM wa_output INDEX sy-tabix TRANSPORTING rcpts issue rets opstock.
          ENDIF.
          CLEAR : wrk_receipts,
                  wrk_issues,
                  wrk_ret,
                  wrk_index.
        ENDIF.
        CLEAR : wa_output,
                it_mseg,
                wa_mseg.
      ENDLOOP.
    ENDIF.
  ENDIF.
w_date = p_dat+3(6).
concatenate  w_date '01' into w_date1 .
SELECT *
      FROM
      mkpf
      INTO TABLE it_mkpft
      WHERE
      budat le sy-datum and
      budat ge w_date1.
IF sy-subrc EQ 0.
    SELECT *
           FROM
           mseg
           INTO TABLE it_msegt
           FOR ALL ENTRIES IN it_mkpft
           WHERE mblnr EQ it_mkpft-mblnr
           AND   bwart IN ('101','102','122','123','201','202').
delete it_msegt where matnr not in matno.
IF sy-subrc EQ 0.
  select * from mbew into table it_mbewt for all entries in it_msegt where matnr eq it_msegt-matnr.
ENDIF.
  IF sy-subrc EQ 0.
    LOOP AT it_mbewt.
      wa_output1-matnr   = it_mbewt-matnr.
      wa_output1-clstock1 = it_mbewt-lbkum .
      wa_output1-opstock1 = it_mbewt-lbkum .
      append wa_output1 TO itab_output .
CLEAR : it_mbewt,
              wa_output1.
    ENDLOOP.
  ENDIF.
IF sy-subrc EQ 0.
      SORT it_msegt BY matnr.
delete it_msegt where matnr not in matno.
LOOP AT it_msegt.
        wrk_index1 = sy-tabix + 1.
        READ TABLE it_msegt INTO wa_msegt INDEX wrk_index1.
        IF it_msegt-matnr EQ wa_msegt-matnr.
*Adding up the Receipts and subtracting reversal of receipts
          IF it_msegt-bwart EQ '101'.
            wrk_receipts1 = wrk_receipts1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '102'.
            wrk_receipts1 = wrk_receipts1 - it_msegt-menge.
          ENDIF.
*Adding up the Issues and subtracting the reversals
          IF it_msegt-bwart EQ '201'.
            wrk_issues1 = wrk_issues1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '202'.
            wrk_issues1 = wrk_issues1 - it_msegt-menge.
          ENDIF.
*Adding up the Returns and subtracting the reversals
          IF it_msegt-bwart EQ '122'.
            wrk_ret1 = wrk_ret1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '123'.
            wrk_ret1 = wrk_ret1 - it_msegt-menge.
          ENDIF.
        ELSE."when last record or no
*Adding up the Receipts and subtracting reversal of receipts
          IF it_msegt-bwart EQ '101'.
            wrk_receipts1 = wrk_receipts1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '102'.
            wrk_receipts1 = wrk_receipts1 - it_msegt-menge.
          ENDIF.
*Adding up the Issues and subtracting the reversals
          IF it_msegt-bwart EQ '201'.
            wrk_issues1 = wrk_issues1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '202'.
            wrk_issues1 = wrk_issues1 - it_msegt-menge.
          ENDIF.
*Adding up the Returns and subtracting the reversals
          IF it_msegt-bwart EQ '122'.
            wrk_ret1 = wrk_ret1 + it_msegt-menge.
          ELSEIF it_msegt-bwart EQ '123'.
            wrk_ret1 = wrk_ret1 - it_msegt-menge.
          ENDIF.
          READ TABLE itab_output INTO wa_output1 WITH KEY matnr = it_msegt-matnr.    " changed mbewt instead of msegt
               IF sy-subrc EQ 0.
            wa_output1-rcpts1 = wrk_receipts1.
            wa_output1-issue1 = wrk_issues1.
            wa_output1-rets1  = wrk_ret1.
            wa_output1-opstock1 = wa_output1-clstock1 + wa_output1-issue1 + wa_output1-rets1 -  wa_output1-rcpts1.
          MODIFY itab_output FROM wa_output1 INDEX sy-tabix TRANSPORTING opstock1 issue1 rets1 rcpts1.
         ENDIF.
          CLEAR : wrk_receipts1,
                  wrk_issues1,
                  wrk_ret1,
                  wrk_index1.
        ENDIF.
        CLEAR : wa_output1,
                it_msegt,
                wa_msegt.
      ENDLOOP.
    ENDIF.
  ENDIF.
endform.
form processdata.
loop at it_output.
  clear ts_output.
  wa_itab-matnr = it_output-matnr.
  wa_itab-opstock = it_output-opstock.
  wa_itab-clstock = it_output-clstock.
  wa_itab-rcpts = it_output-rcpts.
  wa_itab-issue = it_output-issue.
  wa_itab-rets = it_output-rets.
  read table itab_output with  key matnr = it_output-matnr.
  if sy-subrc = 0.
  wa_itab-opstock1 = itab_output-opstock1.
  wa_itab-clstock1 = itab_output-clstock1.
  endif.
append  wa_itab to ts_output.
  endloop.
endform.

See this thread: http://discussions.apple.com/thread.jspa?threadID=1780647&tstart=255

Similar Messages

  • Can our hp laserjet enterprise 500 color printer m551use 67lb card stock?

    The printer specifications list card stock but no weights. 
    This question was solved.
    View Solution.

    Hello,
    the required media weight is not supported by the printer.
    As you may find listed within the Media Weight specification below, the printer support up to 58 lb media.
    Media weight:
    Tray 1: 16 to 58 lb (plain); 28 to 58 lb (glossy);
    Tray 2: 16 to 43 lb (plain paper); 28 to 58 lb (glossy paper)
     You may find the product specification below:
    http://h10010.www1.hp.com/wwpc/us/en/sm/WF06b/18972-18972-3328060-15077-236268-4184772-4184773-41847...
    Regards,
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • MB5B Report table for Open and Closing stock on date wise

    Hi Frds,
    I am trying get values of Open and Closing stock on date wise form the Table MARD and MBEW -Material Valuation but it does not match with MB5B reports,
    Could anyone suggest correct table to fetch the values Open and Closing stock on date wise for MB5B reports.
    Thanks
    Mohan M

    Hi,
    Please check the below links...
    Query for Opening And  Closing Stock
    Inventory Opening and Closing Stock
    open stock and closing stock
    Kuber

  • Adobe Stock Photos Stuck in Trash and Photoshop CS2 won't run!

    Okay, I apparently did something stupid. I'm not even sure how this happened, but I realized that Adobe Stock Photos folder was sitting on my desktop (I'm using OS X 10.5.6). I don't know when this happened and I didn't think I needed it so I dragged it to the trash. NOW I cannot run any of my Adobe software (includes Photoshop CS2, Illustrator CS2 and GoLive CS2).
    I can see the folder sitting in my trash, but it won't let me drag it back out. So, just as a test, I tried dragging out the one other file (.jpg) and I can't get that one either. I know this isn't a Mac forum, but I'm desparate and cannot find anything to help me.
    Probably I am going to have to reinstall everything and (of course) I can't find my CDs!!! Please don't get angry if I'm asking the wrong question. I've done an internet search and I cannot find any solutions.
    Thanks, Anne

    Adobe stock photos does not even exist anymore.
    Have you tried deleting your trash? I have no Adobe stock Photos on my computer and everything works. try restarting the computer.

  • Consignment stock is NOT getting displayed in the MC.9 trnasaction.

    Hi experts,
    We have some vendor consignement stock for some of our materials.
    In inventory trnasactions like MMBE, MB54 it is corrctly displayed.
    In the structure S032 also the consigment stock was updated. But we are not able to see this Consignement stock in the transaction MC.9
    Mc.9 is showing ZERO consignment stock.
    What is the reason for this?
    How to correct this?
    Please help us in solving this.
    Regards,
    Vijove

    Hi,
    Your question can be answered in this [forum Topic|ABAP Development; in a shor time..
    Regards
    Narin.

  • Report for Missing qty in stock transfer

    how to Create a Missing Quantity list that gives the difference between sent and received quantities during Stock transfer. and send me tables involved in that, primary keys also

    suppose, if we transfer goods from plant to plant or St loc to st loc with in one plant, if some goods missed due to some problems, i need that info.
    diff beteen sending stock of plant 1 and receiving stock in plant2
    Where can i gte all this fields

  • Purchasing Report for invoice and stock

    Hi guys,
    in your opinion does it exist a unique report which contains the following informations for suppliers:
    -          invoice codes from supplier not yet paid
    -          POu2019s to supplier not yet delivered
    -          ATH stock at supplier
    At the moment my customer separates informations per supplier  via FBL1N (invoices not paid), ME2L or ME2M (open for delivery), and MB52 (special stock, type O)
    Iu2019m looking for a solution were this 3 information will show on 1 screen by entering the supplier.I have tyed with ME2M but it is not sufficient...
    Thanks in advance best regards
    Massimiliano

    hi,
    What are you trying to get is an Updates from three different area, which are not connected to each other..
    FBL1N will get updated once the Payement is done,
    ME2M would be updated once the GR is done, (ME2M does have any selection Parameter which will include 'Payement done')
    MB52 would be cumulative Stock on Hand (this stock deoesnt link to PO)
    However, you can go for a small Z program to built a customised Report.

  • Report for stock statement

    hi guy's,
       i am doing report for the stock statement .... my issue is in MB5B if i reverse some document it shows as it move's to issue QTY and my receipt is same but my closing stock is correct ...is there any std report avalible ....
    thank's in advance

    Use this code :
    TABLES : MSEG,MKPF,MARA,MAKT,BEWART,MSLB,BSIM.
    TYPE-POOLS : SLIS.
    DATA : IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
           IT_LIST_HEADER TYPE SLIS_T_LISTHEADER,
           IT_EVENTS TYPE SLIS_T_EVENT,
           GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
           WA_SORT TYPE SLIS_SORTINFO_ALV,
           IT_SORT TYPE SLIS_T_SORTINFO_ALV,
           REPID LIKE SY-REPID,
           FRM_DATE(10),TO_DATE(10),
           DISPTEXT(255),DISPTEXT2(255).
    TYPES : BEGIN OF ST_OPBAL,
             MATNR LIKE MSEG-MATNR,
             MAKTX LIKE MAKT-MAKTX,
             BATCH LIKE MSEG-CHARG,
             BWART LIKE MSEG-BWART,
             MENGE LIKE MSEG-MENGE,
             ZEILE LIKE MSEG-ZEILE,
             WERKS LIKE MSEG-WERKS,
             SOBKZ LIKE MSEG-SOBKZ,
             BUDAT LIKE MKPF-BUDAT,
             SHKZG LIKE MSEG-SHKZG,
             DMBTR LIKE MSEG-DMBTR,
             MBLNR LIKE MSEG-MBLNR,
             LGORT LIKE MSEG-LGORT,
           END OF ST_OPBAL.
    DATA : OPBAL TYPE ST_OPBAL OCCURS 0 WITH HEADER LINE,
           TMP_OPBAL TYPE ST_OPBAL OCCURS 0 WITH HEADER LINE.
    DATA : BEGIN OF BAL_NOREF OCCURS 0,
              MATNR LIKE MARA-MATNR,
              SHKZG LIKE MSEG-SHKZG,
              DMBTR LIKE MSEG-DMBTR,
           END OF BAL_NOREF.
    DATA : BEGIN OF OPBAL2 OCCURS 0,
             SNO(3)      TYPE N,
             MATNR       LIKE MSEG-MATNR,
             MAKTX       LIKE MAKT-MAKTX,
             OP_BAL      LIKE MSEG-MENGE,
             OP_STKVAL   LIKE MSEG-DMBTR,   "NEW
             REC         LIKE MSEG-MENGE,
             T_OPBAL_REC LIKE MSEG-MENGE,
             REC_STKVAL  LIKE MSEG-DMBTR,   "NEW
             ISS         LIKE MSEG-MENGE,
             ISS_STKVAL  LIKE MSEG-DMBTR,   "NEW
             SALES       LIKE MSEG-MENGE,
             T_ISS       LIKE MSEG-MENGE,
             CL_BAL      LIKE MSEG-MENGE,
             BATCH       LIKE MSEG-CHARG,
             SUBCON      LIKE MSEG-MENGE,
             CL_STKVAL   LIKE MSEG-DMBTR,
           END OF OPBAL2.
    DATA  SERNO(4) TYPE C.
    DATA OPTOT  TYPE P DECIMALS 3.
    DATA RECTOT TYPE P DECIMALS 3.
    DATA ISSTOT TYPE P DECIMALS 3.
    DATA TOTALL TYPE P DECIMALS 3.
    DATA FLG        TYPE N.
    DATA FLAG       TYPE N.
    DATA STOCKVAL        TYPE MSEG-DMBTR.
    DATA REC_STOCKVAL    TYPE MSEG-DMBTR.
    DATA ISS_STOCKVAL    TYPE MSEG-DMBTR.
    DATA CL_STKVAL       TYPE MSEG-DMBTR.
    SELECTION-SCREEN BEGIN OF BLOCK X WITH FRAME.
         SELECT-OPTIONS: P_MATNR FOR MSEG-MATNR,
                         P_MGRP  FOR MARA-MATKL,
                         P_DATE FOR MKPF-BUDAT,
         P_PLANT FOR MSEG-WERKS DEFAULT  'NB01' OBLIGATORY NO INTERVALS
                                                    NO-EXTENSION .
         SELECT-OPTIONS: P_STLOC FOR MSEG-LGORT NO INTERVALS NO-EXTENSION.
    SELECTION-SCREEN END OF BLOCK X.
    INITIALIZATION.
       REPID = SY-REPID.
       PERFORM FILL_FLDCAT USING IT_FLDCAT.
       PERFORM FILL_EVENTS USING IT_EVENTS.
       PERFORM FILL_LAYOUT USING GS_LAYOUT.
    START-OF-SELECTION.
      CONCATENATE P_DATE-LOW6(2) '.' P_DATE-LOW4(2) '.' P_DATE-LOW+0(4)
      INTO FRM_DATE.
      CONCATENATE P_DATE-HIGH6(2) '.' P_DATE-HIGH4(2) '.' P_DATE-HIGH+0(4)
      INTO TO_DATE.
      CONCATENATE TEXT-003 FRM_DATE' TO : ' TO_DATE INTO DISPTEXT.
      CONCATENATE TEXT-004 P_PLANT-LOW ' Storage Location : ' P_STLOC-LOW
      INTO DISPTEXT2.
      PERFORM FILL_HEADER USING IT_LIST_HEADER.
      SELECT  A~MATNR
              F~MAKTX
              A~CHARG
              A~BWART
              A~MENGE
              A~ZEILE
              A~WERKS
              A~SOBKZ
              D~BUDAT
              A~SHKZG
              A~DMBTR
              A~MBLNR
              A~LGORT
              INTO TABLE OPBAL
       FROM MKPF AS D JOIN MSEG AS A
               ON DMBLNR = AMBLNR  AND
                  DMJAHR = AMJAHR
            JOIN MARA AS E
               ON EMATNR = AMATNR
            JOIN MAKT AS F
               ON FMATNR = AMATNR
       WHERE   A~MATNR IN P_MATNR
         AND   A~WERKS IN P_PLANT
         AND   A~KZBEW IN (' ','B')
         AND   E~MATKL IN P_MGRP
         AND   A~BWART NOT IN ('541','542','321','322','121')
         AND   A~KZVBR NOT IN ('A')
         AND   D~BUDAT LE P_DATE-HIGH.
    LOOP AT OPBAL WHERE BWART EQ '544' AND LGORT EQ ''.
       TMP_OPBAL = OPBAL.
       APPEND TMP_OPBAL.
    ENDLOOP.
    DELETE OPBAL WHERE ( BWART EQ '309' AND DMBTR EQ 0  ).
    DELETE OPBAL WHERE ( BWART NE '543' AND LGORT EQ '' ).
    LOOP AT TMP_OPBAL.
       OPBAL = TMP_OPBAL.
       APPEND OPBAL.
    ENDLOOP.
    STOCKVAL = 0.
    SORT OPBAL BY MATNR BATCH BUDAT.
    LOOP AT OPBAL.
      SELECT SINGLE LBLAB INTO MSLB-LBLAB FROM MSLB
                            WHERE MATNR = OPBAL-MATNR.
      IF OPBAL-BUDAT LT P_DATE-LOW.
         IF OPBAL-SHKZG = 'H'.
            OPTOT = OPTOT - OPBAL-MENGE.
         ELSEIF OPBAL-SHKZG = 'S'.
            OPTOT = OPTOT + OPBAL-MENGE.
         ENDIF.
    For the duration   II part  *****************
      ELSEIF OPBAL-BUDAT IN P_DATE.
         IF OPBAL-SHKZG = 'H'.
            ISSTOT      = ISSTOT + OPBAL-MENGE.
         ELSEIF OPBAL-SHKZG = 'S'.
            RECTOT = RECTOT + OPBAL-MENGE.
         ENDIF.
      ENDIF.
    AT END OF BATCH. " modified for chek
       READ TABLE OPBAL INDEX SY-TABIX.
       CLEAR BAL_NOREF. REFRESH BAL_NOREF.
       SELECT MATNR SHKZG SUM( DMBTR )
         INTO TABLE BAL_NOREF
         FROM BSIM
        WHERE BUDAT LT P_DATE-LOW  AND
              MATNR EQ OPBAL-MATNR AND
              BWTAR EQ OPBAL-BATCH AND
              BWKEY IN P_PLANT     AND
              BLART IN ('RE','WE','WA','PR')
        GROUP BY MATNR SHKZG.
       LOOP AT BAL_NOREF.
          IF BAL_NOREF-SHKZG = 'H'.
             STOCKVAL = STOCKVAL - BAL_NOREF-DMBTR.
          ELSE.
             STOCKVAL = STOCKVAL + BAL_NOREF-DMBTR.
          ENDIF.
       ENDLOOP.
       CLEAR BAL_NOREF. REFRESH BAL_NOREF.
       SELECT MATNR SHKZG SUM( DMBTR )
         INTO TABLE BAL_NOREF
         FROM BSIM
        WHERE BUDAT IN P_DATE AND
              MATNR EQ OPBAL-MATNR AND
              BWTAR EQ OPBAL-BATCH AND
              BWKEY IN P_PLANT     AND
              BLART IN ('RE','WE','WA','PR')
        GROUP BY MATNR SHKZG.
       LOOP AT BAL_NOREF.
          IF BAL_NOREF-SHKZG = 'H'.
             ISS_STOCKVAL = ISS_STOCKVAL + BAL_NOREF-DMBTR.
          ELSE.
             REC_STOCKVAL = REC_STOCKVAL + BAL_NOREF-DMBTR.
          ENDIF.
       ENDLOOP.
       " MSLB-LBLAB (STOCK WITH SUBCONTRACTOR).
       CL_STKVAL       = STOCKVAL + REC_STOCKVAL - ISS_STOCKVAL.
       TOTALL =  OPTOT + RECTOT - ISSTOT.
       IF OPTOT = '0'   AND RECTOT = '0'  AND ISSTOT = '0'.
          FLG = 1.
       ENDIF.
       IF FLG = 1.
          CLEAR FLG.
       ELSE.
          SERNO = SERNO + 1.
          OPBAL2-SNO         = SERNO.
          OPBAL2-MATNR       = OPBAL-MATNR.
          OPBAL2-MAKTX       = OPBAL-MAKTX.
          OPBAL2-OP_BAL      = OPTOT.
          OPBAL2-REC         = RECTOT.
          OPBAL2-T_OPBAL_REC = OPTOT + RECTOT.
          OPBAL2-ISS         = ISSTOT.
          OPBAL2-T_ISS       = ISSTOT.
          OPBAL2-CL_BAL      = TOTALL.
          OPBAL2-BATCH       = OPBAL-BATCH.
          OPBAL2-SUBCON      = MSLB-LBLAB.
          OPBAL2-OP_STKVAL   = STOCKVAL.
          OPBAL2-ISS_STKVAL  = ISS_STOCKVAL.
          OPBAL2-REC_STKVAL  = REC_STOCKVAL.
          OPBAL2-CL_STKVAL   = CL_STKVAL.
          APPEND OPBAL2.
       ENDIF.
      OPTOT = 0.
      RECTOT = 0.
      ISSTOT = 0.
      STOCKVAL = 0.
      ISS_STOCKVAL = 0.
      REC_STOCKVAL = 0.
      CL_STKVAL    = 0.
    ENDAT.
    ENDLOOP.
      WA_SORT-SPOS = 1.
      WA_SORT-FIELDNAME = 'MATNR'.
      WA_SORT-UP = 'X'.
    WA_SORT-SUBTOT = 'X'.
    APPEND WA_SORT TO IT_SORT.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM = REPID
          IT_FIELDCAT        = IT_FLDCAT
          IT_EVENTS          = IT_EVENTS
          IS_LAYOUT          = GS_LAYOUT
          IT_SORT            = IT_SORT
        TABLES
          T_OUTTAB           = OPBAL2.
    FORM FILL_FLDCAT USING P_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.
       PERFORM FILL_PARAM_FLDCAT USING  1 'SNo'          'SNO'       ' ' 'X'
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  2 'Material No.' 'MATNR'     ' ' 'X'
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  3 'Description'  'MAKTX'     ' ' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  4 'Op.Bal'      'OP_BAL'     'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  5 'Op.Stock Val' 'OP_STKVAL' 'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  6 'Receipts'     'REC'       'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  7 'Total'     'T_OPBAL_REC'  'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  8 'Rect.Val.' 'REC_STKVAL'   'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING  9 'Issues'    'ISS'          'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING 10 'Iss. Val.' 'ISS_STKVAL'   'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING 11 'Cl. Bal.'     'CL_BAL'    'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING 12 'Cl.Stock Val' 'CL_STKVAL' 'X' ' '
       'OPBAL2' P_FLDCAT.
       PERFORM FILL_PARAM_FLDCAT USING 13 'BATCH '       'BATCH'     ' ' ' '
       'OPBAL2' P_FLDCAT.
    ENDFORM.
    FORM FILL_PARAM_FLDCAT USING VALUE(P_COL) VALUE(P_TEXT) VALUE(P_FLDNAME)
                           VALUE(P_DOSUM) VALUE(P_NOZERO) VALUE(P_TABNAME)
                           PP_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.
       DATA : WA_FLDCAT TYPE SLIS_FIELDCAT_ALV.
       CLEAR WA_FLDCAT.
         WA_FLDCAT-COL_POS   = P_COL.
         WA_FLDCAT-SELTEXT_M = P_TEXT.
         WA_FLDCAT-FIELDNAME = P_FLDNAME.
         WA_FLDCAT-TABNAME   = P_TABNAME.
         WA_FLDCAT-DO_SUM    = P_DOSUM.
         WA_FLDCAT-NO_ZERO   = P_NOZERO.
       APPEND WA_FLDCAT TO PP_FLDCAT.
    ENDFORM.
    FORM FILL_HEADER USING P_IT_LIST_HEADER TYPE SLIS_T_LISTHEADER.
      DATA: LS_LINE TYPE SLIS_LISTHEADER.
      CLEAR LS_LINE.
      LS_LINE-TYP = 'S'.
      LS_LINE-INFO = TEXT-002.
      APPEND LS_LINE TO P_IT_LIST_HEADER.
      CLEAR LS_LINE.
      LS_LINE-TYP = 'S'.
      LS_LINE-INFO = DISPTEXT.
      APPEND LS_LINE TO P_IT_LIST_HEADER.
      CLEAR LS_LINE.
      LS_LINE-TYP = 'S'.
      LS_LINE-INFO = DISPTEXT2.
      APPEND LS_LINE TO P_IT_LIST_HEADER.
    ENDFORM.
    FORM FILL_EVENTS USING P_IT_EVENTS TYPE SLIS_T_EVENT.
       DATA LS_EVENT TYPE SLIS_ALV_EVENT.
       MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
       MOVE 'TOP_OF_PAGE' TO LS_EVENT-NAME.
       APPEND LS_EVENT TO P_IT_EVENTS.
    ENDFORM.
    FORM TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
         IT_LIST_COMMENTARY       = IT_LIST_HEADER.
    ENDFORM.
    FORM FILL_LAYOUT USING P_GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
       P_GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
       P_GS_LAYOUT-ZEBRA             = 'X'.
       P_GS_LAYOUT-FLEXIBLE_KEY      = 'X'.
    ENDFORM.
    FOR TESTING PURPOSE.
    *SORT OPBAL BY BUDAT.
    *CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM = REPID
         IT_FIELDCAT        = IT_FLDCAT
         IT_EVENTS          = IT_EVENTS
       TABLES
         T_OUTTAB           = OPBAL.
    *FORM FILL_FLDCAT USING P_FLDCAT TYPE SLIS_T_FIELDCAT_ALV.
      PERFORM FILL_PARAM_FLDCAT USING  1 'MBLNR'        'MBLNR'
      'OPBAL' P_FLDCAT.
      PERFORM FILL_PARAM_FLDCAT USING  2 'CREDIT/DEBIT' 'SHKZG'
      'OPBAL' P_FLDCAT.
      PERFORM FILL_PARAM_FLDCAT USING  3 'MOV.TYP.'     'BWART'
      'OPBAL' P_FLDCAT.
      PERFORM FILL_PARAM_FLDCAT USING  4 'ST.LOC.'     'LGORT'
      'OPBAL' P_FLDCAT.
      PERFORM FILL_PARAM_FLDCAT USING  5 'STOCK VAL'    'DMBTR'
      'OPBAL' P_FLDCAT.
      PERFORM FILL_PARAM_FLDCAT USING  6 'POS.DATE'     'BUDAT'
      'OPBAL' P_FLDCAT.
    *ENDFORM.

  • Opening and closing stock

    Hi,
        We have a requirement in which a Customized report has to be developed. The report needs to display the opening stock , Total reciept, consumption and closing stock for supplier wise material.
       We came across a standard report MB5B in which all these values are available. However inorder to display these values in a customized report we require a standard function module. Please provide us a std function module that can solve the purpose.
    If the std module is not available (i dnt come across one) kindly porvide an alternaitve for the same.
    Regards,
          Milan Thaker

    Hi,
    Use Submit Statement to get the output data from MB5b.
    Ex:
    Create selection screen with required filelds and use like this
    SUBMIT RM07MLBD with MATNR in r_matnr
                            with LGBST eq ''
                            with BWBST eq 'X'
                            with datum in datum
                            with bukrs in bukrs
                            with werks in werks
                            with lgort in lgort
                            with charg in charg
                            with bwtar in bwtar
                            with bwart in bwart
    Rgds
    Aeda

  • Opening and closing stock at storage location level

    Dear all
    I need a std report which will give the opening and closing stock at storage location level, Or should I go for dev. if yes please guide me.
    Regards
    Samuel

    Hi,
    check if you can use S_P00_07000139 report, select "Display stock movement by plant (with amount) and further select Sloc from layout.
    Regards,
    Vikas

  • Opening and closing stock balances

    Hi
    What report can i use to show the opening and closing stock balances of materials for the last 12 months.
    Thanks
    Vinesh

    You can view the report in MMBE.
    other than this you can try
    MBEWH and MARDH
    Also follow the link:
    Re: op.& closing stock detail in MM
    Thanks
    Nisha

  • Open order qty,Delivered qty,issued qty, and closing stock---Tables

    Gurus,
    I need to Prepare a report which will show open order qty,Delivered qty,issued qty, and closing stock.
    Please help me with table names where i can find .
    Regards
    venu gopal

    Hi,
    Try EKPO & EKBE tables..
    Thx
    Raju

  • Stock balances std report

    How can i see the opening stock , reciepts , consumption , closing stock for a particular material between a particular period ??/
    pls help

    MB5B-Stock on Posting date
    Is the best T code for the query,
    Make sure you check(tick mark) the  valuated stock check box else, you will get report on only plant stock and no special stocks will be considered
    With Regards
    MNarayanan

  • Sale order stock

    Dear MM consultants,
    We need to know which inventory report will give the stock matching to MB52 report??Including sale order stock
    We need to have sale order stock with value in inventory report?? Which report fulfill this
    pl reply
    Guru

    hi,
    i need to compare MB52 with MC.9 but sale order stock not covered in MC.9?
    pl reply which report is suitable
    guru

  • BW:Inventory stock Report issue based on Vendor and PO number

    Dear Guru's.
    Requirement is to report different inventory  stock's (Total Stock, blocked stock, stock in transit..etc) based on plant, material, storage location, vendor and purchase order in BW.
    For Example:
    Plant
    material
    Stock in Transit
    Total Stock
    1000
    50000001
    0,00
    100kg
    1000
    50000002
    500kg
    600kg
    If we drag the Vendor or Purchase Order Number into the report, Data gets Splitted into +ve (Inflow) and -Ve(Outflow) values.
    For Example:
    Plant
    material
    Vendor
    Purchase Order
    Stock in Transit
    Total Stock
    1000
    50000001
    54545
    567896
    +300 kg
    +400kg
    1000
    50000001
    -300kg
    -300kg
    1000
    50000002
    54549
    567899
    +900kg
    +800kg
    1000
    50000002
    -400kg
    -200kg
    I Think this is because no vendor assigned to outflow data. this is my guess i don't have much knowledge on MM. i have tried to restrict the keyfig's with stock category, but for most of the vendors or PO 's its unassigned.
    But we need the data in single as follows. can any one suggest me any steps to achieve this in BI or BO.
    Plant
    material
    Vendor
    Purchase Order
    Stock in Transit
    Total Stock
    1000
    50000001
    54545
    567896
    0,00
    100 kg
    1000
    50000002
    54549
    567899
    500 kg
    600kg
    Thanks in Advance,
    Dev

    Hi Sheshu and hi Srinu
    Already tried constant selection but it did not helped, the same keyfigure value is displayed in all the rows.
    that means the total stock value is repeated for all the vendors for a particular material.
    For example:
    Plant
    material
    Vendor
    Purchase Order
    Stock in Transit
    Total Stock
    1000
    50000001
    54545
    567896
    0,00 kg
    +400kg
    1000
    50000001
    54546
    567898
    0,00 kg
    400kg
    1000
    50000001
    0,00 kg
    400kg
    1000
    50000002
    54549
    567899
    +900kg
    +800kg
    1000
    50000002
    + 900 kg
    + 800 kg
    Regarding the BO settings, i need to try it.
    Any more suggestions will be much more helpful.
    Thanks and Regards, Sri

  • Date Wise and Storage Location Wise Stock Qty & Value Report......

    Hi Experts,
    We want a report Date Wise(As on 31.03.2008) and Storage Location Wise Quantity & Value Report for only Finish Materials. Is there any report ?
    From Mb5b we canot get storage location wise report as we get only plant level qty and value.
    Pl. guide us.
    Regards,
    Yusuf

    Hi Yusuf,
        Try the Tcode: MC.9 there enter the site and article and executeYou will get details of the article
    stock, value. if you double click the article you will get the details of storage location.
    Hope it will be help for you
    Regards
    GK

Maybe you are looking for

  • Problem with Integration Builder Logon

    Hi all, we get the following error message when logging on  to the Integration Builder:  "Authorization error.  Unknown user name or incorrect passwords." We installed the SDK versions 1.4.2_03 and 1.4.2_05 on our computer and have local Admin rights

  • Problem during creation of equipment

    dear sap gurus, I m facing the problem creating equipment.when i creating equiment the pop message shows as "Customer-specific check determined that the update is not permitted'  plz how it can be rectified Rakesh mane

  • Error in Leave Application

    Hi, We are getting the following error in the Leave Application. Application error occurred during request processing.  Details:          com.sap.tc.webdynpro.services.sal.core.DispatcherException: Wrong WebDynpro-URL: no application name specified E

  • Reinstalled OS, now iPhone won't sync with iTunes library

    Hi all, I recently had to reinstall Tiger on my iMac G5 because Leopard kept crashing it. The iMac is where I have all of my photos and music (I use Leopard on my macbook but I don't have the media on there). When I try to sync my iPhone now, iTunes

  • Create Date Column out of Full Month Name and Year

    I am trying to use Power Query to create a new column of data as a Date.  My data contains two columns: Month as the full text name and Year, for purposes of this example, I will set all days to the 15th.  In Excel, I would simply use a formula to co