Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member776038
Discoverer
0 Kudos
 

 

This Program will help to upload the data for MIGO Transaction and also to send the data to third party system by using PI

 

  1. . Need to display the excel file as ALV output.

    1. In MIGO there are two operations that are performed to post a GR.

    2. a) Check Operation

    3. b) Post Operation.


    There are enhancements that are implemented during check and Post operations.

    During the manual operations all the validations that are given in check operation and

    post operation performed and GR will be posted. The same thing need to be performed

    during the upload program also.




PI - Function module


 

Coding for DATA transfer from SAP to third Party System..

Can write the required validation and pass the values to Header and item table.
            CALL METHOD zcl_grn=>zif_grn~send_data
EXPORTING
lt_header = ls_header
* lt_item1 = lt_item1.
lt_item1 = lt_item2.
CLEAR ls_header.
* ENDIF.
CLEAR lt_item2[].
IF lt_item1[] IS NOT INITIAL AND lt_header[] IS NOT INITIAL.
MODIFY zmti_grn_hdr FROM TABLE lt_header.
MODIFY zmti_grn_itm FROM TABLE lt_item1.
CLEAR : lt_item1[],lt_header[].
ENDIF.
ENDIF.

 


 
TYPE-POOLS: slis.
TYPE-POOLS: truxs,esp1.
TABLES: mkpf , zmt_033_mrp.

""""""""""" Structure declaration for MIGO details""""
TYPES: BEGIN OF ty_field,
bldat TYPE mkpf-bldat,
budat TYPE imkpf-budat,
ebeln TYPE mseg-ebeln,
ebelp TYPE mseg-ebelp,
lifex TYPE imkpf-lifex,
frbnr TYPE imkpf-frbnr,
matnr TYPE mseg-matnr,
menge TYPE mseg-menge,
licha TYPE imseg-licha,
vfdat TYPE mseg-vfdat,
exvkw TYPE mseg-exvkw,
zzrecdate TYPE mkpf-zzrecdate,
zzreason TYPE mkpf-zzreason,
grn TYPE mseg-exvkw,
END OF ty_field.

TYPES: BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
txz01 TYPE ekpo-txz01,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
END OF ty_ekpo.

TYPES: BEGIN OF ty_final,
bldat TYPE imkpf-bldat,
budat TYPE imkpf-budat,
ebeln TYPE mseg-ebeln,
ebelp TYPE mseg-ebelp,
lifex TYPE imkpf-lifex,
frbnr TYPE imkpf-frbnr,
matnr TYPE zmt_033_mrp-zzmatnr,
menge TYPE mseg-menge,
meins TYPE mseg-meins,
werks TYPE mseg-werks,
lgort TYPE mseg-lgort,
licha TYPE imseg-licha,
vfdat TYPE mseg-vfdat,
exvkw TYPE mseg-exvkw,
zzrecdate TYPE mkpf-zzrecdate,
zzreason TYPE mkpf-zzreason,
txz01 TYPE ekpo-txz01,
grn TYPE mseg-exvkw,
check_flag(1) TYPE c,
END OF ty_final.

TYPES: BEGIN OF ty_header.
INCLUDE STRUCTURE bapi2017_gm_head_01.
TYPES: END OF ty_header.

TYPES: BEGIN OF ty_item.
INCLUDE STRUCTURE bapi2017_gm_item_create.
TYPES: END OF ty_item.

TYPES : BEGIN OF ty_errors,
msgty(1) TYPE c,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
matnr(18) TYPE c,
msgv1(120) TYPE c,
END OF ty_errors.

TYPES : BEGIN OF ty_success,
msg(1) TYPE c,
ebeln TYPE ebeln,
mblnr TYPE mkpf-mblnr,
mjahr TYPE mkpf-mjahr,
msg_text(120) TYPE c,
END OF ty_success.
TYPES: BEGIN OF gs_ekko
ebeln TYPE c LENGTH 10,
waers TYPE ekko-waers,
knumv TYPE ekko-knumv,
END OF gs_ekko.

TYPES: BEGIN OF gs_ekpo,
ebeln TYPE c LENGTH 10, "ekpo-ebeln,
ebelp TYPE c LENGTH 5,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
netwr TYPE ekpo-netwr,
END OF gs_ekpo.

DATA: ht_ekko TYPE TABLE OF gs_ekko,
ht_ekko1 TYPE TABLE OF gs_ekko,

hs_ekko TYPE gs_ekko,
hs_ekko1 TYPE gs_ekko,

ht_ekpo TYPE TABLE OF gs_ekpo,
ht_ekpo1 TYPE TABLE OF gs_ekpo,

ht_ekpo2 TYPE TABLE OF gs_ekpo,
hs_ekpo TYPE gs_ekpo,

hs_ekpo1 TYPE gs_ekpo,
hs_ekpo2 TYPE gs_ekpo.

TYPES: BEGIN OF ty_konv,
knumv TYPE ekko-knumv,
kposn TYPE konv-kposn,
kschl TYPE konv-kschl,
kwert TYPE konv-kwert,
END OF ty_konv.

DATA: lt_konv TYPE TABLE OF ty_konv,
lt_konv_c TYPE TABLE OF ty_konv,
ls_konv TYPE ty_konv.

DATA: lv_knumv TYPE konv-knumv,
lv_kposn TYPE konv-kposn.

DATA: lv_netwr TYPE netwr,
lv_po_val TYPE p DECIMALS 6,
lv_gr_val TYPE p DECIMALS 6.

DATA: it_field TYPE TABLE OF ty_field,
it_field1 TYPE TABLE OF ty_field,
wa_field TYPE ty_field,
wa_field1 TYPE ty_field.

DATA: it_final TYPE TABLE OF ty_field,
wa_final TYPE ty_field.
DATA: it_ekpo TYPE TABLE OF ty_ekpo,
wa_ekpo TYPE ty_ekpo.
DATA: it_final_alv TYPE TABLE OF ty_final,
wa_final_alv TYPE ty_final.



DATA : it_final_alv1 TYPE TABLE OF ty_final,
wa_final_alv1 TYPE ty_final.

DATA : bapita-wait TYPE bapiwait,
bapiret2 TYPE bapiret2,
ret TYPE TABLE OF bapiret2,
wa_ret TYPE bapiret2.

DATA: p_date TYPE sy-datum.
DATA: c_date TYPE sy-datum.
DATA: it_type TYPE truxs_t_text_data.
CONSTANTS: cns_x TYPE char1 VALUE 'X'.

DATA: it_fcat TYPE slis_t_fieldcat_alv,
it_fcat_tab TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
wa_fcat_tab TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
wa_layout_tab TYPE slis_layout_alv.

DATA: it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv..

TYPES: ty_t_field TYPE STANDARD TABLE OF ty_field.

DATA: lt_tab TYPE TABLE OF ty_errors,
ls_tab TYPE ty_errors,
lt_msg TYPE TABLE OF ty_success,
ls_msg TYPE ty_success.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file TYPE rlgrap-filename OBLIGATORY.
PARAMETERS: p_zrecda TYPE mkpf-zzrecdate OBLIGATORY,
p_zreaso TYPE mkpf-zzreason MATCHCODE OBJECT zreason.
SELECTION-SCREEN END OF BLOCK b1.




INITIALIZATION.

"""""""Once GR is created on the double click of the genereated GR it will go
to MIGO transaction in display mode""""

CLASS cl_handler DEFINITION.

PUBLIC SECTION.
METHODS on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.

ENDCLASS.

CLASS cl_handler IMPLEMENTATION.
METHOD on_double_click.
IF column = 'MBLNR'.
CLEAR: ls_msg.
READ TABLE lt_msg INTO ls_msg INDEX row.
IF sy-subrc = 0.
SET PARAMETER ID 'MBN' FIELD ls_msg-mblnr.
DATA(gv_mblnr) = ls_msg-mblnr.
DATA(gv_mjahr) = ls_msg-mjahr.
CALL FUNCTION 'MIGO_DIALOG'
EXPORTING
i_action = 'A04'
i_refdoc = 'R02'
i_notree = 'X'
i_no_auth_check = ' '
i_skip_first_screen = 'X'
i_deadend = 'X'
i_okcode = 'OK_GO'
i_leave_after_post = ' '
i_new_rollarea = 'X'
* I_SYTCODE =
* I_EBELN =
* I_EBELP =
i_mblnr = gv_mblnr
i_mjahr = gv_mjahr
EXCEPTIONS
illegal_combination = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
*











"""""Selection screen to upload the excel file""""



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.

START-OF-SELECTION.
* Uploading the data in the file into internal table
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = 'X'
i_tab_raw_data = it_type
i_filename = p_file
TABLES
i_tab_converted_data = it_field[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

IF it_field IS NOT INITIAL.

SELECT ebeln
ebelp
txz01
matnr
werks
lgort
meins
netpr FROM ekpo INTO TABLE it_ekpo FOR ALL ENTRIES IN it_field
WHERE ebeln = it_field-ebeln. "
ENDIF.
SORT it_ekpo BY ebeln ebelp.

SELECT ebeln
waers
knumv FROM ekko INTO TABLE ht_ekko FOR ALL ENTRIES IN it_field
WHERE ebeln = it_field-ebeln.

SELECT ebeln
ebelp
matnr
menge
netwr FROM ekpo INTO TABLE ht_ekpo FOR ALL ENTRIES IN it_field WHERE ebeln = it_field-ebeln.

REFRESH: it_field1, ht_ekko1, ht_ekpo2.
CLEAR: wa_field1, hs_ekko1, hs_ekpo2.

it_field1 = it_field.
ht_ekko1 = ht_ekko.
ht_ekpo2 = ht_ekpo.

LOOP AT it_field INTO wa_field.
CLEAR: lv_knumv, lv_kposn.

READ TABLE ht_ekko INTO hs_ekko WITH KEY ebeln = wa_field-ebeln.
lv_knumv = hs_ekko-knumv.

DATA: ht_matnr TYPE mara-matnr.
ht_matnr = wa_field-matnr.

REPLACE ALL OCCURRENCES OF REGEX '-' IN ht_matnr WITH ''.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ht_matnr
IMPORTING
output = ht_matnr.

READ TABLE ht_ekpo INTO hs_ekpo WITH KEY ebeln = wa_field-ebeln
ebelp = wa_field-ebelp
matnr = ht_matnr
IF hs_ekpo IS INITIAL.

READ TABLE ht_ekpo INTO hs_ekpo1 WITH KEY ebeln = wa_field-ebeln
matnr = ht_matnr
ENDIF.

wa_final_alv-bldat = wa_field-bldat.
wa_final_alv-budat = wa_field-budat.
wa_final_alv-ebeln = wa_field-ebeln.

IF hs_ekpo IS NOT INITIAL.
wa_final_alv-ebelp = hs_ekpo-ebelp."wa_field-ebelp.
ELSE.
wa_final_alv-ebelp = hs_ekpo1-ebelp.
ENDIF.

wa_final_alv-lifex = wa_field-lifex.
wa_final_alv-frbnr = wa_field-frbnr.
wa_final_alv-matnr = wa_field-matnr.
wa_final_alv-menge = wa_field-menge.
wa_final_alv-licha = wa_field-licha.
wa_final_alv-vfdat = wa_field-vfdat.
wa_final_alv-exvkw = wa_field-exvkw.
wa_final_alv-zzrecdate = p_zrecda.

c_date = sy-datum.
p_date = c_date - 3.
IF p_zrecda < p_date.
wa_final_alv-zzreason = p_zreaso.
ENDIF.

READ TABLE it_ekpo INTO wa_ekpo WITH KEY ebeln = wa_final_alv-ebeln
ebelp = wa_final_alv-ebelp.
wa_final_alv-txz01 = wa_ekpo-txz01.

wa_final_alv-meins = wa_ekpo-meins.
wa_final_alv-werks = wa_ekpo-werks.
wa_final_alv-lgort = wa_ekpo-lgort.
APPEND wa_final_alv TO it_final_alv.
CLEAR: wa_final_alv, hs_ekpo, hs_ekpo1 .
ENDLOOP.

LOOP AT it_final_alv INTO wa_final_alv.
READ TABLE ht_ekko1 INTO hs_ekko1 WITH KEY ebeln = wa_final_alv-ebeln.
IF sy-subrc EQ 0.
READ TABLE ht_ekpo2 INTO hs_ekpo2 WITH KEY ebeln = wa_final_alv-ebeln
ebelp = wa_final_alv-ebelp.
IF sy-subrc EQ 0.
ls_konv-knumv = hs_ekko1-knumv.
ls_konv-kposn = hs_ekpo2-ebelp.
APPEND ls_konv TO lt_konv_c.
CLEAR ls_konv.

ENDIF.
ENDIF.
ENDLOOP.
SORT lt_konv_c BY knumv kposn.
DELETE ADJACENT DUPLICATES FROM lt_konv_c COMPARING knumv kposn.
SELECT knumv
kposn
kschl
kwert
FROM konv
INTO TABLE lt_konv
FOR ALL ENTRIES IN lt_konv_c
WHERE knumv = lt_konv_c-knumv
AND kposn = lt_konv_c-kposn.

LOOP AT it_final_alv INTO wa_final_alv.
READ TABLE ht_ekpo2 INTO hs_ekpo2 WITH KEY ebeln = wa_final_alv-ebeln
ebelp = wa_final_alv-ebelp.
IF sy-subrc = 0.
CLEAR hs_ekko1.
READ TABLE ht_ekko1 INTO hs_ekko1 WITH KEY ebeln = hs_ekpo2-ebeln.
IF sy-subrc = 0.
ls_konv-kposn = wa_final_alv-ebelp.
CLEAR : hs_ekpo2-netwr,
lv_po_val.
LOOP AT lt_konv INTO ls_konv WHERE knumv = hs_ekko1-knumv
AND kposn = hs_ekpo2-ebelp.
hs_ekpo2-netwr = hs_ekpo2-netwr + ls_konv-kwert.
ENDLOOP.
IF hs_ekko1-waers NE 'INR'.
CALL FUNCTION 'CONVERT_AMOUNT_TO_CURRENCY'
EXPORTING
date = wa_final_alv-budat
foreign_currency = hs_ekko1-waers
foreign_amount = hs_ekpo2-netwr
local_currency = 'INR'
IMPORTING
local_amount = lv_netwr
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc NE 0.
MOVE: hs_ekpo2-netwr TO lv_netwr.
ENDIF.
ELSE.
MOVE: hs_ekpo2-netwr TO lv_netwr.
ENDIF.
lv_po_val = lv_netwr / hs_ekpo2-menge.
lv_po_val = lv_po_val * wa_final_alv-menge.
wa_final_alv-grn = wa_final_alv-grn + lv_po_val.

CLEAR lv_po_val.

MODIFY it_final_alv FROM wa_final_alv.
CLEAR: wa_final_alv.
ENDIF.
ENDIF.
ENDLOOP.

"""""""Field catelog for ALV output"""""

IF it_final_alv IS NOT INITIAL.
wa_layout-colwidth_optimize = 'X'.
wa_fcat-fieldname = 'BLDAT'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 2.
wa_fcat-seltext_m = 'Document Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'BUDAT'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 3.
wa_fcat-seltext_m = 'Posting Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'EBELN'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 4.
wa_fcat-seltext_m = 'Purchase Doc Number'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'EBELP'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 5.
wa_fcat-seltext_m = 'Purchase Doc Item'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'LIFEX'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 6.
wa_fcat-seltext_m = 'Delivery Note'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'FRBNR'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 7.
wa_fcat-seltext_m = 'Bill of Landing'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'MATNR'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 8.
wa_fcat-seltext_m = 'Material Number'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'TXZ01'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 9.
wa_fcat-seltext_m = 'Material Description'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'MENGE'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 10.
wa_fcat-seltext_m = 'Qty'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'MEINS'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 11.
wa_fcat-seltext_m = 'Units'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'WERKS'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 12.
wa_fcat-seltext_m = 'Plant'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'LGORT'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 13.
wa_fcat-seltext_m = 'Storage Location'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'LICHA'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 14.
wa_fcat-seltext_m = 'Vendor Batch'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'VFDAT'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 15.
wa_fcat-seltext_m = 'Shelf Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'EXVKW'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 16.
* wa_fcat-do_sum = 'X'.
wa_fcat-seltext_m = 'MRP'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ZZRECDATE'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 17.
wa_fcat-seltext_m = 'Security Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ZZREASON'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 18.
wa_fcat-seltext_m = 'Reason'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'GRN'.
wa_fcat-tabname = 'IT_FINAL_ALV'.
wa_fcat-col_pos = 18.
wa_fcat-do_sum = 'X'.
wa_fcat-seltext_m = 'GRN Value'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_sort-spos = '01' .
wa_sort-fieldname = 'EBELN'.
wa_sort-tabname = 'IT_FINAL_ALV'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort .
CLEAR wa_sort.

DEFINE add_fcat.
wa_fcat-col_pos = &1.
wa_fcat-fieldname = &2.
wa_fcat-outputlen = &3.
wa_fcat-seltext_s =
wa_fcat-seltext_m =
wa_fcat-seltext_l = &4.
wa_fcat-checkbox = &5.
wa_fcat-edit = &6.
APPEND wa_fcat to it_fcat.
CLEAR wa_fcat.
END-OF-DEFINITION.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'IT_FINAL_ALV'
CHANGING
ct_fieldcat = it_fcat
* it_sort = it_sort
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.
add_fcat 1 'CHECK_FLAG' 10 'Check' 'X' 'X'.
ENDIF.
ENDIF.
""""""""Displaying the ALV output """"""""

IF it_final_alv IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'ACTION'
is_layout = wa_layout
it_fieldcat = it_fcat
it_sort = it_sort
TABLES
t_outtab = it_final_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.
FORM pf_status USING rt_exclude TYPE kkblo_t_extab..
SET PF-STATUS 'ALV_STAT'.

ENDFORM. "SET_PF_STATUS1

FORM action USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.

CLEAR: lt_tab.
DATA : lr_grid TYPE REF TO cl_gui_alv_grid.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lr_grid.

CALL METHOD lr_grid->check_changed_data.

"""""""" Validations for POST Operations""""
IF r_ucomm = 'POST'.

Can write all the validations required during the POST operation
Note:: Please add the validations during the check operations and post operations here because if the user is giving directly the post operation the also it needs to check the validations given in the check operation

""""""""""" BAPI to Create the GR if there are no errors""""
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = wa_header
goodsmvt_code = '01'
* TESTRUN = 'X'
IMPORTING
materialdocument = lv_mblnr
matdocumentyear = lv_mjahr
TABLES
goodsmvt_item = it_item
return = ret
extensionin = it_exn.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = bapita-wait
IMPORTING
return = bapiret2.


 
 IF ret IS  NOT INITIAL.
LOOP AT ret INTO wa_ret.
READ TABLE it_item INTO wa_item INDEX 1.
IF wa_ret-type = 'E'.
ls_msg-msg = 'E'.
ls_msg-ebeln = wa_item-po_number.
ls_msg-msg_text = wa_ret-message.
APPEND ls_msg TO lt_msg.
CLEAR : ls_msg, wa_item.
ENDIF.
ENDLOOP.


ELSEIF ret IS INITIAL AND lv_mblnr IS NOT INITIAL.
DATA : lv_ind TYPE i,
LV_Item TYPE MBLPO.
DATA : it_ekpo TYPE TABLE OF ekpo,
wa_ekpo TYPE ekpo.
SELECT * FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_item
WHERE ebeln = it_item-po_number.
CLEAR : lv_ind.
LOOP AT it_item INTO wa_item.
lv_ind = lv_ind + 1.
wa_zmt_033-mandt = sy-mandt.
wa_zmt_033-mblnr = lv_mblnr.
wa_zmt_033-mjahr = lv_mjahr.
wa_zmt_033-mjahr = lv_mjahr.
wa_zmt_033-zeile = lv_ind.
wa_zmt_033-zzmatnr = wa_item-material.
wa_zmt_033-zzmrp = wa_item-amount_sv.
wa_zmt_033-zzlicha = wa_item-vendrbatch.
wa_zmt_033-zzvfdat = wa_item-expirydate.
wa_zmt_033-zzbwart = '101'.
wa_zmt_033-zzbudat_mkpf = wa_header-pstng_date.
READ TABLE it_ekpo INTO wa_ekpo WITH KEY ebeln = wa_item-po_number
ebelp = wa_item-po_item.
IF sy-subrc = 0.
wa_zmt_033-zzpovalue = wa_ekpo-netpr * wa_item-entry_qnt.
ENDIF.
wa_zmt_033-zzrecdate = wa_exn-zzrecdate.
wa_zmt_033-zzreason = wa_exn-zzreason.
wa_zmt_033-zzpoval = lv_grn.
APPEND wa_zmt_033 TO it_zmt_033.
CLEAR : wa_zmt_033.

ENDLOOP.
IF it_zmt_033 IS NOT INITIAL.
MODIFY zmt_033_mrp FROM TABLE it_zmt_033.
ENDIF.

DATA: ht_mkpf TYPE TABLE OF mkpf,
hs_mkpf TYPE mkpf.
*
CLEAR: hs_mkpf.
WAIT UP TO 4 SECONDS.
SELECT SINGLE * FROM mkpf INTO hs_mkpf WHERE mblnr = lv_mblnr.
IF hs_mkpf IS NOT INITIAL.
hs_mkpf-zzpovalue = lv_grn."wa_exn-zzpovalue.
MODIFY mkpf FROM hs_mkpf.
WAIT UP TO 4 SECONDS.
ENDIF.


DATA: lt_header TYPE STANDARD TABLE OF zmti_grn_hdr,
ls_header TYPE zmti_grn_hdr,
lt_item TYPE STANDARD TABLE OF zmti_grn_itm,
lt_item1 TYPE STANDARD TABLE OF zmti_grn_itm, "ty_grn_item,
lt_item2 TYPE STANDARD TABLE OF zmti_grn_itm,
ls_item TYPE zmti_grn_itm,
ls_item1 TYPE zmti_grn_itm,
ls_item2 TYPE zmti_grn_itm.
DATA: it_final_alv1 TYPE TABLE OF ty_final,
wa_final_alv1 TYPE ty_final.


DATA: lv_ebeln TYPE ekko-ebeln,
lv_lifnr TYPE ekko-lifnr,
lv_bsart TYPE ekko-bsart.

CALL FUNCTION 'ZMMFI_SAP_KEY_GENERATE'
EXPORTING
module = 'MM'
development_no = '010'
number_range_object = 'ZGRN_NR'
IMPORTING
sap_key = ls_header-sap_key.


ls_header-mandt = sy-mandt.
ls_header-mblnr = lv_mblnr.
ls_header-mjahr = lv_mjahr.

it_final_alv1 = it_final_alv.
READ TABLE it_item INTO DATA(is_iteam) INDEX 1.
IF sy-subrc = 0.
DELETE it_final_alv1 WHERE ebeln NE is_iteam-po_number.
ENDIF.
READ TABLE it_final_alv1 INTO wa_final_alv1 INDEX 1.
LOOP AT it_final_alv1 INTO wa_final_alv1 WHERE lgort IS NOT INITIAL.

IF wa_final_alv1 IS NOT INITIAL.
ls_header-werks = wa_final_alv1-werks.
ls_header-lgort = wa_final_alv1-lgort.
ENDIF.
EXIT.
* endif.
ENDLOOP.
ls_header-xblnr = wa_final_alv1-lifex.
ls_header-bldat = wa_final_alv1-bldat.
ls_header-budat = wa_final_alv1-budat.
ls_header-remarks = wa_final_alv1-frbnr.
SELECT SINGLE ebeln
lifnr
bsart
FROM ekko INTO (lv_ebeln , lv_lifnr , lv_bsart)
WHERE ebeln = wa_final_alv1-ebeln.
ls_header-lifnr = lv_lifnr.
IF lv_bsart = 'ZSTO' OR lv_bsart = 'ZINT' OR lv_bsart = 'ZUB'.
ls_header-zsto = 'Y'.
ENDIF.


CLEAR lv_ind.
LOOP AT it_final_alv1 INTO wa_final_alv1.
DATA: ls_ekko TYPE ekko,
lt_konv TYPE TABLE OF konv,
ls_konv TYPE konv.
*
SHIFT wa_final_alv1-matnr LEFT DELETING LEADING ' '.
* .


SELECT SINGLE * FROM ekko INTO ls_ekko
WHERE ebeln = wa_final_alv1-ebeln.
SELECT * FROM konv INTO TABLE lt_konv
WHERE knumv = ls_ekko-knumv.

IF ls_mseg-bwart = '101' OR ls_mseg-bwart = '102' OR ls_mseg-bwart = '501' OR
ls_mseg-bwart = '502' OR ls_mseg-bwart = '561' OR ls_mseg-bwart = '562'.

IF ls_header IS NOT INITIAL.
CASE ls_ekko-bsart.
WHEN 'ZSTO' OR 'ZUB'. "for ZSTO
ls_header-zsto = 'Y'.
DATA: git_mseg TYPE STANDARD TABLE OF mseg,
git_ekko TYPE STANDARD TABLE OF ekko,
git_ekpo TYPE STANDARD TABLE OF ekpo, "
gwa_ekpo TYPE ekpo,
gwa_mseg TYPE mseg,
gwa_ekko TYPE ekko,
lv_cost TYPE kbetr,
lv_landedcost TYPE kbetr.

SELECT * FROM ekko
INTO TABLE git_ekko
WHERE ebeln = wa_final_alv1-ebeln.

SELECT * FROM ekpo INTO TABLE git_ekpo
WHERE ebeln = wa_final_alv1-ebeln
AND ebelp = wa_final_alv1-ebelp.

lv_ind = lv_ind + 1.
ls_item1-mandt = sy-mandt.
ls_item1-mblnr = lv_mblnr.
ls_item1-ebeln = wa_final_alv1-ebeln.
ls_item1-ebelp = wa_final_alv1-ebelp.
ls_item1-zeile = lv_ind.
ls_item1-matnr = wa_final_alv1-matnr.
ls_item1-charg = ls_mseg-charg.
ls_item1-bwart = ls_mseg-bwart.
ls_item1-vfdat = wa_final_alv1-vfdat.
ls_item1-licha = wa_final_alv1-licha.
ls_item1-maktx = wa_final_alv1-txz01.
ls_item1-sap_key = ls_header-sap_key.
ls_item1-zzmrp = wa_final_alv1-exvkw.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = wa_final_alv1-meins
* LANGUAGE = SY-LANGU
IMPORTING
output = wa_final_alv1-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
ls_item1-unit = wa_final_alv1-meins.
ls_item1-menge = wa_final_alv1-menge.
TYPES: BEGIN OF ty_eekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
knttp TYPE knttp,
mwskz TYPE mwskz,
END OF ty_eekpo.

DATA: lt_ekpo TYPE STANDARD TABLE OF ty_eekpo,
ls_ekpo TYPE ty_eekpo.

SELECT ebeln
ebelp
knttp
mwskz
FROM ekpo
INTO TABLE lt_ekpo
FOR ALL ENTRIES IN git_mseg
WHERE ebeln = git_mseg-ebeln
AND ebelp = git_mseg-ebelp
AND knttp NOT IN ('A','K')

DATA: ls_a003 TYPE a003,
lt_a003 TYPE TABLE OF a003.

IF lt_ekpo[] IS NOT INITIAL.
SELECT * FROM a003
INTO TABLE lt_a003
FOR ALL ENTRIES IN lt_ekpo
WHERE mwskz = lt_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'
AND kschl IN ('ZCSC', 'ZVAD','ZVAT','ZVAC','JISG').
DATA: ls_a790 TYPE a790,
lt_a790 TYPE TABLE OF a790.
SELECT * FROM a790
INTO CORRESPONDING FIELDS OF TABLE lt_a790
FOR ALL ENTRIES IN lt_ekpo
WHERE mwskz = lt_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'
AND kschl IN ('JICG','JIIG','JIGS','JIUG',
'JISN',
'JICN',
'JIIN',
'JIUN').
DATA: lt_konp TYPE TABLE OF konp,
ls_konp TYPE konp.

IF lt_a790[] IS NOT INITIAL.
SELECT knumh
kbetr
loevm_ko
FROM konp
INTO TABLE lt_konp
FOR ALL ENTRIES IN lt_a790
WHERE knumh = lt_a790-knumh
AND loevm_ko NE 'X'.
ENDIF.
ENDIF.

lv_ind = 1.
LOOP AT it_final_alv1 INTO wa_final_alv1.
READ TABLE it_final_alv1 INTO wa_final_alv1 WITH KEY matnr = wa_final_alv1-matnr.
IF sy-subrc = 0.
CLEAR ls_item1.
CLEAR gwa_ekpo.
READ TABLE it_final_alv1 INTO wa_final_alv1 WITH KEY
ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp.
READ TABLE git_ekpo INTO gwa_ekpo WITH KEY ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp. "


lv_cost = gwa_ekpo-netpr * ls_mseg-menge.

ls_item1-costprice = lv_cost.
ENDIF.
DATA: lv_knumh TYPE knumh,
lv_kbetr TYPE kbetr_kond,
lv_kbetr1 TYPE kbetr_kond,
gv_mat1 TYPE char2,
gv_mat2 TYPE char8,
it_mseg_temp TYPE TABLE OF mseg,
it_mseg_temp1 TYPE TABLE OF mseg.
**
READ TABLE lt_item1 INTO ls_item1 WITH KEY ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp.
lv_ind = sy-tabix.

READ TABLE lt_ekpo INTO ls_ekpo WITH KEY ebeln = gwa_mseg-ebeln
ebelp = gwa_mseg-ebelp.
IF sy-subrc = 0.
LOOP AT lt_a790 INTO ls_a790 WHERE mwskz = ls_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'.
LOOP AT lt_konp INTO ls_konp WHERE knumh = ls_a790-knumh.
IF ls_konp-kbetr IS NOT INITIAL.
lv_kbetr = ls_konp-kbetr / 10.
ENDIF.
IF ls_a790-kschl = 'JICG'
OR ls_a790-kschl = 'JIGS'
OR ls_a790-kschl = 'JIUG'
OR ls_a790-kschl = 'JISN'
OR ls_a790-kschl = 'JICN'
OR ls_a790-kschl = 'JIUN'.
ls_item1-vat = ls_item1-vat + lv_kbetr. "cgst/sgst
ELSEIF ls_a790-kschl = 'JIIG' OR ls_a790-kschl = 'JIIN'.
ls_item1-cst = ls_item1-cst + lv_kbetr. "igst
ENDIF.
ENDLOOP.
ENDLOOP.
MODIFY lt_item1 FROM ls_item1 .
lv_landedcost = lv_landedcost + ls_item1-costprice.
CLEAR: ls_item1-vat,ls_item1-cst.

CLEAR :ls_konp.
CLEAR lv_kbetr.
ENDIF.
CLEAR ls_item1.
ENDLOOP.
ls_header-landedcost = lv_landedcost.

MODIFY lt_header FROM ls_header INDEX 1 .
WHEN OTHERS. "non- STO


*******For VAT and CST
LV_Item = LV_Item + 1.
ls_item1-mandt = sy-mandt.
ls_item1-mblnr = lv_mblnr.
ls_item1-ebeln = wa_final_alv1-ebeln.
ls_item1-ebelp = wa_final_alv1-ebelp.
ls_item1-zeile = LV_Item.
ls_item1-matnr = wa_final_alv1-matnr.
ls_item1-bwart = ls_mseg-bwart.
ls_item1-vfdat = wa_final_alv1-vfdat.
ls_item1-sap_key = ls_header-sap_key.
ls_item1-zzmrp = wa_final_alv1-exvkw.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = wa_final_alv1-meins
* LANGUAGE = SY-LANGU
IMPORTING
output = wa_final_alv1-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
ls_item1-unit = wa_final_alv1-meins.
ls_item1-menge = wa_final_alv1-menge.


DATA : it_tab TYPE TABLE OF ekbe,
wa_tab TYPE ekbe.

CLEAR : wa_tab.
WAIT UP TO 3 SECONDS.
SELECT SINGLE * FROM ekbe INTO wa_tab
WHERE ebeln = wa_final_alv1-ebeln
AND ebelp = wa_final_alv1-ebelp
AND gjahr = lv_mjahr
AND belnr = lv_mblnr
and BUZEI = LV_Item.
ls_item1-charg = wa_tab-charg.
ls_item1-licha = wa_final_alv1-licha.
ls_item1-maktx = wa_final_alv1-txz01.

SELECT ebeln
ebelp
knttp
mwskz
FROM ekpo
INTO TABLE lt_ekpo
FOR ALL ENTRIES IN it_final_alv1
WHERE ebeln = it_final_alv1-ebeln
AND ebelp = it_final_alv1-ebelp
AND knttp NOT IN ('A','K') .

IF lt_ekpo[] IS NOT INITIAL.
SELECT * FROM a003
INTO TABLE lt_a003
FOR ALL ENTRIES IN lt_ekpo
WHERE mwskz = lt_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'
AND kschl IN ('ZCSC', 'ZVAD','ZVAT','ZVAC').
ENDIF.
SELECT * FROM a790
INTO CORRESPONDING FIELDS OF TABLE lt_a790
FOR ALL ENTRIES IN lt_ekpo
WHERE mwskz = lt_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'
AND kschl IN ('JICG','JIIG','JIGS','JIUG',
'JISN',
'JICN',
'JIIN',
'JIUN').

IF lt_a790[] IS NOT INITIAL.
SELECT *
FROM konp
INTO TABLE lt_konp
FOR ALL ENTRIES IN lt_a790
WHERE knumh = lt_a790-knumh
AND loevm_ko NE 'X'.
ENDIF.
SELECT * FROM ekko
INTO TABLE git_ekko
WHERE ebeln = wa_final_alv1-ebeln.
SELECT * FROM ekpo INTO TABLE git_ekpo
WHERE ebeln = wa_final_alv1-ebeln
AND ebelp = wa_final_alv1-ebelp.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
input = wa_final_alv1-meins
IMPORTING
output = wa_final_alv1-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

DATA lv_maktx TYPE makt-maktx.

CLEAR : lv_matnr,lv_maktx.
SELECT SINGLE matnr
maktx
INTO (lv_matnr, lv_maktx)
FROM makt
WHERE matnr = wa_final_alv1-matnr.

IF lv_maktx IS NOT INITIAL.
ls_item1-maktx = lv_maktx.
ENDIF.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_final_alv1-matnr
IMPORTING
output = wa_final_alv1-matnr.


READ TABLE git_ekko INTO gwa_ekko INDEX 1.
SELECT SINGLE * FROM mseg
INTO gwa_mseg
WHERE
charg = ls_mseg-charg
AND lifnr NE ' '
AND bwart IN ('101','501','561').
APPEND gwa_mseg TO git_mseg.

IF gwa_mseg IS INITIAL. "for stock upload cases
SELECT SINGLE * FROM mseg
INTO gwa_mseg
WHERE "matnr = ls_mseg-matnr
charg = ls_mseg-charg
AND dmbtr EQ ' '
AND bwart IN ('501','561').
APPEND gwa_mseg TO git_mseg.
ENDIF.


**vat , cst
READ TABLE it_final_alv1 INTO wa_final_alv1 WITH KEY matnr = wa_final_alv1-matnr.
IF wa_final_alv1 IS NOT INITIAL." = 0.
READ TABLE it_final_alv1 INTO wa_final_alv1 WITH KEY ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp.
READ TABLE git_ekpo INTO gwa_ekpo WITH KEY ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp.
lv_cost = gwa_ekpo-netpr * wa_final_alv1-menge..
ls_item1-costprice = lv_cost.
ENDIF.

lv_ind = sy-tabix.

READ TABLE lt_ekpo INTO ls_ekpo WITH KEY ebeln = wa_final_alv1-ebeln
ebelp = wa_final_alv1-ebelp.
IF sy-subrc = 0.
LOOP AT lt_a790 INTO ls_a790 WHERE mwskz = ls_ekpo-mwskz
AND kappl = 'TX'
AND aland = 'IN'.
LOOP AT lt_konp INTO ls_konp WHERE knumh = ls_a790-knumh.
IF ls_konp-kbetr IS NOT INITIAL.
lv_kbetr = ls_konp-kbetr / 10.
ENDIF.
IF ls_a790-kschl = 'JICG'
OR ls_a790-kschl = 'JIGS'
OR ls_a790-kschl = 'JIUG'
OR ls_a790-kschl = 'JISN'
OR ls_a790-kschl = 'JICN'
OR ls_a790-kschl = 'JIUN'.
ls_item1-vat = ls_item1-vat + lv_kbetr. "cgst/sgst
ELSEIF ls_a790-kschl = 'JIIG' OR ls_a790-kschl = 'JIIN'.
ls_item1-cst = ls_item1-cst + lv_kbetr. "igst
ENDIF.
ENDLOOP.

ENDLOOP.

lv_landedcost = lv_landedcost + ls_item1-costprice.
ls_header-landedcost = lv_landedcost.



CLEAR :ls_konp.
CLEAR lv_kbetr.
ENDIF.

APPEND ls_item1 TO lt_item1.

DATA: ht_mara TYPE TABLE OF mara,
hs_mara TYPE mara.
DATA: hs_matnr TYPE mara-matnr.

CLEAR hs_matnr.
hs_matnr = wa_final_alv1-matnr..

REPLACE ALL OCCURRENCES OF REGEX '-' IN hs_matnr WITH ''.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = hs_matnr
IMPORTING
output = hs_matnr.
SELECT SINGLE * FROM mara INTO hs_mara
WHERE matnr = hs_matnr."wa_final_alv1-matnr.

IF hs_mara-mtart NE 'FNB'.
APPEND ls_item1 TO lt_item2.
ENDIF.

CLEAR: ls_item1-vat,ls_item1,wa_final_alv1 .
ENDCASE.
ENDIF.
*
ENDIF.
ENDLOOP.
APPEND ls_header TO lt_header.
CLEAR: lv_landedcost.
SORT lt_item1 BY ebelp matnr.

DELETE ADJACENT DUPLICATES FROM lt_item1 COMPARING ebelp matnr zeile.


DATA: gt_ekpo_temp TYPE TABLE OF ekpo, "TY_EKPO,
gs_ekpo_temp TYPE ekpo. "TY_EKPO.

SELECT * FROM ekpo
INTO TABLE gt_ekpo_temp
FOR ALL ENTRIES IN it_final_alv1
WHERE ebeln = it_final_alv1-ebeln
AND ebelp = it_final_alv1-ebelp
AND knttp NOT IN ('A','K').
*
IF gt_ekpo_temp IS NOT INITIAL.
CALL METHOD zcl_grn=>zif_grn~send_data
EXPORTING
lt_header = ls_header
* lt_item1 = lt_item1.
lt_item1 = lt_item2.
CLEAR ls_header.
* ENDIF.
CLEAR lt_item2[].
IF lt_item1[] IS NOT INITIAL AND lt_header[] IS NOT INITIAL.
MODIFY zmti_grn_hdr FROM TABLE lt_header.
MODIFY zmti_grn_itm FROM TABLE lt_item1.
CLEAR : lt_item1[],lt_header[].
ENDIF.
ENDIF.
*
ls_msg-msg = 'S'.
ls_msg-ebeln = wa_item-po_number.
* ls_msg-ebelp = wa_item-po_item.
ls_msg-mblnr = lv_mblnr.
ls_msg-mjahr = lv_mjahr.
ls_msg-msg_text = 'Material Document Created'.
APPEND ls_msg TO lt_msg.
CLEAR : ls_msg.
ENDIF.
REFRESH : it_exn , it_item.
CLEAR : wa_exn , wa_item, wa_header, it_item, lt_item1, ls_header, lt_header.
ENDLOOP.
IF lt_msg IS NOT INITIAL.
PERFORM display1.
* Exit.
ENDIF.
ELSE.
MESSAGE 'The file Contains some error Entries' TYPE 'E'.
ENDIF.
ENDIF.

  IF r_ucomm = 'CHECK'.

All the validations during check operations can be added.

 

 
  IF lt_tab IS NOT INITIAL.
PERFORM fieldcat.
PERFORM display.
ELSE.
MESSAGE 'No Errors' TYPE 'S'.
ENDIF.

ELSEIF r_ucomm = 'SELALL'.
wa_final_alv-check_flag = 'X'.
MODIFY it_final_alv FROM wa_final_alv
TRANSPORTING check_flag
WHERE check_flag = ''.
** DeSelect All Records
ELSEIF r_ucomm = 'DSELALL'.
wa_final_alv-check_flag = ''.
MODIFY it_final_alv FROM wa_final_alv
TRANSPORTING check_flag
WHERE check_flag = 'X'.
ENDIF.
rs_selfield-refresh = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display .
DATA: l_gr_alv TYPE REF TO cl_salv_table,
l_gr_functions TYPE REF TO cl_salv_functions_list,
lr_grid TYPE REF TO cl_salv_form_layout_grid,
lr_layout TYPE REF TO cl_salv_form_layout_logo,
cr_content TYPE REF TO cl_salv_form_element,
lv_title TYPE string,
lv_name TYPE string,
lv_rep TYPE string,
rows TYPE string.



DATA: gr_layout TYPE REF TO cl_salv_layout,
key TYPE salv_s_layout_key,
lv_display TYPE REF TO cl_salv_display_settings.

DATA: lr_selections TYPE REF TO cl_salv_selections,
lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column_table.

TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = l_gr_alv
CHANGING
t_table = lt_tab.
CATCH cx_salv_msg.
ENDTRY.

l_gr_functions = l_gr_alv->get_functions( ).
l_gr_functions->set_all( abap_true ).

lr_columns = l_gr_alv->get_columns( ).
lr_columns->set_optimize( 'X' ).

* Apply zebra style to rows
lv_display = l_gr_alv->get_display_settings( ).
lv_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Enable the save layout buttons
key-report = sy-repid.
gr_layout = l_gr_alv->get_layout( ).
gr_layout->set_key( key ).
gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
gr_layout->set_default( abap_true ).




* Enable cell selection mode
lr_selections = l_gr_alv->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

DATA: p_ddic TYPE salv_s_ddic_reference.
TRY.

lr_column ?= lr_columns->get_column( 'MSGTY').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Message Type' ).

lr_column ?= lr_columns->get_column( 'EBELN').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'PO Number' ).
*


lr_column ?= lr_columns->get_column( 'MATNR').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Material' ).

lr_column ?= lr_columns->get_column( 'MSGV1').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Error Message' ).
ENDTRY.

l_gr_alv->display( ).

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fieldcat .
IF lt_tab IS NOT INITIAL.
wa_layout_tab-colwidth_optimize = 'X'.
wa_fcat_tab-fieldname = 'MSGTY'.
wa_fcat_tab-tabname = 'LT_TAB'.
wa_fcat_tab-col_pos = 1.
wa_fcat_tab-seltext_m = 'Message Type'.
APPEND wa_fcat_tab TO it_fcat_tab.
CLEAR wa_fcat_tab.
wa_fcat_tab-fieldname = 'EBELN'.
wa_fcat_tab-tabname = 'LT_TAB'.
wa_fcat_tab-col_pos = 2.
wa_fcat_tab-seltext_m = 'PO Number'.
APPEND wa_fcat_tab TO it_fcat_tab.
CLEAR wa_fcat_tab.

CLEAR wa_fcat_tab.
wa_fcat_tab-fieldname = 'MATNR'.
wa_fcat_tab-tabname = 'LT_TAB'.
wa_fcat_tab-col_pos = 4.
wa_fcat_tab-seltext_m = 'Material'.
APPEND wa_fcat_tab TO it_fcat_tab.
CLEAR wa_fcat_tab.
wa_fcat_tab-fieldname = 'MSGV1'.
wa_fcat_tab-tabname = 'LT_TAB'.
wa_fcat_tab-col_pos = 5.
wa_fcat_tab-seltext_m = 'Message'.
APPEND wa_fcat_tab TO it_fcat_tab.
CLEAR wa_fcat_tab.
ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display1 .
DATA: l_gr_alv TYPE REF TO cl_salv_table,
l_gr_functions TYPE REF TO cl_salv_functions_list,
lr_grid TYPE REF TO cl_salv_form_layout_grid,
lr_layout TYPE REF TO cl_salv_form_layout_logo,
cr_content TYPE REF TO cl_salv_form_element,
lv_title TYPE string,
lv_name TYPE string,
lv_rep TYPE string,
rows TYPE string.

DATA: gr_layout TYPE REF TO cl_salv_layout,
key TYPE salv_s_layout_key,
lv_display TYPE REF TO cl_salv_display_settings.

DATA: lr_selections TYPE REF TO cl_salv_selections,
lr_columns TYPE REF TO cl_salv_columns,
lr_column TYPE REF TO cl_salv_column_table.


DATA: lv_event_handler TYPE REF TO cl_handler,
lv_events TYPE REF TO cl_salv_events_table.

TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = l_gr_alv
CHANGING
t_table = lt_msg.
CATCH cx_salv_msg.
ENDTRY.

l_gr_functions = l_gr_alv->get_functions( ).
l_gr_functions->set_all( abap_true ).

lr_columns = l_gr_alv->get_columns( ).
lr_columns->set_optimize( 'X' ).

* Apply zebra style to rows
lv_display = l_gr_alv->get_display_settings( ).
lv_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Enable the save layout buttons
key-report = sy-repid.
gr_layout = l_gr_alv->get_layout( ).
gr_layout->set_key( key ).
gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
gr_layout->set_default( abap_true ).

* Register Events

lv_events = l_gr_alv->get_event( ).
CREATE OBJECT lv_event_handler.
SET HANDLER lv_event_handler->on_double_click FOR lv_events.

* Enable cell selection mode
lr_selections = l_gr_alv->get_selections( ).
lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

DATA: p_ddic TYPE salv_s_ddic_reference.
TRY.

lr_column ?= lr_columns->get_column( 'MSG').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Message Type' ).
*
lr_column ?= lr_columns->get_column( 'EBELN').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'PO Number' ).



lr_column ?= lr_columns->get_column( 'MBLNR').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Material Doc' ).

lr_column ?= lr_columns->get_column( 'MJAHR').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Mat.Doc.Year' ).

lr_column ?= lr_columns->get_column( 'MSG_TEXT').
lr_column->set_visible( if_salv_c_bool_sap=>true ).
lr_column->set_long_text( 'Message' ).
ENDTRY.

l_gr_alv->display( ).
ENDFORM.

 

 


 

 

Conclusion:

Once we give the inputs an ALV output is generated and with the post button BAPI will be executed and GR will be generated for all the Purchase orders given.

 

 

 
1 Comment
Labels in this area