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

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:



Save And Edit In Classical ABAP Report - To Avoid Complexity

*----------------------------------------------------------*
* created by : venkat appikonda
* created date: 28.12.2008
* description : The sample code for editing the clssical report
* and saving after modification successfully. this is an
* example program,so that i didnt use more validations,
* this is to aviod complexicity of the coding .
*----------------------------------------------------------*
REPORT ZEDIT_CLASSICAL_REPORT.

TYPES: BEGIN OF TY_ITAB ,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
END OF TY_ITAB .

DATA: ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE,
WA TYPE TY_ITAB.

DATA: V_MEINS LIKE MARA-MEINS,
V_MEINS1 LIKE MARA-MEINS,
V_MATNR LIKE MARA-MATNR.

START-OF-SELECTION.

SET PF-STATUS 'TEST'.

PERFORM GET_DATA.

PERFORM HEADER_DATA.

PERFORM DISPLAY_DATA.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SAVE'.
PERFORM SAVE_FUNCTION.

ENDCASE.
*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM GET_DATA .

SELECT MATNR
MEINS
FROM MARA
INTO TABLE ITAB
UP TO 5 ROWS.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form header_data
*----------------------------------------------------------------------*
FORM HEADER_DATA .

WRITE:/1(30) SY-ULINE.
WRITE:/1 SY-VLINE,
2 'Material',
20 SY-VLINE,
21 'Mat Unit',
30 SY-VLINE.
WRITE:/1(30) SY-ULINE.

ENDFORM. " header_data
*&---------------------------------------------------------------------*
*& Form display_data
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .


LOOP AT ITAB INTO WA.
WRITE:/1 SY-VLINE,
2 WA-MATNR,
20 SY-VLINE.
FORMAT INTENSIFIED INPUT.
WRITE: 21 WA-MEINS.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE: 30 SY-VLINE.
ENDLOOP.
WRITE:/1(30) SY-ULINE.

ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form save_function
*----------------------------------------------------------------------*
FORM SAVE_FUNCTION .

DO .
CLEAR: V_MATNR,V_MEINS, V_MEINS1.
READ LINE SY-INDEX .
IF SY-SUBRC NE 0.
*---if there exists no line , exit the processing
EXIT.
ELSE.
*---check whether the material exitsting or not .
SELECT MATNR MEINS
FROM MARA
INTO (V_MATNR, V_MEINS)
WHERE MATNR = SY-LISEL+1(18).

ENDSELECT.
IF SY-SUBRC = 0.
*---if material existing then get the actual Unit of measure,
* and capture the value to v_meins capture the changed value
* into v_meins1, process it if it is not initial.
V_MEINS1 = SY-LISEL+20(4).
IF NOT V_MEINS1 IS INITIAL.
*----check whether the data record was changed or not .
* if the two values are same, it means there is no
* change in the data record . here we can also put
* the validation on the v_meins1 to etner a valid
* value if not display an error message.
IF V_MEINS NE V_MEINS1.
*---if changed then update table with the updated value
* dont forget to Lock the table before processing the data
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
IF SY-SUBRC = 0.
* Modify the database table with these changes
UPDATE MARA SET MEINS = V_MEINS1
WHERE MATNR = V_MATNR.
IF SY-SUBRC = 0.
*---if successfully updated then write the modification log
WRITE:/ 'the material',
V_MATNR COLOR 7,
'unit was changed with value:',
V_MEINS1,
'from value:',
V_MEINS.
ENDIF.
* Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDDO.

ENDFORM. " save_function

ABAP - Uploading CSV Files Into Internal Table Using FM GUI_UPLOAD.

REPORT zupload_csv_file.

TYPES: BEGIN OF ttab,
rec(1000) TYPE c,
END OF ttab.

TYPES: BEGIN OF tdat,
fld1(10) TYPE c,
fld2(10) TYPE c,
fld3(10) TYPE c,
END OF tdat.

DATA: itab TYPE TABLE OF ttab WITH HEADER LINE.
DATA: idat TYPE TABLE OF tdat WITH HEADER LINE.

DATA: file_str TYPE string.

PARAMETERS: p_file TYPE localfile.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.

START-OF-SELECTION.

file_str = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.


LOOP AT itab.
CLEAR idat.
SPLIT itab-rec AT ',' INTO idat-fld1
idat-fld2
idat-fld3.
APPEND idat.

ENDLOOP.


LOOP AT idat.
WRITE:/ idat-fld1, idat-fld2, idat-fld3.
ENDLOOP.


ALSO READ:

- Creating A Directory On Presentation Server Using FM GUI_CREATE_DIRECTORY.

- Removing A Directory From Presentation Server Using FM GUI_REMOVE_DIRECTORY.

- Removing A File From Presentation Server Using FM GUI_DELETE_FILE.

- ZIP Files In Application Server Using FM SCMS_XSTRING_TO_BINARY.

- Saving Files To Presentation Server Using Methods.


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.


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.

Unit Conversion In ABAP Reports

REPORT zunit_conversion .

data: lv_input type p DECIMALS 3 value '10000.000',
lv_output type p DECIMALS 3.

CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
input = lv_input
UNIT_IN = 'LB'
UNIT_OUT = 'KG'
IMPORTING
OUTPUT = lv_output
EXCEPTIONS
CONVERSION_NOT_FOUND = 1
DIVISION_BY_ZERO = 2
INPUT_INVALID = 3
OUTPUT_INVALID = 4
OVERFLOW = 5
TYPE_INVALID = 6
UNITS_MISSING = 7
UNIT_IN_NOT_FOUND = 8
UNIT_OUT_NOT_FOUND = 9
OTHERS = 10.

write:/ lv_output.

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.

Show Table Contents Through ABAP Report Program

report zshow_table_contents .

parameters: tname like rsdxx-objname.

call function 'RS_TOOL_ACCESS'
exporting
operation = 'TAB_CONT'
object_name = tname
object_type = 'TABL'
exceptions
not_executed.

ABAP - ZIP Files In Application Server Using FM SCMS_XSTRING_TO_BINARY.

report Z_ZIP_FILES_IN_APPSVR .

DATA: lt_data TYPE TABLE OF x255,
ls_data LIKE LINE OF lt_data.

DATA: lv_zip_content TYPE xstring ,
lv_dsn1(100) VALUE '/sap/NSP/sys/test.as',
lv_dsn2(100) VALUE '/sap/NSP/sys/test2.mxml',
lv_dsn3(100) VALUE '/sap/NSP/sys/testarchive.zip',
lv_file_length TYPE i ,
lv_content TYPE xstring,
lo_zip TYPE REF TO cl_abap_zip.

CREATE OBJECT lo_zip.

* Read the data as a string
clear lv_content .
OPEN DATASET lv_dsn1 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn1 INTO lv_content .
CLOSE DATASET lv_dsn1.

lo_zip->add( name = 'test.as' content = lv_content ).

clear lv_content .

OPEN DATASET lv_dsn2 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn2 INTO lv_content .
CLOSE DATASET lv_dsn2.

lo_zip->add( name = 'test2.mxml' content = lv_content ).

lv_zip_content = lo_zip->save( ).

* Conver the xstring content to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_zip_content
IMPORTING
output_length = lv_file_length
TABLES
binary_tab = lt_data.


OPEN DATASET lv_dsn3 FOR OUTPUT IN BINARY MODE.
LOOP AT lt_data INTO ls_data.
TRANSFER ls_data TO lv_dsn3.
ENDLOOP.
CLOSE DATASET lv_dsn3.



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.


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:



Get The Status Of The Report Program

report zget_status_report.

parameters:p_prog type TRDIR-NAME .

data: result like RLSEU0_DOK-STATUS,
program like TRDIR-NAME .


CALL FUNCTION 'F4_STATUS_LIST'
EXPORTING
PROGRAM = p_prog
SUPPRESS_SELECTION = 'X'
DISPLAY_ONLY = 'X'
IMPORTING
RESULT = RESULT
PROGRAM = PROGRAM
.

write:/ result , program .

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.

ABAP - ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC

REPORT ZTESTALV.

*&---------------------------------------------------------------------*
* type pools
*----------------------------------------------------------------------*
TYPE-POOLS: SLIS.

*&---------------------------------------------------------------------*
* declarations for alv and internal tables
*----------------------------------------------------------------------*
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
WA_FIELDCAT TYPE LVC_S_FCAT,
WA_LAYOUT TYPE LVC_S_LAYO,
V_POSITION TYPE I ,
LS_CELLCOLOR TYPE LVC_S_SCOL,
L_INDEX TYPE SY-TABIX.

DATA: BEGIN OF IT_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
CELLCOLOR TYPE LVC_T_SCOL,
END OF IT_VBAP.

*&---------------------------------------------------------------------*
* start of selection
*----------------------------------------------------------------------*
start-of-selection .

*---get data from db table
perform get_data .

*---build layout for alv
perform build_layout .

*---build fieldcat for alv
perform build_fieldcat .

*---modify fieldcat for colors in alv
Perform modify_fieldcat .

*---display alv
perform display_alv .

*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM get_data .

SELECT VBELN
POSNR
UP TO 25 ROWS
INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
FROM VBAP.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*----------------------------------------------------------------------*
FORM build_fieldcat .

WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-REPTEXT = 'VBELN'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'POSNR'.
WA_FIELDCAT-REPTEXT = 'POSNR'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*& Form build_layout
*----------------------------------------------------------------------*
FORM build_layout .

WA_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
WA_LAYOUT-ZEBRA = 'X'.

ENDFORM. " build_layout
*&---------------------------------------------------------------------*
*& Form modify_fieldcat
*----------------------------------------------------------------------*
FORM modify_fieldcat .

LOOP AT IT_VBAP.

L_INDEX = SY-TABIX.
if l_index = 5 or l_index = 15.
LS_CELLCOLOR-FNAME = 'VBELN'.
LS_CELLCOLOR-COLOR-COL = '6'.
LS_CELLCOLOR-COLOR-INT = '1'.
APPEND LS_CELLCOLOR TO IT_VBAP-CELLCOLOR.
MODIFY IT_VBAP INDEX L_INDEX TRANSPORTING CELLCOLOR.
endif.

if l_index = 10 or l_index = 20.
LS_CELLCOLOR-FNAME = 'VBELN'.
LS_CELLCOLOR-COLOR-COL = '4'.
LS_CELLCOLOR-COLOR-INT = '1'.
APPEND LS_CELLCOLOR TO IT_VBAP-CELLCOLOR.
MODIFY IT_VBAP INDEX L_INDEX TRANSPORTING CELLCOLOR.
endif.

if it_vbap-VBELN is initial .
delete it_vbap.
endif.

ENDLOOP.


ENDFORM. " modify_fieldcat
*&---------------------------------------------------------------------*
*& Form display_alv
*----------------------------------------------------------------------*
FORM display_alv .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_FIELDCAT
TABLES
T_OUTTAB = IT_VBAP .


ENDFORM. " display_alv


ALSO READ:


- ALV Report With User Defined Buttons In It's Toolbar.

- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.

- Displaying Percentage In ALV List / Grid Display.

- Handling An ALV Grid With Check Box Using A Method.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


Dynamic Internal Table With A Single Field

DATA:
o_ref TYPE REF TO data.
FIELD-SYMBOLS:
TYPE STANDARD TABLE,
TYPE ANY,
TYPE ANY,
TYPE ANY.
PARAMETERS:
p_tab TYPE tabname default 'MARA', " Table name (eg: MARA)
p_field(20) TYPE c default 'MATNR'. " Field name (eg: MATNR)

START-OF-SELECTION.
CREATE DATA o_ref TYPE TABLE OF (p_tab).

ASSIGN p_field TO .
ASSIGN o_ref->* TO .

SELECT *
INTO TABLE
FROM (p_tab).

LOOP AT ASSIGNING .
ASSIGN COMPONENT OF STRUCTURE
TO .
IF sy-subrc = 0.
WRITE:/ .
ENDIF.
ENDLOOP.

ABAP - Check Box As A Radio Button In Selection Screen.

REPORT zCHECK_RAD.


PARAMETERS: p_check1 AS CHECKBOX USER-COMMAND check,
p_check2 AS CHECKBOX USER-COMMAND check,
p_check3 AS CHECKBOX USER-COMMAND check ,
p_check4 AS CHECKBOX USER-COMMAND check .

DATA: VALUE TYPE CHAR10.

AT SELECTION-SCREEN.

GET CURSOR FIELD VALUE.

IF VALUE = 'P_CHECK1'.
p_check2 = space.
p_check3 = space.
p_check4 = space.
ELSEIF VALUE = 'P_CHECK2'.
p_check1 = space.
p_check3 = space.
p_check4 = space.
ELSEIF VALUE = 'P_CHECK3'.
p_check1 = space.
p_check2 = space.
p_check4 = space.
ELSEIF VALUE = 'P_CHECK4'.
p_check2 = space.
p_check3 = space.
p_check1 = space.

ENDIF.


ALSO READ:

- F4 (Value On Request) For Files On Presentation Or Application Server.

- Sample Program On Use Of Selection Screen.

- Creating Tab-Strip Selection Screen tab-strip Without Using SE51.

- Change The Height Of The Screen Layout To Make It Full Screen.

- F4 (Value On Request) For Field Using FM RSISP_DDIC_F4_VALUES.

- F4 (Value On Request) For Organization Unit In HR Report Program.

- F4 (Value On Request) For Organization Unit In HR Report Program.

ABAP - Get Changed Data From Tables CDHDR & CDPOS

REPORT z_alv_cdhdr_cdpos.
*---------------------------------------------------------------------
*This ALV report displays tables CDHDR and CDPOS *
*---------------------------------------------------------------------

TYPE-POOLS slis. " Global ALV types

*---------------------------------------------------------------------
* constants
*---------------------------------------------------------------------

CONSTANTS : c_x VALUE 'X',
c_eb9 TYPE syucomm VALUE '&EB9',
c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------
* types
*---------------------------------------------------------------------

TYPES :BEGIN OF ty_s_cdhdr.
INCLUDE TYPE cdhdr.
TYPES :checkbox TYPE xfeld,
END OF ty_s_cdhdr,

BEGIN OF ty_s_cdpos.
INCLUDE TYPE cdpos.
TYPES : checkbox TYPE xfeld,
END OF ty_s_cdpos.

*---------------------------------------------------------------------
* internal tables
*---------------------------------------------------------------------
DATA : gs_cdhdr TYPE cdhdr, " Change document header

* Layout for ALV
gs_layout TYPE slis_layout_alv,

* Change document header
t_cdhdr TYPE TABLE OF ty_s_cdhdr.

*---------------------------------------------------------------------
* selection screen design
*---------------------------------------------------------------------
SELECT-OPTIONS : s_objcls FOR gs_cdhdr-objectclas OBLIGATORY,
s_objtid FOR gs_cdhdr-objectid,
s_chngnr FOR gs_cdhdr-changenr,
s_usrnam FOR gs_cdhdr-username DEFAULT sy-uname,
s_udate FOR gs_cdhdr-udate DEFAULT sy-datum,
s_time FOR gs_cdhdr-utime,
s_tcode FOR gs_cdhdr-tcode,
s_plncnr FOR gs_cdhdr-planchngnr,
s_chngno FOR gs_cdhdr-act_chngno,
s_wsplnd FOR gs_cdhdr-was_plannd,
s_chngid FOR gs_cdhdr-change_ind.

SELECTION-SCREEN SKIP.

PARAMETERS p_max TYPE numc3 OBLIGATORY DEFAULT '200'.

*---------------------------------------------------------------------
* start-of-selection .
*---------------------------------------------------------------------
START-OF-SELECTION.

PERFORM f_read_data.

*---------------------------------------------------------------------
* end-of-selection .
*---------------------------------------------------------------------

END-OF-SELECTION.

PERFORM f_display_cdhdr.

*---------------------------------------------------------------------

*Form f_read_data
*---------------------------------------------------------------------
FORM f_read_data.

*Read Change document header
SELECT * INTO TABLE t_cdhdr
UP TO p_max ROWS
FROM cdhdr
WHERE objectclas IN s_objcls
AND objectid IN s_objtid
AND changenr IN s_chngnr
AND username IN s_usrnam
AND udate IN s_udate
AND utime IN s_time
AND tcode IN s_tcode
AND planchngnr IN s_plncnr
AND act_chngno IN s_chngno
AND was_plannd IN s_wsplnd
AND change_ind IN s_chngid.

ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------
*
*Form f_display_cdhdr
*---------------------------------------------------------------------
FORM f_display_cdhdr.

DATA :ls_event_exit TYPE slis_event_exit,
lt_event_exit TYPE slis_t_event_exit.

gs_layout-zebra = c_x.
gs_layout-colwidth_optimize = c_x.
gs_layout-group_change_edit = c_x.
gs_layout-allow_switch_to_list = c_x.
gs_layout-box_fieldname = 'CHECKBOX'.

*Activate 'More' button
CLEAR ls_event_exit.
ls_event_exit-after = c_x.
ls_event_exit-ucomm = c_eb9. " More
APPEND ls_event_exit TO lt_event_exit.

*Activate refresh button
CLEAR ls_event_exit.
ls_event_exit-after = c_x.
ls_event_exit-ucomm = c_refresh. " Refresh
APPEND ls_event_exit TO lt_event_exit.

*Display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF_STATUS_SET'
i_structure_name = 'CDHDR'
is_layout = gs_layout
it_event_exit = lt_event_exit
i_save = 'A'
TABLES
t_outtab = t_cdhdr.

ENDFORM. " F_DISPLAY_CDHDR
*---------------------------------------------------------------------
*
*FORM USER_COMMAND *
*---------------------------------------------------------------------
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED

*Macro definition
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = c_x.
append ls_sort to lt_sort.
END-OF-DEFINITION.

DATA :
ls_cdhdr TYPE ty_s_cdhdr,
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv,

*Change document items
lt_cdpos TYPE TABLE OF ty_s_cdpos.

CASE u_ucomm.
WHEN '&IC1' OR c_eb9.
PERFORM check_marked USING us_selfield.


*Read Change document items
LOOP AT t_cdhdr INTO ls_cdhdr WHERE checkbox = c_x.
SELECT * APPENDING TABLE lt_cdpos
FROM cdpos
WHERE objectclas = ls_cdhdr-objectclas
AND objectid = ls_cdhdr-objectid
AND changenr = ls_cdhdr-changenr.
ENDLOOP.

m_sort 'CHANGENR'.

*Display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_structure_name = 'CDPOS'
is_layout = gs_layout
it_sort = lt_sort
i_save = 'A'
TABLES
t_outtab = lt_cdpos.

WHEN c_refresh.
PERFORM f_read_data.
us_selfield-refresh = c_x.
ENDCASE.

ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------

*Form CHECK_MARKED
*---------------------------------------------------------------------
*
*What has been marked in t_cdhdr
*---------------------------------------------------------------------
FORM check_marked USING us_selfield TYPE slis_selfield.

FIELD-SYMBOLS :
TYPE ty_s_cdhdr.

READ TABLE t_cdhdr TRANSPORTING NO FIELDS
WITH KEY checkbox = c_x.
IF NOT sy-subrc IS INITIAL AND
NOT us_selfield-tabindex IS INITIAL.

READ TABLE t_cdhdr INDEX us_selfield-tabindex ASSIGNING .

-checkbox = c_x.
ENDIF.

ENDFORM. " CHECK_MARKED
*---------------------------------------------------------------------
*
*FORM PF_STATUS_SET *
*---------------------------------------------------------------------
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED


*Display 'Refresh' button and 'More' button
DELETE ut_extab WHERE fcode = c_refresh
OR fcode = c_eb9.

SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.

ENDFORM. " PF_STATUS_SET

*---------------------------------------------------------------------*
* how to use the function module
*---------------------------------------------------------------------*

*--- how to use the function module CHANGEDOCUMENT_READ_HEADERS

REPORT zchange_headers .

DATA: BEGIN OF it_cdhdr OCCURS 0.
INCLUDE STRUCTURE cdhdr.
DATA: END OF it_cdhdr.

PARAMETERS: begdate LIKE cdhdr-udate ,
enddate LIKE cdhdr-udate ,
begtime LIKE cdhdr-utime ,
endtime LIKE cdhdr-utime .


INITIALIZATION .
begdate = sy-datum .
enddate = sy-datum .
begtime = '000001' .
endtime = '235959'.


CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
date_of_change = begdate
objectclass = 'EINKBELEG' "Object Class T-Code: SCDO
time_of_change = begtime
username = sy-uname
date_until = enddate
time_until = endtime
TABLES
i_cdhdr = it_cdhdr
EXCEPTIONS
no_position_found = 1
wrong_access_to_archive = 2
time_zone_conversion_error = 3
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


IF sy-subrc = 0.

LOOP AT it_cdhdr.
WRITE:/ it_cdhdr-objectclas,
it_cdhdr-objectid,
it_cdhdr-changenr,
it_cdhdr-username,
it_cdhdr-udate,
it_cdhdr-utime,
it_cdhdr-tcode.
ENDLOOP.

ENDIF.



ALSO READ:


- ALV Report With User Defined Buttons In It's Toolbar.

- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.

- Displaying Percentage In ALV List / Grid Display.

- Handling An ALV Grid With Check Box Using A Method.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


ABAP - Mathematical Function Ceil() & Floor() - Report Programming

REPORT zceil_floor .


parameters: p_int type i ,
p_int1 type i .

data: value type p decimals 2 ,
value1 type p decimals 2 ,
value2 type p decimals 2 .


start-of-selection.

value = p_int / p_int1 .

value1 = ceil( value ) .
value2 = floor( value ) .


write:/ 'the actual value is : ' , value .

write:/ 'value using the ceil function : ' , value1 .

write:/ 'value using the floor function : ' , value2 .

ABAP - Catch Last Records From The Table & Display Them.

report zcatch_last_records.


data: begin of itab occurs 0,
lifnr type lfa1-lifnr,
pydat type sy-datum,
end of itab.

data: begin of itab2 occurs 0,
lifnr type lfa1-lifnr,
pydat type sy-datum,
end of itab2.

data: wa like line of itab.

itab-lifnr = '1'.
itab-pydat = '20050709'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050708'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050707'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050712'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050711'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050710'.
append itab.


sort itab by lifnr ascending
pydat descending.

loop at itab.
wa = itab.
at new lifnr.
move-corresponding wa to itab2.
append itab2.
endat.
endloop.


loop at itab2.
write:/ itab2-lifnr, itab2-pydat.
endloop.

Catch And Endcatch In System Exceptions

REPORT zcatch_endcatch.

DATA: BEGIN OF ifile OCCURS 0,
rec(150),
END OF ifile.

PARAMETERS: path(99) TYPE c LOWER CASE
DEFAULT '/usr/sap/TST/SYS/TEST001.txt'.

OPEN DATASET path FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CATCH SYSTEM-EXCEPTIONS dataset_cant_open = 1.
DO.
READ DATASET path INTO ifile-rec.
IF sy-subrc EQ 0.
APPEND ifile.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDCATCH.

IF sy-subrc = 1.
WRITE:/ 'File could not be opened'.
ENDIF.

ABAP - ICON's In ALV Custom Container

REPORT zicon .

*----------------------------------------------------------------*
* type-pools
*----------------------------------------------------------------*

TYPE-POOLS: icon.

*----------------------------------------------------------------*
* internal tables and container declarations
*----------------------------------------------------------------*

DATA: grid TYPE REF TO cl_gui_alv_grid,
CUST_CONT TYPE REF TO cl_gui_custom_container.

TYPES: BEGIN OF ty_vbap ,
vbeln LIKE vbap-vbeln,
matnr LIKE vbap-matnr,
posnr LIKE vbap-posnr,
kunnr LIKE vbak-kunnr,
kwmeng LIKE vbap-kwmeng,
id TYPE icon-id,
END OF ty_vbap.

DATA: it_vbap TYPE TABLE OF ty_vbap,
wa_vbap TYPE ty_vbap,
it_fieldcat TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.

*----------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------*

START-OF-SELECTION.

perform get_data .

perform insert_icon .

perform build_fieldcat .

*--calling a screen to display the data
CALL SCREEN 111.
*&---------------------------------------------------------------------*
*& Module STATUS_0111 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0111 OUTPUT.
SET PF-STATUS 'TEST'.
SET TITLEBAR 'TEST'.

ENDMODULE. " STATUS_0111 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0111 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0111 INPUT.

CASE: SY-UCOMM .
WHEN 'BACK'.
LEAVE TO SCREEN 0 .
ENDCASE .
ENDMODULE. " USER_COMMAND_0111 INPUT
*&---------------------------------------------------------------------*
*& Module FILL_DATA OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE FILL_DATA OUTPUT.

*---create a custom container

CREATE OBJECT CUST_CONT
EXPORTING
CONTAINER_NAME = 'CUST_CONT' .

CREATE OBJECT GRID
EXPORTING
I_PARENT = CUST_CONT .

*----display the data through custom container

CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = it_vbap
IT_FIELDCATALOG = it_fieldcat .


ENDMODULE. " FILL_DATA OUTPUT
*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM get_data .

SELECT vbak~vbeln
vbak~kunnr
vbap~posnr
vbap~matnr
vbap~kwmeng
INTO CORRESPONDING FIELDS OF TABLE it_vbap
FROM vbak JOIN vbap
ON vbak~vbeln = vbap~vbeln
UP TO 20 ROWS.

SORT it_vbap BY matnr.

DELETE it_vbap WHERE matnr IS INITIAL.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form insert_icon
*----------------------------------------------------------------------*
FORM insert_icon .

LOOP AT it_vbap INTO wa_vbap.
wa_vbap-id = '@08@'. " icon green light
MODIFY it_vbap FROM wa_vbap.
ENDLOOP.

ENDFORM. " insert_icon
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*----------------------------------------------------------------------*
FORM build_fieldcat .

wa_fieldcat-fieldname = 'ID'.
wa_fieldcat-coltext = 'Icon'.
wa_fieldcat-icon = 'X'. "This is important
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-coltext = 'MATNR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'KUNNR'.
wa_fieldcat-coltext = 'KUNNR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'VBELN'.
wa_fieldcat-coltext = 'VBELN'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'POSNR'.
wa_fieldcat-coltext = 'POSNR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'KWMENG'.
wa_fieldcat-coltext = 'KWMENG'.
wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

ENDFORM. " build_fieldcat


ALSO READ:


- ALV Report With User Defined Buttons In It's Toolbar.

- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.

- Displaying Percentage In ALV List / Grid Display.

- Handling An ALV Grid With Check Box Using A Method.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


ABAP - 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.

ABAP - Calling A Transaction From Classical Report..

report zcall_tcode_in_repots
no standard page heading.

data: itab type table of d010tinf with header line.


start-of-selection.

select * into corresponding fields of table itab
from d010tinf
where prog like 'Z%'.

loop at itab.
write:/ itab-prog.
endloop.


at line-selection.

data: contents(250) type c.
contents = sy-lisel.
set parameter id 'RID' field contents.
call transaction 'SE38'.

ABAP - ALV Listbox On Selection Screen Using Docking Container.

REPORT ZALV_LISTBOX .

*---------------------------------------------------------------------*
* DATA DECLARATIONS
*---------------------------------------------------------------------*
DATA: CONT_DOCKING TYPE REF TO CL_GUI_DOCKING_CONTAINER,
GRID TYPE REF TO CL_GUI_ALV_GRID,
CUST_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
IT_FIELDCAT TYPE LVC_T_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO,
ITAB TYPE TABLE OF SBOOK.

*&---------------------------------------------------------------------*
*& SELECTION SCREEN PARAMETERS
*&---------------------------------------------------------------------*

PARAMETERS:P_TEST TYPE I .
*&---------------------------------------------------------------------*
*& AT SELECTION SCREEN OUTPUT
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.

CREATE OBJECT CONT_DOCKING
EXPORTING
REPID = SY-REPID
DYNNR = SY-DYNNR
SIDE = CONT_DOCKING->DOCK_AT_LEFT
EXTENSION = 1700.


IF CUST_CONTAINER IS INITIAL.
*----Create the alv with docking container
PERFORM CREATE_AND_INIT_ALV .
ENDIF.

*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
FORM BUILD_FIELDCAT .

DATA WA_FIELDCAT TYPE LVC_S_FCAT.

WA_FIELDCAT-FIELDNAME = 'CARRID'.
WA_FIELDCAT-REPTEXT = 'Airline Code'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'CONNID'.
WA_FIELDCAT-REPTEXT = 'Flight Connection Number'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'WUNIT'.
WA_FIELDCAT-REPTEXT = 'Weight Unit'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.


LOOP AT IT_FIELDCAT INTO WA_FIELDCAT.
IF WA_FIELDCAT-FIELDNAME EQ 'WUNIT'.
WA_FIELDCAT-EDIT = 'X'.
WA_FIELDCAT-DRDN_HNDL = '1'.
WA_FIELDCAT-CHECKTABLE = '!'.
MODIFY IT_FIELDCAT FROM WA_FIELDCAT.
ENDIF.
ENDLOOP.

ENDFORM. "build_fieldcat
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
FORM CREATE_AND_INIT_ALV .

CREATE OBJECT GRID
EXPORTING I_PARENT = CONT_DOCKING.

*--perform build field catalog for alv display
PERFORM BUILD_FIELDCAT .

*--fill the drop down list values
PERFORM fill_dropdown_table .

*----fill final output table
SELECT * FROM SBOOK
INTO TABLE ITAB
UP TO 10 ROWS.
*---display alv
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB.

*---Set editable cells to ready for input initially
CALL METHOD GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.

ENDFORM. "create_and_init_alv

*&---------------------------------------------------------------------*
*& Form set_drdn_table
*&---------------------------------------------------------------------*
FORM fill_dropdown_table.

DATA: LT_DROPDOWN TYPE LVC_T_DROP,
LS_DROPDOWN TYPE LVC_S_DROP.

LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = 'KG'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.

LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = 'G'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.

LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = 'B'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.

LS_DROPDOWN-HANDLE = '1'.
LS_DROPDOWN-VALUE = 'T'.
APPEND LS_DROPDOWN TO LT_DROPDOWN.


CALL METHOD GRID->SET_DROP_DOWN_TABLE
EXPORTING
IT_DROP_DOWN = LT_DROPDOWN.

ENDFORM. "set_drdn_table




ABAP - Read A File From Directory Using cl_gui_frontend_services Method

REPORT zread_a_file.

DATA: v_rc TYPE i.
DATA: lt_filetab TYPE filetable.
DATA: ls_filetab LIKE LINE OF lt_filetab.

PARAMETERS: p_file TYPE localfile.

AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = lt_filetab
rc = v_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

READ TABLE lt_filetab INTO ls_filetab INDEX 1.
IF sy-subrc = 0.
p_file = ls_filetab-filename.
ENDIF.