ABAP Programs For Learners
REPORT zdemo_alvgrid .
type-pools: slis.
*Data Declaration
data: BEGIN OF itab occurs 0,
F1 TYPE I,
F2 TYPE I,
F3 TYPE I,
END OF itab.
data: it_fieldcatalog type slis_t_fieldcat_alv ,
wa_fieldcatalog type slis_fieldcat_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
itab-f1 = '1'.
itab-f2 = '10'.
itab-f3 = '1234'.
append itab.
itab-f1 = '2'.
itab-f2 = '400'.
itab-f3 = '4321'.
append itab.
itab-f1 = '3'.
itab-f2 = '5120'.
itab-f3 = '0766'.
append itab.
itab-f1 = '4'.
itab-f2 = '620'.
itab-f3 = '3245'.
append itab.
itab-f1 = '5'.
itab-f2 = '9430'.
itab-f3 = '564'.
append itab.
itab-f1 = '6'.
itab-f2 = '1098'.
itab-f3 = '14'.
append itab.
itab-f1 = '7'.
itab-f2 = '140'.
itab-f3 = '4325'.
append itab.
wa_fieldcatalog-fieldname = 'F1'.
wa_fieldcatalog-reptext_ddic = 'field1'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
wa_fieldcatalog-fieldname = 'F2'.
wa_fieldcatalog-reptext_ddic = 'field2'.
wa_fieldcatalog-do_sum = 'X'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
wa_fieldcatalog-fieldname = 'F3'.
wa_fieldcatalog-reptext_ddic = 'field3'.
wa_fieldcatalog-do_sum = 'X'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
* gd_layout-
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = it_fieldcatalog[]
tables
t_outtab = itab .
REPORT zintractive .
TYPES : BEGIN OF str_mard,
matnr TYPE mard-matnr,
lgort TYPE mard-lgort,
werks TYPE mard-werks,
END OF str_mard.
DATA : wa_mard TYPE str_mard,
it_mard TYPE TABLE OF str_mard.
TYPES : BEGIN OF str_makt,
matnr TYPE makt-matnr,
maktg TYPE makt-maktg,
END OF str_makt.
DATA : wa_makt TYPE str_makt,
it_makt TYPE TABLE OF str_makt.
TYPES : BEGIN OF str_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF str_mara.
DATA : wa_mara TYPE str_mara,
it_mara TYPE TABLE OF str_mara.
TYPES : BEGIN OF str_final,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
lgort TYPE mard-lgort,
werks TYPE mard-werks,
END OF str_final.
DATA: wa_final TYPE str_final,
it_final TYPE TABLE OF str_final.
PARAMETERS : plant TYPE mard-werks,
stor LIKE mard-lgort.
SELECT matnr
lgort
werks
FROM mard
INTO TABLE it_mard
WHERE lgort = stor AND werks = plant.
.SELECT matnr
maktg
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_mard
WHERE matnr = it_mard-matnr
AND spras = 'E'.
SELECT matnr
ersda
ernam
laeda
mtart
matkl
meins
FROM mara
INTO TABLE it_mara
FOR ALL ENTRIES IN it_makt
WHERE matnr = it_makt-matnr.
LOOP AT it_makt INTO wa_makt.
WRITE : /1 wa_makt-matnr COLOR 1,
40 wa_makt-maktg COLOR 2.
HIDE wa_makt-matnr.
ENDLOOP.
CLEAR wa_mard-matnr.
AT LINE-SELECTION.
REFRESH it_final.
CLEAR wa_final.
ULINE.
IF sy-lsind = 1.
WRITE : /1 'MATERIAL NO' COLOR 2,
20 'CREATION DATE' COLOR 3,
32 'PERSON CREATED',
50 'DATE OF LIST' ,
65 'MATERIALTYPE',
80 'MATGROUP' ,
90 'UNITOFMEASURE',
110 'STORLOCATION' COLOR 4,
130 'PLANT' COLOR 5.
ULINE.
ENDIF.
LOOP AT it_mara INTO wa_mara WHERE matnr = wa_makt-matnr.
wa_final-matnr = wa_mara-matnr.
wa_final-ersda = wa_mara-ersda.
wa_final-ernam = wa_mara-ernam.
wa_final-laeda = wa_mara-laeda.
wa_final-mtart = wa_mara-mtart.
wa_final-matkl = wa_mara-matkl.
wa_final-meins = wa_mara-meins.
READ TABLE it_mard INTO wa_mard WITH KEY matnr = wa_makt-matnr.
wa_final-lgort = wa_mard-lgort.
wa_final-werks = wa_mard-werks.
APPEND wa_final TO it_final.
ENDLOOP.
LOOP AT it_final INTO wa_final.
WRITE :
/1 wa_final-matnr
COLOR 2,
20 wa_final-ersda ,
37 wa_final-ernam,
50 wa_final-laeda ,
70 wa_final-mtart ,
85 wa_final-matkl ,
95 wa_final-meins,
115 wa_final-lgort ,
130 wa_final-werks .
ENDLOOP.
TOP-OF-PAGE.
WRITE : /1 'MATERIAL NO' COLOR 1,
40 'DISCRIPTION' COLOR 2.
ULINE .
deleting, inserting, updating a record from work area
report .
data: begin of itab occurs 0,
name(10) type c,
age type i,
end of itab .
selection-screen begin of line .
parameters:p_wa(100) type c .
selection-screen end of line .
selection-screen skip 2.
selection-screen begin of line .
SELECTION-SCREEN:
PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
PUSHBUTTON 15(20) but2 USER-COMMAND cli2 ,
PUSHBUTTON 40(20) but3 USER-COMMAND cli3 visible length 5 .
selection-screen end of line .
at selection-screen .
case sy-ucomm .
when 'CLI1'.
itab-name = p_wa+0(10) .
itab-age = p_wa+11(2).
append itab.
when 'CLI2'.
delete itab where name = p_wa+0(10) .
when 'CLI3'.
read table itab with key name = p_wa+0(10).
if sy-subrc = 0.
modify itab transporting name age.
else .
exit.
endif .
endcase .
start-of-selection .
loop at itab.
write:/ itab-name .
endloop.
REPORT z_find_userexit NO STANDARD PAGE HEADING.
TABLES : tstc, "SAP Transaction Codes
tadir, "Directory of Repository Objects
modsapt, "SAP Enhancements - Short Texts
modact, "Modifications
trdir, "System table TRDIR
tfdir, "Function Module
enlfdir, "Additional Attributes for Function Modules
tstct. "Transaction Code Texts
*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*
DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
DATA : field1(30).
DATA : v_devclass LIKE tadir-devclass.
*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK a01.
*&---------------------------------------------------------------------*
*& Start of main program
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Validate Transaction Code
SELECT SINGLE * FROM tstc
WHERE tcode EQ p_tcode.
* Find Repository Objects for transaction code
IF sy-subrc EQ 0.
SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'PROG'
AND obj_name = tstc-pgmna.
MOVE : tadir-devclass TO v_devclass.
IF sy-subrc NE 0.
SELECT SINGLE * FROM trdir
WHERE name = tstc-pgmna.
IF trdir-subc EQ 'F'.
SELECT SINGLE * FROM tfdir
WHERE pname = tstc-pgmna.
SELECT SINGLE * FROM enlfdir
WHERE funcname = tfdir-funcname.
SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'FUGR'
AND obj_name = enlfdir-area.
MOVE : tadir-devclass TO v_devclass.
ENDIF.
ENDIF.
* Find SAP Modifactions
SELECT * FROM tadir
INTO TABLE jtab
WHERE pgmid = 'R3TR'
AND object = 'SMOD'
AND devclass = v_devclass.
SELECT SINGLE * FROM tstct
WHERE sprsl EQ sy-langu
AND tcode EQ p_tcode.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
SKIP.
IF NOT jtab[] IS INITIAL.
WRITE:/(95) sy-uline.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
WRITE:/(95) sy-uline.
LOOP AT jtab.
SELECT SINGLE * FROM modsapt
WHERE sprsl = sy-langu AND
name = jtab-obj_name.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/1 sy-vline,
2 jtab-obj_name HOTSPOT ON,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.
ENDLOOP.
WRITE:/(95) sy-uline.
DESCRIBE TABLE jtab.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , sy-tfill.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'No User Exit exists'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'Transaction Code Does Not Exist'.
ENDIF.
* Take the user to SMOD for the Exit that was selected.
AT LINE-SELECTION.
GET CURSOR FIELD field1.
CHECK field1(4) EQ 'JTAB'.
SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
REPORT ZMAIL.
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver .
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
* Retrieve sample data from table ekpo
PERFORM data_retrieval.
* Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
perform populate_email_message_body.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
' '
' '
' '
changing gd_error
gd_reciever.
* Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*& Form BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
* Build data table for .xls document
*----------------------------------------------------------------------*
FORM build_xls_data_table.
data: ld_store(50) type c. "Leading zeros
CONSTANTS: con_cret(5) TYPE c VALUE '0D', "OK for non Unicode
con_tab(5) TYPE c VALUE '09'. "OK for non Unicode
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED
BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
wa_charekpo-ebelp '")' into ld_store .
CONCATENATE wa_charekpo-ebeln ld_store wa_charekpo-aedat
wa_charekpo-matnr INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
* Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
* Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*& Form POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
* Populate message body text
*----------------------------------------------------------------------*
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
REPORT ZPURCHASE_ORDER.
*--type pools
TYPE-POOLS:SLIS.
*--internal tables for alv
DATA:
W_EBELN TYPE EKKO-EBELN,
W_PROG TYPE SY-REPID,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
T_EVENTCAT TYPE SLIS_T_EVENT,
W_EVENTCAT LIKE LINE OF T_EVENTCAT.
DATA:
T_EKKO LIKE STANDARD TABLE OF EKKO,
FS_EKKO LIKE LINE OF T_EKKO.
DATA:T_EKPO LIKE STANDARD TABLE OF EKPO,
FS_EKPO LIKE LINE OF T_EKPO.
*---- SELECT-OPTIONS DECLARATION
SELECT-OPTIONS:S_EBELN FOR W_EBELN.
*----- START-OF-SELECTION
START-OF-SELECTION.
SELECT *
FROM EKKO
INTO TABLE T_EKKO
WHERE EBELN IN S_EBELN.
W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
I_CALLBACK_USER_COMMAND = 'PICK'
I_STRUCTURE_NAME = 'EKKO'
TABLES
T_OUTTAB = T_EKKO .
*&--------------------------------------------------------------------*
*& Form pick
*---------------------------------------------------------------------*
FORM PICK USING COMMAND LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE T_EKKO INTO FS_EKKO INDEX SELFIELD-TABINDEX.
CASE COMMAND.
WHEN '&IC1'.
SELECT *
FROM EKPO
INTO TABLE T_EKPO
WHERE EBELN EQ FS_EKKO-EBELN.
W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'EKPO'
CHANGING
CT_FIELDCAT = T_FIELDCAT .
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'EBELN'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'BUKRS'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'LGORT'.
DELETE T_FIELDCAT WHERE FIELDNAME EQ 'WERKS'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IT_FIELDCAT = T_FIELDCAT
IT_EVENTS = T_EVENTCAT
TABLES
T_OUTTAB = T_EKPO .
ENDCASE. " CASE COMMAND
ENDFORM. " FORM PICK
FORM T_EVENTCAT.
W_EVENTCAT-NAME = 'TOP_OF_PAGE'.
W_EVENTCAT-FORM = 'TOP'.
APPEND W_EVENTCAT TO T_EVENTCAT.
ENDFORM.
FORM TOP.
READ TABLE T_EKPO INTO FS_EKPO INDEX 1.
WRITE:/ 'Purchase Document Number'(001),30 FS_EKPO-EBELN,
/ 'Company Code'(002), 30 FS_EKPO-BUKRS,
/ 'Plant'(003), 30 FS_EKPO-WERKS,
/ 'Storage Location'(004),30 FS_EKPO-LGORT.
ENDFORM.
time difference between two dates
REPORT ztest.
DATA : lv_seconds TYPE sytabix .
data: l type i ,
j(10) type c ,
k(12) type c .
parameters:p_date1 type sy-datum,
p_date2 type sy-datum.
CALL FUNCTION 'SWI_DURATION_DETERMINE'
EXPORTING
start_date = p_date1
end_date = p_date2
start_time = sy-uzeit
end_time = sy-uzeit
IMPORTING
duration = lv_seconds.
l = lv_seconds.
j = l / 60 .
k = l / 3600 .
WRITE :/ k ,'hours' .
write:/ j , 'minutes' .
write:/ l ,'seconds' .
day month year (month in words input sy-datum)
report ztest .
DATA ldate(20).
CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'
EXPORTING
input = sy-datum
IMPORTING
OUTPUT = ldate.
write:/ ldate .
REPORT ZTEST_DWBLD1.
data: it_ekko like ekko occurs 5 with header line.
data: v_aedat type sy-datum.
DATA: dbcur TYPE cursor.
start-of-selection.
v_aedat = '20001102'.
OPEN CURSOR dbcur FOR
select * from ekko where aedat = '20001102'.
do.
FETCH NEXT CURSOR dbcur INTO table it_ekko package size 5.
if sy-subrc <> 0.
close cursor dbcur.
exit.
else.
loop at it_ekko.
write: / it_ekko-ebeln.
endloop.
refresh it_ekko.
endif.
enddo.
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) type c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-info_fieldname = 'LINE_COLOR'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
i_save = 'X'
tables
t_outtab = it_ekko .
endform. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
modify it_ekko from wa_ekko.
endloop.
endform. " DATA_RETRIEVAL
data: word(40) type c.
CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
EXPORTING
AMT_IN_NUM = '10000078'
IMPORTING
AMT_IN_WORDS = word.
write:/ word.
report .
data: i_date like SY-DATUM ,
date like SY-DATUM .
i_date = sy-datum .
CALL FUNCTION 'ADD_TIME_TO_DATE'
EXPORTING
I_IDATE = i_date "Original date
I_TIME = '1' " Ammount to add
I_IPRKZ = '3' " unit: 'blank'-days 1-weeks 2-months 3-years
* I_RDMHD =
IMPORTING
O_IDATE = date ."new date
write:/ date .
simple alv grid with save layout
REPORT ZTEST.
TYPE-POOLS: slis.
DATA: report_id LIKE sy-repid.
DATA: i_qmel LIKE qmel OCCURS 0.
DATA: i_layout TYPE slis_layout_alv.
SELECT * FROM qmel INTO TABLE i_qmel.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = report_id
i_structure_name = 'QMEL'
is_layout = i_layout
i_save = 'A'
TABLES
t_outtab = i_qmel .
FORM f1000_layout_init USING
i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
ENDFORM.
last day of month for fny month
report ztest .
data:lv_actual_date type sy-datum,
lv_end_of_month_date type sy-datum.
parameters:p_date type dats.
lv_actual_date = p_date.
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = lv_actual_date
* I_FLG_END_OF_MONTH = ' '
* I_YEARS = 0
* I_MONTHS = 0
* I_DAYS = 0
* I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = lv_end_of_month_date .
write: / lv_end_of_month_date.
REPORT ZPOPDATE.
DATA: V_CODE LIKE SY-SUBRC.
PARAMETER: V_MONTH LIKE ISELLIST-MONTH.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR V_MONTH.
CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
EXPORTING
ACTUAL_MONTH = '200205'
LANGUAGE = SY-LANGU
START_COLUMN = 8
START_ROW = 5
IMPORTING
SELECTED_MONTH = V_MONTH
RETURN_CODE = V_CODE
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
MONTH_NOT_FOUND = 3
OTHERS = 4.
program to open a file on the pc
REPORT ZUM_OPEN_WORD .
* The internal table is declared of size 3
DATA: BEGIN OF ITAB OCCURS 3,
LINE(50),
END OF ITAB.
PARAMETERS: PROG(70) DEFAULT
'C:\Program Files\Microsoft Office\Office\WINWORD.EXE'.
PARAMETERS: FILE1(70) DEFAULT 'C:\TEMP\TEST.TXT'.
* Tick to print the Text file after saving from MS WORDS
PARAMETERS: S_UP AS CHECKBOX.
* Tick to create new or overwrite Text file
PARAMETERS: S_NEW AS CHECKBOX.
IF S_UP = 'X'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'FILE1'
TABLES
DATA_TAB = ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1.
IF SY-SUBRC = 0.
LOOP AT ITAB.
WRITE: / ITAB.
ENDLOOP.
ELSE.
WRITE: / 'File open error.'.
ENDIF.
ELSE.
IF S_NEW = 'X'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'FILE1'
TABLES
DATA_TAB = ITAB
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
OTHERS = 5.
ENDIF.
CASE SY-SUBRC.
WHEN 1.
WRITE: / 'GUI DOWNLOAD FILE WRITE ERROR'.
WHEN 2.
WRITE: / 'GUI DOWNLOAD NO BATCH'.
WHEN 3.
WRITE: / 'GUI DOWNLOAD GUI REFUSE FILETRANSFER'.
WHEN 4.
WRITE: / 'GUI DOWNLOAD INVALID TYPE'.
WHEN 5.
WRITE: / 'GUI DOWNLOAD OTHERS'.
ENDCASE.
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
PROGRAM = PROG
COMMANDLINE = 'FILE1'
INFORM = ' '
EXCEPTIONS
FRONTEND_ERROR = 1
NO_BATCH = 2
PROG_NOT_FOUND = 3
ILLEGAL_OPTION = 4
GUI_REFUSE_EXECUTE = 5
OTHERS = 6.
CASE SY-SUBRC.
WHEN 1.
WRITE: / 'FRONTEND ERROR'.
WHEN 2.
WRITE: / 'NO BATCH'.
WHEN 3.
WRITE: / 'PROGRAM NOT FOUND'.
WHEN 4.
WRITE: / 'ILLEGA OPTION'.
WHEN 5.
WRITE: / 'GUI REFUSE EXECUTE'.
WHEN 6.
WRITE: / 'OTHERS'.
ENDCASE.
ENDIF.
report ztest .
parameters: v_int TYPE i .
DATA words LIKE SPELL.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = v_int
LANGUAGE = SY-LANGU
IMPORTING
IN_WORDS = words
.
WRITE words-word.
REPORT ZMONTH.
DATA X_MONTH(11).
parameters:p_date type sy-datum.
CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'
EXPORTING
INPUT = p_date
IMPORTING
OUTPUT = X_MONTH.
WRITE:/ 'Month ', X_MONTH+3(8).
report ztest .
tables:mara,marc,mard.
data:begin of it_final occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
werks like marc-werks,
pstat like marc-pstat,
lgort like mard-lgort,
labst like mard-labst,
end of it_final.
select-options:s_matnr for mara-matnr.
start-of-selection.
select matnr
mtart
meins
from mara
into table it_final
where matnr in s_matnr.
if sy-subrc = 0.
loop at it_final.
select single
werks
pstat
from marc
into (it_final-werks,it_final-pstat)
where matnr = it_final-matnr.
modify it_final.
if sy-subrc = 0.
select single
lgort
labst
from mard
into (it_final-lgort,it_final-labst)
where werks = it_final-werks.
modify it_final.
endif.
endloop.
endif.
if sy-subrc = 0.
loop at it_final.
write:/ it_final-matnr,
it_final-mtart,
it_final-meins,
it_final-werks,
it_final-pstat,
it_final-lgort,
it_final-labst.
endloop.
endif.
REPORT ZTEST .
TABLES pernr.
INFOTYPES : 0001.
START-OF-SELECTION.
GET pernr.
WRITE : / 'Result from Macros'.
rp-provide-from-frst p0001 space pn-begda pn-endda.
IF pnp-sw-found = 1.
WRITE : / '-------------------------------------'.
WRITE : / 'Result from rp-provide-from-frst'.
WRITE : / '-------------------------------------'.
WRITE : / p0001-pernr, p0001-begda, p0001-endda.
ENDIF.
rp-provide-from-last p0001 space pn-begda pn-endda.
IF pnp-sw-found = 1.
WRITE : / '-------------------------------------'.
WRITE : / 'Result from rp-provide-from-last'.
WRITE : / '-------------------------------------'.
WRITE : / p0001-pernr, p0001-begda, p0001-endda.
ENDIF.
rp-read-infotype pernr-pernr 0001 p0001 pn-begda pn-endda.
IF pnp-sw-found = 1.
WRITE : / '-------------------------------------'.
WRITE : / 'Result from rp-read-infotype'.
WRITE : / '-------------------------------------'.
LOOP AT p0001.
WRITE : / p0001-pernr, p0001-begda, p0001-endda.
ENDLOOP.
ENDIF.
END-OF-SELECTION.
report ztest.
TYPE-POOLS: VRM.
DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.
PARAMETERS: PS_PARM(10) AS LISTBOX VISIBLE LENGTH 10.
AT SELECTION-SCREEN OUTPUT.
NAME = 'PS_PARM'.
VALUE-KEY = '1'.
VALUE-TEXT = 'LINE 1'.
APPEND VALUE TO LIST.
VALUE-KEY = '2'.
VALUE-TEXT = 'LINE 2'.
APPEND VALUE TO LIST.
VALUE-KEY = '3'.
VALUE-TEXT = 'LINE 3'.
APPEND VALUE TO LIST.
VALUE-KEY = '4'.
VALUE-TEXT = 'LINE 4'.
APPEND VALUE TO LIST.
VALUE-KEY = '5'.
VALUE-TEXT = 'LINE 5'.
APPEND VALUE TO LIST.
VALUE-KEY = '6'.
VALUE-TEXT = 'LINE 6'.
APPEND VALUE TO LIST.
VALUE-KEY = '7'.
VALUE-TEXT = 'LINE 7'.
APPEND VALUE TO LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = NAME
VALUES = LIST.
START-OF-SELECTION.
WRITE: / 'PARAMETER:', PS_PARM.
TABLES:PERNR.
INFOTYPES:0002,0008.
GET PERNR.
PROVIDE * FROM P0002 BETWEEN PN-BEGDA AND PN-ENDDA.
ENDPROVIDE.
PROVIDE * FROM P0008 BETWEEN PN-BEGDA AND PN-ENDDA.
ENDPROVIDE.
IF SY-SUBRC = 0.
WRITE:/ P0002-PERNR,
P0002-BEGDA,
P0002-ENDDA,
P0002-VORNA,
P0008-ANSAL,
P0008-lga01,
P0008-bet01,
P0008-PREAS.
ENDIF.
REPORT ZTEST .
tables:mara,marc,mard.
data:begin of itab occurs 0,
matnr like mara-matnr,
mtart like mara-mtart,
meins like mara-meins,
werks like marc-werks,
pstat like marc-pstat,
labst like mard-labst,
lgort like mard-lgort,
maktx like makt-maktx,
end of itab.
select-options:s_matnr for mara-matnr.
start-of-selection.
select a~matnr
a~mtart
a~meins
b~werks
b~pstat
c~lgort
c~labst
into corresponding fields of table itab
from mara as a inner join marc as b on a~matnr = b~matnr
inner join mard as c on a~matnr = c~matnr
and b~werks = c~werks
where a~matnr in s_matnr.
if sy-subrc = 0.
loop at itab.
select single maktx
from makt
into itab-maktx
where matnr = itab-matnr.
modify itab.
write:/ itab-matnr,
itab-mtart,
itab-meins,
itab-werks,
itab-pstat,
itab-lgort,
itab-labst,
itab-maktx.
endloop.
REPORT ztest .
TABLES : TSTC,
TADIR,
MODSAPT,
MODACT,
TRDIR,
TFDIR,
ENLFDIR,
SXS_ATTRT ,
TSTCT.
DATA : JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE.
DATA : FIELD1(30).
DATA : V_DEVCLASS LIKE TADIR-DEVCLASS.
PARAMETERS : P_TCODE LIKE TSTC-TCODE,
P_PGMNA LIKE TSTC-PGMNA .
DATA wa_tadir type tadir.
START-OF-SELECTION.
IF NOT P_TCODE IS INITIAL.
SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE.
ELSEIF NOT P_PGMNA IS INITIAL.
TSTC-PGMNA = P_PGMNA.
ENDIF.
IF SY-SUBRC EQ 0.
SELECT SINGLE * FROM TADIR
WHERE PGMID = 'R3TR'
AND OBJECT = 'PROG'
AND OBJ_NAME = TSTC-PGMNA.
MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
IF SY-SUBRC NE 0.
SELECT SINGLE * FROM TRDIR
WHERE NAME = TSTC-PGMNA.
IF TRDIR-SUBC EQ 'F'.
SELECT SINGLE * FROM TFDIR
WHERE PNAME = TSTC-PGMNA.
SELECT SINGLE * FROM ENLFDIR
WHERE FUNCNAME = TFDIR-FUNCNAME.
SELECT SINGLE * FROM TADIR
WHERE PGMID = 'R3TR'
AND OBJECT = 'FUGR'
AND OBJ_NAME EQ ENLFDIR-AREA.
MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
ENDIF.
ENDIF.
SELECT * FROM TADIR INTO TABLE JTAB
WHERE PGMID = 'R3TR'
AND OBJECT in ('SMOD', 'SXSD')
AND DEVCLASS = V_DEVCLASS.
SELECT SINGLE * FROM TSTCT
WHERE SPRSL EQ SY-LANGU
AND TCODE EQ P_TCODE.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) P_TCODE,
45(50) TSTCT-TTEXT.
SKIP.
IF NOT JTAB[] IS INITIAL.
WRITE:/(105) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
* Sorting the internal Table
sort jtab by OBJECT.
data : wf_txt(60) type c,
wf_smod type i ,
wf_badi type i ,
wf_object2(30) type C.
clear : wf_smod, wf_badi , wf_object2.
* Get the total SMOD.
LOOP AT JTAB into wa_tadir.
at first.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 SY-VLINE,
2 'Enhancement/ Business Add-in',
41 SY-VLINE ,
42 'Description',
105 SY-VLINE.
WRITE:/(105) SY-ULINE.
endat.
clear wf_txt.
at new object.
if wa_tadir-object = 'SMOD'.
wf_object2 = 'Enhancement' .
elseif wa_tadir-object = 'SXSD'.
wf_object2 = ' Business Add-in'.
endif.
FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE:/1 SY-VLINE,
2 wf_object2,
105 SY-VLINE.
endat.
case wa_tadir-object.
when 'SMOD'.
wf_smod = wf_smod + 1.
SELECT SINGLE MODTEXT into wf_txt
FROM MODSAPT
WHERE SPRSL = SY-LANGU
AND NAME = wa_tadir-OBJ_NAME.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
when 'SXSD'.
* For BADis
wf_badi = wf_badi + 1 .
select single TEXT into wf_txt
from SXS_ATTRT
where sprsl = sy-langu
and EXIT_NAME = wa_tadir-OBJ_NAME.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
endcase.
WRITE:/1 SY-VLINE,
2 wa_tadir-OBJ_NAME hotspot on,
41 SY-VLINE ,
42 wf_txt,
105 SY-VLINE.
AT END OF object.
write : /(105) sy-ULINE.
ENDAT.
ENDLOOP.
WRITE:/(105) SY-ULINE.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No.of Exits:' , wf_smod.
WRITE:/ 'No.of BADis:' , wf_badi.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(105) 'No userexits or BADis exist'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(105) 'Transaction does not exist'.
ENDIF.
AT LINE-SELECTION.
data : wf_object type tadir-object.
clear wf_object.
GET CURSOR FIELD FIELD1.
CHECK FIELD1(8) EQ 'WA_TADIR'.
read table jtab with key obj_name = sy-lisel+1(20).
move jtab-object to wf_object.
case wf_object.
when 'SMOD'.
SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
when 'SXSD'.
SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20).
CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
endcase.
itab to excel or txt file( using f4_file)
TABLES : MARA.
*-------------INTERNAL TABLE DECLARATION
TYPES : BEGIN OF ITAB,
MATNR TYPE MARA-MATNR,
MEINS TYPE MARA-MEINS,
ERNAM LIKE MARA-ERNAM,
AENAM LIKE MARA-AENAM,
MTART LIKE MARA-MTART,
END OF ITAB.
DATA : IG_ITAB type ITAB OCCURS 0.
DATA : V_FILE TYPE STRING.
DATA : T_FILE TYPE RLGRAP-FILENAME.
*-------------RETRIVE DATA FROM DATABASE
SELECT
MATNR
MEINS ERNAM AENAM MTART FROM MARA
INTO CORRESPONDING FIELDS OF TABLE
IG_ITAB
up to 10 rows.
*-------------CALLING FUNCTION MODULES
CALL FUNCTION 'F4_FILENAME' "PASS THE FILE NAME AS U NEED.
EXPORTING
FIELD_NAME = 'T_FILE'
IMPORTING
FILE_NAME = T_FILE.
V_FILE = T_FILE. "STRING CONVERSION
*-------------CALLING GUI DOWNLOAD TO EXTRACT
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = V_FILE
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
WRITE_LF = 'X'
tables
data_tab = IG_ITAB .
simple download from itab to file
REPORT ZVENKATTEST0.
data: begin of itab occurs 0,
a type c,
c type c,
b type i,
end of itab.
itab-a = 'a' .
itab-c = ':'.
itab-b = 1 .
append itab .
itab-a = 'b' .
itab-c = ':'.
itab-b = 2 .
append itab .
itab-a = 'c' .
itab-c = ':'.
itab-b = 3 .
append itab .
data: file type string .
file = 'C:\Documents and Settings\venkatapp\Desktop\test.txt'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = file
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = ':'
TABLES
DATA_TAB = itab.
REPORT ZTEST.
DATA : G_FILE(128) TYPE C.
DATA : G_PATH(80) TYPE C.
DATA : G_END(8) TYPE C.
DATA : G_SUBRC LIKE SY-SUBRC.
PARAMETERS: P_UNAME LIKE SY-UNAME DEFAULT SY-UNAME.
PARAMETERS: P_LANGU LIKE SY-LANGU DEFAULT SY-LANGU.
SELECTION-SCREEN SKIP.
PARAMETERS: P_IMP RADIOBUTTON GROUP ACT .
PARAMETERS: P_EXP RADIOBUTTON GROUP ACT DEFAULT 'X'.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN BEGIN OF BLOCK FIL.
PARAMETERS: P_TYPE LIKE RLGRAP-FILETYPE DEFAULT 'ASC'.
PARAMETERS: P_PATH LIKE G_PATH DEFAULT 'C:\TEMP\XXX.MEN'.
SELECTION-SCREEN END OF BLOCK FIL.
DATA: IT_USER_NODES TYPE TABLE OF BXMNODES1 WITH HEADER LINE.
DATA: IT_FAV_NODES TYPE TABLE OF BXMNODES WITH HEADER LINE.
DATA: BEGIN OF IT_PCF OCCURS 0,
LINE(4096) TYPE C.
DATA: END OF IT_PCF.
INITIALIZATION.
REPLACE 'XXX' WITH SY-UNAME INTO P_PATH.
CONDENSE P_PATH NO-GAPS.
SY-TITLE = 'UPLOAD/DOWNLOAD FAVORITE'.
START-OF-SELECTION.
CLEAR IT_USER_NODES[].
CLEAR IT_FAV_NODES[].
G_FILE = P_UNAME.
IF P_UNAME <> SY-UNAME.
MESSAGE W398(00) WITH 'CURRENT USER <> USER TO BE MODIFIED!'.
ENDIF.
IF P_IMP = 'X'.
PERFORM IMPORT_FAV TABLES IT_FAV_NODES.
PERFORM WRITE_FAV_DB TABLES IT_FAV_NODES.
ELSEIF P_EXP = 'X'.
PERFORM EXPORT_FAV TABLES IT_FAV_NODES.
ENDIF.
FORM DATA_EXPORT TABLES PIT_PCF
USING P_FILE.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = P_TYPE
TABLES
DATA_TAB = PIT_PCF
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
GUI_REFUSE_FILETRANSFER = 8
OTHERS = 9.
IF SY-SUBRC NE 0.
WRITE: / 'FAILURE IN DOWNLOAD' , P_FILE.
ENDIF.
ENDFORM.
FORM DATA_IMPORT TABLES PIT_PCF
USING P_FILE P_SUBRC.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = P_FILE
FILETYPE = P_TYPE
TABLES
DATA_TAB = PIT_PCF
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
GUI_REFUSE_FILETRANSFER = 8
OTHERS = 9.
IF SY-SUBRC NE 0.
WRITE: / 'UPLOAD FAILED' , P_FILE.
P_SUBRC = SY-SUBRC .
ENDIF.
ENDFORM.
FORM IMPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
G_FILE = P_PATH.
PERFORM DATA_IMPORT TABLES IT_FAV_NODES USING G_FILE G_SUBRC .
ENDFORM.
FORM EXPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
CALL FUNCTION 'BX_FAVOS_READ_ALL_NODES'
EXPORTING
USER_NAME = P_UNAME
LANGUAGE = P_LANGU
TABLES
OUTPUT_NODES_AND_TEXTS = IT_FAV_NODES.
G_FILE = P_PATH.
PERFORM DATA_EXPORT TABLES IT_FAV_NODES USING G_FILE .
ENDFORM.
FORM WRITE_FAV_DB TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.
CALL FUNCTION 'BX_FAVOS_WRITE_ALL_NODES'
EXPORTING
USER_NAME = P_UNAME
TARGET_CLIENT = SY-MANDT
TABLES
INPUT_NODES_AND_TEXTS = PIT_FAV_NODES.
ENDFORM.
report ztest.
tables: t247 , DFIES.
parameters:p_month LIKE T247-MNR.
data: begin of itab occurs 0,
mnr like t247-mnr,
ktx like t247-ktx,
end of itab .
DATA : LT_FIELDS TYPE TABLE OF DFIES,
LS_FIELD TYPE DFIES.
at selection-screen on value-request for p_month.
select MNR
KTX
from t247 into corresponding fields of table itab
where spras = 'EN'.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'P_MONTH'
DYNPPROG = sy-cprog
DYNPNR = sy-dynnr
DYNPROFIELD = 'MNR'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = itab
FIELD_TAB = LT_FIELDS .
f4 help for a field with ztable
*--crete a z table with 2 fields and name(10) and age(2) and create entries..
REPORT MESSAGE-ID ZMSF.
TABLES:ZZZ000000 ,DFIES.
DATA: BEGIN OF ITAB OCCURS 0,
NAME(10) ,
AGE(2),
END OF ITAB.
DATA : LT_FIELDS TYPE TABLE OF DFIES WITH HEADER LINE,
LS_FIELD TYPE DFIES.
PARAMETER: P_NAME(10) TYPE C.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_NAME.
REFRESH ITAB.
REFRESH LT_FIELDS.
LT_FIELDS-TABNAME = 'ZZZ00000'.
LT_FIELDS-FIELDNAME = 'NAME'.
APPEND LT_FIELDS.
CLEAR LT_FIELDS .
LT_FIELDS-TABNAME = 'ZZZ00000'.
LT_FIELDS-FIELDNAME = 'AGE'.
LT_FIELDS-POSITION = '2'.
APPEND LT_FIELDS.
CLEAR LT_FIELDS .
SELECT NAME
AGE FROM ZZZ00000
INTO TABLE ITAB.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = LT_FIELDS-FIELDNAME
DYNPPROG = SY-CPROG
DYNPNR = SY-DYNNR
DYNPROFIELD = 'NAME'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = ITAB
FIELD_TAB = LT_FIELDS.
*--create a z table with fields pernr like pa0002-pernr
* vorna like pa0002-vorna
* nachn like pa0002-nachn
* and create entries for the table
report message-id zmsf.
tables:zzz000000 ,DFIES.
DATA: BEGIN OF itab OCCURS 0,
pernr like pa0002-pernr,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
END OF itab.
DATA : LT_FIELDS TYPE TABLE OF DFIES,
LS_FIELD TYPE DFIES.
PARAMETER: pernr LIKE pa0002-pernr .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pernr.
select pernr
vorna
nachn
from zzz000000
into table itab .
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'PERNR'
DYNPPROG = sy-cprog
DYNPNR = sy-dynnr
DYNPROFIELD = 'PERNR'
VALUE_ORG = 'S'
TABLES
VALUE_TAB = itab
FIELD_TAB = LT_FIELDS .
start-of-selection.
select pernr
vorna
nachn
from zzz000000
into table itab
where pernr = pernr.
loop at itab.
write:/ itab-pernr,
itab-vorna,
itab-nachn.
endloop.
report message-id zmsf.
DATA:
l_select_date LIKE workflds-gkday,
l_select_week LIKE scal-week.
* pop up calendar.
CALL FUNCTION 'F4_DATE'
EXPORTING
date_for_first_month = sy-datum
IMPORTING
select_date = l_select_date
select_week = l_select_week
EXCEPTIONS
calendar_buffer_not_loadable = 1
date_after_range = 2
date_before_range = 3
date_invalid = 4
factory_calendar_not_found = 5
holiday_calendar_not_found = 6
parameter_conflict = 7
OTHERS = 8.
IF sy-subrc <> 0.
EXIT.
ENDIF.
* Validate date - An invalid date is caused by using the cancel
* button on the calendar
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = l_select_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* User has cancelled the calendar
EXIT.
ENDIF.
report LINE-SIZE 200.
WRITE:
/(140) 'THIS IS THE HEADER OF THE PAGE' CENTERED,
/(140) 'THIS IS THE VENKAT TEST HEADING' CENTERED,
/(140) 'HI FRIEND THIS IS WORKING' CENTERED,
/(10) 'date:' LEFT-JUSTIFIED,
(10) sy-datum LEFT-JUSTIFIED,
(90) 'CLIENT' RIGHT-JUSTIFIED,
(08) SY-MANDT RIGHT-JUSTIFIED,
/(10) 'time:' LEFT-JUSTIFIED,
(10) sy-uzeit LEFT-JUSTIFIED,
(92) 'USERNAME' RIGHT-JUSTIFIED,
(10) SY-UNAME RIGHT-JUSTIFIED.
inserting deleteing updating values from work area
*--hi create a zdatabase table with 2 entries name(10) and age(2) .
report ztest .
tables:ZZZ00000.
data: begin of itab occurs 0,
name(10) type c,
age type i,
end of itab .
selection-screen begin of line .
parameters:p_wa(100) type c .
selection-screen end of line .
selection-screen skip 2.
selection-screen begin of line .
SELECTION-SCREEN:
PUSHBUTTON 2(10) but1 USER-COMMAND cli1,
PUSHBUTTON 15(20) but2 USER-COMMAND cli2 ,
PUSHBUTTON 40(20) but3 USER-COMMAND cli3 visible length 5 .
selection-screen end of line .
at selection-screen .
case sy-ucomm .
when 'CLI1'.
ZZZ00000-name = p_wa+0(10) .
ZZZ00000-age = p_wa+11(2).
insert ZZZ00000.
when 'CLI2'.
delete from ZZZ00000 where name = p_wa+0(10)..
when 'CLI3'.
update ZZZ00000 from p_wa .
endcase .
REPORT z_alv_list_block.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
SKIP,
BEGIN OF LINE,
COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '02' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
DATA:
* 1st Table
BEGIN OF gt_kna1 OCCURS 0, " Data displayed
kunnr LIKE kna1-kunnr, " Customer number
ernam LIKE kna1-ernam, " Name of Person who Created
erdat LIKE kna1-erdat, " Creation date
name1 LIKE kna1-name1, " Name 1
END OF gt_kna1,
* 2nd Table
BEGIN OF gt_mara OCCURS 0,
ernam LIKE mara-ernam, " Name of Person who Created
matnr LIKE mara-matnr, " Material number
ersda LIKE mara-ersda, " Creation date
brgew LIKE mara-brgew, " Gross weight
END OF gt_mara,
* 3rd Table
BEGIN OF gt_vbak OCCURS 0,
vkorg LIKE vbak-vkorg, " Sales organization
kunnr LIKE vbak-kunnr, " Sold-to party
vbeln LIKE vbak-vbeln, " Sales document
netwr LIKE vbak-netwr, " Net Value of the Sales Order
waerk LIKE vbak-waerk, " SD document currency
END OF gt_vbak.
INITIALIZATION.
v_1 = 'Maximum of records to read'.
START-OF-SELECTION.
* Read data
SELECT * FROM kna1
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_kna1.
SELECT * FROM mara
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_mara.
S