*&———————————————————————*
*& Name          : Premanand Shelke
*& Emp ID       : 129210
*& Description : Sales Order Report by adding necessary header level
*&               data and at least one item have quantity 3 or more.
*&———————————————————————

*&———————————————————————*
REPORT  ZCRM_SO_ALL_210 NO STANDARD PAGE HEADING.
*———————————————————————-*
* Internal tables and work areas declaration
*———————————————————————-*

DATA: I_ORDERADM_H TYPE CRMT_ORDERADM_H_COMT,
      WA_ORDERADM_H TYPE CRMT_ORDERADM_H_COM,

      IT_ORDERADM_u TYPE CRMT_ORDERADM_I_COMT,
      WA_ORDERADM_I TYPE CRMT_ORDERADM_I_COM,

      I_PARTNER TYPE CRMT_PARTNER_COMT,
      WA_PARTNER TYPE CRMT_PARTNER_COM,


      I_ORGMAN TYPE CRMT_ORGMAN_COMT,
      WA_ORGMAN TYPE CRMT_ORGMAN_COM,

      IT_SALES TYPE CRMT_SALES_COMT,
      WA_SALES TYPE CRMT_SALES_COM,

      IT_PRICING TYPE CRMT_PRICING_COMT,
      WA_PRICING TYPE CRMT_PRICING_COM,

      IT_SHIPPING TYPE CRMT_SHIPPING_COMT,
      WA_SHIPPING TYPE CRMT_SHIPPING_COM,

      I_PRODUCT TYPE CRMT_PRODUCT_I_COMT,
      WA_PRODUCT TYPE CRMT_PRODUCT_I_COM,

      IT_SCHEDLIN_U TYPE CRMT_SCHEDLIN_I_COMT,
      WA_SCHEDLIN_I TYPE CRMT_SCHEDLIN_I_COM,

      I_SCHEDLIN TYPE CRMT_SCHEDLIN_EXTDT,
      WA_SCHEDLIN TYPE CRMT_SCHEDLIN_EXTD,

      WA_INPUT_FIELDS TYPE CRMT_INPUT_FIELD,
      I_INPUT_FIELDS TYPE CRMT_INPUT_FIELD_TAB,

      I_FIELD_NAMES TYPE CRMT_INPUT_FIELD_NAMES_TAB,
      WA_FIELD_NAMES TYPE CRMT_INPUT_FIELD_NAMES,

      I_OBJECT_SAVE TYPE TABLE OF BAPIBUS20001_GUID_DIS,
      WA_OBJECT_SAVE TYPE BAPIBUS20001_GUID_DIS,

      I_SAVED_OBJECTS TYPE TABLE OF BAPIBUS20001_OBJECT_ID,
      WA_SAVED_OBJECTS TYPE BAPIBUS20001_OBJECT_ID,

      IT_BAPIRET TYPE TABLE OF BAPIRET2.

*Variable Declaration
DATA: GV_GUID TYPE GUID_16,
            GV_GUID_PROD TYPE guid_16,
            GV_GUID1 TYPE GUID_16.

*Constant Declaration
DATA: C_HANDLE(10) TYPE N VALUE ‘0000000001’,
      C_HANDLE1(10) TYPE N VALUE ‘0000000000’,
      C_PART_HANDLE1(4) TYPE N VALUE ‘0001’,
      C_PART_HANDLE2(4) TYPE N VALUE ‘0002’,
      C_KIND_OF_ENTRY(1) TYPE C VALUE ‘C’,
      C_B(1) TYPE C VALUE ‘B’,

      C_PART_FCT1(8) TYPE N VALUE ‘00000001’,
      C_PART_FCT2(8) TYPE N VALUE ‘00000002’,
      C_PART_NO(32) TYPE C VALUE ‘SA-2509’,
      C_DISP_TYPE(2) TYPE C VALUE ‘BP’,
      C_NO_TYPE(2) TYPE C VALUE ‘BP’,

      C_DISP(20) TYPE C VALUE ‘DISPLAY_TYPE’,
      C_KIND(20) TYPE C VALUE ‘KIND_OF_ENTRY’,
      C_NOTYPE(10) TYPE C VALUE ‘NO_TYPE’,
      C_PARTFCT(15) TYPE C VALUE ‘PARTNER_FCT’,
      C_PARTNO(10) TYPE C VALUE ‘PARTNER_NO’,

      C_MODE(4) TYPE C VALUE ‘MODE’,
      C_PTYPE(20) TYPE C VALUE ‘PROCESSTYPE’,
      C_TA(4) TYPE C VALUE ‘TA’,
      C_A(1) TYPE C VALUE ‘A’,
      C_PARTNER(10) TYPE C VALUE ‘PARTNER’,
      C_ORDERADM_H TYPE CRMT_OBJECT_NAME VALUE ‘ORDERADM_H’,

      C_WINE(4) TYPE C VALUE ‘WINE’,
      C_DESC(40) TYPE C VALUE ‘RED WINE’,
      C_E(2) TYPE C VALUE ‘EN’,
      C_TAN(4) TYPE C VALUE ‘TAN’,

      C_ORDERED_PROD(20) TYPE C VALUE ‘ORDERED_PRODUCT’,
      C_ORDERADM_I TYPE CRMT_OBJECT_NAME VALUE ‘ORDERADM_I’,
      C_SCHEDLIN_I TYPE CRMT_OBJECT_NAME VALUE ‘SCHEDLIN_I’.

*———————————————————————-*
*Start of Selection.
*———————————————————————*
START-OF-SELECTION.

*Calling subroutine to create GUID.
  PERFORM F_CREATE_GUID.

*Calling subroutine to create GUID.
  PERFORM F_CREATE_GUID1.

*Assigning values to variables.
  GV_GUID_PROD = ‘7B160839EF59C249’.

*Calling subroutine to fill values for the table CRMD_ORDERADM_H.
  PERFORM F_CREATE_ORDERADMH USING C_HANDLE GV_GUID C_TA C_A.

*Calling subroutine to fill values for the table I_PARTNER.
  PERFORM F_CREATE_PARTNER USING:
                    GV_GUID C_HANDLE1 C_A C_PART_HANDLE1
C_KIND_OF_ENTRY C_PART_FCT1 C_PART_NO C_DISP_TYPE C_NO_TYPE.

*Calling subroutine to fill values for the table I_ORGMAN.
  PERFORM F_CREATE_ORGMAN.

*Calling subroutine to fill values for the table CRMD_ORDERADM_I.
  PERFORM F_CREATE_ORDERADM_I.

*Calling subroutine to fill values for the table SCHEDLIN_I.
  PERFORM F_CREATE_SCHEDLIN_I USING C_HANDLE1.

*Calling subroutine to call function module CRM_ORDER_MAINTAIN.
  PERFORM F_CRM_ORDER_MAINTAIN.

*Calling function module to save order.
  PERFORM F_ORDER_SAVE.

*&———————————————————————*
*&      Form  F_CREATE_ORDERADMH
*&———————————————————————*
*      This subroutine is used to fill values in the internal table
*      of ORDERADM_H.
*———————————————————————-*
FORM F_CREATE_ORDERADMH  USING    VALUE(P_HANDLE) TYPE N
                                  VALUE(P_GUID) TYPE GUID_16
                                  VALUE(P_PTYPE) TYPE C
                                  VALUE(P_MODE) TYPE C.

*Passing values of the parameters in the work area of internal tabel
*I_ORDERADM_H.
  WA_ORDERADM_HHANDLE = P_HANDLE.
  WA_ORDERADM_HGUID = P_GUID.
  WA_ORDERADM_HPROCESS_TYPE = P_PTYPE.
  WA_ORDERADM_HMODE = P_MODE.

*Inserting values from work area to internal table.
  INSERT WA_ORDERADM_H INTO TABLE I_ORDERADM_H.
  CLEAR WA_ORDERADM_H.

*Calling Subroutine to fill the field names.
  PERFORM F_FIELD_NAMES USING:
                              C_MODE ,
                              C_PTYPE C_B.

*Calling Subroutine to fill Input fields table.
  PERFORM F_INPUT_FIELDS USING C_HANDLE GV_GUID C_B C_ORDERADM_H .
ENDFORM.                    ” F_CREATE_ORDERADMH

*&———————————————————————*
*&      Form  F_CRM_ORDER_MAINTAIN
*&——————————————————————–*
*       This subroutine is used to call function module to create
*       standard order.
*———————————————————————-*
FORM F_CRM_ORDER_MAINTAIN .
*Calling Function module to create standard order.
  CALL FUNCTION ‘CRM_ORDER_MAINTAIN’
   EXPORTING
*     IT_OPPORT_H                   =
*     IT_LEAD_H                     =
*     IT_ACTIVITY_H                 =
*     IT_SALES                      = IT_SALES
*     IT_PRICING                    = IT_PRICING
*     IT_PRICING_I                  =
*     IT_PRIDOC                     =
     IT_ORGMAN                      = I_ORGMAN
*     IT_SHIPPING                   = IT_SHIPPING
**     IT_ACTIVITY_I                 =
*     IT_PRODUCT_I                  = I_PRODUCT

     IT_SCHEDLIN_I                  = IT_SCHEDLIN_U

     IT_PARTNER                     = I_PARTNER

   CHANGING
     CT_ORDERADM_H                  = I_ORDERADM_H
     CT_ORDERADM_I                 IT_ORDERADM_u
     CT_INPUT_FIELDS                = I_INPUT_FIELDS


   EXCEPTIONS
     ERROR_OCCURRED                = 1
     DOCUMENT_LOCKED               = 2
     NO_CHANGE_ALLOWED             = 3
     NO_AUTHORITY                  = 4
     OTHERS                        = 5

*If function module is not called successfully.
  IF SYSUBRC <> 0.
*Display message that order cannot be created successsfully.
    MESSAGE ‘Sales Order Is Not Created’ TYPE ‘E’.
  ENDIF.
ENDFORM.                    ” F_CRM_ORDER_MAINTAIN

*&———————————————————————*
*&      Form  F_FIELD_NAMES
*&———————————————————————*
*       text
*———————————————————————*
*      –>P_FIELD_NAME   text
*      –>P_CHANGEABLE   text
*———————————————————————-*
FORM F_FIELD_NAMES  USING    VALUE(P_FIELD_NAME) TYPE C
                             VALUE(P_CHANGEABLE) TYPE C.

*Passing values in the work area of internal tabel I_FIELD_NAMES1.
  WA_FIELD_NAMESFIELDNAME = P_FIELD_NAME.
  WA_FIELD_NAMESCHANGEABLE = P_CHANGEABLE.

*Inserting values from work area to internal table.
  INSERT WA_FIELD_NAMES INTO TABLE I_FIELD_NAMES.
  CLEAR WA_FIELD_NAMES.
ENDFORM.                    ” F_FIELD_NAMES

*&———————————————————————*
*&      Form  F_INPUT_FIELDS
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_HANDLE   text
*      –>P_GUID   text
*      –>P_KIND   text
*      –>P_OBJECTNAME   text
*      –>P_LOGICAL_KEY   text
*———————————————————————-*
FORM F_INPUT_FIELDS  USING    VALUE(P_HANDLE)
                              VALUE(P_GUID)
                              VALUE(P_KIND)
                              VALUE(P_OBJECTNAME)
                              VALUE(P_LOGICAL_KEY) .

*Passing values in the work area of INPUT_FIELDS1.
  WA_INPUT_FIELDSREF_HANDLE = P_HANDLE.
  WA_INPUT_FIELDSREF_GUID = P_GUID.
  WA_INPUT_FIELDSREF_KIND = P_KIND.
  WA_INPUT_FIELDSOBJECTNAME = P_OBJECTNAME.
  WA_INPUT_FIELDSLOGICAL_KEY = P_LOGICAL_KEY.

*Passing Field names in the work area of INPUT_FIELDS1.
  WA_INPUT_FIELDSFIELD_NAMES = I_FIELD_NAMES.

*Inserting values from work area to internal table.
  INSERT WA_INPUT_FIELDS INTO TABLE I_INPUT_FIELDS.
  CLEAR WA_INPUT_FIELDS.
*    ENDLOOP.
*  ENDIF.
ENDFORM.                    ” F_INPUT_FIELDS

*&———————————————————————*
*&      Form  F_CREATE_PARTNER
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_REF_GUID   text
*      –>P_HANDLE   text
*      –>P_REF_KIND   text
*      –>P_PART_HANDLE   text
*      –>P_KIND_OF_ENTRY   text
*      –>P_PART_FCT   text
*      –>P_PART_NO   text
*      –>P_DISP_TYPE   text
*      –>P_NO_TYPE   text
*———————————————————————*
FORM F_CREATE_PARTNER  USING    VALUE(P_GUID) TYPE GUID_16
                                VALUE(P_HANDLE) TYPE N
                                VALUE(P_REF_KIND) TYPE C
                                VALUE(P_PART_HANDLE) TYPE N
                                VALUE(P_KIND_OF_ENTRY) TYPE C
                                VALUE(P_PART_FCT) TYPE N
                                VALUE(P_PART_NO) TYPE C
                                VALUE(P_DISP_TYPE) TYPE C
                                VALUE(P_NO_TYPE) TYPE C.

*Passing values of the parameters in the work area of internal tabel
*IT_PARTNER1.
  WA_PARTNERREF_GUID = P_GUID.
  WA_PARTNERREF_HANDLE = P_HANDLE.
  WA_PARTNERREF_KIND = P_REF_KIND.
  WA_PARTNERREF_PARTNER_HANDLE = P_PART_HANDLE.
  WA_PARTNERKIND_OF_ENTRY = P_KIND_OF_ENTRY.
  WA_PARTNERPARTNER_FCT = P_PART_FCT.
  WA_PARTNERPARTNER_NO = P_PART_NO.
  WA_PARTNERDISPLAY_TYPE = P_DISP_TYPE.
  WA_PARTNERNO_TYPE = P_NO_TYPE.

*Inserting values from work area to internal table.
  INSERT WA_PARTNER INTO TABLE I_PARTNER.
  CLEAR WA_PARTNER.
  CLEAR I_FIELD_NAMES.

*Calling Subroutine to fill the field names.
  PERFORM F_FIELD_NAMES USING:
                              C_DISP ,
                             C_KIND ,
                             C_NOTYPE ,
                              C_PARTFCT ,
                              C_PARTNO .
*Calling Subroutine to fill Input fields table.
  PERFORM F_INPUT_FIELDS USING:
                            C_HANDLE1 GV_GUID C_A C_PARTNER
C_PART_HANDLE1.
ENDFORM.                    ” F_CREATE_PARTNER

*&———————————————————————*
*&      Form  F_ORDER_SAVE
*&———————————————————————*
*       text
*———————————————————————*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM F_ORDER_SAVE .

*Passing value of GUID to work area of internal table I_OBJECT_SAVE.
  WA_OBJECT_SAVEGUID = GV_GUID.

* Inserting value from work area to internal table.
  INSERT WA_OBJECT_SAVE INTO TABLE I_OBJECT_SAVE.
  CLEAR WA_OBJECT_SAVE.

*Calling Function module to save standard order.
  CALL FUNCTION ‘BAPI_BUSPROCESSND_SAVE’
    TABLES
      OBJECTS_TO_SAVE = I_OBJECT_SAVE
      SAVED_OBJECTS   = I_SAVED_OBJECTS
      RETURN          = IT_BAPIRET.

  IF IT_BAPIRET[] IS INITIAL.
*    MESSAGE ‘Sales Order Is Not Created’ TYPE ‘E’.
    IF NOT I_SAVED_OBJECTS[] IS INITIAL.
      LOOP AT I_SAVED_OBJECTS INTO WA_SAVED_OBJECTS.
        WRITE: /1 ‘Transaction number’,
               20 WA_SAVED_OBJECTSOBJECT_ID,
               30 ‘Is Saved’.
      ENDLOOP.
    ENDIF.
  ENDIF.
  CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
ENDFORM.                    ” F_ORDER_SAVE

*&———————————————————————*
*&      Form  F_CREATE_SALES
*&———————————————————————*
*       text
*———————————————————————*
*      –>P_HANDLE1   text
*      –>P_KIND_B   text
*———————————————————————-*

FORM F_CREATE_SALES  USING    VALUE(P_HANDLE1)
                               VALUE(P_KIND_B).

  WA_SALESREF_HANDLE = P_HANDLE1.
  WA_SALESREF_KIND = P_KIND_B.

  INSERT WA_SALES INTO TABLE IT_SALES.
  CLEAR WA_SALES.
ENDFORM.                    ” F_CREATE_SALES

*&———————————————————————*
*&      Form  F_CREATE_PRICING
*&———————————————————————*
*       text
*———————————————————————*
*      –>P_HANDLE1   text
*      –>P_KIND_B   text
*———————————————————————-*
FORM F_CREATE_PRICING  USING  VALUE(P_HANDLE1)
                              VALUE(P_KIND_B).

  WA_PRICINGREF_HANDLE = P_HANDLE1.
  WA_PRICINGREF_KIND = P_KIND_B.
  INSERT WA_PRICING INTO TABLE IT_PRICING.
  CLEAR WA_PRICING.
ENDFORM.                    ” F_CREATE_PRICING

*&———————————————————————*
*&      Form  F_CREATE_SHIPPING
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_HANDLE1   text
*      –>P_KIND_B   text
*———————————————————————-*
FORM F_CREATE_SHIPPING  USING VALUE(P_HANDLE1)
                              VALUE(P_KIND_B).

  WA_SHIPPINGREF_HANDLE = P_HANDLE1.
  WA_SHIPPINGREF_KIND = P_KIND_B.
  INSERT WA_SHIPPING INTO TABLE IT_SHIPPING.
  CLEAR WA_SHIPPING.
ENDFORM.                    ” F_CREATE_SHIPPING

*&———————————————————————*
*&      Form  F_CREATE_PRODUCT
*&———————————————————————*
*       text
*———————————————————————-*
*       –>P_HANDLE1   text
*———————————————————————-*
FORM F_CREATE_PRODUCT  USING VALUE(P_HANDLE1).

  WA_PRODUCTREF_GUID = GV_GUID1.
*  WA_PRODUCT-REF_HANDLE = P_HANDLE1.

  INSERT WA_PRODUCT INTO TABLE I_PRODUCT.
  CLEAR WA_PRODUCT.
ENDFORM.                    ” F_CREATE_PRODUCT
*&———————————————————————*
*&      Form  F_CREATE_SCHEDLIN_I
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_HANDLE1   text
*———————————————————————-*
FORM F_CREATE_SCHEDLIN_I  USING VALUE(P_HANDLE1).
*  WA_SCHEDLIN-GUID = GV_GUID1.
*  WA_SCHEDLIN-LOGICAL_KEY = ‘0’.
  WA_SCHEDLINQUANTITY = ‘10.00’.

  INSERT WA_SCHEDLIN INTO TABLE I_SCHEDLIN.
  CLEAR WA_SCHEDLIN.

  WA_SCHEDLIN_IREF_GUID = GV_GUID1.
*  WA_SCHEDLIN_I-REF_HANDLE = P_HANDLE1.
  WA_SCHEDLIN_ISCHEDLINES = I_SCHEDLIN.

  INSERT WA_SCHEDLIN_I INTO TABLE IT_SCHEDLIN_U.
  CLEAR WA_SCHEDLIN_I.
  CLEAR I_FIELD_NAMES.

  PERFORM F_FIELD_NAMES USING:
                              ‘LOGICAL KEY’ ,
                              ‘QUANTITY’ .

  PERFORM F_INPUT_FIELDS USING GV_GUID1 C_B ‘SCHEDLIN’ .
  CLEAR I_FIELD_NAMES.
  PERFORM F_INPUT_FIELDS USING C_HANDLE GV_GUID1 C_B C_SCHEDLIN_I .
ENDFORM.                    ” F_CREATE_SCHEDLINES_I

*&———————————————————————*
*&      Form  F_CREATE_GUID
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_GUID   text
*———————————————————————-*
FORM F_CREATE_GUID.

  CALL FUNCTION ‘GUID_CREATE’
    IMPORTING
      EV_GUID_16 = GV_GUID.
ENDFORM.                    ” F_CREATE_GUID

*&———————————————————————*
*&      Form  F_CREATE_ORDERADM_I
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM F_CREATE_ORDERADM_I .

  WA_ORDERADM_IGUID = GV_GUID1.
  WA_ORDERADM_IHANDLE = C_HANDLE.
  WA_ORDERADM_IHEADER = GV_GUID.
*  WA_ORDERADM_I-PRODUCT = ‘7B160839EF59C249’ . “GV_GUID_PROD.
  WA_ORDERADM_IORDERED_PROD = ‘WINE’.
  wa_orderadm_inumber_int = ’10’.
  WA_ORDERADM_IDESCRIPTION = ‘RED WINE’.
  WA_ORDERADM_IITM_LANGUAGE = ‘EN’.
  WA_ORDERADM_IITM_TYPE = ‘ZAGN’.
  WA_ORDERADM_IPRODUCT_KIND = ‘A’.
  WA_ORDERADM_IMODE = ‘A’.
*  append wa_orderadm_i to IT_ORDERADM_u .
  INSERT WA_ORDERADM_I INTO TABLE IT_ORDERADM_u.
  CLEAR WA_ORDERADM_I.
  CLEAR I_FIELD_NAMES.

  PERFORM F_FIELD_NAMES USING: C_ORDERED_PROD ,
                               ‘DESCRIPTION’ ‘A’,
                               ‘ITM_TYPE’ ,
                               ‘MODE’ .
  PERFORM F_INPUT_FIELDS USING C_HANDLE GV_GUID1 C_B C_ORDERADM_I .
ENDFORM.                    ” F_CREATE_ORDERADM_I

*&——————————————————————*
*&      Form  F_CREATE_GUID1
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM F_CREATE_GUID1 .
  CALL FUNCTION ‘GUID_CREATE’
    IMPORTING
      EV_GUID_16 = GV_GUID1.
ENDFORM.                    ” F_CREATE_GUID1

*&——————————————————————-*
*&      Form  F_CREATE_ORGMAN
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM F_CREATE_ORGMAN .

  WA_ORGMANREF_HANDLE = ‘0000000000’.
  WA_ORGMANREF_GUID = GV_GUID.
  WA_ORGMANREF_KIND = ‘A’.
  WA_ORGMANDIS_CHANNEL = ’01’.
  WA_ORGMANDIS_CHANNEL_ORI = ‘C’.
  wa_orgmansales_orgr_ori = ‘C’.
  wa_orgmansales_org_ori = ‘C’.
  WA_ORGMANSALES_ORG_RESP = ‘O 50000127’.
  WA_ORGMANMODE = ‘A’.
  wa_orgmansales_org_resp_short = ‘SORG.BP01’.
  wa_orgmansales_org_short = ‘SORG.BP01’.
*  wa_orgman-sales_org_resp = ‘S 50000207’.
  INSERT WA_ORGMAN INTO TABLE I_ORGMAN.
  CLEAR WA_ORGMAN.
  CLEAR I_FIELD_NAMES.
  PERFORM F_FIELD_NAMES USING: ‘DIS_CHANNEL’ ,
                               ‘DIS_CHANNEL_ORI’ ,
                               ‘NO_DETERMINATION’ ,
                               ‘SALES_ORG’ ,
                               ‘SALES_ORG_ORI’ ,
                               ‘SALES_ORG_RESP’ ,
                               ‘SALES_ORG_RESP_SHORT’ ,
                               ‘SERVICE_ORG_RESP’ .

  PERFORM F_INPUT_FIELDS USING C_HANDLE1 GV_GUID ‘A’ ‘ORGMAN’ .
ENDFORM.                    ” F_CREATE_ORGMAN

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply