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

ABAP - Transform DIR Content Into Binary Table.


With this tutorial you'll learn how to transform a DIR content into binary Table so it can be used for download in background or send by mail .

Hope it's will be helpfull.

*** Data Definition
DATA : v_cout TYPE dms_checkout_def,
v_dttrg TYPE dttrg, "Name of data carrier
v_docfile TYPE dms_doc_file,
v_dappl TYPE dappl, "Application
v_tabix TYPE i ,
v_tdwa TYPE tdwa ,
v_phio TYPE dms_phio,
v_frontend TYPE dms_frontend_data,
v_exception TYPE REF TO cx_root.
*
**
*** Internal Table Definition
DATA : t_drao TYPE STANDARD TABLE OF drao,
t_kpro TYPE dms_tbl_file ,
t_hexa TYPE solix_tab.
**
*** Constants
CONSTANTS : c_hostname TYPE ntadr VALUE 'DEFAULT', "Hostname
c_type TYPE typdt VALUE 'PC', "Type
c_system TYPE char4 VALUE 'WN32'. "System
**
*** field-symblos
FIELD-SYMBOLS : TYPE LINE OF dms_tbl_file,
TYPE LINE OF dms_tbl_phio .


CLEAR : v_tdwa .
v_frontend-frontend_type = c_type. "'PC'.
v_frontend-hostname = c_hostname. "'DEFAULT'.
v_frontend-winsys = c_system. "'WN32'.
v_frontend-platform = 0.
v_cout-comp_get = abap_true.
v_cout-batchmode = abap_true.
v_cout-content_provide = 'TBL'.

* Check if for FID Type KPRO is used
CALL FUNCTION 'CV200_DB_TDWA_SELECT'
EXPORTING
pf_dokar = fid-dokar
IMPORTING
psx_tdwa = v_tdwa
EXCEPTIONS
not_found = 1.

check sy-subrc eq 0.

v_cout-kpro_use = v_tdwa-kpro_use.

CASE v_tdwa-kpro_use.
WHEN abap_true.
* Kpro is used
* retrieve FID Master Data
FREE t_kpro.
CALL FUNCTION 'CV120_KPRO_MASTER_DATA_GET'
EXPORTING
pf_dokar = fid-dokar
pf_doknr = fid-doknr
pf_dokvr = fid-dokvr
pf_doktl = fid-doktl
TABLES
ptx_data = t_kpro
EXCEPTIONS
not_found = 1
error = 2.
check sy-subrc eq 0.

v_frontend-frontend_type = 'KP'.

LOOP AT t_kpro ASSIGNING .
FREE t_drao.
LOOP AT -tbl_phios ASSIGNING .
MOVE-CORRESPONDING TO v_phio.

CALL FUNCTION 'CV120_DOC_CHECKOUT_VIEW'
EXPORTING
ps_cout_def = v_cout
ps_doc_file = v_docfile
ps_draw = fid
ps_phio = v_phio
ps_frontend = v_frontend
TABLES
ptx_content = t_drao
EXCEPTIONS
error = 1.
check sy-subrc eq 0.
perform transform_fid_to_binary table T_DRAO
T_HEXA.
ENDLOOP.
ENDLOOP.

WHEN abap_false.
DO 2 TIMES.
CLEAR : v_docfile .

FREE : t_drao.

v_tabix = sy-index.

v_docfile-fileno = v_tabix.

CASE v_tabix.
WHEN 1.
v_dappl = fid-dappl.
v_dttrg = fid-dttrg.
WHEN 2.
v_dappl = fid-dappl1.
v_dttrg = fid-dttrg1.
ENDCASE.

v_docfile-dappl = v_dappl.
v_docfile-dttrg = v_dttrg.

CALL FUNCTION 'CV120_DOC_CHECKOUT'
EXPORTING
ps_cout_def = v_cout
ps_draw = fid
ps_doc_file = v_docfile
TABLES
ptx_drao = t_drao
EXCEPTIONS
error = 1
OTHERS = 2.
check sy-subrc eq 0.
check sy-subrc eq 0.
perform transform_fid_to_binary tables T_DRAO
T_HEXA.
ENDDO.
ENDCASE.
Form transform_fid_to_binary tables DRAO type DRAO
binary_table type SOLIX.
*** Field-Symbols definition

FIELD-SYMBOLS : TYPE drao ,
TYPE x ,
TYPE x,
TYPE solix .

** Data Definition
DATA : v_filelong TYPE i ,
v_long TYPE i,
v_longdes TYPE i .

FREE binary_table.

CHECK drao[] IS NOT INITIAL.
* Conversion du document en binaire
LOOP AT drao ASSIGNING .
IF v_filelong IS INITIAL.
v_filelong = -orln.
ENDIF.
ASSIGN -orblk TO .
DESCRIBE FIELD LENGTH v_long IN BYTE MODE.
CLEAR v_longdes.

WHILE v_long GT 0.
ASSIGN +v_longdes(v_long) TO .
APPEND INITIAL LINE TO binary_table ASSIGNING .
ASSIGN -line TO .
DESCRIBE FIELD LENGTH v_longdes IN BYTE MODE.

MOVE TO .
v_filelong = v_filelong - v_longdes.
v_long = v_long - v_longdes.
CHECK v_filelong LE v_longdes.
IF v_long NE 0.
v_long = v_filelong.
ENDIF.
CHECK v_long LE 0.
v_long = 0.
ENDWHILE.
ENDLOOP.
Endform.


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.


No comments:

Post a Comment