FUNCTION ZSY_FM_PRE_UPLOAD_IMAGE.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IV_PERNR) TYPE PERNR_D
*" REFERENCE(IV_OBJECT) TYPE STRING DEFAULT 'GRAPHICS'
*" REFERENCE(IV_NAME) TYPE STRING
*" REFERENCE(IV_ID) TYPE THEAD-TDID DEFAULT 'BMAP'
*" REFERENCE(IV_BTYPE) TYPE STRING DEFAULT 'BCOL'
*" REFERENCE(IV_BDS_DESCRIPTION) TYPE BAPISIGNAT-PROP_VALUE
*" EXPORTING
*" REFERENCE(ES_RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2
*"----------------------------------------------------------------------

data:lv_bmcomp type stxbitmaps-bmcomp,
lv_resident TYPE stxbitmaps-resident,
lv_autoheight TYPE stxbitmaps-autoheight,
lv_format TYPE char128,
lv_resolution TYPE stxbitmaps-resolution.

data:lv_pre_pernr_image_xstring TYPE xstring.
DATA OUTPUT_LENGTH TYPE I.

"parameter for bds
data: l_object_key type sbdst_object_key.
data: l_tab type ddobjname.
data: begin of l_bitmap occurs 0,
l(64) type x,
end of l_bitmap.
data: l_filename type string,
l_bytecount type i,
l_bds_bytecount type i.
data: l_color(1) type c,
l_width_tw type stxbitmaps-widthtw,
l_height_tw type stxbitmaps-heighttw,
l_width_pix type stxbitmaps-widthpix,
l_height_pix type stxbitmaps-heightpix.
data: l_bds_object type ref to cl_bds_document_set,
l_bds_content type sbdst_content,
l_bds_components type sbdst_components,
wa_bds_components type line of sbdst_components,
l_bds_signature type sbdst_signature,
wa_bds_signature type line of sbdst_signature,
l_bds_properties type sbdst_properties,
wa_bds_properties type line of sbdst_properties.
data wa_stxbitmaps type stxbitmaps.
data l_vscan_profile type vscan_profile.

data: lv_docid TYPE stxbitmaps-docid.

* DATA:i_igs_image_converter TYPE REF TO cl_igs_image_converter,
* mime TYPE w3mimetabtype,
* html TYPE w3htmltabtype,
* html_line TYPE w3html,
* l_msg_text(72) TYPE c,
* l_url TYPE w3url,
* l_content_length TYPE i,
* l_content_type TYPE w3param-cont_type,
* l_content_subtype TYPE w3param-cont_type.

SELECT SINGLE VALUE
INTO lv_pre_pernr_image_xstring
FROM ZSY_D_PRE_FILE
WHERE PERNR EQ IV_PERNR
AND IS_ICON EQ 'X'.
IF SY-SUBRC NE 0.
ES_RETURN-type = 'E'.
ES_RETURN-message = TEXT-E14.
return.
ENDIF.

* Enqueue
perform enqueue_graphic using IV_OBJECT
IV_NAME
IV_ID
IV_BTYPE.


CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_pre_pernr_image_xstring
* APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH = OUTPUT_LENGTH
TABLES
binary_tab = l_bitmap
.
l_color = 'X'.
lv_format = 'BMP'.
L_BYTECOUNT = OUTPUT_LENGTH.
lv_bmcomp = 'X'.
* Bitmap conversion
call function 'SAPSCRIPT_CONVERT_BITMAP_BDS'
exporting
color = l_color
format = lv_format
resident = lv_resident
bitmap_bytecount = l_bytecount
compress_bitmap = lv_bmcomp
importing
width_tw = l_width_tw
height_tw = l_height_tw
width_pix = l_width_pix
height_pix = l_height_pix
dpi = lv_resolution
bds_bytecount = l_bds_bytecount
tables
bitmap_file = l_bitmap
bitmap_file_bds = l_bds_content
exceptions
format_not_supported = 1
no_bmp_file = 2
bmperr_invalid_format = 3
bmperr_no_colortable = 4
bmperr_unsup_compression = 5
bmperr_corrupt_rle_data = 6
others = 7.


* Save bitmap in BDS
create object l_bds_object.

wa_bds_components-doc_count = '1'.
wa_bds_components-comp_count = '1'.
wa_bds_components-mimetype = c_bds_mimetype.
wa_bds_components-comp_size = l_bds_bytecount.
append wa_bds_components to l_bds_components.

if lv_docid is initial. " graphic is new

wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.

if l_vscan_profile is initial.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
else.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
vscan_profile = l_vscan_profile
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
endif.
if sy-subrc <> 0.
perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
"message e285 with p_name 'BDS'.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
lv_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
"message e285 with p_name 'BDS'.
endif.

else. " graphic already exists
********* read object_key for faster access *****
clear l_object_key.
select single * from stxbitmaps into wa_stxbitmaps
where tdobject = iv_object
and tdid = iv_id
and tdname = iv_name
and tdbtype = iv_btype.
select single tabname from bds_locl into l_tab
where classname = c_bds_classname
and classtype = c_bds_classtype.
if sy-subrc = 0.
select single object_key from (l_tab) into l_object_key
where loio_id = wa_stxbitmaps-docid+10(32)
and classname = c_bds_classname
and classtype = c_bds_classtype.
endif.
******** read object_key end ********************
if l_vscan_profile is initial.
call method l_bds_object->update_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = lv_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
components = l_bds_components
content = l_bds_content
exceptions
nothing_found = 1
others = 2.
else.
call method l_bds_object->update_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = lv_docid
doc_ver_no = '1'
doc_var_id = '1'
vscan_profile = l_vscan_profile
changing
components = l_bds_components
content = l_bds_content
exceptions
nothing_found = 1
others = 2.
endif.
if sy-subrc = 1. " inconsistency STXBITMAPS - BDS; repeat check in
wa_bds_signature-doc_count = '1'.
append wa_bds_signature to l_bds_signature.

if l_vscan_profile is initial.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
else.
call method l_bds_object->create_with_table
exporting
classname = c_bds_classname
classtype = c_bds_classtype
components = l_bds_components
content = l_bds_content
vscan_profile = l_vscan_profile
changing
signature = l_bds_signature
object_key = l_object_key
exceptions
others = 1.
endif.
if sy-subrc <> 0.
perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
"message e285 with p_name 'BDS'.
endif.
read table l_bds_signature index 1 into wa_bds_signature
transporting doc_id.
if sy-subrc = 0.
lv_docid = wa_bds_signature-doc_id.
else.
perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
"message e285 with p_name 'BDS'.
endif.

elseif sy-subrc = 2.
perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
"message e285 with p_name 'BDS'.
endif.

endif.

* Save bitmap header in STXBITPMAPS
wa_stxbitmaps-tdname = iv_name.
wa_stxbitmaps-tdobject = iv_object.
wa_stxbitmaps-tdid = iv_id.
wa_stxbitmaps-tdbtype = iv_btype.
wa_stxbitmaps-docid = lv_docid.
wa_stxbitmaps-widthpix = l_width_pix.
wa_stxbitmaps-heightpix = l_height_pix.
wa_stxbitmaps-widthtw = l_width_tw.
wa_stxbitmaps-heighttw = l_height_tw.
wa_stxbitmaps-resolution = lv_resolution.
wa_stxbitmaps-resident = lv_resident.
wa_stxbitmaps-autoheight = lv_autoheight.
wa_stxbitmaps-bmcomp = lv_bmcomp.
insert into stxbitmaps values wa_stxbitmaps.
if sy-subrc <> 0.
update stxbitmaps from wa_stxbitmaps.
if sy-subrc <> 0.
"message e285 with p_name 'STXBITMAPS'.
endif.
endif.

* Set description in BDS attributes
wa_bds_properties-prop_name = 'DESCRIPTION'.
wa_bds_properties-prop_value = IV_BDS_DESCRIPTION.
append wa_bds_properties to l_bds_properties.

call method l_bds_object->change_properties
exporting
classname = c_bds_classname
classtype = c_bds_classtype
object_key = l_object_key
doc_id = lv_docid
doc_ver_no = '1'
doc_var_id = '1'
changing
properties = l_bds_properties
exceptions
others = 1.

perform dequeue_graphic using iv_object
iv_name
iv_id
iv_btype.
ENDFUNCTION.

FUNCTION-POOL ZSY_FG_HR_COMMON.             "MESSAGE-ID ..

* INCLUDE LZSY_FG_HR_COMMOND... " Local class definition

DATA:BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE."用来存储屏幕字段参数值,传递录屏参数
* messages of call transaction
DATA:MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE."记录执行BDC过程中产生的消息
DATA:CTUMODE TYPE CHAR1 VALUE 'E'.

DATA:
G_IDENTIFIER(10) TYPE N,
G_LOGNUMBER TYPE BALHDR-LOGNUMBER.


tables: rstxu, rsscg, " Screen fields
itcth, rlgrap, stxh,
pstxt. " SPA/GPA
tables: ttxob, ttxid, ttxgr. "#EC NEEDED
tables: stxbitmaps. "BDS bitmaps

type-pools: shlp, " for Help functions
sbdst. " for BDS functions

*************************************************************
* SAPscript bitmap utility functions
*************************************************************
types:
ty_boolean(1) type c.

constants:
c_true type ty_boolean value 'X',
c_false type ty_boolean value space.
constants:
c_otf_rd_otfbitma(16) value '4F54466269746D61',
c_otf_rd_ff type x value 'FF',
c_otf_rd_formatid_bmon type x value '01',
c_otf_rd_formatid_bcol type x value '02',
c_otf_rd_subformatid_none type x value '00',
c_otf_rd_subformatid_bds type x value '01',
c_otf_rd_formatpar1_nonresi type x value '00',
c_otf_rd_formatpar1_resi type x value '01',
c_otf_rd_formatpar1_hi_nocomp type x value '00',
c_otf_rd_formatpar1_hi_runl type x value '10',
c_otf_rd_formatpar2_none type x value '00',
c_otf_rd_imageid_len type i value 90,
c_bm_format_itf(3) type c value 'ITF',
c_bm_format_bmp(3) type c value 'BMP',
c_bm_format_bds(3) type c value 'BDS',
c_itf_tline_len type i value 132,
c_itf_format_cmd(2) type c value '/:',
c_itf_format_cmnt(2) type c value '/*',
c_itf_format_datl(2) type c value '/=',
c_itf_hex_hex(3) type c value 'HEX',
c_itf_hex_endhex(6) type c value 'ENDHEX',
c_itf_hex_height(6) type c value 'HEIGHT',
c_itf_hex_cm(2) type c value 'CM',
c_itf_hex_mm(2) type c value 'MM',
c_itf_hex_point(2) type c value 'PT',
c_itf_hex_twip(2) type c value 'TW',
c_itf_hex_type(4) type c value 'TYPE',
c_itf_hex_bmon(4) type c value 'BMON',
c_itf_hex_bcol(4) type c value 'BCOL',
c_itf_hex_resi(4) type c value 'RESI',
c_bmp_compr_rgb type i value 0,
c_bmp_compr_rle8 type i value 1,
c_bmp_compr_rle4 type i value 2,
c_bmp_compr_bitfields type i value 3.
data: begin of otf_bminfo,
bmtype(4) type c,
new_rd_format type ty_boolean,
is_monochrome type ty_boolean,
is_resident type ty_boolean,
w_tw type i,
h_tw type i,
w_pix type i,
h_pix type i,
dpi type i,
bitsperpix type i,
coltabsize type i,
numdatabytes type i,
autoheight type ty_boolean,
res_h_tw type i,
bytes_per_row type i,
bytes_per_row_act type i,
bytes_per_row_fullcolor type i,
is_compressed type ty_boolean,
end of otf_bminfo.
constants:
c_bm_file_linelen type i value 80.
data: bm_file_lineofs type i.
data: begin of bm_file occurs 0,
l(80) type x,
end of bm_file.
constants:
c_bm_file_tmp_linelen type i value 80.
data: bm_file_tmp_lineofs type i.
data: begin of bm_file_tmp occurs 0,
l(80) type x,
end of bm_file_tmp.
constants: c_bm_file8bit_linelen type i value 80.
data: bm_file8bit_lineofs type i.
data: begin of bm_file8bit occurs 0,
l(80) type x,
end of bm_file8bit.
data: bitmap_file_lineofs type i,
bitmap_file_linewidth type i,
bitmap_file_bytecount type i.
* BMP color table
DATA: BEGIN OF BMP_COLOR_TAB OCCURS 256,
R TYPE x,
G TYPE x,
B TYPE x,
END OF BMP_COLOR_TAB.
* TIFF: global format info
DATA: BEGIN OF TIF_INFO,
BYTEORDER(1) TYPE C,
VERSION TYPE I,
FIRSTIFDOFS TYPE I,
WIDTH TYPE I,
LENGTH TYPE I,
BITSPERSAMPLE_1 TYPE I,
BITSPERSAMPLE_2 TYPE I,
BITSPERSAMPLE_3 TYPE I,
BITSPERSAMPLEPLANES TYPE I,
COMPRESSION TYPE I,
PHOTOMETRIC TYPE I,
FILLORDER TYPE I,
NUMBER_STRIPS TYPE I,
SAMPLESPERPIX TYPE I,
ROWSPERSTRIP TYPE I,
MINSAMPLE TYPE I,
MAXSAMPLE TYPE I,
XRES_N TYPE I,
XRES_D TYPE I,
YRES_N TYPE I,
YRES_D TYPE I,
RESUNIT TYPE I,
COLORMAP_SIZE TYPE I,
MAXROW TYPE I,
MAXCOL TYPE I,
DPI TYPE I,
TIFTYPE TYPE C,
WIDTH_ORI TYPE I,
LENGTH_ORI TYPE I,
DPI_ORI TYPE I,
END OF TIF_INFO.
* TIFF: list of strip offset pointers to image data
DATA: BEGIN OF TIF_STRIPOFS_TAB OCCURS 20,
OFS TYPE I,
COUNT TYPE I,
END OF TIF_STRIPOFS_TAB.
* TIFF: list of color table entries
DATA: BEGIN OF TIF_COLOR_TAB OCCURS 256,
R TYPE I,
G TYPE I,
B TYPE I,
END OF TIF_COLOR_TAB.
* TIFF constants
CONSTANTS:
C_BYTEORD_INTEL VALUE 'I',
C_BYTEORD_MOTO VALUE 'M',
C_DTYPE_BYTE TYPE I VALUE 1,
C_DTYPE_ASCII TYPE I VALUE 2,
C_DTYPE_SHORT TYPE I VALUE 3,
C_DTYPE_LONG TYPE I VALUE 4,
C_DTYPE_RATIONAL TYPE I VALUE 5,
C_TIFTYPE_NONE VALUE ' ',
C_TIFTYPE_BILEVEL VALUE 'B',
C_TIFTYPE_GRAYSCALE VALUE 'G',
C_TIFTYPE_COLORMAP VALUE 'C',
C_TIFTYPE_FULLCOLOR VALUE 'F',
C_XCONST_80 TYPE X VALUE '80',
C_XCONST_40 TYPE X VALUE '40',
C_XCONST_20 TYPE X VALUE '20',
C_XCONST_10 TYPE X VALUE '10',
C_XCONST_08 TYPE X VALUE '08',
C_XCONST_04 TYPE X VALUE '04',
C_XCONST_02 TYPE X VALUE '02',
C_XCONST_01 TYPE X VALUE '01',
C_COMP_UNCOMP TYPE I VALUE 1,
C_COMP_HUFFMAN TYPE I VALUE 2,
C_COMP_PACKBITS TYPE I VALUE 32773.

*************************************************************
* BDS bitmap storage
*************************************************************
* BDS bitmaps: buffer that holds info on resident bitmaps
data begin of bitmap_buffer_bds occurs 10.
include structure stxbitmaps.
data: act_w_tw like stxbitmaps-widthtw,
act_h_tw like stxbitmaps-heighttw,
act_dpi like stxbitmaps-resolution.
data end of bitmap_buffer_bds.
data: bdstab_lineofs type i,
bdstab_linewidth type i,
bdstab_bytecount type i.

* BDS handling
constants:
c_bds_classname type sbdst_classname value 'DEVC_STXD_BITMAP',
c_bds_classtype type sbdst_classtype value 'OT', " others
c_bds_mimetype type bds_mimetp value 'application/octet-stream',
c_bds_original type sbdst_doc_var_tg value 'OR'.

* generating command lines
data:
c_cmd_position_window like tline value '/:POSITION WINDOW',
c_cmd_position_page like tline value '/:POSITION PAGE',
c_cmd_position_xy like tline
value '/:POSITION XORIGIN ''&1'' &2 YORIGIN ''&3'' &4',
c_cmd_size_window like tline value '/:SIZE WINDOW',
c_cmd_size_page like tline value '/:SIZE PAGE',
c_cmd_size_dx like tline value '/:SIZE WIDTH ''&1'' &2',
c_cmd_size_dy like tline value '/:SIZE HEIGHT ''&1'' &2',
c_cmd_size_dxdy like tline
value '/:SIZE WIDTH ''&1'' &2 HEIGHT ''&3'' &4',
c_cmd_width like tline value 'WIDTH ''&1'' &2',
c_cmd_height like tline value 'HEIGHT ''&1'' &2',
c_cmd_box like tline value '/:BOX',
c_cmd_box_frame like tline value 'FRAME ''&1'' &2',
c_cmd_box_intensity like tline value 'INTENSITY &1',
c_cmd_box_x like tline value 'XPOS ''&1'' &2',
c_cmd_box_y like tline value 'YPOS ''&1'' &2',
c_cmd_box_xy like tline
value 'XPOS ''&1'' &2 YPOS ''&3'' &4'.
data: l_commands like tline occurs 1 with header line.

* Globals for screen processing
* Screen attributes
constants:
c_screen_on like screen-active value '1',
c_screen_off like screen-active value '0'.

data: fcode like sy-ucomm,
fcode_old like sy-ucomm,
f_found(1) type c,
f_action_canceled(1) type c,
f_resolution_changed(1) type c,
f_show_attributes_2001(1) type c,
f_show_attributes_2002(1) type c,
g_repid like sy-repid value 'SAPLSTXBITMAPS'.

constants:
fcode_ok like sy-ucomm value 'OK',
** fcode_f3 like sy-ucomm value 'BACK',
fcode_f12 like sy-ucomm value 'CANC',
** fcode_f15 like sy-ucomm value 'BEEN',
fcode_search like sy-ucomm value 'CATA',
fcode_import like sy-ucomm value 'UPLD',
fcode_detail like sy-ucomm value 'DETAIL',
fcode_btype like sy-ucomm value 'BTYPE',
fcode_gr_id like sy-ucomm value 'GRAPHICS_ID',
fcode_tab_bds like sy-ucomm value 'STXBITMAPS',
fcode_tab_grtext like sy-ucomm value 'STXHGRAPHICS',
fcode_tab_stdtext like sy-ucomm value 'STXHTEXT'.

* Tabstrips
controls:
tabstrip_bitmaps type tabstrip.
data: tabstrip_nr like sy-dynnr.

define tab_bds.
tabstrip_nr = '2001'.
tabstrip_bitmaps-activetab = 'STXBITMAPS'.
end-of-definition.
define tab_stxh_graphics.
tabstrip_nr = '2002'.
tabstrip_bitmaps-activetab = 'STXHGRAPHICS'.
end-of-definition.


* Globals and globals for dynpro fields
data: g_objecttype(20) type c,
g_new_resolution like stxbitmaps-resolution,
g_stxbitmaps type stxbitmaps,
g_stxh type stxh,
g_techinfo type rsscg,
t_size(40),
bds_description like bapisignat-prop_value.
constants:
c_objecttype_bds like g_objecttype value 'BDS',
c_objecttype_stdtext like g_objecttype value 'OBTEXT',
c_objecttype_grtext like g_objecttype value 'OBGRAPHICS'.

* Graphic handling
constants:
c_stdtext like thead-tdobject value 'TEXT',
c_graphics like thead-tdobject value 'GRAPHICS',
c_bmon like thead-tdid value 'BMON',
c_bcol like thead-tdid value 'BCOL'.
constants:
c_screen_graphic_import like sy-dynnr value '4000',
c_screen_graphic_import_bds like sy-dynnr value '4001'.
* radio buttons
data: rb_origin_page(1) value ' ',
rb_origin_window(1) value 'X',
rb_origin_absolute(1) value ' ',
rb_height_page(1) value ' ',
rb_height_window(1) value ' ',
rb_height_absolute(1) value 'X',
rb_width_page(1) value ' ',
rb_width_window(1) value ' ',
rb_width_absolute(1) value 'X',
rb_no_line(1) value ' ',
rb_line_user_def(1) value 'X',
rb_graphic_bmon(1) value 'X',
rb_graphic_bcol(1) value ' ',
rb_graphic_general(1) value ' '.
* measures
data: box_left like rstxu-negative,
box_left_unit like rstxu-unith,
box_top like rstxu-negative,
box_top_unit like rstxu-unitv,
box_width like rstxu-positive,
box_width_unit like rstxu-unith,
box_height like rstxu-positive,
box_height_unit like rstxu-unitv,
box_origin_left like rstxu-positive,
box_origin_left_unit like rstxu-unith,
box_origin_top like rstxu-positive,
box_origin_top_unit like rstxu-unitv,
box_frame like rstxu-positive,
box_frame_unit like rstxu-unit.

*----------------------------------------------------------------------*
***INCLUDE LZSY_FG_HR_COMMONF01.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_STRUC
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LT_RESULT_TAB_TEMP
*& --> LT_RESULT_OBJEC
*& --> LT_RESULT_STRUC
*& --> LV_WEGID
*& --> LV_ACT_OTYPE
*& --> LV_OBJID
*& --> LV_BEGDA
*& --> LV_ENDDA
*&---------------------------------------------------------------------*
FORM get_struc TABLES p_lt_result_tab_temp STRUCTURE swhactor
p_lt_result_objec STRUCTURE objec
p_lt_result_struc STRUCTURE struc
USING p_wegid
p_act_otype
p_objid
p_begda
p_endda.

DATA: lv_act_otype TYPE objec-otype,
lv_wegid TYPE gdstr-wegid,
lt_result_tab TYPE TABLE OF swhactor,
lt_result_tab_temp TYPE TABLE OF swhactor,
ls_result_tab LIKE LINE OF lt_result_tab,
ls_result_tab_temp LIKE LINE OF lt_result_tab_temp,
lt_result_objec TYPE TABLE OF objec,
ls_result_objec LIKE LINE OF lt_result_objec,
lt_result_objec_copy TYPE TABLE OF objec,
lt_result_objec_temp TYPE TABLE OF objec,
lt_result_struc TYPE TABLE OF struc,
lt_result_struc2 TYPE TABLE OF struc.

DATA: lv_objid TYPE hrp1000-objid,
lv_otype TYPE hrp1000-otype,
lv_plvar TYPE plvar VALUE '01',
lv_begda TYPE sy-datum,
lv_endda TYPE sy-datum,
lv_orgeh TYPE yac_t_rule-orgeh,
lv_wf_id TYPE hr_sobjid.


lv_wegid = p_wegid.
lv_act_otype = p_act_otype.
lv_objid = p_objid.
LV_BEGDA = p_begda.
LV_ENDDA = p_endda.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = lv_act_otype
act_objid = lv_objid
act_wegid = lv_wegid
act_plvar = lv_plvar
act_begda = lv_begda
act_endda = lv_endda
act_tflag = 'X'
act_vflag = 'X'
authority_check = 'X'
TABLES
result_tab = p_lt_result_tab_temp
result_objec = p_lt_result_objec
result_struc = p_lt_result_struc
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HR_READ_INFOTYPE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LT_PA0000
*& --> P_
*& --> <FS_PA0000>_PERNR
*& --> P_
*& --> SY_DATUM
*& --> SY_DATUM
*& --> LV_SUBRC
*&---------------------------------------------------------------------*
FORM hr_read_infotype TABLES p_lt_pa
USING p_lv_tclas
p_lv_pernr
p_lv_infty
p_begda
p_endda
p_lv_subrc.

CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
TCLAS = p_lv_tclas
pernr = p_lv_pernr
infty = p_lv_infty
BEGDA = p_begda
ENDDA = p_endda
* SPRPS = '*'
* BYPASS_BUFFER = ' '
* LEGACY_MODE = ' '
IMPORTING
SUBRC = p_lv_subrc
TABLES
infty_tab = p_lt_pa
EXCEPTIONS
INFTY_NOT_FOUND = 1
INVALID_INPUT = 2
.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form log_header_create
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- L_LOG_HANDLE
*&---------------------------------------------------------------------*
FORM log_header_create USING IV_OBJECT
IV_EXTNUMBER
IV_MSG_IDENT
CHANGING c_log_handle TYPE balloghndl.

DATA:
l_s_log TYPE bal_s_log.


* create log header data
CLEAR l_s_log.
l_s_log-object = IV_OBJECT.
l_s_log-extnumber = IV_EXTNUMBER.

* define callback routine
l_s_log-params-callback-userexitp = sy-repid.
l_s_log-params-callback-userexitf = 'CALLBACK_LOG_DETAIL'.
* l_s_log-params-callback-userexitt = const_callback_form.

* create the log header
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = c_log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* we want to store some information in the log header
* to describe which carriers and flight were handled in this log
* g_my_header_data-carrid = 'AB'. "#EC NOTEXT
* g_my_header_data-txt_carrid = 'Airways AB'. "#EC NOTEXT
* g_my_header_data-connid = '0003'."#EC NOTEXT
* g_my_header_data-txt_connid = 'Hamburg - New York'(001).
* APPEND g_my_header_data.
* g_my_header_data-carrid = 'XY'. "#EC NOTEXT
* g_my_header_data-txt_carrid = 'XY Lines'. "#EC NOTEXT
* g_my_header_data-connid = '0002'."#EC NOTEXT
* g_my_header_data-txt_connid = 'Walldorf - Tokio'(002).
* APPEND g_my_header_data.
* g_my_header_data-carrid = 'ZZ'. "#EC NOTEXT
* g_my_header_data-txt_carrid = 'ZZ Wings'. "#EC NOTEXT
* g_my_header_data-connid = '0014'."#EC NOTEXT
* g_my_header_data-txt_connid = 'Paris - Frankfurt'(003).
* APPEND g_my_header_data.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form log_message_create
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> L_LOG_HANDLE
*& --> IV_OBJECT
*& --> IV_EXTNUMBER
*& --> IV_MSG_IDENT
*&---------------------------------------------------------------------*
FORM log_message_create USING i_log_handle
IV_OBJECT
IV_EXTNUMBER
IV_MSG_IDENT.
DATA:
l_s_msg TYPE bal_s_msg,
l_s_par TYPE bal_s_par,
l_s_my_data TYPE bal_s_ex06.


* create a message
* 327(BL): "&1 customers were allowed to fly for free (see detail)"
CLEAR l_s_msg.
l_s_msg-msgty = 'E'.
l_s_msg-msgid = 'BL'.
l_s_msg-msgno = '327'.
l_s_msg-msgv1 = '3'.

* define callback routine
l_s_msg-params-callback-userexitp = sy-repid.
l_s_msg-params-callback-userexitf = 'CALLBACK_MSG_DETAIL'.
"l_s_msg-params-callback-userexitt = const_callback_form.

* define an identifer. This is used to establish the link between
* the message and its additional data
ADD 1 TO g_identifier.

* put his identifier into the parameters of the message
l_s_par-parname = IV_MSG_IDENT.
l_s_par-parvalue = g_identifier.
APPEND l_s_par TO l_s_msg-params-t_par.

* create the message
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = i_log_handle
i_s_msg = l_s_msg
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* we want to store information for this message about the customers
* which were allowed to fly for free:
* g_my_message_data-identifier = g_identifier.
* l_s_my_data-id = '00000002'.
* l_s_my_data-txt_id = 'Peter Smith'. "#EC NOTEXT
* APPEND l_s_my_data TO g_my_message_data-t_my_data.
* l_s_my_data-id = '00000013'.
* l_s_my_data-txt_id = 'Paula Jones'. "#EC NOTEXT
* APPEND l_s_my_data TO g_my_message_data-t_my_data.
* l_s_my_data-id = '00001345'.
* l_s_my_data-txt_id = 'Jane Meyer'. "#EC NOTEXT
* APPEND l_s_my_data TO g_my_message_data-t_my_data.
* APPEND g_my_message_data.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form log_save
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> L_LOG_HANDLE
*& --> IV_OBJECT
*& --> IV_EXTNUMBER
*& --> IV_MSG_IDENT
*&---------------------------------------------------------------------*
FORM log_save USING i_log_handle
IV_OBJECT
IV_EXTNUMBER
IV_MSG_IDENT.
DATA:
l_t_log_handle TYPE bal_t_logh,
l_s_new_lognumber TYPE bal_s_lgnm,
l_t_new_lognumbers TYPE bal_t_lgnm.


* save this log
INSERT i_log_handle INTO TABLE l_t_log_handle.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = l_t_log_handle
IMPORTING
e_new_lognumbers = l_t_new_lognumbers
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* find out the lognumber of this saved log
READ TABLE l_t_new_lognumbers INTO l_s_new_lognumber
WITH KEY log_handle = i_log_handle.
CHECK sy-subrc = 0.
g_lognumber = l_s_new_lognumber-lognumber.

* also save our own, complex data:
* EXPORT g_my_header_data g_my_message_data
* TO DATABASE bal_indx(al)
* ID g_lognumber.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CAL_YEAR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> DATE
*& --> DAYS
*& --> MONTHS
*& --> SIGNUM
*& --> YEARS
*& <-- LS_TS_GET_PERSON_ZHR_FDXTRQ
*&---------------------------------------------------------------------*
FORM cal_year USING p_date
p_days
p_months
p_signum
p_years
CHANGING P_RETURN_DATE.


DATA DATE TYPE P0001-BEGDA.
DATA DAYS TYPE T5A4A-DLYDY.
DATA MONTHS TYPE T5A4A-DLYMO.
DATA SIGNUM TYPE T5A4A-SPLIT.
DATA YEARS TYPE T5A4A-DLYYR.
DATA LV_SUBRC TYPE SY-SUBRC .
DATA:LV_RETURN_DATE TYPE SY-DATUM.

DATE = p_date.
DAYS = p_days.
months = p_months.
SIGNUM = p_signum.
YEARS = p_years.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = DATE
days = DAYS
months = months
SIGNUM = SIGNUM
years = years
IMPORTING
CALC_DATE = LV_RETURN_DATE.
P_RETURN_DATE = LV_RETURN_DATE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ENQUEUE_GRAPHIC
*&---------------------------------------------------------------------*
* Enqueue of graphics stored in BDS
*----------------------------------------------------------------------*
form enqueue_graphic using p_object
p_name
p_id
p_btype.

DATA:LV_TDOBJECT TYPE TDOBJECTGR,
LV_TDNAME TYPE TDOBNAME,
LV_TDID TYPE TDIDGR,
LV_TDBTYPE TYPE TDBTYPE.

LV_TDOBJECT = p_object.
LV_TDNAME = p_name.
LV_TDID = p_id.
LV_TDBTYPE = p_btype.

call function 'ENQUEUE_ESSGRABDS'
exporting
* MODE_STXBITMAPS = 'E'
tdobject = LV_TDOBJECT
tdname = LV_TDNAME
tdid = LV_TDID
tdbtype = LV_TDBTYPE
* X_TDOBJECT = ' '
* X_TDNAME = ' '
* X_TDID = ' '
* X_TDBTYPE = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
exceptions
foreign_lock = 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
raising enqueue_failed.
endif.

endform. " ENQUEUE_GRAPHIC

*&---------------------------------------------------------------------*
*& Form DEQUEUE_GRAPHIC
*&---------------------------------------------------------------------*
* Dequeue of graphics stored in BDS
*----------------------------------------------------------------------*
form dequeue_graphic using p_object
p_name
p_id
p_btype.

DATA:LV_TDOBJECT TYPE TDOBJECTGR,
LV_TDNAME TYPE TDOBNAME,
LV_TDID TYPE TDIDGR,
LV_TDBTYPE TYPE TDBTYPE.

LV_TDOBJECT = p_object.
LV_TDNAME = p_name.
LV_TDID = p_id.
LV_TDBTYPE = p_btype.

call function 'DEQUEUE_ESSGRABDS'
exporting
* MODE_STXBITMAPS = 'E'
* X_TDOBJECT = ' '
* X_TDNAME = ' '
* X_TDID = ' '
* X_TDBTYPE = ' '
* _SCOPE = '3'
* _SYNCHRON = ' '
* _COLLECT = ' '
tdobject = LV_TDOBJECT
tdname = LV_TDNAME
tdid = LV_TDID
tdbtype = LV_TDBTYPE.

endform. " DEQUEUE_GRAPHIC