Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Problem Statement: In standard MDG implementation for customer/ vendor it’s a common requirement to get the details of customer / vendor through the Change Request number. SAP has not provided any standard table which stores this relation nor there any method of class to serve the purpose described above.

Solution: A small report program is developed. It takes the CR number as input as shows the customer details linked to this CR number as output. This solution could be molded as per the real time requirement to fetch the Customer / Supplier number from CR number.

Code:

REPORT z_r_get_cust_from_cr.

*****************************************************************************************
*                                                                    
* System   : MDG 7.0                    
* Author     : Sachin 
* Title        :  Customer Details through CR number                                     &*
*--------------------------------------------------------------------------------------------------------------&*
* Description : Report to get the customer details from CR number as input
*--------------------------------------------------------------------------------------------------------------*

* Type declaration
TYPES: BEGIN OF lty_bp,
bp_header
TYPE  bu_businesspartner,
END OF lty_bp.

* Data declaration
DATA ls_usmd120c TYPE usmd120c.
DATA ls_kna1           TYPE kna1.

DATA lv_ktokd             TYPE ktokd.
DATA lv_bphdr             TYPE bu_businesspartner.
DATA lt_changelist_object TYPE if_usmd_cr_changelist=>gtt_changelist_object.
DATA lv_crequest          TYPE usmd_crequest.
DATA lv_kunnr             TYPE kunnr.
DATA lt_kna1              TYPE TABLE OF kna1.

DATA lo_data                 TYPE REF TO data.
DATA lo_cr_changelist        TYPE REF TO if_usmd_cr_changelist.
DATA lo_cr_changelist_object TYPE REF TO if_usmd_cr_changelist_object.
DATA lo_fsbp_object          TYPE REF TO fsbp_bo_cvi.
DATA lo_alv                  TYPE REF TO cl_salv_table.

FIELD-SYMBOLS <ls_key> TYPE any.

PARAMETERS p_cr_num          TYPE usmd_crequest OBLIGATORY.

* Start of selection
START-OF-SELECTION.

* Get all create and update change request with status Final Check Approved
SELECT SINGLE *
FROM usmd120c
INTO ls_usmd120c
WHERE usmd_crequest EQ p_cr_num.
IF sy-subrc IS NOT INITIAL.
* Display Error and Exit
WRITE'CR number is not correct' COLOR COL_NEGATIVE INTENSIFIED.
EXIT.
ENDIF.

* Get change list obj
lo_cr_changelist
= cl_usmd_cr_changelist=>get_instance(
iv_crequest_id
= ls_usmd120c-usmd_crequest
iv_model
= 'BP' ).

CLEAR lt_changelist_object.
lo_cr_changelist
->get_changelist_objects(
IMPORTING
et_changelist_object
= lt_changelist_object ).

* Create data reference
CREATE DATA lo_data TYPE lty_bp.
ASSIGN lo_data->* TO <ls_key>.

* Get business partner
LOOP AT lt_changelist_object INTO lo_cr_changelist_object.
IF lo_cr_changelist_object->get_object_entity_type( ) EQ 'BP_HEADER'.
lo_cr_changelist_object
->get_object_entity_key(
IMPORTING
es_entity_key     
=   <ls_key>  " Business Partner ID
).
ENDIF.
ENDLOOP.

* Get the customer number
IF <ls_key> IS ASSIGNED.
lv_bphdr
= <ls_key>.
ENDIF.

lo_fsbp_object ?= fsbp_business_factory
=>get_instance( i_partner  = lv_bphdr ).
IF lo_fsbp_object IS BOUND.
CLEAR lv_kunnr.
lv_kunnr
= lo_fsbp_object->customer->get_customer( ).
IF lv_kunnr IS NOT INITIAL.
SELECT SINGLE *
INTO ls_kna1
FROM kna1
WHERE kunnr EQ lv_kunnr.
IF sy-subrc IS NOT INITIAL.
* Display Error and Exit
WRITE'No Customer exists, CR might not be in final check approved state' COLOR COL_NEGATIVE INTENSIFIED.
EXIT.
ENDIF.
ELSE.
* Display Error and Exit
WRITE'No Customer exists, CR might not be in final check approved state' COLOR COL_NEGATIVE INTENSIFIED.
EXIT.
ENDIF.
ENDIF.

APPEND ls_kna1 TO lt_kna1.


* Display table
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table
= lo_alv
CHANGING
t_table     
= lt_kna1.

lo_alv
->get_functions( )->set_all(
value = if_salv_c_bool_sap=>true
).

lo_alv
->display( ).

3 Comments
Labels in this area