Application Development 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: 

how to get material component data when click 'SAVE' in CJ20N?

0 Kudos
556

Hi, everyone:

I will do an enhancement when 'SAVE' in CJ20N, and have found the palce to enhancement (FCODE_SAVE(SAPLCNPB_M)).

But how can I get material component data there?

Thanks in advance!

1 ACCEPTED SOLUTION

former_member192023
Active Participant
0 Kudos
138

Hi,

Just for you information. LCNPB_MF55->fcode_save

It works good for me ^*^

  DATA: lwa_changes              TYPE cnpb_h_changes.

  DATA lwa_proj TYPE proj.

  DATA lt_data TYPE STANDARD TABLE OF caufvdget WITH HEADER LINE.

  DATA lwa_zpst00010_config TYPE zpst00010_config.

  DATA lv_str TYPE string.

  DATA lv_project TYPE afko-pronr.

  DATA lt_zpst00010 TYPE STANDARD TABLE OF zpst00010.

  DATA gt_msg TYPE STANDARD TABLE OF bapiret2.

  DATA wa_msg TYPE bapiret2.

  DATA lt_resbd LIKE TABLE OF resbd WITH HEADER LINE.

  break d00156.

  CLEAR lwa_zpst00010_config.

  SELECT SINGLE *

    FROM zpst00010_config

    INTO lwa_zpst00010_config

    WHERE zobject = 'ZPST00010'.

  IF lwa_zpst00010_config-zon_off = '1'

    AND sy-tcode = 'CJ20N'

    AND SY-UCOMM = 'SAVE'.

* check if data were changed

    PERFORM data_check_changes IN PROGRAM SAPLCNPB_M CHANGING lwa_changes.

    IF NOT lwa_changes-network IS INITIAL.

      CALL FUNCTION 'CO_BH_GET_ORDERS'

        EXPORTING

          no_dialog_info = 'X'

        TABLES

          caufvd_get     = lt_data[].

      DATA LV_ERR TYPE C LENGTH 1.

      LOOP AT lt_data.

        SELECT SINGLE pronr

        FROM afko

        INTO lv_project

        WHERE aufnr = lt_data-aufnr.

        IF sy-subrc = 0.

          SELECT SINGLE *

            FROM proj

            INTO lwa_proj

           WHERE pspnr = lv_project.

          IF sy-subrc = 0.

            CLEAR lt_zpst00010[].

            SELECT *

              FROM zpst00010

              INTO TABLE lt_zpst00010

             WHERE syb_code = lwa_proj-astnr

              AND  fzr_code = lwa_proj-vernr

              AND  change_id = sy-uname. 

            IF sy-subrc <> 0.

              MESSAGE i001(zps) WITH  lwa_proj-astnr lwa_proj-vernr INTO LV_STR.

              WA_MSG-TYPE = 'E'.

              WA_MSG-ID = 'ZPS'.

              WA_MSG-NUMBER = '001'.

              MESSAGE E001(zps) WITH LWA_PROJ-astnr  LWA_PROJ-vernr  INTO WA_MSG-MESSAGE ."= 'MESSAGE'.

              WA_MSG-LOG_NO = ''.

              WA_MSG-LOG_MSG_NO = ''.

              WA_MSG-MESSAGE_V1 = LWA_PROJ-astnr.

              WA_MSG-MESSAGE_V2 =  LWA_PROJ-vernr.

              WA_MSG-ROW = '1'.

              WA_MSG-FIELD = ''.

              WA_MSG-SYSTEM = ''.

              CLEAR GT_MSG.

              APPEND WA_MSG TO GT_MSG.

              e_subrc = '1'.

              LV_ERR = 'X'.

              CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                EXPORTING

                  it_message       = GT_MSG.

              EXIT.

            ENDIF.

          ENDIF.

        ENDIF.

      ENDLOOP.

             IF NOT lwa_proj IS INITIAL.

              IMPORT p1 = lt_resbd FROM MEMORY ID 'ZXCN2U13'.

              LOOP AT lt_resbd.

                IF lwa_proj-astnr <> '00000010' AND lt_resbd-zwlxqsqr IS INITIAL OR lt_resbd-zwlyt IS INITIAL.

                  MESSAGE E002(ZPS).

                  wa_msg-type = 'E'.

                  wa_msg-id = 'ZPS'.

                  wa_msg-number = '002'.

                  wa_msg-row = '1'.

                  APPEND wa_msg TO gt_msg.

                  CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                    EXPORTING

                      it_message       = gt_msg.

                  LV_ERR = 'X'.

                  EXIT.

                ENDIF.

                IF lt_resbd-bdter <= lt_resbd-creadat.

                  MESSAGE E003(ZPS).

                  wa_msg-type = 'E'.

                  wa_msg-id = 'ZPS'.

                  wa_msg-number = '003'.

                  wa_msg-row = '1'.

                  APPEND wa_msg TO gt_msg.

                  CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                    EXPORTING

                      it_message       = gt_msg.

                  LV_ERR = 'X'.

                  EXIT.

                ENDIF.

              ENDLOOP.

            ENDIF.

            "}

      IF NOT LV_ERR IS INITIAL.

        EXIT.

      ELSE.

        FREE MEMORY ID 'ZXCN2U13'.

      ENDIF.

    ENDIF.

  ENDIF.

3 REPLIES 3

suresh_kutam
Participant
0 Kudos
138

Hello,

Implement one of the below BADI - which will trigger during SAVE, Here you will all the details of the project.

You need to check which is suitable for your requirement.

WORKBREAKDOWN_UPDATE

WBS_FIELDS_FOR_ASSET

Thanks,

SK

former_member192023
Active Participant
0 Kudos
139

Hi,

Just for you information. LCNPB_MF55->fcode_save

It works good for me ^*^

  DATA: lwa_changes              TYPE cnpb_h_changes.

  DATA lwa_proj TYPE proj.

  DATA lt_data TYPE STANDARD TABLE OF caufvdget WITH HEADER LINE.

  DATA lwa_zpst00010_config TYPE zpst00010_config.

  DATA lv_str TYPE string.

  DATA lv_project TYPE afko-pronr.

  DATA lt_zpst00010 TYPE STANDARD TABLE OF zpst00010.

  DATA gt_msg TYPE STANDARD TABLE OF bapiret2.

  DATA wa_msg TYPE bapiret2.

  DATA lt_resbd LIKE TABLE OF resbd WITH HEADER LINE.

  break d00156.

  CLEAR lwa_zpst00010_config.

  SELECT SINGLE *

    FROM zpst00010_config

    INTO lwa_zpst00010_config

    WHERE zobject = 'ZPST00010'.

  IF lwa_zpst00010_config-zon_off = '1'

    AND sy-tcode = 'CJ20N'

    AND SY-UCOMM = 'SAVE'.

* check if data were changed

    PERFORM data_check_changes IN PROGRAM SAPLCNPB_M CHANGING lwa_changes.

    IF NOT lwa_changes-network IS INITIAL.

      CALL FUNCTION 'CO_BH_GET_ORDERS'

        EXPORTING

          no_dialog_info = 'X'

        TABLES

          caufvd_get     = lt_data[].

      DATA LV_ERR TYPE C LENGTH 1.

      LOOP AT lt_data.

        SELECT SINGLE pronr

        FROM afko

        INTO lv_project

        WHERE aufnr = lt_data-aufnr.

        IF sy-subrc = 0.

          SELECT SINGLE *

            FROM proj

            INTO lwa_proj

           WHERE pspnr = lv_project.

          IF sy-subrc = 0.

            CLEAR lt_zpst00010[].

            SELECT *

              FROM zpst00010

              INTO TABLE lt_zpst00010

             WHERE syb_code = lwa_proj-astnr

              AND  fzr_code = lwa_proj-vernr

              AND  change_id = sy-uname. 

            IF sy-subrc <> 0.

              MESSAGE i001(zps) WITH  lwa_proj-astnr lwa_proj-vernr INTO LV_STR.

              WA_MSG-TYPE = 'E'.

              WA_MSG-ID = 'ZPS'.

              WA_MSG-NUMBER = '001'.

              MESSAGE E001(zps) WITH LWA_PROJ-astnr  LWA_PROJ-vernr  INTO WA_MSG-MESSAGE ."= 'MESSAGE'.

              WA_MSG-LOG_NO = ''.

              WA_MSG-LOG_MSG_NO = ''.

              WA_MSG-MESSAGE_V1 = LWA_PROJ-astnr.

              WA_MSG-MESSAGE_V2 =  LWA_PROJ-vernr.

              WA_MSG-ROW = '1'.

              WA_MSG-FIELD = ''.

              WA_MSG-SYSTEM = ''.

              CLEAR GT_MSG.

              APPEND WA_MSG TO GT_MSG.

              e_subrc = '1'.

              LV_ERR = 'X'.

              CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                EXPORTING

                  it_message       = GT_MSG.

              EXIT.

            ENDIF.

          ENDIF.

        ENDIF.

      ENDLOOP.

             IF NOT lwa_proj IS INITIAL.

              IMPORT p1 = lt_resbd FROM MEMORY ID 'ZXCN2U13'.

              LOOP AT lt_resbd.

                IF lwa_proj-astnr <> '00000010' AND lt_resbd-zwlxqsqr IS INITIAL OR lt_resbd-zwlyt IS INITIAL.

                  MESSAGE E002(ZPS).

                  wa_msg-type = 'E'.

                  wa_msg-id = 'ZPS'.

                  wa_msg-number = '002'.

                  wa_msg-row = '1'.

                  APPEND wa_msg TO gt_msg.

                  CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                    EXPORTING

                      it_message       = gt_msg.

                  LV_ERR = 'X'.

                  EXIT.

                ENDIF.

                IF lt_resbd-bdter <= lt_resbd-creadat.

                  MESSAGE E003(ZPS).

                  wa_msg-type = 'E'.

                  wa_msg-id = 'ZPS'.

                  wa_msg-number = '003'.

                  wa_msg-row = '1'.

                  APPEND wa_msg TO gt_msg.

                  CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'

                    EXPORTING

                      it_message       = gt_msg.

                  LV_ERR = 'X'.

                  EXIT.

                ENDIF.

              ENDLOOP.

            ENDIF.

            "}

      IF NOT LV_ERR IS INITIAL.

        EXIT.

      ELSE.

        FREE MEMORY ID 'ZXCN2U13'.

      ENDIF.

    ENDIF.

  ENDIF.

0 Kudos
138

Hi, Feiyun Wu,

    Is there a Function Module to read the buffer, like FM: CO_BH_GET_ORDERS in your codes?

    I think there is a buffer also exist for material component.

Thanks.