UPLOAD XML FILE FROM APPLICATION SERVER

Here is the code for uploading XML file from application server into data base server of SAP.

TYPE-POOLS: ixml. "iXML Library Types
*TABLES : rbkp.

&---------------------------------------------------------------------

* TYPE DECLERATIION

&---------------------------------------------------------------------

TYPES: BEGIN OF type_tabpo,
ebeln TYPE ekko-ebeln, "PO document number
ebelp TYPE ekpo-ebelp, "PO line item
END OF type_tabpo.

TYPES: BEGIN OF type_ekbe,
belnr TYPE rbkp-belnr, "Invoice document
gjahr TYPE rbkp-gjahr, "fiscal year
END OF type_ekbe.

TYPES: BEGIN OF type_invoice,
belnr TYPE rbkp-belnr, "PO document number
gjahr TYPE rbkp-gjahr, "Fiscal Year
rbstat TYPE rbkp-rbstat, "invoice status
END OF type_invoice.

TYPES: BEGIN OF t_xml_line, "Structure for holding XML data
data(256) TYPE x,
END OF t_xml_line.

&---------------------------------------------------------------------

* INTERNAL TABLE DECLERATIION

&---------------------------------------------------------------------

DATA: gi_tabpo TYPE STANDARD TABLE OF type_tabpo,
gi_ekbe TYPE STANDARD TABLE OF type_ekbe,
gi_invoice TYPE STANDARD TABLE OF type_invoice,
gi_bapiret2 TYPE STANDARD TABLE OF bapiret2.

DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory.

* l_parser TYPE REF TO if_ixml_parser,
* l_istream TYPE REF TO swif_ixml_istream,
* l_document TYPE REF TO if_ixml_document,
* l_node TYPE REF TO if_ixml_node,
* l_xmldata TYPE string.


*DATA: l_elem TYPE REF TO if_ixml_element,

* l_root_node TYPE REF TO if_ixml_node,
* l_next_node TYPE REF TO if_ixml_node,
* l_name TYPE string,
* l_iterator TYPE REF TO if_ixml_node_iterator.


DATA: l_xml_table TYPE TABLE OF t_xml_line, " XML Table of the structure

l_xml_line TYPE t_xml_line, " Record of structure t_xml_line
l_xml_table_size TYPE i. " XML table size

DATA: l_filename TYPE string.

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

* WORK AREA DECLARATION

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

DATA: gw_tabpo TYPE type_tabpo,
gw_ekbe TYPE type_ekbe,
gw_invoice TYPE type_invoice,
gw_bapiret2 TYPE bapiret2.

*********************************************************************

* BEGIN OF SELECTION SCREEN

*********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE pathintern LOWER CASE DEFAULT '/usr/sap/tmp/'.

* Validation of XML file: Only DTD included in XML document is supported


SELECTION-SCREEN END OF BLOCK blk1.

***********************************************************************

* INTIALISATION.

***********************************************************************

INITIALIZATION.

***********************************************************************

* SELECTION SCREEN VALIDATION

***********************************************************************

AT SELECTION-SCREEN.

* To validate p_file is not initial

PERFORM sub_validate_file.

* PERFORM sub_validate_path.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

* Request for filename for xml file from the application server

PERFORM sub_get_filename_appl USING p_file.

***********************************************************************

* START OF SELECTION SCREEN

***********************************************************************

START-OF-SELECTION.

PERFORM sub_fetch_po_details.

PERFORM sub_get_invoice.

PERFORM sub_rel_invoice.

***********************************************************************

* END OF SELECTION SCREEN

***********************************************************************

END-OF-SELECTION.

&---------------------------------------------------------------------
*& Form sub_validate_file
&---------------------------------------------------------------------

* To Validate the file

*
----------------------------------------------------------------------
FORM sub_validate_file .

IF p_file IS INITIAL.
MESSAGE e000. "specify the file path

ENDIF.

ENDFORM. " sub_validate_file

&---------------------------------------------------------------------
*& Form sub_get_filename_appl
&----------------------------------------------------------------------
form sub_get_filename_appl USING l_fname TYPE any.

* DATA: l_fname TYPE filename-fileintern. " File name

*GET THE FILENAME FROM THE APPLICATION SERVER

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = l_fname
filemask = '*'
IMPORTING
serverfile = l_fname
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.
ENDFORM. " sub_get_filename_appl


&---------------------------------------------------------------------
*& Form sub_fetch_po_details
&---------------------------------------------------------------------

* To fetch the PO details from the application server
* Format of file is XML

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

FORM sub_fetch_po_details .

************************************************************************

* TYPE DECLERATIION

************************************************************************

l_ixml = cl_ixml=>create( ).

* Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

PERFORM get_xml_table.

LOOP AT gi_tabpo INTO gw_tabpo.
WRITE:/ gw_tabpo.
ENDLOOP.

ENDFORM. " sub_fetch_po_details

&--------------------------------------------------------------------
*& Form get_xml_table
&--------------------------------------------------------------------

* Read from the xml file

---------------------------------------------------------------------
FORM get_xml_table .

************************************************************************

* Local variable declarations

************************************************************************

DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab TYPE TABLE OF string.

l_filename = p_file.

***********************************************************************

* code to upload data from application server

***********************************************************************

OPEN DATASET l_filename FOR INPUT IN BINARY MODE.
IF sy-subrc 0.
WRITE:/ 'invalid file path'.
ENDIF.
DO.
READ DATASET l_filename INTO l_xml_line.

IF sy-subrc EQ 0.

APPEND l_xml_line TO l_xml_table.

ELSE.
EXIT.
ENDIF.
ENDDO.

CLOSE DATASET l_filename.

* code to find the table size

DESCRIBE TABLE l_xml_table.
l_xml_table_size = ( sy-tleng ) * ( sy-tfill ).

*code to convert hexadecimal to XML

LOOP AT l_xml_table INTO l_xml_line.

c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
replacement
= space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.

ENDLOOP.

l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN
l_str1 WITH space.
ENDLOOP.

CALL TRANSFORMATION ('ID') " code to put in internal table
SOURCE XML l_str1
RESULT tab = gi_tabpo[].

ENDFORM. " get_xml_table

The previous post of the blog is regarding COLORING CELLS USING ALV REPORT

ADD COLOR TO CELL WITH ALV REPORT

This alv report is useful to add color to a particular cell using abap alv report.Here is the code.

DATA: g_color_green TYPE slis_t_specialcol_alv.

  • create a table of fieldnames to be coloured intensified green -

PERFORM colour_cells TABLES g_color_green
USING 21 31 5.


  • set cells of this line to intensified green
IF CONDITION.....
out-color] = g_color_green[.
ENDIF.


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

  • FORM E05_LAYOUT_BUILD *
---------------------------------------------------------------------
  • ALV Layout options *
---------------------------------------------------------------------
  • <-> E05_LS_LAYOUT *
---------------------------------------------------------------------
FORM e05_layout_build USING e05_ls_layout TYPE slis_layout_alv.
  • Setting this flag avoids having to define field sizes.
e05_ls_layout-colwidth_optimize = 'X'.

  • FIELD COLOR contains table of FIELDNAME and COLOURS.
e05_ls_layout-coltab_fieldname = 'COLOR'.
ENDFORM.

&---------------------------------------------------------------------
*& Form colour_cells
&---------------------------------------------------------------------
  • Set up table to color field groups different from default colour
----------------------------------------------------------------------
  • <--> t_color table of fields and colours
  • <-- p_index_from - first field of catalogue to be coloured
  • <-- p_index_to - last field of catalogue to be coloured
  • <-- p_color - color number
----------------------------------------------------------------------
FORM colour_cells TABLES t_color
USING p_index_from TYPE sy-index
p_index_to TYPE sy-index
p_color TYPE i.

DATA: ls_fieldcat TYPE slis_fieldcat_alv,
w_tab TYPE slis_specialcol_alv.

  • use field catalogue to build new table for consecutive fields
LOOP AT gt_fieldcat INTO ls_fieldcat FROM p_index_from TO p_index_to.
w_tab-fieldname = ls_fieldcat-fieldname.
w_tab-color-col = p_color.
IF p_color = 5. "green
w_tab-color-int = 1. "intensified on
ELSE.
w_tab-color-int = 0. "intensified off
ENDIF.
APPEND w_tab TO t_color.

ENDLOOP.
ENDFORM. " colour_cells

The previous post deals with finding user exits for a given sap transaction code.

Find user exits for a sap trasaction code

Unable to identify user exits for a given transaction code.

install the following ABAP in you dev environnement (local, do not need package).

This program looks for any user-exit (type SMOD) avalaible for any transaction code.


Report Z_CHECK_USEREXIT.

tables : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.

tables : tstct.

data : jtab like tadir occurs 0 with header line.

data : field1(30).

data : v_devclass like tadir-devclass.

parameters : p_tcode like tstc-tcode obligatory.

select single * from tstc where tcode eq p_tcode.

if sy-subrc eq 0.

select single * from tadir where pgmid = 'R3TR'

and object = 'PROG'

and obj_name = tstc-pgmna.

move : tadir-devclass to v_devclass.

if sy-subrc ne 0.

select single * from trdir where name = tstc-pgmna.

if trdir-subc eq 'F'.

select single * from tfdir where pname = tstc-pgmna.

select single * from enlfdir where funcname =

tfdir-funcname.

select single * from tadir where pgmid = 'R3TR'

and object = 'FUGR'

and obj_name eq enlfdir-area.

move : tadir-devclass to v_devclass.

endif.

endif.

select * from tadir into table jtab

where pgmid = 'R3TR'

and object = 'SMOD'

and devclass = v_devclass.

select single * from tstct where sprsl eq sy-langu and

tcode eq p_tcode.

format color col_positive intensified off.

write:/(19) 'Transaction Code - ',

20(20) p_tcode,

45(50) tstct-ttext.

skip.

if not jtab[] is initial.

write:/(95) sy-uline.

format color col_heading intensified on.

write:/1 sy-vline,

2 'Exit Name',

21 sy-vline ,

22 'Description',

95 sy-vline.

write:/(95) sy-uline.

loop at jtab.

select single * from modsapt

where sprsl = sy-langu and

name = jtab-obj_name.

format color col_normal intensified off.

write:/1 sy-vline,

2 jtab-obj_name hotspot on,

21 sy-vline ,

22 modsapt-modtext,

95 sy-vline.

endloop.

write:/(95) sy-uline.

describe table jtab.

skip.

format color col_total intensified on.

write:/ 'No of Exits:' , sy-tfill.

else.

format color col_negative intensified on.

write:/(95) 'No User Exit exists'.

endif.

else.

format color col_negative intensified on.

write:/(95) 'Transaction Code Does Not Exist'.

endif.

at line-selection.

get cursor field field1.

check field1(4) eq 'JTAB'.

set parameter id 'MON' field sy-lisel+1(10).

call transaction 'SMOD' and skip first screen.

Hope it will help.

The previous post of this blog deals with ACCESSING DATA FROM APPLICAITON SERVER AS A E MAIL SAMPLE CODE.

To Do Next: Thank you for visiting ABAP REPORTS . If you liked the post, please subscribe to its RSS FEED or Get the information directly into your email box by EMAIL SUBSCRIPTION.


Privacy policy

This website/blog uses third-party advertising companies to serve ads when visiting this site. These third parties may collect and use information (but not your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, you can visit Google's Advertising and Privacy page.

If you wish to opt out of Advertising companies tracking and tailoring advertisements to your surfing patterns you may do so at Network Advertising Initiative.

Google uses the Doubleclick DART cookie to serve ads across it's Adsense network and you can get further information regarding the DART cookie at Doubleclick as well as opt out options at Google's Privacy Center.

Privacy:
I respect your privacy and I am committed to safeguarding your privacy while online at this site www.physicspractice.com. The following discloses how I gather and disseminate information for this Blog.

RSS Feeds and Email Updates

If a user wishes to subscribe to my RSS Feeds or Email Updates (powered by Feedburner), I ask for contact information such as name and email address. Users may opt-out of these communications at any time. Your personal information will never be sold or given to a third party. (You will never be spammed by me - ever)

Log Files and Stats

Like most blogging platforms I use log files, in this case Statcounter. This stores information such as internet protocol (IP) addresses, browser type, internet service provider (ISP), referring, exit and visited pages, platform used, date/time stamp, track user’s movement in the whole, and gather broad demographic information for aggregate use. IP addresses etc. are not linked to personally identifiable information.

Cookies

A cookie is a piece of data stored on the user’s computer tied to information about the user. This blog doesn't use cookies. However, some of my business partners use cookies on this site (for example - advertisers). I can't access or control these cookies once the advertisers have set them.

Links

This Blog contains links to other sites. Please be aware that I am not responsible for the privacy practices of these other sites. I suggest my users to be aware of this when they leave this blog and to read the privacy statements of each and every site that collects personally identifiable information. This privacy statement applies solely to information collected by this Blog.

Advertisers

I use outside ad companies to display ads on this blog. These ads may contain cookies and are collected by the advertising companies and I do not have access to this information. I work with Google Adsense. Please check the advertisers websites for respective privacy policies.

Contact Information

If you have any questions or concerns please contact d_vsuesh[at the rate of]yahoo[dot]co[dot]in.


@ 2007 Abapreports - The articles are copyrighted to D V Suresh and can only be reproduced given the author's permission.


All product names are trademarks of their respective companies.Every effort is made to ensure content integrity. Use information on this site at your own risk. Information furnished in the blog is collected from various sites. This blog does not host any files on its server. Please report any broken links in comment.

The Blog http://abapreports.blogspot.com no way affiliated with SAP AG.

ABAP Sample code for Data file from applicaion server as a mail

* This program will allow you to send email with attachment.
  • First, specify the attachment file from your local hardisk and execute.
  • Next, specify the sender email address and click the send button.
report z_mail.

data method1 like sy-ucomm.
data g_user like soudnamei1.
data g_user_data like soudatai1.
data g_owner like soud-usrnam.
data g_receipients like soos1 occurs 0 with header line.
data g_document like sood4 .
data g_header like sood2.
data g_folmam like sofm2.
data g_objcnt like soli occurs 0 with header line.
data g_objhead like soli occurs 0 with header line.
data g_objpara like selc occurs 0 with header line.
data g_objparb like soop1 occurs 0 with header line.
data g_attachments like sood5 occurs 0 with header line.
data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.
data g_ref_document like sood4.
data g_new_parent like soodk.
data: begin of g_files occurs 10 ,
text(4096) type c,
end of g_files.

data : fold_number(12) type c,
fold_yr(2) type c,
fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.
  • Can me any file fromyour pc ....either xls or word or ppt etc ...
g_user-sapname = sy-uname.
call function 'SO_USER_READ_API1'
exporting
user = g_user
  • PREPARE_FOR_FOLDER_ACCESS = ' '
importing
user_data = g_user_data
  • EXCEPTIONS
  • USER_NOT_EXIST = 1
  • PARAMETER_ERROR = 2
  • X_ERROR = 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.

fold_type = g_user_data-outboxfol+0(3).
fold_yr = g_user_data-outboxfol+3(2).
fold_number = g_user_data-outboxfol+5(12).
clear g_files.

refresh : g_objcnt,
g_objhead,
g_objpara,
g_objparb,
g_receipients,
g_attachments,
g_references,
g_files.

method1 = 'SAVE'.
g_document-foltp = fold_type.
g_document-folyr = fold_yr.
g_document-folno = fold_number.
g_document-objtp = g_user_data-object_typ.
*g_document-OBJYR = '27'.
*g_document-OBJNO = '000000002365'.
*g_document-OBJNAM = 'MESSAGE'.
g_document-objdes = 'sap-img.com testing by program'.
g_document-folrg = 'O'.
*g_document-okcode = 'CHNG'.
g_document-objlen = '0'.
g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.
g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = sy-uname
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header
  • FOLMEM_DATA =
  • RECEIVE_DATA =
.

  • File from the pc to send...
method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.
append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = g_owner
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header
.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.
g_receipients-recesc = 'B'.
g_receipients-sndex = 'X'.
append g_receipients.
call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
exporting
method = method1
office_user = g_owner
ref_document = g_ref_document
new_parent = g_new_parent
importing
authority = g_authority
tables
objcont = g_objcnt
objhead = g_objhead
objpara = g_objpara
objparb = g_objparb
recipients = g_receipients
attachments = g_attachments
references = g_references
files = g_files
changing
document = g_document
header_data = g_header.

Learn SAP ABAP SYNTAX HERE COMPLETELY.