Last Physical Inventory Date In Quant (LQUA) Table - SAP Upload Tool.

Generally, when an organization goes live with warehouse management functionality, it faces a big challenge to upload the last physical inventory date from Inventory management data (MARD-DLINL) in warehouse management quant data (LQUA-IDATU).

This code can be used to upload directly in quant data (LQUA) table. Once you upload the last physical inventory date in quant data table, you need to make changes in Cycle count physical inventory program.


CODE:

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

REPORT zupdate_lqua.

TYPESBEGIN OF gty_upload,
         lgnum TYPE lqua-lgnum,
         lqnum TYPE lqua-lqnum,
         idatu TYPE lqua-idatu,
       END OF gty_upload.

DATAgt_upload  TYPE TABLE OF gty_upload,
      gwa_upload TYPE gty_upload.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERSp_fname TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*— File Open Dialog
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
  PERFORM f4_file_name.

START-OF-SELECTION.
  PERFORM upload_file.
  PERFORM update_lqua.

*&---------------------------------------------------------------------*
*& Form F4_FILE_NAME
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f4_file_name .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  syst-cprog
      dynpro_number syst-dynnr
      field_name    ' '
    IMPORTING
      file_name     p_fname.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM upload_file .
  FIELD-SYMBOLS <col> TYPE any.

  DATABEGIN OF ex_itab OCCURS 0.
      INCLUDE STRUCTURE alsmex_tabline.
  DATAEND OF ex_itab.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                p_fname
      i_begin_col             '1'
      i_begin_row             '2'
      i_end_col               '200'
      i_end_row               '60000'
    TABLES
      intern                  ex_itab
    EXCEPTIONS
      inconsistent_parameters 1
      upload_ole              2
      OTHERS                  3.
  IF sy-subrc <> 0.
    RAISE read_failed.
  ENDIF.

  LOOP AT ex_itab.
    ASSIGN COMPONENT ex_itab-col OF STRUCTURE gwa_upload TO <col>.
    CATCH SYSTEM-EXCEPTIONS conversion_errors 1.
      <col> ex_itab-value.
    ENDCATCH.
    IF sy-subrc 1.
      WRITE'Conversion error:',ex_itab-value.
      EXIT.
    ENDIF.
    AT END OF row.
      APPEND gwa_upload TO gt_upload.
      CLEAR gwa_upload.
    ENDAT.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPDATE_LQUA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM update_lqua.

  DATAlt_lqua  TYPE TABLE OF lqua,
        lwa_lqua TYPE lqua.
  SELECT FROM lqua
    INTO TABLE lt_lqua
    FOR ALL ENTRIES IN gt_upload
    WHERE lgnum gt_upload-lgnum
      AND lqnum gt_upload-lqnum.

  SORT lt_lqua BY lgnum lqnum.
  LOOP AT gt_upload INTO gwa_upload.

    CLEARlwa_lqua.
    READ TABLE lt_lqua INTO lwa_lqua WITH KEY lgnum gwa_upload-lgnum
                                              lqnum gwa_upload-lqnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      lwa_lqua-idatu gwa_upload-idatu.
      MODIFY lt_lqua FROM lwa_lqua INDEX sy-tabix.
    ENDIF.
  ENDLOOP.

  IF lt_lqua IS NOT INITIAL.
    MODIFY lqua FROM TABLE lt_lqua.
    IF sy-subrc EQ 0.
      CALL FUNCTION 'DB_COMMIT'.
      MESSAGE 'Successfully updated' TYPE 'S'.
    ENDIF.
  ENDIF.
ENDFORM.


Comments

Also Read...