Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Zcqp01 Programe

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

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

*& Report Z_INSPECTION_PLAN_BAPI


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_INSPECTION_PLAN_BAPI NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPES : BEGIN OF TY_TAB,

MATNR TYPE MAPL-MATNR, "Material Number .


WERKS TYPE MAPL-WERKS, "plant .
STTAG(10) TYPE C, "Key Date .
ROTXT(40) TYPE C , "Routing Text .
GC(3) TYPE C, "Group Counter .
UOM(4) TYPE C , " UOM
OPID(4) TYPE C, " OPERATION ID
USAGE(1) TYPE C, "USAGE .
STATUS TYPE PLKO-STATU, "status .
LOTSZ(1) TYPE C, "Lot Size min
LOTSI(9) TYPE C, "Lot Size mAX
WRKCN(8) TYPE C, "WORK CENTER
STEUS_01 TYPE PLPO-STEUS, "Control key
OPDES(40) TYPE C, "Operation Description
CHRNO(3) TYPE C, "CHAR NO
QTY TYPE BMSCH , " BASE QUANTITY .
VERWMERKM TYPE PLMK-VERWMERKM, "Master Inspection Characteristics
STICHPRVER TYPE PLMK-STICHPRVER, "Sampling Procedure
END OF TY_TAB.

TYPES: BEGIN OF TY_QPMT ,


MKMNR TYPE QPMT-MKMNR,
KURZTEXT TYPE QPMT-KURZTEXT,
END OF TY_QPMT.

DATA : IT_QPMT TYPE TABLE OF TY_QPMT,


WA_QPMT TYPE TY_QPMT.

DATA : WA_TAB TYPE TY_TAB,


IT_TAB TYPE TABLE OF TY_TAB,
CA_TAB TYPE TY_TAB.

DATA: IT_XL_DAT TYPE STANDARD TABLE OF ALSMEX_TABLINE,


WA_XL_DAT TYPE ALSMEX_TABLINE.

DATA : WA_UPDATE TYPE CTU_PARAMS-UPDMODE,


WA_INDEX TYPE I,
WA_LINE TYPE I,
WA_ROW TYPE I VALUE 1,
V_S TYPE CHAR15.

FIELD-SYMBOLS : <FS> TYPE ANY .

DATA : BEGIN OF IT_LOGDETAIL OCCURS 0,


MATNR LIKE BAPI1191_MTK_C-MATERIAL,
WERKS LIKE BAPI1191_TSK_C-PLANT,
MSGTYPE LIKE BAPIRET2-TYPE,
MSG(100) TYPE C,
END OF IT_LOGDETAIL.

DATA: BEGIN OF IT_LOGHEAD OCCURS 0,


MATNR LIKE BAPI1191_MTK_C-MATERIAL,
WERKS LIKE BAPI1191_TSK_C-PLANT,
MSGTYPE LIKE BAPIRET2-TYPE,
MSG(100) TYPE C,
EXPAND TYPE C,
END OF IT_LOGHEAD .

DATA: IT_TASK TYPE TABLE OF BAPI1191_TSK_C WITH HEADER LINE,


IT_MATERIAL TYPE TABLE OF BAPI1191_MTK_C WITH HEADER LINE,
IT_INSP_CHAR TYPE TABLE OF BAPI1191_CHA_C WITH HEADER LINE,
IT_OPERATION TYPE TABLE OF BAPI1191_OPR_C WITH HEADER LINE,
IT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
IT_RETURN1 TYPE TABLE OF BAPIRET2 WITH HEADER LINE.

DATA: V_GROUP TYPE BAPI1191_TSK_C-TASK_LIST_GROUP,


V_GRPCOUNTER TYPE BAPI1191_TSK_C-GROUP_COUNTER,
V_ROW TYPE N,
V_PLANT LIKE IT_TASK-PLANT,
LV_DATE TYPE SY-DATUM,
L_MSG(200).

DATA: WA_RETURN TYPE BAPIRET2,


WA_RETURN1 TYPE BAPIRET2.

SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-101.

PARAMETERS : P_FNAME TYPE IBIPPARMS-PATH OBLIGATORY,


P_TEST type BAPIFLAG DEFAULT 'X'.

SELECTION-SCREEN : SKIP.
SELECTION-SCREEN : END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

PERFORM F4_FILENAME.

START-OF-SELECTION.

PERFORM UPLOAD_EXCELDATA_ITAB.
PERFORM BAPI_DATA.
* PERFORM display_log_list.

*&---------------------------------------------------------------------*
*& Form F4_FILENAME
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM F4_FILENAME .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FNAME'
IMPORTING
FILE_NAME = P_FNAME.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_EXCELDATA_ITAB
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM UPLOAD_EXCELDATA_ITAB .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'


EXPORTING
FILENAME = P_FNAME
I_BEGIN_COL = '1'
I_BEGIN_ROW = '2'
I_END_COL = '18'
I_END_ROW = '60000'
TABLES
INTERN = IT_XL_DAT
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC IS NOT INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE : / 'File Error'(001).
EXIT.
ENDIF.

IF IT_XL_DAT[] IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE : / 'No Data Uploaded'(002).
EXIT.
ELSE.
LOOP AT IT_XL_DAT INTO WA_XL_DAT .

IF WA_XL_DAT-ROW EQ WA_ROW.

MOVE WA_XL_DAT-COL TO WA_INDEX.


ASSIGN COMPONENT WA_INDEX OF STRUCTURE WA_TAB TO <FS>.
IF WA_XL_DAT-VALUE IS INITIAL.
CONTINUE.
ELSE.
<FS> = WA_XL_DAT-VALUE.
ENDIF.
AT END OF ROW.
APPEND WA_TAB TO IT_TAB.
CLEAR WA_TAB.
WA_ROW = WA_XL_DAT-ROW + 1 .
ENDAT.
ELSE.
EXIT.

ENDIF.
ENDLOOP.
ENDIF.

IF IT_TAB IS NOT INITIAL .

SELECT MKMNR
KURZTEXT FROM QPMT
INTO TABLE IT_QPMT FOR ALL ENTRIES IN IT_TAB
WHERE ZAEHLER = IT_TAB-WERKS AND MKMNR = IT_TAB-VERWMERKM AND SPRACHE =
'E' .

SORT IT_QPMT BY MKMNR .

ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form BAPI_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM BAPI_DATA .

DATA: LV_MATNR TYPE MARA-MATNR,


LT_MAPL TYPE TABLE OF MAPL,
LS_MAPL TYPE MAPL,
lv_uom type mara-meins.

REFRESH : IT_MATERIAL , IT_TASK ,IT_OPERATION,IT_INSP_CHAR.

LOOP AT IT_TAB INTO CA_TAB.


WA_TAB = CA_TAB .

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'


EXPORTING
DATE_EXTERNAL = WA_TAB-STTAG
* ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = LV_DATE
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
INPUT = wa_tab-uom
* LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = lv_uom
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

AT NEW MATNR.

TRANSLATE WA_TAB-MATNR TO UPPER CASE.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'


EXPORTING
INPUT = WA_TAB-MATNR
IMPORTING
OUTPUT = LV_MATNR
* EXCEPTIONS
* LENGTH_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

SELECT * FROM MAPL INTO TABLE LT_MAPL


WHERE MATNR = LV_MATNR
AND WERKS = WA_TAB-WERKS
AND PLNTY = 'Q'
AND LOEKZ = ' '.
IF SY-SUBRC = 0.
READ TABLE LT_MAPL INTO LS_MAPL INDEX 1.
CONCATENATE 'FOR MATERIAL ' LV_MATNR 'TASK LIST ALREADY EXISTING WITH
COUNTER' LS_MAPL-PLNAL
INTO L_MSG SEPARATED BY SPACE.
WRITE:/ L_MSG.
SKIP.
DELETE IT_TAB WHERE MATNR = WA_TAB-MATNR.
CLEAR: CA_TAB, WA_TAB, LS_MAPL, L_MSG, LT_MAPL[].
CONTINUE.
ENDIF.
IT_MATERIAL-MATERIAL = LV_MATNR ."wa_tab-matnr .
IT_MATERIAL-PLANT = WA_TAB-WERKS .
IT_MATERIAL-GROUP_COUNTER = WA_TAB-GC .
IT_MATERIAL-VALID_FROM = LV_DATE .

APPEND IT_MATERIAL.

IT_TASK-GROUP_COUNTER = WA_TAB-GC .
IT_TASK-VALID_FROM = LV_DATE .
IT_TASK-TASK_LIST_USAGE = WA_TAB-USAGE .
IT_TASK-PLANT = WA_TAB-WERKS.
IT_TASK-TASK_LIST_STATUS = WA_TAB-STATUS .
IT_TASK-TASK_MEASURE_UNIT = lv_uom ." WA_TAB-UOM . .
IT_TASK-LOT_SIZE_FROM = WA_TAB-LOTSZ .
IT_TASK-LOT_SIZE_TO = WA_TAB-LOTSI .
IT_TASK-DESCRIPTION = WA_TAB-ROTXT.
APPEND IT_TASK.

IT_OPERATION-GROUP_COUNTER = WA_TAB-GC .
IT_OPERATION-VALID_FROM = LV_DATE .
IT_OPERATION-ACTIVITY = WA_TAB-OPID .
IT_OPERATION-OPERATION_ID = WA_TAB-OPID .
IT_OPERATION-CONTROL_KEY = WA_TAB-STEUS_01 .
* it_operation-obj_id = .
IT_OPERATION-WORK_CNTR = WA_TAB-WRKCN .
IT_OPERATION-PLANT = WA_TAB-WERKS .
IT_OPERATION-DESCRIPTION = WA_TAB-OPDES.
IT_OPERATION-OPERATION_MEASURE_UNIT = lv_uom ." WA_TAB-UOM .
IT_OPERATION-DENOMINATOR = '1'.
IT_OPERATION-NOMINATOR = '1' .
IT_OPERATION-BASE_QUANTITY = WA_TAB-QTY .
APPEND IT_OPERATION.
ENDAT .

IT_INSP_CHAR-GROUP_COUNTER = WA_TAB-GC.
IT_INSP_CHAR-OPERATION_ID = WA_TAB-OPID .
IT_INSP_CHAR-ACTIVITY = WA_TAB-OPID.
IT_INSP_CHAR-INSPCHAR = WA_TAB-CHRNO. .
IT_INSP_CHAR-VALID_FROM = LV_DATE .
IT_INSP_CHAR-MSTR_CHAR = WA_TAB-VERWMERKM .
IT_INSP_CHAR-PMSTR_CHAR = WA_TAB-WERKS .
IT_INSP_CHAR-CHA_MASTER_IMPORT_MODUS = 'C' .

IF WA_TAB-VERWMERKM IS NOT INITIAL .

READ TABLE IT_QPMT INTO WA_QPMT WITH KEY MKMNR = WA_TAB-VERWMERKM BINARY
SEARCH.
IF SY-SUBRC IS INITIAL .
IT_INSP_CHAR-CHAR_DESCR = WA_QPMT-KURZTEXT. .
ENDIF.
CLEAR: WA_QPMT.
ENDIF .

TRANSLATE WA_TAB-STICHPRVER TO UPPER CASE.

IT_INSP_CHAR-SMPL_PROCEDURE = WA_TAB-STICHPRVER .
IT_INSP_CHAR-SMPL_UNIT = lv_uom ." WA_TAB-UOM.
IT_INSP_CHAR-SMPL_QUANT = WA_TAB-QTY.
APPEND IT_INSP_CHAR .

AT END OF MATNR .

PERFORM CALL_BAPI_AND_COMMIT .

CLEAR: IT_MATERIAL , IT_TASK ,IT_OPERATION,IT_INSP_CHAR , WA_TAB , CA_TAB.

REFRESH: IT_MATERIAL , IT_TASK ,IT_OPERATION,IT_INSP_CHAR.


ENDAT .

ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form CALL_BAPI_AND_COMMIT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM CALL_BAPI_AND_COMMIT .

CALL FUNCTION 'BAPI_INSPECTIONPLAN_CREATE'


EXPORTING
TESTRUN = P_TEST
IMPORTING
GROUP = V_GROUP
GROUPCOUNTER = V_GRPCOUNTER
TABLES
TASK = IT_TASK
MATERIALTASKALLOCATION = IT_MATERIAL
OPERATION = IT_OPERATION
INSPCHARACTERISTIC = IT_INSP_CHAR
RETURN = IT_RETURN.

READ TABLE IT_RETURN INTO WA_RETURN WITH KEY TYPE = 'E'.


IF SY-SUBRC IS INITIAL .
WRITE:/ 'FOR MATERIAL', WA_TAB-MATNR, 'PROCESSING FAILED, PLEASE CHECK THE
BELOW LOG'.
LOOP AT IT_RETURN INTO WA_RETURN WHERE MESSAGE IS NOT INITIAL.
WRITE:/ WA_RETURN-MESSAGE .
ENDLOOP.
SKIP.
ELSE.
IF P_TEST IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
** IMPORTING
** return = it_return1.

IF V_GROUP IS NOT INITIAL .


CONCATENATE 'Inspection Plan for Material' WA_TAB-MATNR 'successfully
creatted' 'with group/counter'
V_GROUP '/' V_GRPCOUNTER INTO L_MSG SEPARATED BY SPACE.
WRITE:/ L_MSG.
SKIP.
CLEAR: V_GROUP, V_GRPCOUNTER, L_MSG.
ENDIF.
ELSE .
WRITE : / 'Inspection Plan for Material', WA_TAB-MATNR ,'Can be processed'.
ENDIF.
ENDIF.
ENDFORM.

You might also like