Google Search - Blog...........

Showing posts with label Sap Abap. Show all posts
Showing posts with label Sap Abap. Show all posts

Get Rental Object Data using BAPI BAPI_RE_RO_GET_LIST

CALL FUNCTION 'BAPI_RE_RO_GET_LIST'
TABLES
seloption = t_seloption
rental_object = t_rental_object
object_address = t_object_address
cosettle_param = t_cosettle_param
term_org_assignment = t_term_org_assignment
term_payment = t_term_payment
term_rhythm = t_term_rhythm
term_vacancy = t_term_vacancy
term_adjustment = t_term_adjustment
measurement = t_measurement
rent_obj_rel = t_rent_obj_rel
partner = t_partner
option_rate = t_option_rate
cosettle_rule = t_cosettle_rule
charact = t_charact
condition = t_condition
cond_calc = t_cond_calc
acc_firm = t_acc_firm
obj_assign = t_obj_assign
occupancy = t_occupancy
measpt = t_measpt
measpt_rel = t_measpt_rel
arch_rel = t_arch_rel
arch_relms = t_arch_relms
resubm_rule = t_resubm_rule
resubm_date = t_resubm_date
status = t_status
extension_out = t_extension_out
return = t_return
infrastructure = t_infrastructure.

Export And Import Data From Memory.

REPORT ztest.


start-of-selection.

perform export_data .

perform import_data.

*&---------------------------------------------------------------------*
*& Form export_data
*----------------------------------------------------------------------*
form export_data .

data: l_char type char10,
l_num type i.

l_num = 110.
l_char = 'test'.

export l_char l_num to memory id 'TEST'.

endform. " export_data
*&---------------------------------------------------------------------*
*& Form import_data
*----------------------------------------------------------------------*
form import_data .

data: l_char type char10,
l_num type i.

import l_char l_num from memory id 'TEST'.

write:/ l_char, l_num.

endform. " import_data

ABAP - Displaying Percentage In ALV List / Grid Display

REPORT zalv_test.

TYPE-POOLS:slis .

DATA: it_fieldcat TYPE slis_t_fieldcat_alv ,
wa_fieldcat TYPE slis_fieldcat_alv .

DATA: BEGIN OF itab OCCURS 0,
name(10) TYPE c,
marks TYPE i ,
pers type char5, "<---this should be character
grade TYPE char10,
END OF itab .

itab-name = 'venkat01'.
itab-marks = 4.
APPEND itab .

itab-name = 'venkat01'.
itab-marks = 15.
APPEND itab .

itab-name = 'venkat02'.
itab-marks = 21.
APPEND itab .

itab-name = 'venkat03'.
itab-marks = 18.
APPEND itab .

itab-name = 'venkat04'.
itab-marks = 9.
APPEND itab .

itab-name = 'venkat04'.
itab-marks = 24.
APPEND itab .

loop at itab .
itab-pers = ( itab-marks / 25 ) * 100 .
if itab-pers lt 35 .

itab-grade = 'bad'.

elseif itab-pers ge 35 and itab-pers lt 60 .
itab-grade = 'average '.
elseif itab-pers ge 60 and itab-pers lt 80 .
itab-grade = 'good'.

elseif itab-pers ge 80 and itab-pers lt 90 .
itab-grade = 'very good'.
elseif itab-pers ge 90 and itab-pers lt 100 .
itab-grade = 'best'.
endif.

concatenate itab-pers '%' into itab-pers.
modify itab.
endloop.

wa_fieldcat-fieldname = 'NAME'.
wa_fieldcat-seltext_m = 'name'.
append wa_fieldcat to it_fieldcat .

clear wa_fieldcat .
wa_fieldcat-fieldname = 'MARKS'.
wa_fieldcat-seltext_m = 'marks'.
append wa_fieldcat to it_fieldcat .

clear wa_fieldcat .
wa_fieldcat-fieldname = 'PERS'.
wa_fieldcat-seltext_m = 'percentage'.
append wa_fieldcat to it_fieldcat .

clear wa_fieldcat .
wa_fieldcat-fieldname = 'GRADE'.
wa_fieldcat-seltext_m = 'grade'.
append wa_fieldcat to it_fieldcat .

clear wa_fieldcat .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING
i_callback_program = sy-repid
* IS_LAYOUT = IS_LAYOUT
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab .


ALSO READ:



Split Command In Files ABAP Report

report zsplit_command_in_files .


parameters: p_file type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
fielp_file(20) type c,
field2(20) type c,
field3(20) type c,
end of itab.
data: wa type string.

CONSTANTS: con_tab TYPE x VALUE '09'.

* if you have a newer version, then you can use this instead.
* constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.[/b]


start-of-selection.

open dataset p_file for input in text mode encoding default.
if sy-subrc = 0.
do.
read dataset p_file into wa.
if sy-subrc ne 0.
exit.
endif.

* Here you are splitting at the hex value of "tab" not at
* the # sign.

split wa at con_tab into itab-fielp_file itab-field2 itab-field3.
append itab.
enddo.
endif.
close dataset p_file.

ABAP - Saving Files To Presentation Server Using Methods.

REPORT zsave_file_pres_oops .

data: your_file_name type string,
your_file_path type string,
the_full_path type string.

types:

begin of the_alv_structure,
field1(10) type c,
field2(10) type c,
end of the_alv_structure.

data: the_alv_itab type table of the_alv_structure.
data: wa like line of the_alv_itab.

wa-field1 = 'A1'.
wa-field2 = 'B1'.
append wa to the_alv_itab.

wa-field1 = 'A2'.
wa-field2 = 'B2'.
append wa to the_alv_itab.

wa-field1 = 'A3'.
wa-field2 = 'B3'.
append wa to the_alv_itab.

call method cl_gui_frontend_services=>file_save_dialog
exporting
default_extension = '.xls'
default_file_name = 'Text'
changing
filename = your_file_name
path = your_file_path
fullpath = the_full_path.

call method cl_gui_frontend_services=>gui_download
exporting
filename = the_full_path
write_field_separator = 'X'
changing
data_tab = the_alv_itab.



RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.


Check Request Transported Or Not To Other SAP / R3 Servers

REPORT ztransport .


data: xtpalog type tpalog.


parameters: trkorr type tpalog-trkorr.

select single * from tpalog into xtpalog
where trkorr = trkorr
and trstep = '<' .

if sy-subrc = 0.
write:/ 'This has been transported'.
else.
write:/ 'This has not been transported'.
endif.

Moving And Zooming Report Output Program

report zmultiple_container .

data: docking type ref to cl_gui_docking_container,
viewer type ref to cl_gui_ecl_2dviewer ,
repid like sy-repid ,
file_name like sapb-sapfiles,
file_type like bdn_con-mimetype.

parameters: p_check type c.

at selection-screen output.
perform build_viewer.

start-of-selection.

*&---------------------------------------------------------------------
**& Form build_viewer
*----------------------------------------------------------------------
form build_viewer.

repid = sy-repid.

create object docking
exporting
repid = repid
dynnr = sy-dynnr
side = cl_gui_docking_container=>dock_at_right
extension = '600'
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.


create object viewer
exporting
parent = docking
autoalign = ' '
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
others = 5.

check sy-subrc = 0.

call method viewer->create_toolbar
exporting
close_button = ' '
tools = 'X'
viewer = 'X'
navigation = 'X'
options = ' '
viewer_openfile = ' '
viewer_savefile = ' '
tool_measurement = ' '
remove_document = ' '
exceptions
cntl_system_error = 1
cntl_error = 2
cntb_btype_error = 3
dp_error = 4.

check sy-subrc = 0.

*Populate the file path
file_name = 'C:\Documents and Settings\venkatapp\Desktop\rich\zoom in alv report.txt'.

call method viewer->open_document
exporting
file = file_name
file_type = file_type
exceptions
cntl_error = 1
cntl_system_error = 2
invalid_file_format = 3
permission_denied = 4
file_not_found = 5
bad_file_name = 6
invalid_data = 7
others = 8.

endform.

Use Of Move Corresponding In The Field Symbols

report zmovecorresponding_fs.

types: begin of type_item,
f1(3),
f2(3),
f3(3),
f4(3),
end of type_item.

types: begin of type_data,
data(800),
end of type_data.

data: lineitems type table of type_item with header line,
t_output type table of type_data with header line,
fieldlist type table of rstrucinfo with header line,
fieldsym type table of rfieldlist with header line.

data: syrepid type sy-repid.

data: fieldname like fieldlist-compname,
data_line type type_data.

field-symbols : type any,
type any.

lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.

lineitems-f1 = 'b1'.
lineitems-f2 = 'b2'.
lineitems-f3 = 'b3'.
lineitems-f4 = 'b4'.
append lineitems.

lineitems-f1 = 'c1'.
lineitems-f2 = 'c2'.
lineitems-f3 = 'c3'.
lineitems-f4 = 'c4'.
append lineitems.

lineitems-f1 = 'd1'.
lineitems-f2 = 'd2'.
lineitems-f3 = 'd3'.
lineitems-f4 = 'd4'.
append lineitems.

syrepid = sy-repid.

* Gets all of the global data types.
call function 'GET_GLOBAL_SYMBOLS'
exporting
program = syrepid
tables
fieldlist = fieldsym.

* gets all of the components of a structure
call function 'GET_COMPONENT_LIST'
exporting
program = syrepid
fieldname = 'lineitems'
tables
components = fieldlist.


loop at lineitems assigning .

loop at fieldlist.
fieldname = fieldlist-compname .
assign component fieldname of structure to .
concatenate data_line into data_line .
endloop.
append data_line to t_output.
clear data_line.
endloop.

loop at t_output.
write:/ t_output.
endloop.

Program On Field Symbols Using OOPS Concept.

report zfieldsymbols_oops .

*---------------------------------------------------------------------*
* CLASS c1 DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class c1 definition.

public section.

data: it_tab type table of i.
data: wa_tab type i.

methods: constructor .

endclass.
*---------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class c1 implementation.

method constructor.

wa_tab = 1.
append wa_tab to it_tab.

wa_tab = 2.
append wa_tab to it_tab.

wa_tab = 3.
append wa_tab to it_tab.


endmethod.


endclass.

data: object type ref to c1.
data: wa2 type i.

field-symbols: type table.

start-of-selection.

create object object.

assign object->it_tab to .

loop at into wa2.
write:/ wa2.
endloop.

ABAp - Dynamic Internal Table Single Field.

report zdynamic_table_all_fields.

type-pools: slis.

field-symbols: type standard table,
,
.

data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.

type-pools : abap.

data : it_details type abap_compdescr_tab,
wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.


* Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].

loop at it_details into wa_details.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = wa_details-name .
wa_it_fldcat-datatype = wa_details-type_kind.
wa_it_fldcat-intlen = wa_details-length.
wa_it_fldcat-decimals = wa_details-decimals.
append wa_it_fldcat to it_fldcat .
endloop.

* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.

assign new_table->* to .

* Create dynamic work area and assign to FS
create data new_line like line of .
assign new_line->* to .

* Select Data from table.
select * into table
from (p_table).

* Write out data from table.
loop at into .
do.
assign component sy-index of structure to .
if sy-subrc ne 0.
exit.
endif.
if sy-index = 1.
write:/ .
else.
write: .
endif.
enddo.
endloop.



ALSO READ:



Use Of Field Symbols In Methods(Program type).

report zfieldsymbols_methods_tables .

field-symbols: type table.

*---------------------------------------------------------------------*
* CLASS lclapp DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lclapp definition.

public section.

data: itabb type table of i.
data: xtabb type i.


methods: constructor,
get_table importing im_table type string
exporting ex_table type any table.

endclass.


*---------------------------------------------------------------------*
* CLASS lclapp IMPLEMENTATION
*---------------------------------------------------------------------*
class lclapp implementation.

method constructor.

xtabb = 10. append xtabb to itabb.
xtabb = 20. append xtabb to itabb.
xtabb = 30. append xtabb to itabb.

endmethod.

method get_table.

data: internaltable(30) type c.
concatenate im_table '[]' into internaltable.
assign (internaltable) to .
ex_table = .

endmethod.

endclass.

data: myapp type ref to lclapp.
data: imytab type table of i.
data: xmytab type i.

start-of-selection.

create object myapp.


call method myapp->get_table
exporting
im_table = 'ITABB'
importing
ex_table = imytab.


loop at imytab into xmytab.
write:/ xmytab.
endloop.

Writing String At Different Positions In ABAP Report Program.

report ztest line-size 200 .

data: c1(60) type c value 'Hello World',
c2(60) type c value 'Hello again, World'.
data: length type i.
data: left type i.
data: length_of_field type i.


data: str type string.


describe field c1 length length_of_field IN CHARACTER MODE.

length = strlen( c1 ).

left = length_of_field - length.

translate c1+length(left) using ' %'.

concatenate c1 c2 into str separated by space.

translate str using '% '.

write:/ str.

Transfer Report Program Output To Internal Table

report zcal_another_rep .


data: begin of listout occurs 0,
line(1024) type c,
end of listout.

* Submit the report and export list to memory
submit YTESTSTSSTS exporting list to memory
and return.

* Get list from memory and convert to ascii
perform retrieve_list_from_memory tables listout.

loop at listout.
write:/ listout.
endloop.

************************************************************************
* RETRIEVE_LIST_FROM_MEMORY
************************************************************************
form retrieve_list_from_memory tables reportlines.

data: list like abaplist occurs 0 with header line.
data: txtlines(1024) type c occurs 0 with header line.

clear : list , reportlines .
refresh : list , reportlines.

call function 'LIST_FROM_MEMORY'
tables
listobject = list
exceptions
not_found = 1
others = 2.

check sy-subrc = 0.

call function 'LIST_TO_ASCI'
tables
listobject = list
listasci = txtlines
exceptions
empty_list = 1
list_index_invalid = 2
others = 3.

check sy-subrc = 0.

reportlines[] = txtlines[].

call function 'LIST_FREE_MEMORY'.

endform.

Change Uppercase To Lowercase

REPORT zchange_case .


PARAMETERS: P_STR TYPE CHAR100 .

DATA: STRING TYPE CHAR100 .

INITIALIZATION .

P_STR = 'THIS IS THE TEST' .

START-OF-SELECTION .

CALL FUNCTION 'STRING_UPPER_LOWER_CASE'
EXPORTING
delimiter = ' '
string1 = P_STR
IMPORTING
STRING = STRING
EXCEPTIONS
NOT_VALID = 1
TOO_LONG = 2
TOO_SMALL = 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.


WRITE:/ STRING .

Print All The Dates Between Two Dates

report zdates.


parameters: p_bdate type sy-datum ,
p_edate type sy-datum .


data: begin of it_date occurs 0,
date type sy-datum ,
end of it_date .

it_date-date = p_bdate.
append it_date.

do.

if it_date-date = p_edate.
exit.
endif.

it_date-date = it_date-date + 1.
append it_date.

enddo.


loop at it_date.

write:/ it_date-date.
endloop.


OUTPUT :

suppose if i input the start date as 12/04/2008
and enddate as 12/18/2008 then the output will be

12/04/2008
12/05/2008
12/06/2008
12/07/2008
12/08/2008
12/09/2008
12/10/2008
12/11/2008
12/12/2008
12/13/2008
12/14/2008
12/15/2008
12/16/2008
12/17/2008
12/18/2008

Insert Data Into Hashed Table

REPORT zhashed_table .

types: begin of t_foo,
field1 type char2,
field2 type char2,
field3 type char2,
field4 type i,
end of t_foo.

data: lt_foo type HASHED TABLE OF t_foo
WITH UNIQUE KEY field1 field2 field3.

data: ls_foo like line of lt_foo.

FIELD-SYMBOLS: like LINE OF lt_foo.

* Must assign it to use it.
assign ls_foo to .

clear .
-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.
insert into table lt_foo.

clear .
-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.
insert into table lt_foo.
If sy-subrc ne 0.
write:/ ' this is the duplidate key'.
endif.

Display ICON On Selection Screen

report zicon .

type-pools: icon.

selection-screen begin of block b1 with frame title text-001.
parameters: p_check.
selection-screen comment 40(20) icon1.
selection-screen end of block b1.

at selection-screen output.

* Write pushbutton text
write icon_configuration as icon to icon1.
concatenate icon1 'Your Icon' into icon1
separated by space.

-------------------------------------------------------------

report zicon .

type-pools: icon.

selection-screen begin of block b1 with frame title text-001.
selection-screen begin of line.
selection-screen comment 1(17) fld_lab.
selection-screen comment 18(5) icon1.
parameters: p_check.
selection-screen end of line.
selection-screen end of block b1.

at selection-screen output.

write icon_configuration as icon to icon1.
fld_lab = 'This is the label'.

start-of-selection.

-------------------------------------------------------------------------

ABAP - Dynamic Internal Tables Using OOPS Concept

REPORT z_test .

TYPE-POOLS: slis.

DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: TYPE ANY TABLE,
TYPE ANY,
TYPE ANY.


PARAMETERS: p_table TYPE dd02l-tabname.

* Build fieldcat
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_table
CHANGING
ct_fieldcat = it_fieldcat[].


* Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.

ASSIGN new_table->* TO .

* Create Work Area
CREATE DATA new_line LIKE LINE OF .
ASSIGN new_line->* TO .



ALSO READ:



ABAP - Dynamic Internal Table All Fields

REPORT Z_DYNAMIC.

type-pools : abap.

field-symbols: type standard table,
,
.

data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

perform get_structure.
perform create_dynamic_itab.
perform get_data.
perform write_out.


form get_structure.

data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].

loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.

endform.

form create_dynamic_itab.

* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.

assign dy_table->* to .

* Create dynamic work area and assign to FS
create data dy_line like line of .
assign dy_line->* to .

endform.


form get_data.

* Select Data from table.
select * into table
from (p_table).

endform.

form write_out.
* Write out data from table.

loop at into .
do.
assign component sy-index
of structure to .
if sy-subrc ne 0.
exit.
endif.
if sy-index = 1.
write:/ .
else.
write: .
endif.
enddo.
endloop.
endform.



ALSO READ:



Get The First And Last Date For The Year - ABAP Report Program

report zdate .


parameters: p_period type t009b-poper,
p_year type t009b-bdatj.

data: from_date type sy-datum,
to_date type sy-datum.

call function 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
exporting
i_gjahr = p_year
i_periv = 'YT'
importing
e_first_day = from_date
e_last_day = to_date
exceptions
input_false = 1
t009_notfound = 2
t009b_notfound = 3
others = 4.

write:/ from_date, to_date.