Offline scenario to upload a filled-in adobe form using Web Dynpro for ABAP
For the tutorial, click here.
TYPE-POOLS: ixml.
DATA: w_pdf_source TYPE xstring,
w_dob TYPE char10.
* Get a reference to the form Processing class
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_pdf_source LIKE ls_context-pdf_source.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* get single attribute
lo_el_context->get_attribute(
EXPORTING
name = `PDF_SOURCE`
IMPORTING
value = lv_pdf_source ).
DATA: l_fp TYPE REF TO if_fp.
l_fp = cl_fp=>get_reference( ).
* Get reference to the Pdf Object Class
DATA:l_pdfobj TYPE REF TO if_fp_pdf_object.
TRY.
l_pdfobj = l_fp->create_pdf_object( ).
CATCH cx_fp_runtime_internal.
CATCH cx_fp_runtime_usage.
CATCH cx_fp_runtime_system.
ENDTRY.
* Set your Pdf In the Pdf object created
TRY .
l_pdfobj->set_document( pdfdata = lv_pdf_source ).
* Extract data from pdf object
l_pdfobj->set_extractdata( ).
CATCH cx_fp_runtime_usage.
ENDTRY.
TRY.
* Call Adobe Document Service
l_pdfobj->execute( ).
CATCH cx_fp_runtime_usage.
CATCH cx_fp_runtime_system.
CATCH cx_fp_runtime_internal.
ENDTRY.
* Get the pdf Data to a Xstring Variable
DATA: pdf_form_data TYPE xstring.
l_pdfobj->get_data( IMPORTING formdata = pdf_form_data ).
* Call method to convert xstring to string.
DATA: converter TYPE REF TO cl_abap_conv_in_ce,
formxml TYPE string.
converter = cl_abap_conv_in_ce=>create( input = pdf_form_data ).
converter->read( IMPORTING data = formxml ).
* Get the ixm type group Into Our prorgram
DATA: l_ixml TYPE REF TO if_ixml.
l_ixml = cl_ixml=>create( ).
* Get istream Object from Stream Factory
DATA: streamfactory TYPE REF TO if_ixml_stream_factory,
istream TYPE REF TO if_ixml_istream.
streamfactory = l_ixml->create_stream_factory( ).
istream = streamfactory->create_istream_string( formxml ).
* Get xml document Class to process XML
DATA: document TYPE REF TO if_ixml_document.
document = l_ixml->create_document( ).
* Get an Interface to Parse the XML
DATA: parser TYPE REF TO if_ixml_parser.
parser = l_ixml->create_parser( stream_factory = streamfactory
istream = istream
document = document ).
* Start parsing theDocument with parsing interface referenced.
parser->parse( ).
DATA: node TYPE REF TO if_ixml_node,
fs_emp TYPE zwd_per_info.
node = document->find_from_name('FNAME').
IF node IS NOT INITIAL.
fs_emp-fname = node->get_value( ).
ENDIF.
node = document->find_from_name('LNAME').
IF node IS NOT INITIAL.
fs_emp-lname = node->get_value( ).
ENDIF.
node = document->find_from_name('DOB').
IF node IS NOT INITIAL.
w_dob = node->get_value( ).
REPLACE ALL OCCURRENCES OF '-' IN w_dob WITH space.
CONDENSE w_dob.
move w_dob to fs_emp-dob.
ENDIF.
node = document->find_from_name('TEXP').
IF node IS NOT INITIAL.
fs_emp-texp = node->get_value( ).
ENDIF.
node = document->find_from_name('CEMPLOYER').
IF node IS NOT INITIAL.
fs_emp-cemployer = node->get_value( ).
ENDIF.
node = document->find_from_name('CSALARY').
IF node IS NOT INITIAL.
fs_emp-csalary = node->get_value( ).
ENDIF.
node = document->find_from_name('ESALARY').
IF node IS NOT INITIAL.
fs_emp-esalary = node->get_value( ).
ENDIF.
IF fs_emp IS NOT INITIAL.
fs_emp-waers = 'INR'.
INSERT into zwd_per_info VALUES fs_emp.
ENDIF.
|