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

qp01 Upload

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

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

*& Report ZALM_QM_INSPLAN_BDC_UPLD


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalm_qm_insplan_bdc_upld.

TYPES : BEGIN OF ty_itab,


matnr TYPE matnr, " Product code
werks TYPE werks, " Plant
sttag TYPE char10, " Date
verwe TYPE plkod-verwe, " Usage
statu TYPE plkod-statu, " Overall Status
* losvn TYPE plkod-losvn, " Lot Size
losvn TYPE char16, " Lot Size
steus TYPE plpod-steus, " Control Key
quantitat TYPE rqpas-quantitat, " Quantative
verwmerkm TYPE plmkb-verwmerkm, " Master Inspection Char
sollwert TYPE qfltp-sollwert, " Target Val
toleranzun TYPE qfltp-toleranzun, " Lower limit
toleranzob TYPE qfltp-toleranzob, " Upper Limit
stichprver TYPE plmkb-stichprver, " Sampling Procedure
kurztext TYPE plmkb-kurztext,
END OF ty_itab.

DATA: BEGIN OF it_loghead OCCURS 0,


matnr LIKE mara-matnr,
msgtype LIKE bapiret2-type,
msgno LIKE bapiret2-number,
msg(100) TYPE c,
expand TYPE c,
END OF it_loghead .

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.


DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA : ist_itab TYPE TABLE OF ty_itab,
wa_itab TYPE ty_itab.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.


PARAMETERS : p_file LIKE rlgrap-filename OBLIGATORY,
p_mode LIKE ctu_params-dismode DEFAULT 'N'.
* PARAMETERS: nodata DEFAULT '/' LOWER CASE NO-DISPLAY. "nodata
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM f4value.

START-OF-SELECTION.

PERFORM upload.
IF ist_itab[] IS INITIAL.
MESSAGE 'No records selected.. Check file name.' TYPE 'E'.
EXIT.
ELSE.
PERFORM bdc_fill.
ENDIF.
PERFORM displayalv.

FORM f4value.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'


EXPORTING
field_name = ''
CHANGING
file_name = p_file.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM.

FORM upload.

DATA i_type TYPE truxs_t_text_data.

REFRESH ist_itab[].

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = i_type
i_filename = p_file
TABLES
i_tab_converted_data = ist_itab[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.

* DELETE TA_FLATFILE FROM 1 TO 1.


IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

** ELSE.
** MESSAGE e398(00) WITH 'Invalid File Type'.
** ENDIF.

IF ist_itab IS INITIAL.
MESSAGE 'No records to upload' TYPE 'E'.
ENDIF.

ENDFORM.

FORM bdc_field USING fnam fval.


* IF fval <> nodata.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
* ENDIF.
ENDFORM.

FORM bdc_dynpro USING program dynpro.


CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.

FORM bdc_transaction.
DATA: l_mstring(480).
DATA: l_subrc LIKE sy-subrc.
DATA: lx_auth_check TYPE REF TO cx_root.
DATA: l_auth_check_text TYPE string.
* batch input session

TRY.
CALL TRANSACTION 'QP01' WITH AUTHORITY-CHECK USING bdcdata
MODE p_mode
UPDATE 'A'
MESSAGES INTO messtab.
CATCH cx_sy_authorization_error INTO lx_auth_check.
* Authorization missing for user when executing transaction
l_auth_check_text = lx_auth_check->get_text( ).
sy-subrc = 99.
ENDTRY.
l_subrc = sy-subrc.
* WRITE: / 'CALL_TRANSACTION',
* 'QP01',
* 'returncode:'(i05),
* l_subrc,
* 'RECORD:',
* sy-index.
IF l_subrc <> 99.
LOOP AT messtab.
MESSAGE ID messtab-msgid
TYPE messtab-msgtyp
NUMBER messtab-msgnr
INTO l_mstring
WITH messtab-msgv1
messtab-msgv2
messtab-msgv3
messtab-msgv4.
* WRITE: / messtab-msgtyp, 'Material', wa_itab-matnr, l_mstring(250).
it_loghead-matnr = wa_itab-matnr.
it_loghead-msgno = messtab-msgnr.
it_loghead-msgtype = messtab-msgtyp.

CALL FUNCTION 'FORMAT_MESSAGE'


EXPORTING
id = messtab-msgid
lang = sy-langu
no = messtab-msgnr
v1 = messtab-msgv1
v2 = messtab-msgv2
v3 = messtab-msgv3
v4 = messtab-msgv4
IMPORTING
msg = it_loghead-msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
APPEND it_loghead.
ENDLOOP.
REFRESH messtab.
* ELSE.
* WRITE: / l_auth_check_text.
ENDIF.
** Erzeugen fehlermappe ************************************************

REFRESH bdcdata.
ENDFORM.

FORM bdc_fill .
LOOP AT ist_itab INTO wa_itab.

wa_itab-kurztext = wa_itab-verwmerkm.
TRANSLATE wa_itab-verwmerkm TO UPPER CASE.
PERFORM bdc_dynpro USING 'SAPLCPDI' '8010'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RC27M-WERKS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=XALU'.
PERFORM bdc_field USING 'RC27M-MATNR'
wa_itab-matnr.
PERFORM bdc_field USING 'RC27M-WERKS'
wa_itab-werks.
PERFORM bdc_field USING 'RC271-STTAG'
wa_itab-sttag.
* PERFORM bdc_dynpro USING 'SAPLCPDA' '1200'.
* PERFORM bdc_field USING 'BDC_OKCODE'
* '=VOUE'.
* PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCPDA
1210GENERAL'.
** PERFORM bdc_field USING 'BDC_CURSOR'
** 'PLKOD-PLNAL(01)'.
* PERFORM bdc_field USING 'RC27X-ENTRY_ACT'
* '1'.
* PERFORM bdc_field USING 'RC27X-FLG_SEL(01)'
* 'X'.

PERFORM bdc_dynpro USING 'SAPLCPDA' '1200'.


PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
* PERFORM bdc_field USING 'PLKOD-PLNAL'
* '1'.
* PERFORM bdc_field USING 'PLKOD-KTEXT'
* 'Raw material steel'.
* PERFORM bdc_field USING 'PLKOD-WERKS'
* '2000'.
* PERFORM bdc_field USING 'BDC_CURSOR'
* 'PLKOD-LOSVN'.
PERFORM bdc_field USING 'PLKOD-VERWE' wa_itab-verwe.
PERFORM bdc_field USING 'PLKOD-STATU' wa_itab-statu.
PERFORM bdc_field USING 'PLKOD-LOSVN' wa_itab-losvn.
PERFORM bdc_dynpro USING 'SAPLCPDA' '1200'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ALUE'.
PERFORM bdc_field USING 'PLKOD-VERWE' wa_itab-verwe.
PERFORM bdc_field USING 'PLKOD-STATU' wa_itab-statu.
PERFORM bdc_field USING 'PLKOD-LOSVN' wa_itab-losvn.

PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.


PERFORM bdc_field USING 'BDC_CURSOR'
'RC27X-ENTRY_ACT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=VOUE'.
PERFORM bdc_field USING 'RC27X-ENTRY_ACT'
'1'.
* PERFORM bdc_field USING 'PLPOD-BMSCH(01)'
* record-bmsch_01_007.
* PERFORM bdc_field USING 'PLPOD-MEINH(01)'
* record-meinh_01_008.
PERFORM bdc_dynpro USING 'SAPLCPDI' '1400'.
PERFORM bdc_field USING 'BDC_CURSOR'
'PLPOD-STEUS(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'PLPOD-STEUS(01)'
'QM01'.

PERFORM bdc_dynpro USING 'SAPLCPDI' '1400'.


PERFORM bdc_field USING 'BDC_CURSOR'
'PLPOD-VORNR(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=QMUE'.
PERFORM bdc_field USING 'RC27X-ENTRY_ACT'
'1'.
PERFORM bdc_field USING 'RC27X-FLG_SEL(01)'
'X'.
PERFORM bdc_dynpro USING 'SAPLQPAA' '0150'.
PERFORM bdc_field USING 'BDC_CURSOR'
'QFLTP-TOLERANZOB(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=QMBU'.
PERFORM bdc_field USING 'RQPAS-ENTRY_ACT'
'1'.
PERFORM bdc_field USING 'RQPAS-QUANTITAT(01)'
'X'.
PERFORM bdc_field USING 'PLMKB-VERWMERKM(01)'
wa_itab-verwmerkm.
PERFORM bdc_field USING 'PLMKB-KURZTEXT(01)'
wa_itab-kurztext.
PERFORM bdc_field USING 'QFLTP-SOLLWERT(01)'
wa_itab-sollwert.
PERFORM bdc_field USING 'QFLTP-TOLERANZUN(01)'
wa_itab-toleranzun.
PERFORM bdc_field USING 'QFLTP-TOLERANZOB(01)'
wa_itab-toleranzob.
PERFORM bdc_dynpro USING 'SAPLQPAA' '1501'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENT1'.
PERFORM bdc_field USING 'PLMKB-QMTB_WERKS' ' '.

PERFORM bdc_field USING 'BDC_CURSOR'


'PLMKB-VERWMERKM'.
PERFORM bdc_field USING 'PLMKB-VERWMERKM'
wa_itab-verwmerkm.
PERFORM bdc_field USING 'PLMKB-QPMK_WERKS'
wa_itab-werks.
** PERFORM bdc_dynpro USING 'SAPLQPAA' '0160'.
** PERFORM bdc_field USING 'BDC_OKCODE'
** '=ENT1'.
** PERFORM bdc_field USING 'PLMKB-KURZTEXT'
** wa_itab-kurztext.
** PERFORM bdc_field USING 'BDC_CURSOR'
** 'QFLTP-TOLERANZOB'.
** PERFORM bdc_field USING 'QFLTP-SOLLWERT'
** wa_itab-sollwert.
** PERFORM bdc_field USING 'QFLTP-TOLERANZUN'
** wa_itab-toleranzun.
** PERFORM bdc_field USING 'QFLTP-TOLERANZOB'
** wa_itab-toleranzob.
PERFORM bdc_dynpro USING 'SAPLQSS0' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RQMST-TEXT1'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENT1'.
PERFORM bdc_field USING 'RQMST-TOLERUNTEN'
'X'.
PERFORM bdc_field USING 'RQMST-TOLEROBEN'
'X'.
PERFORM bdc_field USING 'RQMST-SOLLPRUEF'
'X'.
PERFORM bdc_field USING 'RQMST-STICHPR'
'X'.
PERFORM bdc_field USING 'RQMST-ESTUKZ5'
'X'.
PERFORM bdc_field USING 'RQMST-RZWANG4'
'X'.
PERFORM bdc_dynpro USING 'SAPLQSS0' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RQMST-TEXT1'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENT1'.
PERFORM bdc_field USING 'RQMST-DOKUKZ1'
'X'.
PERFORM bdc_field USING 'RQMST-PUMFKZ4'
'X'.
PERFORM bdc_field USING 'RQMST-MESSWERTE'
'X'.
PERFORM bdc_field USING 'RQMST-DRUCK1'
'X'.
PERFORM bdc_field USING 'RQMST-KEINEFORMEL'
'X'.
PERFORM bdc_dynpro USING 'SAPLQPAA' '0150'.
* PERFORM bdc_field USING 'BDC_CURSOR'
* 'RQPAS-QUANTITAT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=QMBU'.
PERFORM bdc_field USING 'RQPAS-ENTRY_ACT'
'1'.

PERFORM bdc_transaction.
ENDLOOP.
ENDFORM.

FORM displayalv .

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,


wa_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
it_keyinfo TYPE TABLE OF slis_keyinfo_alv WITH HEADER LINE.

* Create FieldCatalog for ALV


CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_LOGHEAD'
* i_inclname = sy-repid
i_bypassing_buffer = 'X'
CHANGING
ct_fieldcat = it_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 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.

wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-seltext_m = 'Material'.
wa_fieldcat-seltext_l = 'Material'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MSGTYPE'.
wa_fieldcat-seltext_m = 'Message Type'.
wa_fieldcat-seltext_l = 'Message Type'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MSGNO'.
wa_fieldcat-seltext_m = 'Message No'.
wa_fieldcat-seltext_l = 'Message No'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MSG'.
wa_fieldcat-seltext_m = 'Message'.
wa_fieldcat-seltext_l = 'Message'.
wa_fieldcat-outputlen = '100'.
APPEND wa_fieldcat TO it_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
is_layout = wa_layout
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = it_loghead
EXCEPTIONS
program_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.

ENDFORM. " DISPLAY_OUTPUT

* wa_itab-verwe.wa_itab-statu.wa_itab-losvn. wa_itab-steus.
* wa_itab-stichprver. wa_itab-quantitat.

*** PERFORM bdc_dynpro USING 'SAPLCPDI' '8010'.


*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'RC27M-MATNR'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=XALU'.
*** PERFORM bdc_field USING 'RC27M-MATNR'
**** 'GA0000002'.
*** wa_itab-matnr.
*** PERFORM bdc_field USING 'RC27M-WERKS'
**** '2000'.
*** wa_itab-werks.
*** PERFORM bdc_field USING 'RC271-STTAG'
**** '22.10.2022'.
*** wa_itab-sttag.
*** PERFORM bdc_dynpro USING 'SAPLCPDA' '1200'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '/00'.
*** PERFORM bdc_field USING 'PLKOD-PLNAL'
*** '1'.
****perform bdc_field using 'PLKOD-KTEXT'
**** 'V-belts'.
*** PERFORM bdc_field USING 'PLKOD-WERKS'
**** '2000'.
*** wa_itab-werks.
***
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLKOD-LOSVN'.
*** PERFORM bdc_field USING 'PLKOD-VERWE'
**** '5'.
*** wa_itab-verwe.
*** PERFORM bdc_field USING 'PLKOD-STATU'
**** '4'.
*** wa_itab-statu.
*** PERFORM bdc_field USING 'PLKOD-LOSVN'
**** '1'.
*** wa_itab-losvn.
****perform bdc_field using 'PLKOD-LOSBS'
**** '99,999,999'.
****perform bdc_field using 'PLKOD-PLNME'
**** 'EA'.
*** PERFORM bdc_dynpro USING 'SAPLCPDA' '1200'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=ALUE'.
****perform bdc_field using 'PLKOD-KTEXT'
**** 'V-belts'.
****perform bdc_field using 'PLKOD-WERKS'
**** '2000'.
**** PERFORM bdc_field USING 'BDC_CURSOR'
**** 'PLKOD-LOSVN'.
*** PERFORM bdc_field USING 'PLKOD-VERWE'
**** '5'.
*** wa_itab-verwe.
*** PERFORM bdc_field USING 'PLKOD-STATU'
**** '4'.
*** wa_itab-statu.
*** PERFORM bdc_field USING 'PLKOD-LOSVN'
**** '1'.
*** wa_itab-losvn.
****perform bdc_field using 'PLKOD-LOSBS'
**** '99,999,999'.
****perform bdc_field using 'PLKOD-PLNME'
**** 'EA'.
*** PERFORM bdc_dynpro USING 'SAPLCPDI' '1200'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'RC27X-ENTRY_ACT'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=VOUE'.
*** PERFORM bdc_field USING 'RC27X-ENTRY_ACT'
*** '1'.
*** PERFORM bdc_dynpro USING 'SAPLCPDI' '1400'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLPOD-VORNR(01)'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=QMUE'.
*** PERFORM bdc_field USING 'RC27X-FLG_SEL(01)'
*** 'X'.
*** PERFORM bdc_field USING 'PLPOD-STEUS(01)'
**** 'QM01'.
*** wa_itab-steus.

*** PERFORM bdc_dynpro USING 'SAPLQPAA' '0150'.


*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLMKB-STICHPRVER(01)'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '/00'.
*** PERFORM bdc_field USING 'PLMKB-VERWMERKM(01)'
**** 'MIC_01'.
*** wa_itab-verwmerkm.
*** PERFORM bdc_field USING 'PLMKB-KURZTEXT'
**** 'MIC_01'.
*** wa_itab-kurztext.
*** PERFORM bdc_field USING 'PLMKB-STICHPRVER(01)'
**** 'SP_FIXED'.
*** wa_itab-stichprver.
*** PERFORM bdc_field USING 'QFLTP-SOLLWERT(01)'
**** '17'.
*** wa_itab-sollwert.
*** PERFORM bdc_field USING 'QFLTP-TOLERANZUN(01)'
**** '16'.
*** wa_itab-toleranzun.
*** PERFORM bdc_field USING 'QFLTP-TOLERANZOB(01)'
**** '18'.
*** wa_itab-toleranzob.
*** PERFORM bdc_field USING 'RQPAS-QUANTITAT(01)'
**** 'X'.
*** wa_itab-quantitat.
*** PERFORM bdc_dynpro USING 'SAPLQPAA' '1501'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '/EE'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLMKB-VERWMERKM'.
*** PERFORM bdc_dynpro USING 'SAPLQSS0' '0100'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'RQMST-TEXT1'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=ENT1'.
*** PERFORM bdc_field USING 'RQMST-TOLERUNTEN'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-TOLEROBEN'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-SOLLPRUEF'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-STICHPR'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-ESTUKZ5'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-RZWANG4'
*** 'X'.
*** PERFORM bdc_dynpro USING 'SAPLQSS0' '0101'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'RQMST-TEXT1'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=ENT1'.
*** PERFORM bdc_field USING 'RQMST-DOKUKZ1'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-PUMFKZ4'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-MESSWERTE'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-DRUCK1'
*** 'X'.
*** PERFORM bdc_field USING 'RQMST-KEINEFORMEL'
*** 'X'.
*** PERFORM bdc_dynpro USING 'SAPLQPAA' '0160'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLMKB-KURZTEXT'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=ENT1'.
***
*** PERFORM bdc_dynpro USING 'SAPLQPAA' '0150'.
*** PERFORM bdc_field USING 'BDC_CURSOR'
*** 'PLMKB-STICHPRVER(01)'.
*** PERFORM bdc_field USING 'BDC_OKCODE'
*** '=QMBU'.
*** PERFORM bdc_field USING 'RQPAS-ENTRY_ACT'
*** '1'.

You might also like