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

Weighbridge to SAP 4.6C Integration



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sun Oct 14, 2007 9:03 pm    Post subject: Weighbridge to SAP 4.6C Integration Reply with quote

Requirement:
Avery digitizer is used to get the gross and tare weight of vehicles carrying materials. The requirement is to get the weight of material directly into SAP and then use the weight data of respective materials to post goods receipt, production booking and dispatch documents.

Processing:
An ABAP application is developed to get the vehicle and material information along with the gross and tare weight of vehicles. The application executes a visual basic program on the local PC that captures weight data from the Avery digitizer and generates an unique weighment-id for every weighment. Against the weighment-id vehicle and material information is stored , depending on the type of material transfer (e.g. Production Material , Dispatch, Receipt, Miscellaneous ).This weighment id is further used for posting Goods Receipt , Production Booking and creating dispatch documents through standard SAP transactions. Field-Exits are used to populate the weight and vehicle information automatically against a weighmentпїЅid. Further, BADI ( Business Add-in ), at the time of material document save, is used to set the status of the weighment-id as completed.

Avery digitizer is connected to the PC - Port. Function Modules 'WS_EXECUTE' is used to execute the external VB program which copies the PC's port data to clipboard. Further, function module 'CLPB_IMPORT' is used to get the weight data from clipboard.


Code:
REPORT Z_WEIGHBRIDGE_TO_SAP LINE-SIZE 200.
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari / Rahul Aurangabadkar         
*----------------------------------------------------------------------*
*       Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*

DATA : RB_OTHERS(1) TYPE C,
       RB_TARE(1) TYPE C,
       RB_GROSS TYPE C.

DATA : BEGIN OF ITAB_TAREWT OCCURS 0,
           WEIGHT(50) TYPE C,
       END OF ITAB_TAREWT.
TABLES : ZWB_CARRIER,ZWB_WEIGHT, ZWB_PVEH_WT.
controls: ZTC1 type tableview using screen 3000.
controls: ZTC2 type tableview using screen 4000.
controls: TC3 type tableview using screen 5000.
DATA: ITAB LIKE ZWB_WEIGHT OCCURS 0 WITH HEADER LINE.
DATA  RCODE(1) TYPE C.
DATA  OK_CODE(4) TYPE C.
DATA  ZITEMS TYPE I.
DATA  RND_NO TYPE I.
DATA  ITAB_LINES TYPE I.
DATA  FLAG(4) TYPE C.
DATA : BEGIN OF OPEN_WID OCCURS 0,
       WID LIKE ZWB_WEIGHT-WID,
       MATL_DESC LIKE ZWB_WEIGHT-MATL_DESC,
       END OF OPEN_WID.

DATA  MESS_STRING(100) TYPE C.
DATA  STATUS(5) TYPE C.
DATA  VAR_ANS(1) TYPE C.
DATA  LAST_OPEN_WID LIKE ZWB_WEIGHT-WID.
DATA  LAST_OPEN_WID1(8) TYPE C.
DATA : BEGIN OF DEL_ITAB OCCURS 0,
       WID LIKE ZWB_WEIGHT-WID,
       MATL_DESC LIKE ZWB_WEIGHT-MATL_DESC,
       END OF DEL_ITAB.
DATA  MARKER(1) TYPE C.

DATA : ITAB_TO_DELETE LIKE ZWB_WEIGHT OCCURS 0 WITH header line.
DATA : COUNTER(1) TYPE C.
DATA  VAR_CONF(1) TYPE C.
DATA  VAR_WID1 LIKE ZWB_CARRIER-WID1.
data: begin of desti occurs 100.
        include structure msxxlist.
data: end of desti.
data: begin of serverp occurs 100,     " Presentationserver
        s(32),
        sl(15),
        x(4) type x,
        l(5),h(5),
        m(5),
        c,
        pro(4),
        commu,
      end of serverp.
data: begin of usr_liste occurs 1000.
        include structure uinfo.
data: end of usr_liste.
DATA : BEGIN OF ITAB_WT OCCURS 0,
           WEIGHT(50) TYPE C,
       END OF ITAB_WT.
DATA  PROD_MATL(1) TYPE C.
DATA  INT_MVMT(1) TYPE C.
DATA  NET_WT LIKE ZWB_WEIGHT-WEIGHT1.
DATA  WEIGHT_CONF(1) TYPE C.
DATA  WEIGHT_TAKEN(1) TYPE C.
DATA : ITAB_PRINT LIKE ZWB_WEIGHT OCCURS 1 WITH HEADER LINE.
DATA : CONTROL_ITAB LIKE SSFCTRLOP OCCURS 1 WITH HEADER LINE.

DATA  PRINT_FLAG(12) TYPE C.
                                     1

DATA FM_NAME TYPE RS38L_FNAM.
DATA  HELP_WID LIKE ZWB_WEIGHT-WID.
DATA  RETURN(4) TYPE C.
DATA  SELECTION LIKE ZWB_WEIGHT-WID.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_1000 INPUT.
  CASE OK_CODE.
    WHEN 'ENTE'.
**** AUTHORITY CHECKING ****
     AUTHORITY-CHECK OBJECT 'ZWEIGHMENT'
          ID 'ACTVT' FIELD '01'.
       IF SY-SUBRC NE 0.
          MESSAGE E000(ZJ) WITH
          'You have no authorization'.
       ENDIF.
*    PERFORM GET_IP_ADD.
      SELECT SINGLE MATL_DESC WEIGHT1 WEIGHT2 CAST_NO W1_USER W1_DATE
             W1_TIME STATUS
       INTO (ZWB_WEIGHT-MATL_DESC,ZWB_WEIGHT-WEIGHT1,ZWB_WEIGHT-WEIGHT2,
             ZWB_WEIGHT-CAST_NO,ZWB_WEIGHT-W1_USER,ZWB_WEIGHT-W1_DATE,
             ZWB_WEIGHT-W1_TIME,ZWB_WEIGHT-STATUS)
        FROM ZWB_WEIGHT
       WHERE WID = ZWB_WEIGHT-WID.
      IF SY-SUBRC NE 0.
        MESSAGE I000(ZJ) WITH 'Invalid Weighment ID'.
        CLEAR : OK_CODE, ZWB_WEIGHT.
        LEAVE TO SCREEN 1000.
      ELSE.
        VAR_WID1 = ZWB_WEIGHT-WID+0(6).
        SELECT SINGLE VEH_NO TRANSPORTER REMARKS
          INTO (ZWB_CARRIER-VEH_NO,ZWB_CARRIER-TRANSPORTER,
               ZWB_CARRIER-REMARKS) FROM ZWB_CARRIER
         WHERE WID1 = VAR_WID1.
         IF ZWB_WEIGHT-STATUS = 'I'.
            INT_MVMT = 'X'.
         ENDIF.
        LEAVE TO SCREEN 6000.
      ENDIF.
    WHEN 'IDGE'.
      LEAVE TO SCREEN 3000.
    WHEN 'TRWT'.
      LEAVE TO SCREEN 2000.
    WHEN 'PRNT'.
      IF ZWB_WEIGHT-WID IS INITIAL.
        MESSAGE I000(ZJ) WITH 'Enter Weighment ID'.
        LEAVE TO SCREEN 1000.
      ELSE.
        SELECT SINGLE WID MATL_DESC CAST_NO WEIGHT1 WEIGHT2 W1_DATE
               W1_TIME W2_DATE W2_TIME
          INTO (ITAB_PRINT-WID,ITAB_PRINT-MATL_DESC,ITAB_PRINT-CAST_NO,
               ITAB_PRINT-WEIGHT1,ITAB_PRINT-WEIGHT2,ITAB_PRINT-W1_DATE,
              ITAB_PRINT-W1_TIME,ITAB_PRINT-W2_DATE,ITAB_PRINT-W2_TIME)
        FROM ZWB_WEIGHT
       WHERE WID = ZWB_WEIGHT-WID.
        IF SY-SUBRC NE 0.
          MESSAGE I000(ZJ) WITH 'Weighment ID doesnot exist'.
          CLEAR : ITAB_PRINT, ZWB_WEIGHT, ZWB_CARRIER.
          REFRESH : ITAB_PRINT.
          LEAVE TO SCREEN 1000.
        ELSE.
          VAR_WID1 = ZWB_WEIGHT-WID+0(6).
          SELECT SINGLE VEH_NO TRANSPORTER
            INTO (ZWB_CARRIER-VEH_NO,ZWB_CARRIER-TRANSPORTER)
            FROM ZWB_CARRIER
           WHERE WID1 = VAR_WID1.
          IF SY-SUBRC NE 0.
            MESSAGE I000(ZJ) WITH 'Weighment ID doesnot exist'.
            CLEAR : ITAB_PRINT, ZWB_WEIGHT, ZWB_CARRIER.
            REFRESH : ITAB_PRINT.
            LEAVE TO SCREEN 1000.
          ELSE.
            IF NOT ITAB_PRINT-WEIGHT1 IS INITIAL AND
               NOT ITAB_PRINT-WEIGHT2 IS INITIAL.
*              ITAB_PRINT-NET_WT = ABS( ITAB_PRINT-WEIGHT2 -
*                                       ITAB_PRINT-WEIGHT2 ).
            ENDIF.
            APPEND ITAB_PRINT.
            IF PRINT_FLAG <> 'CANCEL_PRINT'.
              PERFORM PRINT_SLIP.
            ENDIF.
            CLEAR : ITAB_PRINT, ZWB_WEIGHT, ZWB_CARRIER.
            REFRESH : ITAB_PRINT.
          ENDIF.
        ENDIF.
      ENDIF.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'CANC'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_1000  INPUT
*&---------------------------------------------------------------------*
*&      Module  DEFAULT_SCREEN  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE DEFAULT_SCREEN OUTPUT.
  CLEAR PRINT_FLAG.

ENDMODULE.                 " DEFAULT_SCREEN  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_1000 OUTPUT.
*SELECT AUTH_OPT INTO ZAUTH_OPT FROM ZWB_USER_OPT
* WHERE USER_ID = SY-UNAME.
* IF ZAUTH_OPT = '1'.
  SET PF-STATUS 'ZMENU'.
* ELSEIF ZAUTH_OPT = '1'.
*    SET PF-STATUS 'Z
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_1000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
  CASE OK_CODE.
    WHEN 'GETW'.
      IF ZWB_PVEH_WT-VEH_NO = ' '.
        MESSAGE I000(ZJ) WITH 'Enter Vehicle number'.
        CLEAR OK_CODE.
        LEAVE TO SCREEN 2000.
      ELSE.
        SELECT SINGLE VEH_NO INTO ZWB_PVEH_WT-VEH_NO
          FROM ZWB_PVEH_WT
         WHERE VEH_NO = ZWB_PVEH_WT-VEH_NO.
        IF SY-SUBRC NE 0.
          CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
            EXPORTING
              DEFAULTOPTION        = 'Y'
              DIAGNOSETEXT1        = 'Vehicle number doesnot exist'
*          DIAGNOSETEXT2        = ' '
*          DIAGNOSETEXT3        = ' '
              TEXTLINE1            = 'Want to create a new entry?'
*          TEXTLINE2            = ' '
              TITEL                = 'Confirm'
*          START_COLUMN         = 25
*          START_ROW            = 6
*          CANCEL_DISPLAY       = 'X'
            IMPORTING
              ANSWER               = VAR_CONF
                     .
          CASE VAR_CONF.
            WHEN 'N'.
              CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT.
              REFRESH ITAB_TAREWT.
              LEAVE TO SCREEN 2000.
            WHEN 'A'.
              CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT.
              REFRESH ITAB_TAREWT.
              LEAVE TO SCREEN 2000.
          ENDCASE.
        ENDIF.
CLEAR ITAB_TAREWT.
REFRESH ITAB_TAREWT.

********* to clear clipboard containts ************

     CALL FUNCTION 'CLPB_EXPORT'
*         IMPORTING
*           EMPTY            =
        TABLES
           DATA_TAB         = ITAB_TAREWT
         EXCEPTIONS
           CLPB_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.

*********    EXECUTE THE VB PROGRAM HERE ********************
CALL FUNCTION 'WS_EXECUTE'
 EXPORTING
*   DOCUMENT                 = ' '
*   CD                       = ' '
*   COMMANDLINE              = ' '
   INFORM                   = 'X'
   PROGRAM                  = 'C:\WEIGHBRIDGE\WEIGHBRIDGE.EXE'
*   STAT                     = ' '
*   WINID                    = ' '
*   OSMAC_SCRIPT             = ' '
*   OSMAC_CREATOR            = ' '
*   WIN16_EXT                = ' '
*   EXEC_RC                  = ' '
* IMPORTING
*   RBUFF                    =
 EXCEPTIONS
   FRONTEND_ERROR           = 1
   NO_BATCH                 = 2
   PROG_NOT_FOUND           = 3
   ILLEGAL_OPTION           = 4
   GUI_REFUSE_EXECUTE       = 5
   OTHERS                   = 6
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
        CALL FUNCTION 'CLPB_IMPORT'
*            IMPORTING
*              EMPTY            =
           TABLES
             DATA_TAB         = ITAB_TAREWT
           EXCEPTIONS
             CLPB_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.
        READ TABLE ITAB_TAREWT INDEX 1.
        IF ITAB_TAREWT-WEIGHT = ' '.
          MESSAGE I000(ZJ) WITH 'NO WEIGHT DATA'.
          CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT, ZWB_PVEH_WT.
          REFRESH ITAB_TAREWT.
          LEAVE TO SCREEN 2000.
        ELSE.
          CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
            EXPORTING
              DEFAULTOPTION        = 'Y'
              DIAGNOSETEXT1        = 'The weight value is'
              DIAGNOSETEXT2        = ITAB_TAREWT-WEIGHT
              DIAGNOSETEXT3        = 'Want to confirm weight ? '
              TEXTLINE1            = 'Choose YES to confirm...'
*              TEXTLINE2            = ' '
              TITEL                = 'Confirm'
*              START_COLUMN         = 25
*              START_ROW            = 6
*              CANCEL_DISPLAY       = 'X'
            IMPORTING
              ANSWER               = WEIGHT_CONF
                      .
          CASE WEIGHT_CONF.
            WHEN 'J'.
              ZWB_PVEH_WT-T_WEIGHT = ITAB_TAREWT-WEIGHT.
              ZWB_PVEH_WT-W_DATE = SY-DATUM.
              ZWB_PVEH_WT-W_TIME = SY-UZEIT.
              ZWB_PVEH_WT-W_USER = SY-UNAME.
              MODIFY ZWB_PVEH_WT.
              IF SY-SUBRC = 0.
                COMMIT WORK.
*                NET_WT = ABS( ZWB_WEIGHT-WEIGHT2 - ZWB_WEIGHT-WEIGHT1).
                MESSAGE I000(ZJ) WITH 'WEIGHT CAPATURED AND UPDATED'.
                CLEAR : OK_CODE, PROD_MATL,INT_MVMT,ZWB_WEIGHT,
WEIGHT_TAKEN,
                        WEIGHT_CONF, ZWB_CARRIER, ZWB_PVEH_WT,
                        ITAB_TAREWT.
                REFRESH ITAB_TAREWT.
                LEAVE TO SCREEN 1000.
              ELSE.
                ROLLBACK WORK.
                MESSAGE I000(ZJ) WITH 'PROBLEM IN UPDATION, RETRY. '.
                CLEAR : OK_CODE, WEIGHT_CONF, ITAB_TAREWT,
                        WEIGHT_TAKEN, WEIGHT_CONF.
                REFRESH ITAB_TAREWT.
                LEAVE TO SCREEN 2000.
              ENDIF.
            WHEN OTHERS.
              CLEAR : OK_CODE, WEIGHT_CONF, ITAB_TAREWT, WEIGHT_TAKEN.
              REFRESH ITAB_TAREWT.
              LEAVE TO SCREEN 2000.
          ENDCASE.
*
*             ZWB_PVEH_WT-T_WEIGHT = ITAB_TAREWT-WEIGHT.
*             ZWB_PVEH_WT-W_DATE = SY-DATUM.
*             ZWB_PVEH_WT-W_TIME = SY-UZEIT.
*             ZWB_PVEH_WT-W_USER = SY-UNAME.
*             MODIFY ZWB_PVEH_WT.
*             IF SY-SUBRC = 0.
*                COMMIT WORK.
*                MESSAGE I000(ZJ) WITH
*                   'TARE WEIGHT SUCCESSFULLY INSERTED'.
*                CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT, ZWB_PVEH_WT.
*                REFRESH ITAB_TAREWT.
*                LEAVE TO SCREEN 1000.
*             ELSE.
*                ROLLBACK WORK.
*                message I000(ZJ) WITH 'PROBLEM IN UPDATING RECORD'.
*                CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT, ZWB_PVEH_WT.
*                REFRESH ITAB_TAREWT.
*             ENDIF.
        ENDIF.
      ENDIF.
    WHEN 'BACK'.
      CLEAR : OK_CODE, VAR_CONF, ITAB_TAREWT. REFRESH ITAB_TAREWT.
      LEAVE TO SCREEN 1000.
    WHEN 'CANC'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_2000  INPUT

*&---------------------------------------------------------------------*
*&      Module  SHOW_WID  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE SHOW_WID OUTPUT.
  IF NOT ITAB IS INITIAL AND ( OK_CODE = 'SAVE' OR OK_CODE = ' ' ).
    ZWB_WEIGHT-WID = ITAB-WID.
    ZWB_WEIGHT-MATL_DESC = ITAB-MATL_DESC.
    COUNTER = 'X'.
  ELSE.
    IF NOT COUNTER = 'X'.
      ZITEMS = 1.
      CLEAR COUNTER.
    ENDIF.
  ENDIF.
ENDMODULE.                 " SHOW_WID  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  INITIALIZE  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE INITIALIZE OUTPUT.
  CLEAR : OK_CODE, COUNTER.
  CLEAR ITAB. REFRESH ITAB.
ENDMODULE.                 " INITIALIZE  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  BACK  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE BACK INPUT.
  CASE OK_CODE.
    WHEN 'BACK'.
    CLEAR : ITAB,OPEN_WID, STATUS, MESS_STRING, VAR_ANS, LAST_OPEN_WID1,
                ZWB_CARRIER, ZWB_WEIGHT, OK_CODE, ZITEMS, LAST_OPEN_WID,
                        DEL_ITAB, ITAB_TO_DELETE.
      REFRESH :ITAB, OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.
      LEAVE TO SCREEN 1000.
    WHEN 'CANC' OR 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " BACK  INPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_VEHICLE_STATUS  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE CHECK_VEHICLE_STATUS INPUT.
  IF OK_CODE = 'SAVE'.

    IF ZWB_CARRIER-VEH_NO = ' ' OR ZWB_CARRIER-TRANSPORTER = ' '
       OR ZITEMS = ' '.
      MESSAGE I000(ZJ) WITH 'Enter values in all fields'.
      LEAVE TO SCREEN 3000.
    ELSEIF ZWB_CARRIER-VEH_NO CA '*-/\|:;'''.
      MESSAGE I000(ZJ) WITH
         'Vehicle No should no contain special characters'.
      LEAVE TO SCREEN 3000.
    ELSE.
      SELECT WID MATL_DESC INTO TABLE OPEN_WID FROM ZWB_WEIGHT
       WHERE ( WEIGHT2 IS NULL OR WEIGHT2 = 0 ).
*  MESS_STRING = 'OPEN WIDs ARE '.
      SORT OPEN_WID.
      LOOP AT OPEN_WID.
*  VAR_WID = OPEN_WID-WID+1(6).
        SELECT WID1 INTO ZWB_CARRIER-WID1 FROM ZWB_CARRIER
         WHERE VEH_NO = ZWB_CARRIER-VEH_NO
           AND WID1 = OPEN_WID-WID+0(6).
          IF SY-SUBRC = 0.
            STATUS = 'OPEN'.
            DEL_ITAB-WID = OPEN_WID-WID.
            DEL_ITAB-MATL_DESC = OPEN_WID-MATL_DESC.
            APPEND DEL_ITAB.
            CONCATENATE MESS_STRING  OPEN_WID-WID ','  INTO MESS_STRING.
            LAST_OPEN_WID = OPEN_WID-WID.
          ENDIF.
        ENDSELECT.
      ENDLOOP.

      IF STATUS = 'OPEN'.
*   CONCATENATE MESS_STRING
*   ' Delete / Insert extra items ' INTO MESS_STRING.
        CALL FUNCTION 'POPUP_TO_DECIDE_WITH_MESSAGE'
          EXPORTING
*      DEFAULTOPTION           = '1'
            DIAGNOSETEXT1           = 'OPEN WIDs ARE '
            DIAGNOSETEXT2           = MESS_STRING
            DIAGNOSETEXT3           = ' Delete / Insert extra items '
            TEXTLINE1               = 'CHOOSE ONE OPTION'
*      TEXTLINE2               = ' '
*      TEXTLINE3               = ' '
            TEXT_OPTION1            = 'Insert extra item'
            TEXT_OPTION2            = 'Delete extra item'
*      ICON_TEXT_OPTION1       =
*      ICON_TEXT_OPTION2       =
            TITEL                   = 'CONFIRM'
*      START_COLUMN            = 25
*      START_ROW               = 6
*      CANCEL_DISPLAY          = 'X'
         IMPORTING
           ANSWER                  = VAR_ANS
                  .

*   MESSAGE I000(ZJ) WITH MESS_STRING.
        CLEAR STATUS.
        IF VAR_ANS = 'A' .  "CANCLE OPTION
          CLEAR : OPEN_WID,VAR_ANS,STATUS.REFRESH OPEN_WID.
          LEAVE TO SCREEN 3000.
        ELSEIF VAR_ANS = '1'.  "INSERT OPTION
          LAST_OPEN_WID1 = LAST_OPEN_WID+0(8).
        ELSEIF VAR_ANS = '2'. "DELETE OPTION
          LEAVE TO SCREEN 5000.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDMODULE.                 " CHECK_VEHICLE_STATUS  INPUT
*&---------------------------------------------------------------------*
*&      Module  INSERT_REMARK  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE INSERT_REMARK INPUT.
  IF OK_CODE = 'SAVE' OR OK_CODE = ''.
    IF NOT ZWB_WEIGHT-MATL_DESC = ' '.
      ITAB-MATL_DESC = ZWB_WEIGHT-MATL_DESC.
      APPEND ITAB.
    ENDIF.
  ENDIF.
ENDMODULE.                 " INSERT_REMARK  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_3000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_3000 INPUT.
  CASE OK_CODE.
    WHEN 'SAVE'.
      LOOP AT ITAB.
        IF ITAB-MATL_DESC IS INITIAL.
          MESSAGE I000(ZJ) WITH
            'Enter Material Desc for all Items'.
    CLEAR : ITAB,OPEN_WID, STATUS, MESS_STRING, VAR_ANS, LAST_OPEN_WID1
                              , LAST_OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.
          REFRESH :ITAB, OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.

          LEAVE TO SCREEN 3000.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE ITAB LINES ITAB_LINES.
      IF NOT ITAB_LINES EQ ZITEMS.
        MESSAGE I000(ZJ) WITH
        'Enter Desc only for the number of items given'.
        CLEAR : OPEN_WID, STATUS, MESS_STRING, VAR_ANS,
                LAST_OPEN_WID1, LAST_OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.
        REFRESH :OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.
*       CLEAR ITAB. REFRESH ITAB.
        LEAVE TO SCREEN 3000.
      ENDIF.

      IF VAR_ANS NE '1'.
        CALL FUNCTION 'NUMBER_GET_NEXT'
               EXPORTING
                 NR_RANGE_NR                   = '1'
                 OBJECT                        = 'ZWID1'
                 QUANTITY                      = '1'
*        SUBOBJECT                     = ' '
*        TOYEAR                        = '0000'
*        IGNORE_BUFFER                 = ' '
               IMPORTING
                 NUMBER                        = ZWB_CARRIER-WID1
*        QUANTITY                      =
                 RETURNCODE                    = RCODE
              EXCEPTIONS
                INTERVAL_NOT_FOUND            = 1
                NUMBER_RANGE_NOT_INTERN       = 2
                OBJECT_NOT_FOUND              = 3
                QUANTITY_IS_0                 = 4
                QUANTITY_IS_NOT_1             = 5
                INTERVAL_OVERFLOW             = 6
                BUFFER_OVERFLOW               = 7
                OTHERS                        = 8
                       .
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.
      DO ZITEMS TIMES.
        CALL FUNCTION 'QF05_RANDOM_INTEGER'
             EXPORTING
                  RAN_INT_MAX   = 9999
                  RAN_INT_MIN   = 1000
             IMPORTING
                  RAN_INT       = RND_NO
             EXCEPTIONS
                  INVALID_INPUT = 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.
        IF VAR_ANS = '1'. " Insert extra items.
          ZWB_WEIGHT-WID =  ( LAST_OPEN_WID1 * 10000 ) +
                            ( SY-INDEX * 10000 ) +
                            RND_NO.
        ELSE.
          ZWB_WEIGHT-WID = ( ZWB_CARRIER-WID1 * 1000000 ) +
                           ( SY-INDEX * 10000 ) +
                           RND_NO.
        ENDIF.
        READ TABLE ITAB INDEX SY-INDEX.
        ITAB-WID = ZWB_WEIGHT-WID.
        MODIFY ITAB INDEX SY-INDEX .

*       MESSAGE I000(ZJ) WITH ZWB_WEIGHT-WID.
      ENDDO.

    WHEN 'BACK'.
    CLEAR : ITAB,OPEN_WID, STATUS, MESS_STRING, VAR_ANS, LAST_OPEN_WID1,
                ZWB_CARRIER, ZWB_WEIGHT, OK_CODE, ZITEMS, LAST_OPEN_WID,
                     DEL_ITAB, ITAB_TO_DELETE.
      REFRESH :ITAB, OPEN_WID, DEL_ITAB, ITAB_TO_DELETE.
      LEAVE TO SCREEN 1000.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'CANC'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_3000  INPUT
*&---------------------------------------------------------------------*
*&      Module  INSERT_DATA  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE INSERT_DATA INPUT.
  IF NOT ITAB IS INITIAL AND OK_CODE = 'SAVE'.
    IF VAR_ANS NE '1'.
      ZWB_CARRIER-WID_DATE = SY-DATUM.
      ZWB_CARRIER-WID_TIME = SY-UZEIT.
      INSERT INTO ZWB_CARRIER VALUES ZWB_CARRIER.
      IF SY-SUBRC EQ 0.
        INSERT ZWB_WEIGHT FROM TABLE itab.
        IF SY-SUBRC EQ 0.
          COMMIT WORK.
          LEAVE TO SCREEN 4000.
*        MESSAGE I000(ZJ) WITH ZITEMS 'IDS CREATED'.
        ELSE.
          ROLLBACK WORK.
          MESSAGE E000(ZJ) WITH 'PROBLEM IN INSERTION FOR ZWB_WEIGHT'.
        ENDIF.
      ELSE.
        MESSAGE E000(ZJ) WITH 'PROBLEM IN INSERTION FOR ZWB_CARRIER'.
      ENDIF.
    ELSE.
      INSERT ZWB_WEIGHT FROM TABLE itab.
      IF SY-SUBRC EQ 0.
        COMMIT WORK.
        LEAVE TO SCREEN 4000.
*         MESSAGE I000(ZJ) WITH ZITEMS 'IDS CREATED'.
      ELSE.
        ROLLBACK WORK.
        MESSAGE E000(ZJ) WITH 'PROBLEM IN INSERTION FOR ZWB_WEIGHT'.
      ENDIF.
    ENDIF.
  ENDIF.

ENDMODULE.                 " INSERT_DATA  INPUT
*&---------------------------------------------------------------------*
*&      Module  SHOW_DETAILS  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE SHOW_DETAILS OUTPUT.
  ZWB_WEIGHT-WID = DEL_ITAB-WID.
  ZWB_WEIGHT-MATL_DESC = DEL_ITAB-MATL_DESC.
ENDMODULE.                 " SHOW_DETAILS  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  SELECT_DEL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE SELECT_DEL INPUT.
  IF MARKER = 'X'.
    ITAB_TO_DELETE-WID = ZWB_WEIGHT-WID.
    APPEND ITAB_TO_DELETE.
  ENDIF.
ENDMODULE.                 " SELECT_DEL  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_5000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_5000 INPUT.
  CASE OK_CODE.
    WHEN 'DELE'.
      DELETE ZWB_WEIGHT FROM TABLE ITAB_TO_DELETE.
      IF SY-SUBRC = 0.
        MESSAGE I000(ZJ) WITH 'Selected IDs deleted'.
        COMMIT WORK.
        CLEAR : OPEN_WID, ZWB_CARRIER, ZWB_WEIGHT, ITAB_TO_DELETE,
                DEL_ITAB, ZITEMS,OK_CODE, VAR_ANS, ITAB, LAST_OPEN_WID,
                LAST_OPEN_WID1,MESS_STRING, STATUS.
        REFRESH : OPEN_WID, ITAB_TO_DELETE, DEL_ITAB, ITAB.
        LEAVE TO SCREEN 3000.
      ELSE.
        MESSAGE I000(ZJ) WITH 'Problem in deletion'.
        ROLLBACK WORK.
*      CLEAR : OPEN_WID, ITAB_TO_DELETE, OK_CODE, LAST_OPEN_WID,
*             LAST_OPEN_WID1, MESS_STRING, VAR_ANS.
*      REFRESH : ITAB_TO_DELETE, OPEN_WID.
        LEAVE TO SCREEN 5000.
      ENDIF.
    WHEN 'BACK'.
      CLEAR : OPEN_WID, ZWB_CARRIER, ZWB_WEIGHT, ITAB_TO_DELETE,
              DEL_ITAB, ZITEMS,OK_CODE, VAR_ANS, ITAB, LAST_OPEN_WID,
              LAST_OPEN_WID1,MESS_STRING, STATUS.
      REFRESH : OPEN_WID, ITAB_TO_DELETE, DEL_ITAB, ITAB.
      LEAVE TO SCREEN 3000.
    WHEN 'CANC'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_5000  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_4000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_4000 OUTPUT.
  SET PF-STATUS 'PFSTAT_4'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_4000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_4000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_4000 INPUT.
  CASE OK_CODE.
    WHEN 'NEW' OR 'BACK'.
    CLEAR : ITAB,OPEN_WID, STATUS, MESS_STRING, VAR_ANS, LAST_OPEN_WID1,
                ZWB_CARRIER, ZWB_WEIGHT, OK_CODE, ZITEMS, LAST_OPEN_WID,
                    DEL_ITAB, ITAB_TO_DELETE, ITAB_PRINT,PRINT_FLAG.
      REFRESH :ITAB, OPEN_WID, DEL_ITAB, ITAB_TO_DELETE, ITAB_PRINT.
      LEAVE TO SCREEN 3000.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
    WHEN 'CANC'.
      LEAVE TO SCREEN 0.
    WHEN 'PRNT'.
      PERFORM PRINT_SLIP.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_4000  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_5000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_5000 OUTPUT.
  SET PF-STATUS 'PFSTAT_5'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_5000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
  SET PF-STATUS 'PFSTAT_2'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_3000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_3000 OUTPUT.
  SET PF-STATUS 'PFSTAT_3'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_3000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_6000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_6000 OUTPUT.

  SET PF-STATUS 'PFSTAT_6'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_6000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_6000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_6000 INPUT.
  CASE OK_CODE.
    WHEN 'GETW'.
      IF  PROD_MATL = 'X' AND NOT ZWB_WEIGHT-CAST_NO IS INITIAL.
        SELECT SINGLE T_WEIGHT INTO ZWB_WEIGHT-WEIGHT1
          FROM ZWB_PVEH_WT
         WHERE VEH_NO = ZWB_CARRIER-VEH_NO.
        IF SY-SUBRC = 0.
          ZWB_WEIGHT-W1_USER = SY-UNAME.
          ZWB_WEIGHT-W1_DATE = SY-DATUM.
          ZWB_WEIGHT-W1_TIME = SY-UZEIT.
        ELSE.
         MESSAGE I000(ZJ) WITH 'Vehicle not maintained for tare weight'.
          CLEAR : OK_CODE.
          LEAVE TO SCREEN 6000.
        ENDIF.
      ELSEIF ( ( PROD_MATL = 'X' AND ZWB_WEIGHT-CAST_NO IS INITIAL )
        OR ( PROD_MATL NE 'X' AND NOT ZWB_WEIGHT-CAST_NO IS INITIAL ) ).
        MESSAGE I000(ZJ) WITH
      'Cast Number should be present only for Production Material'.
        CLEAR : OK_CODE, ZWB_WEIGHT-CAST_NO, PROD_MATL.
        LEAVE TO SCREEN 6000.
      ELSEIF INT_MVMT = 'X'.
        ZWB_WEIGHT-STATUS = 'I'.
        CLEAR INT_MVMT.
      ENDIF.

*   ELSEIF PROD_MATL NE 'X' AND ZWB_WEIGHT-CAST_NO IS INITIAL.
*       ********* to cleat clipboard containts ************
     CLEAR ITAB_WT.
     REFRESH ITAB_WT.
     CALL FUNCTION 'CLPB_EXPORT'
*         IMPORTING
*           EMPTY
          TABLES
            DATA_TAB         = ITAB_WT
         EXCEPTIONS
           CLPB_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.

**********    EXECUTE THE VB PROGRAM HERE ********************
CALL FUNCTION 'WS_EXECUTE'
 EXPORTING
*   DOCUMENT                 = ' '
*   CD                       = ' '
*   COMMANDLINE              = ' '
   INFORM                   = 'X'
   PROGRAM                  = 'C:\WEIGHBRIDGE\WEIGHBRIDGE.EXE'
*   STAT                     = ' '
*   WINID                    = ' '
*   OSMAC_SCRIPT             = ' '
*   OSMAC_CREATOR            = ' '
*   WIN16_EXT                = ' '
*   EXEC_RC                  = ' '
* IMPORTING
*   RBUFF                    =
 EXCEPTIONS
   FRONTEND_ERROR           = 1
   NO_BATCH                 = 2
   PROG_NOT_FOUND           = 3
   ILLEGAL_OPTION           = 4
   GUI_REFUSE_EXECUTE       = 5
   OTHERS                   = 6
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
      CALL FUNCTION 'CLPB_IMPORT'
*        IMPORTING
*           EMPTY            =
           TABLES
              DATA_TAB         = ITAB_WT
           EXCEPTIONS
              CLPB_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.

      READ TABLE ITAB_WT INDEX 1.
      IF ITAB_WT-WEIGHT = ' '.
        MESSAGE I000(ZJ) WITH 'NO WEIGHT DATA'.
        CLEAR : OK_CODE, ITAB_WT.
        REFRESH ITAB_WT.
        LEAVE TO SCREEN 6000.
      ELSE.
*        IF PROD_MATL = 'X' AND NOT ZWB_WEIGHT-CAST_NO IS INITIAL.
*           ZWB_WEIGHT-WEIGHT2 = ITAB_WT-WEIGHT.
*        ELSEIF ZWB_WEIGHT-WEIGHT1 IS INITIAL.
*           ZWB_WEIGHT-WEIGHT1 = ITAB_WT-WEIGHT.
*        ELSE.
*           ZWB_WEIGHT-WEIGHT2 = ITAB_WT-WEIGHT.
*        ENDIF.
        IF ZWB_WEIGHT-WEIGHT1 IS INITIAL.
          ZWB_WEIGHT-WEIGHT1 = ITAB_WT-WEIGHT.
          ZWB_WEIGHT-W1_USER = SY-UNAME.
          ZWB_WEIGHT-W1_DATE = SY-DATUM.
          ZWB_WEIGHT-W1_TIME = SY-UZEIT.
        ELSE.
          ZWB_WEIGHT-WEIGHT2 = ITAB_WT-WEIGHT.
          ZWB_WEIGHT-W2_USER = SY-UNAME.
          ZWB_WEIGHT-W2_DATE = SY-DATUM.
          ZWB_WEIGHT-W2_TIME = SY-UZEIT.
          NET_WT = ABS( ZWB_WEIGHT-WEIGHT2 - ZWB_WEIGHT-WEIGHT1 ).
        ENDIF.
        WEIGHT_TAKEN = 'Y'.
      ENDIF.
*Cancellation of wid.
    WHEN 'DELE'.
      SELECT SINGLE *
        FROM ZWB_WEIGHT
       WHERE WID = ZWB_WEIGHT-WID
         AND STATUS <> 'C'
         AND STATUS <> 'D' .

      IF SY-SUBRC <> 0.
         ROLLBACK WORK.
         IF ZWB_WEIGHT-STATUS = 'D'.
            MESSAGE I000(ZJ) WITH 'ID already cancelled'.
            CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT.
            CLEAR : WEIGHT_TAKEN, ZWB_CARRIER, ZWB_PVEH_WT.
            CLEAR : ITAB_WT,ITAB_PRINT.
            REFRESH : ITAB_WT,ITAB_PRINT.
            LEAVE TO SCREEN 1000.

         ELSEIF ZWB_WEIGHT-STATUS = 'C'.
MESSAGE I000(ZJ) WITH 'Processing completed, Cancellation not possible '
.
            CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT.
            CLEAR : WEIGHT_TAKEN, ZWB_CARRIER, ZWB_PVEH_WT.
            CLEAR : ITAB_WT,ITAB_PRINT.
            REFRESH : ITAB_WT,ITAB_PRINT.
            LEAVE TO SCREEN 1000.
         ENDIF.
      ELSE.
***********************
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
            EXPORTING
              DEFAULTOPTION        = 'N'
              DIAGNOSETEXT1        = 'Caution !!'
*          DIAGNOSETEXT2        = ' '
*          DIAGNOSETEXT3        = ' '
              TEXTLINE1            = 'Want to cancel the Weighment ID?'
*          TEXTLINE2            = ' '
              TITEL                = 'Confirm'
*          START_COLUMN         = 25
*          START_ROW            = 6
           CANCEL_DISPLAY       = ' '
            IMPORTING
              ANSWER               = VAR_CONF
                     .
          CASE VAR_CONF.
            WHEN 'N'.
*              ROLLBACK WORK.
              MESSAGE I000(ZJ) WITH 'Cancellation aborted'.
              CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT,
                      WEIGHT_TAKEN,ZWB_CARRIER, ZWB_PVEH_WT,
                      ITAB_WT,ITAB_PRINT,VAR_CONF.
              REFRESH : ITAB_WT,ITAB_PRINT.
              LEAVE TO SCREEN 1000.
            WHEN 'J'.
               UPDATE ZWB_WEIGHT
                  SET STATUS = 'D'
                WHERE WID = ZWB_WEIGHT-WID
                  AND STATUS <> 'C'
                  AND STATUS <> 'D' .

              COMMIT WORK.

              MESSAGE I000(ZJ) WITH 'Cancellation done'.
              CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT,
                      WEIGHT_TAKEN,ZWB_CARRIER, ZWB_PVEH_WT,
                      ITAB_WT,ITAB_PRINT,VAR_CONF.
              REFRESH : ITAB_WT,ITAB_PRINT.
              LEAVE TO SCREEN 1000.
            WHEN OTHERS.
              ROLLBACK WORK.
              MESSAGE I000(ZJ) WITH 'Cancellation aborted'.
              CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT,
                      WEIGHT_TAKEN,ZWB_CARRIER, ZWB_PVEH_WT,
                      ITAB_WT,ITAB_PRINT,VAR_CONF.
              REFRESH : ITAB_WT,ITAB_PRINT.
              LEAVE TO SCREEN 1000.

          ENDCASE.


***********************
      ENDIF.

      CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT, WEIGHT_TAKEN,
              ZWB_CARRIER, ZWB_PVEH_WT, ITAB_WT,ITAB_PRINT.
      REFRESH : ITAB_WT,ITAB_PRINT.
      LEAVE TO SCREEN 1000.
    WHEN 'BACK'.
      CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, NET_WT, WEIGHT_TAKEN,
              ZWB_CARRIER, ZWB_PVEH_WT, ITAB_WT,ITAB_PRINT,INT_MVMT.
      REFRESH : ITAB_WT,ITAB_PRINT.
      LEAVE TO SCREEN 1000.
    WHEN 'EXIT' OR 'CANC'.
      LEAVE TO SCREEN 0.

  ENDCASE.
ENDMODULE.                 " USER_COMMAND_6000  INPUT
*&---------------------------------------------------------------------*
*&      Form  GET_IP_ADD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_IP_ADD.
  REFRESH : DESTI,SERVERP.
  CALL FUNCTION 'RFC_GET_LOCAL_SERVERS'
       TABLES
            HOSTS         = DESTI
       EXCEPTIONS
            NOT_AVAILABLE = 1.

  LOOP AT DESTI.
    REFRESH USR_LISTE.
    CALL FUNCTION 'THUSRINFO' DESTINATION DESTI-NAME
        TABLES     USR_TABL  =  USR_LISTE
        EXCEPTIONS COMMUNICATION_FAILURE = 17.
    IF SY-SUBRC = '17'.
*   SERVERA-COMMU = 'P'.
      EXIT.
    ELSE.
*   SERVERA-COMMU = ' '.
    ENDIF.
    DELETE USR_LISTE WHERE BNAME NE SY-UNAME.
    LOOP AT USR_LISTE.
      CHECK USR_LISTE-TERM <> '????' AND USR_LISTE-TERM <> 'APPC-TM'.
      IF USR_LISTE-TERM CS ':'.
        USR_LISTE-TERM = USR_LISTE-TERM(SY-FDPOS).
      ENDIF.
      CLEAR SERVERP-S.
      SERVERP-S = USR_LISTE-TERM.
      SERVERP-X = USR_LISTE-HOSTADR.
*      PERFORM IP_HEX2ASCII_N USING SERVERP-X CHANGING SERVERP-SL.
      IF SERVERP-S IS INITIAL.         " OR SERVERP-SL CS '0.0.0.0'.
      ELSE.
        COLLECT SERVERP.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    " GET_IP_ADD
*&---------------------------------------------------------------------*
*&      Module  SAVE_WEIGHT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE SAVE_WEIGHT OUTPUT.
  IF PRINT_FLAG = 'CANCEL_PRINT'.
    CLEAR : PRINT_FLAG,WEIGHT_TAKEN.
    LEAVE SCREEN.
  ENDIF.

  IF WEIGHT_TAKEN = 'Y'.
*  OR PRINT_FLAG <> 'CANCEL_PRINT'.
    CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
          EXPORTING
            DEFAULTOPTION        = 'Y'
            DIAGNOSETEXT1        = 'The weight value is'
            DIAGNOSETEXT2        = ITAB_WT-WEIGHT
            DIAGNOSETEXT3        = 'Want to confirm weight ? '
            TEXTLINE1            = 'Choose YES to confirm...'
*          TEXTLINE2            = ' '
            TITEL                = 'Confirm'
*          START_COLUMN         = 25
*          START_ROW            = 6
*          CANCEL_DISPLAY       = 'X'
          IMPORTING
            ANSWER               = WEIGHT_CONF
                        .
    CASE WEIGHT_CONF.
      WHEN 'J'.
        IF NOT ZWB_WEIGHT-WEIGHT2 IS INITIAL AND NET_WT = 0.
          MESSAGE I000(ZJ) WITH
                  'GROSS WEIGHT AND TARE WEIGHT CAN''T BE EQUAL'.
          CLEAR : ZWB_WEIGHT-WEIGHT2, NET_WT,WEIGHT_TAKEN.
          LEAVE TO SCREEN 6000.
        ELSE.
          MODIFY ZWB_WEIGHT.

          IF SY-SUBRC = 0.
            COMMIT WORK.
*               NET_WT = ABS( ZWB_WEIGHT-WEIGHT2 - ZWB_WEIGHT-WEIGHT1).
            MESSAGE I000(ZJ) WITH 'WEIGHT CAPATURED AND UPDATED'.
            IF NOT ZWB_WEIGHT-WEIGHT2 IS INITIAL.
              ITAB_PRINT-WID = ZWB_WEIGHT-WID.
              ITAB_PRINT-MATL_DESC = ZWB_WEIGHT-MATL_DESC.
              ITAB_PRINT-CAST_NO = ZWB_WEIGHT-CAST_NO.
              ITAB_PRINT-WEIGHT1 = ZWB_WEIGHT-WEIGHT1.
              ITAB_PRINT-WEIGHT2 = ZWB_WEIGHT-WEIGHT2.
              ITAB_PRINT-W1_DATE = ZWB_WEIGHT-W1_DATE.
              ITAB_PRINT-W1_TIME = ZWB_WEIGHT-W1_TIME.
              ITAB_PRINT-W2_DATE = ZWB_WEIGHT-W2_DATE.
              ITAB_PRINT-W2_TIME = ZWB_WEIGHT-W2_TIME.
              APPEND ITAB_PRINT.
*              IF PRINT_FLAG <> 'CANCEL_PRINT'.
              PERFORM PRINT_SLIP.
*              ENDIF.
            ENDIF.
*            IF PRINT_FLAG <> 'CANCEL_PRINT'.
            CLEAR : OK_CODE, PROD_MATL, ZWB_WEIGHT, WEIGHT_TAKEN,
                    ZWB_CARRIER, ZWB_PVEH_WT, ITAB_WT, ITAB_PRINT,
INT_MVMT,NET_WT.
            REFRESH : ITAB_WT, ITAB_PRINT.
            LEAVE TO SCREEN 1000.
*            ELSE.
*              CLEAR : OK_CODE.
*              LEAVE TO SCREEN 6000.
*            ENDIF.
          ELSE.
            ROLLBACK WORK.
            MESSAGE I000(ZJ) WITH
                'PROBLEM IN UPDATION, RETRY... '.
            CLEAR : OK_CODE, WEIGHT_CONF, ITAB_WT, WEIGHT_TAKEN.
            REFRESH ITAB_WT.
            LEAVE TO SCREEN 6000.
          ENDIF.
        ENDIF.
      WHEN OTHERS.
        IF  PROD_MATL = 'X' AND NOT ZWB_WEIGHT-CAST_NO IS INITIAL.
          CLEAR : ZWB_WEIGHT-WEIGHT2, NET_WT. "TO CLEAR WEIGHT

        ELSE.
          IF ZWB_WEIGHT-WEIGHT2 IS INITIAL.
            CLEAR ZWB_WEIGHT-WEIGHT1.
          ELSE.
            CLEAR : ZWB_WEIGHT-WEIGHT2, NET_WT.
          ENDIF.
        ENDIF.
        CLEAR : OK_CODE, WEIGHT_CONF, ITAB_WT, WEIGHT_TAKEN.
        REFRESH ITAB_WT.
        LEAVE TO SCREEN 6000.
    ENDCASE.
*  ELSE.
*    CLEAR PRINT_FLAG.
  ENDIF.
ENDMODULE.                 " SAVE_WEIGHT  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  SHOW_WID_4000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE SHOW_WID_4000 OUTPUT.
  IF NOT ITAB IS INITIAL AND ( OK_CODE = 'SAVE' OR OK_CODE = 'PRNT' ).
    ZWB_WEIGHT-WID = ITAB-WID.
    ZWB_WEIGHT-MATL_DESC = ITAB-MATL_DESC.
    ITAB_PRINT-WID = ITAB-WID.
    ITAB_PRINT-MATL_DESC = ITAB-MATL_DESC.
    APPEND ITAB_PRINT.
*   COUNTER = 'X'.
*ELSE.
*   IF NOT COUNTER = 'X'.
*      ZITEMS = 1.
*      CLEAR COUNTER.
*    ENDIF.
  ENDIF.

ENDMODULE.                 " SHOW_WID_4000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  AUTH_CHK  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE AUTH_CHK OUTPUT.

**** TO ENABLE THE FIELDS FOR THE FIRST TIME AND DISABLE THEM WHEN
****WEIGHT VALUES ARE TAKEN.

  IF NOT ZWB_WEIGHT-WEIGHT1 IS INITIAL AND
     NOT ZWB_WEIGHT-WEIGHT2 IS INITIAL.
    NET_WT = ABS( ZWB_WEIGHT-WEIGHT2 - ZWB_WEIGHT-WEIGHT1 ).
    LOOP AT SCREEN.
      IF SCREEN-GROUP1 = 'G1'.
        SCREEN-INPUT = '0'.
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
*IF NOT ZWB_WEIGHT-CAST_NO IS INITIAL.

ENDMODULE.                 " AUTH_CHK  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  PRINT_SLIP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PRINT_SLIP.
*{   INSERT         KD1K900432                                        2
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME                 = 'ZWEIGHMENT_SLIP'
*     VARIANT                  = ' '
*     DIRECT_CALL              = ' '
   IMPORTING
     FM_NAME                  = FM_NAME
   EXCEPTIONS
     NO_FORM                  = 1
     NO_FUNCTION_MODULE       = 2
     OTHERS                   = 3
            .
  IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

*}   INSERT
*CONTROL_ITAB-NO_CLOSE = 'X'.
*APPEND CONTROL_ITAB.
*{   REPLACE        KD1K900432                                        1
*\  CALL FUNCTION '/1BCDWB/SF00000005'
  CALL FUNCTION FM_NAME
*}   REPLACE
    EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
      CONTROL_PARAMETERS         = CONTROL_ITAB
*   MAIL_APPL_OBJ              =
*   MAIL_RECIPIENT             =
*   MAIL_SENDER                =
*   OUTPUT_OPTIONS             =
*   USER_SETTINGS              = 'X'
      VEHICLE_NO                 = ZWB_CARRIER-VEH_NO
      CARRIER                    = ZWB_CARRIER-TRANSPORTER
* IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
*   JOB_OUTPUT_INFO            =
*   JOB_OUTPUT_OPTIONS         =
    TABLES
      ITAB                       = ITAB_PRINT
    EXCEPTIONS
      FORMATTING_ERROR           = 1
      INTERNAL_ERROR             = 2
      SEND_ERROR                 = 3
      USER_CANCELED              = 4
      OTHERS                     = 5
            .
  IF SY-SUBRC = 4 .
   PRINT_FLAG = 'CANCEL_PRINT'.
    LEAVE SCREEN.

  ELSEIF SY-SUBRC <> 0 .

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

* LEAVE SCREEN.
  ELSE.
    PRINT_FLAG = ' '.
  ENDIF.

ENDFORM.                    " PRINT_SLIP
*&---------------------------------------------------------------------*
*&      Module  PRINT_SLIP  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE PRINT_SLIP OUTPUT.
  IF PRINT_FLAG <> 'CANCEL_PRINT'.
    PERFORM PRINT_SLIP.
    CLEAR PRINT_FLAG.
  ENDIF.
ENDMODULE.                 " PRINT_SLIP  OUTPUT

*{   INSERT         KD1K900432                                        1
*&---------------------------------------------------------------------*
*&      Module  VAL_REQ_WID  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE VAL_REQ_WID INPUT.
CALL SCREEN 100 STARTING AT 10 5
                   ENDING AT 25 15.
   CASE RETURN.
     WHEN 'SELE'.
       ZWB_WEIGHT-WID = SELECTION.
     WHEN 'BREAK'.
      LEAVE TO SCREEN 0.
      CLEAR : RETURN.
   ENDCASE.

ENDMODULE.                 " VAL_REQ_WID  INPUT

AT LINE-SELECTION.
     RETURN = 'SELE'.
     SELECTION = HELP_WID.
     LEAVE LIST-PROCESSING.


*}   INSERT

*{   INSERT         KD1K900432                                        2
*&---------------------------------------------------------------------*
*&      Module  LIST_PROCESSING  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE LIST_PROCESSING OUTPUT.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
  NEW-PAGE LINE-SIZE 15.
*  SET PF-STATUS 'POP_PICK'.
  SET PF-STATUS SPACE.
  SET TITLEBAR 'HELP_TITLE'.
  FORMAT COLOR COL_HEADING.
  WRITE : / 'Weighment Id'.
  ULINE AT 0(15).
  FORMAT COLOR COL_NORMAL.
  SELECT WID
    INTO HELP_WID
    FROM ZWB_WEIGHT UP TO 20 ROWS
   WHERE WEIGHT2 = 0
     AND STATUS <> 'D'
 ORDER BY WID DESCENDING.
     WRITE : / HELP_WID.
     HIDE : HELP_WID.

  ENDSELECT.
  IF SY-SUBRC <> 0.
     WRITE : /'No WID generated for today'.
     CLEAR : HELP_WID.
  ENDIF.

 LEAVE SCREEN.

ENDMODULE.                 " LIST_PROCESSING  OUTPUT

AT LINE-SELECTION.
     RETURN = 'SELE'.
     SELECTION = HELP_WID.
     LEAVE LIST-PROCESSING.
  AT USER-COMMAND.

     CASE SY-UCOMM.
       WHEN 'EXIT'.
          RETURN = 'BREAK'. LEAVE LIST-PROCESSING.
       WHEN 'RTRN'.
          RETURN = 'BREAK'. LEAVE LIST-PROCESSING.
       WHEN 'SELE'.
          RETURN = 'SELE'.
     ENDCASE.


Code:

method IF_EX_MB_DOCUMENT_BADI~MB_DOCUMENT_UPDATE.
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari                
*----------------------------------------------------------------------*
*       Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*

DATA: l_mseg       TYPE mseg.
DATA: l_xmkpf       TYPE mkpf.
DATA: var_wid type zwb_weight-wid.
DATA: NEW_WID type zwb_weight-wid.
DATA: itab type zwb_weight.
DATA : CONVERTED_QTY TYPE PLFH-MGVGW.
DATA : CONVERTED_QTY_N TYPE zwb_weight-weight1.
DATA : VAR_QTY TYPE PLFH-MGVGW.

CLEAR : L_MSEG.

READ TABLE xmkpf into l_xmkpf INDEX 1.
LOOP AT xmseg INTO L_MSEG.

  IF sy-subrc <> 0.
    EXIT.
  ENDIF.

 IF ( l_xmkpf-tcode2 = 'MIGO_GR' and                      "For MIGO
      ( l_mseg-bwart = '101' or l_mseg-bwart = '105' )  ).
  UPDATE ZWB_WEIGHT
     SET STATUS = 'C'
   WHERE WID = L_MSEG-ABLAD.

  IF sy-subrc <> 0.
     EXIT.
  ENDIF.

 ELSEIF ( l_xmkpf-tcode2 = 'CORK' and                          "For CORK
          l_mseg-bwart = '101' ).
  UPDATE ZWB_WEIGHT
     SET STATUS = 'C'
   WHERE CAST_NO = L_MSEG-CHARG.

  IF sy-subrc <> 0.
     EXIT.
  ENDIF.
 ELSEIF ( ( l_xmkpf-tcode2 = 'MB1A' or                        "For MB1A
            l_xmkpf-tcode2 = 'MB1C' )                         "For MB1C
        and l_mseg-bwart = '531' ).
  UPDATE ZWB_WEIGHT
     SET STATUS = 'C'
   WHERE WID = L_MSEG-SGTXT.

  IF sy-subrc <> 0.
     EXIT.
  ENDIF.

************For reversals of material document*********
ELSEIF ( l_xmkpf-tcode2 = 'MIGO_GR' and                      "For MIGO
      ( l_mseg-bwart = '102' )  ).
  UPDATE ZWB_WEIGHT
     SET STATUS = ' '
   WHERE WID = L_MSEG-ABLAD.

  IF sy-subrc <> 0.
     EXIT.
  ENDIF.

 ELSEIF ( l_xmkpf-tcode2 = 'CORS' and                "For CORK reversal
          l_mseg-bwart = '102' ).
  SELECT WID INTO NEW_WID
    FROM ZWB_WEIGHT
    UP TO 1 ROWS
   WHERE CAST_NO = L_MSEG-CHARG
     AND STATUS = 'C'.
   IF SY-SUBRC = 0.
      VAR_QTY = L_MSEG-ERFMG.
      CALL FUNCTION 'CF_UT_UNIT_CONVERSION'
    EXPORTING
      MATNR_IMP           = L_MSEG-MATNR
*     MEINS_IMP           = ' '
      UNIT_NEW_IMP        = 'WT'
      UNIT_OLD_IMP        = 'TO'
      VALUE_OLD_IMP       = VAR_QTY
    IMPORTING
      VALUE_NEW_EXP       = CONVERTED_QTY
    EXCEPTIONS
      OVERFLOW            = 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.
  CONVERTED_QTY_N = CONVERTED_QTY * 1000.

      CONCATENATE NEW_WID+0(6) '99' '0000' INTO NEW_WID.
      itab-WID = NEW_WID.
      itab-CAST_NO = L_MSEG-CHARG.
      itab-W1_DATE = sy-datum.
      itab-W2_DATE = sy-datum.
      itab-W1_TIME = SY-UZEIT.
      itab-W2_TIME = SY-UZEIT.
      itab-WEIGHT1 = 1.
      itab-WEIGHT2 = ( CONVERTED_QTY_N + 1 ).
      itab-STATUS = 'R'.
      INSERT INTO ZWB_WEIGHT  VALUES itab.
   ENDIF.
  ENDSELECT.

 ELSEIF (  l_xmkpf-tcode2 = 'MBST'                    "For MB1A & MB1C
       and l_mseg-bwart = '532' ).
  UPDATE ZWB_WEIGHT
     SET STATUS = ' '
   WHERE WID = L_MSEG-SGTXT.

  IF sy-subrc <> 0.
     EXIT.
  ENDIF.

ENDIF.
ENDLOOP.
******************for delivery document ***************************

IF ( ( l_xmkpf-tcode2 = 'VL01N' or l_xmkpf-tcode2 = 'VL02N' ) and
     ( l_mseg-bwart = '601' ) ).
      select single kdmat into var_wid
        from lips
      where vbeln = l_xmkpf-xblnr.
       IF sy-subrc <> 0.
          EXIT.
       ELSE.
         update zwb_weight
            set status = 'C'
          where wid = var_wid.
       ENDIF.
******************Added to handle reversals ************************

ELSEIF ( ( l_xmkpf-tcode2 = 'VL01N' or l_xmkpf-tcode2 = 'VL02N' ) and
     ( l_mseg-bwart = '602' ) ).
      select single kdmat into var_wid
        from lips
      where vbeln = l_xmkpf-xblnr.
       IF sy-subrc <> 0.
          EXIT.
       ELSE.
         update zwb_weight
            set status = ' '
          where wid = var_wid.
       ENDIF.

ENDIF.

endmethod.
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 -> ММ 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.