REPORT ztest.
* Constant Declaration
CONSTANTS:
lc_separator TYPE char1 VALUE '~'. " Separator of type CHAR1
TYPES: BEGIN OF typ_outtab,
matnr TYPE matnr , "Material
matkl TYPE matkl , "Material Group
END OF typ_outtab,
BEGIN OF typ_content,
rundt TYPE datum,
phy_class TYPE sdok_class,
phy_objid TYPE sdok_docid,
file_name TYPE sdok_filnm,
END OF typ_content.
DATA :
lt_file_string TYPE sdokcntascs,
ls_file_string TYPE sdokcntasc, " SDOK: line of text document content for Web server
ls_outtab TYPE typ_outtab,
lw_fname TYPE lvc_fname , "Field name
lt_outtab TYPE STANDARD TABLE OF typ_outtab INITIAL SIZE 0.
*Local constant declarations
DATA: lc_soffloio TYPE sdok_class VALUE 'SOFFLOIO', " Document class
lc_soffphio TYPE sdok_class VALUE 'SOFFPHIO', " Document class
lc_logobject TYPE char10 VALUE 'LOGOBJECT'. " Logobject of type CHAR10
*Local data declarations
DATA: lw_lines TYPE int4, " Natural Number
ls_loio_object TYPE sdokobject, " SDOK: BOR key for information object
ls_phio_object TYPE sdokobject, " SDOK: BOR key for information object
lt_relations TYPE sdokrelists,
ls_relations TYPE sdokrelist, " SDOK: List of relationships for information object
ls_file_access TYPE sdokfilaci, " SDOK: Entries for document contents in internal tables
lt_context TYPE sdokproptys,
lt_asii TYPE sdokcntascs,
lt_binary TYPE sdokcntbins,
lt_file_access1 TYPE STANDARD TABLE OF sdokfilacs INITIAL SIZE 0, " SDOK: information for file access using Web server
ls_file_access1 TYPE sdokfilacs, " SDOK: information for file access using Web server
lt_file_access TYPE sdokfilacis,
ls_content TYPE typ_content.
SELECT matnr
matkl
FROM mara
INTO TABLE lt_outtab
UP TO 10 ROWS.
IF sy-subrc EQ 0.
* Create the logical placeholder
CALL FUNCTION 'SDOK_LOIO_CREATE'
EXPORTING
object_class = lc_soffloio " class
IMPORTING
object_id = ls_loio_object
EXCEPTIONS
missing_class = 1 " class
bad_class = 2 " class
missing_properties = 3
bad_properties = 4
not_authorized = 5
duplicate_object_id = 6
exception_in_exit = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF. " IF sy-subrc <> 0
ls_relations-re_class = lc_logobject. " class
ls_relations-prtn_id = ls_loio_object-objid.
ls_relations-prtn_class = lc_soffloio. " class
APPEND ls_relations TO lt_relations.
*Create the physical document place holder
CALL FUNCTION 'SDOK_PHIO_CREATE'
EXPORTING
object_class = lc_soffphio " class
IMPORTING
object_id = ls_phio_object "physical object ID
TABLES
to_relations = lt_relations
EXCEPTIONS
missing_class = 1 " class
bad_class = 2 " class
missing_properties = 3
bad_relations = 4
bad_properties = 5
not_authorized = 6
duplicate_object_id = 7
enqueue_failure = 8
exception_in_exit = 9
OTHERS = 10.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF. " IF sy-subrc <> 0
* Pass ALV Header
CONCATENATE 'Material' 'Material group' INTO ls_file_string-line SEPARATED BY cl_abap_char_utilities=>horizontal_tab..
APPEND ls_file_string TO lt_file_string.
CLEAR: ls_file_string-line.
LOOP AT lt_outtab INTO ls_outtab.
* Concatenate the fields values to store
CONCATENATE ls_outtab-matnr "Material
ls_outtab-matkl "Material description
INTO ls_file_string-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
APPEND ls_file_string TO lt_file_string.
CLEAR: ls_file_string-line.
ENDLOOP. " LOOP AT ut_outtab INTO ls_outtab
*Claculate the lines
lw_lines = lines( lt_file_string ).
CONCATENATE 'Material Data' '_' sy-datum sy-uzeit '.' 'txt' INTO ls_file_access-file_name.
ls_file_access-first_line = 1.
ls_file_access-last_line = lw_lines.
APPEND ls_file_access TO lt_file_access.
*Store the document in the content server
CALL FUNCTION 'SDOK_PHIO_STORE_CONTENT'
EXPORTING
object_id = ls_phio_object
TABLES
file_access_info = lt_file_access
file_content_ascii = lt_file_string
EXCEPTIONS
not_existing = 1
not_allowed = 2
not_authorized = 3
no_content = 4
bad_storage_type = 5
OTHERS = 6.
IF sy-subrc EQ 0.
*Get the file URLs
REFRESH lt_file_access1[].
CALL FUNCTION 'SDOK_GET_PHIO_ACCESS'
EXPORTING
loio_object_id = ls_loio_object
content_or_url_only = abap_true
TABLES
file_access_info = lt_file_access1
context = lt_context
file_content_ascii = lt_asii
file_content_binary = lt_binary
EXCEPTIONS
not_existing = 1
no_physical_object = 2
not_authorized = 3
no_content = 4
bad_storage_type = 5
context_incomplete = 6
no_codepage_info = 7
bad_parameter = 8
OTHERS = 9.
IF sy-subrc EQ 0.
ls_content-rundt = sy-datum.
ls_content-phy_class = ls_phio_object-class. " class
ls_content-phy_objid = ls_phio_object-objid.
ls_content-file_name = ls_file_access-file_name.
ENDIF. " IF sy-subrc EQ 0
write:/ 'Writing Data to Content Server'.
WRITE:/ ls_content-rundt , ls_content-file_name.
ENDIF. " IF sy-subrc EQ 0
write:/ .
write: / 'Reading Data from Content Server'.
* Get the data based on the file path from content server
CLEAR : lt_file_string[],lt_file_access[].
CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
EXPORTING
object_id = ls_phio_object
TABLES
file_access_info = lt_file_access
file_content_ascii = lt_file_string
EXCEPTIONS
not_existing = 1
not_authorized = 2
no_content = 3
bad_storage_type = 4
OTHERS = 5.
write:/, 1(18)'Material' , 'Material Group'.
LOOP AT lt_file_string INTO ls_file_string.
IF sy-tabix GT 1.
SPLIT ls_file_string
AT cl_abap_char_utilities=>horizontal_tab
INTO ls_outtab-matnr "Material
ls_outtab-matkl. "Material group
WRITE:/ ls_outtab-matnr , ls_outtab-matkl.
CLEAR ls_outtab.
ENDIF.
ENDLOOP.
ELSE.
WRITE:/ 'No data found'.
ENDIF.
Output:
* Constant Declaration
CONSTANTS:
lc_separator TYPE char1 VALUE '~'. " Separator of type CHAR1
TYPES: BEGIN OF typ_outtab,
matnr TYPE matnr , "Material
matkl TYPE matkl , "Material Group
END OF typ_outtab,
BEGIN OF typ_content,
rundt TYPE datum,
phy_class TYPE sdok_class,
phy_objid TYPE sdok_docid,
file_name TYPE sdok_filnm,
END OF typ_content.
DATA :
lt_file_string TYPE sdokcntascs,
ls_file_string TYPE sdokcntasc, " SDOK: line of text document content for Web server
ls_outtab TYPE typ_outtab,
lw_fname TYPE lvc_fname , "Field name
lt_outtab TYPE STANDARD TABLE OF typ_outtab INITIAL SIZE 0.
*Local constant declarations
DATA: lc_soffloio TYPE sdok_class VALUE 'SOFFLOIO', " Document class
lc_soffphio TYPE sdok_class VALUE 'SOFFPHIO', " Document class
lc_logobject TYPE char10 VALUE 'LOGOBJECT'. " Logobject of type CHAR10
*Local data declarations
DATA: lw_lines TYPE int4, " Natural Number
ls_loio_object TYPE sdokobject, " SDOK: BOR key for information object
ls_phio_object TYPE sdokobject, " SDOK: BOR key for information object
lt_relations TYPE sdokrelists,
ls_relations TYPE sdokrelist, " SDOK: List of relationships for information object
ls_file_access TYPE sdokfilaci, " SDOK: Entries for document contents in internal tables
lt_context TYPE sdokproptys,
lt_asii TYPE sdokcntascs,
lt_binary TYPE sdokcntbins,
lt_file_access1 TYPE STANDARD TABLE OF sdokfilacs INITIAL SIZE 0, " SDOK: information for file access using Web server
ls_file_access1 TYPE sdokfilacs, " SDOK: information for file access using Web server
lt_file_access TYPE sdokfilacis,
ls_content TYPE typ_content.
SELECT matnr
matkl
FROM mara
INTO TABLE lt_outtab
UP TO 10 ROWS.
IF sy-subrc EQ 0.
* Create the logical placeholder
CALL FUNCTION 'SDOK_LOIO_CREATE'
EXPORTING
object_class = lc_soffloio " class
IMPORTING
object_id = ls_loio_object
EXCEPTIONS
missing_class = 1 " class
bad_class = 2 " class
missing_properties = 3
bad_properties = 4
not_authorized = 5
duplicate_object_id = 6
exception_in_exit = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF. " IF sy-subrc <> 0
ls_relations-re_class = lc_logobject. " class
ls_relations-prtn_id = ls_loio_object-objid.
ls_relations-prtn_class = lc_soffloio. " class
APPEND ls_relations TO lt_relations.
*Create the physical document place holder
CALL FUNCTION 'SDOK_PHIO_CREATE'
EXPORTING
object_class = lc_soffphio " class
IMPORTING
object_id = ls_phio_object "physical object ID
TABLES
to_relations = lt_relations
EXCEPTIONS
missing_class = 1 " class
bad_class = 2 " class
missing_properties = 3
bad_relations = 4
bad_properties = 5
not_authorized = 6
duplicate_object_id = 7
enqueue_failure = 8
exception_in_exit = 9
OTHERS = 10.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF. " IF sy-subrc <> 0
* Pass ALV Header
CONCATENATE 'Material' 'Material group' INTO ls_file_string-line SEPARATED BY cl_abap_char_utilities=>horizontal_tab..
APPEND ls_file_string TO lt_file_string.
CLEAR: ls_file_string-line.
LOOP AT lt_outtab INTO ls_outtab.
* Concatenate the fields values to store
CONCATENATE ls_outtab-matnr "Material
ls_outtab-matkl "Material description
INTO ls_file_string-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
APPEND ls_file_string TO lt_file_string.
CLEAR: ls_file_string-line.
ENDLOOP. " LOOP AT ut_outtab INTO ls_outtab
*Claculate the lines
lw_lines = lines( lt_file_string ).
CONCATENATE 'Material Data' '_' sy-datum sy-uzeit '.' 'txt' INTO ls_file_access-file_name.
ls_file_access-first_line = 1.
ls_file_access-last_line = lw_lines.
APPEND ls_file_access TO lt_file_access.
*Store the document in the content server
CALL FUNCTION 'SDOK_PHIO_STORE_CONTENT'
EXPORTING
object_id = ls_phio_object
TABLES
file_access_info = lt_file_access
file_content_ascii = lt_file_string
EXCEPTIONS
not_existing = 1
not_allowed = 2
not_authorized = 3
no_content = 4
bad_storage_type = 5
OTHERS = 6.
IF sy-subrc EQ 0.
*Get the file URLs
REFRESH lt_file_access1[].
CALL FUNCTION 'SDOK_GET_PHIO_ACCESS'
EXPORTING
loio_object_id = ls_loio_object
content_or_url_only = abap_true
TABLES
file_access_info = lt_file_access1
context = lt_context
file_content_ascii = lt_asii
file_content_binary = lt_binary
EXCEPTIONS
not_existing = 1
no_physical_object = 2
not_authorized = 3
no_content = 4
bad_storage_type = 5
context_incomplete = 6
no_codepage_info = 7
bad_parameter = 8
OTHERS = 9.
IF sy-subrc EQ 0.
ls_content-rundt = sy-datum.
ls_content-phy_class = ls_phio_object-class. " class
ls_content-phy_objid = ls_phio_object-objid.
ls_content-file_name = ls_file_access-file_name.
ENDIF. " IF sy-subrc EQ 0
write:/ 'Writing Data to Content Server'.
WRITE:/ ls_content-rundt , ls_content-file_name.
ENDIF. " IF sy-subrc EQ 0
write:/ .
write: / 'Reading Data from Content Server'.
* Get the data based on the file path from content server
CLEAR : lt_file_string[],lt_file_access[].
CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
EXPORTING
object_id = ls_phio_object
TABLES
file_access_info = lt_file_access
file_content_ascii = lt_file_string
EXCEPTIONS
not_existing = 1
not_authorized = 2
no_content = 3
bad_storage_type = 4
OTHERS = 5.
write:/, 1(18)'Material' , 'Material Group'.
LOOP AT lt_file_string INTO ls_file_string.
IF sy-tabix GT 1.
SPLIT ls_file_string
AT cl_abap_char_utilities=>horizontal_tab
INTO ls_outtab-matnr "Material
ls_outtab-matkl. "Material group
WRITE:/ ls_outtab-matnr , ls_outtab-matkl.
CLEAR ls_outtab.
ENDIF.
ENDLOOP.
ELSE.
WRITE:/ 'No data found'.
ENDIF.
Output: