ABAP Programs

1. Simple ALV
2. ALV Using Field Catalog
3. Advance ALV
4. Editable ALV
5. ALV With Checkbox
6. ALV With Colour
7. ALV in Module Pool
8. ALV Autorefresh
9. Default Variant
10. Download Data
11. Upload Data in Back Ground
12. Email Report
13. PDF On Screen 1
14. PDF On Screen 2
15. Program To Find User Exit
16. Selection Option in Module Pool
17. Service PO Using BAPI
18. New Tab in PO Using BADI

1. Simple ALV:
*&---------------------------------------------------------------------*
*& Report Y_D_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Y_D_ALV.


TABLES : vbap,vbak.

data: rptname like sy-repid,
w_shift type i.

type-pools: slis.

data: fcat type table of slis_fieldcat_alv with non-unique default key
with header line initial size 0,

fs_layo type slis_layout_alv,

fevents type table of slis_alv_event with non-unique default key
with header line initial size 0,

fheader type table of slis_listheader with non-unique default key
with header line initial size 0,

fexclude type table of slis_extab with non-unique default key
with header line initial size 0,

gt_sort type slis_t_sortinfo_alv.

data : alv_variant like disvariant,
layout type slis_layout_alv.


DATA : BEGIN OF i_vbap OCCURS 0,
vbeln TYPE vbap-vbeln,"CHAR
posnr TYPE vbap-posnr ,"NUMC
matnr TYPE vbap-matnr ,"CHAR
charg TYPE vbap-charg ,"CHAR
matkl TYPE vbap-matkl ,"CHAR
arktx TYPE vbap-arktx ,"CHAR
meins TYPE vbap-meins ,"UNIT
smeng TYPE vbap-smeng ,"QUAN
faksp TYPE vbap-faksp ,"CHAR
spart TYPE vbap-spart ,"CHAR
gsber TYPE vbap-gsber ,"CHAR
netwr TYPE vbap-netwr ,"CURR
waerk TYPE vbap-waerk ,
antlf TYPE vbap-antlf ,
kztlf TYPE vbap-kztlf ,
abgru TYPE vbap-abgru,
chspl TYPE vbap-chspl ,
kwmeng TYPE vbap-kwmeng,
lsmeng TYPE vbap-lsmeng,
kbmeng TYPE vbap-kbmeng,
klmeng TYPE vbap-klmeng,
vrkme TYPE vbap-vrkme ,
umvkz TYPE vbap-umvkz ,
umvkn TYPE vbap-umvkn ,
brgew TYPE vbap-brgew ,
ntgew TYPE vbap-ntgew ,
gewei TYPE vbap-gewei ,
volum TYPE vbap-volum ,
voleh TYPE vbap-voleh ,
vbelv TYPE vbap-vbelv ,
posnv TYPE vbap-posnv ,
vgbel TYPE vbap-vgbel ,
vgpos TYPE vbap-vgpos ,
voref TYPE vbap-voref ,
upflu TYPE vbap-upflu ,
erlre TYPE vbap-erlre ,
lprio TYPE vbap-lprio ,
werks TYPE vbap-werks ,
lgort TYPE vbap-lgort ,
vstel TYPE vbap-vstel ,
erdat TYPE vbap-erdat ,
ernam TYPE vbap-ernam ,
erzet TYPE vbap-erzet ,
netpr TYPE vbap-netpr ,
kpein TYPE vbap-kpein ,
kmein TYPE vbap-kmein ,
shkzg TYPE vbap-shkzg ,
sktof TYPE vbap-sktof ,
mtvfp TYPE vbap-mtvfp ,
sumbd TYPE vbap-sumbd ,
kondm TYPE vbap-kondm ,
ktgrm TYPE vbap-ktgrm ,
provg TYPE vbap-provg ,
eannr TYPE vbap-eannr ,
prsok TYPE vbap-prsok ,
bwtar TYPE vbap-bwtar ,
bwtex TYPE vbap-bwtex ,
xchpf TYPE vbap-xchpf ,
xchar TYPE vbap-xchar ,
lfmng TYPE vbap-lfmng ,
stafo TYPE vbap-stafo ,
wavwr TYPE vbap-wavwr ,
kmpmg TYPE vbap-kmpmg ,
sobkz TYPE vbap-sobkz ,
stcur TYPE vbap-stcur ,
aedat TYPE vbap-aedat ,
audat TYPE vbak-audat,
var1 TYPE icon-id.
DATA : END OF i_vbap.

SELECT-OPTIONS:
p_audat FOR vbak-audat OBLIGATORY DEFAULT sy-datum TO sy-datum,
p_vkorg FOR vbak-vkorg OBLIGATORY NO INTERVALS NO-EXTENSION
DEFAULT '1100'.

parameter : variant type disvariant-variant.



at selection-screen on value-request for variant.
alv_variant-report = sy-repid.
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = alv_variant
i_save = 'A'
importing
es_variant = alv_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
variant = alv_variant-variant.
endif.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Hi this is durgesh'.

Start-of-selection.
SELECT B~vbeln B~posnr B~matnr B~charg B~matkl B~arktx B~meins
B~smeng B~faksp B~spart B~gsber B~netwr B~waerk B~antlf B~kztlf
B~abgru B~chspl
B~kwmeng B~lsmeng B~kbmeng B~klmeng B~vrkme B~umvkz B~umvkn B~brgew
B~ntgew B~gewei B~volum B~voleh B~vbelv B~posnv B~vgbel B~vgpos
B~voref B~upflu
B~erlre B~lprio B~werks B~lgort B~vstel B~erdat B~ernam B~erzet
B~netpr B~kpein B~kmein B~shkzg B~sktof B~mtvfp B~sumbd B~kondm
B~ktgrm B~provg B~eannr
B~prsok B~bwtar B~bwtex B~xchpf B~xchar B~lfmng B~stafo B~wavwr
B~kmpmg B~sobkz B~stcur B~aedat a~audat
INTO CORRESPONDING FIELDS OF TABLE i_vbap
FROM vbak as a INNER JOIN vbap as b on a~vbELN = B~VBELN
WHERE A~audat IN p_audat AND
A~vkorg IN p_vkorg.

IF sy-subrc NE 0.
MESSAGE 'No Data Found...' TYPE 'S'.
EXIT.
ENDIF.


layout-zebra = 'X'.
*layout-no_vline = 'X'. "Vertical Lines between columns will not be
* "shown
*layout-no_hline = 'X'. "Horizontal Lines between columns will not
* "be shown
*layout-edit = 'X'. "Columns can be edit in Grid at run time
*layout-no_colhead = 'X'. "Columns Heading will not be shown


perform build_field_catalog.
rptname = sy-repid.

alv_variant-report = rptname.
alv_variant-variant = variant.

* TO Show Logo in Report
*perform show_pic in program ('Z_LOGO_SCREEN') using sy-repid.


call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = rptname "program name
i_callback_user_command = 'USER_COMMAND'
* i_callback_pf_status_set = 'SM04_SET_STATUS'
"disable
"menubar
is_layout = layout"layout of grid
it_fieldcat = fcat[]"field catalog
it_excluding = fexclude[]
it_sort = gt_sort[]
i_default = 'X'
i_save = 'A'"user specific
is_variant = alv_variant" variant of grid
it_events = fevents[]"top of page
tables
t_outtab = i_vbap[]"final table name
exceptions
program_error = 1
others = 2.

*call function 'REUSE_ALV_GRID_DISPLAY'
* exporting
* i_callback_program = sy-repid
** is_layout = layout
* it_fieldcat = fcat[]
* i_default = 'X'
* i_save = 'A'
* is_variant = alv_variant
* tables
* t_outtab = i_vbap[]
* exceptions
* program_error = 1
* others = 2.
*----------------------------------------------------------------------*
form topofpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = fheader[].

* I_LOGO =
* I_END_OF_LIST_GRID =

endform. "TOPOFPAGE

*&--------------------------------------------------------------------*
*& FORM USER_COMMAND
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
* -->R_UCOMM TEXT
* -->RS_SELFIELDTEXT
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.

read table i_vbap index rs_selfield-tabindex.
if sy-subrc = 0.
set parameter id 'AUN' field i_vbap-vbeln.
call transaction 'VA03'." and skip first screen.
endif.

endform. "USER_COMMAND

*&---------------------------------------------------------------------*
*& Form build_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_field_catalog .
data: w_dthigh(10).

*
* call function 'REUSE_ALV_FIELDCATALOG_MERGE'
* exporting
* i_program_name = sy-repid
* i_internal_tabname = 'I_FINAL'
* i_inclname = sy-repid
* changing
* ct_fieldcat = fcat[].

clear fcat.
fcat-fieldname = 'VBELN'."Field name of Final Table
fcat-outputlen = 11. " Size of Field in Grid
fcat-seltext_s = 'Sales '." For Name of Colunm in Grid
fcat-seltext_m = 'Sales Order No'.
fcat-seltext_l = 'Sales Order No'. " For Tool Tip
* fcat-no_zero = 'X'."All Zero in start of Sales Order Number wll
"be suppressed.
* fcat-checkbox = 'X'. "Field will be shown as Checkboxx
* fcat-no_out = 'X'. "This field will not be show but
"can be select from select layout
* fcat-input = 'X'. "Not Clear
* fcat-icon = 'X'. "display icons
fcat-ddictxt = 'M'."M= fcat-seltext_m, S=fcat-seltext_s,
"L=fcat-seltext_l
fcat-inttype = 'C'. "Alignment N for Right C For Left
fcat-key = 'X'. "Fix the Column.(Col.will not drag
fcat-datatype = 'CHAR'. "Type of field in table
* fcat-do_sum = 'X'. "will display sum of this column
append fcat.

clear fcat.
fcat-fieldname = 'POSNR'.
fcat-outputlen = 10.
fcat-seltext_s = 'Item'.
fcat-seltext_m = 'Item'.
fcat-seltext_l = 'Item'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-key = 'X'.
fcat-datatype = 'NUMC'.
append fcat.
*
clear fcat.
fcat-fieldname = 'MATNR'.
fcat-outputlen = 15.
fcat-seltext_s = 'Material Number '.
fcat-seltext_m = 'Material Number '.
fcat-seltext_l = 'Material Number '.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-key = 'X'.
fcat-datatype = 'CHAR'.
append fcat.
*
clear fcat.
fcat-fieldname = 'CHARG'.
fcat-outputlen = 15.
fcat-seltext_s = 'Batch Numb'.
fcat-seltext_m = 'Batch Numb'.
fcat-seltext_l = 'Batch Numb'.
fcat-ddictxt = 'L'.
fcat-inttype = 'C'.
fcat-key = 'X'.
fcat-datatype = 'CHAR'.
append fcat.

clear fcat.
fcat-fieldname = 'MATKL'.
fcat-outputlen = 25.
fcat-seltext_s = 'MGroup '.
fcat-seltext_m = 'MGroup '.
fcat-seltext_l = 'MGroup '.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
* fcat-emphasize = 'C200'.
append fcat.

clear fcat.
fcat-fieldname = 'ARKTX'.
fcat-outputlen = 15.
fcat-seltext_s = 'Description '.
fcat-seltext_m = 'Description '.
fcat-seltext_l = 'Description '.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
*
clear fcat.
fcat-fieldname = 'MEINS'.
fcat-outputlen = 5.
fcat-seltext_s = 'UOM'.
fcat-seltext_m = 'UOM'.
fcat-seltext_l = 'UOM'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'UNIT'.
append fcat.

clear fcat.
fcat-fieldname = 'SMENG'.
fcat-outputlen = 5.
fcat-seltext_s = 'Scale Quantity '.
fcat-seltext_m = 'Scale Quantity '.
fcat-seltext_l = 'Scale Quantity '.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'QUAN'.
* fcat-emphasize = 'C200'.
append fcat.

clear fcat.
fcat-fieldname = 'FAKSP'.
fcat-outputlen = 5.
fcat-seltext_s = 'Bi'.
fcat-seltext_m = 'Bi'.
fcat-seltext_l = 'Bi'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
* fcat-emphasize = 'C200'.
append fcat.
*
clear fcat.
fcat-fieldname = 'SPART'.
fcat-outputlen = 10.
fcat-seltext_s = 'Di'.
fcat-seltext_m = 'Di'.
fcat-seltext_l = 'Di'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
* fcat-emphasize = 'C200'.
append fcat.

clear fcat.
fcat-fieldname = 'GSBER'.
fcat-outputlen = 20.
fcat-seltext_s = 'Area'.
fcat-seltext_m = 'Area'.
fcat-seltext_l = 'Area'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
* fcat-emphasize = 'C200'.
append fcat.

clear fcat.
fcat-fieldname = 'NETWR'.
fcat-outputlen = 35.
fcat-seltext_s = 'Net Value'.
fcat-seltext_m = 'Net Value'.
fcat-seltext_l = 'Net Value'.
* fcat-ddictxt = 'M'.
fcat-datatype = 'CURR'.

* fcat-emphasize = 'C200'.
append fcat.
*
*
* clear fcat.
* fcat-fieldname = 'WAERK'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'Curr.'.
* fcat-seltext_m = 'Curr.'.
* fcat-seltext_l = 'Curr.'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'CHAR'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'ANTLF'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'M'.
* fcat-seltext_m = 'M'.
* fcat-seltext_l = 'M'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'CHAR'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'KZTLF'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'P'.
* fcat-seltext_m = 'P'.
* fcat-seltext_l = 'P'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'CHAR'.
** fcat-emphasize = 'C200'.
* append fcat.
**
* clear fcat.
* fcat-fieldname = 'ABGRU'.
* fcat-outputlen = 5.
* fcat-seltext_s = 'Rr'.
* fcat-seltext_m = 'Rr'.
* fcat-seltext_l = 'Rr'.
* fcat-ddictxt = 'Rr'.
* fcat-inttype = 'Rr'.
* fcat-datatype = 'Rr'.
** fcat-emphasize = 'Rr'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'CHSPL'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'b'.
* fcat-seltext_m = 'b'.
* fcat-seltext_l = 'b'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'DATS'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'KWMENG'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'sales Unit'.
* fcat-seltext_m = 'sales Unit'.
* fcat-seltext_l = 'sales Unit'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'DATS'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'LSMENG'.
* fcat-outputlen = 15.
* fcat-seltext_s = 'Requires Quantity'.
* fcat-seltext_m = 'Requires Quantity'.
* fcat-seltext_l = 'Requires Quantity'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'KBMENG'.
* fcat-outputlen = 10.
* fcat-seltext_s = 'Dilivered Quantity'.
* fcat-seltext_m = 'Dilivered Quantity'.
* fcat-seltext_l = 'Dilivered Quantity'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'KLMENG'.
* fcat-outputlen = 10.
* fcat-seltext_s = 'confirm quantity '.
* fcat-seltext_m = 'confirm quantity '.
* fcat-seltext_l = 'confirm quantity '.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
**
* clear fcat.
* fcat-fieldname = 'VRKME'.
* fcat-outputlen = 10.
* fcat-seltext_s = 'sal'.
* fcat-seltext_m = 'sal'.
* fcat-seltext_l = 'sal'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
*
* clear fcat.
* fcat-fieldname = 'UMVKG'.
* fcat-outputlen = 5.
* fcat-seltext_s = 'numrtr'.
* fcat-seltext_m = 'numrtr'.
* fcat-seltext_l = 'numrtr'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'UMVKN'.
* fcat-outputlen = 10.
* fcat-seltext_s = 'Conver'.
* fcat-seltext_m = 'Conver'.
* fcat-seltext_l = 'Conver'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'CHAR'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'BRGEW'.
* fcat-outputlen = 5.
* fcat-seltext_s = 'Gross Wight'.
* fcat-seltext_m = 'Gross Wight'.
* fcat-seltext_l = 'Gross Wight'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'NTGEW'.
* fcat-outputlen = 10.
* fcat-seltext_s = 'Net Weight'.
* fcat-seltext_m = 'Net Weight'.
* fcat-seltext_l = 'Net Weight'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'NUMC'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'GEWIE'.
* fcat-outputlen = 5.
* fcat-seltext_s = 'uni'.
* fcat-seltext_m = 'uni'.
* fcat-seltext_l = 'uni'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'CHAR'.
** fcat-emphasize = 'C200'.
* append fcat.
*
* clear fcat.
* fcat-fieldname = 'AUDAT'.
* fcat-outputlen = 5.
* fcat-seltext_s = 'Date'.
* fcat-seltext_m = 'Date'.
* fcat-seltext_l = 'Date'.
* fcat-ddictxt = 'M'.
* fcat-inttype = 'C'.
* fcat-datatype = 'DATS'.
** fcat-datatype = 'DAT'.
** fcat-emphasize = 'C200'.
* append fcat.



*************** To Show Header Description of Reportt****************
fheader-typ = 'H'.

fheader-info = 'RAJASTHAN TEXTILE MILLS, BHAWANIMANDI'.
append fheader.
clear fheader.

* To show in Italic Style
fheader-typ = 'A' .

fheader-info = 'Pachpahar Road'.
append fheader.
clear fheader.

* To Show in small character
* Info is Char 60 Colunm
* typ is Char 1 Column
fheader-typ = 'S'.
fheader-info = ' List of Sale Orders for Testing in ALV Report'.
append fheader.
clear fheader.

fheader-typ = 'S'.
data : trptdt(10) type c.
data : xdt type string.
write : sy-datum to trptdt.
concatenate 'Report run date : ' trptdt into xdt separated by space.

fheader-typ = 'S'.
fheader-info = xdt.
append fheader.
clear fheader.
************************************************************************
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = fevents[]
exceptions
list_type_wrong = 1
others = 2.

* This Statement will print the Heading on Pages
read table fevents with key name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
fevents-form = 'TOPOFPAGE'.
modify fevents index sy-tabix.
clear fevents.
endif.

* BREAK Stildev01.
read table fevents with key name = 'USER_COMMAND'.
if sy-subrc = 0.
fevents-form = 'USER_COMMAND'.
modify fevents index sy-tabix.
clear fevents.
endif.
endform.

2. ALV Using Field Catalog:
Note: Using field catalog function we have to define final table by using keyword “LIKE” rather than “TYPE”

*&---------------------------------------------------------------------*
*& Report Y_D_ALV1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Y_D_ALV1.


TABLES : vbak.

data: rptname like sy-repid.
* w_shift type i.

type-pools: slis.

data: fcat type table of slis_fieldcat_alv with non-unique default key
with header line initial size 0,

fevents type table of slis_alv_event with non-unique default key
with header line initial size 0,

fheader type table of slis_listheader with non-unique default key
with header line initial size 0,

fexclude type table of slis_extab with non-unique default key
with header line initial size 0,

gt_sort type slis_t_sortinfo_alv.

data : alv_variant like disvariant,
layout type slis_layout_alv.


DATA : BEGIN OF i_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr ,
matnr LIKE vbap-matnr ,
charg LIKE vbap-charg ,
matkl LIKE vbap-matkl ,
arktx LIKE vbap-arktx ,
meins LIKE vbap-meins ,
smeng LIKE vbap-smeng ,
faksp LIKE vbap-faksp ,
spart LIKE vbap-spart ,
gsber LIKE vbap-gsber ,
netwr LIKE vbap-netwr ,
waerk LIKE vbap-waerk ,
antlf LIKE vbap-antlf ,
kztlf LIKE vbap-kztlf ,
abgru LIKE vbap-abgru,
chspl LIKE vbap-chspl ,
kwmeng LIKE vbap-kwmeng,
lsmeng LIKE vbap-lsmeng,
kbmeng LIKE vbap-kbmeng,
klmeng LIKE vbap-klmeng,
vrkme LIKE vbap-vrkme ,
umvkz LIKE vbap-umvkz ,
umvkn LIKE vbap-umvkn ,
brgew LIKE vbap-brgew ,
ntgew LIKE vbap-ntgew ,
gewei LIKE vbap-gewei ,
volum LIKE vbap-volum ,
voleh LIKE vbap-voleh ,
vbelv LIKE vbap-vbelv ,
posnv LIKE vbap-posnv ,
vgbel LIKE vbap-vgbel ,
vgpos LIKE vbap-vgpos ,
voref LIKE vbap-voref ,
upflu LIKE vbap-upflu ,
erlre LIKE vbap-erlre ,
lprio LIKE vbap-lprio ,
werks LIKE vbap-werks ,
lgort LIKE vbap-lgort ,
vstel LIKE vbap-vstel ,
erdat LIKE vbap-erdat ,
ernam LIKE vbap-ernam ,
erzet LIKE vbap-erzet ,
netpr LIKE vbap-netpr ,
kpein LIKE vbap-kpein ,
kmein LIKE vbap-kmein ,
shkzg LIKE vbap-shkzg ,
sktof LIKE vbap-sktof ,
mtvfp LIKE vbap-mtvfp ,
sumbd LIKE vbap-sumbd ,
kondm LIKE vbap-kondm ,
ktgrm LIKE vbap-ktgrm ,
provg LIKE vbap-provg ,
eannr LIKE vbap-eannr ,
prsok LIKE vbap-prsok ,
bwtar LIKE vbap-bwtar ,
bwtex LIKE vbap-bwtex ,
xchpf LIKE vbap-xchpf ,
xchar LIKE vbap-xchar ,
lfmng LIKE vbap-lfmng ,
stafo LIKE vbap-stafo ,
wavwr LIKE vbap-wavwr ,
kmpmg LIKE vbap-kmpmg ,
sobkz LIKE vbap-sobkz ,
stcur LIKE vbap-stcur ,
aedat LIKE vbap-aedat ,
audat LIKE vbak-audat.
* var1 TYPE icon-id.
DATA : END OF i_vbap.

SELECT-OPTIONS:
p_audat FOR vbak-audat OBLIGATORY DEFAULT sy-datum TO sy-datum,
p_vkorg FOR vbak-vkorg OBLIGATORY NO INTERVALS NO-EXTENSION
DEFAULT '1100'.

parameter : variant type disvariant-variant.



at selection-screen on value-request for variant.
alv_variant-report = sy-repid.
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = alv_variant
i_save = 'A'
importing
es_variant = alv_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
variant = alv_variant-variant.
endif.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Hi this is durgesh'.

Start-of-selection.
SELECT B~vbeln B~posnr B~matnr B~charg B~matkl B~arktx B~meins
B~smeng B~faksp B~spart B~gsber B~netwr B~waerk B~antlf B~kztlf
B~abgru B~chspl
B~kwmeng B~lsmeng B~kbmeng B~klmeng B~vrkme B~umvkz B~umvkn B~brgew
B~ntgew B~gewei B~volum B~voleh B~vbelv B~posnv B~vgbel B~vgpos
B~voref B~upflu
B~erlre B~lprio B~werks B~lgort B~vstel B~erdat B~ernam B~erzet
B~netpr B~kpein B~kmein B~shkzg B~sktof B~mtvfp B~sumbd B~kondm
B~ktgrm B~provg B~eannr
B~prsok B~bwtar B~bwtex B~xchpf B~xchar B~lfmng B~stafo B~wavwr
B~kmpmg B~sobkz B~stcur B~aedat a~audat
INTO CORRESPONDING FIELDS OF TABLE i_vbap
FROM vbak as a INNER JOIN vbap as b on a~vbELN = B~VBELN
WHERE A~audat IN p_audat AND
A~vkorg IN p_vkorg.

IF sy-subrc NE 0.
MESSAGE 'No Data Found...' TYPE 'S'.
EXIT.
ENDIF.


layout-zebra = 'X'.

perform build_field_catalog.
rptname = sy-repid.

alv_variant-report = rptname.
alv_variant-variant = variant.

* TO Show Logo in Report
*perform show_pic in program ('Z_LOGO_SCREEN') using sy-repid.


call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = rptname "program name
i_callback_user_command = 'USER_COMMAND'
* i_callback_pf_status_set = 'SM04_SET_STATUS'
"disable
"menubar
is_layout = layout"layout of grid
it_fieldcat = fcat[]"field catalog
it_excluding = fexclude[]"remove icon from toolbar
it_sort = gt_sort[]
i_default = 'X'
i_save = 'A'"user specific
is_variant = alv_variant" variant of grid
i_grid_title = 'DURGESH'"Display Title of grid
it_events = fevents[]"top of page
tables
t_outtab = i_vbap[]"final table name
exceptions
program_error = 1
others = 2.


*----------------------------------------------------------------------*
form topofpage.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = fheader[].

* I_LOGO =
* I_END_OF_LIST_GRID =

endform. "TOPOFPAGE

*&--------------------------------------------------------------------*
*& FORM USER_COMMAND
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
* -->R_UCOMM TEXT
* -->RS_SELFIELDTEXT
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.

read table i_vbap index rs_selfield-tabindex.
if sy-subrc = 0.
set parameter id 'AUN' field i_vbap-vbeln.
call transaction 'VA03'." and skip first screen.
endif.


endform. "USER_COMMAND

*&---------------------------------------------------------------------*
*& Form build_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form build_field_catalog .
* data: w_dthigh(10).
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'I_VBAP'
i_inclname = sy-repid
changing
ct_fieldcat = fcat[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

*************** To Show Header Description of Reportt****************
fheader-typ = 'H'.

fheader-info = 'RAJASTHAN TEXTILE MILLS, BHAWANIMANDI'.
append fheader.
clear fheader.

* To show in Italic Style
fheader-typ = 'A' .

fheader-info = 'Pachpahar Road'.
append fheader.
clear fheader.

fheader-typ = 'S'.
fheader-info = ' List of Sale Orders for Testing in ALV Report'.
append fheader.
clear fheader.

fheader-typ = 'S'.
data : trptdt(10) type c.
data : xdt type string.
write : sy-datum to trptdt.
concatenate 'Report run date : ' trptdt into xdt separated by space.

fheader-typ = 'S'.
fheader-info = xdt.
append fheader.
clear fheader.
************************************************************************
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = fevents[]
exceptions
list_type_wrong = 1
others = 2.

* This Statement will print the Heading on Pages
read table fevents with key name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
fevents-form = 'TOPOFPAGE'.
modify fevents index sy-tabix.
clear fevents.
endif.

fexclude-fcode = '&ABC'.
append fexclude.
clear fexclude.
endform.

3. Advance ALV:
*&---------------------------------------------------------------------*
*& Report Z_MM_REP_BTMCSTK *
*&---------------------------------------------------------------------*
*& T.Krishna Chaitanya *
*& BTM Lot Wise Current & Special Stock Report *
*&---------------------------------------------------------------------*

report z_mm_rep_btmcstk message-id zmsg.

tables : mchb,t148,mara.
type-pools : slis.

data : begin of i_mchb occurs 50,
matnr like mchb-matnr,
werks like mchb-werks,
lgort like mchb-lgort,
charg like mchb-charg,
lvorm like mchb-lvorm,
clabs like mchb-clabs, "Valuated Unrestricted-Use Stock
cumlm like mchb-cumlm, "Stock in transfer
cinsm like mchb-cinsm, "Stock in Quality Inspection
ceinm like mchb-ceinm, "Total Stock of All Restricted Batches
cspem like mchb-cspem, "Blocked Stock
cretm like mchb-cretm, "Blocked Stock Returns
end of i_mchb,

begin of i_mska occurs 50,
matnr like mska-matnr,
werks like mska-werks,
lgort like mska-lgort,
charg like mska-charg,
sobkz like mska-sobkz,
kalab like mska-kalab, " Valuated Unrestricted-Use Stock
kains like mska-kains, " Stock in Quality Inspection
kaspe like mska-kaspe, " Blocked Stock
end of i_mska,

begin of i_matnr occurs 50,
matnr like mara-matnr,
mtart like mara-mtart,
matkl like mara-matkl,
werks like marc-werks,
end of i_matnr,

begin of i_makt occurs 10,
matnr like mara-matnr,
maktx like makt-maktx,
end of i_makt,

begin of i_out occurs 0,
matnr like mchb-matnr,
charg like mchb-charg,
maktx like makt-maktx,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mchb-werks,
lgort like mchb-lgort,
lotno like ausp-atwrt,
sobkz like mska-sobkz,
clabs like mchb-clabs, "Valuated Unrestricted-Use Stock
cumlm like mchb-cumlm, "Stock in transfer
cinsm like mchb-cinsm, "Stock in Quality Inspection
ceinm like mchb-ceinm, "Total Stock of All Restricted Batches
cspem like mchb-cspem, "Blocked Stock
cretm like mchb-cretm, "Blocked Stock Returns
end of i_out,

begin of i_mch1 occurs 50,
matnr like mch1-matnr,
charg like mch1-charg,
cuobj_bm like ausp-objek,
end of i_mch1,

begin of i_ausp occurs 50,
objek type ausp-objek,
atinn type ausp-atinn,
atwrt type ausp-atwrt,
end of i_ausp,

v_atinn type cabn-atinn,
v_atnam type cabn-atnam value 'LOT_NO',
v_lines type i.
*-> ALV
data : alv_variant like disvariant,
fcat type table of slis_fieldcat_alv with header line,
layout type slis_layout_alv.


selection-screen begin of block b1 with frame title text-001.
select-options : werks for mchb-werks,
lgort for mchb-lgort,
charg for mchb-charg,
sobkz for t148-sobkz modif id gp1.
selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-002.
select-options : matnr for mara-matnr,
mtart for mara-mtart,
matkl for mara-matkl.
selection-screen end of block b2.

selection-screen begin of block b3 with frame title text-004.
parameters : variant type disvariant-variant.
selection-screen end of block b3.

selection-screen begin of block b4 with frame title text-003.
parameters : rd1 radiobutton group rad user-command rd default 'X',
rd2 radiobutton group rad,
rd3 radiobutton group rad.
selection-screen end of block b4.

*-> Hide Special Stock
at selection-screen output.
loop at screen.
if rd1 = 'X'.
if screen-group1 = 'GP1'.
screen-input = 0.
screen-active = 0.
screen-required = 1.
modify screen.
endif.
endif.
endloop.
*-> ALV Layout
at selection-screen on value-request for variant.
alv_variant-report = sy-repid.
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = alv_variant
i_save = 'A'
importing
es_variant = alv_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
variant = alv_variant-variant.
endif.


*-> Program Start
start-of-selection.
*-> Mandatory Fields
if werks[] is initial.
message i011 with 'Maintain Plant'.
exit.
endif.
if mtart[] is initial.
message i011 with 'Maintain Material type'.
exit.
endif.

*-> Get the character Name
v_atnam = 'LOT_NO'.
select single atinn
from cabn
into v_atinn
where atnam = v_atnam.

*-> Data Selection

*-> Select main Stock from mchb table
if rd3 ne 'X'.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Read Current Stock'.
select matnr
werks
lgort
charg
lvorm
clabs
cumlm
cinsm
ceinm
cspem
cretm
from mchb
into table i_mchb
where matnr in matnr
and werks in werks
and lgort in lgort
and charg in charg
and lvorm eq space.
if sy-subrc <> 0.
message i011 with 'No Stock'.
endif.
endif.

delete i_mchb where clabs is initial
and cumlm is initial
and cinsm is initial
and ceinm is initial
and cspem is initial
and cretm is initial.

if rd1 ne 'X'.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Read Current Special Stock'.
select matnr
werks
lgort
charg
sobkz
kalab " Valuated Unrestricted-Use Stock
kains " Stock in Quality Inspection
kaspe " blocked stock
from mska
into table i_mska
where matnr in matnr
and werks in werks
and lgort in lgort
and charg in charg
and sobkz in sobkz.
if sy-subrc <> 0.
message i011 with 'No Special Stock'.
endif.
endif.
delete i_mska where kalab is initial " Unrestricted-Stock
and kains is initial " Stock in Qual Inspection
and kaspe is initial. " blocked stock

if i_mchb[] is initial and i_mska[] is initial.
message s011 with 'NO Data'.
exit.
endif.


call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Read Material Master'.

select mara~matnr
mara~mtart
mara~matkl
marc~werks
into table i_matnr
from mara
join marc
on marc~matnr = mara~matnr
where mara~matnr in matnr
and mara~mtart in mtart
and mara~matkl in matkl
and marc~werks in werks.
if sy-subrc = 0.
select matnr
maktx
from makt
into table i_makt
for all entries in i_matnr
where matnr eq i_matnr-matnr.
endif.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Calculate Stock'.

sort i_matnr by matnr.
sort i_makt by matnr.

loop at i_mchb.
read table i_makt with key matnr = i_mchb-matnr
binary search.
read table i_matnr with key matnr = i_mchb-matnr
binary search.
if sy-subrc = 0.
i_out-matnr = i_mchb-matnr.
i_out-werks = i_mchb-werks.
i_out-lgort = i_mchb-lgort.
i_out-charg = i_mchb-charg.
i_out-maktx = i_makt-maktx.
i_out-mtart = i_matnr-mtart.
i_out-matkl = i_matnr-matkl.
i_out-clabs = i_mchb-clabs. "Unrestricted-Stock
i_out-cumlm = i_mchb-cumlm. "Stock in transfer
i_out-cinsm = i_mchb-cinsm. "Stock in Quality Inspection
i_out-ceinm = i_mchb-ceinm. "Total Stk of All Restricted Batche
i_out-cspem = i_mchb-cspem. "Blocked Stock
i_out-cretm = i_mchb-cretm. "Blocked Stock Returns
append i_out.
clear : i_out,i_matnr.
endif.
endloop.
sort i_matnr by matnr.
sort i_makt by matnr.

loop at i_mska.
read table i_makt with key matnr = i_mska-matnr
binary search.
read table i_matnr with key matnr = i_mska-matnr
binary search.

if sy-subrc = 0.
i_out-matnr = i_mska-matnr.
i_out-werks = i_mska-werks.
i_out-lgort = i_mska-lgort.
i_out-charg = i_mska-charg.
i_out-maktx = i_makt-maktx.
i_out-mtart = i_matnr-mtart.
i_out-matkl = i_matnr-matkl.
i_out-sobkz = i_mska-sobkz.
i_out-clabs = i_mska-kalab. "Unrestricted-Stock
i_out-cinsm = i_mska-kains. "Stock in Quality Inspection
i_out-cspem = i_mska-kaspe. "Blocked Stock
append i_out.
clear : i_out,i_matnr.
endif.
endloop.

free : i_mchb,i_mska.
sort i_out by matnr charg.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Read Batch Classification'.

if i_out[] is not initial.
select matnr
charg
cuobj_bm
from mch1
into table i_mch1
for all entries in i_out
where matnr = i_out-matnr
and charg = i_out-charg.
endif.

if i_mch1[] is not initial.
select objek
atinn
atwrt
from ausp
into table i_ausp
for all entries in i_mch1
where objek = i_mch1-cuobj_bm
and atinn = v_atinn.
endif.

call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Prepare Final List'.

sort i_mch1 by matnr charg.
sort i_ausp by objek.

loop at i_out.
read table i_mch1 with key matnr = i_out-matnr
charg = i_out-charg
binary search.
read table i_ausp with key objek = i_mch1-cuobj_bm
binary search.

if sy-subrc = 0.
i_out-lotno = i_ausp-atwrt.
modify i_out transporting lotno.
endif.
clear : i_mch1,i_ausp.
endloop.

*-> ALV
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'I_OUT'
i_inclname = sy-repid
changing
ct_fieldcat = fcat[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

loop at fcat.
clear fcat-key.
if fcat-fieldname = 'LOTNO'.
fcat-seltext_s = fcat-seltext_m = fcat-seltext_l = 'Lot no'.
fcat-reptext_ddic = fcat-seltext_l.
fcat-ddictxt = 'L'.
fcat-outputlen = '10'.
endif.
if fcat-fieldname = 'SOBKZ'.
fcat-outputlen = '10'.
endif.
if fcat-fieldname = 'WERKS' or fcat-fieldname = 'LGORT'
or fcat-fieldname = 'MTART'.
fcat-outputlen = '6'.
endif.
modify fcat.
endloop.
layout-zebra = 'X'.

describe table i_out lines v_lines.

message s011 with v_lines 'Records'.

alv_variant-report = sy-repid.
alv_variant-variant = variant.

call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
is_layout = layout
it_fieldcat = fcat[]
i_default = 'X'
i_save = 'A'
is_variant = alv_variant
tables
t_outtab = i_out[]
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

4. Editable ALV:
*&---------------------------------------------------------------------*
*& Report yfdntn_RPT
*& By : Avadhesh Sharma
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report yfdntn_rpt.
tables : yfdntn,knkk.
type-pools slis.
data : i_fcat type table of slis_fieldcat_alv with header line,

fs_layo type slis_layout_alv,

fevents type table of slis_alv_event with non-unique default key
with header line initial size 0,

fheader type table of slis_listheader with non-unique default key
with header line initial size 0,

fexclude type table of slis_extab with non-unique default key
with header line initial size 0,

gt_sort type slis_t_sortinfo_alv.

data: begin of i_yfdntn occurs 0,
mandt like yfdntn-mandt ,
bukrs like yfdntn-bukrs ,
dbtno like yfdntn-dbtno ,
dnsno like yfdntn-dnsno ,
frmdt like yfdntn-frmdt ,
todat like yfdntn-todat ,
issdt like yfdntn-issdt ,
werks like yfdntn-werks ,
kunnr like yfdntn-kunnr ,
name1 like yfdntn-name1 ,
ort01 like yfdntn-ort01 ,
xblnr like yfdntn-xblnr ,
vbeln like yfdntn-vbeln ,
bldat like yfdntn-bldat ,
duedt like yfdntn-duedt ,
dued1 like yfdntn-dued1 ,
zterm like yfdntn-zterm ,
recdt like yfdntn-recdt ,
ldays like yfdntn-ldays ,
reamt like yfdntn-reamt ,
vzskz like yfdntn-vzskz ,
inamt like yfdntn-inamt ,
inrdt like yfdntn-inrdt ,
inram like yfdntn-inram ,
tdamt like yfdntn-tdamt ,
rmamt like yfdntn-rmamt ,
clrdc like yfdntn-clrdc ,
clrdt like yfdntn-clrdt ,
belnr like yfdntn-belnr ,
blamt like yfdntn-blamt ,
remark like yfdntn-remark.
data : end of i_yfdntn.

data : begin of i_knkk occurs 0,
kunnr type knkk-kunnr,
kkber type knkk-kkber,
sbgrp type knkk-sbgrp.
data : end of i_knkk.

data : begin of i_knk occurs 0,
kunnr type knkk-kunnr,
kkber type knkk-kkber,
sbgrp type knkk-sbgrp.
data : end of i_knk.

data : w_answer type c.
data : ind type sy-tabix,
t_flg type i value 0.

selection-screen begin of block blk with frame title text-001.
select-options: vbukrs for yfdntn-bukrs no-extension no intervals
obligatory,
vdbtno for yfdntn-dbtno obligatory,
vdnsno for yfdntn-dnsno no-display,
vfrmdt for yfdntn-frmdt no-display,
vtodat for yfdntn-todat no-display,
s_sbgrp for knkk-sbgrp no intervals obligatory,

vkunnr for yfdntn-kunnr ,
vissdt for yfdntn-issdt ,
vwerks for yfdntn-werks no-display.

selection-screen end of block blk.
*AUTHORITY-CHECK

*PARAMETERS carr TYPE spfli-carrid.
*
*AT SELECTION-SCREEN.
* AUTHORITY-CHECK OBJECT 'S_CARRID'
* ID 'CARRID' FIELD carr
* ID 'ACTVT' FIELD '03'.
*
* IF sy-subrc <> 0.
* MESSAGE 'No authorization' TYPE 'E'.
* ENDIF.
*
*--Company code validation
at selection-screen on vbukrs.
perform company_code_check.


at selection-screen on vdbtno.

if vdbtno-low is not initial.
loop at vdbtno where low is not initial.
find '*' in vdbtno-low.
if sy-subrc <> 0.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = vdbtno-low
importing
output = vdbtno-low.
modify vdbtno.
endif.
endloop.
endif.

if vdbtno-high is not initial.
loop at vdbtno where high is not initial.
find '*' in vdbtno-high.
if sy-subrc <> 0.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = vdbtno-high
importing
output = vdbtno-high.
modify vdbtno.
endif.
endloop.
endif.


at selection-screen on s_sbgrp.
if s_sbgrp-low = '*' .
select kunnr
kkber
sbgrp
into table i_knk
from knkk
where kkber = vbukrs.
sort i_knk.
delete adjacent duplicates from i_knk comparing kkber sbgrp.
loop at i_knk.
ind = sy-tabix.
authority-check object 'ZSBGRP'
id 'SBGRP' field i_knk-sbgrp.

if sy-subrc <> 0.
message 'No authorization for Credit Rep. group' type 'E'.

exit.
endif.
sy-tabix = ind.
endloop.
else.
loop at s_sbgrp.
ind = sy-tabix.

authority-check object 'ZSBGRP'
id 'SBGRP' field s_sbgrp-low.

if sy-subrc <> 0.
message 'No authorization for Credit Rep. group' type 'S'.
t_flg = 1.
exit.
endif.
sy-tabix = ind.
endloop.
endif.


start-of-selection.
*--------Authorization for Credit Rep. Group -------------------------
if s_sbgrp[] is not initial.
select kunnr
kkber
sbgrp
into table i_knkk
from knkk
where sbgrp in s_sbgrp and
kunnr in vkunnr.

if s_sbgrp-low <> '*'.
if i_knkk[] is initial.
message 'No Data Found...check Customer / Credit Group' type 'S'.
exit.
else.
clear : vkunnr.
loop at i_knkk.
ind = sy-tabix.
vkunnr-sign = 'I'.
vkunnr-option = 'EQ'.
vkunnr-low = i_knkk-kunnr.
append vkunnr.
sy-tabix = ind.
endloop.
endif.
endif.
endif.

*--------Authorization for Credit Rep. Group -------------------------

select bukrs
dbtno
dnsno
frmdt
todat
issdt
werks
kunnr
name1
ort01
xblnr
vbeln
bldat
duedt
dued1
zterm
recdt
ldays
reamt
vzskz
inamt
inrdt
inram
tdamt
rmamt
clrdc
clrdt
belnr
blamt
remark
into corresponding fields of table i_yfdntn
from yfdntn
where bukrs in vbukrs and
dbtno in vdbtno and
dnsno in vdnsno and
frmdt in vfrmdt and
todat in vtodat and
issdt in vissdt and
werks in vwerks and
kunnr in vkunnr.

perform: build_field_catalog.


end-of-selection.
data : i_ava type slis_t_event_exit with header line.

i_ava-ucomm = '&F03'.
i_ava-after = 'X'.
append i_ava.

call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = i_fcat[]
it_excluding = fexclude[]
it_sort = gt_sort[]
i_default = 'X'
i_save = 'A'
it_event_exit = i_ava[]
it_events = fevents[]
tables
t_outtab = i_yfdntn[].

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

*&---------------------------------------------------------------------*
*& Form BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_field_catalog .

call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = sy-repid
i_internal_tabname = 'I_YFDNTN'
i_inclname = sy-repid
changing
ct_fieldcat = i_fcat[].

perform modify_fcat.

* READ TABLE i_fcat WITH KEY fieldname = 'INRDT'.
* IF sy-subrc = 0.
* i_fcat-outputlen = '14'.
* i_fcat-edit = 'X'.
* i_fcat-input = 'X'.
* MODIFY i_fcat INDEX sy-tabix.
* ENDIF.

endform. " BUILD_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.

if r_ucomm = '&DATA_SAVE'.
call function 'POPUP_TO_CONFIRM'
exporting
titlebar = 'Confirm Save...'
text_question = 'Do you want to Save Data ?'
text_button_1 = 'Yes'
icon_button_1 = 'ICON_SYSTEM_SAVE'
text_button_2 = 'No'
icon_button_2 = 'ICON_SYSTEM_CANCEL'
default_button = '1'
display_cancel_button = 'X'
start_column = 25
start_row = 6
popup_type = 'ICON_MESSAGE_QUESTION'
importing
answer = w_answer
exceptions
text_not_found = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

if w_answer eq '1'.
modify yfdntn from table i_yfdntn.
message 'Data Successfully Saved...' type 'S'.
endif.
elseif r_ucomm = '&F03'.
call function 'POPUP_TO_CONFIRM'
exporting
titlebar = 'Confirm Save...'
text_question = 'Do you want to Save Data Before Exit ?'
text_button_1 = 'Yes'
icon_button_1 = 'ICON_SYSTEM_SAVE'
text_button_2 = 'No'
icon_button_2 = 'ICON_SYSTEM_CANCEL'
default_button = '2'
display_cancel_button = 'X'
start_column = 25
start_row = 6
popup_type = 'ICON_MESSAGE_CRITICAL'
importing
answer = w_answer
exceptions
text_not_found = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
if w_answer eq '1'.
modify yfdntn from table i_yfdntn.
message 'Data Successfully Saved...' type 'S'.
endif.
endif.
clear : w_answer.
endform. "user_command
*&---------------------------------------------------------------------*
*& Form MODIFY_FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form modify_fcat .
read table i_fcat with key fieldname = 'DBTNO'.
ind = sy-tabix.
i_fcat-seltext_s = 'DebNote No.'.
i_fcat-seltext_m = 'Debit Note No.'.
i_fcat-seltext_l = 'Debit Note No.'.
i_fcat-reptext_ddic = 'Debit Note No.'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'FRMDT'.
ind = sy-tabix.
i_fcat-seltext_s = 'From Date'.
i_fcat-seltext_m = 'Debit Note From Date'.
i_fcat-seltext_l = 'Debit Note From Date'.
i_fcat-reptext_ddic = 'Debit Note From Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'TODAT'.
ind = sy-tabix.
i_fcat-seltext_s = 'To Date'.
i_fcat-seltext_m = 'Debit Note To Date'.
i_fcat-seltext_l = 'Debit Note To Date'.
i_fcat-reptext_ddic = 'Debit Note To Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'ISSDT'.
ind = sy-tabix.
i_fcat-seltext_s = 'IssueDate'.
i_fcat-seltext_m = 'Debit Note IssueDate'.
i_fcat-seltext_l = 'Debit Note IssueDate'.
i_fcat-reptext_ddic = 'Debit Note IssueDate'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'VBELN'.
ind = sy-tabix.
i_fcat-seltext_s = 'Inv.Doc.'.
i_fcat-seltext_m = 'Invoice Document No.'.
i_fcat-seltext_l = 'Invoice Document No.'.
i_fcat-reptext_ddic = 'Invoice Document No.'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'LDAYS'.
ind = sy-tabix.
i_fcat-seltext_s = 'Days'.
i_fcat-seltext_m = 'No. of Days'.
i_fcat-seltext_l = 'No. of Days'.
i_fcat-reptext_ddic = 'No. of Days'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'REAMT'.
ind = sy-tabix.
i_fcat-seltext_s = 'Recd.Amount'.
i_fcat-seltext_m = 'Received Amount'.
i_fcat-seltext_l = 'Received Amount'.
i_fcat-reptext_ddic = 'Received Amount'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'VZSKZ'.
ind = sy-tabix.
i_fcat-seltext_s = 'RatOfIntt.'.
i_fcat-seltext_m = 'Interest Rate'.
i_fcat-seltext_l = 'Interest Rate'.
i_fcat-reptext_ddic = 'Interest Rate'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'INAMT'.
ind = sy-tabix.
i_fcat-seltext_s = 'IntrstAmt'.
i_fcat-seltext_m = 'Interest Amount'.
i_fcat-seltext_l = 'Interest Amount'.
i_fcat-reptext_ddic = 'Interest Amount'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'INRDT'.
ind = sy-tabix.
i_fcat-seltext_s = 'Intt.RecDt'.
i_fcat-seltext_m = 'Interest Rec. Date'.
i_fcat-seltext_l = 'Interest Received Date'.
i_fcat-reptext_ddic = 'Interest Received Date'.
i_fcat-outputlen = '14'.
i_fcat-edit = 'X'.
i_fcat-input = 'X'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'INRAM'.
ind = sy-tabix.
i_fcat-seltext_s = 'InttRecAmt'.
i_fcat-seltext_m = 'Interest Rec. Amount'.
i_fcat-seltext_l = 'Interest Received Amount'.
i_fcat-reptext_ddic = 'Interest Received Amount'.
i_fcat-outputlen = '14'.
i_fcat-edit = 'X'.
i_fcat-input = 'X'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'TDAMT'.
ind = sy-tabix.
i_fcat-seltext_s = 'TDSRecAmt'.
i_fcat-seltext_m = 'T.D.S. Rec. Amount'.
i_fcat-seltext_l = 'T.D.S. Received Amount'.
i_fcat-reptext_ddic = 'T.D.S. Received Amount'.
i_fcat-outputlen = '14'.
i_fcat-edit = 'X'.
i_fcat-input = 'X'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'REMARK'.
ind = sy-tabix.
i_fcat-seltext_s = 'Text'.
i_fcat-seltext_m = 'Text'.
i_fcat-seltext_l = 'Text'.
i_fcat-reptext_ddic = 'Text'.
i_fcat-outputlen = '14'.
i_fcat-edit = 'X'.
i_fcat-input = 'X'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'RMAMT'.
ind = sy-tabix.
i_fcat-seltext_s = 'BalanceAmt'.
i_fcat-seltext_m = 'Balance Amount'.
i_fcat-seltext_l = 'Balance Amount'.
i_fcat-reptext_ddic = 'Balance Amount'.
i_fcat-outputlen = '14'.
i_fcat-edit = 'X'.
i_fcat-input = 'X'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'NAME1'.
ind = sy-tabix.
i_fcat-seltext_s = 'Cust.Name'.
i_fcat-seltext_m = 'Customer Name'.
i_fcat-seltext_l = 'Customer Name'.
i_fcat-reptext_ddic = 'Customer Name'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'BLDAT'.
ind = sy-tabix.
i_fcat-seltext_s = 'Bill Date'.
i_fcat-seltext_m = 'Bill Date'.
i_fcat-seltext_l = 'Bill Date'.
i_fcat-reptext_ddic = 'Bill Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'DUEDT'.
ind = sy-tabix.
i_fcat-seltext_s = 'Due Date'.
i_fcat-seltext_m = 'Due Date'.
i_fcat-seltext_l = 'Due Date'.
i_fcat-reptext_ddic = 'Due Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'DUED1'.
ind = sy-tabix.
i_fcat-seltext_s = 'D.O. Date'.
i_fcat-seltext_m = 'D.O. Date'.
i_fcat-seltext_l = 'D.O. Date'.
i_fcat-reptext_ddic = 'D.O. Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'RECDT'.
ind = sy-tabix.
i_fcat-seltext_s = 'AmtRecDt'.
i_fcat-seltext_m = 'Amount Rec.Date'.
i_fcat-seltext_l = 'Amount Received Date'.
i_fcat-reptext_ddic = 'Amount Received Date'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'CLRDC'.
ind = sy-tabix.
i_fcat-seltext_s = 'Chequ/Ref'.
i_fcat-seltext_m = 'Cheque / Ref.No.'.
i_fcat-seltext_l = 'Cheque / Referance No.'.
i_fcat-reptext_ddic = 'Cheque / Referance No.'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'BELNR'.
ind = sy-tabix.
i_fcat-seltext_s = 'InvDocNo'.
i_fcat-seltext_m = 'Invoice Document No.'.
i_fcat-seltext_l = 'Invoice Document No.'.
i_fcat-reptext_ddic = 'Invoice Document No.'.
modify i_fcat index ind.

read table i_fcat with key fieldname = 'BLAMT'.
ind = sy-tabix.
i_fcat-seltext_s = 'InvAmt.'.
i_fcat-seltext_m = 'Invoice Amount'.
i_fcat-seltext_l = 'Invoice Amount'.
i_fcat-reptext_ddic = 'Invoice Amount'.
modify i_fcat index ind.


endform. " MODIFY_FCAT
*&---------------------------------------------------------------------*
*& Form COMPANY_CODE_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form company_code_check .

data : lv_bukrs like bkpf-bukrs,
v_butxt like t001-butxt.

*-- checking company code no is exists or no
select bukrs butxt
from t001 up to 1 rows
into (lv_bukrs,v_butxt )
where bukrs in vbukrs.
endselect.

if sy-subrc <> 0.
message 'Please check Company Code' type 'E'.
endif. "IF sy-subrc <> 0
clear lv_bukrs.

authority-check object 'F_BKPF_BUK'
id 'ACTVT' field '03'
id 'BUKRS' field vbukrs-low.
if sy-subrc ne 0.
message 'No Authorization for Company Code' type 'E'.
endif.


endform. " COMPANY_CODE_CHECK

5. ALV With Checkbox:
*&---------------------------------------------------------------------*
*& Report Z_BAGGING
*&
*&---------------------------------------------------------------------*
*& Developed By : Durgesh Singh
*& Developed On : 23.05.2012
*&---------------------------------------------------------------------*
REPORT Z_BAGGING NO STANDARD PAGE HEADING LINE-SIZE 84.
TYPE-POOLS : SLIS.
TABLES : EKKN,ZBAG_S.
DATA : FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV WITH NON-UNIQUE DEFAULT
KEY WITH HEADER LINE INITIAL SIZE 0,
FEVENT TYPE TABLE OF SLIS_ALV_EVENT WITH NON-UNIQUE DEFAULT
KEY WITH HEADER LINE INITIAL SIZE 0,
FHEADER TYPE TABLE OF SLIS_LISTHEADER WITH NON-UNIQUE DEFAULT KEY
WITH HEADER LINE INITIAL SIZE 0,
FLAYOUT TYPE STANDARD TABLE OF SLIS_LAYOUT_ALV WITH NON-UNIQUE
DEFAULT KEY WITH HEADER LINE INITIAL SIZE 0.
DATA : BEGIN OF I_EKKN OCCURS 0,
EBELN TYPE EKKN-EBELN,
EBELP TYPE EKKN-EBELP,
VBELN TYPE EKKN-VBELN,
VBELP TYPE EKKN-VBELP,
MENGE TYPE EKKN-MENGE,
END OF I_EKKN.
DATA : BEGIN OF I_TEMP OCCURS 0,
EBELN TYPE EKKN-EBELN,
EBELP TYPE EKKN-EBELP,
VBELN TYPE EKKN-VBELN,
VBELP TYPE EKKN-VBELP,
MENGE TYPE EKKN-MENGE,
END OF I_TEMP.
DATA : I_FINAL TYPE ZBAG_S OCCURS 0 WITH HEADER LINE.
DATA: FM_NAME TYPE RS38L_FNAM,
VVBELN TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK BLK02 WITH FRAME TITLE TEXT-007.
PARAMETERS : V_R1 RADIOBUTTON GROUP G1 USER-COMMAND ACT DEFAULT 'X',
V_R2 RADIOBUTTON GROUP G1.
SELECTION-SCREEN END OF BLOCK BLK02.
SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001.
PARAMETERS : V_EBELN TYPE EKKN-EBELN MODIF ID A,
V_VBELN TYPE EKKN-VBELN MODIF ID B,
V_VBELP TYPE EKKN-VBELP MODIF ID B.
SELECTION-SCREEN END OF BLOCK BLK01.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF V_R1 = 'X'.
IF SCREEN-GROUP1 = 'B'.
SCREEN-ACTIVE = 0.
ENDIF.
ELSE.
IF SCREEN-GROUP1 = 'A'.
SCREEN-ACTIVE = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
START-OF-SELECTION.
IF V_R1 = 'X' AND V_EBELN = SPACE.
MESSAGE 'Enter production order No.' TYPE 'I'.
EXIT.
ELSEIF V_R2 = 'X'.
IF V_VBELN = SPACE OR V_VBELP = SPACE.
MESSAGE 'Enter sales order and sales item' TYPE 'I'.
EXIT.
ENDIF.
ENDIF.
IF V_R1 = 'X'.
PERFORM GET_DATA.
IF I_EKKN[] IS NOT INITIAL.
PERFORM DISPLAY_REPORT.
ELSE.
MESSAGE 'No Record Found!' TYPE 'I'.
EXIT.
ENDIF.
ELSE.
I_FINAL-CHECK = 'X'.
I_FINAL-VBELN = V_VBELN.
I_FINAL-VBELP = V_VBELP.
APPEND I_FINAL.
CLEAR I_FINAL.
PERFORM DISPLAY_BARCODE.
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT EBELN
EBELP
VBELN
VBELP
MENGE
INTO TABLE I_EKKN FROM EKKN WHERE EBELN = V_EBELN.
IF I_EKKN[] IS NOT INITIAL.
I_TEMP[] = I_EKKN[].
SORT I_TEMP BY VBELN VBELP ASCENDING.
DELETE ADJACENT DUPLICATES FROM I_TEMP COMPARING VBELN VBELP.
LOOP AT I_TEMP.
CLEAR : I_TEMP-MENGE.
MOVE-CORRESPONDING I_TEMP TO I_FINAL.
LOOP AT I_EKKN WHERE VBELN = I_TEMP-VBELN AND VBELP = I_TEMP-VBELP
.
I_FINAL-MENGE = I_FINAL-MENGE + I_EKKN-MENGE.
ENDLOOP.
APPEND I_FINAL.
CLEAR : I_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_REPORT .
PERFORM FIELD_CATALOG.
PERFORM GIRD_DISPLAY.
ENDFORM. " DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD_CATALOG .
FCAT-FIELDNAME = 'CHECK'.
FCAT-SELTEXT_S = TEXT-006.
FCAT-SELTEXT_M = TEXT-006.
FCAT-SELTEXT_L = TEXT-006.
FCAT-REPTEXT_DDIC = TEXT-006.
FCAT-CHECKBOX = 'X'.
FCAT-EDIT = 'X'.
APPEND FCAT.
CLEAR FCAT.
FCAT-FIELDNAME = 'EBELN'.
FCAT-SELTEXT_S = TEXT-002.
FCAT-SELTEXT_M = TEXT-002.
FCAT-SELTEXT_L = TEXT-002.
FCAT-REPTEXT_DDIC = TEXT-002.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
CLEAR FCAT.
FCAT-FIELDNAME = 'VBELN'.
FCAT-SELTEXT_S = TEXT-003.
FCAT-SELTEXT_M = TEXT-003.
FCAT-SELTEXT_L = TEXT-003.
FCAT-REPTEXT_DDIC = TEXT-003.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
CLEAR FCAT.
FCAT-FIELDNAME = 'VBELP'.
FCAT-SELTEXT_S = TEXT-004.
FCAT-SELTEXT_M = TEXT-004.
FCAT-SELTEXT_L = TEXT-004.
FCAT-REPTEXT_DDIC = TEXT-004.
FCAT-OUTPUTLEN = '10'.
APPEND FCAT.
CLEAR FCAT.
FCAT-FIELDNAME = 'MENGE'.
FCAT-SELTEXT_S = TEXT-005.
FCAT-SELTEXT_M = TEXT-005.
FCAT-SELTEXT_L = TEXT-005.
FCAT-REPTEXT_DDIC = TEXT-005.
FCAT-OUTPUTLEN = '10'.
APPEND FCAT.
CLEAR FCAT.
ENDFORM. " FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form GIRD_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GIRD_DISPLAY .
FLAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = FLAYOUT
IT_FIELDCAT = FCAT[]
I_DEFAULT = 'X'
TABLES
T_OUTTAB = I_FINAL[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " GIRD_DISPLAY
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF1.
CALL METHOD REF1->CHECK_CHANGED_DATA.
CASE R_UCOMM.
WHEN 'BARC'.
READ TABLE I_FINAL WITH KEY CHECK = 'X'.
IF SY-SUBRC = 0.
PERFORM DISPLAY_BARCODE.
ELSE.
MESSAGE 'Select at least on row' TYPE 'I'.
EXIT.
ENDIF.
ENDCASE.
ENDFORM. " USER_COMMAND
*&---------------------------------------------------------------------*
*& Form PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'ZLBLN'.
ENDFORM. " PF_STATUS
*&---------------------------------------------------------------------*
*& Form DISPLAY_BARCODE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_BARCODE .
DELETE I_FINAL WHERE CHECK = SPACE.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'Z_BAGGING_BARCODE'
IMPORTING
FM_NAME = FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION FM_NAME
TABLES
I_FINAL = I_FINAL[].
ENDFORM. " DISPLAY_BARCODE

6. ALV With Colour:
*&---------------------------------------------------------------------*
*& Report ZDEMO_ALV1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO_ALV1.
type-pools slis.
data: fieldcat type slis_t_fieldcat_alv.
data: begin of imara occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
maktx type makt-maktx,
color_line(4) type c,
tcolor type slis_t_specialcol_alv, "cell
end of imara.
data: xcolor type slis_specialcol_alv.
start-of-selection.
perform get_data.
perform write_report.
************************************************************************
* Get_Data
************************************************************************
form get_data.
imara-matnr = 'ABC'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for ABC'.
append imara.
imara-matnr = 'DEF'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for DEF'.
append imara.
imara-matnr = 'GHI'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for GHI'.
append imara.
loop at imara.
if sy-tabix = 1.
imara-color_line = 'C410'. " color line
endif.
if sy-tabix = 2. "color CELL
clear xcolor.
xcolor-fieldname = 'MTART'.
xcolor-color-col = '7'.
xcolor-color-int = '1'. "Intensified on/off
xcolor-color-inv = '0'.
append xcolor to imara-tcolor.
endif.
modify imara.
endloop.
endform.
************************************************************************
* WRITE_REPORT
************************************************************************
form write_report.
data: layout type slis_layout_alv.
layout-coltab_fieldname = 'TCOLOR'.
layout-info_fieldname = 'COLOR_LINE'.
perform build_field_catalog.
* CALL ABAP LIST VIEWER (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = layout
it_fieldcat = fieldcat
tables
t_outtab = imara.
endform.
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
data: fc_tmp type slis_t_fieldcat_alv with header line.
clear: fieldcat. refresh: fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Number'.
fc_tmp-fieldname = 'MATNR'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '18'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Type'.
fc_tmp-fieldname = 'MTART'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '4'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material'.
fc_tmp-fieldname = 'MAKTX'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '40'.
fc_tmp-emphasize = 'C610'. " color column
append fc_tmp to fieldcat.
endform.
*Here is the color code chart as well.
*****************************************************************
* Colour code : *
* Colour is a 4-char field where : *
* - 1st char = C (color property) *
* - 2nd char = color code (from 0 to 7) *
* 0 = background color *
* 1 = blue *
* 2 = gray *
* 3 = yellow *
* 4 = blue/gray *
* 5 = green *
* 6 = red *
* 7 = orange *
* - 3rd char = intensified (0=off, 1=on) *
* - 4th char = inverse display (0=off, 1=on) *
* *
* Colour overwriting priority : *
* 1. Line *
* 2. Cell
*3. Column *
*C110
*C210
*C310
*C410
*C510
*C610
*C710
*C810
*C010
****************************************************************************

7. ALV in Module Pool:
Driver Program
*&---------------------------------------------------------------------*
*& Report ZRFGLBALANCE_N
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRFGLBALANCE_N MESSAGE-ID ZDMSG.
TYPE-POOLS : SLIS,TPIT.
TABLES: SKAT, SKB1, BSIS,T001,GLT0,TGSBT,BSEG.
*--------Table Declaration
DATA : BEGIN OF I_GLDETAIL OCCURS 0,
HKONT TYPE BSIS-HKONT,
BUKRS TYPE BSIS-BUKRS,
GJAHR TYPE BSIS-GJAHR,
GSBER TYPE BSIS-GSBER,
MONAT TYPE BSIS-MONAT,
DMBTR TYPE BSIS-DMBTR,
SHKZG TYPE BSIS-SHKZG,
XNEGP TYPE BSIS-XNEGP,
END OF I_GLDETAIL,
BEGIN OF I_GLSUMMARY OCCURS 0,
MONAT LIKE BSIS-XREF3,
DMBTR LIKE BSIS-DMBTR,
CMBTR LIKE BSIS-DMBTR,
BMBTR LIKE BSIS-DMBTR,
UMBTR LIKE BSIS-DMBTR,
END OF I_GLSUMMARY,
BEGIN OF I_GLT0 OCCURS 0,
BUKRS TYPE GLT0-BUKRS,
RYEAR TYPE GLT0-RYEAR,
RACCT TYPE GLT0-RACCT,
TSLVT TYPE GLT0-TSLVT,
END OF I_GLT0,
BEGIN OF I_BSEG OCCURS 0,
BUKRS TYPE BSEG-BUKRS,
BELNR TYPE BSEG-BELNR,
GJAHR TYPE BSEG-GJAHR,
BUZEI TYPE BSEG-BUZEI,
LIFNR TYPE BSEG-LIFNR,
VNAME TYPE LFA1-NAME1,
MATNR TYPE BSEG-MATNR,
MENGE TYPE BSEG-MENGE,
KUNNR TYPE BSEG-KUNNR,
CNAME TYPE KNA1-NAME1,
ANLN1 TYPE BSEG-ANLN1,
ANLN2 TYPE BSEG-ANLN2,
EBELN TYPE BSEG-EBELN,
EBELP TYPE BSEG-EBELP,
ETEN2 TYPE BSEG-ETEN2,
FILKD TYPE BSEG-FILKD,
POSN2 TYPE BSEG-POSN2,
VBEL2 TYPE BSEG-VBEL2,
VBELN TYPE BSEG-VBELN,
END OF I_BSEG.
DATA : WA LIKE LINE OF I_GLSUMMARY.
*--------Structure Declaration
DATA : IT_LIST LIKE ZRFPOSXEXT OCCURS 1 WITH HEADER LINE,
I_RDTXT TYPE TLINE OCCURS 0 WITH HEADER LINE.
*--------Variable Declaration For ALV
DATA : FCAT TYPE LVC_T_FCAT WITH HEADER LINE.
DATA : I_FIELDCAT TYPE TABLE OF SLIS_FIELDCAT_ALV WITH NON-UNIQUE DEFAULT
KEY WITH HEADER LINE INITIAL SIZE 0,
FEVENT TYPE TABLE OF SLIS_ALV_EVENT WITH NON-UNIQUE DEFAULT
KEY WITH HEADER LINE INITIAL SIZE 0,
FHEADER TYPE TABLE OF SLIS_LISTHEADER WITH NON-UNIQUE DEFAULT KEY
WITH HEADER LINE INITIAL SIZE 0,
FLAYOUT TYPE STANDARD TABLE OF SLIS_LAYOUT_ALV WITH NON-UNIQUE
DEFAULT KEY WITH HEADER LINE INITIAL SIZE 0.
*--------Variable Declaration
DATA : TEMP TYPE BSIS-DMBTR,
CFBL TYPE BSIS-DMBTR,
CNT TYPE BSIS-MONAT,
TDEB TYPE BSIS-DMBTR,
TCRD TYPE BSIS-DMBTR,
TDIF TYPE BSIS-DMBTR,
VGLN TYPE SKAT-TXT20,
VCOM TYPE T001-BUTXT,
VBUS TYPE TGSBT-GTEXT,
VFYR TYPE BSIS-GJAHR,
VDCR TYPE C,
MONT(10) TYPE C,
RCNT TYPE I.
DATA :V_TXTNAME TYPE THEAD-TDNAME,
GTEXT(60) TYPE C,
IGUI TYPE I.
DATA : CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GRID TYPE REF TO CL_GUI_ALV_GRID,
L_UCOMM TYPE SY-UCOMM,
V_GJAHR TYPE BSIS-GJAHR.
*--------Constant Declaration
CONSTANTS : C_BACK TYPE SY-UCOMM VALUE 'BACK',
C_EXIT TYPE SY-UCOMM VALUE 'EXIT',
C_CANC TYPE SY-UCOMM VALUE 'CANC',
VID TYPE THEAD-TDID VALUE '0001',
VOBJ TYPE THEAD-TDOBJECT VALUE 'DOC_ITEM',
C_GUICNT LIKE SY-TABIX VALUE 100.
*--------Selection Screen Declaration
SELECT-OPTIONS: VHKONT FOR BSIS-HKONT NO INTERVALS,
VBUKRS FOR T001-BUKRS NO INTERVALS,
VGJAHR FOR BSIS-GJAHR NO INTERVALS NO-EXTENSION,
VGSBER FOR BSIS-GSBER NO INTERVALS.
*--------Class Definition
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS: HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IM
PORTING E_ROW E_COLUMN.
ENDCLASS. "LCL_EVENT_HANDLER DEFINITION
*--------Class Implementationn
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
METHOD HANDLE_DOUBLE_CLICK.
READ TABLE I_GLSUMMARY INDEX E_ROW-INDEX INTO WA.
IF WA-MONAT = 'Balance Carryforward'.
MESSAGE S002.
EXIT.
ELSE.
IF E_COLUMN = 'MONAT' AND WA-BMBTR = 0.
MESSAGE I003.
EXIT.
ELSEIF E_COLUMN = 'DMBTR' AND WA-DMBTR = 0.
MESSAGE I003.
EXIT.
ELSEIF E_COLUMN = 'CMBTR' AND WA-CMBTR = 0.
MESSAGE I003.
EXIT.
ELSEIF E_COLUMN = 'BMBTR' AND WA-BMBTR = 0.
MESSAGE I003.
EXIT.
ELSE.
PERFORM OUT_PUT_LIST USING WA E_COLUMN.
PERFORM FIELD_CATALOG_FOR_DOUBLE_CLICK.
PERFORM DISPLAY_DATA_FOR_DOUBLE_CLICK.
ENDIF.
ENDIF.
CLEAR : WA.
ENDMETHOD. "HANDLE_DOUBLE_CLICK
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
START-OF-SELECTION.
IF VHKONT-LOW IS INITIAL.
MESSAGE I005.
EXIT.
ELSEIF VBUKRS-LOW IS INITIAL.
MESSAGE I006.
EXIT.
ELSEIF VGJAHR-LOW IS INITIAL.
MESSAGE I007.
EXIT.
ENDIF.
PERFORM GET_DATA.
IF I_GLDETAIL[] IS NOT INITIAL.
PERFORM PROCESS_DATA.
PERFORM FIELD_CATALOG_BUILD.
CALL SCREEN 100.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT HKONT
BUKRS
GJAHR
GSBER
MONAT
DMBTR
SHKZG
XNEGP
INTO CORRESPONDING FIELDS OF TABLE I_GLDETAIL FROM BSIS
WHERE HKONT IN VHKONT AND
BUKRS IN VBUKRS AND
GJAHR EQ VGJAHR-LOW AND
GSBER IN VGSBER.
IF I_GLDETAIL[] IS INITIAL.
MESSAGE I000.
RETURN.
ENDIF.
SELECT BUKRS
RYEAR
RACCT
TSLVT
INTO TABLE I_GLT0 FROM GLT0
WHERE BUKRS IN VBUKRS AND
RYEAR EQ VGJAHR-LOW AND
RACCT IN VHKONT AND
RBUSA IN VGSBER.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
V_GJAHR = VGJAHR-LOW.
CLEAR : CFBL.
LOOP AT I_GLT0.
CFBL = CFBL + I_GLT0-TSLVT.
ENDLOOP.
I_GLSUMMARY-MONAT = '00'.
I_GLSUMMARY-UMBTR = CFBL.
APPEND I_GLSUMMARY.
LOOP AT I_GLDETAIL.
I_GLSUMMARY-MONAT = I_GLDETAIL-MONAT.
IF I_GLDETAIL-SHKZG = 'S' AND I_GLDETAIL-XNEGP = ' '.
I_GLSUMMARY-DMBTR = I_GLDETAIL-DMBTR.
I_GLSUMMARY-CMBTR = 0.
ELSEIF I_GLDETAIL-SHKZG = 'S' AND I_GLDETAIL-XNEGP = 'X'.
I_GLSUMMARY-CMBTR = I_GLDETAIL-DMBTR * -1.
I_GLSUMMARY-DMBTR = 0.
ELSEIF I_GLDETAIL-SHKZG = 'H' AND I_GLDETAIL-XNEGP = ' '.
I_GLSUMMARY-CMBTR = I_GLDETAIL-DMBTR.
I_GLSUMMARY-DMBTR = 0.
ELSEIF I_GLDETAIL-SHKZG = 'H' AND I_GLDETAIL-XNEGP = 'X'.
I_GLSUMMARY-DMBTR = I_GLDETAIL-DMBTR * -1.
I_GLSUMMARY-CMBTR = 0.
ENDIF.
I_GLSUMMARY-BMBTR = ( I_GLSUMMARY-DMBTR - I_GLSUMMARY-CMBTR ).
COLLECT I_GLSUMMARY.
ENDLOOP.
DO 17 TIMES.
CNT = CNT + 1.
READ TABLE I_GLSUMMARY WITH KEY MONAT = CNT.
IF SY-SUBRC IS NOT INITIAL.
CLEAR : I_GLSUMMARY.
I_GLSUMMARY-MONAT = CNT.
APPEND I_GLSUMMARY.
ELSE.
TDEB = TDEB + I_GLSUMMARY-DMBTR.
TCRD = TCRD + I_GLSUMMARY-CMBTR.
TDIF = TDIF + I_GLSUMMARY-BMBTR.
ENDIF.
ENDDO.
SORT I_GLSUMMARY BY MONAT.
LOOP AT I_GLSUMMARY.
IF I_GLSUMMARY-MONAT = '00'.
I_GLSUMMARY-MONAT = 'Balance Carryforward'.
TEMP = I_GLSUMMARY-UMBTR.
ELSE.
I_GLSUMMARY-UMBTR = TEMP + I_GLSUMMARY-BMBTR.
TEMP = I_GLSUMMARY-UMBTR.
ENDIF.
MODIFY I_GLSUMMARY.
ENDLOOP.
LOOP AT I_GLSUMMARY WHERE MONAT = '17'.
I_GLSUMMARY-MONAT = 'Total'.
I_GLSUMMARY-DMBTR = TDEB.
I_GLSUMMARY-CMBTR = TCRD.
I_GLSUMMARY-BMBTR = TDIF.
MODIFY I_GLSUMMARY.
ENDLOOP.
ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD_CATALOG_BUILD .
FCAT-FIELDNAME = 'MONAT'.
FCAT-REPTEXT = 'Period'.
FCAT-OUTPUTLEN = '10'.
FCAT-EMPHASIZE = 'C110'.
APPEND FCAT.
CLEAR FCAT.
FCAT-FIELDNAME = 'DMBTR'.
FCAT-REPTEXT = 'Debit'.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
FCAT-FIELDNAME = 'CMBTR'.
FCAT-REPTEXT = 'Credit'.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
FCAT-FIELDNAME = 'BMBTR'.
FCAT-REPTEXT = 'Balance'.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
FCAT-FIELDNAME = 'UMBTR'.
FCAT-REPTEXT = 'Cum. balance'.
FCAT-OUTPUTLEN = '15'.
APPEND FCAT.
ENDFORM. " FIELD_CATALOG_BUILD
INCLUDE ZRFGLBALANCE_N_STATUS_0100O02.
*&---------------------------------------------------------------------*
*& Form OUT_PUT_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA text
*----------------------------------------------------------------------*
FORM OUT_PUT_LIST USING P_WA P_E_COLUMN.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = 'Fetching Data For List'.
IF WA-MONAT = 'Total'.
SELECT HKONT
BUKRS
GJAHR
GSBER
MONAT
DMBTR
SHKZG
XNEGP
WAERS AS HWAER
BLDAT
BELNR
ZUONR
BUZEI
AUFNR
AUGBL
AUGDT
BSCHL
BSTAT
BUDAT
DMBE2
DMBE3
BUZID
KOSTL
MWSKZ
PRCTR
SGTXT
VALUT
VBUND
WERKS
XBLNR
XREF3
PROJK
BUPLA
PROPMANO
INTO CORRESPONDING FIELDS OF TABLE IT_LIST
FROM BSIS
WHERE HKONT IN VHKONT AND
BUKRS IN VBUKRS AND
GJAHR EQ V_GJAHR AND
GSBER IN VGSBER .
ELSE.
SELECT HKONT
BUKRS
GJAHR
GSBER
MONAT
DMBTR
SHKZG
XNEGP
WAERS AS HWAER
BLDAT
BELNR
ZUONR
BUZEI
AUFNR
AUGBL
AUGDT
BSCHL
BSTAT
BUDAT
DMBE2
DMBE3
BUZID
KOSTL
MWSKZ
PRCTR
SGTXT
VALUT
VBUND
WERKS
XBLNR
XREF3
PROJK
BUPLA
PROPMANO
INTO CORRESPONDING FIELDS OF TABLE IT_LIST
FROM BSIS
WHERE HKONT IN VHKONT AND
BUKRS IN VBUKRS AND
GJAHR EQ V_GJAHR AND
GSBER IN VGSBER AND
MONAT EQ WA-MONAT.
ENDIF.
SELECT BUKRS
BELNR
GJAHR
BUZEI
LIFNR
MATNR
MENGE
KUNNR
ANLN1
ANLN2
EBELN
EBELP
ETEN2
FILKD
POSN2
VBEL2
VBELN
INTO CORRESPONDING FIELDS OF TABLE I_BSEG
FROM BSEG FOR ALL ENTRIES IN IT_LIST
WHERE BUKRS = IT_LIST-BUKRS AND
BELNR = IT_LIST-BELNR AND
GJAHR = IT_LIST-GJAHR AND
BUZEI = IT_LIST-BUZEI.
LOOP AT I_BSEG.
SELECT SINGLE NAME1 FROM LFA1 INTO I_BSEG-VNAME WHERE LIFNR = I_BSEGLIFNR.
SELECT SINGLE NAME1 FROM KNA1 INTO I_BSEG-CNAME WHERE KUNNR = I_BSEGKUNNR.
MODIFY I_BSEG.
ENDLOOP.
IF P_E_COLUMN = 'CMBTR'.
DELETE IT_LIST WHERE ( SHKZG = 'S' AND XNEGP = SPACE ) OR ( SHKZG = 'H'
AND XNEGP = 'X' ).
ELSEIF P_E_COLUMN = 'DMBTR'.
DELETE IT_LIST WHERE ( SHKZG = 'H' AND XNEGP = SPACE ) OR ( SHKZG = 'S'
AND XNEGP = 'X' ).
ENDIF.
LOOP AT IT_LIST.
RCNT = RCNT + 1.
IF IT_LIST-SHKZG = 'H'.
IT_LIST-DMBTR = IT_LIST-DMBTR * -1.
ENDIF.
READ TABLE I_BSEG WITH KEY BUKRS = IT_LIST-BUKRS
BELNR = IT_LIST-BELNR
GJAHR = IT_LIST-GJAHR
BUZEI = IT_LIST-BUZEI.
IF SY-SUBRC IS INITIAL.
IT_LIST-LIFNR = I_BSEG-LIFNR.
IT_LIST-KUNNR = I_BSEG-KUNNR.
IT_LIST-MATNR = I_BSEG-MATNR.
IT_LIST-MENGE = I_BSEG-MENGE.
IT_LIST-VNAME = I_BSEG-VNAME.
IT_LIST-CNAME = I_BSEG-CNAME.
IT_LIST-ANLN1 = I_BSEG-ANLN1.
IT_LIST-ANLN2 = I_BSEG-ANLN2.
IT_LIST-EBELN = I_BSEG-EBELN.
IT_LIST-EBELP = I_BSEG-EBELP.
IT_LIST-ETEN2 = I_BSEG-ETEN2.
IT_LIST-FILKD = I_BSEG-FILKD.
IT_LIST-POSN2 = I_BSEG-POSN2.
IT_LIST-VBEL2 = I_BSEG-VBEL2.
IT_LIST-VBELN = I_BSEG-VBELN.
ENDIF.
CONCATENATE IT_LIST-GJAHR '/' WA-MONAT INTO MONT.
IT_LIST-YMONT = MONT.
CONCATENATE IT_LIST-BUKRS IT_LIST-BELNR IT_LIST-GJAHR IT_LISTBUZEI
INTO V_TXTNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = VID
LANGUAGE = SY-LANGU
NAME = V_TXTNAME
OBJECT = VOBJ
TABLES
LINES = I_RDTXT[]
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC EQ 0.
READ TABLE I_RDTXT INDEX 1.
IF SY-SUBRC IS INITIAL.
IT_LIST-LGTXT = I_RDTXT-TDLINE.
ENDIF.
ENDIF.
MODIFY IT_LIST.
CLEAR : MONT,V_TXTNAME.
ENDLOOP.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = 'List Being Generated'.
ENDFORM. " OUT_PUT_LIST
*&---------------------------------------------------------------------*
*& Form FIELD_CATALOG_FOR_DOUBLE_CLICK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FIELD_CATALOG_FOR_DOUBLE_CLICK .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZRFPOSXEXT'
CHANGING
CT_FIELDCAT = I_FIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
LOOP AT I_FIELDCAT WHERE FIELDNAME = 'LGTXT'.
I_FIELDCAT-SELTEXT_S = 'Long Text'.
I_FIELDCAT-SELTEXT_M = 'Long Text'.
I_FIELDCAT-SELTEXT_L = 'Long Text'.
I_FIELDCAT-REPTEXT_DDIC = 'Long Text'.
MODIFY I_FIELDCAT.
CLEAR :I_FIELDCAT.
ENDLOOP.
ENDFORM. " FIELD_CATALOG_FOR_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA_FOR_DOUBLE_CLICK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA_FOR_DOUBLE_CLICK .
CLEAR : RCNT.
DESCRIBE TABLE IT_LIST[] LINES RCNT.
MESSAGE S004 WITH RCNT.
FLAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = I_FIELDCAT[]
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_DEFAULT = 'X'
IS_LAYOUT = FLAYOUT
TABLES
T_OUTTAB = IT_LIST[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " DISPLAY_DATA_FOR_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
READ TABLE IT_LIST INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC IS INITIAL.
SET PARAMETER ID 'BLN' FIELD IT_LIST-BELNR.
SET PARAMETER ID 'BUK' FIELD IT_LIST-BUKRS.
SET PARAMETER ID 'GJR' FIELD IT_LIST-GJAHR.
SET PARAMETER ID 'BUZ' FIELD IT_LIST-BUZEI.
CALL TRANSACTION 'FB09D' AND SKIP FIRST SCREEN.
ENDIF.
ENDFORM. " USER_COMMAND
Screen 100
PAI
MOVE SY-UCOMM TO L_UCOMM.
CASE SY-UCOMM.
WHEN C_BACK.
LEAVE TO SCREEN 0.
WHEN SY-UCOMM.
LEAVE TO SCREEN 0.
WHEN SY-UCOMM.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
PBO
DATA : GR_EVENT_HANDLER TYPE REF TO LCL_EVENT_HANDLER.
SET PF-STATUS 'ZSTS'.
SET TITLEBAR 'ZTITL'.
CREATE OBJECT CONTAINER1
EXPORTING
CONTAINER_NAME = 'CUSTOM1'.
CREATE OBJECT GRID
EXPORTING
I_PARENT = CONTAINER1.
CREATE OBJECT GR_EVENT_HANDLER.
*——Registering handler methods to handle alv grid event
SET HANDLER GR_EVENT_HANDLER->HANDLE_DOUBLE_CLICK FOR GRID.
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = I_GLSUMMARY[]
IT_FIELDCATALOG = FCAT[]
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
OTHERS = 4.
CLEAR : CNT.
*-------------Account
DESCRIBE TABLE VHKONT LINES CNT.
IF CNT = '01'.
READ TABLE VHKONT INDEX 1.
BSIS-HKONT = VHKONT-LOW.
SELECT SINGLE TXT20 INTO VGLN FROM SKAT WHERE SAKNR =
VHKONT-LOW.
SHIFT BSIS-HKONT LEFT DELETING LEADING '0'.
ELSE.
BSIS-HKONT = '*'.
ENDIF.
*-------------Company Code
READ TABLE VBUKRS INDEX 1.
T001-BUKRS = VBUKRS-LOW.
SELECT SINGLE BUTXT INTO VCOM FROM T001 WHERE BUKRS = VBUKRS-LOW.
*-------------Business Area
IF VGSBER[] IS NOT INITIAL.
CLEAR : CNT.
DESCRIBE TABLE VGSBER LINES CNT.
IF CNT = '01'.
READ TABLE VGSBER INDEX 1.
BSIS-GSBER = VGSBER-LOW.
SELECT SINGLE GTEXT INTO VBUS FROM TGSBT WHERE GSBER = VGSBER-LOW
AND SPRAS = 'EN'.
ELSE.
BSIS-GSBER = '*'.
ENDIF.
ELSE.
BSIS-GSBER = '*'.
ENDIF.
*-------------Fiscal Year
VGJAHR = VGJAHR+3(4).
*------------All documents in currency
VDCR = '*'.
*------------Display currency



































8. ALV Autorefresh:
*&---------------------------------------------------------------------*
*& Report Z_TEST_DURGESH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
"REPORT Z_TEST_DURGESH.
REPORT zpwtest8.
CLASS lcl_timer DEFINITION DEFERRED .
DATA : i_ekpo TYPE TABLE OF ekpo .
DATA : ob_grid TYPE REF TO cl_gui_alv_grid ,
ob_recev TYPE REF TO lcl_timer ,
ob_timer TYPE REF TO cl_gui_timer .
*----------------------------------------------------------------------*
* CLASS lcl_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_timer DEFINITION.
PUBLIC SECTION.
METHODS:
handle_finished FOR EVENT finished OF cl_gui_timer.
ENDCLASS. "lcl_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_timer IMPLEMENTATION.
METHOD handle_finished.
PERFORM refresh_data .
MESSAGE s003(z001) WITH 'Report refreshed at' sy-uzeit.
CALL METHOD ob_timer->run.
ENDMETHOD. "handle_finished
ENDCLASS. "lcl_receiver IMPLEMENTATION
*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION .
PERFORM select_data .
*--------------------------------------------------------------------*
* End of Selection
*--------------------------------------------------------------------*
END-OF-SELECTION .
* Step 1 : Initialise Time control
CREATE OBJECT ob_timer.
* Step 2 : Initialise object to receive event
CREATE OBJECT ob_recev.
* Step 3 : Couple event to method
SET HANDLER ob_recev->handle_finished FOR ob_timer. "
* Step 4 : Set Interval in seconds
ob_timer->interval = 20 .
* Step 5 : Start Timer
CALL METHOD ob_timer->run.
PERFORM display_data .
*--------------------------------------------------------------------*
*& Form Select_Date
*--------------------------------------------------------------------*
FORM select_data .
SELECT *
APPENDING TABLE i_ekpo
FROM ekpo .
ENDFORM. "SELECT_DATA
*&---------------------------------------------------------------------*
*& Form refresh_data
*&---------------------------------------------------------------------*
FORM refresh_data .
* Get grid reference
IF ob_grid IS INITIAL .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ob_grid.
ENDIF.
IF ob_grid IS NOT INITIAL. "Sanity Test
PERFORM select_data .
CALL METHOD ob_grid->refresh_table_display.
ENDIF.
ENDFORM. "refresh_data
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
FORM display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'EKPO'
TABLES
t_outtab = i_ekpo
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM . "display_data

9. Default Variant:
*&---------------------------------------------------------------------*
*& Report Z_TEST_DURGESH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_TEST_DURGESH.
data: report type rsvar-report value 'Z_LOOSE_STOCK_DOWNLOAD',
variant type rsvar-variant .
variant = 'DLD'.
CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
EXPORTING
REPORT = 'Z_LOOSE_STOCK_DOWNLOAD'
VARIANT = variant
EXCEPTIONS
VARIANT_NOT_EXISTENT = 1
VARIANT_OBSOLETE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
submit (report) via selection-screen
and return.
else.
submit (report) via selection-screen
using selection-set variant
and return.
ENDIF.

10. Download Data:
**********************************************************************
* Title : GIA Report Check.
* Desription : GIA Report Check.
* Type : REPORT
* T code : ZGIA
* Author : Durgesh Singh
* Functional : Rakesh Churri
* Date : 19/03/2011
* Version : 1
* Modifications :
**********************************************************************
REPORT ZSD_GIA_REPORT MESSAGE-ID ZGIA NO STANDARD PAGE HEADING.
TYPE-POOLS: TRUXS.
TABLES: ZSD_GIA, SSCRFIELDS, MCHB,ZLARGE_STONE_HDR,ZLARGE_STONE_ITM,EKBE,ZFLU
ORES_CODE.
*INCLUDE cntl.
TYPES: BEGIN OF T_ITTAB,
REPORT(13) TYPE C,
WEIGHT(8) TYPE C,
CHARG(10) TYPE C,
END OF T_ITTAB.
DATA : BEGIN OF I_ERROR OCCURS 0,
REPORT(13) TYPE C,
CHARG(10) TYPE C,
WEIGHT(8) TYPE C,
ERROR(50) TYPE C,
END OF I_ERROR.
data : val3 TYPE string,
val4 TYPE string.
DATA : BEGIN OF I_ZLARGE_HDR OCCURS 0.
INCLUDE STRUCTURE ZLARGE_STONE_HDR.
DATA : END OF I_ZLARGE_HDR.
DATA : BEGIN OF I_ZLARGE_ITM OCCURS 0.
INCLUDE STRUCTURE ZLARGE_STONE_ITM.
DATA : END OF I_ZLARGE_ITM.
DATA : BEGIN OF I_TEMP OCCURS 0.
INCLUDE STRUCTURE ZSD_GIA.
DATA : END OF I_TEMP.
DATA : BEGIN OF I_ERROR1 OCCURS 0,
REPORT(13) TYPE C,
CHARG(10) TYPE C,
WEIGHT(8) TYPE C,
ERROR(50) TYPE C,
FLG TYPE C,
END OF I_ERROR1.
FIELD-SYMBOLS: TYPE T_ITTAB .
DATA: IT_FILE TYPE T_ITTAB OCCURS 0 WITH HEADER LINE,
WA_FILE TYPE ZSD_GIA,
VAL1 TYPE I VALUE 0,
sapno TYPE ZLARGE_STONE_HDR-sapno,
litem TYPE i,
litem1 TYPE i,
rval TYPE i.
DATA: URL(250) TYPE C,"STRING,
PATH(50) TYPE C."string.
DATA:STATUS_CODE TYPE C,
STATUS_TEXT TYPE C,
P_FILE TYPE RLGRAP-FILENAME,
FLG TYPE I VALUE 0.
TYPES: BEGIN OF T_DATATAB,
COL1(30) TYPE C,
COL2(50) TYPE C,
END OF T_DATATAB.
DATA: IT_DATATAB TYPE STANDARD TABLE OF T_DATATAB WITH HEADER LINE,
EXCEL2 TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE,
EXCEL3 TYPE STANDARD TABLE OF ALSMEX_TABLINE WITH HEADER LINE,
WA_GIA TYPE ZSD_GIA,
WEIGHT(8) TYPE C,
TDATE(10) TYPE C,
WA_DATATAB TYPE T_DATATAB.
DATA: TCHARG TYPE EKET-CHARG.
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
FIELD-SYMBOLS : TYPE T_DATATAB,
TYPE ALSMEX_TABLINE,
TYPE ALSMEX_TABLINE.
SELECTION-SCREEN: BEGIN OF BLOCK SCR_BLK WITH FRAME TITLE TEXT-002.
PARAMETER: PFILEIT LIKE RLGRAP-FILENAME OBLIGATORY MEMORY ID ITM.
*SKIP 2.
SELECTION-SCREEN: END OF BLOCK SCR_BLK.
*
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.
PARAMETERS: P_VARI LIKE DISVARIANT-VARIANT. " ALV Variant
SELECTION-SCREEN END OF BLOCK B3.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR PFILEIT.
PERFORM F4_HELP_P_FILE_IT.
START-OF-SELECTION.
PERFORM UPLOAD_FILE.
PERFORM WEIGHT_VALIDATION.
IF I_ERROR[] IS INITIAL.
LOOP AT IT_FILE ASSIGNING .
FLG = 0.
SELECT SINGLE CHARG FROM EKBE INTO TCHARG
WHERE CHARG = -CHARG.
IF SY-SUBRC NE 0.
* MESSAGE E003 with -CHARG.
I_ERROR1-REPORT = -REPORT.
I_ERROR1-CHARG = -CHARG.
I_ERROR1-WEIGHT = -WEIGHT.
I_ERROR1-ERROR = 'Invalid Batch No.'.
I_ERROR1-FLG = 'E'.
APPEND I_ERROR1.
FLG = 1.
ENDIF.
IF FLG = 0.
CONCATENATE 'http://www2.gia.edu/reportcheck/index.cfm?fuseaction=h
ome.showReportVerification&reportno=' -REPORT INTO URL .
CONCATENATE URL '&weight=' INTO URL.
WEIGHT = -WEIGHT.
CONCATENATE URL WEIGHT INTO URL.
CONDENSE URL NO-GAPS.
* * URL = 'http://www.hrdantwerplink.be/?record_number=0900136600
1&weight=4.01&L='.
DATA:DATE TYPE SY-DATUM.
DATE = SY-DATUM.
* \\192.168.155.3\gia " old dubai server path
PATH = '\\192.168.160.3\gia\'.
CONCATENATE PATH DATE INTO PATH.
CONCATENATE PATH '.cfm' INTO PATH.
CONDENSE URL NO-GAPS.
CONDENSE PATH NO-GAPS.
CALL FUNCTION 'HTTP_GET_FILE_DP'
EXPORTING
ABSOLUTE_URI = URL
DOCUMENT_PATH = PATH
IMPORTING
STATUS_CODE = STATUS_CODE
STATUS_TEXT = STATUS_TEXT
* TABLES
* RESPONSE_HEADERS =
* EXCEPTIONS
* DP_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* WAIT UP TO 1 SECONDS.
P_FILE = PATH.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '2'
I_END_ROW = '31'
TABLES
INTERN = EXCEL2[].
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
PERFORM UPLOAD_TABLE.
ENDIF.
ENDLOOP.
WRITE :/5 'Batch updated successully' COLOR 6.
ULINE.
FORMAT COLOR 1.
WRITE :/5 'Batch No', 30 'Report No.', 50 'Weight', 70(50) 'Message'.
ULINE.
LOOP AT I_TEMP WHERE CUT IS NOT INITIAL AND CLARITY IS NOT INITIAL AND COLOR
IS NOT INITIAL and shape is NOT INITIAL.
IF VAL1 = 0.
VAL1 = 1.
FORMAT COLOR 3.
ELSE.
VAL1 = 0.
FORMAT COLOR 6.
ENDIF.
WRITE :/5 I_TEMP-CHARG, 30 I_TEMP-REPORT, 50 I_TEMPWEIGHT,
70(50) 'Record uploaded successfully'.
ENDLOOP.
ULINE.
SKIP 3.
WRITE :/5 'Error occured in batch' COLOR 5.
ULINE.
FORMAT COLOR 1.
WRITE :/5 'Batch No', 30 'Report No.', 50 'Weight', 70(50) 'Message'.
ULINE.
LOOP AT I_ERROR1.
IF VAL1 = 0.
VAL1 = 1.
FORMAT COLOR 3.
ELSE.
VAL1 = 0.
FORMAT COLOR 6.
ENDIF.
WRITE :/5 I_ERROR1-CHARG, 30 I_ERROR1-REPORT, 50 I_ERROR1-
WEIGHT, 70(50) I_ERROR1-ERROR.
ENDLOOP.
SKIP 3.
WRITE :/5 'Batch uploaded with blank field' COLOR 5.
ULINE.
FORMAT COLOR 1.
WRITE :/5 'Batch No', 30 'Report No.', 50 'Weight', 70(50) 'Message'.
ULINE.
LOOP AT I_TEMP WHERE CUT IS INITIAL or CLARITY IS INITIAL or COLOR IS INITIAL
or shape is INITIAL.
IF VAL1 = 0.
VAL1 = 1.
FORMAT COLOR 3.
ELSE.
VAL1 = 0.
FORMAT COLOR 6.
ENDIF.
WRITE :/5 I_TEMP-CHARG, 30 I_TEMP-REPORT, 50 I_TEMPWEIGHT,
70(50) 'Record updated with blank field'.
ENDLOOP.
ENDIF.
***********************************************************************
*&---------------------------------------------------------------------*
*& Form FILTER_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_TABLE .
CLEAR : EXCEL3[].
excel3[] = excel2[].
delete ADJACENT DUPLICATES FROM excel2 COMPARING row.
LOOP AT EXCEL2 ASSIGNING .
CASE -VALUE.
WHEN 'Date of Issue:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
CONDENSE -VALUE NO-GAPS.
PERFORM CONVERT_DATE USING -VALUE CHANGING WA_GIA-ISDAT.
ENDIF.
WHEN 'Measurements:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-MGRMENT = -VALUE.
ENDIF.
"------Shape just above from measurment line-------------------------
rval = ( -row - 1 ).
READ TABLE excel3 ASSIGNING WITH KEY row = rval col = 1 .
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZSHAPE4 INTO WA_GIA-SHAPE WHERE DESCR = -
VALUE.
WHEN 'Carat Weight:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-WEIGHT = -WEIGHT.
ENDIF.
WHEN 'Color Grade:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-COLOR = -VALUE.
ENDIF.
WHEN 'Color:'.
READ TABLE excel3 ASSIGNING WITH KEY value = ' Grade:'.
IF sy-subrc eq 0.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
WA_GIA-COLOR = -VALUE.
ENDIF.
WHEN 'Clarity Grade:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-CLARITY = -VALUE.
ENDIF.
WHEN 'Cut Grade:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZDESCR INTO WA_GIA-CUT WHERE DESCR = -
VALUE.
ENDIF.
WHEN 'Depth:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-DEPTHPER = -VALUE.
ENDIF.
WHEN 'Table:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-TABLEPER = -VALUE.
ENDIF.
WHEN 'Crown Angle:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
CLEAR : val3, val4.
SPLIT -VALUE AT '°' INTO val3 val4.
WA_GIA-CROWNANG = val3.
ENDIF.
WHEN 'Crown Height:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-CROWN_HEIGHT = -VALUE.
ENDIF.
WHEN 'Pavilion Angle:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
CLEAR : val3, val4.
SPLIT -VALUE AT '°' INTO val3 val4.
WA_GIA-PAVILINANG = val3.
ENDIF.
WHEN 'Pavilion Depth:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-PAVILIONDEP = -VALUE.
ENDIF.
WHEN 'Star length:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-STAR = -VALUE.
ENDIF.
WHEN 'Lower Half:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
WA_GIA-LOWERHALF = -VALUE.
ENDIF.
WHEN 'Girdle:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZDESCR INTO WA_GIAGIRDLE
WHERE DESCR = -VALUE.
ENDIF.
WHEN 'Culet:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZDESCR INTO WA_GIACULETSIZE
WHERE DESCR = -VALUE.
ENDIF.
WHEN 'Polish:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZDESCR INTO WA_GIAPOLISH
WHERE DESCR = -VALUE.
ENDIF.
WHEN 'Symmetry:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE CODE_N FROM ZDESCR INTO WA_GIASYMMETRY
WHERE DESCR = -VALUE.
ENDIF.
WHEN 'Fluorescence:'.
READ TABLE excel3 ASSIGNING WITH KEY row = -row col = 2.
IF sy-subrc eq 0.
TRANSLATE -VALUE TO UPPER CASE.
SELECT SINGLE FLUORES FROM ZFLUORES_CODE INTO WA_GIAFL
WHERE DESCR = -VALUE.
ENDIF.
ENDCASE.
ENDLOOP.
"WA_GIA-SHAPE = 'TESTING'.
WA_GIA-CHARG = -CHARG.
WA_GIA-REPORT = -REPORT.
WA_GIA-WEIGHT = -WEIGHT.
MOVE-CORRESPONDING WA_GIA TO ZSD_GIA.
*IF WA_GIA-CUT IS NOT INITIAL AND WA_GIA-CLARITY IS NOT INITIAL AND WA_GIACOLOR
IS NOT INITIAL and WA_GIA-shape is NOT INITIAL.
*-----------Enter Record in ZSD_GIA table.
MODIFY ZSD_GIA.
*-----------Enter Record in zlarge_stone_hdr table.
SELECT SINGLE * INTO i_zlarge_hdr FROM zlarge_stone_hdr WHERE BATNO = WA_GI
A-charg.
IF sy-subrc is not INITIAL.
SELECT MAX( SAPNO ) FROM zlarge_stone_hdr INTO sapno .
i_zlarge_hdr-batno = WA_GIA-charg.
i_zlarge_hdr-sapno = sapno + 1.
i_zlarge_hdr-ERSDA = sy-datum.
i_zlarge_hdr-ERNAM = sy-uname.
MOVE-CORRESPONDING i_zlarge_hdr to zlarge_stone_hdr.
modify zlarge_stone_hdr.
ENDIF.
*-----------Enter Record in zlarge_stone_itm table.
SELECT SINGLE * INTO i_zlarge_itm FROM zlarge_stone_itm WHERE BATNO = WA_GIAcharg
and lab = 'GIA'.
IF sy-subrc is not INITIAL.
SELECT MAX( SAPNO ) FROM zlarge_stone_hdr INTO sapno .
SELECT count( * ) FROM zlarge_stone_itm INTO litem1 where batno = WA_GIAcharg
and SEL = 'X'.
SELECT count( * ) FROM zlarge_stone_itm INTO litem where batno = WA_GIAcharg.
i_zlarge_itm-LITEM = ( litem + 1 ) * 10.
i_zlarge_itm-SAPNO = sapno.
i_zlarge_itm-batno = WA_GIA-charg.
i_zlarge_itm-report = WA_GIA-report.
i_zlarge_itm-WEIGHT = WA_GIA-WEIGHT.
i_zlarge_itm-RESULTDAT = WA_GIA-ISDAT.
i_zlarge_itm-MESURMNTS = WA_GIA-MGRMENT.
i_zlarge_itm-COLOR = WA_GIA-COLOR.
i_zlarge_itm-CLARITY = WA_GIA-CLARITY.
i_zlarge_itm-CUT = WA_GIA-CUT.
i_zlarge_itm-DEPTHPER = WA_GIA-DEPTHPER.
i_zlarge_itm-TABLEPER = WA_GIA-TABLEPER.
i_zlarge_itm-CROWNANG = WA_GIA-CROWNANG.
i_zlarge_itm-CROWN_HEIGHT = WA_GIA-CROWN_HEIGHT.
i_zlarge_itm-PAVILINANG = WA_GIA-PAVILINANG.
i_zlarge_itm-PAVILIONDEP = WA_GIA-PAVILIONDEP.
i_zlarge_itm-star = WA_GIA-star.
i_zlarge_itm-LOWERHALF = WA_GIA-LOWERHALF.
i_zlarge_itm-GIRDLE = WA_GIA-GIRDLE.
i_zlarge_itm-CULETSIZE = WA_GIA-CULETSIZE.
i_zlarge_itm-POLISH = WA_GIA-POLISH.
i_zlarge_itm-SYMMETRY = WA_GIA-SYMMETRY.
i_zlarge_itm-FL = WA_GIA-FL.
i_zlarge_itm-SHAPE = WA_GIA-SHAPE.
i_zlarge_itm-LAB = 'GIA'.
IF litem1 EQ 0.
i_zlarge_itm-SEL = 'X'.
ENDIF.
MOVE-CORRESPONDING i_zlarge_itm to zlarge_stone_itm.
modify zlarge_stone_itm.
ENDIF.
*ENDIF.
APPEND ZSD_GIA TO I_TEMP.
CLEAR WA_GIA.
ENDFORM. " FILTER_TABLE
*&---------------------------------------------------------------------*
*& Form F4_HELP_P_FILE_IT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F4_HELP_P_FILE_IT .
DATA : V_FILE LIKE PFILEIT.
* Display popup with files list to select
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = V_FILE.
* if file is selected, then
CHECK SY-SUBRC EQ 0.
PFILEIT = V_FILE.
ENDFORM. " F4_HELP_P_FILE_IT
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = PFILEIT
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_FILE
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
IF IT_FILE[] IS INITIAL.
MESSAGE E001.
RETURN.
ENDIF.
IF SY-SUBRC NE 0 .
MESSAGE E002.
RETURN.
ENDIF.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form CONVERT_DATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_DATATAB_COL2 text
* <--P_WA_GIA_ISDAT text
*----------------------------------------------------------------------*
FORM CONVERT_DATE USING P_IT_DATATAB_COL2
CHANGING P_WA_GIA_ISDAT.
TDATE = P_IT_DATATAB_COL2.
CALL FUNCTION 'Z_CONVERT_TO_INTERNAL_FORMAT1'
EXPORTING
IM_INPUT = TDATE
IMPORTING
EX_OUTPUT = P_WA_GIA_ISDAT
* EXCEPTIONS
* INVALID_DATE = 1
* OTHERS = 2.
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
.
ENDFORM. " CONVERT_DATE
*&---------------------------------------------------------------------*
*& Form WEIGHT_VALIDATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WEIGHT_VALIDATION .
DATA : I_WT(3) TYPE C,
D_WT(3) TYPE C,
VAL TYPE I VALUE 0.
LOOP AT IT_FILE.
SPLIT IT_FILE-WEIGHT AT '.' INTO I_WT D_WT.
IF STRLEN( D_WT ) NE 2.
I_ERROR-REPORT = IT_FILE-REPORT.
I_ERROR-CHARG = IT_FILE-CHARG.
I_ERROR-WEIGHT = IT_FILE-WEIGHT.
I_ERROR-ERROR = 'Decimal part of weight must be of length 2 only.'.
APPEND I_ERROR.
ENDIF.
ENDLOOP.
IF I_ERROR[] IS NOT INITIAL.
ULINE.
FORMAT COLOR 1.
WRITE :/5 'Batch No', 30 'Report No', 50 'Weight', 70(50) 'Error'.
ULINE.
LOOP AT I_ERROR.
IF VAL = 0.
VAL = 1.
FORMAT COLOR 3.
ELSE.
VAL = 0.
FORMAT COLOR 6.
ENDIF.
WRITE :/5 I_ERROR-CHARG, 30 I_ERROR-REPORT, 50 I_ERRORWEIGHT,
70(50) I_ERROR-ERROR.
ENDLOOP.
ENDIF.
ENDFORM. " WEIGHT_VALIDATION

11. Upload Data in Back Ground:
*&---------------------------------------------------------------------*
*& Report Z_LOOSE_STOCK_DOWNLOAD
*&---------------------------------------------------------------------*
*& Report For Finding Loose Stock Matching
*& Developed By : Durgesh Singh
*& Developed On : 24.08.2011
*& Functional : Rakesh Churi
*& T. Code :
*& Modification :
*&---------------------------------------------------------------------*
REPORT Z_LOOSE_STOCK_DOWNLOAD.
TABLES : MCHB, ZMCHB.
DATA: BEGIN OF I_MCHB OCCURS 0,
MATNR TYPE MCHB-MATNR,
WERKS TYPE MCHB-WERKS,
LGORT TYPE MCHB-LGORT,
CHARG TYPE MCHB-CHARG,
CLABS TYPE MCHB-CLABS,
NORMT TYPE MARA-NORMT,
MAKTX TYPE MAKT-MAKTX,
END OF I_MCHB,
BEGIN OF I_TAB OCCURS 0,
MATNR(18) TYPE C,
WERKS(4) TYPE C,
LGORT(4) TYPE C,
CHARG(10) TYPE C,
CLABS(13) TYPE C,
NORMT(18) TYPE C,
MAKTX(40) TYPE C,
TEMP(1) TYPE C,
END OF I_TAB.
DATA : I_ZMCHB TYPE STANDARD TABLE OF ZMCHB WITH HEADER LINE.
DATA : E_FILE LIKE RLGRAP-FILENAME,
HTAB(1) TYPE C,
STR(110) TYPE C,
LENG TYPE I,
VAL TYPE I.
SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001.
PARAMETERS : V_DLD RADIOBUTTON GROUP GRP1,
V_UPD RADIOBUTTON GROUP GRP1.
SELECTION-SCREEN END OF BLOCK BLK01.
START-OF-SELECTION.
IF V_DLD = 'X'.
PERFORM DOWNLOAD.
ELSE.
PERFORM UPLOAD.
ENDIF.
*&---------------------------------------------------------------------*
*& Form DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD .
SELECT A~MATNR
A~WERKS
A~LGORT
A~CHARG
A~CLABS
B~NORMT
C~MAKTX
INTO CORRESPONDING FIELDS OF TABLE I_MCHB
FROM MCHB AS A LEFT JOIN MARA AS B
ON A~MATNR = B~MATNR
LEFT JOIN MAKT AS C
ON A~MATNR = C~MATNR
WHERE A~WERKS IN ('7100','8100','9200') AND
A~CLABS NE 0 AND
A~LGORT EQ 'DNAC'.
SELECT MATNR
WERKS
LGORT
CHARG
CLABS
NORMT
MAKTX
INTO CORRESPONDING FIELDS OF TABLE I_ZMCHB
FROM ZMCHB WHERE CLABS NE 0.
LOOP AT I_ZMCHB.
MOVE-CORRESPONDING I_ZMCHB TO I_TAB.
I_TAB-TEMP = '@'.
APPEND I_TAB.
ENDLOOP.
LOOP AT I_MCHB.
READ TABLE I_ZMCHB WITH KEY MATNR = I_MCHB-MATNR
WERKS = I_MCHB-WERKS
LGORT = I_MCHB-LGORT
CHARG = I_MCHB-CHARG.
IF SYSUBRC
IS NOT INITIAL. " append data that exist in MCHB and not exist in table
ZMCHB
MOVE-CORRESPONDING I_MCHB TO I_TAB.
I_TABTEMP
= '@'. "temprary variable for frmat line at upload only.
APPEND I_TAB.
ENDIF.
ENDLOOP.
READ TABLE I_TAB WITH KEY WERKS = '8100'.
IF SY-SUBRC IS INITIAL.
"E_FILE = '\\192.168.12.12\Downloads\RJCDLD.TXT'.
E_FILE = '\\192.168.50.36\Downloads\RJCDLD.TXT'.
ELSE.
"E_FILE = '\\192.168.12.12\Downloads\FSGDLD.TXT'.
E_FILE = '\\192.168.12.7\Downloads\FSGDLD.TXT'.
ENDIF.
OPEN DATASET E_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT I_TAB.
TRANSFER I_TAB TO E_FILE.
ENDLOOP.
CLOSE DATASET E_FILE.
ENDFORM. " DOWNLOAD
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM UPLOAD .
* E_FILE = '\\192.168.12.12\Downloads\600DLD.TXT'.
IF SY-MANDT = '009'.
E_FILE = '\\192.168.12.7\Downloads\600DLD.TXT'.
ELSEIF SY-MANDT = '007'.
E_FILE = '\\192.168.50.36\Downloads\600DLD.TXT'.
ENDIF.
OPEN DATASET E_FILE FOR INPUT IN BINARY MODE.
IF SY-SUBRC IS INITIAL.
DO.
READ DATASET E_FILE INTO STR LENGTH LENG .
I_TAB-MATNR = STR+0(18).
I_TAB-WERKS = STR+18(4).
I_TAB-LGORT = STR+22(4).
I_TAB-CHARG = STR+26(10).
I_TAB-CLABS = STR+36(13).
I_TAB-NORMT = STR+49(18).
I_TAB-MAKTX = STR+67(40).
APPEND I_TAB.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET E_FILE.
DESCRIBE TABLE I_TAB LINES VAL.
DELETE I_TAB INDEX VAL.
IF SY-MANDT = '009'.
LOOP AT I_TAB WHERE WERKS NE '8100'.
MOVE-CORRESPONDING I_TAB TO I_ZMCHB.
APPEND I_ZMCHB.
ENDLOOP.
ELSEIF SY-MANDT = '007'.
LOOP AT I_TAB WHERE WERKS EQ '8100'.
MOVE-CORRESPONDING I_TAB TO I_ZMCHB.
APPEND I_ZMCHB.
ENDLOOP.
ENDIF.
MODIFY ZMCHB FROM TABLE I_ZMCHB.
ENDIF.
ENDFORM. " UPLOAD

12. Email Report:
DATA: lt_mailrecipients TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,
lt_mailtxt TYPE STANDARD TABLE OF soli WITH HEADER LINE,
lt_attachment TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,
lt_mailsubject TYPE sodocchgi1,
lt_packing_list TYPE STANDARD TABLE OF zsopcklsti1 WITH HEADER LIN
E,
gv_cnt TYPE i,
gd_subject like sodocchgi1-obj_descr,
it_mess_att like solisti1 occurs 0 with header line.
DATA : cts TYPE string,
pcs TYPE string,
weight1 TYPE string,
diff1 TYPE string,
subject TYPE string.
DATA : BEGIN OF i_email OCCURS 0,
emailid TYPE zemailid-EMAIL_ID,
END OF i_email.
SELECT email_id INTO TABLE i_email from zemailid.
LOOP AT i_email.
lt_mailrecipients-rec_type = 'U'.
lt_mailrecipients-com_type = 'INT'.
lt_mailrecipients-RECEIVER = i_email-emailid.
APPEND lt_mailrecipients .
CLEAR lt_mailrecipients .
ENDLOOP.
CLEAR : subject.
Data: temp type string.
Clear : temp.
CONCATENATE '-' sloc into temp.
* CONCATENATE 'PLEASE FIND ATTACHMENT FOR HKSTOCK
STATUS FOR STORAGE LOCATION -
' sloc ' OF PLANT: ' plant1 ' AS ON: ' sdate ', ' stime
* INTO subject. "Commented by raj
CONCATENATE 'PLEASE FIND ATTACHMENT FOR HKSTOCK
STATUS FOR STORAGE LOCATION' temp 'OF PLANT: ' plant1 'AS ON: ' sdate '
, ' stime
INTO subject SEPARATED BY SPACE.
lt_mailtxt = subject. APPEND lt_mailtxt. CLEAR lt_mailtxt.
APPEND lt_mailtxt. CLEAR lt_mailtxt.
lt_mailtxt = 'Thanks,'. APPEND lt_mailtxt. CLEAR lt_mailtxt.
lt_mailtxt = 'SAP'. APPEND lt_mailtxt. CLEAR lt_mailtxt.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONCATENATE 'STOCK STATUS FOR STORAGE LOCATION -
' sloc 'OF PLANT : ' plant1 'AS ON : ' sdate ' ' stime
INTO lt_attachment.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
*"------------------------------Insert Record For DISPLAY System Inventory
CONCATENATE 'Stock Batches not in System Inventory' ' '
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
CONCATENATE 'Batch No.' ' '
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
LOOP AT IT_PCODE INTO WA_PCODE.
CONCATENATE wa_pcode-charg ' '
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
ENDLOOP.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
"------------------------------End Of DISPLAY System Inventory
"------------------------------Insert Record For DISPLAY Physical Inventory
CONCATENATE 'Stock Batches not in Physical Inventory' ' '
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
CONCATENATE 'Batch No.' 'Plant' 'Material No.' 'Material Description' 'Stor
age Location' 'Qty in CTS' 'Qty in Pcs' 'Batch Description'
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
loop at IT_DATA_ST INTO WA_DATA .
CLEAR : cts, pcs.
cts = WA_DATA-CLABS.
pcs = WA_DATA-ext_menge01.
CONCATENATE WA_DATA-charg WA_DATA-werks WA_DATA-MATNR WA_DATAMAKTX
WA_DATA-LGORT cts pcs WA_DATA-STATUS
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
ENDLOOP.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
"------------------------------End Of DISPLAY Physical Inventory
*"------------------------------
Insert Record For DISPLAY System and Physical Inventory
CONCATENATE 'Stock Batches in System and Physical Inventory' ' '
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
CONCATENATE 'Batch No.' 'Plant' 'Material No.' 'Material Description' 'Stor
age Location' 'Qty in CTS' 'Qty in Pcs' 'Phy. Weight' 'Difference'
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
LOOP AT IT_BCODE_WT INTO WA_SCODE.
CLEAR : cts, pcs,weight1,diff1.
cts = WA_SCODE-CLABS.
pcs = WA_SCODE-ext_menge01.
weight1 = WA_SCODE-weight.
diff1 = WA_SCODE-DIFF.
CONCATENATE WA_SCODE-charg WA_SCODE-werks WA_SCODE-MATNR WA_SCODEMAKTX
WA_SCODE-LGORT cts pcs weight1 diff1
INTO lt_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lt_attachment
INTO lt_attachment.
APPEND lt_attachment. CLEAR lt_attachment.
ENDLOOP.
"------------------------------End Of DISPLAY System and Physical Inventory
CLEAR : subject.
CONCATENATE 'STOCK STATUS - ' ' SAP SYSTEM GENERATED EMAIL'
INTO subject.
lt_packing_list-transf_bin = SPACE.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = LINES( lt_attachment ).
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list. CLEAR lt_packing_list.
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = LINES( lt_attachment ).
lt_packing_listdoc_
type = 'XLS'. " You can give RAW incase if you want just a txt file.
lt_packing_list-obj_name = 'ZBARCODE_WT'.
lt_packing_list-obj_descr = 'ZBARCODE_WT'.
lt_packing_list-doc_size = lt_packing_list-body_num * 255.
APPEND lt_packing_list. CLEAR lt_packing_list.
lt_mailsubject-obj_name = 'MAILATTCH'.
lt_mailsubject-obj_langu = sy-langu.
lt_mailsubject-obj_descr = subject.
lt_mailsubject-sensitivty = 'F'.
gv_cnt = LINES( lt_attachment ).
lt_mailsubject-doc_size = ( gv_cnt -
1 ) * 255 + STRLEN( lt_attachment ).
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lt_mailsubject
TABLES
packing_list = lt_packing_list
contents_bin = lt_attachment
contents_txt = lt_mailtxt
receivers = lt_mailrecipients
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc EQ 0.
COMMIT WORK.
SUBMIT rsconn01 WITH MODE = 'INT' AND RETURN.
ENDIF.

13. PDF On Screen 1:
Driver Program
*&---------------------------------------------------------------------*
*& Report Z_PDF_CONVERT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_PDF_CONVERT NO STANDARD PAGE HEADING.
DATA : GS_PRINT_PARMS TYPE PRI_PARAMS,
L_VALID TYPE STRING,
GS_TSP01 TYPE TSP01,
GV_RQ2NAME TYPE TSP01-RQ2NAME.
DATA: CONTROL TYPE SSFCTRLOP,
ERRTAB TYPE TSFERROR,
OUTPUT TYPE SSFCOMPOP,
FMCNP TYPE RS38L_FNAM.
PARAMETERS :
VAL AS CHECKBOX.
IF VAL = 'X'.
CONCATENATE SY-REPID+0(9) SY-UNAME+0(3) INTO GV_RQ2NAME.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
DESTINATION = 'LOCL'
LAYOUT = 'X_65_80'
LINE_SIZE = '80'
NO_DIALOG = 'X'
IMPORTING
OUT_PARAMETERS = GS_PRINT_PARMS
VALID = L_VALID
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GS_PRINT_PARMS-PRIMM = ' '.
GS_PRINT_PARMS-PRCOP = '1'.
DELETE FROM TSP01
WHERE RQ2NAME EQ GV_RQ2NAME.
SUBMIT Z_PDF_CONVERT TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS GS_PRINT_PARMS
AND RETURN.
SELECT SINGLE *
FROM TSP01
INTO GS_TSP01
WHERE RQOWNER EQ SY-UNAME.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'Z_FM_PDF_DATADISPLAY'
EXPORTING
SPOOLNO = GS_TSP01-RQIDENT
NAME = GS_TSP01-RQO1NAME.
DELETE TSP01 FROM GS_TSP01.
COMMIT WORK AND WAIT.
EXIT.
ENDIF.
ELSE.
DATA: WA_OUTPUT_OPTIONS TYPE SSFCOMPOP.
DATA :WA_JOB_OUTPUT_INFO TYPE SSFCRESCL,
JOB_OUTPUT_OPTIONS TYPE SSFCRESOP.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'Z_TEST_DURGESH'
IMPORTING
FM_NAME = FMCNP
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
CONTROL-NO_DIALOG = 'X'.
OUTPUT-TDDEST = 'LOCL'.
OUTPUT-TDNEWID = 'X'.
OUTPUT-TDIEXIT = 'X'.
OUTPUT-TDFINAL = 'X'.
OUTPUT-TDNOPRINT = ' '.
CALL FUNCTION FMCNP
EXPORTING
USER_SETTINGS = ' '
CONTROL_PARAMETERS = CONTROL
OUTPUT_OPTIONS = OUTPUT
IMPORTING
JOB_OUTPUT_INFO = WA_JOB_OUTPUT_INFO
JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS.
ENDIF.
'Z_FM_PDF_DATADISPLAY'
Import parameter - SPOOLNO TYPE TSP01-RQIDENT
NAME TYPE RSTSTYPE-NAME
Source Code –
DATA: NUMBYTES TYPE I,
PDFSPOOLID LIKE TSP01-RQIDENT,
JOBNAME LIKE TBTCJOB-JOBNAME,
JOBCOUNT LIKE TBTCJOB-JOBCOUNT,
OBJTYPE LIKE RSTSTYPE-TYPE,
TYPE LIKE RSTSTYPE-TYPE,
IS_OTF.
DATA: PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
AUTHORITY = 'SP01'
CLIENT = SY-MANDT
NAME = NAME
PART = 1
IMPORTING
TYPE = TYPE
OBJTYPE = OBJTYPE
EXCEPTIONS
FB_ERROR = 1
FB_RSTS_OTHER = 2
NO_OBJECT = 3
NO_PERMISSION = 4.
IF OBJTYPE(3) = 'OTF'.
IS_OTF = 'X'.
ELSE.
IS_OTF = SPACE.
ENDIF.
IF IS_OTF = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = NUMBYTES
PDF_SPOOLID = PDFSPOOLID
BTC_JOBNAME = JOBNAME
BTC_JOBCOUNT = JOBCOUNT
TABLES
PDF = PDF
EXCEPTIONS
ERR_NO_OTF_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DSTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = NUMBYTES
PDF_SPOOLID = PDFSPOOLID
BTC_JOBNAME = JOBNAME
BTC_JOBCOUNT = JOBCOUNT
TABLES
PDF = PDF
EXCEPTIONS
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'D:\durgesh.pdf'
FILETYPE = 'BIN'
TABLES
DATA_TAB = PDF
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
CALL SCREEN 100.
Screen –
PBO –
SET PF-STATUS 'STS'.
SET TITLEBAR 'TTL'.
IF MY_MAIN_CONTAINER IS INITIAL.
CREATE OBJECT MY_MAIN_CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM_CNTL'
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
" -----------------------------------
" create PDF Viewer object
CREATE OBJECT MY_PDF_VIEWER
EXPORTING
PARENT = MY_MAIN_CONTAINER
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
"could not create PDF Viewer
ENDIF.
ENDIF.
DATA: VIEW_BUTTONS_ACTIVE TYPE CHAR01.
IF MY_PDF_VIEWER->ACROBAT_VS_READER = ''.
VIEW_BUTTONS_ACTIVE = 'X'.
ENDIF.
" -----------------------------------
" create SAP toolbar for PDF Viewer
CALL METHOD MY_PDF_VIEWER->CREATE_TOOLBAR
EXPORTING
TOOL_BUTTONS = 'X'
VIEW_BUTTONS = VIEW_BUTTONS_ACTIVE
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
"could not create toolbar
ENDIF.
CREATE OBJECT L_EVENT_RECEIVER.
SET HANDLER L_EVENT_RECEIVER->ON_DOCUMENT_SAVED FOR MY_PDF_VIEWER.
SET HANDLER L_EVENT_RECEIVER->ON_VIEWING_FINISHED FOR MY_PDF_VIEWER.
IF NOT MY_PDF_VIEWER->HTML_VIEWER IS INITIAL.
CALL METHOD MY_PDF_VIEWER->OPEN_DOCUMENT
EXPORTING
URL = 'D:\durgesh.pdf'.
ENDIF.
ENDIF.
PAI –
CASE OKCODE.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
WHEN 'LOADURL'.
CALL METHOD MY_PDF_VIEWER->OPEN_DOCUMENT
EXPORTING
URL = 'http://p34198/myweb/Devfaq.pdf'.
WHEN 'EVENT'.
ENTRY1 = L_EVENT_RECEIVER->ENTRY_FIELD1.
ENTRY2 = L_EVENT_RECEIVER->ENTRY_FIELD2.
ENDCASE.






























14. PDF On Screen 2:

Driver Program
*&---------------------------------------------------------------------*
*& Report Z_PDF_CONVERT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_PDF_CONVERT NO STANDARD PAGE HEADING.
DATA : GS_PRINT_PARMS TYPE PRI_PARAMS,
L_VALID TYPE STRING,
GS_TSP01 TYPE TSP01,
GV_RQ2NAME TYPE TSP01-RQ2NAME.
DATA: CONTROL TYPE SSFCTRLOP,
ERRTAB TYPE TSFERROR,
OUTPUT TYPE SSFCOMPOP,
FMCNP TYPE RS38L_FNAM.
PARAMETERS :
VAL AS CHECKBOX.
IF VAL = 'X'.
CONCATENATE SY-REPID+0(9) SY-UNAME+0(3) INTO GV_RQ2NAME.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
DESTINATION = 'LOCL'
LAYOUT = 'X_65_80'
LINE_SIZE = '80'
NO_DIALOG = 'X'
IMPORTING
OUT_PARAMETERS = GS_PRINT_PARMS
VALID = L_VALID
EXCEPTIONS
ARCHIVE_INFO_NOT_FOUND = 1
INVALID_PRINT_PARAMS = 2
INVALID_ARCHIVE_PARAMS = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GS_PRINT_PARMS-PRIMM = ' '.
GS_PRINT_PARMS-PRCOP = '1'.
DELETE FROM TSP01
WHERE RQOWNER EQ SY-UNAME.
SUBMIT Z_PDF_CONVERT TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS GS_PRINT_PARMS
AND RETURN.
SELECT SINGLE *
FROM TSP01
INTO GS_TSP01
WHERE RQOWNER EQ SY-UNAME.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'Z_FM_PDF_DATADISPLAY'
EXPORTING
SPOOLNO = GS_TSP01-RQIDENT
NAME = GS_TSP01-RQO1NAME.
DELETE TSP01 FROM GS_TSP01.
COMMIT WORK AND WAIT.
EXIT.
ENDIF.
ELSE.
DATA: WA_OUTPUT_OPTIONS TYPE SSFCOMPOP.
DATA :WA_JOB_OUTPUT_INFO TYPE SSFCRESCL,
JOB_OUTPUT_OPTIONS TYPE SSFCRESOP.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'Z_TEST_DURGESH'
IMPORTING
FM_NAME = FMCNP
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
CONTROL-NO_DIALOG = 'X'.
OUTPUT-TDDEST = 'LOCL'.
OUTPUT-TDNEWID = 'X'.
OUTPUT-TDIEXIT = 'X'.
OUTPUT-TDFINAL = 'X'.
OUTPUT-TDNOPRINT = ' '.
CALL FUNCTION FMCNP
EXPORTING
USER_SETTINGS = ' '
CONTROL_PARAMETERS = CONTROL
OUTPUT_OPTIONS = OUTPUT
IMPORTING
JOB_OUTPUT_INFO = WA_JOB_OUTPUT_INFO
JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS.
ENDIF.
'Z_FM_PDF_DATADISPLAY'
Import parameter - SPOOLNO TYPE TSP01-RQIDENT
NAME TYPE RSTSTYPE-NAME
Source Code –
FUNCTION Z_FM_PDF_DATADISPLAY.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(SPOOLNO) TYPE TSP01-RQIDENT
*" REFERENCE(NAME) TYPE RSTSTYPE-NAME
*"----------------------------------------------------------------------
DATA: NUMBYTES TYPE I,
PDFSPOOLID LIKE TSP01-RQIDENT,
JOBNAME LIKE TBTCJOB-JOBNAME,
JOBCOUNT LIKE TBTCJOB-JOBCOUNT,
OBJTYPE LIKE RSTSTYPE-TYPE,
TYPE LIKE RSTSTYPE-TYPE,
IS_OTF.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
AUTHORITY = 'SP01'
CLIENT = SY-MANDT
NAME = NAME
PART = 1
IMPORTING
TYPE = TYPE
OBJTYPE = OBJTYPE
EXCEPTIONS
FB_ERROR = 1
FB_RSTS_OTHER = 2
NO_OBJECT = 3
NO_PERMISSION = 4.
IF OBJTYPE(3) = 'OTF'.
IS_OTF = 'X'.
ELSEIF OBJTYPE(3) = 'TEX'.
IS_OTF = SPACE.
ELSE.
IS_OTF = 'X'.
ENDIF.
IF IS_OTF = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = NUMBYTES
PDF_SPOOLID = PDFSPOOLID
BTC_JOBNAME = JOBNAME
BTC_JOBCOUNT = JOBCOUNT
TABLES
PDF = PDF
EXCEPTIONS
ERR_NO_OTF_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DSTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = SPOOLNO
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = NUMBYTES
PDF_SPOOLID = PDFSPOOLID
BTC_JOBNAME = JOBNAME
BTC_JOBCOUNT = JOBCOUNT
TABLES
PDF = PDF
EXCEPTIONS
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
ENDIF.
* convert pdf to xstring string
LOOP AT PDF INTO LS_PDF.
ASSIGN LS_PDF TO CASTING.
CONCATENATE LV_CONTENT INTO LV_CONTENT IN BYTE MODE.
ENDLOOP.
CALL SCREEN 100.
ENDFUNCTION.
Screen
PBO –
SET PF-STATUS 'STS'.
SET TITLEBAR 'TTL'.
CREATE OBJECT G_HTML_CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM_CNTL'.
CREATE OBJECT G_HTML_CONTROL
EXPORTING
PARENT = G_HTML_CONTAINER.
* Convert xstring to binary table to pass to the LOAD_DATA method
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LV_CONTENT
TABLES
BINARY_TAB = LT_DATA.
* Load the HTML
CALL METHOD G_HTML_CONTROL->LOAD_DATA(
EXPORTING
TYPE = 'application'
SUBTYPE = 'pdf'
IMPORTING
ASSIGNED_URL = LV_URL
CHANGING
DATA_TABLE = LT_DATA
EXCEPTIONS
DP_INVALID_PARAMETER = 1
DP_ERROR_GENERAL = 2
CNTL_ERROR = 3
OTHERS = 4 ).
* Show it
CALL METHOD G_HTML_CONTROL->SHOW_URL( URL = LV_URL IN_PLACE = 'X' ).
PAI –
CASE OKCODE.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.


15. Program To Find User Exit:
*&---------------------------------------------------------------------*
*& Report Z_FIND_EXIT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_FIND_EXIT.
tables : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.
tables : tstct.
data : jtab like tadir occurs 0 with header line.
data : field1(30).
data : v_devclass like tadir-devclass.
parameters : p_tcode like tstc-tcode obligatory.
select single * from tstc where tcode eq p_tcode.
if sy-subrc eq 0.
select single * from tadir where pgmid = 'R3TR'
and object = 'PROG'
and obj_name = tstc-pgmna.
move : tadir-devclass to v_devclass.
if sy-subrc ne 0.
select single * from trdir where name = tstc-pgmna.
if trdir-subc eq 'F'.
select single * from tfdir where pname = tstc-pgmna.
select single * from enlfdir where funcname =
tfdir-funcname.
select single * from tadir where pgmid = 'R3TR'
and object = 'FUGR'
and obj_name eq enlfdir-area.
move : tadir-devclass to v_devclass.
endif.
endif.
select * from tadir into table jtab
where pgmid = 'R3TR'
and object = 'SMOD'
and devclass = v_devclass.
select single * from tstct where sprsl eq sy-langu and
tcode eq p_tcode.
format color col_positive intensified off.
write:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
skip.
if not jtab[] is initial.
write:/(95) sy-uline.
format color col_heading intensified on.
write:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
write:/(95) sy-uline.
loop at jtab.
select single * from modsapt
where sprsl = sy-langu and
name = jtab-obj_name.
format color col_normal intensified off.
write:/1 sy-vline,
2 jtab-obj_name hotspot on,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.
endloop.
write:/(95) sy-uline.
describe table jtab.
skip.
format color col_total intensified on.
write:/ 'No of Exits:' , sy-tfill.
else.
format color col_negative intensified on.
write:/(95) 'No User Exit exists'.
endif.
else.
format color col_negative intensified on.
write:/(95) 'Transaction Code Does Not Exist'.
endif.
at line-selection.
get cursor field field1.
check field1(4) eq 'JTAB'.
set parameter id 'MON' field sy-lisel+1(10).
call transaction 'SMOD' and skip first screen.
*---End of Program

16. Selection Option in Module Pool:
*&---------------------------------------------------------------------*
*& Report Z_PO_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_PO_UPLOAD MESSAGE-ID zpoattach.
TABLES : EKKO.
DATA: BEGIN OF ITAB OCCURS 0,
EBELN LIKE EKKO-EBELN,
END OF ITAB .
DATA : LT_FIELDS TYPE TABLE OF DFIES,
LS_FIELD TYPE DFIES,
FLG TYPE I VALUE 1,
OK_CODE TYPE SY-UCOMM,
ebeln TYPE ekko-ebeln.
SELECTION-SCREEN BEGIN OF SCREEN 400 AS SUBSCREEN.
PARAMETERS : VPATH TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF SCREEN 400.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR VPATH.
PERFORM F4_HELP_P_FILE_IT.
START-OF-SELECTION.
CALL SCREEN 100.
INCLUDE Z_PO_UPLOAD_STATUS_0100O01.
INCLUDE Z_PO_UPLOAD_USER_COMMAND_01I01.
INCLUDE Z_PO_UPLOAD_VALIDATEI01.
*&---------------------------------------------------------------------*
*& Form F4_HELP_P_FILE_IT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F4_HELP_P_FILE_IT .
DATA : V_FILE LIKE VPATH.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = V_FILE.
CHECK SY-SUBRC EQ 0.
VPATH = V_FILE.
ENDFORM. " F4_HELP_P_FILE_IT
INCLUDE Z_PO_UPLOAD_RENAME_FILEF01.
INCLUDE Z_PO_UPLOAD_COPYF01.

17. Service PO Using BAPI:
DATA : I_POHDR TYPE STANDARD TABLE OF BAPIMEPOHEADER WITH HEADER LINE,
I_POHDRX TYPE STANDARD TABLE OF BAPIMEPOHEADERX WITH HEADER LINE,
I_POITM TYPE STANDARD TABLE OF BAPIMEPOITEM WITH HEADER LINE,
I_POITMX TYPE STANDARD TABLE OF BAPIMEPOITEMX WITH HEADER LINE,
I_POSERVICE TYPE STANDARD TABLE OF BAPIESLLC WITH HEADER LINE,
I_POACCOUNT TYPE STANDARD TABLE OF BAPIMEPOACCOUNT WITH HEADER LINE,
I_POACCOUNTX TYPE STANDARD TABLE OF BAPIMEPOACCOUNTX WITH HEADER LINE,
I_POSERVICEV TYPE STANDARD TABLE OF BAPIESKLC WITH HEADER LINE.
DATA : PONO TYPE BAPIMEPOHEADER-PO_NUMBER,
PCKG_NO TYPE BAPIMEPOITEM-PCKG_NO.
REFRESH: I_POHDR[],I_POHDRX[],I_POITM[],I_POITMX[],I_POSERVICE[],
I_POSERVICEV[],I_POACCOUNT[],I_POACCOUNTX[].
CLEAR : ICNT,I_POHDR,I_POITM,I_POHDRX,I_POITMX,I_POSERVICE,I_POSERVICEV,
I_POACCOUNT,I_POACCOUNTX.
*--------Header data
I_POHDR-COMP_CODE = 4000. "VBUKRS.
I_POHDR-DOC_TYPE = 'ZLAB'.
I_POHDR-ITEM_INTVL = '00010'.
I_POHDR-VENDOR = LFA1-LIFNR.
I_POHDR-PMNTTRMS = 'D060'. "EKKO-ZTERM.
I_POHDR-PURCH_ORG = 4130. "VEKORG.
I_POHDR-PUR_GROUP = 100. " VEKGRP.
I_POHDR-CURRENCY = 'HKD'. "EKKO-WAERS.
I_POHDR-DOC_DATE = PDATE.
APPEND I_POHDR.
I_POHDRX-COMP_CODE = 'X'.
I_POHDRX-DOC_TYPE = 'X'.
I_POHDRX-ITEM_INTVL = 'X'.
I_POHDRX-VENDOR = 'X'.
I_POHDRX-PMNTTRMS = 'X'.
I_POHDRX-PURCH_ORG = 'X'.
I_POHDRX-PUR_GROUP = 'X'.
I_POHDRX-CURRENCY = 'X'.
I_POHDRX-DOC_DATE = 'X'.
APPEND I_POHDRX.
*--------Line data
LOOP AT IT_OUT1 INTO WA_OUT.
ICNT = ICNT + 1.
PCKG_NO = PCKG_NO + 1.
I_POITM-PO_ITEM = ICNT * 10.
I_POITM-PCKG_NO = PCKG_NO.
I_POITM-ACCTASSCAT = 'K'.
I_POITM-ITEM_CAT = 'D'.
I_POITM-SHORT_TEXT = WA_OUT-CHARG.
I_POITM-PLANT = WA_OUT-WERKS.
I_POITM-BATCH = WA_OUT-CHARG.
I_POITM-STGE_LOC = WA_OUT-LGORT.
I_POITM-QUANTITY = WA_OUT-CLABS.
I_POITM-MATL_GROUP = 'D11'.
APPEND I_POITM.
CLEAR :I_POITM.
I_POITMX-PO_ITEM = ICNT * 10.
I_POITMX-PCKG_NO = 'X'.
I_POITMX-ACCTASSCAT = 'X'.
I_POITMX-ITEM_CAT = 'X'.
I_POITMX-SHORT_TEXT = 'X'.
I_POITMX-PLANT = 'X'.
I_POITMX-BATCH = 'X'.
I_POITMX-STGE_LOC = 'X'.
I_POITMX-QUANTITY = 'X'.
I_POITMX-MATL_GROUP = 'X'.
APPEND I_POITMX.
CLEAR :I_POITMX.
I_POSERVICE-PCKG_NO = PCKG_NO.
I_POSERVICE-LINE_NO = '0000000001'.
I_POSERVICE-OUTL_IND = 'X'.
I_POSERVICE-SUBPCKG_NO = PCKG_NO + 1.
I_POSERVICE-FROM_LINE = '1'.
APPEND I_POSERVICE.
CLEAR I_POSERVICE.
PCKG_NO = PCKG_NO + 1.
I_POSERVICE-PCKG_NO = PCKG_NO.
I_POSERVICE-LINE_NO = '0000000002'.
I_POSERVICE-SERVICE = '000000000003000000'.
I_POSERVICE-QUANTITY = WA_OUT-CLABS.
I_POSERVICE-BASE_UOM = 'AU'.
I_POSERVICE-PRICE_UNIT = '1'.
I_POSERVICE-GR_PRICE = 1000."ZMCHA_S-TOT_PRICE.
I_POSERVICE-MATL_GROUP = 'POLISH'.
APPEND I_POSERVICE.
CLEAR I_POSERVICE.
I_POSERVICEV-PCKG_NO = PCKG_NO.
I_POSERVICEV-LINE_NO = '0000000002'.
I_POSERVICEV-SERNO_LINE = '01'.
I_POSERVICEV-SERIAL_NO = '01'.
I_POSERVICEV-QUANTITY = WA_OUT-CLABS.
APPEND I_POSERVICEV.
I_POACCOUNT-PO_ITEM = ICNT * 10.
I_POACCOUNT-SERIAL_NO = '01'.
I_POACCOUNT-QUANTITY = WA_OUT-CLABS.
I_POACCOUNT-GL_ACCOUNT = '0000800101'.
I_POACCOUNT-COSTCENTER = '0041304001'.
I_POACCOUNT-CO_AREA = 4000.
I_POACCOUNT-NET_VALUE = 1000.
APPEND I_POACCOUNT.
I_POACCOUNTX-PO_ITEM = ICNT * 10.
I_POACCOUNTX-SERIAL_NO = '01'.
I_POACCOUNTX-QUANTITY = 'X'.
I_POACCOUNTX-GL_ACCOUNT = 'X'.
I_POACCOUNTX-COSTCENTER = 'X'.
I_POACCOUNTX-CO_AREA = 'X'.
I_POACCOUNTX-NET_VALUE = 'X'.
APPEND I_POACCOUNTX.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = I_POHDR
POHEADERX = I_POHDRX
IMPORTING
EXPPURCHASEORDER = PONO
TABLES
RETURN = GT_RETURN
POITEM = I_POITM
POITEMX = I_POITMX
POACCOUNT = I_POACCOUNT
POACCOUNTX = I_POACCOUNTX
POSERVICES = I_POSERVICE
POSRVACCESSVALUES = I_POSERVICEV.
READ TABLE GT_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CALL SCREEN 101 STARTING AT '15' '3'.
MESSAGE ID 'ZGRN' TYPE 'E' NUMBER 001 .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
CLEAR TEXT2.
CONCATENATE 'Document no.' GOODSMVT_HEADRET-MAT_DOC 'and PO no.' PONO
INTO TEXT2 SEPARATED BY SPACE.
MESSAGE S000 WITH TEXT2.
PERFORM UPDATE_TABLE1 .
LEAVE TO SCREEN 0.
ENDIF.

18. New Tab in PO Using BADI:
Implement BADI (ME_GUI_PO_CUST & ME_PROCESS_PO_CUST) For Adding New Tab In PO Creation
(ME21N)
BADI ‐ ME_GUI_PO_CUST ‐>
Subscribe Method ‐> (Create subscreen)
method IF_EX_ME_GUI_PO_CUST~SUBSCRIBE.
data : i_subscribers like line of re_subscribers.
check im_application = 'PO'.
check im_element = 'HEADER'.
clear : re_subscribers[].
i_subscribers-name = subscreen1.
i_subscribers-DYNPRO = '0100'.
i_subscribers-program = 'SAPLZPOHDR'. (i.e. SAPL + ZPOHDR(function group))
i_subscribers-STRUCT_NAME = 'CI_EKKODB'.
i_subscribers-label = text-001.
i_subscribers-POSITION = 5.
i_subscribers-HEIGHT = 7.
append i_subscribers to re_subscribers.
endmethod.


MAP_DYNPRO_FIELDS Method‐> (Create Field Catalog)
method IF_EX_ME_GUI_PO_CUST~MAP_DYNPRO_FIELDS.
field-symbols : like line of ch_mapping.
LOOP AT ch_mapping assigning .
IF -fieldname = 'ZCUSTNAME'.
-metafield = mmmfd_cust_01.
elseif -fieldname = 'ZCUSTADR'.
-metafield = mmmfd_cust_02.
ENDIF.
ENDLOOP.
endmethod.
TRANSPORT_FROM_MODEL Method‐>(Get Data From Table EKKO)


TRANSPORT_FROM_MODEL Method‐>(Get Data From Table EKKO)
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_MODEL.
DATA: l_header TYPE REF TO if_purchase_order_mm,
ls_mepoheader TYPE mepoheader.
check im_name = subscreen1.
mmpur_dynamic_cast l_header im_model.
check not l_header is initial.

ls_mepoheader = l_header->get_data( ).
move-corresponding ls_mepoheader to DYNP_DATA_PBO.
endmethod.
TRANSPORT_TO_DYNP Method‐> (Pass Data To Display Screen)
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_DYNP.
check im_name = subscreen1.
CALL FUNCTION 'ZPOHDR_MOVE_TO_SCREEN'
EXPORTING
DYNP_DATA_PBO = DYNP_DATA_PBO.
endmethod.
TRANSPORT_FROM_DYNP Method‐>(Fetch Data From Screen After Change or Containing same Value)
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_DYNP.
check im_name = subscreen1.
CALL FUNCTION 'ZPOHDR_FETCH_FROM_SCREEN'
IMPORTING
DYNP_DATA_PAI = DYNP_DATA_PAI.
if DYNP_DATA_PAI ne DYNP_DATA_PBO.
re_changed = 'X'.
endif.
endmethod


TRANSPORT_TO_MODEL Method‐> (Save Data To Database)
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_MODEL.
DATA: l_header TYPE REF TO if_purchase_order_mm,
ls_mepoheader TYPE mepoheader.
check im_name = subscreen1.
mmpur_dynamic_cast l_header im_model.
check not l_header is initial.
ls_mepoheader = l_header->get_data( ).
if DYNP_DATA_PAI ne DYNP_DATA_PBO.
move-corresponding DYNP_DATA_PAI to ls_mepoheader.
CALL METHOD l_header->set_data
EXPORTING
im_data = ls_mepoheader.
endif.




BADI ‐ ME_PROCESS_PO_CUST ‐>
FIELDSELECTION_HEADER Method‐>
method IF_EX_ME_PROCESS_PO_CUST~FIELDSELECTION_HEADER.
FIELD-SYMBOLS: LIKE LINE OF CH_FIELDSELECTION.
if sy-tcode ='ME21N' OR sy-tcode ='ME22N'.
READ TABLE CH_FIELDSELECTION ASSIGNING WITH TABLE KEY METAFIELD = MM
MFD_CUST_01.
IF SY-SUBRC IS INITIAL.
-FIELDSTATUS = '.'. " change
ENDIF.
READ TABLE CH_FIELDSELECTION ASSIGNING WITH TABLE KEY METAFIELD = MM
MFD_CUST_02.
IF SY-SUBRC IS INITIAL.
-FIELDSTATUS = '.'. " change
ENDIF.
else.
READ TABLE CH_FIELDSELECTION ASSIGNING WITH TABLE KEY METAFIELD = MM
MFD_CUST_01.
IF SY-SUBRC IS INITIAL.
-FIELDSTATUS = '*'. " display
ENDIF.
READ TABLE CH_FIELDSELECTION ASSIGNING WITH TABLE KEY METAFIELD = MM
MFD_CUST_02.
IF SY-SUBRC IS INITIAL.
-FIELDSTATUS = '*'. " display
ENDIF.
ENDIF.
endmethod.