Anda di halaman 1dari 19

report zdktesthr01

message-id zh.
************************************************************************
* Report: ZHO00036
* Object: HRI0036
*****------------------------------------------------------------------*
* Program title: Org publisher extract
*****------------------------------------------------------------------*
* Author:
* Date:
*****------------------------------------------------------------------*
* Processing Details:
* This program will display org structure using relationaships org to
* org, position to org and chief to org
* Inputs : for Detailed Audit Report
* Output :
* Logical Path
* Physical File Name
* Download File Name

: Z_INT_OUTBOUND_PATH
: ZHO00036
: /<sid>/int/out/hr/ZHO00004_YYYYMMDD_HHMM.TXT

*
* Requirement

* Assumptions in Program :
* Procedures / Forms Used :
* Logical Database Used

: PCH

* Message Class

: ZH

* Transport Request Number :


*---------------------------------------------------------------------**
************************************************************************
*
T A B L E S
************************************************************************
*
tables: objec,
"Work Area for Database PCH
gdstr,
"General Structure Description
hrp1001,
filenameci.
" Platform-Independent File Names, Cross-Client
infotypes: 0002,
1000,
1001 ,
1003.

"HR Master Record: Infotype 0002 (Personal Data)


"Object Name
"Relationships
"Staff/Approval

************************************************************************
*
S E L E C T I O N
S C R E E N
*
************************************************************************
*----------------------------------------------------------------------*
*
SELECT-OPTIONS & PARAMETERS
**---------------------------------------------------------------------*

selection-screen: begin of block a with frame title text-t02.


selection-screen begin of line.
selection-screen position 5.
parameters p_opfil1 radiobutton group ctu.
selection-screen comment 8(25) text-s01 for field p_opfil1.
selection-screen position 40.
parameters p_opfil2 radiobutton group ctu.
selection-screen comment 43(35) text-s02 for field p_opfil2.
selection-screen end of line.
* Logical Path Name
parameters : p_lgfil like filenameci-pathintern.
* File Name
parameters : p_ofile like filenameci-fileextern.
parameters : p_lfile like rlgrap-filename default 'C:\'.
selection-screen: end of block a.
selection-screen: begin of block a1 with frame title text-t01.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab1(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld1(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab2(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld2(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab03(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld3(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab4(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld4(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab5(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld5(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab6(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld6(10) type c. "like dd03l-fieldname.
selection-screen end of line.

selection-screen begin of line.


selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab7(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld7(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab8(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld8(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab9(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld9(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 2(30) text-p01 for field p_tab1.
parameter: p_tab10(10) type c. "like dd03l-tabname.
selection-screen comment 48(10) text-p02 for field p_fld1.
parameter: p_fld10(10) type c. "like dd03l-fieldname.
selection-screen end of line.
selection-screen: end of block a1 .
************************************************************************
*
DATA DECLARATIONS
*
************************************************************************
type-pools: slis.
*----------------------------------------------------------------------*
*
INTERNAL TABLES
*
*----------------------------------------------------------------------*
data: begin of i_data occurs 0,
sup_org like hrp1001-objid,
org_unit like hrp1001-objid,
org_name like hrp1000-stext,
emp_type type c,
emp_id like p0002-pernr,
l_name like p0002-vorna,
f_name like objec-stext,
m_name like p0002-midnm,
pos_no like hrp1001-sobid,
pos_text like objec-stext,
blank1(1)
type c,
blank2(1)
type c,
blank3(1)
type c,
blank4(1)
type c,
blank5(1)
type c,
blank6(1)
type c,
blank7(1)
type c,
blank8(1)
type c,
cust_fld1(15) type c,
cust_fld2(15) type c,

cust_fld3(15) type c,
cust_fld4(15) type c,
cust_fld5(15) type c,
cust_fld6(15) type c,
cust_fld7(15) type c,
cust_fld8(15) type c,
cust_fld9(15) type c,
cust_fld10(15) type c,
end of i_data.
data: i_fieldcat type slis_t_fieldcat_alv.

"for passing data to ALV

*----------------------------------------------------------------------*
*
WORKAREAS - variables that will hold temporary data values
*----------------------------------------------------------------------data: w_name
like p0001-ename,
w_position
like p1001-sobid,
w_tabname(10) type c,
w_fldname(10) type c,
w_itabfld(15) type c,
w_fieldcat_ln like line of i_fieldcat, " Work area for alv
w_pgm
like sy-repid,
w_actn(06)
type c,
" Used for Authorization Check Action
w_dataset(60) type c, " Used for FileName Get Storage
w_ofile(60)
type c, " Final Output File Name
w_dd03fldname
like dd03l-fieldname.
*----------------------------------------------------------------------*
*
ACCUMULATORS - accumulate for subtotals or counters
**---------------------------------------------------------------------data: a_cntr type i,
a_col_pos type i,
a_tablines type i,
a_person like sy-index,
a_position like sy-index,
a_orgunit like sy-index,
a_len type i.
*----------------------------------------------------------------------*
*
Constantns
*
*----------------------------------------------------------------------*
data: c_module(2)
type c
value 'hr',
c_write(6)
type c
value 'WRITE ',
c_sep(1)
type c
value '_',
c_ext(4)
type c
value '.txt',
c_coma
type c
value ','.
*----------------------------------------------------------------------*
*
SWITCHES - off/on or true/false values
**---------------------------------------------------------------------*
data: x_chief
type c,
"Flag for chief
x_appended
type c.
*----------------------------------------------------------------------*
*
Field-symbols
*----------------------------------------------------------------------*
field-symbols: <ftab> like p_tab1,

<ffld> like p_fld1,


<fitabfld> like i_data-cust_fld1.
************************************************************************
*
I N I T I A L I Z A T I O N
*
************************************************************************
initialization.
p_lgfil = 'Z_INT_OUTBOUND_PATH'.
p_ofile = sy-repid.
pchplvar = '01'.
pchwegid = 'O-S-P'.
pchotype = 'O'.
pchobjid-low = '50000057'.
append pchobjid.
a_col_pos = 0.
************************************************************************
*
M A I N P R O C E S S I N G F L O W
*
************************************************************************
start-of-selection.
"Main logic
* Procedure for Getting File name from Logical file path and Name and
* Checking Authorization for that Path & File.
if p_opfil2 = 'X'. " Server
perform z_file_name using p_lgfil
" Logical File Name
p_ofile
" Physical Filename
c_module. " Module Name
else.
w_ofile = p_lfile.
* Adding Date & Time Stamp into Output File Name
condense w_ofile no-gaps.
* CONDENSE p_ofile NO-GAPS.
concatenate w_ofile c_sep sy-datum c_sep sy-uzeit+0(4) c_ext
into w_ofile.
endif.
get objec.
perform z_get_data.
* clear i_data.
*----------------------------------------------------------------------*
*
E N D - O F - S E L E C T I O N
*
*----------------------------------------------------------------------*
end-of-selection.
*sort i_data by sup_org org_unit.
*delete adjacent duplicates from i_data.
perform z_control_report.
perform z_write_download.
perform z_create_alv .
perform z_call_func.
*----------------------------------------------------------------------*
*
T 0 P - O F - P A G E
**---------------------------------------------------------------------*
top-of-page.
"Executed before output on a new page
* Report Header Function
* perform z_print_header_report.

*----------------------------------------------------------------------*
*
S E L E C T I O N
S C R E E N
E V E N T S
**---------------------------------------------------------------------at selection-screen on value-request for p_lfile.
call function 'WS_FILENAME_GET'
exporting
def_filename
= p_ofile
def_path
= 'C:\ '
mask
= ',,*.*,*.*.'
mode
= 'O'
importing
filename
= p_lfile
exceptions
inv_winsys
= 1
no_batch
= 2
selection_cancel = 3
selection_error = 4
others
= 5.
at selection-screen.
if p_ofile is initial.
message e027. " File Name Missing !!
endif.
if p_opfil1 = 'X'. " Local PC
if p_lfile is initial.
message e021. " File Name Missing !!
else.
a_len = strlen( p_lfile ).
if a_len <= 3.
message e021. " File Name Missing !!
endif.
endif.
else.
select pathintern up to 1 rows into filenameci-pathintern
from filenameci where pathintern = p_lgfil.
endselect.
if sy-subrc <> 0.
message e019.
endif.
endif.
************************************************************************
*
F O R M S
** NOTE: Write 'Perform <name> and double-click to create forms
***********************************************************************
*&---------------------------------------------------------------------*
*&
Form z_get_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form z_get_data.
data: w_org1 like hrp1001-objid,
w_org2 like hrp1001-sobid,
w_sobid like hrp1001-sobid.
* x_appended = ' '.
* x_chief = ' '.
if objec-otype = 'O'. "and objec-endda = '12.31.9999'.
i_data-org_unit = objec-objid.
"Org id

i_data-org_name = objec-stext.
loop at p1001 where begda le pc-endda
and endda ge pc-begda
and rsign = 'A'
and sclas = 'O'
and relat = '002'.
i_data-sup_org = p1001-sobid.
endloop.
*---Start of Sailaja Change
w_org1 = objec-objid.
do.
select single sobid
into w_sobid
from hrp1001
where begda le pc-endda
and endda ge pc-begda
and rsign = 'A'
and sclas = 'K'
and relat = '011'
and objid = w_org1.
if sy-subrc = 0.
i_data-cust_fld2 = w_sobid+0(10).
exit.
else.
clear : w_org2.
select single sobid
into w_org2
from hrp1001
where begda le pc-endda
and endda ge pc-begda
and rsign = 'A'
and sclas = 'O'
and relat = '002'
and objid = w_org1.
if sy-subrc <> 0.
exit.
endif.
endif.
w_org1 = w_org2+0(8).
enddo.
*---End of Sailaja Change
a_orgunit = a_orgunit + 1.
endif.
if objec-otype = 'S'.
i_data-pos_no = objec-objid.
i_data-pos_text = objec-stext.
loop at p1001 where begda le pc-endda
and endda ge pc-begda
and rsign = 'A'
and relat = '012'
and sclas = 'O'.
*
i_data-emp_id = p1001-sobid.
x_chief = 'X'.
*
i_data-emp_type = 'M'.
*
provide vorna nachn from p0002
*
between pc-begda and pc-endda.
**
where pernr = p001-sobid.
*
i_data-f_name = p0002-vorna.

"Superior org.

"Position for org


"Text for position

"Person for pos


"Chief Person for pos

*
*
*
*
*
*
*

i_data-l_name = p0002-nachn.
i_data-m_name = p0002-midnm.
endprovide.
perform z_custom_fields.
if x_appended = ' '.
append i_data.
endif.
endloop.
a_position = a_position + 1.
endif.

if objec-otype = 'P' .
i_data-emp_id = objec-objid.
*
i_data-f_name = objec-stext.
provide vorna nachn from p0002
between pc-begda and pc-endda.
i_data-f_name = p0002-vorna.
i_data-l_name = p0002-nachn.
i_data-m_name = p0002-midnm.
endprovide.

"Person for pos


"Name of person

*
*
*
*
*
*

loop at p1001 where begda le pc-endda


and endda ge pc-begda
and rsign = 'B'
and relat = '008'.
x_chief = 'X'.
endloop.
if x_chief = 'X'.
i_data-emp_type = 'M'.
"Chief Person for pos
else.
i_data-emp_type = 'E'.
"Person for pos
endif.
x_chief = ' '.
*Selecting custom fields entered on the screen
perform z_custom_fields.
a_person = a_person + 1.
if x_appended = ' '.
append i_data.
endif.
endif.
endform.

" z_get_data

*&---------------------------------------------------------------------*
*&
Form z_custom_fields
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form z_custom_fields.
data: l_cntr(2) type c.
a_cntr = 0.
do 10 times.
a_cntr = a_cntr + 1.
if a_cntr = 2.
continue.
endif.
l_cntr = a_cntr.
concatenate 'P_TAB' l_cntr into w_tabname.
concatenate 'P_FLD' l_cntr into w_fldname.

concatenate 'I_DATA-CUST_FLD' l_cntr into w_itabfld.


assign (w_tabname) to <ftab>.
assign (w_fldname) to <ffld>.
assign (w_itabfld) to <fitabfld>.
*
*
*

<ftab> = w_tabname.
<ffld> = w_fldname.
<fitabfld> = w_itabfld.

if not ( <ftab> is initial ) and not ( <ffld> is initial ).


select single fieldname into w_dd03fldname from dd03l
where tabname = <ftab>
and fieldname = 'PERNR'
and keyflag = 'X'.
if sy-subrc = 0.
select single <ffld> into <fitabfld>
from (<ftab>) where pernr = i_data-emp_id.
*
APPEND i_data.
*
x_appended = 'X'.
endif.
endif.
enddo.
endform.
" z_custom_fields
*&---------------------------------------------------------------------*
*&
Form z_create_alv
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form z_create_alv .
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'SUP_ORG'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Superior Org Unit'(018).
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'ORG_UNIT'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Org Unit'(008).
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.

a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'ORG_NAME'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Org Unit Name'(020).
w_fieldcat_ln-outputlen = '020'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'EMP_TYPE'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-just = 'R'.
w_fieldcat_ln-reptext_ddic = 'Employee Type'(013).
w_fieldcat_ln-outputlen = '013'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
w_fieldcat_ln-just = ' '.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'EMP_ID'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Employee ID'(011).
w_fieldcat_ln-outputlen = '011'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'L_NAME'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Last Name'(009).
w_fieldcat_ln-outputlen = '015'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.

w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'F_NAME'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'First Name'(025).
w_fieldcat_ln-outputlen = '015'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'M_NAME'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Middle Name'(011).
w_fieldcat_ln-outputlen = '015'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'POS_NO'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Position Number'(015).
w_fieldcat_ln-outputlen = '015'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'POS_TEXT'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Position Text'(030).
w_fieldcat_ln-outputlen = '030'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK1'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.

w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK2'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK3'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK4'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK5'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.

append w_fieldcat_ln to i_fieldcat.


a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK6'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK7'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'BLANK8'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Blank'(005).
w_fieldcat_ln-outputlen = '005'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD1'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD2'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.

w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD3'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD4'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD5'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD6'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.

w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD7'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD8'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD9'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
a_col_pos = a_col_pos + 1.
w_fieldcat_ln-tabname = 'i_data'.
w_fieldcat_ln-fieldname = 'CUST_FLD10'.
w_fieldcat_ln-key = ' '.
w_fieldcat_ln-col_pos = a_col_pos.
w_fieldcat_ln-no_out = space.
w_fieldcat_ln-qfieldname = space.
w_fieldcat_ln-reptext_ddic = 'Custom Field'(012).
w_fieldcat_ln-outputlen = '012'.
w_fieldcat_ln-hotspot = ' '.
append w_fieldcat_ln to i_fieldcat.
endform.

" z_create_alv

*&---------------------------------------------------------------------*
*&
Form z_call_func
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text

*----------------------------------------------------------------------*
form z_call_func.
w_pgm = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program
= w_pgm
*
i_callback_user_command = 'USER_COMMAND'
it_fieldcat
= i_fieldcat
i_default
= 'X'
i_save
= 'A'
*
it_events
= g_eventcat
*
it_sort
= g_sortcat
tables
t_outtab
= i_data.
endform.

" z_call_func

*&---------------------------------------------------------------------*
*&
Form z_file_name
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form z_file_name using p_logfil like filenameci-pathintern
p_datset like filenameci-fileextern
p_module like c_module.
* Get the platform-independent logical file name
call function 'FILE_GET_NAME_USING_PATH'
exporting
client
= sy-mandt
logical_path
= p_logfil
operating_system
= sy-opsys
parameter_2
= p_module
file_name
= p_datset
importing
file_name_with_path
= w_dataset
exceptions
path_not_found
= 1
missing_parameter
= 2
operating_system_not_found = 3
file_system_not_found
= 4
others
= 5.
* Error Messages
if sy-subrc <> 0.
message e003 with text-e01.
endif.
w_ofile = w_dataset.
perform z_dwnld_file_check. "To check for download file
clear: w_dataset.
endform.

" z_file_name

*&---------------------------------------------------------------------*
*&
Form Z_DWNLD_FILE_CHECK
*&---------------------------------------------------------------------*
*To check the download file existance

*----------------------------------------------------------------------*
form z_dwnld_file_check.
* Adding Date & Time Stamp into Output File Name
condense w_ofile no-gaps.
* CONDENSE p_ofile NO-GAPS.
concatenate w_ofile c_sep sy-datum c_sep sy-uzeit+0(4) c_ext
into w_ofile.
w_actn = c_write.
* Checking User Authorization
perform z_dataset_auth_check using w_ofile w_actn.
* Checking if file already exist
* open dataset w_ofile in text mode for input.
* if sy-subrc = 0.
*
close dataset w_ofile.
*
message e002 with w_ofile.
* endif.
endform.

" Z_DWNLD_FILE_CHECK

*&---------------------------------------------------------------------*
*&
Form Z_DATASET_AUTH_CHECK
*&---------------------------------------------------------------------*
*To check user authorization before writing dataset
*----------------------------------------------------------------------*
form z_dataset_auth_check using
p_fil like authb-filename
p_actn like c_write.
data: l_fil like authb-filename,
l_actn like c_write.
l_fil = p_fil.
l_actn = p_actn.
call function 'AUTHORITY_CHECK_DATASET'
exporting
activity
= l_actn
filename
= l_fil
exceptions
no_authority
= 1
activity_unknown = 2
others
= 3.
if sy-subrc <> 0.
message e003 with text-e07.
endif.
clear: l_fil, l_actn.
endform.
" Z_DATASET_AUTH_CHECK
*&---------------------------------------------------------------------*
*&
Form Z_Write_Download
*&---------------------------------------------------------------------*
* This Procedure will Check i_line for number of records. If there are
* records in i_line then it will download i_line to Application sever on
* file name stored in w_ofile.
*----------------------------------------------------------------------*
form z_write_download.
data : l_filename like rlgrap-filename.
* Check i_line Internal Table for Number of Records.
a_tablines = 0.
describe table i_data lines a_tablines.
* If I_line has any record.
if a_tablines > 0.

if p_opfil2 = 'X'. " Server


close dataset w_ofile.
* Opening Text file for Output.
open dataset w_ofile for output in text mode.
if sy-subrc <> 0.
message e003 with text-e01.
leave program.
endif.
* Write i_line to Output File.
loop at i_data.
transfer i_data to w_ofile.
clear i_data.
endloop.
*
Closing Output Text File.
close dataset w_ofile.
else.
l_filename = w_ofile.
types truxs_t_text_data(4096) type c occurs 0.
data: i_csv_data type truxs_t_text_data.
call function 'SAP_CONVERT_TO_TEX_FORMAT'
exporting
i_field_seperator
= ','
* I_LINE_HEADER
=
* I_FILENAME
=
* I_APPL_KEEP
= ' '
tables
i_tab_sap_data
= i_data
changing
i_tab_converted_data
= i_csv_data
* EXCEPTIONS
* CONVERSION_FAILED
= 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.
call function 'WS_DOWNLOAD'
exporting
filename
= l_filename
filetype
= 'ASC'
tables
data_tab
= i_csv_data
exceptions
file_open_error
= 1
file_write_error
= 2
invalid_filesize
= 3
invalid_type
= 4
no_batch
= 5
unknown_error
= 6
invalid_table_width
= 7
gui_refuse_filetransfer = 8
customer_error
= 9
others
= 10.
if sy-subrc <> 0.
write:/ 'Error downloading file', w_ofile.
endif.
endif.
endif.
endform.
" Z_write_Download

*&---------------------------------------------------------------------*
*&
Form Z_Control_report
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form z_control_report.
write :/2 text-c01, 25 sy-datum, 40 sy-uzeit.
skip 2.
write :/2 text-c04, 22 w_ofile color 1.
skip 2.
write :/2 text-c05, 22 a_orgunit.
write :/2 text-c06, 22 a_position.
write :/2 text-c07, 22 a_person.
skip 2.
write :/2 text-c12 color 1.
write :/2 text-c08, 22 pchplvar.
write :/2 text-c09, 22 pchotype.
write :/2 text-c10.
loop at pchobjid.
if pchobjid-sign = 'I'. write 22 text-c02. endif.
if pchobjid-sign = 'E'. write 22 text-c03. endif.
if not ( pchobjid-option is initial ).
write 32 pchobjid-option.
endif.
write: 42(10) pchobjid-low, 55(10) pchobjid-high.
skip 1.
endloop.
write :/2 text-c11, 22 pchwegid.
endform.
" Z_Control_report