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

Adding Comment Lines to a Delivery Document



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Tue Sep 09, 2008 4:52 pm    Post subject: Adding Comment Lines to a Delivery Document Reply with quote

Explode Load Items on a Delivery - for purpose of adding Comment Lines to a Delivery Document

Code:
REPORT ZPROJDEL MESSAGE-ID ZZ NO STANDARD PAGE HEADING
                LINE-SIZE 132 LINE-COUNT 65.
TABLES: LIKP, LIPS, MAST, MAKT, MARA, MVKE.
PARAMETERS: DELNOTE LIKE LIKP-VBELN MATCHCODE OBJECT VMVL.
*Select Text 'E' Delivery Note Number

DATA: BEGIN OF MATTAB OCCURS 100.
        INCLUDE STRUCTURE STPO_API02.
DATA: END OF MATTAB.

DATA: BEGIN OF TAB OCCURS 100,
      ITEMNO TYPE P,
      LEVELNO TYPE P,
      MATNR   LIKE LIPS-MATNR,
      VKORG   LIKE LIKP-VKORG,
      VTWEG   LIKE LIPS-VTWEG,
      WERKS   LIKE LIPS-WERKS,
      QTY     LIKE LIPS-LFIMG,
      COMMENT(20),
      ALREADY-EXPLODED,
      END OF TAB.

DATA: BEGIN OF TAB2 OCCURS 100.
        INCLUDE STRUCTURE TAB.
DATA: END OF TAB2.
DATA: BEGIN OF PROCESSTAB OCCURS 100,
        MATNR LIKE TAB-MATNR,
        QTY   LIKE TAB-QTY,
      END OF PROCESSTAB.

DATA: TLINE(130).
DATA: OFFSET(3) TYPE N.
DATA: LEVELNO LIKE TAB-LEVELNO VALUE 0.
DATA: ITEMNO  LIKE TAB-ITEMNO VALUE 0.
DATA: EXPLODE-AGAIN VALUE 'Y'.
DATA: NUMLINES TYPE P.
DATA: MARKFIELD.
DATA: REC_COUNT TYPE P.
DATA: REC_PROCESSED LIKE REC_COUNT.
DATA: REC_ERRORS LIKE REC_COUNT.
DATA: SESNAME(12) VALUE '            '.
DATA: SESNAME_ERR(12) VALUE 'PROJDEL'.
DATA: TMODE_BD VALUE ' '.
DATA: TMODE_CT VALUE 'X'.
DATA: DSPL-DATE(10).
DATA: TCODE(4),
      TMP-MATNR LIKE LIPS-MATNR,
      SPECIALVAL(4) VALUE 'ZDLX',
      BAD-RECORD(1)  VALUE 'N',
      UPMODE VALUE   'N',
      COMMIT_FREQUENCY TYPE I VALUE 100,
      COMMIT_CHECK     TYPE I,
      LOAD_MODE_BD     TYPE I VALUE 1,
      LOAD_MODE_CT     TYPE I VALUE 2,
      LOAD_MODE        TYPE N.

DATA: BEGIN OF COUNTS OCCURS 200,
      TYPE(30),
      INPUT LIKE REC_COUNT,
      GOOD LIKE REC_COUNT,
      BAD LIKE REC_COUNT,
        END OF COUNTS.
SELECTION-SCREEN SKIP.
PARAMETERS:
  UPMODE_N             RADIOBUTTON GROUP UPMD,
*SELTEXT*E*  "Screen MODE - See NOTHING"
  UPMODE_A             RADIOBUTTON GROUP UPMD,
*SELTEXT*E*  "Screen MODE - See ALL"
  UPMODE_E DEFAULT 'X' RADIOBUTTON GROUP UPMD.
*SELTEXT*E*  "Screen MODE - ERRORS Only"

DATA: BEGIN OF BDC_TAB OCCURS 10.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB.

AT SELECTION-SCREEN.
  IF SESNAME IS INITIAL AND TMODE_BD EQ 'X'.
    MESSAGE E999 WITH
            'BDC Flag set but no BDC Session Name provided.'.
    EXIT.
  ENDIF.
  IF SESNAME GT SPACE AND TMODE_CT EQ 'X'.
    CLEAR SESNAME.
    MESSAGE W999 WITH
            'Call Trans Flag set.  BDC Session Name ignored.'.
    EXIT.
  ENDIF.

START-OF-SELECTION.
*---------------------------------------------------------------------*
* perform check-tcode-authority using 'SE38'.
  IF UPMODE_A EQ 'X'.
    UPMODE = 'A'.             " If CALL Transaction - Show All Screens
  ELSEIF UPMODE_N EQ 'X'.
    UPMODE = 'N'.             "                     - Show Nothing
  ELSEIF UPMODE_E EQ 'X'.
    UPMODE = 'E'.             "                     - Show Only Errors
  ENDIF.
  if not sy-batch is initial.
    move 'N' to upmode.
  endif.
  if sesname is initial.
    load_mode = load_mode_ct.
  else.
    load_mode = load_mode_bd.
  endif.

  PERFORM CREATE-REPORT.

*---------------------------------------------------------------------*
*       FORM CREATE-REPORT                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CREATE-REPORT.
  SELECT SINGLE * FROM LIKP WHERE VBELN EQ DELNOTE.
  IF SY-SUBRC NE 0.
    MESSAGE E999 WITH 'Delivery Note' DELNOTE 'Does Not Exist'.
  ENDIF.
  REFRESH TAB.
  SELECT * FROM LIPS WHERE VBELN EQ LIKP-VBELN.
    IF LIPS-PSTYV EQ SPECIALVAL.
      MESSAGE E999 WITH 'Delivery Line' DELNOTE LIPS-POSNR
                        'is prepared for Packing'.
    ENDIF.
    CLEAR TAB.
    MOVE LIPS-MATNR TO TAB-MATNR.
    MOVE LIPS-WERKS TO TAB-WERKS.
    MOVE LIKP-VKORG TO TAB-VKORG.
    MOVE LIPS-VTWEG TO TAB-VTWEG.
    MOVE LIPS-LFIMG TO TAB-QTY.
    MOVE 1          TO TAB-ITEMNO.
    MOVE 1          TO TAB-LEVELNO.
    MOVE 'N'        TO TAB-ALREADY-EXPLODED.
    IF NOT TAB-MATNR IS INITIAL.
      APPEND TAB.
    ENDIF.
  ENDSELECT.

  WHILE EXPLODE-AGAIN EQ 'Y'.
    REFRESH TAB2.
    MOVE 'N' TO EXPLODE-AGAIN.
    LOOP AT TAB.
      REFRESH MATTAB.
      SELECT * FROM MAST WHERE MATNR EQ TAB-MATNR   "Determine if BOM
                           AND WERKS EQ LIPS-WERKS   " in Current Plant
                           AND STLAN EQ '1'
                           AND STLAL EQ '01'.
         MOVE LIPS-WERKS   TO TAB-WERKS.
      ENDSELECT.
      IF SY-SUBRC NE 0.
        SELECT * FROM MAST WHERE MATNR EQ TAB-MATNR   "If NOT -
                             AND STLAN EQ '1'         "get a Plant
                             AND STLAL EQ '01'.
          MOVE MAST-WERKS  TO TAB-WERKS.
          EXIT.
        ENDSELECT.
      ENDIF.
      IF TAB-ALREADY-EXPLODED EQ 'N'.
        WRITE TAB-MATNR TO TMP-MATNR.
        CALL FUNCTION 'CSAP_MAT_BOM_READ'
             EXPORTING
                  MATERIAL    = TMP-MATNR
                  PLANT       = TAB-WERKS
                  BOM_USAGE   = '1'
                  ALTERNATIVE = ' '
             TABLES
                  T_STPO      = MATTAB
             EXCEPTIONS
                  ERROR       = 1
                  OTHERS      = 2.
        DESCRIBE TABLE MATTAB LINES NUMLINES.
        IF NUMLINES NE 0.
          MOVE 'Y' TO EXPLODE-AGAIN.
        ENDIF.
      ENDIF.
      CLEAR TAB2.
      MOVE-CORRESPONDING TAB TO TAB2.
      TAB2-ITEMNO = TAB2-ITEMNO + 1.
      MOVE 'Y'               TO TAB2-ALREADY-EXPLODED.
      APPEND TAB2.
      LOOP AT MATTAB.
        CLEAR TAB2.
        MOVE-CORRESPONDING TAB TO TAB2.
*       move mattab-component to tab2-matnr.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
             EXPORTING
                  INPUT  = MATTAB-COMPONENT
             IMPORTING
                  OUTPUT = TAB2-MATNR
             EXCEPTIONS
                  OTHERS = 1.
        TAB2-QTY     = TAB2-QTY * MATTAB-COMP_QTY.
        TAB2-LEVELNO = TAB2-LEVELNO + 1.
        ITEMNO = ITEMNO + 1.
        MOVE ITEMNO  TO TAB2-ITEMNO.
        MOVE 'N'     TO TAB2-ALREADY-EXPLODED.
        IF NOT TAB2-MATNR IS INITIAL.
          APPEND TAB2.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
    REFRESH TAB.
    LOOP AT TAB2.
      MOVE-CORRESPONDING TAB2 TO TAB.
      APPEND TAB.
    ENDLOOP.
  ENDWHILE.

  LOOP AT TAB2.
    CLEAR MARA.
    CLEAR MARKFIELD.
    SELECT SINGLE * FROM MARA WHERE MATNR EQ TAB2-MATNR.
    IF  MARA-MAGRV EQ '9001'.          "Only for SPECIAL Types
      SELECT SINGLE * FROM MVKE WHERE MATNR EQ TAB2-MATNR
                                  AND VKORG EQ TAB2-VKORG
                                  AND VTWEG EQ TAB2-VTWEG.
      IF SY-SUBRC EQ 0.
        PERFORM PRINT-TLINE.
        MOVE 'X' TO MARKFIELD.
        WRITE:  / MARKFIELD AS CHECKBOX, TLINE.
        HIDE TAB2-MATNR.
        HIDE TAB2-QTY.
      ELSE.
        MOVE 'NOT SALEABLE' TO TAB2-COMMENT.
        PERFORM PRINT-TLINE.
        WRITE: / ' ', TLINE.
        HIDE TAB2-MATNR.
        HIDE TAB2-QTY.
      ENDIF.
    ELSE.
      PERFORM PRINT-TLINE.
      WRITE: / ' ', TLINE.
      HIDE TAB2-MATNR.
      HIDE TAB2-QTY.
    ENDIF.
    SKIP.
  ENDLOOP.
  SET PF-STATUS 'BASE'.

ENDFORM.
*---------------------------------------------------------------------*
*       FORM PRINT-TLINE                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM PRINT-TLINE.
  CLEAR TLINE.
  CLEAR OFFSET.
  DO TAB2-LEVELNO TIMES.
    WRITE ' ' TO TLINE+OFFSET(1).
    ADD 1 TO OFFSET.
  ENDDO.
  WRITE TAB2-MATNR TO TLINE+OFFSET(18).
  MOVE 65 TO OFFSET.
  WRITE TAB2-QTY TO TLINE+OFFSET(17).
  ADD 17 TO OFFSET.
  CLEAR MAKT.
  SELECT SINGLE * FROM MAKT WHERE MATNR EQ TAB2-MATNR
                              AND SPRAS EQ SY-LANGU.
  WRITE MAKT-MAKTX TO TLINE+OFFSET(40).
  ADD 17 TO OFFSET.
  WRITE TAB2-COMMENT TO TLINE+OFFSET(20).
  ADD 20 TO OFFSET.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM MAINLINE_INPUT                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM MAINLINE_INPUT.
  if load_mode eq load_mode_bd.
    perFORM open_bdc_session using sesname.
  endif.

  PERFORM PROCESS_DATA.

  if not sesname is INITIAL.
    perform close_bdc_session.
  endif.

  NEW-PAGE.
  ULINE.
  IF LOAD_MODE EQ LOAD_MODE_BD.
    WRITE: / 'Data loaded into BDC Session'.
  ELSE.
    WRITE: / 'Data loaded using Call Transaction'.
  ENDIF.
  ULINE.
  WRITE: / REC_COUNT,    'Generated SAP Change records'.
  WRITE: / REC_PROCESSED,    'Records Processed'.
  WRITE: / REC_ERRORS,       'Records processed in ERROR'.
  IF LOAD_MODE EQ LOAD_MODE_BD.
    WRITE: / 'MUST MANUALLY Process Batch Input Session=', SESNAME.
  ENDIF.
  IF REC_ERRORS GT 0.
    WRITE: / '****************************************'.
    WRITE: / 'Not ALL of the Data Process Successfully'.
    WRITE: / 'You can MANUALLY Process Batch Input Session=',
              SESNAME_ERR.
    WRITE: / 'To Update the Remaining Unprocessed Data'.
    WRITE: / '****************************************'.
  ENDIF.
  ULINE.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM PROCESS_DATA                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM PROCESS_DATA.
  DATA:
  COMMIT_CHECK TYPE I.
  LOOP AT PROCESSTAB.
    PERFORM PROCESS-REC.
    COMMIT_CHECK = REC_COUNT MOD COMMIT_FREQUENCY.
    IF COMMIT_CHECK EQ 0.
      COMMIT WORK.
    ENDIF.
  ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM PROCESS-REC                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM PROCESS-REC.
  ADD 1 TO REC_COUNT.
  MOVE 'VL02'    TO TCODE.
  PERFORM GENERATE_BDC.
  PERFORM PROCESS_BDC_DATA.
  IF LOAD_MODE EQ LOAD_MODE_CT.
    IF SY-SUBRC NE 0.
      WRITE: / 'Did not Process in BDC',
               'Material', PROCESSTAB-MATNR.
      PERFORM WRITE_TRANSACTION_MSG.
      PERFORM PROCES_CALL_TRANSACTION_ERROR.
      ADD 1 TO REC_ERRORS.
    ELSE.
      PERFORM WRITE_TRANSACTION_MSG.
      ADD 1 TO REC_PROCESSED.
    ENDIF.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM GENERATE_BDC                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM GENERATE_BDC.
  DATA: TMP-MATNR LIKE MARA-MATNR.
  DATA: TMP-QTY(17).
  REFRESH BDC_TAB.
  PERFORM ADD_BDC_SCREEN USING 'SAPMV50A' '0101' 'X'.
  PERFORM ADD_BDC_FIELD USING 'LIKP-VBELN' LIKP-VBELN.
  PERFORM ADD_BDC_OKCODE USING 'UELG'.
  PERFORM ADD_BDC_SCREEN USING 'SAPMV50A' '0210' 'X'.
  PERFORM ADD_BDC_OKCODE USING 'POAN'.
  PERFORM ADD_BDC_SCREEN USING 'SAPMV50A' '0210' 'X'.
  WRITE  PROCESSTAB-MATNR TO TMP-MATNR.
  PERFORM ADD_BDC_FIELD USING 'LIPS-MATNR(5)' TMP-MATNR.
  WRITE PROCESSTAB-QTY TO TMP-QTY.
  PERFORM ADD_BDC_FIELD USING 'LIPSD-G_LFIMG(5)' TMP-QTY.
  PERFORM ADD_BDC_FIELD USING 'LIPS-PSTYV(5)' SPECIALVAL.
  PERFORM ADD_BDC_OKCODE USING '/11'.
  PERFORM ADD_BDC_SCREEN USING 'SAPMV50A' '0210' 'X'.
  PERFORM ADD_BDC_OKCODE USING 'SICH'.
ENDFORM.

AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'PROC'.
      REFRESH PROCESSTAB.
      SET PF-STATUS 'PROC'.
      DO.
        CLEAR MARKFIELD.
        CLEAR TAB2-MATNR.
        CLEAR TAB2-QTY.
        READ LINE SY-INDEX FIELD VALUE MARKFIELD.
        IF SY-SUBRC > 0.
          EXIT.
        ENDIF.
        CHECK MARKFIELD NE SPACE.
        MOVE TAB2-MATNR TO PROCESSTAB-MATNR.
        MOVE TAB2-QTY   TO PROCESSTAB-QTY.
        COLLECT PROCESSTAB.
        MODIFY CURRENT LINE
          FIELD VALUE
             MARKFIELD  FROM SPACE.
      ENDDO.
      PERFORM MAINLINE_INPUT.
    WHEN 'SALL'.
      DO.
        CLEAR MARKFIELD.
        READ LINE SY-INDEX FIELD VALUE MARKFIELD.
        IF SY-SUBRC > 0.
          EXIT.
        ENDIF.
        MODIFY CURRENT LINE
          FIELD VALUE
             MARKFIELD  FROM 'X'.
      ENDDO.
    WHEN 'UALL'.
      DO.
        CLEAR MARKFIELD.
        READ LINE SY-INDEX FIELD VALUE MARKFIELD.
        IF SY-SUBRC > 0.
          EXIT.
        ENDIF.
        MODIFY CURRENT LINE
          FIELD VALUE
             MARKFIELD  FROM SPACE.
      ENDDO.
    WHEN 'REFR'.
      PERFORM CREATE-REPORT.
    WHEN OTHERS.
      SET PF-STATUS 'BASE'.
  ENDCASE.
  INCLUDE ZCONINC5.
  INCLUDE ZCONINC3.
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 -> SD 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.