SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Materials issued to a service order



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Thu Jan 21, 2010 3:22 pm    Post subject: Materials issued to a service order Reply with quote

Code:
REPORT zmmr7018
NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 65(0)
MESSAGE-ID zmm.
*-----------------------------------------------------------------------
* PROGRAM SPECIFICATION *
*----------------------------------------------------------------------*
* Programming Date :
* *
* Report Title : Issue Record file

* Description : This program creates a report,which list
* out all the materials issued to a service
* order with the issued qty and outstanding
* well qty.This report include planned issued as
* as unplanned issued.For unplanned issued,
* reservation no, required qty, date raised,
* qty duesout info will not be available.
*
*
* INPUT:
* Logical Database: None
* Database tables : mesg,mkpf,mara,makt,ausp,resb.
* Tables : None
*----------------------------------------------------------------------*
*SELECTION:
* Select-options : None.
* Parameters : Order like aufk-aufnr. " For Order no.
*----------------------------------------------------------------------*
*PROCESS:
* Planned issued to service order
* 1. User will enter the servie order no. to execute the report.
* 2. Select all the reservation items from RESB table using the service
* order number. There will be only one reservation no. as one service
* order can generate one reservation only.
* 3. Access the selected records sequentially. With the Order No.,
* reservation no., material code and reservation item no. access
* MSEG table, pick up records for MVT 261 and 262.
* 4. Subtract the issued quantity for records with mvmnt 261 by return
* quantity for records with mvmnt type 262.
* 5. If the item was issued from consignment stock, update the customer
* issue field else update the ST Elect issue.
* 6. Repeat step 3 to 5 until all selected records are processed.
*
* Unplanned issued to service order
* 7. With the input service order no., access MSEG table, select records
* with mvmnt type 261 and 262, reservation no is blank.
* 8. Sort the selected records by material code, special stock
* indicator and movement type.
* 9. Access the selected records sequentially.
* 10. Calculate the unplanned issue qty for an item from ST Elect stock
* to a service order, by subtracting issued qty for records with
* mvmnt 261 by returned qty for records with mvmnt 262 and special
* stock indicator equal to blank.
* 11. Calculate the unplanned issue qty for an item from Mindef stock
* to a service order, by subtracting issued qty for records with
* mvmnt 261 by returned qty for records with mvmnt 262 and special
* stock indicator equal to K.
* 12. Repeat step 8 to step 10 until all records have been proessed.
* 13. Output report as the specified format.
*
* Output:
* Database Tables : None.
* Dataset Name : None.
* Report : Issue record file
* Sort Fields : Reservation No., Desc, Matl code, Date raised
* Page Breaks : None
*----------------------------------------------------------------------*
* Modification Number :
* Analyst : *
* Specification Date : DD.MM.YYYY *
* Programmer :
* Programming Date : *
* Description : Issue Record File
*
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* TABLES AND DATA DECLARATION *
*----------------------------------------------------------------------*
TABLES : mkpf, " Material Document - Header detail
mseg, " Material Document - Item Detail
mara, " Material master : General data
makt, " Material description
ausp, " Characteristics Values
resb. " Reservation/dependent requirements

DATA : c_pland TYPE c, " Planned issue indicator
c_unplnd TYPE c, " Unplanned issue indicator
p_enmng LIKE resb-enmng, " Issued qty. - Total
p_enmngu LIKE resb-enmng, " Issued qty. - Total
p_menge LIKE mseg-menge, " ST Elect issue qty.
p_mengeu LIKE mseg-menge, " ST Elect issue qty.
p_mengk LIKE mseg-menge, " Mindef vendor consignment issue qty.
p_mengku LIKE mseg-menge. " Mindef vendor consignment issue qty.
*----------------------------------------------------------------------*
* Internal Table Declaration *
*----------------------------------------------------------------------*
DATA : BEGIN OF itab OCCURS 0,
aufnr LIKE resb-aufnr, " Service order number
rsnum LIKE resb-rsnum, " Reservation number
rspos LIKE resb-rspos, " Reservation item no.
matnr LIKE mseg-matnr, " Material code
bdter LIKE resb-bdter, " Date raised
nsn LIKE cawn-atwrt, " Nato serial number
mfrpn LIKE mara-mfrpn, " Manufacturer part number
maktx LIKE makt-maktx, " Material description
pdues LIKE resb-enmng, " Qty. Outstanding
enmng LIKE resb-enmng, " Issued qty.
bdmng LIKE resb-bdmng, " Requirements quantity
bwart LIKE mseg-bwart, " Movement type
menge1 LIKE mseg-menge, " ST Elect issue qty. mvmnt type 261
menge2 LIKE mseg-menge, " ST Elect issue qty. mvmnt type 262
mengk1 LIKE mseg-menge, " Mindef consignment issue qty. - 261
mengk2 LIKE mseg-menge. " Mindef consignment issue qty. - 262
DATA : END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,
aufnr LIKE resb-aufnr, " Service order number
rsnum LIKE resb-rsnum, " Reservation number
rspos LIKE resb-rspos, " Reservation item no.
matnr LIKE mseg-matnr, " Material code
nsn LIKE cawn-atwrt, " Nato serial number
mfrpn LIKE mara-mfrpn, " Manufacturer part number
maktx LIKE makt-maktx, " Material description
bdter LIKE resb-bdter, " Date raised
bwart LIKE mseg-bwart, " Movement type
mengeu1 LIKE mseg-menge, " ST Elect issue qty. mvmnt type 261
mengeu2 LIKE mseg-menge, " ST Elect issue qty. mvmnt type 262
mengku1 LIKE mseg-menge, " Mindef consignment issue qty. - 261
mengku2 LIKE mseg-menge. " Mindef consignment issue qty. - 262
DATA : END OF itab1.

DATA: BEGIN OF rec.
        INCLUDE STRUCTURE itab.
DATA: END OF rec.

DATA: BEGIN OF rec1.
        INCLUDE STRUCTURE itab1.
DATA: END OF rec1.

DATA: imakt LIKE makt OCCURS 0 WITH HEADER LINE,
imara LIKE mara OCCURS 0 WITH HEADER LINE,
iresb LIKE resb OCCURS 0 WITH HEADER LINE,
imseg LIKE mseg OCCURS 0 WITH HEADER LINE.
*----------------------------------------------------------------------*
* SELECTION SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1
WITH FRAME TITLE text-001.
PARAMETERS : p_aufnr LIKE aufk-aufnr OBLIGATORY. " Service order no.
SELECTION-SCREEN END OF BLOCK blk1.

AT SELECTION-SCREEN.
  SELECT SINGLE * FROM mseg WHERE aufnr = p_aufnr.
  IF sy-subrc NE 0.
    MESSAGE e201 WITH p_aufnr. " No GI document for Order no.
  ENDIF.
  CLEAR c_pland.
  SELECT SINGLE * FROM resb WHERE aufnr = p_aufnr.
  IF sy-subrc = 0.
    c_pland = 'Y'. " planned issue indicator
  ENDIF.
*----------------------------------------------------------------------*
* START OF SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  SELECT * FROM mseg INTO TABLE imseg
  WHERE aufnr = p_aufnr
  AND ( bwart = '261' OR bwart = '262' ).

*/ Selecting planned issue data from tables RESB, MSEG.
  IF c_pland EQ 'Y'.
    PERFORM get_planned_issue_data.
  ENDIF.
*/ Selecting unplanned issue data from table MSEG.
  PERFORM get_unplanned_issue_data.

  SELECT * FROM makt INTO TABLE imakt WHERE spras = 'E'
  ORDER BY matnr.
  SELECT * FROM mara INTO TABLE imara ORDER BY matnr.

  LOOP AT itab.
    CLEAR imakt.
    READ TABLE imakt WITH KEY matnr = itab-matnr BINARY SEARCH.
    MOVE imakt-maktx TO itab-maktx. " Material description

    CLEAR imara.
    READ TABLE imara WITH KEY matnr = itab-matnr BINARY SEARCH.
    MOVE imara-mfrpn TO itab-mfrpn. " Manufacturer part no.

    PERFORM get_nsn_data USING itab-matnr
    CHANGING itab-nsn. " Nato Serial Number

    MODIFY itab.
    CLEAR itab.
  ENDLOOP.
  LOOP AT itab1.
    CLEAR imakt.
    READ TABLE imakt WITH KEY matnr = itab1-matnr BINARY SEARCH.
    MOVE imakt-maktx TO itab1-maktx. " Material description

    CLEAR imara.
    READ TABLE imara WITH KEY matnr = itab1-matnr BINARY SEARCH.
    MOVE imara-mfrpn TO itab1-mfrpn. " Manufacturer part no.

    PERFORM get_nsn_data USING itab1-matnr
    CHANGING itab1-nsn. " Nato Serial Number

    MODIFY itab1.
    CLEAR itab1.
  ENDLOOP.

*----------------------------------------------------------------------*
* END OF SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
  PERFORM print_report.
  PERFORM print_footer.

TOP-OF-PAGE.
  PERFORM print_title.
  PERFORM print_header.
*&---------------------------------------------------------------------*
*& Form GET_PLANNED_ISSUE_DATA
*&---------------------------------------------------------------------*
* Selecting values from tables MSEG and RESB
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_planned_issue_data.
  SELECT * FROM resb INTO TABLE iresb WHERE aufnr = p_aufnr
  AND ( bwart = '261' OR bwart = '262' )
  AND xloek NE 'X'.

  LOOP AT iresb.
    CLEAR imseg.
*/ checking planned goods issue against reservation number.
    LOOP AT imseg
    WHERE rsnum = iresb-rsnum
    AND rspos = iresb-rspos.
*/ Checking for issue from vendor consignment stock.
      IF imseg-sobkz EQ 'K'.
*/ Checking for issue movement type 261 and reversal mvmt 262.
        CASE imseg-bwart.
          WHEN '261'.
            ADD imseg-menge TO itab-mengk1.
          WHEN '262'.
            ADD imseg-menge TO itab-mengk2.
        ENDCASE.
      ELSE.
        CASE imseg-bwart.
          WHEN '261'.
            ADD imseg-menge TO itab-menge1.
          WHEN '262'.
            ADD imseg-menge TO itab-menge2.
        ENDCASE.
      ENDIF.
    ENDLOOP.
    itab-pdues = iresb-bdmng - iresb-enmng.
    itab-bdter = iresb-bdter.
    itab-enmng = iresb-enmng.
    itab-matnr = iresb-matnr.
    itab-rsnum = iresb-rsnum.
    itab-rspos = iresb-rspos.
    APPEND itab.CLEAR itab.
  ENDLOOP.
ENDFORM. " GET_PLANNED_ISSUE_DATA
*&---------------------------------------------------------------------*
*& Form GET_UNPLANNED_ISSUE_DATA
*&---------------------------------------------------------------------*
FORM get_unplanned_issue_data.
  LOOP AT imseg
  WHERE rsnum IS INITIAL
  AND rspos IS INITIAL.
*/ Setting unplanned issue indicator.
    IF sy-subrc = 0.
      MOVE 'Y' TO c_unplnd.
    ENDIF.
*/ Checking for issue from vendor consignment stock.
    IF imseg-sobkz EQ 'K'.
*/ Checking for issue movement type 261 and reversal mvmt 262.
      CASE imseg-bwart.
        WHEN '261'.
          MOVE imseg-menge TO itab1-mengku1.
        WHEN '262'.
          MOVE imseg-menge TO itab1-mengku2.
      ENDCASE.
    ELSE.
      CASE imseg-bwart.
        WHEN '261'.
          MOVE imseg-menge TO itab1-mengeu1.
        WHEN '262'.
          MOVE imseg-menge TO itab1-mengeu2.
      ENDCASE.
    ENDIF.
    MOVE : imseg-matnr TO itab1-matnr,
    imseg-aufnr TO itab1-aufnr,
    imseg-bwart TO itab1-bwart.
    APPEND itab1.
    CLEAR itab1.
  ENDLOOP.
ENDFORM. " GET_UNPLANNED_ISSUE_DATA
*&---------------------------------------------------------------------*
*& Form PRINT_REPORT
*&---------------------------------------------------------------------*
FORM print_report.
*/ Printing the item details.
  IF c_pland EQ 'Y'.
    WRITE: 46 '<<<<>>>>' COLOR 6 INVERSE ON.
    SKIP.
    SORT itab BY matnr bdter.
* delete adjacent duplicates from itab.
    LOOP AT itab.
      MOVE-CORRESPONDING itab TO rec.
      AT NEW bdter.
        SUM.
        CLEAR : p_menge, p_mengk, p_enmng.
*/ Calculations.
        p_menge = itab-menge1 - itab-menge2. " ST Elect issue
        p_mengk = itab-mengk1 - itab-mengk2. " Mindef issue
        IF rec-mfrpn EQ space.
          MOVE '-' TO rec-mfrpn. " Manufacturer part no.
        ENDIF.
        IF rec-nsn EQ space.
          MOVE '-' TO rec-nsn. " Nato stock no.
        ENDIF.

*/ Item serial number generation
        DATA : counter(4) TYPE n. " Item Serial No.
        counter = counter + 1.
*/ Printing.
        FORMAT COLOR 2.
        WRITE: /(4) counter NO-ZERO,
        7(30) rec-matnr,
        (40) rec-nsn,
        (17) rec-enmng NO-SIGN,
        (17) rec-pdues,
        (17) p_menge,
        /7(30) rec-maktx,
        (40) rec-mfrpn,
        (17) rec-bdter RIGHT-JUSTIFIED,
        (17) space,
        (17) p_mengk.
        SKIP.
      ENDAT. " bdter
    ENDLOOP. " itab
    IF sy-linno NE 1.
      ULINE /.
    ENDIF.
  ENDIF. " for c_pland

*/ Printing unplanned issue details in a new page always.
  IF c_unplnd EQ 'Y' AND c_pland EQ 'Y'.
    NEW-PAGE NO-TITLE.
  ENDIF.
  IF c_unplnd EQ 'Y'.
    FORMAT COLOR OFF.
    WRITE: 45 '<<<<>>>>' COLOR 6 INVERSE ON.
    SKIP.

    SORT itab1 BY matnr.
    LOOP AT itab1.
      MOVE-CORRESPONDING itab1 TO rec1.
      AT NEW matnr.
        SUM.
        CLEAR : p_mengeu, p_mengku, p_enmngu.
*/ Calculations.
        p_mengeu = itab1-mengeu1 - itab1-mengeu2. " ST Elect issue
        p_mengku = itab1-mengku1 - itab1-mengku2. " Mindef issue
        p_enmngu = p_mengeu + p_mengku." Issued qty -total unplnd
        IF rec1-mfrpn CA '?' OR rec1-mfrpn IS INITIAL.
          MOVE '-' TO rec1-mfrpn. " Manufacturer part no.
        ENDIF.
        IF rec1-nsn CA '?' OR rec1-nsn EQ space.
          MOVE '-' TO rec1-nsn. " Nato stock no.
        ENDIF.
*/ Item serial number generation
        DATA : counteru(4) TYPE n. " Item Serial No.
        counteru = counteru + 1.
*/ Printing.
        FORMAT COLOR 2.
        WRITE: /(4) counteru NO-ZERO,
        7(30) rec1-matnr,
        (40) rec1-nsn,
        (17) p_enmngu NO-SIGN,
        (17) '0.00' RIGHT-JUSTIFIED,
        (17) p_mengeu,
        /7(30) rec1-maktx,
        (40) rec1-mfrpn,
        (17) rec1-bdter RIGHT-JUSTIFIED,
        (17) space,
        (17) p_mengku.
        SKIP.
      ENDAT.
    ENDLOOP.                                                " itab1
  ENDIF.
  IF sy-linno NE 1.
    ULINE /.
  ENDIF.
ENDFORM. " PRINT_REPORT

*&---------------------------------------------------------------------*
*& Form PRINT_TITLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_title.
  FORMAT COLOR 3 INTENSIFIED ON.
  WRITE : /.
  WRITE : /5 'PROG ID :',sy-repid,
  44 'SINGAPORE TECHNOLOGIES ELECTRONICS LIMITED',
  114 'DATE :', sy-datum,
  /51 'ISSUE RECORDS FILE',
  114 'PAGE :', sy-pagno.

  WRITE : /.
  FORMAT COLOR 4.
  WRITE : /5 'SERVICE ORDER NO. :', p_aufnr.
  FORMAT COLOR OFF.
ENDFORM. " PRINT_TITLE

*&---------------------------------------------------------------------*
*& Form GET_NSN_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_nsn_data USING f_matnr LIKE itab-matnr
CHANGING f_nsn LIKE itab-nsn.

  DATA: v_objek LIKE ausp-objek,
  f_smbez LIKE clobjdat-smbez.

  DATA: BEGIN OF isclass OCCURS 0.
          INCLUDE STRUCTURE sclass.
  DATA: END OF isclass.

  DATA: BEGIN OF iclobjdat OCCURS 0.
          INCLUDE STRUCTURE clobjdat.
  DATA: END OF iclobjdat.

  MOVE f_matnr TO v_objek+0(18).

  CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
  EXPORTING
* CLASS = ' '
* CLASSTEXT = 'X'
  classtype = '001'
* CLINT = ' '
* FEATURES = 'X'
* LANGUAGE = SY-LANGU
  object = v_objek
* OBJECTTABLE = ' '
* KEY_DATE = SY-DATUM
* INITIAL_CHARACT = 'X'
* NO_VALUE_DESCRIPT =
* CHANGE_SERVICE_CLF = 'X'
  inherited_char = 'X'
  TABLES
  t_class = isclass
  t_objectdata = iclobjdat
* I_SEL_CHARACTERISTIC =
  EXCEPTIONS
  no_classification = 1
  no_classtypes = 2
  invalid_class_type = 3
  OTHERS = 4.


  IF sy-subrc EQ 0.
    APPEND iclobjdat.
    CLEAR iclobjdat.
    LOOP AT iclobjdat
    WHERE smbez+0(17) = 'Nato Stock Number'.
      MOVE iclobjdat-ausp1 TO f_nsn.
    ENDLOOP.
    REFRESH iclobjdat.
  ELSE.
    REFRESH iclobjdat.
  ENDIF.

ENDFORM. " GET_NSN_DATA
*&---------------------------------------------------------------------*
*& Form PRINT_FOOTER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_footer.
  FORMAT COLOR 6.
  IF sy-pagno = 1
  AND sy-linno = 1
  AND sy-colno = 1.
    IF sy-linsz > 80.
      WRITE: /51 '*** NO DATA TO REPORT ***', 132 ' ' .
    ELSE.
      WRITE: /27 '*** NO DATA TO REPORT ***', 80 ' '.
    ENDIF.
  ELSE.
    IF sy-linsz > 80.
      WRITE: /53 '*** END OF REPORT ***', 132 ' '.
    ELSE.
      WRITE: /29 '*** END OF REPORT ***', 80 ' '.
    ENDIF.
  ENDIF.
  FORMAT COLOR OFF.
ENDFORM. " PRINT_FOOTER

*&---------------------------------------------------------------------*
*& Form PRINT_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_header.
*/ Printing the Header.
  FORMAT COLOR 1.
  ULINE /.
  WRITE: /(5) 'S/NO.' LEFT-JUSTIFIED,
  (30) 'MATERIAL CODE' LEFT-JUSTIFIED,
  (40) 'NSN' LEFT-JUSTIFIED,
  (17) 'ISSUE QTY' RIGHT-JUSTIFIED,
  (17) 'QTY DUESOUT' RIGHT-JUSTIFIED,
  (16) 'ST Elect ISSUE' RIGHT-JUSTIFIED,
  /7(30) 'DESCRIPTION' LEFT-JUSTIFIED,
  (40) 'MPN' LEFT-JUSTIFIED,
  (17) 'DATE RAISED' RIGHT-JUSTIFIED,
  (17) ' ',
  (16) 'MINDEF ISSUE' RIGHT-JUSTIFIED.
  ULINE /.

ENDFORM. " PRINT_HEADER
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> PP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.