Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Comment field for Inventory Adjustments

$
0
0

Applies to:

SAP ECC 6.0 EHP 4

 

Summary


There are various options for posting inventory differences depending on the processing status of the physical inventory transaction.

  • Posting differences after the count has been posted
A physical inventory document has already been created, and the count has already been posted. You only have to post the inventory differences.
  • Posting the count and inventory differences simultaneously after the physical inventory document has been created
A physical inventory document has been created, but the count has not yet been posted. The count results are available. You enter the count and post the differences in one step.
  • Entering the count without a document reference

 

You have a count result without reference; that is, no physical inventory document has yet been created for this physical inventory transaction. You create a physical inventory document, enter the count, and post the differences in one step.

SAP provides transactions MI07, MI10 to post inventory difference. These transactions do not provide any ability to user to enter some free text to further explain the need to make any adjustments. For end user, it becomes much more easier to later on understand the reasons of inventory difference, if there is provision to enter free text. Entering comments also help to identify reasons for quant write-offs.

 

This document describes a work around developed in SAP to allow user to enter free text as inventory adjustment reason.

 

Author: Parag Parikh

Company: Deloitte Consulting LLP

Created on: 24th March 2012

Author Bio

 

Parag (2).JPG

 

Parag Parikh is an SAP ABAP, SAP workflow consultant with 4.5 years of experience. He has extensively worked on SAP ABAP and SAP workflow. Parag also has functional skills for SAP FS-CD solution. He has worked on many SAP modules including SAP FI/CO, SD, MM, QM, PP, PLM-RM, SRM, HCM, ESS/MSS and EH&S. Parag is working with Deloitte Consulting LLP as Workflow Specialist.

 

Author: Vamsi Krishna Parepalli   ( SCN ID: E1106724)

Company:    Deloitte Consulting LLP

 

Vamsi Parepalli has over 6 years of experience in SAP ABAP, SAP OO-ABAP. He has extensively worked on Object Oriented ABAP. Vamsi is a techno-functional expert in SAP Retail, SAP SD and SAP MM modules. His experience includes Reports, Enhancements, Forms, Interfaces and Workflow development. Vamsi is also an iRise expert and has developed many pre-sales demo using iRise Visual Simulator. He is currently working with Deloitte Consulting LLP as SAP Technical Consultant in capacity of a process lead and is technically leading iRise initiative. He is also responsible for implementing EH&S and Global Label Management solution for clients.

 

Vamsi.PNG

 

Document Created on: 1st March 2013

 

Requirement:

 

Provide user with ability to enter the free text on the below transaction screens.

 

MI10 – Post Document, Count and Differences: Initial Screen

MI07 – Post Inventory Difference: Initial Screen

 

Challenges:

 

1) SAP does not provide any screen entrancement option (BAdi, customer exit) for both the transactions on initial screen.

2) What if user needs to enter different adjustment comments for each material in stock?

 

Solution Proposed:

 

Instead of initial screen, provide an editable ALV screen when user press SAVE button with details of all materials for which count is adjusted. An assumption is made that reason comment will be less than or equal to 100 characters.

 

If needed the approach can be modified to publish a long text editor in pop-up for each row in ALV to enter long text.

 

Demonstration:

 

Below section describes behavior of enhanced transaction once development was in place.

 

MI10:

 

I. Perform inventory adjustment w/o reference (via MI10)

 

Go to MI10 transaction (Post, Count, and Difference).


1.jpg

Enter the material, batch, inventory count, reason code and save the record.

 

2.jpg

 

Below is new screen created to allow user to enter reason text for each line entered on screen above. For user's reference, the ALV screen also provides Material Description, Plant, Storage Location, Batch, Special Indicator, Stock Type information as well in addition to provision to edit Reason Comment.

 

3.jpg

 

Check the data posted in ISEG table.

 

4.jpg

5.jpg

 

We see that comment is updated in table ISEG in custom field of 100 characters.

6.jpg

II. Create inventory document (via MI01).

 

Create a Physical inventory document in MI01 transaction.

 

2.1.jpg

Enter the material number and the batch and save the inventory record.


2.2.jpg

 

Enter the inventory count in MI04 transaction.

 

2.3.jpg


Enter the inventory count and save the physical inventory document.

2.4.png

 

 

2.6.jpg

Post the inventory difference in MI07 transaction.


2.7.jpg

 

Enter the reason code and hit SAVE.


2.8.jpg

 

Custom screen to enter rejection comments is displayed.

2.9.jpg

III. Execute MI07, using inventory record from case II.

 

Create a System inventory record using transaction LI01.

 

3.1.jpg

Enter the storage bin value and save the system inventory record.


3.2.jpg


3.3.jpg

Activate the record using LI02 transaction.


3.4.jpg

3.5.jpg

 

Enter the count in the inventory record using LI11 transaction.


3.6.jpg

 

3.7.jpg

3.8.jpg

 

Clear the Storage bin associated with the inventory record using LI20 transaction.

 

3.9.jpg

3.10.jpg

3.11.jpg

 

Post the inventory record in LI21 transaction entering the reason code comment.

 

3.12.jpg

3.14.jpg

As shown below, custom screen is displayed to provide reason text. This time user can enter reason for write-off reason for a particular inventory item.

3.15.jpg

3.16.jpg

 

Technical Approach:

 

To create a custom screen, a custom function group can be created. Function Modules inside this Function Group can then call the custom screen using familiar CALL SCREEN command.

 

FM to display ALV:


To display an editable ALV, we can encapsulate ALV code in a FM. create a function group ZFSIM_INV. Create a custom function module ‘ZFSIM_INV_REASON_COMMENT’. Code snippet below provides details on FM implementation.

 

FUNCTION zfsim_inv_reason_comment.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  TABLES

*"      CT_ISEG STRUCTURE  ISEG

*"----------------------------------------------------------------------

TYPES: BEGIN OF ty_mat_text,

         matnr    TYPE matnr,

         maktx    TYPE maktx,

         END OF   ty_mat_text,

         tt_mat_text TYPE STANDARD TABLE OF ty_mat_text.

 

 

  DATA: lt_mat TYPE tt_mat_text.

  FIELD-SYMBOLS: <lfs_mat> TYPE LINE OF tt_mat_text.

 

 

  SELECT matnr maktx

    INTO TABLE lt_mat

    FROM makt

    FOR ALL ENTRIES IN ct_iseg

   WHERE matnr = ct_iseg-matnr

     AND spras = sy-langu.

  IF sy-subrc EQ 0.

    SORT lt_mat BY matnr.

  ENDIF.

 

 

  IF NOT ct_iseg[] IS INITIAL.

    LOOP AT ct_iseg ASSIGNING <lfs_iseg>.

      ls_iseg-zeili = <lfs_iseg>-zeili.

      ls_iseg-matnr = <lfs_iseg>-matnr.

      READ TABLE lt_mat ASSIGNING <lfs_mat>

          WITH KEY matnr = <lfs_iseg>-matnr

          BINARY SEARCH.

      IF sy-subrc EQ 0.

        ls_iseg-maktx = <lfs_mat>-maktx.

      ENDIF.

      ls_iseg-lgort = <lfs_iseg>-lgort.

      ls_iseg-werks = <lfs_iseg>-werks.

      ls_iseg-charg = <lfs_iseg>-charg.

      ls_iseg-sobkz = <lfs_iseg>-sobkz.

      ls_iseg-bstar = <lfs_iseg>-bstar.

      APPEND ls_iseg TO lt_iseg.

      CLEAR ls_iseg.

    ENDLOOP.

    IF NOT lt_iseg[] IS INITIAL.

      PERFORM f_alv_display CHANGING lt_iseg.

    ENDIF.

  ENDIF.

  IF NOT lt_iseg[] IS INITIAL.

    CLEAR ls_iseg.

    LOOP AT lt_iseg INTO ls_iseg.

      READ TABLE ct_iseg ASSIGNING <lfs_iseg> WITH KEY

                 zeili = ls_iseg-zeili.

      IF sy-subrc EQ 0.

        <lfs_iseg>-reas_comm = ls_iseg-reas.

      ENDIF.

    ENDLOOP.

  ENDIF.

 

 

ENDFUNCTION.

 

Top include and subroutine include for the function group:

 

*&---------------------------------------------------------------------*

*&      Form  F_ALV_DISPLAY

*&---------------------------------------------------------------------*

*       To display the data in the ALV format

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_alv_display CHANGING ct_iseg TYPE tt_iseg.

  DATA: lt_fieldcat   TYPE slis_t_fieldcat_alv,

        lt_events     TYPE slis_t_event,

        ls_layout     TYPE slis_layout_alv.

*&-- Build Fieldcatalog for ALV display

  PERFORM f_build_fieldcat CHANGING lt_fieldcat.

 

 

*&-- Build the event table for the ALV Display

  PERFORM f_build_events CHANGING lt_events.

*&-- Build the layout table for ALV Display

  PERFORM f_build_layout CHANGING ls_layout.

*&-- Perform to display the output

  PERFORM f_alv_output USING lt_fieldcat

                             lt_events

                             ls_layout

                             ct_iseg.

 

 

ENDFORM.                    " F_ALV_DISPLAY

*&---------------------------------------------------------------------*

*&      Form  F_BUILD_FIELDCAT

*&---------------------------------------------------------------------*

*       Building the Fieldcatalog Table for Display of ALV

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_build_fieldcat CHANGING pct_fieldcat TYPE slis_t_fieldcat_alv.

  CONSTANTS: lc_1       TYPE sycucol           VALUE '1',

             lc_2       TYPE sycucol           VALUE '2',

             lc_3       TYPE sycucol           VALUE '3',

             lc_4       TYPE sycucol           VALUE '4',

             lc_5       TYPE sycucol           VALUE '5',

             lc_6       TYPE sycucol           VALUE '6',

             lc_7       TYPE sycucol           VALUE '7',

             lc_8       TYPE sycucol           VALUE '8',

             lc_9       TYPE sycucol           VALUE '9',

             lc_100     TYPE outputlen         VALUE '100',

             lc_zeili   TYPE slis_fieldname    VALUE 'ZEILI',

             lc_matnr   TYPE slis_fieldname    VALUE 'MATNR',

             lc_werks   TYPE slis_fieldname    VALUE 'WERKS',

             lc_lgort   TYPE slis_fieldname    VALUE 'LGORT',

             lc_charg   TYPE slis_fieldname    VALUE 'CHARG',

             lc_sobkz   TYPE slis_fieldname    VALUE 'SOBKZ',

             lc_bstar   TYPE slis_fieldname    VALUE 'BSTAR',

             lc_reas    TYPE slis_fieldname    VALUE 'REAS',

             lc_maktx   TYPE slis_fieldname    VALUE 'MAKTX',

             lc_table   TYPE slis_tabname      VALUE 'PT_ISEG'.

 

 

  DATA: ls_fieldcat TYPE slis_fieldcat_alv.

 

 

  ls_fieldcat-col_pos   = lc_1.

  ls_fieldcat-fieldname = lc_zeili.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l01.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_2.

  ls_fieldcat-fieldname = lc_matnr.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l02.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_3.

  ls_fieldcat-fieldname = lc_maktx.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l09.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_4.

  ls_fieldcat-fieldname = lc_werks.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l03.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_5.

  ls_fieldcat-fieldname = lc_lgort.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l04.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_6.

  ls_fieldcat-fieldname = lc_charg.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l05.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_7.

  ls_fieldcat-fieldname = lc_sobkz.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l06.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_8.

  ls_fieldcat-fieldname = lc_bstar.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-seltext_m = text-l07.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

  ls_fieldcat-col_pos   = lc_9.

  ls_fieldcat-fieldname = lc_reas.

  ls_fieldcat-tabname   = lc_table.

  ls_fieldcat-edit      = abap_true.

  ls_fieldcat-outputlen = lc_100.

  ls_fieldcat-seltext_m = text-l08.

  APPEND ls_fieldcat TO pct_fieldcat.

  CLEAR ls_fieldcat.

 

 

ENDFORM.                    " F_BUILD_FIELDCAT

*&---------------------------------------------------------------------*

*&      Form  F_BUILD_EVENTS

*&---------------------------------------------------------------------*

*       Building the Events Table for ALV

*----------------------------------------------------------------------*

*      <--P_LT_EVENTS  text

*----------------------------------------------------------------------*

FORM f_build_events  CHANGING pct_events TYPE slis_t_event.

  DATA: ls_event TYPE slis_alv_event.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

    EXPORTING

      i_list_type = 0

    IMPORTING

      et_events   = pct_events.

 

 

  READ TABLE pct_events WITH KEY name = slis_ev_user_command INTO ls_event.

  IF sy-subrc = 0.

    MOVE 'F_USER_COMMAND' TO ls_event-form.

    APPEND ls_event TO pct_events.

  ENDIF.

ENDFORM.                    " F_BUILD_EVENTS

*&---------------------------------------------------------------------*

*&      Form  F_BUILD_LAYOUT

*&---------------------------------------------------------------------*

*       Building the layout setting of the ALV

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_build_layout CHANGING pcs_layout TYPE slis_layout_alv.

  pcs_layout-zebra = abap_true.

ENDFORM.                    " F_BUILD_LAYOUT

*&---------------------------------------------------------------------*

*&      Form  F_ALV_OUTPUT

*&---------------------------------------------------------------------*

*       Displaying the ALV GRID Display

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_alv_output USING pt_fieldcat TYPE slis_t_fieldcat_alv

                        pt_events   TYPE slis_t_event

                        ps_layout   TYPE slis_layout_alv

                        pt_iseg     TYPE tt_iseg.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program    = sy-repid

      i_grid_title          = 'Inventory Document Data'(001)

      is_layout             = ps_layout

      it_fieldcat           = pt_fieldcat

      it_events             = pt_events

      i_screen_start_column = 10

      i_screen_start_line   = 10 "20

      i_screen_end_column   = 200

      i_screen_end_line     = 30 "40

    TABLES

      t_outtab              = pt_iseg

    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.                    " F_ALV_OUTPUT

*&---------------------------------------------------------------------*

*&      Form  F_USER_COMMAND

*&---------------------------------------------------------------------*

*       Update the Reason code Comment Data

*----------------------------------------------------------------------*

FORM f_user_command USING r_ucomm     LIKE sy-ucomm

                          rs_selfield TYPE slis_selfield..

  IF rs_selfield IS INITIAL.

    CLEAR rs_selfield.

  ENDIF.

  CASE r_ucomm.

    WHEN OTHERS.

      DATA: lrf_grid TYPE REF TO cl_gui_alv_grid.

      IF lrf_grid IS INITIAL.

        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

          IMPORTING

            e_grid = lrf_grid.

      ENDIF.

      IF NOT lrf_grid IS INITIAL.

        CALL METHOD lrf_grid->check_changed_data .

      ENDIF.

  ENDCASE.

ENDFORM.                    "F_USER_COMMAND

 

TOP Include data declaration:

Top include.jpg

 

The hierarchy of Function Group then would be as shown below once development is completed.

 

Function Group.jpg

 

Implicit Enhancement:


Once done with the code to display ALV for entering comments, the FM can be called from appropriate enhancement points.

 

Here the enhancement is placed inside include MM07IFB0 for IM transactions and MM07MFI0 for WM related transactions. These enhancement points are chosen in such a way that all the data required to display in ALV is available.

 

For_IM.png

 

for_WN.jpg

 

Code inside the include as shown below.

 

CONSTANTS: lc_mi07 TYPE sytcode VALUE 'MI07',

           lc_mi10 TYPE sytcode VALUE 'MI10',

           lc_li21 TYPE sytcode VALUE 'LI21'.

 

 

  IF sy-tcode EQ lc_mi07 OR sy-tcode EQ lc_mi10.

    CALL FUNCTION 'ZFSIM_INV_REASON_COMMENT'

      TABLES

        ct_iseg = xiseg.

  ENDIF.

 

 

  IF sy-tcode EQ lc_li21.

    CALL FUNCTION 'ZFSIM_INV_REASON_COMMENT'

      TABLES

        ct_iseg = yiseg.

  ENDIF.

 

As shown, since we are updating SAP internal table XISEG/YISEG, SAP automatically takes care of updating value in standard tables.

 

Append Structure:

 

Shown below is append structure to house comments.

 

Append structure.png

 

Copyright

© Copyright 2013 SAP AG. All rights reserved.

 

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

 

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,

OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

 

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

 

Oracle is a registered trademark of Oracle Corporation.

 

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

 

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

 

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

 

Java is a registered trademark of Oracle Corporation. JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and

implemented by Netscape.

 

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

 

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

 

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

 

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

 




Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>