Skip to Content

This program will help to Create Sales order by using crm_order_maintain bapi with mandatory fields .




*&———————————————————————*

*&  Include           ZSALES_ORDER_TOP

*&———————————————————————*

*&———————————————————————*

*& Loacal Class Object Declaration

*&———————————————————————*

CLASS ZSALES_ORDER DEFINITION DEFERRED.

DATA :o_ref TYPE REF TO ZSALES_ORDER .

*———————————————————————-*

*Internal Table and Work area to get Header data                     *

*———————————————————————-*

DATA: i_orderadm_h TYPE crmt_orderadm_h_comt,

       wa_orderadm_h TYPE crmt_orderadm_h_com,

*———————————————————————-*

*Internal Table and Work area to get Input Fields data             *

*———————————————————————-*

       wa_input_fields TYPE crmt_input_field,

       i_input_fields TYPE crmt_input_field_tab,

*———————————————————————-*

*Internal Table and Work area to Save Sales data         *

*———————————————————————-*

       i_object_save1 TYPE  crmt_object_guid_tab,

       wa_object_save1 TYPE  crmt_object_guid,

       i_saved_objects1 TYPE  crmt_return_objects,

       wa_saved_objects1 TYPE  crmt_return_objects_struc,

       it_bapiret TYPE TABLE OF bapiret2.

*———————————————————————*

*Variable for Guid           *

*———————————————————————-*

DATA: gv_guid TYPE guid_16 .

DATA return type STANDARD TABLE OF DDSHRETVAL .

data:BEGIN OF itab OCCURS 0,

       P_TYP type CRMT_PROCESS_TYPE_DB ,

   END OF itab.



*&———————————————————————*

*&  Include           ZSALES_ORDER_SCR

*&———————————————————————*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001 .

   PARAMETERS :proc_typ TYPE CRMT_PROCESS_TYPE_DB  .

  SELECTION-SCREEN END OF BLOCK b1 .

*———————————————————————-*

*                    Initialization                                *

*———————————————————————-*

INITIALIZATION .

   CREATE OBJECT  o_ref .

   o_ref->clear_all( ).

AT SELECTION-SCREEN on VALUE-REQUEST FOR proc_typ.

refresh itab.

SELECT PROCESS_TYPE from CRMD_ORDERADM_H

   into TABLE itab.

CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’

   EXPORTING

     RETFIELD               = ‘P_TYP’

     DYNPROFIELD            = ‘PROC_TYP’

     DYNPPROG               = syrepid

    DYNPNR                 = sydynnr

     VALUE_ORG              = ‘S’

   TABLES

     VALUE_TAB              = itab

     RETURN_TAB = return .

*———————————————————————-*

* Event Start of Selection.

*———————————————————————-*


START-OF-SELECTION.

CALL FUNCTION ‘GUID_CREATE’

       IMPORTING

         ev_guid_16 = gv_guid.


     wa_orderadm_hhandle = ‘0000000001’.

     wa_orderadm_hguid = gv_guid.

     wa_orderadm_hprocess_type = proc_typ .

     wa_orderadm_hmode = ‘A’.

     wa_orderadm_hdescr_language = ‘E’ .

     wa_orderadm_hlogical_system = ‘ZCRM1234’ .

     wa_orderadm_hchanged_at = sydatum .

     wa_orderadm_hchanged_by = syuname .

*Inserting values from work area to internal table.

     INSERT wa_orderadm_h INTO TABLE i_orderadm_h.

     CLEAR wa_orderadm_h.

*Passing values in the work area of INPUT_FIELDS1.

     wa_input_fieldsref_guid = gv_guid.

     wa_input_fieldsref_kind = ‘A’ .

*Inserting values from work area to internal table.

     INSERT wa_input_fields INTO TABLE i_input_fields.

     CLEAR wa_input_fields.

     CALL FUNCTION ‘CRM_ORDER_MAINTAIN’

       CHANGING

         ct_orderadm_h     = i_orderadm_h

         ct_input_fields   = i_input_fields

       EXCEPTIONS

         error_occurred    = 1

         document_locked   = 2

         no_change_allowed = 3

         no_authority      = 4

         OTHERS            = 5.

     IF sysubrc <> 0.

       MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

                   WITH symsgv1 symsgv2 symsgv3 symsgv4.

     ENDIF.

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

     wa_object_save1 = gv_guid.

* Inserting value from work area to internal table.

     INSERT wa_object_save1 INTO TABLE i_object_save1.

     CLEAR wa_object_save1.

*———————————————————————-*

*         Save created Sales Order  *

*———————————————————————-*

     CALL FUNCTION ‘CRM_ORDER_SAVE’

       EXPORTING

         it_objects_to_save = i_object_save1

       IMPORTING

         et_saved_objects   = i_saved_objects1

       EXCEPTIONS

         document_not_saved = 1

         OTHERS             = 2.

     IF sysubrc <> 0.

       MESSAGE ID symsgid TYPE symsgty NUMBER symsgno

                   WITH symsgv1 symsgv2 symsgv3 symsgv4.

     ENDIF.



IF NOT i_saved_objects1[] IS INITIAL.

       LOOP AT i_saved_objects1 INTO wa_saved_objects1.

         WRITE: /1 ‘Transaction number’,

                20 wa_saved_objects1object_id,

                30 ‘Is Saved’.

       ENDLOOP.

     ENDIF.

     CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.

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