Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Upload inspection setup using BAPI

Former Member
0 Likes
5,907

Hi Expert,


kindly need your help,


I have done created/ extended QM view and now i want to upload for inspection setup. I already search through SAP forums and follow the suggestions but it's still failed to upload the inspection setup.


Below is a part of code that i used to upload the inspection setup in QM view,


LOOP AT gt_upload_file INTO gw_upload_file.

     CLEAR: gw_qmat.

     bapimathead-material = gw_upload_file-col1.

     bapimathead-quality_view = 'X'.

     bapimathead-inp_fld_check = 'W'. " added by nliyanah

     bapi_marc-plant         = gw_upload_file-col2.

     bapi_marcx-plant        = gw_upload_file-col2.

     " 1. Material Code

     gw_qmat-material  = gw_upload_file-col1.

     " 2. Plant

     gw_qmat-plant     = gw_upload_file-col2.

     " 3. Inspection Type

     gw_qmat-insptype  = gw_upload_file-col3.

     " 4. Active

     gw_qmat-ind_insptype_mat_active   = gw_upload_file-col4.

     " 5. HU

     gw_qmat-ind_hu_inspection = gw_upload_file-col5.

     "6.  Function

     gw_qmat-function = '009'.

     APPEND gw_qmat TO gt_qmat.

   ENDLOOP.

   CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'

     TABLES

       return         = lt_return

       inspectionctrl = gt_qmat.

   READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

   IF sy-subrc <> 0.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .

     IF sy-subrc = '0'.

       MESSAGE I016(ZMAT).

     ELSE.

       gv_error = 1.

       MESSAGE I008(ZMAT).

       EXIT.

     ENDIF.

   ELSE.

     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

     IF sy-subrc <> 0.

       MESSAGE I009(ZMAT).

     ENDIF.

     gv_error = 1.

     MESSAGE I015(ZMAT).

     EXIT.

   ENDIF.


Please advise,

Liyana

1 ACCEPTED SOLUTION
Read only

former_member196331
Active Contributor
0 Likes
4,458

Hi,

You can use below code. it will be work, Just now i checked in my development system, It is working.

If you don't mind small suggestions.

1)Choose one material code then add it manually. If u add inspection type successfully. then again go to mm02  delete that inspection type . then use the below code and add the inspection type  For that material Code only,then only you know whether bapi is having the problem or particular material is having the problem.

**Test

DATA:

   WS_RETURN        LIKE                " To store status

     BAPIRET2 OCCURS 0 WITH HEADER LINE.

*INTERNAL TABLE TO STORE INSPECTION DETAILS TO PASS

*AS PARAMETER TO BAPI

DATA:

   BEGIN OF WS_QMAT OCCURS 0.

         INCLUDE STRUCTURE  BAPI1001004_QMAT.

DATA:

   END OF WS_QMAT.

DATA:

WS_INSP(2).

*

*RETRIEVING QUALITY SCORE PROCEDURE FROM TQ34 TABLE

SELECT SINGLE QKZVERF

    FROM TQ34

    INTO WS_INSP

   WHERE ART = 'Z1'.

WS_QMAT-INSPTYPE = 'A1'. "Your Inspection type

WS_QMAT-MATERIAL = 'abcd'. "Your material code.

WS_QMAT-PLANT = '1000'.

WS_QMAT-IND_INSPTYPE_MAT_ACTIVE = 'X'.

WS_QMAT-QUAL_SCORE_PROCEDURE = WS_INSP.

WS_QMAT-PREFERRED_INSPTYPE = 'X'.

APPEND WS_QMAT.

CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'

   TABLES

     RETURN         = WS_RETURN

     INSPECTIONCTRL = WS_QMAT.

IF SY-SUBRC NE 0.

*  NO SY-SUBRC CHECK IS REQUIRED

     ENDIF.                               " IF SY-SUBRC NE 0

   IF WS_RETURN-TYPE EQ 'S' OR

      WS_RETURN-TYPE EQ 'I' OR

      WS_RETURN-TYPE EQ 'W'.

*    TO COMMIT THE TRANSATION FOR SUCCESFULL RECORDS

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

           EXPORTING

             WAIT = 'X'.

   ENDIF.

14 REPLIES 14
Read only

former_member196331
Active Contributor
0 Likes
4,458

Hi,

Small suggestion, If  u need urgently u can also try.. Bdc also it will work,

I had recently this type of requirement. I complete the task.

U may try Qa08  also. This is Standard T-Code at a time mass materials u may assigned Inspection type By Material type wise.

Read only

0 Likes
4,458

You may try below post also.

Read only

0 Likes
4,458

If I may ask: why did you go for BDC instead of using the BAPI?

cheers

Paul

Read only

0 Likes
4,458

HI, Because that type of provision is possible in sap.

Read only

0 Likes
4,458

Hi,

  I assume you didn't just choose BDC because it's 'possible'?

  I'm curious to know why you preferred this approach to using a BAPI, which is the official, supported, published, SAP interface?

cheers

Paul

Read only

0 Likes
4,458

Hi,

The answer is, I never used before. Bdc i have some knowledge.

Actually once got the requirement i never searched whether bapi is exists or not.

I choose bdc because previously i did on bdc. this is the reason. But next time on words i will choose bapi next bdc. I know bdc it is having it's own drawbacks.

Read only

0 Likes
4,458

NewB,

I'm very pleased to hear that - good on you for moving out of your comfort zone!

BDCs are actually very old school... you would be fired by most clients if you implemented one

cheers

Paul

Read only

paul_bakker2
Active Contributor
0 Likes
4,458

Hi,

Is there an error message in the RETURN table?

Did you try debugging the BAPI?

cheers

Paul

Read only

0 Likes
4,458

Yes, there got an error 'The quality score procedure  does not exist for inspection type 03' in my RETURN  table. is my code got missing any of necessary part?

Read only

0 Likes
4,458

Hi, Can u do a small thing , For which material u r getting , Just do the same thing as manual.

Then u can able to understood. Whether it is Standard Error or Whether Bapi is Giving the Error.

Read only

former_member196331
Active Contributor
0 Likes
4,459

Hi,

You can use below code. it will be work, Just now i checked in my development system, It is working.

If you don't mind small suggestions.

1)Choose one material code then add it manually. If u add inspection type successfully. then again go to mm02  delete that inspection type . then use the below code and add the inspection type  For that material Code only,then only you know whether bapi is having the problem or particular material is having the problem.

**Test

DATA:

   WS_RETURN        LIKE                " To store status

     BAPIRET2 OCCURS 0 WITH HEADER LINE.

*INTERNAL TABLE TO STORE INSPECTION DETAILS TO PASS

*AS PARAMETER TO BAPI

DATA:

   BEGIN OF WS_QMAT OCCURS 0.

         INCLUDE STRUCTURE  BAPI1001004_QMAT.

DATA:

   END OF WS_QMAT.

DATA:

WS_INSP(2).

*

*RETRIEVING QUALITY SCORE PROCEDURE FROM TQ34 TABLE

SELECT SINGLE QKZVERF

    FROM TQ34

    INTO WS_INSP

   WHERE ART = 'Z1'.

WS_QMAT-INSPTYPE = 'A1'. "Your Inspection type

WS_QMAT-MATERIAL = 'abcd'. "Your material code.

WS_QMAT-PLANT = '1000'.

WS_QMAT-IND_INSPTYPE_MAT_ACTIVE = 'X'.

WS_QMAT-QUAL_SCORE_PROCEDURE = WS_INSP.

WS_QMAT-PREFERRED_INSPTYPE = 'X'.

APPEND WS_QMAT.

CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'

   TABLES

     RETURN         = WS_RETURN

     INSPECTIONCTRL = WS_QMAT.

IF SY-SUBRC NE 0.

*  NO SY-SUBRC CHECK IS REQUIRED

     ENDIF.                               " IF SY-SUBRC NE 0

   IF WS_RETURN-TYPE EQ 'S' OR

      WS_RETURN-TYPE EQ 'I' OR

      WS_RETURN-TYPE EQ 'W'.

*    TO COMMIT THE TRANSATION FOR SUCCESFULL RECORDS

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

           EXPORTING

             WAIT = 'X'.

   ENDIF.

Read only

0 Likes
4,458

Big thanks, your suggestion was very helpful, The program work fine.

Regards,

Liyana

Read only

0 Likes
4,458

It's My Pleasure to help other.

Read only

0 Likes
4,458

Looks like using a BAPI was the right suggestion.