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: 

Issue in Editable alv storing datas in custom table !

k_sriram
Explorer
0 Kudos

Hi experts , my requirement is to capture data's from an editable alv report to a database table.

i am facing an issue that im unable to save a data which has same MBLNR and MATNR. it overwrites the existing one in DB table .

1. the screen where im manually giving value . manually giving values for same MATERIAL DOC with same MATNR

.

2.datas in DB Table. only last data is saved for the entry with same material doc and same matnr

i have attached my usercommand piece of code here below.

GT_FINAL1 is where all data's is captured before changes are made , it is compared with gt_final where the ongoing changes are captured.

CASE sy-ucomm.
WHEN '&DATA_SAVE'.
LOOP AT gt_final INTO gs_final.
CLEAR gs_final1.
READ TABLE gt_final1 INTO gs_final1 INDEX sy-tabix.sap
IF gs_final NE gs_final1.
gs_zmm_dc-mblnr = gs_final-mblnr.
gs_zmm_dc-matnr = gs_final-matnr.
gs_zmm_dc-vehicle = gs_final-vehicle.
gs_zmm_dc-delivery = gs_final-delivery.
gs_zmm_dc-cgst = gs_final-cgst.
gs_zmm_dc-sgst = gs_final-sgst.
gs_zmm_dc-igst = gs_final-igst.
gs_zmm_dc-price = gs_final-price.
MODIFY zmm_dc FROM gs_zmm_dc.
IF sy-subrc = 0.
MESSAGE 'RECORD HAS BEEN SAVED' TYPE 'S'.
ENDIF.
ENDIF.
CLEAR : gs_zmm_dc , gs_final.
ENDLOOP.
ENDCASE.

12 REPLIES 12

FredericGirod
Active Contributor
0 Kudos

Why do you read the table with the same line number ? are you assuming the tables are in the same order with the same line number ?

LOOP AT gt_final INTO gs_final.
CLEAR gs_final1.
READ TABLE gt_final1 INTO gs_final1 INDEX sy-tabix

FredericGirod
Active Contributor
0 Kudos

don't use Answer, use comment

Why didn't you try to acces the internal table using the table key MBLNR + MATNR?

k_sriram
Explorer
0 Kudos

Hello Frederic , thanks for your answer.

what you r telling is

READ TABLE gt_final1 INTO gs_final1 with key matnr = gt_final-matnr and mblnr = gt_final-mblnr. ?

k_sriram
Explorer
0 Kudos

I tried it but it didnt work aswell

FredericGirod
Active Contributor
0 Kudos

you should post this code

you have a sy-subrc = 4 when you do the READ statement ?

k_sriram
Explorer
0 Kudos

SY SUBRC IS 0 . Im not sure how to post a code . im attaching below for ur ref

***&---------------------------------------------------------------------*
***& Report ZMM_DELIVERY_CHALLAN_REPORT
***&---------------------------------------------------------------------*
***&
***&---------------------------------------------------------------------*004
REPORT zmm_delivery_challan_report.

TABLES : mseg , zmm_dc.

TYPES : BEGIN OF ty_mseg,
* mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
sobkz TYPE mseg-sobkz,
steuc TYPE marc-steuc,
* shipper TYPE zmm_dc-shipper,
* transport TYPE zmm_dc-transport,
* vehicle TYPE zmm_dc-vehicle,
* delivery TYPE zmm_dc-delivery,
* cgst TYPE zmm_dc-cgst,
* sgst TYPE zmm_dc-sgst,
* igst TYPE zmm_dc-igst,
* price TYPE zmm_dc-price,
END OF ty_mseg.

TYPES : BEGIN OF ty_final,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_final.
*
TYPES : BEGIN OF ty_zmmdc,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
* steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_zmmdc.

*

DATA :gt_final TYPE TABLE OF ty_final,
gs_final TYPE ty_final,
gt_mseg TYPE TABLE OF ty_mseg,
gs_mseg TYPE ty_mseg,
gt_zmmdc TYPE TABLE OF ty_zmmdc,
gs_zmmdc TYPE ty_zmmdc,
gt_final1 TYPE TABLE OF ty_final,
gs_final1 TYPE ty_final.


DATA : gt_fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.

DATA : gs_zmm_dc TYPE zmm_dc.
*BREAK abap01.
SELECTION-SCREEN BEGIN OF BLOCK sc_blk1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS:s_mblnr FOR mseg-mblnr.
SELECTION-SCREEN END OF BLOCK sc_blk1

START-OF-SELECTION.

select a~mblnr,a~matnr,a~werks,a~budat_mkpf,a~lifnr,
a~erfmg ,a~erfme , a~sobkz , b~steuc from mseg as a
INNER JOIN marc as b on a~matnr = b~matnr and a~werks = b~werks
into table @gt_mseg where mblnr in @s_mblnr and a~sobkz eq 'O'.


SELECT mandt,mblnr,matnr,werks,budat_mkpf,lifnr ,erfmg,erfme,
shipper,transport,vehicle,delivery,
cgst , sgst, igst, price from zmm_dc
into table @gt_zmmdc FOR ALL ENTRIES IN
@gt_mseg where mblnr eq @gt_mseg-mblnr.


loop at gt_mseg into gs_mseg.

gs_final-mblnr = gs_mseg-mblnr.
gs_final-matnr = gs_mseg-matnr.
gs_final-werks = gs_mseg-werks.
gs_final-budat_mkpf = gs_mseg-budat_mkpf.
gs_final-lifnr = gs_mseg-lifnr.
gs_final-sobkz = gs_mseg-sobkz.
gs_final-erfmg = gs_mseg-erfmg.
gs_final-erfme = gs_mseg-erfme.
gs_final-steuc = gs_mseg-steuc.


READ TABLE gt_zmmdc into gs_zmmdc with key mblnr = gs_final-mblnr.
gs_final-shipper = gs_zmmdc-shipper.
gs_final-transport = gs_zmmdc-transport.
gs_final-vehicle = gs_zmmdc-vehicle.
gs_final-delivery = gs_zmmdc-delivery.
gs_final-cgst = gs_zmmdc-cgst.
gs_final-sgst = gs_zmmdc-sgst.
gs_final-igst = gs_zmmdc-igst.
gs_final-price = gs_zmmdc-price.

append gs_final to gt_final.
clear gs_final.
endloop.

gt_final1 = gt_final
DATA : GS_LAYOUT TYPE slis_layout_alv.
CLEAR gs_fcat.
gs_fcat-fieldname = 'MBLNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MBLNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**
**
CLEAR gs_fcat.
gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MATNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**


CLEAR gs_fcat.
gs_fcat-seltext_m = 'CGST'.
gs_fcat-fieldname = 'CGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'CGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'SGST'.
gs_fcat-fieldname = 'SGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'SGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'IGST'.
gs_fcat-fieldname = 'IGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'IGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-seltext_m = 'Price'.
gs_fcat-fieldname = 'PRICE'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'PRICE'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.




CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING

i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'SAVE'

it_fieldcat = gt_fcat

TABLES
t_outtab = gt_final
*ENDFORM. " DISPLAY

FORM save USING rcomm TYPE sy-ucomm
sel TYPE slis_selfield.


CASE sy-ucomm.
WHEN '&DATA_SAVE'.
LOOP AT gt_final INTO gs_final.
IF GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-SGST IS INITIAL.
MESSAGE 'CGST/SGST Cannot Be Empty !' TYPE 'E'.
elseif GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-igST IS not INITIAL.
MESSAGE 'Enter Any One Tax TYPE!' TYPE 'E'.
ELSE.
CLEAR gs_final1.
READ TABLE gt_final1 INTO gs_final1 WITH KEY MBLNR = GS_FINAL-MBLNR
MATNR = GS_FINAL-MATNR.
IF gs_final-shipper IS INITIAL.

gs_final-shipper = gs_final-werks.
ENDIF.
IF gs_final NE gs_final1.
* WA_VBAP-VBELN = WA_SO-VBELN.
* WA_VBAP-POSNR = WA_SO-POSNR.
* WA_VBAP-MATNR = WA_SO-MATNR.
* WA_VBAP-ARKTX = WA_SO-ARKTX.
gs_zmm_dc-mblnr = gs_final-mblnr.
gs_zmm_dc-matnr = gs_final-matnr.
gs_zmm_dc-werks = gs_final-werks.
gs_zmm_dc-shipper = gs_final-shipper.
gs_zmm_dc-budat_mkpf = gs_final-budat_mkpf.
gs_zmm_dc-lifnr = gs_final-lifnr.
gs_zmm_dc-erfmg = gs_final-erfmg.
gs_zmm_dc-erfme = gs_final-erfme.
gs_zmm_dc-transport = gs_final-transport.
gs_zmm_dc-vehicle = gs_final-vehicle.
gs_zmm_dc-delivery = gs_final-delivery.
gs_zmm_dc-cgst = gs_final-cgst.
gs_zmm_dc-sgst = gs_final-sgst.
gs_zmm_dc-igst = gs_final-igst.
gs_zmm_dc-price = gs_final-price.
MODIFY zmm_dc FROM gs_zmm_dc.
IF sy-subrc = 0.
MESSAGE 'RECORD HAS BEEN SAVED' TYPE 'S'.
ENDIF.

ENDIF.
ENDIF.
CLEAR : gs_zmm_dc , gs_final.
ENDLOOP.


ENDCASE.


ENDFORM.

raymond_giuseppi
Active Contributor

With transaction SE11, look at the primary keys of your custom database table,

  • From your post I suppose you only use MANDT, MBLNR and MATNR?
  • If you want to save more records you must add other primary keys (Look at primary keys of MSEG for an example, MBLNR is not enough, you require also MJAHR and ZEILE.)

0 Kudos

Hi Raymond , thanks for your reply . can u pls help me with it. i

0 Kudos

I could write 'Add MJAHR and ZEILE in the table and define those as primary keys.'

But it depends on actual requirement, final purpose of this table?

matt
Active Contributor
0 Kudos

Please use the "CODE" button in the editor when posting code.

If I see unformatted code, I don't even bother reading the question. And I'm not the only one.

k_sriram
Explorer
0 Kudos
***&---------------------------------------------------------------------*
***& Report ZMM_DELIVERY_CHALLAN_REPORT
***&---------------------------------------------------------------------*
***&
***&---------------------------------------------------------------------*004
REPORT zmm_delivery_challan_report.

TABLES : mseg , zmm_dc.

TYPES : BEGIN OF ty_mseg,
* mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
sobkz TYPE mseg-sobkz,
steuc TYPE marc-steuc,
* shipper TYPE zmm_dc-shipper,
* transport TYPE zmm_dc-transport,
* vehicle TYPE zmm_dc-vehicle,
* delivery TYPE zmm_dc-delivery,
* cgst TYPE zmm_dc-cgst,
* sgst TYPE zmm_dc-sgst,
* igst TYPE zmm_dc-igst,
* price TYPE zmm_dc-price,
END OF ty_mseg.

TYPES : BEGIN OF ty_final,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_final.
*
TYPES : BEGIN OF ty_zmmdc,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
* steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_zmmdc.

*

DATA :gt_final TYPE TABLE OF ty_final,
gs_final TYPE ty_final,
gt_mseg TYPE TABLE OF ty_mseg,
gs_mseg TYPE ty_mseg,
gt_zmmdc TYPE TABLE OF ty_zmmdc,
gs_zmmdc TYPE ty_zmmdc,
gt_final1 TYPE TABLE OF ty_final,
gs_final1 TYPE ty_final.


DATA : gt_fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.

DATA : gs_zmm_dc TYPE zmm_dc.
*BREAK abap01.
SELECTION-SCREEN BEGIN OF BLOCK sc_blk1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS:s_mblnr FOR mseg-mblnr.
SELECTION-SCREEN END OF BLOCK sc_blk1

START-OF-SELECTION.

select a~mblnr,a~matnr,a~werks,a~budat_mkpf,a~lifnr,
a~erfmg ,a~erfme , a~sobkz , b~steuc from mseg as a
INNER JOIN marc as b on a~matnr = b~matnr and a~werks = b~werks
into table @gt_mseg where mblnr in @s_mblnr and a~sobkz eq 'O'.


SELECT mandt,mblnr,matnr,werks,budat_mkpf,lifnr ,erfmg,erfme,
shipper,transport,vehicle,delivery,
cgst , sgst, igst, price from zmm_dc
into table @gt_zmmdc FOR ALL ENTRIES IN
@gt_mseg where mblnr eq @gt_mseg-mblnr.


loop at gt_mseg into gs_mseg.

gs_final-mblnr = gs_mseg-mblnr.
gs_final-matnr = gs_mseg-matnr.
gs_final-werks = gs_mseg-werks.
gs_final-budat_mkpf = gs_mseg-budat_mkpf.
gs_final-lifnr = gs_mseg-lifnr.
gs_final-sobkz = gs_mseg-sobkz.
gs_final-erfmg = gs_mseg-erfmg.
gs_final-erfme = gs_mseg-erfme.
gs_final-steuc = gs_mseg-steuc.


READ TABLE gt_zmmdc into gs_zmmdc with key mblnr = gs_final-mblnr.
gs_final-shipper = gs_zmmdc-shipper.
gs_final-transport = gs_zmmdc-transport.
gs_final-vehicle = gs_zmmdc-vehicle.
gs_final-delivery = gs_zmmdc-delivery.
gs_final-cgst = gs_zmmdc-cgst.
gs_final-sgst = gs_zmmdc-sgst.
gs_final-igst = gs_zmmdc-igst.
gs_final-price = gs_zmmdc-price.

append gs_final to gt_final.
clear gs_final.
endloop.

gt_final1 = gt_final
DATA : GS_LAYOUT TYPE slis_layout_alv.
CLEAR gs_fcat.
gs_fcat-fieldname = 'MBLNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MBLNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**
**
CLEAR gs_fcat.
gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MATNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**


CLEAR gs_fcat.
gs_fcat-seltext_m = 'CGST'.
gs_fcat-fieldname = 'CGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'CGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'SGST'.
gs_fcat-fieldname = 'SGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'SGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'IGST'.
gs_fcat-fieldname = 'IGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'IGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-seltext_m = 'Price'.
gs_fcat-fieldname = 'PRICE'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'PRICE'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.




CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING

i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'SAVE'

it_fieldcat = gt_fcat

TABLES
t_outtab = gt_final
*ENDFORM. " DISPLAY

FORM save USING rcomm TYPE sy-ucomm
sel TYPE slis_selfield.


CASE sy-ucomm.
WHEN '&DATA_SAVE'.
LOOP AT gt_final INTO gs_final.
IF GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-SGST IS INITIAL.
MESSAGE 'CGST/SGST Cannot Be Empty !' TYPE 'E'.
elseif GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-igST IS not INITIAL.
MESSAGE 'Enter Any One Tax TYPE!' TYPE 'E'.
ELSE.
CLEAR gs_final1.
READ TABLE gt_final1 INTO gs_final1 WITH KEY MBLNR = GS_FINAL-MBLNR
MATNR = GS_FINAL-MATNR.
IF gs_final-shipper IS INITIAL.

gs_final-shipper = gs_final-werks.
ENDIF.
IF gs_final NE gs_final1.
* WA_VBAP-VBELN = WA_SO-VBELN.
* WA_VBAP-POSNR = WA_SO-POSNR.
* WA_VBAP-MATNR = WA_SO-MATNR.
* WA_VBAP-ARKTX = WA_SO-ARKTX.
gs_zmm_dc-mblnr = gs_final-mblnr.
gs_zmm_dc-matnr = gs_final-matnr.
gs_zmm_dc-werks = gs_final-werks.
gs_zmm_dc-shipper = gs_final-shipper.
gs_zmm_dc-budat_mkpf = gs_final-budat_mkpf.
gs_zmm_dc-lifnr = gs_final-lifnr.
gs_zmm_dc-erfmg = gs_final-erfmg.
gs_zmm_dc-erfme = gs_final-erfme.
gs_zmm_dc-transport = gs_final-transport.
gs_zmm_dc-vehicle = gs_final-vehicle.
gs_zmm_dc-delivery = gs_final-delivery.
gs_zmm_dc-cgst = gs_final-cgst.
gs_zmm_dc-sgst = gs_final-sgst.
gs_zmm_dc-igst = gs_final-igst.
gs_zmm_dc-price = gs_final-price.
MODIFY zmm_dc FROM gs_zmm_dc.
IF sy-subrc = 0.
MESSAGE 'RECORD HAS BEEN SAVED' TYPE 'S'.
ENDIF.

ENDIF.
ENDIF.
CLEAR : gs_zmm_dc , gs_final.
ENDLOOP.


ENDCASE.


ENDFORM.

k_sriram
Explorer
0 Kudos
***&---------------------------------------------------------------------*
***& Report ZMM_DELIVERY_CHALLAN_REPORT
***&---------------------------------------------------------------------*
***&
***&---------------------------------------------------------------------*004
REPORT zmm_delivery_challan_report.

TABLES : mseg , zmm_dc.

TYPES : BEGIN OF ty_mseg,
* mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
sobkz TYPE mseg-sobkz,
steuc TYPE marc-steuc,
* shipper TYPE zmm_dc-shipper,
* transport TYPE zmm_dc-transport,
* vehicle TYPE zmm_dc-vehicle,
* delivery TYPE zmm_dc-delivery,
* cgst TYPE zmm_dc-cgst,
* sgst TYPE zmm_dc-sgst,
* igst TYPE zmm_dc-igst,
* price TYPE zmm_dc-price,
END OF ty_mseg.

TYPES : BEGIN OF ty_final,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_final.
*
TYPES : BEGIN OF ty_zmmdc,
mandt TYPE mandt,
mblnr TYPE mseg-mblnr,
matnr TYPE mseg-matnr,
werks TYPE mseg-werks,
budat_mkpf TYPE mseg-budat_mkpf,
lifnr TYPE mseg-lifnr,
* sobkz TYPE mseg-sobkz,
erfmg TYPE mseg-erfmg,
erfme TYPE mseg-erfme,
* steuc TYPE marc-steuc,
shipper TYPE zmm_dc-shipper,
transport TYPE zmm_dc-transport,
vehicle TYPE zmm_dc-vehicle,
delivery TYPE zmm_dc-delivery,
cgst TYPE zmm_dc-cgst,
sgst TYPE zmm_dc-sgst,
igst TYPE zmm_dc-igst,
price TYPE zmm_dc-price,
END OF ty_zmmdc.

*

DATA :gt_final TYPE TABLE OF ty_final,
gs_final TYPE ty_final,
gt_mseg TYPE TABLE OF ty_mseg,
gs_mseg TYPE ty_mseg,
gt_zmmdc TYPE TABLE OF ty_zmmdc,
gs_zmmdc TYPE ty_zmmdc,
gt_final1 TYPE TABLE OF ty_final,
gs_final1 TYPE ty_final.


DATA : gt_fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.

DATA : gs_zmm_dc TYPE zmm_dc.
*BREAK abap01.
SELECTION-SCREEN BEGIN OF BLOCK sc_blk1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS:s_mblnr FOR mseg-mblnr.
SELECTION-SCREEN END OF BLOCK sc_blk1

START-OF-SELECTION.

select a~mblnr,a~matnr,a~werks,a~budat_mkpf,a~lifnr,
a~erfmg ,a~erfme , a~sobkz , b~steuc from mseg as a
INNER JOIN marc as b on a~matnr = b~matnr and a~werks = b~werks
into table @gt_mseg where mblnr in @s_mblnr and a~sobkz eq 'O'.


SELECT mandt,mblnr,matnr,werks,budat_mkpf,lifnr ,erfmg,erfme,
shipper,transport,vehicle,delivery,
cgst , sgst, igst, price from zmm_dc
into table @gt_zmmdc FOR ALL ENTRIES IN
@gt_mseg where mblnr eq @gt_mseg-mblnr.


loop at gt_mseg into gs_mseg.

gs_final-mblnr = gs_mseg-mblnr.
gs_final-matnr = gs_mseg-matnr.
gs_final-werks = gs_mseg-werks.
gs_final-budat_mkpf = gs_mseg-budat_mkpf.
gs_final-lifnr = gs_mseg-lifnr.
gs_final-sobkz = gs_mseg-sobkz.
gs_final-erfmg = gs_mseg-erfmg.
gs_final-erfme = gs_mseg-erfme.
gs_final-steuc = gs_mseg-steuc.


READ TABLE gt_zmmdc into gs_zmmdc with key mblnr = gs_final-mblnr.
gs_final-shipper = gs_zmmdc-shipper.
gs_final-transport = gs_zmmdc-transport.
gs_final-vehicle = gs_zmmdc-vehicle.
gs_final-delivery = gs_zmmdc-delivery.
gs_final-cgst = gs_zmmdc-cgst.
gs_final-sgst = gs_zmmdc-sgst.
gs_final-igst = gs_zmmdc-igst.
gs_final-price = gs_zmmdc-price.

append gs_final to gt_final.
clear gs_final.
endloop.

gt_final1 = gt_final
DATA : GS_LAYOUT TYPE slis_layout_alv.
CLEAR gs_fcat.
gs_fcat-fieldname = 'MBLNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MBLNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**
**
CLEAR gs_fcat.
gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'MSEG'.
gs_fcat-ref_fieldname = 'MATNR'.
gs_layout-colwidth_optimize = 'X'.
APPEND gs_fcat TO gt_fcat.
**


CLEAR gs_fcat.
gs_fcat-seltext_m = 'CGST'.
gs_fcat-fieldname = 'CGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'CGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'SGST'.
gs_fcat-fieldname = 'SGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'SGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.


CLEAR gs_fcat.
gs_fcat-seltext_m = 'IGST'.
gs_fcat-fieldname = 'IGST'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'IGST'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.

CLEAR gs_fcat.
gs_fcat-seltext_m = 'Price'.
gs_fcat-fieldname = 'PRICE'.
gs_fcat-tabname = 'GT_FINAL'.
gs_fcat-ref_tabname = 'ZMM_DC'.
gs_fcat-ref_fieldname = 'PRICE'.
gs_layout-colwidth_optimize = 'X'.
gs_fcat-edit = 'X'.
APPEND gs_fcat TO gt_fcat.




CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING

i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'SAVE'

it_fieldcat = gt_fcat

TABLES
t_outtab = gt_final
*ENDFORM. " DISPLAY

FORM save USING rcomm TYPE sy-ucomm
sel TYPE slis_selfield.


CASE sy-ucomm.
WHEN '&DATA_SAVE'.
LOOP AT gt_final INTO gs_final.
IF GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-SGST IS INITIAL.
MESSAGE 'CGST/SGST Cannot Be Empty !' TYPE 'E'.
elseif GS_FINAL-CGST IS NOT INITIAL AND GS_FINAL-igST IS not INITIAL.
MESSAGE 'Enter Any One Tax TYPE!' TYPE 'E'.
ELSE.
CLEAR gs_final1.
READ TABLE gt_final1 INTO gs_final1 WITH KEY MBLNR = GS_FINAL-MBLNR
MATNR = GS_FINAL-MATNR.
IF gs_final-shipper IS INITIAL.

gs_final-shipper = gs_final-werks.
ENDIF.
IF gs_final NE gs_final1.
* WA_VBAP-VBELN = WA_SO-VBELN.
* WA_VBAP-POSNR = WA_SO-POSNR.
* WA_VBAP-MATNR = WA_SO-MATNR.
* WA_VBAP-ARKTX = WA_SO-ARKTX.
gs_zmm_dc-mblnr = gs_final-mblnr.
gs_zmm_dc-matnr = gs_final-matnr.
gs_zmm_dc-werks = gs_final-werks.
gs_zmm_dc-shipper = gs_final-shipper.
gs_zmm_dc-budat_mkpf = gs_final-budat_mkpf.
gs_zmm_dc-lifnr = gs_final-lifnr.
gs_zmm_dc-erfmg = gs_final-erfmg.
gs_zmm_dc-erfme = gs_final-erfme.
gs_zmm_dc-transport = gs_final-transport.
gs_zmm_dc-vehicle = gs_final-vehicle.
gs_zmm_dc-delivery = gs_final-delivery.
gs_zmm_dc-cgst = gs_final-cgst.
gs_zmm_dc-sgst = gs_final-sgst.
gs_zmm_dc-igst = gs_final-igst.
gs_zmm_dc-price = gs_final-price.
MODIFY zmm_dc FROM gs_zmm_dc.
IF sy-subrc = 0.
MESSAGE 'RECORD HAS BEEN SAVED' TYPE 'S'.
ENDIF.

ENDIF.
ENDIF.
CLEAR : gs_zmm_dc , gs_final.
ENDLOOP.


ENDCASE.


ENDFORM.