Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

sales order with multiple items varient updation using bapi change

$
0
0

Dear Friends,

 

 

 

Rightnow i am working on sale order with more then one item using  'BAPI_SALESORDER_CHANGE.

 

 

the below code is working for sales order with one item.

 

 

In this BAPI, I have filled the detials of following structures.

 

 

I have set all the necessary flag for this issue in the structure 'ORDER_ITEM_INX' for the updation purposes.

 

 

ORDER_ITEM_INX-UPDATEFLAG = 'X'.

 

 

ORDER_ITEM_INX-PO_ITM_NO = 'X'.

 

 

ORDER_ITEM_INX-CONFIG_ID = 'X'

 

 

 

I have gone throgh almost all the SDN results.

 

 

But i am unable to update the variant configuration field in sale order.

 

 

Plesae if any one can provide the solution for this are most appreciable.

 

 

the below code is working for sales order with one item. IF I CREATE SALES OREDER WITH MORE THEN ONE ITEM ITS NOT UPDATING VARIENT.

 

 

 

Thanks & Regards,

 

 

nAINI

 

 

 

 

CODE:

 

 

*&---------------------------------------------------------------------*

*& Report  ZNAVIS_BI_BLOCK_UPDATE_BAPI

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

 

 

REPORT  znavis_bi_block_update_bapi.

 

 

TABLES: znavis_wm_bill.

 

 

DATA : it_wmbill LIKE znavis_wm_bill OCCURS 0 WITH HEADER LINE.

DATA : wa_wmbill LIKE LINE OF it_wmbill.

 

 

DATA : it_cdhdr LIKE cdhdr OCCURS 0 WITH HEADER LINE.

DATA : wa_cdhdr LIKE LINE OF it_cdhdr.

 

 

DATA : l_wagon_number LIKE znavis_wm_bill-wagon_number,

       l_train_number LIKE znavis_wm_bill-train_number,

       l_container_owner LIKE znavis_wm_bill-container_owner,

       l_container_number LIKE znavis_wm_bill-container_number,

       l_temp_scale LIKE znavis_wm_bill-temp_scale.

 

 

DATA : check_wagon(1)  TYPE c VALUE 'N'.

DATA : check_train(1)  TYPE c VALUE 'N'.

DATA : check_owner(1)  TYPE c VALUE 'N'.

DATA : check_number(1)  TYPE c VALUE 'N'.

DATA : check_temp(1)  TYPE c VALUE 'N'.

DATA : check_scale(1)  TYPE c VALUE 'N'.

DATA : v_net_weight(15)  TYPE n,

       l_net(1)          type n,

       v_tare(15)       TYPE n,

       v_gross_mass(15)  TYPE n,

       v_refer_tem(15) TYPE n,

       v_junk1(50) type c,

       v_junk2(50) type c,

       v_junk3(50) type c,

       v_junk4(50) type c,

       v_junk5(50) type c,

       v_junk6(50) type c,

       v_temp1(9) type c,

       v_temp2(9) type c.

DATA : grossmass(50) type c.

DATA : taremass(50) type c.

DATA : refer_tem(9) type c.

DATA : nettmass(50) type c.

DATA: ls_val(180) TYPE c,

    ls_vbeln    TYPE sales_key,

    lt_vbeln TYPE TABLE OF sales_key,

    ls_bapi_view TYPE order_view,

    ls_logic TYPE bapisdls,

    lt_header TYPE TABLE OF bapisdhd,

    lt_header_x TYPE bapisdh1x,

    ls_item TYPE bapisdit,

    ls_items TYPE bapisditm,

    lt_item TYPE TABLE OF bapisdit,

    lt_items TYPE TABLE OF bapisditm,

    lt_item_x TYPE TABLE OF bapisditmx,

    ls_item_x TYPE bapisditmx,

    lt_schedules TYPE TABLE OF bapisdhedu,

    lt_partners TYPE TABLE OF bapisdpart,

    lt_conditions TYPE TABLE OF bapisdcond,

    ls_curefs TYPE bapicurefm,

    lt_curefs TYPE TABLE OF bapicurefm,

    ls_cucfgs TYPE bapicucfgm,

    lt_cucfgs TYPE TABLE OF bapicucfgm,

    ls_cuins TYPE bapicuinsm,

    lt_cuins TYPE TABLE OF bapicuinsm,

    ls_cuprts TYPE bapicuprtm,

    lt_cuprts TYPE TABLE OF bapicuprtm,

    ls_cuvals TYPE bapicuvalm,

    lt_cuvals TYPE TABLE OF bapicuvalm,

    wa_cuvals TYPE bapicuvalm,

    lt_cuval_ch TYPE TABLE OF bapicuvalm WITH HEADER LINE,

    ls_blob TYPE bapicublbm,

    lt_blob TYPE TABLE OF bapicublbm,

    ls_cuvks TYPE bapicuvkm,

    lt_cuvks TYPE TABLE OF bapicuvkm,

    ls_return TYPE bapiret2,

    lt_return TYPE TABLE OF bapiret2,

    ls_cfgs_ref TYPE bapicucfg,

    lt_cfgs_ref TYPE TABLE OF bapicucfg,

    ls_inst TYPE bapicuins,

    lt_inst TYPE TABLE OF bapicuins,

    ls_parts TYPE bapicuprt,

    lt_parts TYPE TABLE OF bapicuprt,

    ls_values TYPE bapicuval,

    lt_values TYPE TABLE OF bapicuval,

    ls_cublob TYPE bapicublb,

    lt_cublob TYPE TABLE OF bapicublb,

    ls_cuvk TYPE bapicuvk,

    lt_cuvk TYPE TABLE OF bapicuvk,

    ls_curef TYPE bapicuref,

    lt_curef TYPE TABLE OF bapicuref.

 

 

CLEAR : it_wmbill[],wa_wmbill.

REFRESH : it_wmbill[].

SELECT * FROM znavis_wm_bill

         INTO TABLE it_wmbill

         WHERE date_received EQ sy-datum

           AND  bpi EQ 'X'.

IF sy-subrc EQ 0.

  CLEAR : wa_wmbill.

  LOOP AT it_wmbill INTO wa_wmbill.

    CLEAR: ls_vbeln,lt_vbeln[],lt_header[],lt_item[],lt_schedules[],lt_conditions[],lt_curefs[],lt_cucfgs[],lt_cuins[].

    CLEAR: lt_cuprts[],lt_cuvals[],lt_blob[],lt_cuvks[],lt_cuval_ch[].

    REFRESH : lt_vbeln[],lt_header[],lt_item[],lt_schedules[],lt_conditions[],lt_curefs[],lt_cucfgs[],lt_cuins[].

    REFRESH : lt_cuprts[],lt_cuvals[],lt_blob[],lt_cuvks[],lt_cuval_ch[].

 

 

    CLEAR: lt_return[],lt_items,lt_item_x,lt_cfgs_ref[].

    CLEAR: lt_inst[],lt_parts[],lt_values[],lt_cublob[],lt_cuvk[],lt_curef[].

    REFRESH : lt_return[],lt_items,lt_item_x,lt_cfgs_ref[].

    REFRESH : lt_inst[],lt_parts[],lt_values[],lt_cublob[],lt_cuvk[],lt_curef[].

    CLEAR: ls_item,ls_cucfgs,ls_cuins,ls_cuprts,ls_cuvals,ls_blob,ls_cuvks,ls_return.

 

 

    ls_vbeln-vbeln = wa_wmbill-vbeln.

    APPEND ls_vbeln TO lt_vbeln.

 

 

    ls_bapi_view-header = 'X'.

    ls_bapi_view-item = 'X'.

    ls_bapi_view-sdschedule = 'X'.

    ls_bapi_view-partner = 'X'.

    ls_bapi_view-sdcond = 'X'.

    ls_bapi_view-configure = 'X'.

 

 

    CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'

      EXPORTING

        I_BAPI_VIEW           = LS_BAPI_VIEW

      TABLES

        SALES_DOCUMENTS       = LT_VBELN

        ORDER_HEADERS_OUT     = LT_HEADER

        ORDER_ITEMS_OUT       = LT_ITEM

        ORDER_SCHEDULES_OUT   = LT_SCHEDULES

        ORDER_CONDITIONS_OUT  = LT_CONDITIONS

        ORDER_CFGS_CUREFS_OUT = LT_CUREFS

        ORDER_CFGS_CUCFGS_OUT = LT_CUCFGS

        ORDER_CFGS_CUINS_OUT  = LT_CUINS

        ORDER_CFGS_CUPRTS_OUT = LT_CUPRTS

        ORDER_CFGS_CUVALS_OUT = LT_CUVALS

        ORDER_CFGS_CUBLBS_OUT = LT_BLOB

        ORDER_CFGS_CUVKS_OUT  = LT_CUVKS.

 

 

    CLEAR: v_gross_mass,v_tare,v_net_weight,v_refer_tem.

 

 

    MOVE:  wa_wmbill-gross_mass to v_gross_mass.

    SHIFT  v_gross_mass  LEFT DELETING LEADING '0'.

 

 

    MOVE:  wa_wmbill-tare_mass to v_tare.

    SHIFT  v_tare  LEFT DELETING LEADING '0'.

 

 

    MOVE:  wa_wmbill-net_mass to v_net_weight.

    SHIFT  v_net_weight  LEFT DELETING LEADING '0'.

 

 

    MOVE:  wa_wmbill-reefer_temp to v_refer_tem.

    SHIFT  v_refer_tem  LEFT DELETING LEADING '0'.

 

 

    if wa_wmbill-gross_mass is initial and

     wa_wmbill-tare_mass is not initial and

     wa_wmbill-net_mass is not initial.

      v_gross_mass = v_net_weight - v_tare.

      SHIFT  v_gross_mass  LEFT DELETING LEADING '0'.

    endif.

 

 

    if  wa_wmbill-tare_mass is initial and

       wa_wmbill-gross_mass is not initial and

       wa_wmbill-net_mass is not initial.

      v_tare = v_net_weight - v_gross_mass.

      SHIFT  v_tare  LEFT DELETING LEADING '0'.

    endif.

 

 

    if  wa_wmbill-net_mass is initial and

       wa_wmbill-gross_mass is not initial and

       wa_wmbill-tare_mass is not initial.

      v_net_weight =  v_gross_mass - v_tare.

      SHIFT  v_net_weight  LEFT DELETING LEADING '0'.

    endif.

 

 

    CLEAR : l_wagon_number,l_train_number,l_container_owner,l_container_number,l_temp_scale.

 

 

    MOVE : wa_wmbill-wagon_number TO l_wagon_number,

           wa_wmbill-train_number TO l_train_number,

           wa_wmbill-container_owner TO l_container_owner,

           wa_wmbill-container_number TO l_container_number,

           wa_wmbill-temp_scale TO l_temp_scale.

 

 

 

 

    CLEAR: wa_cuvals."check_wagon, check_train, check_owner, check_number,check_temp,check_scale.

    LOOP AT lt_cuvals INTO  wa_cuvals.

      IF wa_cuvals-charc     = 'WAGON_NUMBER'.

        MOVE :

               wa_cuvals-config_id TO ls_cuvals-config_id,

               wa_cuvals-inst_id TO ls_cuvals-inst_id,

               wa_cuvals-charc TO ls_cuvals-charc,

               l_wagon_number TO ls_cuvals-value,

                'Y' TO check_wagon.

      ELSEIF wa_cuvals-charc      = 'TRAIN_NUMBER'.

        MOVE :

             wa_cuvals-config_id TO ls_cuvals-config_id,

             wa_cuvals-inst_id TO ls_cuvals-inst_id,

             wa_cuvals-charc TO ls_cuvals-charc,

             l_train_number TO ls_cuvals-value,

             'Y' TO check_train.

 

 

 

 

      ELSEIF wa_cuvals-charc     = 'NETT_MASS1'.

        MOVE :

              wa_cuvals-config_id TO ls_cuvals-config_id,

              wa_cuvals-inst_id TO ls_cuvals-inst_id,

              wa_cuvals-charc TO ls_cuvals-charc,

              v_net_weight TO ls_cuvals-value.

 

 

 

 

      ELSEIF wa_cuvals-charc      = 'TARE'.

        MOVE :

               wa_cuvals-config_id TO ls_cuvals-config_id,

               wa_cuvals-inst_id TO ls_cuvals-inst_id,

               wa_cuvals-charc TO ls_cuvals-charc,

               v_tare TO ls_cuvals-value.

 

 

 

 

      ELSEIF wa_cuvals-charc     = 'GROSS_MASS'.

        MOVE :

              wa_cuvals-config_id TO ls_cuvals-config_id,

              wa_cuvals-inst_id TO ls_cuvals-inst_id,

              wa_cuvals-charc TO ls_cuvals-charc,

              v_gross_mass TO ls_cuvals-value.

 

 

 

 

      ELSEIF wa_cuvals-charc      = 'CONTNO_OWNER'.

        MOVE :

              wa_cuvals-config_id TO ls_cuvals-config_id,

              wa_cuvals-inst_id TO ls_cuvals-inst_id,

              wa_cuvals-charc TO ls_cuvals-charc,

              l_container_owner TO ls_cuvals-value,

              'Y' TO check_owner.

 

 

 

 

      ELSEIF wa_cuvals-charc      = 'CONT_NUM'.

        MOVE :

               wa_cuvals-config_id TO ls_cuvals-config_id,

               wa_cuvals-inst_id TO ls_cuvals-inst_id,

               wa_cuvals-charc TO ls_cuvals-charc,

              l_container_number TO ls_cuvals-value,

              'Y' TO check_number.

 

 

 

 

 

 

      ELSEIF wa_cuvals-charc      = 'TEM'.

        MOVE :

              wa_cuvals-config_id TO ls_cuvals-config_id,

              wa_cuvals-inst_id TO ls_cuvals-inst_id,

              wa_cuvals-charc TO ls_cuvals-charc,

             v_refer_tem TO ls_cuvals-value,

             'Y' TO check_temp.

 

 

 

 

      ELSEIF wa_cuvals-charc      = 'TEMP_SCALE'.

        MOVE :

             wa_cuvals-config_id TO ls_cuvals-config_id,

             wa_cuvals-inst_id TO ls_cuvals-inst_id,

             wa_cuvals-charc TO ls_cuvals-charc,

            l_temp_scale TO ls_cuvals-value,

             'Y' TO check_scale.

      ELSE.

        MOVE :

               wa_cuvals-config_id TO ls_cuvals-config_id,

               wa_cuvals-inst_id TO ls_cuvals-inst_id,

               wa_cuvals-charc TO ls_cuvals-charc,

               wa_cuvals-value TO ls_cuvals-value.

 

 

      ENDIF.

      append ls_cuvals to lt_cuval_ch.

    ENDLOOP.

 

 

    loop at lt_cuval_ch.

      READ TABLE lt_cuvals into ls_cuvals WITH KEY

                                 config_id = lt_cuval_ch-config_id

                                 inst_id   = lt_cuval_ch-inst_id

                                 charc    = lt_cuval_ch-charc.

      if sy-subrc = 0." and ls_cuvals-author is initial.

        ls_cuvals-value = lt_cuval_ch-value.

        MODIFY lt_cuvals FROM ls_cuvals INDEX sy-tabix.

      ENDIF.

    endloop.

 

 

    loop at lt_cucfgs INTO ls_cucfgs WHERE NOT sce IS INITIAL.

      CLEAR ls_cucfgs-sce.

      MODIFY lt_cucfgs FROM ls_cucfgs.

    ENDLOOP.

 

 

    LT_HEADER_X-UPDATEFLAG = 'U'.

    LT_HEADER_X-BILL_BLOCK = 'X'.

 

 

    LOOP AT lt_item INTO ls_item.

      LS_ITEM_X-ITM_NUMBER = LS_ITEM-ITM_NUMBER.

      LS_ITEM_X-UPDATEFLAG = 'U'.

      LS_ITEM_X-CONFIG_ID = 'X'.

      LS_ITEM_X-PO_ITM_NO = 'X'.

      APPEND ls_item_x TO lt_item_x.

    ENDLOOP.

    LOOP AT lt_item INTO ls_item.

      ls_items-itm_number = ls_item-itm_number.

      ls_items-hg_lv_item = ls_item-hg_lv_item.

      ls_items-po_itm_no = ls_item-itm_number.

      ls_items-material = ls_item-material.

      APPEND ls_items TO lt_items.

    ENDLOOP.

 

 

    LOOP AT lt_cucfgs INTO ls_cucfgs.

      ls_cfgs_ref-posex = ls_cucfgs-posex.

      ls_cfgs_ref-config_id = ls_cucfgs-config_id.

      ls_cfgs_ref-root_id = ls_cucfgs-root_id.

      ls_cfgs_ref-sce = ls_cucfgs-sce.

      ls_cfgs_ref-kbname = ls_cucfgs-kbname.

      ls_cfgs_ref-kbversion = ls_cucfgs-kbversion.

      APPEND ls_cfgs_ref TO lt_cfgs_ref.

    ENDLOOP.

 

 

 

 

    LOOP AT lt_cuins INTO ls_cuins.

      ls_inst-config_id = ls_cuins-config_id.

      ls_inst-inst_id = ls_cuins-inst_id.

      ls_inst-obj_type = ls_cuins-obj_type.

      ls_inst-class_type = ls_cuins-class_type.

      ls_inst-obj_key = ls_cuins-obj_key.

      APPEND ls_inst TO lt_inst.

    ENDLOOP.

 

 

    LOOP AT lt_cuprts INTO ls_cuprts.

      ls_parts-config_id = ls_cuprts-config_id.

      ls_parts-parent_id = ls_cuprts-parent_id.

      ls_parts-inst_id =  ls_cuprts-inst_id.

      ls_parts-part_of_no = ls_cuprts-part_of_no.

      ls_parts-obj_type = ls_cuprts-obj_type.

      ls_parts-class_type = ls_cuprts-class_type.

      ls_parts-obj_key = ls_cuprts-obj_key.

      APPEND ls_parts TO lt_parts.

    ENDLOOP.

 

 

    LOOP AT lt_cuvals INTO ls_cuvals.

      ls_values-config_id = ls_cuvals-config_id.

      ls_values-inst_id = ls_cuvals-inst_id.

      ls_values-charc = ls_cuvals-charc.

      ls_values-value = ls_cuvals-value.

      ls_values-author = ls_cuvals-author.

      APPEND ls_values TO lt_values.

    ENDLOOP.

 

 

    LOOP AT lt_blob INTO ls_blob.

      ls_cublob-config_id = ls_blob-config_id.

      ls_cublob-context = ls_blob-context.

      APPEND ls_cublob to lt_cublob.

    ENDLOOP.

 

 

    LOOP AT lt_cuvks INTO ls_cuvks.

      ls_cuvk-config_id = ls_cuvks-config_id.

      ls_cuvk-inst_id = ls_cuvks-inst_id.

      ls_cuvk-vkey = ls_cuvks-vkey.

      ls_cuvk-factor = ls_cuvks-factor.

      APPEND ls_cuvk to lt_cuvk.

    ENDLOOP.

 

 

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

      EXPORTING

        SALESDOCUMENT      = wa_wmbill-vbeln

        ORDER_HEADER_INX   = LT_HEADER_X

        LOGIC_SWITCH       = LS_LOGIC

      TABLES

        RETURN             = LT_RETURN

        ORDER_ITEM_IN      = LT_ITEMS

        ORDER_ITEM_INX     = LT_ITEM_X

        ORDER_CFGS_REF     = LT_CFGS_REF

        ORDER_CFGS_INST    = LT_INST

        ORDER_CFGS_PART_OF = LT_PARTS

        ORDER_CFGS_VALUE   = LT_VALUES

        ORDER_CFGS_BLOB    = LT_CUBLOB

        ORDER_CFGS_VK      = LT_CUVK

        ORDER_CFGS_REFINST = LT_CUREF.

 

 

 

 

    LOOP AT lt_return INTO ls_return.

      if ls_return-type  = 'A' Or ls_return-type = 'E'.

        EXIT.

      else.

 

 

        if ls_return-type  = 'S' and

           ls_return-id    = 'V1' and

           ls_return-number  = 311.

 

 

          MOVE ' ' TO wa_wmbill-bpi.

          MOVE ' ' TO wa_wmbill-bill_block_ind.

          MOVE sy-datum TO wa_wmbill-bill_blk_rm_dat.

          MOVE 'C'  TO wa_wmbill-mpi.

          MODIFY znavis_wm_bill FROM wa_wmbill.

          IF sy-subrc EQ 0.

          ENDIF.

        endif.

        COMMIT WORK .

      endif.

    ENDLOOP.

 

 

    CLEAR : wa_wmbill.

  ENDLOOP.

ENDIF.


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>