Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

************************************************************************report zfi_sap_to_iss no standard page heading

line-size 255.************************************************************************

* Original specification: ARCH project* This program extracts new waybills for transfer to ISS.

* It reads billing documents posted to accounting since the last

* run date and time and creates IDocs to send data in EDI-426 format

* to ISS.

* Test mode will generate a list of some of the output data;

* no IDocs are created.

*

* Segment definitions are stored as IDoc segments with names of the

* form:

* Z1EDI426<segment>01

* For example, the segment definition of BNX is in Z1EDI426BNX01.

* If a segment occurs in more than one position in the 426 (e.g. DTM,

* N9, PI), then the final two digits of the IDoc segment are

* incremented.

************************************************************************tables: zsd_wb_so_status.************************************************************************

* Types

************************************************************************type-pools: abap.* zfa01,

* zva01,

* zvast.types: begin of ty_junction_settlement,

scac_text type char18,

scac type char5,

fsac_text type char19,

fsac type char5,

end of ty_junction_settlement.

types: begin of ty_required,

arch_set type zsd_arch_set,

seg_id type zarch_seg_id,

compname type abap_compname,

end of ty_required.

types: tyt_required type standard table of ty_required.

types: begin of ty_stack,

hlevel type edi_hlevel,

psgnum type edi_psgnum,

end of ty_stack.

types: tyt_stack type standard table of ty_stack.

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

* Forward definitions

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

*class: zcl_arch_waybill definition load.

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

* Constants

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

* Controlling entity on the CUR segment

constants: c_cur_entity type char3 value 'RR'.

* Dummy ST control number, used in test runs

constants: c_dummy_ctl_num type char9 value '999999999'.

* Texts in NTE02 for junction settlement origin/destination

constants: begin of c_junc_text,

begin of dest,

scac_text type char18 value 'FW JS-DEST-SCAC = ',

fsac_text type char19 value ', D901-DEST-FSAC = ',

end of dest,

begin of orig,

scac_text type char18 value 'FW JS-ORIG-SCAC = ',

fsac_text type char19 value ', F901-ORIG-FSAC = ',

end of orig,

end of c_junc_text.

* Relevant L1 charge types to be sent to ISS

constants: begin of c_l1_charge_type,

fat type char4 value '_FAT',

freight type char4 value 'LH',

fuel type char4 value 'FUEL',

misc type char4 value '_MSG',

end of c_l1_charge_type.

* PI ref id qualifiers

constants: begin of c_pi_ref_id_qual,

contract type char3 value 'CT',

end of c_pi_ref_id_qual.

* Routing sequence codes for junction settlement SCAC's

constants: begin of c_r202,

dest type char2 value 'JD',

orig type char2 value 'JO',

end of c_r202.

* IDoc Receiver data - Port, Partner and Partner Type

constants: c_rcvpor type edi_rcvpor value 'ZMIDDLE',

c_rcvprn type edi_rcvprn value 'ISSO',

c_rcvprt type edi_rcvprt value 'LS'.

* Waybill response codes in the ZR segment

constants: begin of c_resp_code,

cancellation type char1 value 'S',

full_waybill type char1 value 'A',

rule_11 type char1 value 'R',

end of c_resp_code.

* CPRS SCAC

constants: c_scac_cprs type char4 value 'CPRS'.

* Source system

* (used to identify special SAP-ISS data in standard fields).

constants: c_source_sys_sap type zarch_srce_sys value 'SAP'.

* Values used for unpopulated fields

constants: c_test_batch_no type zar_batch_no value '<TEST RUN>',

c_test_docnum type edi_docnum value 9999999999999999.

* Waybill types (to determine what to write to the IDoc)

constants: begin of c_wbty,

cancellation type char1 value '0',

normal type char1 value '1',

r11_notificn type char1 value '2',

r11_revenue type char1 value '3',

end of c_wbty.

* Weight qualifiers

constants: begin of c_weight_qual,

billed type char2 value 'B',

minimum type char2 value 'M',

end of c_weight_qual.

* Weight unit codes

constants: begin of c_weight_unit,

kilogram type char1 value 'K',

end of c_weight_unit.

* Defaults for ZR segment

constants: c_zr07_scac type char4 value 'CPRS'.

constants: begin of c_zr09_iss_status1,

cancel type char2 value 'CA',

internal type char2 value 'XO',

end of c_zr09_iss_status1.

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

* Data

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

data : save_date like sy-datum,

save_time like sy-uzeit.

data: flag_date(1).

data wa_dt_tm_stamp like zfi_dt_tm_stamp.

data itab_dt_tm like zfi_dt_tm_stamp occurs 0 with header line.

data: w_arch_set type zsd_arch_set,

* w_control_number TYPE z1edi426st01-control_number,

w_control_number TYPE EDI_DOCNO3,

w_extnumber type balnrext,

w_length type i,

w_logsys type logsys,

w_mq_msg_num type SYMSGNO,

w_msgtxt type char100,

w_nidocs type numc5,

w_nlines type i,

w_nsegs type numc10,

w_object type balobj_d,

w_routing_seq_code type char2,

w_scac_r2 type char4,

w_statuses type SYPFKEY,

w_subobject type balsubobj,

w_tabix type sytabix,

w_tabix_l0 type sytabix,

w_tariff_item_no_p(9) type p decimals 3,

w_total_l1a01 type zarch_tot_l1a01,

w_total_l104 type zarch_tot_l104,

w_trans_ctl_number(9) type n,

w_waybill type zva01_waybill,

w_zar_iface_cntl_curr type zar_iface_cntl.

data: begin of w_count,

bad_idoc type zar_rec_count, "No. of bad IDoc

good_idoc type zar_rec_count, "No. of good IDocs

failed_idoc type zar_rec_count, "No. of IDocs failed

idoc type zar_rec_count, "No. of IDocs created

end of w_count.

data: begin of w_flag,

create_l0_chunk type flag,

create_pi_under_bnx type flag,

first type flag,

first_l0_row type flag,

found type flag,

junc_settle_d9 type flag,

junc_settle_f9 type flag,

l1_fat type flag,

l1_freight type flag,

l1_fuel type flag,

l1_misc type flag,

scac_dropped_first type flag,

scac_dropped_last type flag,

overhead_waybill type flag,

end of w_flag.

data: begin of w_routing,

scac1 type char4,

scac2 type char4,

scac3 type char4,

scac4 type char4,

scac5 type char4,

scac6 type char4,

end of w_routing.

data: begin of w_scac,

curr type char4,

dest type char4,

orig type char4,

end of w_scac.

data: t_iss_id_codes type standard table of zfi_iss_id_codes,

w_iss_id_codes type zfi_iss_id_codes.

data: r_n101 type range of zarch_id_code,

wa_n101 like line of r_n101.

data: r_n901 type range of zarch_id_code,

wa_n901 like line of r_n901.

data: t_so_status type table of zsd_wb_so_status

with header line,

t_so_status1 type table of zsd_wb_so_status with

header line,

w_so_status type zsd_wb_so_status.

data: t_edi426 type standard table of zfa01_426,

w_edi426 type zfa01_426.

* IDoc data

data: w_edidc type edidc,

w_hlevel type edi_hlevel,

w_psgnum type edi_psgnum,

w_segnum type idocdsgnum.

data: t_edidc_comm type standard table of edidc,

w_edidc_comm type edidc.

data: t_edidd type standard table of edidd.

data: begin of w_docnum,

first type edi_docnum,

last type edi_docnum,

end of w_docnum.

data: begin of w_docnum_c,

first type char16,

last type char16,

end of w_docnum_c.

* Temp storage for Waybill and EDI426 workareas

data: begin of w_wb,

bl type zsd_arch_bl,

dtm type zsd_arch_dtm,

ga type zsd_arch_ga,

h3 type zsd_arch_h3,

l0 type zsd_arch_l0,

l1 type zsd_arch_l1,

l5 type zsd_arch_l5,

m7 type zsd_arch_m7,

mea type zsd_arch_mea,

n2 type zsd_arch_n2,

n3 type zsd_arch_n3,

n8 type zsd_arch_n8,

n9 type zsd_arch_n9,

nte type zsd_arch_nte,

per type zsd_arch_per,

pi type zsd_arch_pi,

ps type zsd_arch_ps,

r2b type zsd_arch_r2b,

r2c type zsd_arch_r2c,

r2d type zsd_arch_r2d,

r2x type zsd_arch_r2x,

t2 type zsd_arch_t2,

t3 type zsd_arch_t3,

vc type zsd_arch_vc,

bnx_row type zva01_bnx_row,

l0_row type zva01_l0_row,

l1_row type zva01_l1_row,

lx_row type zva01_lx_row,

n1_row type zva01_n1_row,

n7_row type zva01_n7_row,

r2_row type zva01_r2_row,

r2b_row type zva01_r2b_row,

s1_row type zva01_s1_row,

t1_row type zva01_t1_row,

end of w_wb.

data: begin of w_426,

bl type z1edi426bl01,

bx type z1edi426bx01,

dtm01 type z1edi426dtm01,

dtm03 type z1edi426dtm03,

ga type z1edi426ga01,

h3 type z1edi426h301,

l0 type z1edi426l001,

l1 type z1edi426l101,

l1a type z1edi426l1a01,

l1a_dest type z1edi426l1a01,

l1a_orig type z1edi426l1a01,

l5 type z1edi426l501,

m7 type z1edi426m701,

mea type z1edi426mea01,

n2 type z1edi426n201,

n3 type z1edi426n301,

n8 type z1edi426n801,

n8a type z1edi426n8a01,

n9 type z1edi426n902,

nte type z1edi426nte01,

per02 type z1edi426per02,

pi01 type z1edi426pi01,

pi02 type z1edi426pi02,

ps type z1edi426ps01,

r2 type z1edi426r201,

r2b type z1edi426r2b01,

r2c type z1edi426r2c01,

r2d type z1edi426r2d01,

t2 type z1edi426t201,

t3 type z1edi426t301,

vc type z1edi426vc01,

loop1000_row type zfa01_loop1000_row,

loop1100_row type zfa01_loop1100_row,

loop1200_row type zfa01_loop1200_row,

loop1300_row type zfa01_loop1300_row,

loop1400_row type zfa01_loop1400_row,

loop1410_row type zfa01_loop1410_row,

loop1500_row type zfa01_loop1500_row,

loop1510_row type zfa01_loop1510_row,

loop1600_row type zfa01_loop1600_row,

end of w_426.

* List of required fields with missing values in an IDoc

data: t_required type tyt_required,

w_required type ty_required.

* Stack to keep track of levels and parent segments as we build the IDoc

data: t_stack type tyt_stack,

w_stack type ty_stack.

* Redefinitions of standard fields to contain special interface data

data: w_l010 type zfi_arch_426_l010,

w_nte02 type zfi_arch_426_nte02,

w_zr06 type zfi_arch_426_zr06.

* Redefinitions of NTE to store junction settlement origin/destination

data: begin of w_nte_junc,

dest type z1edi426nte01,

orig type z1edi426nte01,

end of w_nte_junc.

data: begin of w_nte02_junc,

dest type ty_junction_settlement,

orig type ty_junction_settlement,

end of w_nte02_junc.

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

* Declarations for standard interface controls

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

constants: c_iface1 type zar_iface_id value 'ISSO'.

data: o_iface1 type ref to zcl_arch_ifaces.

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

* Field-symbols

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

field-symbols: <edi426> type zfa01_426,

<l0> type zsd_arch_l0,

<l0_prev> type zsd_arch_l0,

<l0_row> type zva01_l0_row,

<lx_row> type zva01_lx_row,

<nte> type z1edi426nte01.

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

* Selection screen

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

* Output control

selection-screen: begin of block b2 with frame

title comm_out. "#EC NEEDED

* Fastway transaction set key

select-options: s_fwset for zsd_wb_so_status-fwset.

* Version

select-options: s_versn for zsd_wb_so_status-versn.

selection-screen: skip.

selection-screen begin of block sdate with frame title text-001.

parameters: start_dt like sy-datum,

start_tm like sy-uzeit.

selection-screen skip.

parameters: end_dt like sy-datum,

end_tm like sy-uzeit.

selection-screen end of block sdate.

selection-screen: skip.

* Run mode

selection-screen: begin of block b2b with frame

title comm_rmo. "#EC NEEDED

* Test run

selection-screen: begin of line,

comment (30) comm_tst, "#EC NEEDED

position pos_low.

parameters: p_test as checkbox default abap_false.

selection-screen: end of line.

selection-screen: end of block b2b.

selection-screen: skip.

selection-screen: end of block b2.

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

* Events

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

initialization.

perform set_selscrn_texts.

perform set_date_time.

at selection-screen.

if end_dt lt start_dt.

message e999(lx) with 'Start Date can not be less than the End Date'.

endif.

if start_dt eq end_dt.

flag_date = '1'.

else.

flag_date = '0'.

endif.

start-of-selection.

perform start_interface.

perform build_current_batch_info.

perform gather_pending_waybills.

perform gather_valid_id_codes.

perform build_edi_426_messages.

perform calculate_control_totals.

end-of-selection.

perform test_output.

perform create_idocs.

perform update_current_batch_info.

at line-selection.

perform line_selection.

top-of-page.

perform top_of_page.

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

* Forms

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

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

form add_iface_msg using px_msgty1

px_msgty2

px_msgid

px_msgno

px_msgv1

px_msgv2

px_msgv3

px_msgv4

px_context

px_add_cancel_msg.

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

* Note: PX_MSGTY1 is the message type for the application log and the

* spool report line.

* PX_MSGTY2 is the message type for the regular MESSAGE statement

* (For example, you can write an ERROR to the log but issue an

* INFO message to avoid interrupting the program).

* This routine adds an application log message (with context if

* supplied), adds the message to the job spool and displays the message

* with the MESSAGE statement.

data: l_context type bal_s_cont.

if not px_context is initial.

l_context = px_context.

endif.

* Add message to application log.

CALL METHOD O_IFACE1->ADD_INTERFACE_MSG

EXPORTING

X_MSGTY = px_msgty1

X_MSGID = px_msgid

X_MSGNO = px_msgno

X_MSGV1 = px_msgv1

X_MSGV2 = px_msgv2

X_MSGV3 = px_msgv3

X_MSGV4 = px_msgv4

X_CONTEXT = l_context

X_ADD_CANCEL_MSG = px_add_cancel_msg

EXCEPTIONS

others = 0.

* Write message to spool.

MESSAGE ID px_msgid TYPE px_msgty1 NUMBER px_msgno

WITH px_msgv1 px_msgv2 px_msgv3 px_msgv4

INTO w_msgtxt.

write: / w_msgtxt.

skip 1.

* Display message normally.

MESSAGE ID px_msgid TYPE px_msgty2 NUMBER px_msgno

WITH px_msgv1 px_msgv2 px_msgv3 px_msgv4.

endform.

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

form add_iface_msg_with_idoc using px_msgty1 "#EC CALLED

px_msgty2

px_msgid

px_msgno

px_msgv1

px_msgv2

px_msgv3

px_msgv4

px_docnum

px_add_cancel_msg.

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

* Note: PX_MSGTY1 is the message type for the application log and the

* spool report line.

* PX_MSGTY2 is the message type for the regular MESSAGE statement

* (For example, you can write an ERROR to the log but issue an

* INFO message to avoid interrupting the program).

* This routine adds an application log message with a callback to

* display an IDoc.

data: l_context type bal_s_cont.

* Get context if required

if not px_docnum is initial.

l_context-tabname = 'IDOCDOCNUM'.

l_context-value = px_docnum.

endif.

perform add_iface_msg using px_msgty1

px_msgty2

px_msgid

px_msgno

px_msgv1

px_msgv2

px_msgv3

px_msgv4

l_context

px_add_cancel_msg.

endform.

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

form add_iface_msg_with_waybill using px_msgty1

px_msgty2

px_msgid

px_msgno

px_msgv1

px_msgv2

px_msgv3

px_msgv4

px_docnum

px_fwset

px_versn

px_add_cancel_msg.

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

* Note: PX_MSGTY1 is the message type for the application log and the

* spool report line.

* PX_MSGTY2 is the message type for the regular MESSAGE statement

* (For example, you can write an ERROR to the log but issue an

* INFO message to avoid interrupting the program).

* This routine adds an application log message with a callback to

* display an IDoc and the associated waybill and waybill status. The

* callback routine also allows the user to change the settlement status.

data: l_context type bal_s_cont,

l_iss_status_update type zfi_iss_status_update.

* Get context if required

l_iss_status_update-docnum = px_docnum.

l_iss_status_update-fwset = px_fwset.

l_iss_status_update-versn = px_versn.

l_iss_status_update-change_stset = abap_true.

CALL METHOD O_IFACE1->GET_APPLOG_KEY

IMPORTING

Y_OBJECT = l_iss_status_update-object

Y_SUBOBJECT = l_iss_status_update-subobject

Y_EXTNUMBER = l_iss_status_update-extnumber.

if not l_iss_status_update is initial.

l_context-tabname = 'ZFI_ISS_STATUS_UPDATE'.

l_context-value = l_iss_status_update.

endif.

perform add_iface_msg using px_msgty1

px_msgty2

px_msgid

px_msgno

px_msgv1

px_msgv2

px_msgv3

px_msgv4

l_context

px_add_cancel_msg.

endform.

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

form add_loop_segment using px_segnam.

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

* Add a segment to indicate the start of a loop in the IDoc.

data: l_edidd type edidd,

l_id type char3.

check not px_segnam is initial.

l_id = sy-tabix.

add 1 to w_segnum.

w_psgnum = w_segnum.

l_edidd-docnum = w_edidc-docnum.

l_edidd-segnam = px_segnam.

l_edidd-segnum = w_segnum.

l_edidd-psgnum = w_stack-psgnum.

l_edidd-hlevel = w_stack-hlevel.

l_edidd-sdata = l_id.

l_edidd-dtint2 = strlen( l_edidd-sdata ).

append l_edidd to t_edidd.

endform.

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

form add_repeat_segment tables pt_sdata.

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

* Add a segment that may occur more than once to the IDoc.

data: lo_desc_ref type ref to cl_abap_typedescr.

data: l_edidd type edidd,

l_abstype type abap_abstypename.

field-symbols: <sdata> type any.

loop at pt_sdata assigning <sdata>.

at first.

lo_desc_ref = cl_abap_typedescr=>describe_by_data( <sdata> ).

l_abstype = lo_desc_ref->absolute_name.

replace '\TYPE=' with space into l_abstype.

condense l_abstype no-gaps.

endat.

add 1 to w_segnum.

l_edidd-docnum = w_edidc-docnum.

l_edidd-segnam = l_abstype.

l_edidd-segnum = w_segnum.

l_edidd-psgnum = w_psgnum.

l_edidd-hlevel = w_hlevel.

l_edidd-sdata = <sdata>.

l_edidd-dtint2 = strlen( l_edidd-sdata ).

append l_edidd to t_edidd.

endloop.

endform.

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

form add_seg_id using px_struc

value(px_descref) type ref to cl_abap_typedescr.

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

data: lo_struc_ref type ref to cl_abap_structdescr.

data: lt_compdescr type abap_compdescr_tab,

l_compdescr type abap_compdescr.

data: l_iss_fields type zfi_iss_fields,

l_seg_id type zarch_seg_id,

l_tabix type sy-tabix.

field-symbols: <field> type any.

* Get the components

catch system-exceptions move_cast_error = 4.

lo_struc_ref ?= px_descref.

lt_compdescr = lo_struc_ref->components.

loop at lt_compdescr into l_compdescr.

l_tabix = sy-tabix.

* Get the segment ID.

if l_tabix eq 1

and l_compdescr-name eq 'SEG_ID'.

assign component sy-tabix of structure px_struc to <field>.

perform derive_segment_id using px_descref->absolute_name

changing <field>.

l_seg_id = <field>.

endif.

* Transform numeric fields and check for required fields.

if l_compdescr-type_kind eq cl_abap_typedescr=>typekind_char.

assign component l_tabix of structure px_struc to <field>.

select single * into l_iss_fields

from zfi_iss_fields

where segment eq l_seg_id

and fieldname eq l_compdescr-name

and num_type eq abap_true.

if sy-subrc eq 0.

if l_iss_fields-required eq abap_true.

* Check for required fields.

if <field> is initial.

w_required-arch_set = w_arch_set.

w_required-seg_id = l_seg_id.

w_required-compname = l_compdescr-name.

append w_required to t_required.

clear w_required.

endif.

endif.

if l_iss_fields-num_type eq abap_true.

* Transform numeric field.

if <field> cn '0123456789+-. '.

* Field contents are not numeric.

w_required-arch_set = w_arch_set.

w_required-seg_id = l_seg_id.

w_required-compname = l_compdescr-name.

append w_required to t_required.

clear w_required.

else.

perform transform_decimal_places

using l_seg_id

l_compdescr-name

l_iss_fields-decimals

changing <field>.

CALL FUNCTION 'Z_FORMAT_NUMBER'

EXPORTING

X_FORMAT = l_iss_fields-num_fmt

CHANGING

XY_NUMBER = <field>

EXCEPTIONS

OTHERS = 0.

endif.

endif.

endif.

endif.

* Keep on crawling.

if l_compdescr-type_kind eq cl_abap_typedescr=>typekind_struct1

or l_compdescr-type_kind eq cl_abap_typedescr=>typekind_struct2

or l_compdescr-type_kind eq cl_abap_typedescr=>typekind_table.

* If a structure, get the components

assign component sy-tabix of structure px_struc to <field>.

perform add_seg_id_by_crawling changing <field>.

endif.

endloop.

endcatch.

endform.

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

form add_seg_id_by_crawling changing px_struc.

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

* Move recursively through a deep structure, adding components to the

* tree (we only add structures to the tree, not individual fields).

* The recursion involves both this subroutine and also GET_COMPONENTS.

data: l_typekind type abap_typekind.

data: ldr_struc type ref to data,

lo_desc_ref type ref to cl_abap_typedescr,

lo_table_ref type ref to cl_abap_tabledescr.

field-symbols: <struc> type any,

<table> type any table.

* If the structure is actually an internal table, create a line type

* field for use when looping through the table.

lo_desc_ref = cl_abap_typedescr=>describe_by_data( px_struc ).

l_typekind = lo_desc_ref->type_kind.

if l_typekind eq cl_abap_typedescr=>typekind_table.

lo_table_ref ?= lo_desc_ref.

lo_desc_ref = lo_table_ref->get_table_line_type( ).

create data ldr_struc type (lo_desc_ref->absolute_name).

assign ldr_struc->* to <struc>.

endif.

case l_typekind.

when cl_abap_typedescr=>typekind_struct1

or cl_abap_typedescr=>typekind_struct2.

* If this component is a structure, list its components.

if not px_struc is initial.

perform add_seg_id using px_struc

lo_desc_ref.

endif.

when cl_abap_typedescr=>typekind_table.

* If this component is a table, get the components for each row.

assign px_struc to <table>.

loop at <table> assigning <struc>.

if not <struc> is initial.

perform add_seg_id using <struc>

lo_desc_ref.

endif.

endloop.

endcase.

endform.

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

form add_seg_id_to_all_segments changing py_edi426 type zfa01_426.

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

* Crawl through the EDI-426 message to add the segment ID if the

* segment contains that field and to transform numeric fields.

* We assume that the segment ID field will be the first field in

* a segment and that it will always be named SEG_ID.

perform add_seg_id_by_crawling changing py_edi426.

endform.

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

form add_single_segment using px_sdata.

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

* Add a segment that only occurs once to the IDoc.

* The parameter PX_SDATA must have the same type as the IDoc segment.

data: lo_desc_ref type ref to cl_abap_typedescr.

data: l_edidd type edidd,

l_abstype type abap_abstypename.

check not px_sdata is initial.

lo_desc_ref = cl_abap_typedescr=>describe_by_data( px_sdata ).

l_abstype = lo_desc_ref->absolute_name.

replace '\TYPE=' with space into l_abstype.

condense l_abstype no-gaps.

add 1 to w_segnum.

l_edidd-docnum = w_edidc-docnum.

l_edidd-segnam = l_abstype.

l_edidd-segnum = w_segnum.

l_edidd-psgnum = w_psgnum.

l_edidd-hlevel = w_hlevel.

l_edidd-sdata = px_sdata.

l_edidd-dtint2 = strlen( l_edidd-sdata ).

append l_edidd to t_edidd.

endform.

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

form add_table_row tables pt_data

changing pxy_row.

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

if not pxy_row is initial.

append pxy_row to pt_data.

clear pxy_row.

endif.

endform.

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

form build_current_batch_info.

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

* New items

CALL METHOD O_IFACE1->BUILD_CURRENT_BATCH_INFO

EXCEPTIONS

NUMBER_RANGE_ERROR = 1

CANNOT_LOCK = 2

others = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD O_IFACE1->GET_APPLOG_KEY

IMPORTING

Y_OBJECT = w_object

Y_SUBOBJECT = w_subobject

Y_EXTNUMBER = w_extnumber.

* w_zar_iface_cntl_last = o_iface1->get_last_batch_info( ).

w_zar_iface_cntl_curr = o_iface1->get_current_batch_info( ).

endform.

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

form build_edi_426_messages.

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

* For each Fastway set found, create an EDI 426 to send to ISS.

loop at t_so_status into w_so_status.

* Get the waybill

move-corresponding w_so_status to w_arch_set.

w_waybill = zcl_arch_waybill=>get_one_waybill(

x_arch_set = w_arch_set

x_get_version = abap_true ).

if w_waybill is initial.

continue.

endif.

* Plough through the waybill and fill the EDI 426 message

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

* Cancellation - one very small IDoc

* 'Pure' Rule 11 - one IDoc for notification (parent) only

* Other Rule 11 - one IDoc for notification and one for revenue

* (parent and child)

* Others - one 'normal' IDoc

* Note that, for bunch bills, the L0/L1/PI segments are presented in a

* summary format (rather than one per waggon).

if w_so_status-cancellation eq abap_true.

perform build_single_edi_426_message using c_wbty-cancellation.

else.

perform summarise_bunch_bill changing w_waybill.

if w_so_status-rule_11 eq abap_true.

perform build_single_edi_426_message using c_wbty-r11_notificn.

* 'Pure' Rule 11 has a blank Rule 11 type, so any non-blank type

* triggers a revenue waybill.

if w_so_status-rule_11_type ne space.

perform build_single_edi_426_message using c_wbty-r11_revenue.

endif.

else.

perform build_single_edi_426_message using c_wbty-normal.

endif.

endif.

clear w_waybill.

endloop.

endform.

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

form build_single_edi_426_message using px_wbty.

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

* This subroutine creates the start and end ST and SE segments and also

* the ZR segments. Other segments are created by copying corresponding

* fields from like-named segments in the waybill.

* Parameter PX_WBTY distinguishes "normal", "Rule 11 notification

* (parent)", "Rule 11 revenue (child)" waybills and "Cancellations".

* A cancellation only requires a ZR segment.

* To find the relevant section of this routine, search for the segment

* ID or loop number from the 426 definition.

* This started off as a rather nice little routine, reading the waybill

* structure and copying the fields to similar segments in the 426.

* However, there are, needless to say, countless exceptions to the

* obvious mapping and you will find lots of ugly exception processing

* here. You will particularly enjoy the handling of the WEIGHT_QUAL

* field on the L0 segment, since it depends not only on the lower-level

* L1 segment but also (I really like this) on the following L0 segments.

data : flag_idler type i.

clear: w_nsegs,

w_routing,

w_wb,

w_426.

move-corresponding: w_arch_set to w_edi426-arch_set,

w_so_status to w_edi426-so_status.

move abap_false to: w_flag-junc_settle_d9,

w_flag-junc_settle_f9.

* Log - mandatory

* The segment is populated below after the SE segment, since a couple

* of fields require data from later segments.

* HDR - mandatory

perform get_st_control_number changing w_control_number.

perform populate_hdr_segment using w_control_number.

perform increment_nsegs using w_edi426-hdr

changing w_nsegs.

* ST - mandatory for EDI but not required for direct transfer to ISS

* (control number is assigned above under the HDR segment)

* w_edi426-st-control_number = w_control_number.

* w_edi426-st-set_identifier_code = '426'.

* perform increment_nsegs using w_edi426-st

* changing w_nsegs.

* ZR - mandatory

* Equip Init/Num are set in the N7 section

* The segment is populated below just before SE,

* so that the IF NOT...INITIAL check makes sense.

* N9 occ

* (N9 is not filled here for the 426 but after the BNX)

* DTM occ - mandatory

* (but (a) not needed for Rule 11 & (b) will be supplied by ISS itself)

* if px_wbty ne c_wbty-r11_notificn

* and px_wbty ne c_wbty-r11_revenue.

* w_426-dtm01-date_time_qual = '702'. "Sending Road Time Stamp

* w_426-dtm01-dtmdate = w_zar_iface_cntl_curr-lastrundt.

* w_426-dtm01-dtmtime = w_zar_iface_cntl_curr-lastruntm.

* perform store_repeating_segment tables w_edi426-dtm_occ

* changing w_426-dtm01

* w_nsegs.

* endif.

* CUR

* (According to 426 definition, not required for Rule 11, Cancellation

* or for USD waybills)

if px_wbty ne c_wbty-r11_notificn

and px_wbty ne c_wbty-cancellation

and w_edi426-so_status-iss_curr_code ne 'USD'.

w_edi426-cur-entity_code = c_cur_entity.

w_edi426-cur-currency_code = w_edi426-so_status-iss_curr_code.

perform increment_nsegs using w_edi426-cur

changing w_nsegs.

endif.

* PER

* (optional and not needed for Rule 11)

* NTE occ

if px_wbty ne c_wbty-cancellation.

loop at w_waybill-nte_occ into w_wb-nte.

move-corresponding w_wb-nte to w_426-nte.

perform store_repeating_segment tables w_edi426-nte_occ

changing w_426-nte

w_nsegs.

endloop.

* Add a 'placeholder' NTE segment for control totals.

* We'll calculate the control totals later and store them here in

* all IDocs in the current run.

clear w_426-nte.

w_426-nte-note_ref_code = c_source_sys_sap.

perform store_repeating_segment tables w_edi426-nte_occ

changing w_426-nte

w_nsegs.

endif.

* BX occ

w_scac-orig = w_426-bx-scac.

if px_wbty ne c_wbty-cancellation.

move-corresponding w_waybill-bx to w_426-bx.

* The BX13 GST_REASON_CODE can only have one of two values.

read table w_waybill-bnx_tab index 1 into w_wb-bnx_row.

if w_waybill-b3b-net_amt_due_cdn ne '000000000000'

and w_wb-bnx_row-l3-total_gst_amt eq '000000000'

and w_wb-bnx_row-l3-total_prov_tax eq '000000000'

and w_waybill-bx-gst_reason_code ca '234'.

w_426-bx-gst_reason_code = '3'.

else.

clear w_426-bx-gst_reason_code.

endif.

perform store_repeating_segment tables w_edi426-bx_occ

changing w_426-bx

w_nsegs.

endif.

* Loop 1000 (BNX loop)

* (occurs once only)

loop at w_waybill-bnx_tab into w_wb-bnx_row.

* BNX

if px_wbty ne c_wbty-cancellation.

move-corresponding w_wb-bnx_row-bnx to w_426-loop1000_row-bnx.

perform increment_nsegs using w_426-loop1000_row-bnx

changing w_nsegs.

endif.

* N9 occ

* (we only send N9 segments with valid qualifiers)

if px_wbty ne c_wbty-cancellation.

loop at w_waybill-n9_occ into w_wb-n9.

check w_wb-n9-ref_id_qual in r_n901.

move-corresponding w_wb-n9 to w_426-n9.

if w_426-n9-ref_id_qual eq 'WM'.

* clear w_426-n9-date1.

w_426-n9-date1 = space.

endif.

perform store_repeating_segment tables w_426-loop1000_row-n9_occ

changing w_426-n9

w_nsegs.

endloop.

endif.

* Loop 1100 (N7 loop) - we ignore idler cars

loop at w_wb-bnx_row-n7_tab into w_wb-n7_row

where n7-equip_desc_code ne 'ID'.

w_tabix = sy-tabix.

* N7 - mandatory

move-corresponding w_wb-n7_row-n7 to w_426-loop1100_row-n7.

call function 'Z_FORMAT_NUMBER'

EXPORTING

X_FORMAT = 'LJ'

changing

xy_number = w_426-loop1100_row-n7-equip_num

EXCEPTIONS

OTHERS = 2.

w_length = strlen( w_426-loop1100_row-n7-equip_num ).

if w_length gt 6.

w_426-loop1100_row-n7-equip_chk_digit =

w_426-loop1100_row-n7-equip_num+6(1).

clear w_426-loop1100_row-n7-equip_num+6(1).

endif.

perform fill_with_zeroes using abap_false

changing w_426-loop1100_row-n7-equip_length.

if px_wbty ne c_wbty-cancellation.

perform increment_nsegs using w_426-loop1100_row-n7

changing w_nsegs.

endif.

* Lead car is stored on the ZR segment.

if w_tabix eq 1.

w_edi426-zr-equip_initial = w_426-loop1100_row-n7-equip_init.

w_edi426-zr-equip_number = w_426-loop1100_row-n7-equip_num.

w_edi426-zr-equip_chk_digit =

w_426-loop1100_row-n7-equip_chk_digit.

* URRWIN date is always zeroes.

perform fill_with_zeroes using abap_true

changing w_edi426-zr-date2.

endif.

* VC occ

if px_wbty ne c_wbty-cancellation.

loop at w_wb-n7_row-vc_occ into w_wb-vc.

move-corresponding w_wb-vc to w_426-vc.

perform store_repeating_segment

tables w_426-loop1100_row-vc_occ

changing w_426-vc

w_nsegs.

endloop.

endif.

* IC

if px_wbty ne c_wbty-cancellation.

move-corresponding w_wb-n7_row-ic to w_426-loop1100_row-ic.

perform increment_nsegs using w_426-loop1100_row-ic

changing w_nsegs.

endif.

* G4

if px_wbty ne c_wbty-cancellation.

move-corresponding w_wb-n7_row-g4 to w_426-loop1100_row-g4.

* Default the province to Manitoba (for some obscure reason)

if not w_426-loop1100_row-g4-city_name is initial

and w_426-loop1100_row-g4-province is initial.

w_426-loop1100_row-g4-province = 'MB'.

endif.

* Time should be left justified

if not w_426-loop1100_row-g4-time is initial.

write w_426-loop1100_row-g4-time

to w_426-loop1100_row-g4-time left-justified.

w_426-loop1100_row-g4-time+4(4) = '0000'.

endif.

perform increment_nsegs using w_426-loop1100_row-g4

changing w_nsegs.

endif.

* M7 occ

if px_wbty ne c_wbty-cancellation.

loop at w_wb-n7_row-m7_occ into w_wb-m7.

move-corresponding w_wb-m7 to w_426-m7.

perform store_repeating_segment

tables w_426-loop1100_row-m7_occ

changing w_426-m7

w_nsegs.

endloop.

endif.

* N5 (only if certain fields are populated)

if px_wbty ne c_wbty-cancellation.

if not ( w_wb-n7_row-n5-equip_length is initial

and w_wb-n7_row-n5-weight_capacity is initial

and w_wb-n7_row-n5-cubic_capacity is initial ).

move-corresponding w_wb-n7_row-n5 to w_426-loop1100_row-n5.

perform increment_nsegs using w_426-loop1100_row-n5

changing w_nsegs.

endif.

endif.

** GA occ

* if px_wbty ne c_wbty-cancellation.

* loop at w_wb-n7_row-ga_occ into w_wb-ga.

* move-corresponding w_wb-ga to w_426-ga.

* perform store_repeating_segment

* tables w_426-loop1100_row-ga_occ

* changing w_426-ga

* w_nsegs.

* endloop.

* endif.

if px_wbty ne c_wbty-cancellation.

perform add_table_row tables w_426-loop1000_row-loop1100_tab

changing w_426-loop1100_row.

endif.

*added by sandhya : issue 1658

flag_idler = flag_idler + 1.

endloop.

* N8 occ - mandatory

if px_wbty ne c_wbty-cancellation.

* loop at w_wb-bnx_row-n8_occ into w_wb-n8.

* move-corresponding w_wb-n8 to w_426-n8.

* perform store_repeating_segment

* tables w_426-loop1000_row-n8_occ

* changing w_426-n8

* w_nsegs.

* endloop.

move-corresponding w_wb-bnx_row-n8 to w_426-n8.

* Equip Init and Number are not transferred.

clear: w_426-n8-equip_init,

w_426-n8-equip_num.

* WAYBILL_NUM2 and N8DATE2 are always zeroes.

perform fill_with_zeroes using abap_true:

changing w_426-n8-waybill_num2,

changing w_426-n8-n8date2.

perform store_repeating_segment tables w_426-loop1000_row-n8_occ

changing w_426-n8

w_nsegs.

endif.

* N8A occ - optional

* (but required for Rule 11 revenue waybills)

if px_wbty eq c_wbty-r11_revenue.

clear w_426-n8a.

w_426-n8a-waybill_cross_ref = 'W2'.

perform store_repeating_segment tables w_426-loop1000_row-n8a_occ

changing w_426-n8a

w_nsegs.

endif.

* F9 - mandatory

if px_wbty ne c_wbty-cancellation.

if w_wb-bnx_row-f9-jcn_or_load eq 'J'.

w_flag-junc_settle_f9 = abap_true.

endif.

move-corresponding w_wb-bnx_row-f9 to w_426-loop1000_row-f9.

perform move_fsac using w_wb-bnx_row-f9-frt_stn_acc_cd1

changing w_426-loop1000_row-f9-frt_stn_acc_cd1.

perform move_fsac using w_wb-bnx_row-f9-frt_stn_acc_cd2

changing w_426-loop1000_row-f9-frt_stn_acc_cd2.

perform increment_nsegs using w_426-loop1000_row-f9

changing w_nsegs.

endif.

* D9 - mandatory

if px_wbty ne c_wbty-cancellation.

if w_wb-bnx_row-d9-jcn_or_load eq 'J'.

w_flag-junc_settle_d9 = abap_true.

endif.

move-corresponding w_wb-bnx_row-d9 to w_426-loop1000_row-d9.

perform move_fsac using w_wb-bnx_row-d9-frt_acc_stn_cd1

changing w_426-loop1000_row-d9-frt_acc_stn_cd1.

perform move_fsac using w_wb-bnx_row-d9-frt_acc_stn_cd2

changing w_426-loop1000_row-d9-frt_acc_stn_cd2.

perform increment_nsegs using w_426-loop1000_row-d9

changing w_nsegs.

endif.

** NTE - Junction settlement info based on F9 and D9

** (we also move data within F9 and D9)

* clear w_nte_junc.

** Origin

* if not w_426-loop1000_row-f9-frt_stn_acc_cd2 is initial

* or not w_426-loop1000_row-f9-city_name2 is initial

* or not w_426-loop1000_row-f9-province2 is initial.

** Data for the NTE02

* perform get_junction_settlement_scac using c_r202-orig

* w_wb-bnx_row-r2_tab

* changing w_nte02_junc-orig-scac

*.

* if not w_nte02_junc-orig-scac is initial.

* w_nte02_junc-orig-fsac = w_426-loop1000_row-f9-frt_stn_acc_cd1.

** Texts for the NTE02

* move-corresponding c_junc_text-orig to w_nte02_junc-orig.

** Store the NTE segment

* w_nte_junc-orig-description = w_nte02_junc-orig.

* perform store_repeating_segment tables w_edi426-nte_occ

* changing w_nte_junc-orig

* w_nsegs.

* endif.

** Move data within F9

* w_426-loop1000_row-f9-frt_stn_acc_cd1 =

* w_426-loop1000_row-f9-frt_stn_acc_cd2.

* w_426-loop1000_row-f9-city_name1 =

* w_426-loop1000_row-f9-city_name2.

* w_426-loop1000_row-f9-province1 =

* w_426-loop1000_row-f9-province2.

* clear: w_426-loop1000_row-f9-frt_stn_acc_cd2,

* w_426-loop1000_row-f9-city_name2,

* w_426-loop1000_row-f9-province2.

* endif.

** Destination

* if not w_426-loop1000_row-d9-frt_acc_stn_cd2 is initial

* or not w_426-loop1000_row-d9-city_name2 is initial

* or not w_426-loop1000_row-d9-province2 is initial.

** Data for the NTE02

* perform get_junction_settlement_scac using c_r202-dest

* w_wb-bnx_row-r2_tab

* changing w_nte02_junc-dest-scac

*.

* if not w_nte02_junc-dest-scac is initial.

* w_nte02_junc-dest-fsac = w_426-loop1000_row-d9-frt_acc_stn_cd1.

** Texts for the NTE02

* move-corresponding c_junc_text-dest to w_nte02_junc-dest.

** Store the NTE segment

* w_nte_junc-dest-description = w_nte02_junc-dest.

* perform store_repeating_segment tables w_edi426-nte_occ

* changing w_nte_junc-dest

* w_nsegs.

* endif.

** Move data within D9

* w_426-loop1000_row-d9-frt_acc_stn_cd1 =

* w_426-loop1000_row-d9-frt_acc_stn_cd2.

* w_426-loop1000_row-d9-city_name1 =

* w_426-loop1000_row-d9-city_name2.

* w_426-loop1000_row-d9-province1 =

* w_426-loop1000_row-d9-province2.

* clear: w_426-loop1000_row-d9-frt_acc_stn_cd2,

* w_426-loop1000_row-d9-city_name2,

* w_426-loop1000_row-d9-province2.

* endif.

* Loop 1200 (N1 loop)

* (we only send N1 data with valid entity ID codes)

if px_wbty ne c_wbty-cancellation.

loop at w_wb-bnx_row-n1_tab into w_wb-n1_row.

check w_wb-n1_row-n1-entity_id_code in r_n101.

* N1 - mandatory

move-corresponding w_wb-n1_row-n1 to w_426-loop1200_row-n1.

* Strange handling for N1's on Rule 11 child (revenue) waybills

if px_wbty eq c_wbty-r11_revenue

and w_426-loop1200_row-n1-entity_id_code eq '11'.

w_426-loop1200_row-n1-entity_id_code = 'PF'.

endif.

clear w_426-loop1200_row-n1-id_code.

perform increment_nsegs using w_426-loop1200_row-n1

changing w_nsegs.

* N2 occ

loop at w_wb-n1_row-n2_occ into w_wb-n2.

move-corresponding w_wb-n2 to w_426-n2.

perform store_repeating_segment

tables w_426-loop1200_row-n2_occ

changing w_426-n2

w_nsegs.

endloop.

* N3 occ

loop at w_wb-n1_row-n3_occ into w_wb-n3.

move-corresponding w_wb-n3 to w_426-n3.

perform store_repeating_segment

tables w_426-loop1200_row-n3_occ

changing w_426-n3

w_nsegs.

endloop.

* N4

move-corresponding w_wb-n1_row-n4 to w_426-loop1200_row-n4.

perform increment_nsegs using w_426-loop1200_row-n4

changing w_nsegs.

* PER occ

loop at w_wb-n1_row-per_occ into w_wb-per.

move-corresponding w_wb-per to w_426-per02.

perform store_repeating_segment

tables w_426-loop1200_row-per_occ

changing w_426-per02

w_nsegs.

endloop.

* BL occ (Rule 11 notification only)

if px_wbty eq c_wbty-r11_notificn.

loop at w_wb-n1_row-bl_occ into w_wb-bl.

move-corresponding w_wb-bl to w_426-bl.

perform store_repeating_segment

tables w_426-loop1200_row-bl_occ

changing w_426-bl

w_nsegs.

endloop.

elseif px_wbty eq c_wbty-r11_revenue.

* Need some routing info for later on (Rule 11 revenue only)

loop at w_wb-n1_row-bl_occ into w_wb-bl

where scac1 eq c_scac_cprs

or scac2 eq c_scac_cprs

or scac3 eq c_scac_cprs

or scac4 eq c_scac_cprs

or scac5 eq c_scac_cprs

or scac6 eq c_scac_cprs.

move-corresponding w_wb-bl to w_routing.

endloop.

endif.

perform add_table_row tables w_426-loop1000_row-loop1200_tab

changing w_426-loop1200_row.

endloop.

* Loop 1200 requirements for Rule 11

case px_wbty.

when c_wbty-r11_notificn.

perform loop1200_for_rule_11_notificn.

when c_wbty-r11_revenue.

perform loop1200_for_rule_11_revenue.

endcase.

endif.

* Loop 1300 (S1 loop)

if px_wbty ne c_wbty-cancellation.

loop at w_wb-bnx_row-s1_tab into w_wb-s1_row.

* S1

move-corresponding w_wb-s1_row-s1 to w_426-loop1300_row-s1.

perform increment_nsegs using w_426-loop1300_row-s1

changing w_nsegs.

* S9

move-corresponding w_wb-s1_row-s9 to w_426-loop1300_row-s9.

perform increment_nsegs using w_426-loop1300_row-s9

changing w_nsegs.

perform add_table_row tables w_426-loop1000_row-loop1300_tab

changing w_426-loop1300_row.

endloop.

endif.

* Loop 1400 (R2 loop)

if px_wbty ne c_wbty-cancellation.

loop at w_wb-bnx_row-r2_tab into w_wb-r2_row.

* Capture the destination SCAC (from the last R2).

w_scac-curr = w_wb-r2_row-r2-scac.

at last.

w_scac-dest = w_scac-curr.

endat.

* R2 - mandatory

move-corresponding w_wb-r2_row-r2 to w_426-loop1400_row-r2.

* This field (R206) is not used in ISS.

clear w_426-loop1400_row-r2-transport_type_code.

perform strip_leading_zeroes

changing w_426-loop1400_row-r2-routing_seq_code.

perform increment_nsegs using w_426-loop1400_row-r2

changing w_nsegs.

* Loop 1410 (R2B loop)

loop at w_wb-r2_row-r2b_tab into w_wb-r2b_row.

* R2B

move-corresponding w_wb-r2b_row-r2b to w_426-loop1410_row-r2b.

perform increment_nsegs using w_426-loop1410_row-r2b

changing w_nsegs.

* R2C occ

loop at w_wb-r2b_row-r2c_occ into w_wb-r2c.

move-corresponding w_wb-r2c to w_426-r2c.

perform store_repeating_segment

tables w_426-loop1410_row-r2c_occ

changing w_426-r2c

w_nsegs.

endloop.

* R2D occ

loop at w_wb-r2b_row-r2d_occ into w_wb-r2d.

move-corresponding w_wb-r2d to w_426-r2d.

perform store_repeating_segment

tables w_426-loop1410_row-r2d_occ

changing w_426-r2d

w_nsegs.

endloop.

perform add_table_row tables w_426-loop1400_row-loop1410_tab

changing w_426-loop1410_row.

endloop.

perform add_table_row tables w_426-loop1000_row-loop1400_tab

changing w_426-loop1400_row.

endloop.

endif.

** R9

* if px_wbty ne c_wbty-cancellation.

* move-corresponding w_wb-bnx_row-r9 to w_426-loop1000_row-r9.

* perform increment_nsegs using w_426-loop1000_row-r9

* changing w_nsegs.

* endif.

* H3 occ

if px_wbty ne c_wbty-cancellation.

loop at w_wb-bnx_row-h3_occ into w_wb-h3.

* Only certain H301 values (Special Handling Code)

* are relevant for ISS.

select count(star)

from zfi_iss_h301

where spcl_handlg_code eq w_wb-h3-spcl_handlg_code.

check sy-subrc eq 0.

move-corresponding w_wb-h3 to w_426-h3.

perform store_repeating_segment tables w_426-loop1000_row-h3_occ

changing w_426-h3

w_nsegs.

endloop.

endif.

* PS occ

if px_wbty ne c_wbty-cancellation.

loop at w_wb-bnx_row-ps_occ into w_wb-ps.

move-corresponding w_wb-ps to w_426-ps.

perform store_repeating_segment tables w_426-loop1000_row-ps_occ

changing w_426-ps

w_nsegs.

endloop.

endif.

* Loop 1500 (LX loop)

if px_wbty ne c_wbty-cancellation.

* First, determine if contract PI segments are created at this point

* or directly under the BNX between loops 1300 and 1400 - they fall

* under the BNX if all freight L1's with an associated contract PI

* have no division number (is that confusing enough for you?)

w_flag-create_pi_under_bnx = abap_true.

loop at w_wb-bnx_row-lx_tab into w_wb-lx_row.

loop at w_wb-lx_row-l0_tab into w_wb-l0_row.

loop at w_wb-l0_row-l1_tab into w_wb-l1_row

where l1-charge_type eq c_l1_charge_type-freight

and l1-division_no ne space

and l1-division_no ne 0

and l1-division_no ne '000000000'.

read table w_wb-l0_row-pi_occ transporting no fields

with key ref_id_qual = c_pi_ref_id_qual-contract.

w_flag-create_pi_under_bnx = abap_false.

endloop.

endloop.

endloop.

* Fudge the weight qualifier on freight and fuel lines.

loop at w_wb-bnx_row-lx_tab assigning <lx_row>.

unassign <l0_prev>.

w_flag-first_l0_row = abap_true.

loop at <lx_row>-l0_tab assigning <l0_row>.

move abap_false to: w_flag-l1_fat,

w_flag-l1_freight,

w_flag-l1_fuel,

w_flag-l1_misc.

w_flag-create_l0_chunk = abap_true.

loop at <l0_row>-l1_tab transporting no fields

where l1-charge_type ne c_l1_charge_type-freight

and l1-charge_type ne c_l1_charge_type-fuel

and l1-charge_type ne c_l1_charge_type-fat.

w_flag-create_l0_chunk = abap_false.

exit.

endloop.

loop at <l0_row>-l1_tab into w_wb-l1_row.

case w_wb-l1_row-l1-charge_type.

when c_l1_charge_type-fat.

if w_waybill-bx-blkug_rev_type eq 'OH'

and w_waybill-bx-rating_source eq space.

w_flag-l1_fat = abap_true.

endif.

when c_l1_charge_type-freight.

w_flag-l1_freight = abap_true.

when c_l1_charge_type-fuel.

w_flag-l1_fuel = abap_true.

when c_l1_charge_type-misc.

w_flag-l1_misc = abap_true.

endcase.

endloop.

if w_flag-create_l0_chunk eq abap_true.

* Fudge the weight qualifier on freight and fuel lines.

loop at <l0_row>-l0_occ assigning <l0>.

if w_flag-l1_freight eq abap_true.

if w_flag-first_l0_row eq abap_true.

* First row.

<l0>-weight_qual = 'N'.

w_flag-first_l0_row = abap_false.

else.

* Subsequent L0 rows.

case <l0>-weight_qual.

when 'N'.

<l0>-weight_qual = 'B'.

when 'M'.

assign <l0> to <l0_prev>.

when 'O'.

if <l0_prev> is assigned.

<l0_prev>-weight_qual = 'X'.

unassign <l0_prev>.

endif.

endcase.

endif.

elseif w_flag-l1_fuel eq abap_true.

<l0>-weight_qual = c_weight_qual-minimum.

endif.

endloop.

endif.

endloop.

endloop.

loop at w_wb-bnx_row-lx_tab assigning <lx_row>.

* LX - mandatory

move-corresponding <lx_row>-lx to w_426-loop1500_row-lx.

perform increment_nsegs using w_426-loop1500_row-lx

changing w_nsegs.

* L5 occ - mandatory

loop at <lx_row>-l5_occ into w_wb-l5.

move-corresponding w_wb-l5 to w_426-l5.

perform store_repeating_segment

tables w_426-loop1500_row-l5_occ

changing w_426-l5

w_nsegs.

endloop.

* Loop 1510 (L0 loop)

loop at <lx_row>-l0_tab assigning <l0_row>.

move abap_false to: w_flag-l1_fat,

w_flag-l1_freight,

w_flag-l1_fuel,

w_flag-l1_misc.

w_flag-create_l0_chunk = abap_true.

* No L0 segments for miscellaneous charges

* read table <l0_row>-l1_tab

* with key l1-charge_type = '_MSG'

* transporting no fields.

* if sy-subrc eq 0.

* w_flag-create_l0_chunk = abap_false.

* endif.

loop at <l0_row>-l1_tab transporting no fields

where l1-charge_type ne c_l1_charge_type-freight

and l1-charge_type ne c_l1_charge_type-fuel

and l1-charge_type ne c_l1_charge_type-fat.

w_flag-create_l0_chunk = abap_false.

exit.

endloop.

* L0

* (assigned *after* the L1 as we may store division data

* from the L1 in the L0 segment)

* MEA occ

loop at <l0_row>-mea_occ into w_wb-mea.

move-corresponding w_wb-mea to w_426-mea.

perform store_repeating_segment

tables w_426-loop1510_row-mea_occ

changing w_426-mea

w_nsegs.

endloop.

* L1 occ (from L1 tab in Z tables)

* (we also capture extra data for the L0, Log & CUR segments;

* No L1 segments for a Rule 11 notification)

if px_wbty ne c_wbty-r11_notificn.

clear w_l010.

loop at <l0_row>-l1_tab into w_wb-l1_row.

case w_wb-l1_row-l1-charge_type.

when c_l1_charge_type-fat.

if w_waybill-bx-blkug_rev_type eq 'OH'

and w_waybill-bx-rating_source eq space.

w_flag-l1_fat = abap_true.

endif.

when c_l1_charge_type-freight.

w_flag-l1_freight = abap_true.

when c_l1_charge_type-fuel.

w_flag-l1_fuel = abap_true.

when c_l1_charge_type-misc.

w_flag-l1_misc = abap_true.

endcase.

* L0

if not w_wb-l1_row-l1-division_no is initial

and w_wb-l1_row-l1-division_no ne space

and w_wb-l1_row-l1-division_no ne 0

and w_wb-l1_row-l1-division_no ne '000000000'.

w_l010-source_sys = c_source_sys_sap.

w_l010-div_num = w_wb-l1_row-l1-division_no.

w_l010-div_versn = w_wb-l1_row-l1-division_versn.

endif.

* Log

if w_flag-l1_freight eq abap_true

or w_flag-l1_fuel eq abap_true

or w_flag-l1_fat eq abap_true

or w_flag-l1_misc eq abap_true.

if px_wbty = c_wbty-r11_notificn or "pure rule 11

( w_waybill-bx-blkug_rev_type eq 'OH' and

w_waybill-bx-rating_source eq space ).

clear w_edi426-log-total_l104.

else.

add w_wb-l1_row-l1-amount_charged

to w_edi426-log-total_l104.

endif.

endif.

* L1

* if w_flag-l1_fat eq abap_false.

if w_flag-l1_freight eq abap_true

or w_flag-l1_fuel eq abap_true

or w_flag-l1_misc eq abap_true.

move-corresponding w_wb-l1_row-l1 to w_426-l1.

if w_wb-l1_row-l1-charge_type = c_l1_charge_type-misc.

w_426-l1-special_chrg_dsc =

w_wb-l1_row-l1-misc_charge_scac.

endif.

perform store_repeating_segment

tables w_426-loop1510_row-l1_occ

changing w_426-l1

w_nsegs.

endif.

endloop.

endif.

* L0

if w_flag-create_l0_chunk eq abap_true.

describe table <l0_row>-l0_occ lines w_nlines.

* Now build the output L0.

loop at <l0_row>-l0_occ into w_wb-l0.

w_tabix_l0 = sy-tabix.

* Fill the output L0.

move-corresponding w_wb-l0 to w_426-l0.

* Some fudging of other L0 fields is also required.

if w_flag-l1_freight eq abap_true

and w_wb-l0-weight_unit_cd eq c_weight_unit-kilogram.

perform convert_weight_to_kilos using w_wb-l0-weight

changing w_426-l0-weight.

endif.

clear w_426-l0-weight_unit_cd.

clear w_426-l0-billd_rated_qual.

perform fill_with_zeroes using abap_true

changing w_426-l0-billd_rated_qty.

if w_tabix_l0 eq w_nlines

and not w_l010 is initial.

* We only fill the L010 (DUNNAGE_DESC) field for the L0

* immediately preceding an L1.

w_426-l0-dunnage_desc = w_l010.

endif.

perform store_repeating_segment

tables w_426-loop1510_row-l0_occ

changing w_426-l0

w_nsegs.

endloop.

endif.

* DTM occ

loop at <l0_row>-dtm_occ into w_wb-dtm.

move-corresponding w_wb-dtm to w_426-dtm03.

perform store_repeating_segment

tables w_426-loop1510_row-dtm_occ

changing w_426-dtm03

w_nsegs.

endloop.

* PI occ

read table <l0_row>-pi_occ index 1 into w_wb-pi.

if sy-subrc eq 0

and not ( w_waybill-bx-blkug_rev_type eq 'OH'

and w_waybill-bx-rating_source eq space ).

move-corresponding w_wb-pi to w_426-loop1510_row-pi.

* Fudge a couple of fields before storing them.

perform strip_leading_zeroes

using w_426-loop1510_row-pi-ref_id.

w_tariff_item_no_p = w_426-loop1510_row-pi-tariff_item_no.

divide w_tariff_item_no_p by 1000.

write w_tariff_item_no_p

to w_426-loop1510_row-pi-tariff_item_no left-justified

no-grouping

decimals 3.

if w_flag-l1_freight eq abap_false

or w_wb-pi-ref_id_qual ne c_pi_ref_id_qual-contract.

* Store PI under the L1

perform increment_nsegs using w_426-loop1510_row-pi

changing w_nsegs.

elseif w_flag-l1_freight eq abap_true

and w_wb-pi-ref_id_qual eq c_pi_ref_id_qual-contract

and w_flag-create_pi_under_bnx

eq abap_true.

* Store PI under the BNX (ensuring each row is unique)

* and under the L1

w_426-pi01-ref_id_qual = '19'.

w_426-pi01-ref_id = w_426-loop1510_row-pi-ref_id.

read table w_426-loop1000_row-pi_occ

transporting no fields

with key ref_id_qual = w_426-pi01-ref_id_qual.

if sy-subrc ne 0.

perform store_repeating_segment

tables w_426-loop1000_row-pi_occ

changing w_426-pi01

w_nsegs.

endif.

perform increment_nsegs using w_426-loop1510_row-pi

changing w_nsegs.

else.

* Stuff the PI.

clear w_426-loop1510_row-pi.

endif.

else.

clear w_426-loop1510_row-pi.

endif.

* if w_flag-create_l0_chunk eq abap_true.

* perform add_table_row

* tables w_426-loop1500_row-loop1510_tab

* changing w_426-loop1510_row.

* endif.

*

* * We only send L0/L1... data for certain charge types.

* if w_flag-l1_fat eq abap_true

* or w_flag-l1_freight eq abap_true

* or w_flag-l1_fuel eq abap_true

* or w_flag-l1_misc eq abap_true.

* perform add_table_row

* tables w_426-loop1500_row-loop1510_tab

* changing w_426-loop1510_row.

* endif.

* We only send L0/L1... data for certain charge types.

if w_flag-create_l0_chunk eq abap_true

or w_flag-l1_fat eq abap_true

or w_flag-l1_freight eq abap_true

or w_flag-l1_fuel eq abap_true

or w_flag-l1_misc eq abap_true.

perform add_table_row tables w_426-loop1500_row-loop1510_tab

changing w_426-loop1510_row.

endif.

endloop.

perform add_table_row tables w_426-loop1000_row-loop1500_tab

changing w_426-loop1500_row.

endloop.

endif.

** Loop 1600 (T1 loop)

* if px_wbty ne c_wbty-cancellation.

* loop at w_wb-bnx_row-t1_tab into w_wb-t1_row.

* * T1

* move-corresponding w_wb-t1_row-t1 to w_426-loop1600_row-t1.

* perform increment_nsegs using w_426-loop1600_row-t1

* changing w_nsegs.

* * T2 occ

* loop at w_wb-t1_row-t2_occ into w_wb-t2.

* move-corresponding w_wb-t2 to w_426-t2.

* perform store_repeating_segment

* tables w_426-loop1600_row-t2_occ

* changing w_426-t2

* w_nsegs.

* endloop.

* * T3 occ

* loop at w_wb-t1_row-t3_occ into w_wb-t3.

* move-corresponding w_wb-t3 to w_426-t3.

* perform store_repeating_segment

* tables w_426-loop1600_row-t3_occ

* changing w_426-t3

* w_nsegs.

* endloop.

*

* perform add_table_row tables w_426-loop1000_row-loop1600_tab

* changing w_426-loop1600_row.

* endloop.

* endif.

* L3

* (field L301 (weight) is not used)

if px_wbty ne c_wbty-cancellation.

move-corresponding w_wb-bnx_row-l3 to w_426-loop1000_row-l3.

perform fill_with_zeroes using abap_true

changing w_426-loop1000_row-l3-weight.

perform increment_nsegs using w_426-loop1000_row-l3

changing w_nsegs.

endif.

* L1A

* (the L1A is derived from data in other segments)

if px_wbty ne c_wbty-cancellation.

clear: w_426-l1a_dest,

w_426-l1a_orig.

w_426-l1a_dest-charge = w_wb-bnx_row-l3-amount_charged

- w_wb-bnx_row-l3-prepaid_amount.

perform format_number changing w_426-l1a_dest-charge.

* Destination L1A (amount to collect)

if w_426-l1a_dest-charge gt 0. "#EC PORTABLE

if px_wbty = c_wbty-r11_notificn OR

( w_waybill-bx-blkug_rev_type eq 'OH' and

w_waybill-bx-rating_source eq space ).

clear w_edi426-log-total_l1a01.

else.

add w_426-l1a_dest-charge to w_edi426-log-total_l1a01.

endif.

w_426-l1a_dest-scac = w_scac-dest.

perform store_repeating_segment

tables w_426-loop1000_row-l1a_occ

changing w_426-l1a_dest

w_nsegs.

endif.

* Origin L1A (amount prepaid)

if w_wb-bnx_row-l3-prepaid_amount gt 0. "#EC PORTABLE

*reversed the order of the followinf 2 statements for the control

*totals

w_426-l1a_orig-charge = w_wb-bnx_row-l3-prepaid_amount.

if px_wbty = c_wbty-r11_notificn OR

( w_waybill-bx-blkug_rev_type eq 'OH' and

w_waybill-bx-rating_source eq space ).

clear w_edi426-log-total_l1a01.

else.

add w_426-l1a_orig-charge to w_edi426-log-total_l1a01.

endif.

w_426-l1a_orig-scac = w_scac-orig.

perform store_repeating_segment

tables w_426-loop1000_row-l1a_occ

changing w_426-l1a_orig

w_nsegs.

endif.

endif.

perform add_table_row tables w_edi426-loop1000_tab

changing w_426-loop1000_row.

endloop.

* ZR - mandatory (deferred from above)

case px_wbty.

when c_wbty-cancellation.

w_edi426-zr-waybill_response_code = c_resp_code-cancellation.

w_edi426-zr-iss_status1 = w_edi426-zr-correction_ind = 'CA'.

when c_wbty-r11_notificn.

w_edi426-zr-waybill_response_code = c_resp_code-rule_11.

when others.

w_edi426-zr-waybill_response_code = c_resp_code-full_waybill.

endcase.

* w_edi426-zr-equip_initial = "Filled above from N7 segment

* w_edi426-zr-equip_number = "Filled above from N7 segment

* w_edi426-zr-equip_chk_digit = "Filled above from N7 segment

w_edi426-zr-waybill_no = w_edi426-so_status-waybill_num.

w_edi426-zr-date1 = w_edi426-so_status-waybill_date.

w_edi426-zr-settling_road = c_zr07_scac.

perform fill_with_zeroes using abap_true

changing w_edi426-zr-date2.

* Add special data for ZR06 (message) using structure ZFI_ARCH_426_ZR06.

clear w_zr06.

w_zr06-source_sys = c_source_sys_sap.

* w_zr06-fwseq_orig = w_edi426-so_status-fwseq_orig.

* w_zr06-fwseq = w_edi426-so_status-inv_number.

w_zr06-fwseq = w_edi426-so_status-fwseq_orig.

w_zr06-scac_orig = w_waybill-bx-scac.

if w_so_status-rule_11 eq abap_true.

w_zr06-rule_11 = c_resp_code-rule_11.

if px_wbty eq c_wbty-r11_revenue

and w_so_status-rule_11_type ne space.

w_zr06-rule_11_child = 'Y'.

else.

w_zr06-rule_11_child = space.

endif.

else.

w_zr06-rule_11 = space.

w_zr06-rule_11_child = space.

endif.

if w_so_status-cancellation eq abap_true.

w_edi426-zr-iss_status1 = c_zr09_iss_status1-cancel.

else.

w_edi426-zr-iss_status1 = c_zr09_iss_status1-internal.

endif.

** Posted date currently uses same convention as the BW extract

** to presume the date the waybill was entered on Fastway.

* w_zr06-posted_date = w_so_status-erdat - 1.

* Posted date from FI.

w_zr06-posted_date = w_so_status-budat.

* The field DOCNUM is assigned later during the MQ translation

* but we'll enter a dummy value for a test run.

if p_test eq abap_true.

w_zr06-docnum = c_test_docnum.

w_zr06-iface_batch_no = c_test_batch_no.

else.

w_zr06-iface_batch_no = w_zar_iface_cntl_curr-batch_no.

endif.

w_edi426-zr-message = w_zr06.

perform increment_nsegs using w_edi426-zr

changing w_nsegs.

* SE - mandatory for EDI but not required for direct transfer to ISS

* add 1 to w_nsegs.

* w_edi426-se-num_segments = w_nsegs.

* w_edi426-se-control_number = w_edi426-st-control_number.

* Log - mandatory (deferred from above)

* This segment is used for writing application log messages in the IDoc

* translation routine.

w_edi426-log-object = w_object.

w_edi426-log-subobject = w_subobject.

w_edi426-log-extnumber = w_extnumber.

w_edi426-log-fwset = w_arch_set-fwset.

w_edi426-log-versn = w_arch_set-versn.

* Following two fields are assigned above:

* w_edi426-log-total_l1a01

* w_edi426-log-total_l104

perform increment_nsegs using w_edi426-log

changing w_nsegs.

* Edit the new waybill to fit requirements for Rule 11.5, etc.

* (This must be performed before we add segment ID's since we may clear

* the contents of an entire segment and we wouldn't want to lose the ID)

if px_wbty ne c_wbty-cancellation.

perform massage_edi_426_message using px_wbty.

endif.

* Add the segment ID to all segments containing that field;

* check that required fields are present; and transform numeric fields

* according to the formats defined in table ZFI_ISS_FIELDS.

perform add_seg_id_to_all_segments changing w_edi426.

*added by Sandhya : issue 1658

if flag_idler = 1.

loop at w_edi426-bx_occ into w_426-bx.

w_426-bx-ship_qualifier = 'B'.

modify w_edi426-bx_occ from w_426-bx.

endloop.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

w_426-loop1000_row-bnx-billing_code = 'S'.

modify w_edi426-loop1000_tab from w_426-loop1000_row.

endloop.

endif.

*end:added by sandhya

*Store the IDoc segments

append w_edi426 to t_edi426.

clear w_edi426.

endform.

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

form calculate_control_totals.

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

* Calculate the control totals.

clear: w_nidocs,

w_total_l1a01,

w_total_l104.

loop at t_edi426 assigning <edi426>.

add 1 to w_nidocs.

add <edi426>-log-total_l1a01 to w_total_l1a01.

add <edi426>-log-total_l104 to w_total_l104.

endloop.

* Pad the totals with leading zeroes and, if negative, a leading sign.

perform format_number changing: w_total_l1a01,

w_total_l104.

* Store the control totals on each IDoc

* (since we use field-symbols, we modify the table directly).

w_nte02-total_idocs = w_nidocs.

w_nte02-total_l1a01 = w_total_l1a01.

w_nte02-total_l104 = w_total_l104.

if p_test eq abap_true.

w_nte02-iface_batch_no = c_test_batch_no.

else.

w_nte02-iface_batch_no = w_zar_iface_cntl_curr-batch_no.

endif.

loop at t_edi426 assigning <edi426>.

read table <edi426>-nte_occ

with key note_ref_code = c_source_sys_sap

assigning <nte>.

if sy-subrc eq 0.

<nte>-description = w_nte02.

endif.

endloop.

endform.

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

form convert_weight_to_kilos using px_weight

changing py_weight.

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

* Convert kilos to stupid old-fashioned pounds

data: begin of l_msehi,

in type msehi value 'KG',

out type msehi value 'LB',

end of l_msehi.

data: l_input(6) type p,

l_output(6) type p.

l_input = px_weight.

call function 'UNIT_CONVERSION_SIMPLE'

exporting

input = l_input

NO_TYPE_CHECK = 'X'

ROUND_SIGN = space

UNIT_IN = l_msehi-in

UNIT_OUT = l_msehi-out

IMPORTING

OUTPUT = l_output

EXCEPTIONS

OTHERS = 10.

if sy-subrc ne 0.

l_output = '2.204623' * l_input.

endif.

write l_output to py_weight right-justified no-grouping no-sign.

perform fill_with_zeroes using abap_false

changing py_weight.

endform.

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

form create_idocs.

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

check p_test eq abap_false.

perform get_own_logical_system.

loop at t_edi426 into w_edi426.

* Fill IDoc control record

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

w_edidc-docnum = 1.

w_edidc-direct = zcl_arch_ifaces=>c_idoc_outbound.

w_edidc-mestyp = 'ZEDI426'.

w_edidc-idoctp = 'ZEDI426001'.

* Receiver

w_edidc-rcvpor = c_rcvpor.

w_edidc-rcvprt = c_rcvprt.

w_edidc-rcvprn = c_rcvprn.

* Sender (can be allowed to default)

concatenate 'SAP' sy-sysid into w_edidc-sndpor.

w_edidc-sndprt = 'LS'.

w_edidc-sndprn = w_logsys.

* Fill IDoc segment table

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

w_hlevel = 1.

clear: w_psgnum,

w_segnum.

* Log

perform add_single_segment using w_edi426-log.

* HDR

perform add_single_segment using w_edi426-hdr.

* ST

perform add_single_segment using w_edi426-st.

* ZR

perform add_single_segment using w_edi426-zr.

* N9 occ

perform add_repeat_segment tables w_edi426-n9_occ.

* DTM occ

perform add_repeat_segment tables w_edi426-dtm_occ.

* CUR

perform add_single_segment using w_edi426-cur.

* NTE occ

perform add_repeat_segment tables w_edi426-nte_occ.

* PER occ

perform add_repeat_segment tables w_edi426-per_occ.

* BX occ

perform add_repeat_segment tables w_edi426-bx_occ.

* Loop 1000 (BNX loop)

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1000'.

* BNX

perform add_single_segment using w_426-loop1000_row-bnx.

* N9 occ

perform add_repeat_segment tables w_426-loop1000_row-n9_occ.

* DTM occ

perform add_repeat_segment tables w_426-loop1000_row-dtm_occ.

* Loop 1100 (N7 loop)

loop at w_426-loop1000_row-loop1100_tab into w_426-loop1100_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1100'.

* N7

perform add_single_segment using w_426-loop1100_row-n7.

* VC occ

perform add_repeat_segment tables w_426-loop1100_row-vc_occ.

* IC

perform add_single_segment using w_426-loop1100_row-ic.

* G4

perform add_single_segment using w_426-loop1100_row-g4.

* M7 occ

perform add_repeat_segment tables w_426-loop1100_row-m7_occ.

* N5

perform add_single_segment using w_426-loop1100_row-n5.

* GA occ

perform add_repeat_segment tables w_426-loop1100_row-ga_occ.

* Loop 1100 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* N8 occ

perform add_repeat_segment tables w_426-loop1000_row-n8_occ.

* N8A occ

perform add_repeat_segment tables w_426-loop1000_row-n8a_occ.

* V9

perform add_single_segment using w_426-loop1000_row-v9.

* F9

perform add_single_segment using w_426-loop1000_row-f9.

* D9

perform add_single_segment using w_426-loop1000_row-d9.

* Loop 1200 (N1 loop)

loop at w_426-loop1000_row-loop1200_tab into w_426-loop1200_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1200'.

* N1

perform add_single_segment using w_426-loop1200_row-n1.

* N2 occ

perform add_repeat_segment tables w_426-loop1200_row-n2_occ.

* N3 occ

perform add_repeat_segment tables w_426-loop1200_row-n3_occ.

* N4

perform add_single_segment using w_426-loop1200_row-n4.

* PER occ

perform add_repeat_segment tables w_426-loop1200_row-per_occ.

* BL occ

perform add_repeat_segment tables w_426-loop1200_row-bl_occ.

* Loop 1200 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* Loop 1300 (S1 loop)

loop at w_426-loop1000_row-loop1300_tab into w_426-loop1300_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1300'.

* S1

perform add_single_segment using w_426-loop1300_row-s1.

* S9

perform add_single_segment using w_426-loop1300_row-s9.

* Loop 1300 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* PI occ

perform add_repeat_segment tables w_426-loop1000_row-pi_occ.

* Loop 1400 (R2 loop)

loop at w_426-loop1000_row-loop1400_tab into w_426-loop1400_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1400'.

* R2

perform add_single_segment using w_426-loop1400_row-r2.

* Loop 1410

loop at w_426-loop1400_row-loop1410_tab into w_426-loop1410_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1410'.

* R2B

perform add_single_segment using w_426-loop1410_row-r2b.

* R2C occ

perform add_repeat_segment tables w_426-loop1410_row-r2c_occ.

* R2D occ

perform add_repeat_segment tables w_426-loop1410_row-r2d_occ.

* Loop 1410 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* Loop 1400 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* R9

perform add_single_segment using w_426-loop1000_row-r9.

* H3 occ

perform add_repeat_segment tables w_426-loop1000_row-h3_occ.

* PS occ

perform add_repeat_segment tables w_426-loop1000_row-ps_occ.

* Loop 1500 (LX loop)

loop at w_426-loop1000_row-loop1500_tab into w_426-loop1500_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1500'.

* LX

perform add_single_segment using w_426-loop1500_row-lx.

* L5 occ

perform add_repeat_segment tables w_426-loop1500_row-l5_occ.

* Loop 1510 (L0 loop)

loop at w_426-loop1500_row-loop1510_tab into w_426-loop1510_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1510'.

* L0

perform add_repeat_segment tables w_426-loop1510_row-l0_occ.

* MEA occ

perform add_repeat_segment tables w_426-loop1510_row-mea_occ.

* L1 occ

perform add_repeat_segment tables w_426-loop1510_row-l1_occ.

* DTM occ

perform add_repeat_segment tables w_426-loop1510_row-dtm_occ.

* PI

perform add_single_segment using w_426-loop1510_row-pi.

* Loop 1510 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* Loop 1500 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* Loop 1600 (T1 loop)

loop at w_426-loop1000_row-loop1600_tab into w_426-loop1600_row.

at first.

perform store_hlevel_psgnum.

endat.

perform add_loop_segment using 'Z1EDI426LOOP1600'.

* T1

perform add_single_segment using w_426-loop1600_row-t1.

* T2 occ

perform add_repeat_segment tables w_426-loop1600_row-t2_occ.

* T3 occ

perform add_repeat_segment tables w_426-loop1600_row-t3_occ.

* T6

perform add_single_segment using w_426-loop1600_row-t6.

* T8 occ

perform add_repeat_segment tables w_426-loop1600_row-t8_occ.

* Loop 1600 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* L3

perform add_single_segment using w_426-loop1000_row-l3.

* L1A occ

perform add_repeat_segment tables w_426-loop1000_row-l1a_occ.

* Loop 1000 ends

at last.

perform restore_hlevel_psgnum.

endat.

endloop.

* SE

perform add_single_segment using w_edi426-se.

* Create IDoc

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

CALL METHOD O_IFACE1->CREATE_OUTBOUND_IDOC

EXPORTING

X_EDIDC = w_edidc

XT_EDIDD = t_edidd

IMPORTING

YT_EDIDC = t_edidc_comm

EXCEPTIONS

CREATE_ERROR = 1

others = 2.

if sy-subrc eq 0.

clear w_edidc_comm.

read table t_edidc_comm index 1 into w_edidc_comm.

move-corresponding w_edi426-arch_set to w_arch_set.

* If required fields are missing values, set status to 26

* (Error during syntax check of IDoc (outbound)).

loop at t_required into w_required where arch_set eq w_arch_set.

perform set_idoc_status using w_edidc_comm-docnum

'26'

w_required.

endloop.

if sy-subrc eq 0.

add 1 to w_count-bad_idoc.

else.

add 1 to w_count-good_idoc.

endif.

* Change the waybill status to SENT TO ISS.

Data: w_change_status type zsd_arch_change_status.

clear w_statuses.

w_statuses-stset = zvast_stset-sent_to_iss.

Move-corresponding w_statuses to w_change_status.

W_change_status-docnum = w_edidc_comm-docnum.

*New design Changes : Added by Sandhya

wa_dt_tm-type = 'I'.

wa_dt_tm-

CALL METHOD ZCL_ARCH_WAYBILL=>UPDATE_WAYBILL_STATUS

EXPORTING

X_ARCH_SET = w_arch_set

X_GET_VERSION = abap_true

X_CHANGE_STATUS = w_change_status

* X_DOCNUM = w_edidc_comm-docnum

EXCEPTIONS

NO_FWSET = 1

BAD_DATA = 2

CANNOT_UPDATE = 3

others = 4.

if sy-subrc ne 0.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = w_edidc_comm-docnum

IMPORTING

OUTPUT = w_docnum_c-first.

perform add_iface_msg_with_waybill using 'E' 'I'

'ZFI_ISS'

'014'

w_docnum_c-first

w_arch_set-fwset

w_arch_set-versn

space

w_edidc_comm-docnum

w_arch_set-fwset

w_arch_set-versn

abap_false.

** Created IDoc &1 but failed to set Sent status on FW set &2 versn &3

* endif.

commit work.

add 1 to w_count-idoc.

else.

* IDoc error handling

* (method has also written application log)

rollback work.

add 1 to w_count-failed_idoc.

perform add_iface_msg using 'E' 'I'

'ZFI_ISS'

'013'

w_edi426-zr-waybill_no

space space space

space abap_false.

* Failed to create outbound IDoc for waybill &1

endif.

* Store first and last IDoc numbers for reporting purposes

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

at first.

read table t_edidc_comm index 1 into w_edidc_comm.

if sy-subrc eq 0.

w_docnum-first = w_edidc_comm-docnum.

endif.

endat.

at last.

describe table t_edidc_comm lines w_nlines.

read table t_edidc_comm index w_nlines into w_edidc_comm.

if sy-subrc eq 0.

w_docnum-last = w_edidc_comm-docnum.

endif.

endat.

* Tidy up IDoc work areas

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

clear: w_edidc,

t_edidc_comm,

w_edidc_comm,

t_edidd.

clear: t_stack,

w_stack.

endloop.

* Messages

**********

if w_count-bad_idoc gt 0. "#EC PORTABLE

* If IDocs had missing values, report number of good and bad IDocs

perform add_iface_msg using 'W' 'I'

'ZFI_ISS'

'018'

w_count-bad_idoc

space space space

space abap_false.

* Created &1 IDocs with missing values

perform add_iface_msg using 'I' 'I'

'ZFI_ISS'

'019'

w_count-good_idoc

space space space

space abap_false.

* Created &1 IDocs with no missing values

endif.

* Total IDocs created

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = w_docnum-first

IMPORTING

OUTPUT = w_docnum_c-first.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

INPUT = w_docnum-last

IMPORTING

OUTPUT = w_docnum_c-last.

perform add_iface_msg using 'S' 'S'

'ZFI_ISS'

'016'

w_count-idoc

w_docnum_c-first

w_docnum_c-last

space

space abap_false.

* Created &1 IDocs numbered between &2 and &3

if w_count-failed_idoc gt 0. "#EC PORTABLE

* IDocs that could not be created

perform add_iface_msg using 'W' 'I'

'ZFI_ISS'

'020'

w_count-failed_idoc

space space space

space abap_false.

* Failed to create &1 IDocs (see other log messages for this run)

endif.

endform.

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

form derive_segment_id using px_absname

changing py_seg_id.

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

* Segment name is of the form Z1EDI426ab01 - we want 'ab'

* or Z1EDI426abc01 - we want 'abc'

* or Z1EDI426LOOPnnnn - ignore

data: l_length type i.

l_length = strlen( px_absname ).

case l_length.

when 18. "2-char segment, e.g. 'BX'

py_seg_id = px_absname+14(2).

when 19. "3-char segment, e.g. 'BNX'

py_seg_id = px_absname+14(3).

when others. "Loop segment, e.g. LOOP1200

clear py_seg_id.

exit.

endcase.

endform.

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

form fill_with_zeroes using px_allbytes type flag

changing pxy_value.

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

* Fill a field with zeroes. Change all bytes if flag is True; else only

* change bytes at initial value.

data: l_length type i,

l_offset type i,

l_type type c.

field-symbols: <char> type c.

* Only for character fields.

describe field pxy_value type l_type.

check l_type eq 'C'.

describe field pxy_value length l_length.

l_offset = 0.

while l_offset lt l_length.

assign pxy_value+l_offset(1) to <char>.

if sy-subrc ne 0.

exit.

endif.

if px_allbytes eq abap_true

or <char> is initial.

<char> = '0'.

endif.

add 1 to l_offset.

endwhile.

endform.

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

form format_number changing pxy_number.

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

* Ensure a number value is right-justified and filled with leading

* zeroes. If the value is negative, include a leading sign.

CALL FUNCTION 'Z_FORMAT_NUMBER'

CHANGING

XY_NUMBER = pxy_number

EXCEPTIONS

OTHERS = 0.

* NOT_NUMERIC = 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.

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

form gather_pending_waybills.

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

* Collect all waybills marked Ready for ISS.

* select * into corresponding fields of table t_so_status

* from zsd_wb_so_status

* where fwset in s_fwset

* and versn in s_versn

* and stset eq zvast_stset-ready.

select * into corresponding fields of table t_so_status

from zsd_wb_so_status

where fwset in s_fwset

and versn in s_versn

and stset eq zvast_stset-ready

and interline eq abap_true

and iss_date ge start_dt

and iss_date le end_dt.

loop at t_so_status.

if start_dt eq end_dt.

if t_so_status-iss_date = start_dt and

t_so_status-iss_time ge start_tm and

t_so_status-iss_time le end_tm.

continue.

else.

delete t_so_status index sy-tabix.

endif.

elseif start_dt ne end_dt.

if ( t_so_status-iss_date gt start_dt and

t_so_status-iss_date lt end_dt ) or

( t_so_status-iss_date eq start_dt and

t_so_status-iss_time ge start_tm ) or

( t_so_status-iss_date = end_dt and

t_so_status-iss_time le end_tm ).

continue.

else.

delete t_so_status index sy-tabix.

endif.

endif.

endloop.

if t_so_status[] is initial.

write:/ 'No waybills selected'.

stop.

endif.

sort t_so_status by fwset versn.

save_date = sy-datum.

save_time = sy-uzeit.

*added by sandhya for new design changes

loop at t_so_status into w_so_status.

if w_so_status-cancellation = 'X'.

w_so_status-cancellation = abap_true.

modify t_so_status from w_so_status index sy-tabix.

continue.

endif.

if w_so_status-source = 'NAIO' or

w_so_status-source = 'NAIS'.

select * into corresponding fields of table t_so_status1

from zsd_wb_so_status

where fwset = w_so_status-fwset and

versn lt w_so_status-versn and

iss_date ne space and

iss_time ne space

order by versn descending.

if sy-subrc eq 0.

read table t_so_status1 index 1.

move-corresponding t_so_status1 to w_so_status.

w_so_status-cancellation = abap_true.

append w_so_status to t_so_status.

endif.

clear t_so_status1.

refresh t_so_status1.

endif.

endloop.

endform.

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

form gather_valid_id_codes.

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

* Build ranges containing valid N1 and N9 codes to determine

* which of these segments should be added to the IDocs.

check not t_so_status is initial.

select * into table t_iss_id_codes

from zfi_iss_id_codes

where segment eq 'N1'

or segment eq 'N9'.

wa_n101-sign = wa_n901-sign = 'I'.

wa_n101-option = wa_n901-option = 'EQ'.

loop at t_iss_id_codes into w_iss_id_codes.

case w_iss_id_codes-segment.

when 'N1'.

wa_n101-low = w_iss_id_codes-id_code.

append wa_n101 to r_n101.

when 'N9'.

wa_n901-low = w_iss_id_codes-id_code.

append wa_n901 to r_n901.

endcase.

endloop.

endform.

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

form get_own_logical_system.

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

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

OWN_LOGICAL_SYSTEM = w_logsys

EXCEPTIONS

OWN_LOGICAL_SYSTEM_NOT_DEFINED = 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.

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

form get_junction_settlement_scac

using px_code

px_r2_tab type zfa01_loop1400_tab

changing py_scac.

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

data: l_r2_row type zfa01_loop1400_row.

clear py_scac.

read table px_r2_tab with key r2-routing_seq_code = px_code

into l_r2_row.

if sy-subrc eq 0.

py_scac = l_r2_row-r2-scac.

endif.

endform.

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

form get_st_control_number changing py_control_number.

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

* Get the next EDI transaction set control number

clear py_control_number.

if p_test eq abap_true.

py_control_number = c_dummy_ctl_num.

else.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

NR_RANGE_NR = '01'

OBJECT = 'ZAR_ISSO'

IMPORTING

NUMBER = py_control_number

EXCEPTIONS

OTHERS = 8.

IF SY-SUBRC <> 0.

perform add_iface_msg using sy-msgty sy-msgty

sy-msgid

sy-msgno

sy-msgv1 sy-msgv2

sy-msgv3 sy-msgv4

space abap_true.

ENDIF.

endif.

endform.

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

form increment_nsegs using px_segment

changing pxy_nsegs.

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

* We only incremement the number of segments (for the SE segment) if

* the segment includes a segment ID (i.e. is a segment that is sent to

* ISS).

* This will also increment the number of segments for the NTE control

* totals segment. However, for most IDocs, this segment is not sent to

* ISS. The adjustment to the SE total is made in the MQ translation

* function.

data: lo_strucref type ref to cl_abap_structdescr,

lo_typeref type ref to cl_abap_typedescr.

data: lt_component type abap_compdescr_tab,

l_component type abap_compdescr.

if not px_segment is initial.

lo_typeref = cl_abap_typedescr=>describe_by_data( px_segment ).

lo_strucref ?= lo_typeref.

lt_component = lo_strucref->components.

read table lt_component index 1 into l_component.

if l_component-name eq 'SEG_ID'.

add 1 to pxy_nsegs.

endif.

endif.

endform.

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

form massage_edi_426_message using px_wbty.

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

* Special handling of Rule 11.5 child waybills, followed by some

* junction settlement stuff and then some more crap.

* Waybill types (global constants):

****** Waybill types (to determine what to write to the IDoc)

*****constants: begin of c_wbty,

***** normal type char1 value '1',

***** r11_notificn type char1 value '2',

***** r11_revenue type char1 value '3',

***** end of c_wbty.

* The "r11_revenue" type is the "child" waybill

* Steps (1) and (2) are relevant for "child" waybills only. I guess

* adults can look after themselves.

if px_wbty eq c_wbty-r11_revenue.

clear: w_flag-scac_dropped_first,

w_flag-scac_dropped_last.

* (1) Build subset of complete routing

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

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

* Delete lines that are not part of the subset.

describe table w_426-loop1000_row-loop1400_tab lines w_nlines.

loop at w_426-loop1000_row-loop1400_tab into w_426-loop1400_row.

if not ( w_426-loop1400_row-r2-scac eq w_routing-scac1

or w_426-loop1400_row-r2-scac eq w_routing-scac2

or w_426-loop1400_row-r2-scac eq w_routing-scac3

or w_426-loop1400_row-r2-scac eq w_routing-scac4

or w_426-loop1400_row-r2-scac eq w_routing-scac5

or w_426-loop1400_row-r2-scac eq w_routing-scac6 ).

if sy-tabix eq 1.

w_flag-scac_dropped_first = abap_true.

elseif sy-tabix = w_nlines.

w_flag-scac_dropped_last = abap_true.

endif.

delete w_426-loop1000_row-loop1400_tab index sy-tabix.

subtract 1 from w_nlines.

endif.

endloop.

* Adjust the routing sequence codes.

clear w_routing_seq_code.

describe table w_426-loop1000_row-loop1400_tab lines w_nlines.

loop at w_426-loop1000_row-loop1400_tab into w_426-loop1400_row.

case sy-tabix.

when 1.

* First R2 is "A" if not already "JO" (how appropriate).

if w_426-loop1400_row-r2-routing_seq_code ne 'JO'.

w_426-loop1400_row-r2-routing_seq_code = 'A'.

endif.

when w_nlines.

* Last R2 is incremented if not already "JD".

if w_426-loop1400_row-r2-routing_seq_code ne 'JD'.

add 1 to w_routing_seq_code.

w_426-loop1400_row-r2-routing_seq_code =

w_routing_seq_code.

perform strip_leading_zeroes

changing w_426-loop1400_row-r2-routing_seq_code.

endif.

when others.

* Intermediate R2's are incremented.

add 1 to w_routing_seq_code.

w_426-loop1400_row-r2-routing_seq_code =

w_routing_seq_code.

perform strip_leading_zeroes

changing w_426-loop1400_row-r2-routing_seq_code.

endcase.

modify w_426-loop1000_row-loop1400_tab

from w_426-loop1400_row.

endloop.

* Update the waybill.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting loop1400_tab.

endloop.

* (2) Adjust BX, F9 (origin) and D9 (destination)

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

* BX

loop at w_edi426-bx_occ into w_426-bx.

w_426-bx-ship_method_code = w_waybill-b3b-ship_method_pay.

modify w_edi426-bx_occ from w_426-bx.

endloop.

if w_flag-scac_dropped_first eq abap_true

or w_flag-scac_dropped_last eq abap_true.

loop at w_waybill-bnx_tab into w_wb-bnx_row.

if w_flag-scac_dropped_first eq abap_true.

* Origin F9

read table w_wb-bnx_row-r2x_occ index 1

into w_wb-r2x.

if sy-subrc eq 0.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

clear w_426-loop1000_row-f9.

w_426-loop1000_row-f9-frt_stn_acc_cd1 =

w_wb-r2x-n_stn_no.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting f9.

endloop.

endif.

endif.

if w_flag-scac_dropped_last eq abap_true.

* Destination D9

describe table w_wb-bnx_row-r2x_occ lines w_nlines.

read table w_wb-bnx_row-r2x_occ index w_nlines

into w_wb-r2x.

if sy-subrc eq 0.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

clear w_426-loop1000_row-d9.

w_426-loop1000_row-d9-frt_acc_stn_cd1 =

w_wb-r2x-n_rtg_dest_stn+1(5).

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting d9.

endloop.

endif.

endif.

endloop.

* If the last R2 SCAC was dropped, then drop the City name on the

* previous R2 (which is now the last one).

if w_flag-scac_dropped_last eq abap_true.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

describe table w_426-loop1000_row-loop1400_tab lines w_nlines.

read table w_426-loop1000_row-loop1400_tab index w_nlines

into w_426-loop1400_row.

if sy-subrc eq 0.

w_tabix = sy-tabix.

clear w_426-loop1400_row-r2-city_name.

modify w_426-loop1000_row-loop1400_tab index w_tabix

from w_426-loop1400_row

transporting r2.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting loop1400_tab.

endif.

endloop.

endif.

endif.

endif. "px_wbty

* (3) Junction settlement logic

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

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

* NTE - Junction settlement info based on F9 and D9

* (we also move data within F9 and D9)

clear w_nte_junc.

* Origin

* if not w_426-loop1000_row-f9-frt_stn_acc_cd2 is initial

* or not w_426-loop1000_row-f9-city_name2 is initial

* or not w_426-loop1000_row-f9-province2 is initial.

if w_flag-junc_settle_f9 eq abap_true.

* Data for the NTE02

perform get_junction_settlement_scac

using c_r202-orig

w_426-loop1000_row-loop1400_tab

changing w_nte02_junc-orig-scac.

if not w_nte02_junc-orig-scac is initial.

w_nte02_junc-orig-fsac = w_426-loop1000_row-f9-frt_stn_acc_cd1.

* Texts for the NTE02

move-corresponding c_junc_text-orig to w_nte02_junc-orig.

* Store the NTE segment

w_nte_junc-orig-description = w_nte02_junc-orig.

perform store_repeating_segment tables w_edi426-nte_occ

changing w_nte_junc-orig

w_nsegs.

endif.

* Move data within F9

w_426-loop1000_row-f9-frt_stn_acc_cd1 =

w_426-loop1000_row-f9-frt_stn_acc_cd2.

w_426-loop1000_row-f9-city_name1 =

w_426-loop1000_row-f9-city_name2.

w_426-loop1000_row-f9-province1 =

w_426-loop1000_row-f9-province2.

w_426-loop1000_row-f9-splc1 =

w_426-loop1000_row-f9-splc2.

clear: w_426-loop1000_row-f9-splc2,

w_426-loop1000_row-f9-frt_stn_acc_cd2,

w_426-loop1000_row-f9-city_name2,

w_426-loop1000_row-f9-province2.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting f9.

endif.

* Destination

* if not w_426-loop1000_row-d9-frt_acc_stn_cd2 is initial

* or not w_426-loop1000_row-d9-city_name2 is initial

* or not w_426-loop1000_row-d9-province2 is initial.

if w_flag-junc_settle_d9 eq abap_true.

* Data for the NTE02

perform get_junction_settlement_scac

using c_r202-dest

w_426-loop1000_row-loop1400_tab

changing w_nte02_junc-dest-scac.

if not w_nte02_junc-dest-scac is initial.

w_nte02_junc-dest-fsac = w_426-loop1000_row-d9-frt_acc_stn_cd1.

* Texts for the NTE02

move-corresponding c_junc_text-dest to w_nte02_junc-dest.

* Store the NTE segment

w_nte_junc-dest-description = w_nte02_junc-dest.

perform store_repeating_segment tables w_edi426-nte_occ

changing w_nte_junc-dest

w_nsegs.

endif.

* Move data within D9

w_426-loop1000_row-d9-frt_acc_stn_cd1 =

w_426-loop1000_row-d9-frt_acc_stn_cd2.

w_426-loop1000_row-d9-city_name1 =

w_426-loop1000_row-d9-city_name2.

w_426-loop1000_row-d9-province1 =

w_426-loop1000_row-d9-province2.

w_426-loop1000_row-d9-splc1 =

w_426-loop1000_row-d9-splc2.

clear: w_426-loop1000_row-d9-splc2,

w_426-loop1000_row-d9-frt_acc_stn_cd2,

w_426-loop1000_row-d9-city_name2,

w_426-loop1000_row-d9-province2.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting d9.

endif.

endloop.

* (4) Common logic after Rule 11.5 child and junction settlement logic

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

* ZR and BX

clear w_426-r2.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

loop at w_426-loop1000_row-loop1400_tab into w_426-loop1400_row

where r2-routing_seq_code ne 'JO'.

w_426-r2 = w_426-loop1400_row-r2.

exit.

endloop.

exit.

endloop.

read table w_edi426-bx_occ index 1 into w_426-bx.

if sy-subrc eq 0.

w_426-bx-scac = w_426-r2-scac.

modify w_edi426-bx_occ index 1 from w_426-bx.

endif.

w_zr06 = w_edi426-zr-message.

w_zr06-scac_orig = w_426-r2-scac.

w_edi426-zr-message = w_zr06.

* L1A

if px_wbty eq c_wbty-r11_notificn

or ( w_waybill-bx-blkug_rev_type eq 'OH'

and w_waybill-bx-rating_source eq space ).

* No L1A required for Rule 11 notifications

* or when BX has certain values.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

clear w_426-loop1000_row-l1a_occ.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting l1a_occ.

endloop.

else.

* Otherwise, L1A SCAC comes from an R2 segment.

clear: w_scac_r2.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

loop at w_426-loop1000_row-loop1400_tab into w_426-loop1400_row

where r2-routing_seq_code ne 'JO'

and r2-routing_seq_code ne 'JD'.

w_scac_r2 = w_426-loop1400_row-r2-scac.

if w_waybill-b3b-ship_method_pay eq 'PP'.

exit.

endif.

endloop.

loop at w_426-loop1000_row-l1a_occ into w_426-l1a.

w_426-l1a-scac = w_scac_r2.

modify w_426-loop1000_row-l1a_occ from w_426-l1a.

endloop.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting l1a_occ.

endloop.

endif.

* L0, etc, and L3 are not required for Rule 11 notifications.

if px_wbty eq c_wbty-r11_notificn.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

loop at w_426-loop1000_row-loop1500_tab into w_426-loop1500_row.

clear w_426-loop1500_row-loop1510_tab.

modify w_426-loop1000_row-loop1500_tab

from w_426-loop1500_row

transporting loop1510_tab.

endloop.

clear w_426-loop1000_row-l3.

modify w_edi426-loop1000_tab from w_426-loop1000_row

transporting loop1500_tab l3.

endloop.

endif.

* L1 and L3

if w_waybill-bx-blkug_rev_type eq 'OH'

and w_waybill-bx-rating_source eq space.

loop at w_edi426-loop1000_tab into w_426-loop1000_row.

loop at w_426-loop1000_row-loop1500_tab into w_426-loop1500_row.

loop at w_426-loop1500_row-loop1510_tab into w_426-loop1510_row.

clear w_426-loop1510_row-l1_occ.

modify w_426-loop1500_row-loop1510_tab

from w_426-loop1510_row.

endloop.

modify w_426-loop1000_row-loop1500_tab from w_426-loop1500_row.

endloop.

clear: w_426-loop1000_row-l3-amount_charged,

w_426-loop1000_row-l3-prepaid_amount.

modify w_edi426-loop1000_tab from w_426-loop1000_row.

endloop.

endif.

* N9

clear w_426-n9-date1.

modify w_edi426-n9_occ from w_426-n9

transporting date1

where ref_id_qual eq 'WM'.

endform.

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

form move_fsac using px_fsac

changing py_fsac.

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

* If output FSAC is shorter than the input FSAC, move the rightmost

* characters from the input to fill the output.

data: l_len_px type i,

l_len_py type i,

l_offset type i.

describe: field px_fsac length l_len_px,

field py_fsac length l_len_py.

l_offset = l_len_px - l_len_py.

if l_offset le 0.

exit.

endif.

py_fsac = px_fsac+l_offset(l_len_py).

endform.

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

form populate_hdr_segment using px_st_control_num.

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

add 1 to w_trans_ctl_number.

w_edi426-hdr-sender = 'CPRS'.

w_edi426-hdr-group_date = sy-datum.

w_edi426-hdr-group_time = sy-uzeit.

w_edi426-hdr-trans_set_id = '426'.

w_edi426-hdr-trans_ctl_number = px_st_control_num.

w_edi426-hdr-trans_suffix = '00'.

w_edi426-hdr-version = '005010RAIL'.

* Get unique number for the MQ message.

if p_test eq abap_true.

w_edi426-hdr-group_ctl_number = c_dummy_ctl_num.

else.

CALL FUNCTION 'NUMBER_GET_NEXT'

EXPORTING

NR_RANGE_NR = '01'

OBJECT = 'ZAR_ISSMQ'

IMPORTING

NUMBER = w_mq_msg_num

EXCEPTIONS

INTERVAL_NOT_FOUND = 1

NUMBER_RANGE_NOT_INTERN = 2

OBJECT_NOT_FOUND = 3

QUANTITY_IS_0 = 4

QUANTITY_IS_NOT_1 = 5

INTERVAL_OVERFLOW = 6

BUFFER_OVERFLOW = 7

OTHERS = 8.

IF SY-SUBRC <> 0.

message e899(fi) with 'Cannot assign number for MQ message'.

perform add_iface_msg using 'E' 'E'

'ZFI_ISS'

'021'

'ZAR_ISSMQ'

space space space

space abap_true.

* Cannot assign number for MQ message from number range &1

ENDIF.

w_edi426-hdr-group_ctl_number = w_mq_msg_num.

endif.

w_edi426-hdr-group_suffix = '00'.

endform.

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

form restore_hlevel_psgnum.

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

* At end of a hierarchy level, restore the values used on the higher

* level.

read table t_stack index 1 into w_stack.

if sy-subrc eq 0.

w_hlevel = w_stack-hlevel.

w_psgnum = w_stack-psgnum.

delete t_stack index 1.

endif.

endform.

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

form line_selection.

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

clear w_tabix.

read current line field value w_tabix.

if w_tabix gt 0.

read table t_edi426 index w_tabix into w_edi426.

CALL FUNCTION 'Z_DISPLAY_DEEP_STRUCTURE'

EXPORTING

X_STRUC = w_edi426

X_HEADER_LTEXT = 'EDI 426'

X_TITLEBAR_TEXT = 'Display EDI 426'

X_OFFSET = 6

X_LENGTH = 30

X_ALV_NO_HEADERS_FLAG = abap_false

X_ALV_FIELDNAME_FLAG = abap_true

EXCEPTIONS

CANNOT_DISPLAY = 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.

endif.

endform.

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

form loop1200_for_rule_11_notificn.

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

* Rule 11 notification must have an N1 with entity ID code '11'.

w_flag-found = abap_false.

loop at w_426-loop1000_row-loop1200_tab

into w_426-loop1200_row where n1-entity_id_code eq '11'.

w_flag-found = abap_true.

exit.

endloop.

if w_flag-found eq abap_false.

* No '11' found, so add a default value.

w_426-loop1200_row-n1-entity_id_code = '11'.

w_426-loop1200_row-n1-name = 'BILL TO PARTY UNKNOWN, DEFAULT'.

perform increment_nsegs using w_426-loop1200_row-n1

changing w_nsegs.

perform add_table_row tables w_426-loop1000_row-loop1200_tab

changing w_426-loop1200_row.

endif.

* N3 and N4 are required if N1 has entity ID code '11' or 'PF'.

loop at w_426-loop1000_row-loop1200_tab

into w_426-loop1200_row where n1-entity_id_code eq '11'

or n1-entity_id_code eq 'PF'.

w_tabix = sy-tabix.

* N3

read table w_426-loop1200_row-n3_occ index 1 transporting no fields.

if sy-subrc ne 0.

clear w_426-n3.

w_426-n3-address1 = 'PF OR 11 PARTY UNKNOWN'.

w_426-n3-address2 = 'DEFAULT VALUE USED'.

perform store_repeating_segment tables w_426-loop1200_row-n3_occ

changing w_426-n3

w_nsegs.

endif.

* N4

if w_426-loop1200_row-n4-city_name is initial.

w_426-loop1200_row-n4-city_name = 'CITY DEFAULT USED'.

w_426-loop1200_row-n4-state_prov_code = 'ON'.

elseif w_426-loop1200_row-n4-state_prov_code is initial.

w_426-loop1200_row-n4-state_prov_code = 'ON'.

endif.

modify w_426-loop1000_row-loop1200_tab index w_tabix

from w_426-loop1200_row.

endloop.

endform.

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

form loop1200_for_rule_11_revenue.

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

* Rule 11 revenue waybills require N1 entries for origin and

* destination stations.

* Origin

if not w_wb-bnx_row-f9-frt_stn_acc_cd1 is initial.

w_426-loop1200_row-n1-entity_id_code = 'SF'.

w_426-loop1200_row-n1-name = w_wb-bnx_row-f9-city_name1.

perform increment_nsegs using w_426-loop1200_row-n1

changing w_nsegs.

perform add_table_row tables w_426-loop1000_row-loop1200_tab

changing w_426-loop1200_row.

endif.

* Destination

if not w_wb-bnx_row-d9-frt_acc_stn_cd1 is initial.

w_426-loop1200_row-n1-entity_id_code = 'UC'.

w_426-loop1200_row-n1-name = w_wb-bnx_row-d9-city_name1.

perform increment_nsegs using w_426-loop1200_row-n1

changing w_nsegs.

perform add_table_row tables w_426-loop1000_row-loop1200_tab

changing w_426-loop1200_row.

endif.

endform.

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

form set_idoc_status using px_docnum type edi_docnum

px_status type edi_status

px_required type ty_required.

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

* data: l_edidc type edidc.

data: l_edi_ds type edi_ds.

l_edi_ds-mandt = sy-mandt.

l_edi_ds-logdat = sy-datum.

l_edi_ds-logtim = sy-uzeit.

l_edi_ds-status = px_status.

l_edi_ds-uname = sy-uname.

l_edi_ds-repid = sy-cprog.

l_edi_ds-stapa1 = px_required-seg_id.

l_edi_ds-stapa2 = px_required-compname.

l_edi_ds-statyp = 'E'.

l_edi_ds-stamid = 'ZFI_ISS'.

l_edi_ds-stamno = '017'.

* No value for required field &1 in segment &2

call function 'EDI_DOCUMENT_OPEN_FOR_PROCESS'

exporting

db_read_option = 'N'

document_number = px_docnum

enqueue_option = 'S'

* importing

* idoc_control = l_edidc

exceptions

document_foreign_lock = 1

document_not_exist = 2

document_number_invalid = 3

document_is_already_open = 4

others = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

exit.

ENDIF.

call function 'EDI_DOCUMENT_STATUS_SET'

exporting

document_number = px_docnum

idoc_status = l_edi_ds

* importing

* idoc_control = l_edidc

exceptions

document_number_invalid = 1

other_fields_invalid = 2

status_invalid = 3

others = 4.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

exit.

ENDIF.

call function 'EDI_DOCUMENT_CLOSE_PROCESS'

exporting

document_number = px_docnum

background = 'N'

no_dequeue = ' '

* importing

* idoc_control = l_edidc

exceptions

document_not_open = 1

failure_in_db_write = 2

parameter_error = 3

status_set_missing = 4

others = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

exit.

ENDIF.

endform.

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

form set_selscrn_texts.

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

* comm_dat = 'Data selection'(dat).

comm_out = 'Output control'(out).

comm_rmo = 'Run mode'(rmo).

comm_tst = 'Test run'(tst).

endform.

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

form start_interface.

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

CREATE OBJECT O_IFACE1

EXPORTING

PX_IFACE_ID = c_iface1

PX_DIRECTION = zcl_arch_ifaces=>c_direction_out

PX_APPSERVER = abap_false

PX_LOGICAL = abap_false

PX_FILENAME = space

PX_TEST = p_test

PX_IDOC_FLAG = abap_true

EXCEPTIONS

GENERIC_ERROR = 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.

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

form store_hlevel_psgnum.

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

* At start of a hierarchy level, store the values used on the higher

* level.

w_stack-hlevel = w_hlevel.

w_stack-psgnum = w_psgnum.

insert w_stack into t_stack index 1.

add 1 to w_hlevel.

endform.

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

form store_repeating_segment tables pt_data

changing pxy_segment

pxy_nsegs.

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

perform increment_nsegs using pxy_segment

changing pxy_nsegs.

if not pxy_segment is initial.

append pxy_segment to pt_data.

clear pxy_segment.

endif.

endform.

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

form strip_leading_zeroes changing pxy_value.

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

* Remove leading zeroes from a field.

data: l_type type c.

field-symbols: <char> type c.

* Only for character fields.

describe field pxy_value type l_type.

check l_type eq 'C'.

* assign pxy_value+0(1) to <char>.

* while <char> eq '0'.

* shift pxy_value left.

* endwhile.

if pxy_value co '0123456789 '.

CALL FUNCTION 'Z_FORMAT_NUMBER'

EXPORTING

X_FORMAT = 'LJ'

CHANGING

XY_NUMBER = pxy_value

EXCEPTIONS

* NOT_NUMERIC = 1

OTHERS = 0.

endif.

endform.

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

form summarise_bunch_bill changing pxy_waybill type zva01_waybill.

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

* For bunch bills, the L0/L1/PI segments for Freight and Fuel are

* presented in a summary format (rather than one per waggon).

* Miscellaneous charges are left in their original format.

* Types

* *****

types: begin of lty_compare_freight,

tabix type sytabix,

* lading_line like zsd_arch_l0-lading_line,

*commented by sandhya

lading_line like zsd_arch_l1-lading_line,

* billd_rated_qual like zsd_arch_l0-billd_rated_qual,

*commented by sandhya

freight_rate like zsd_arch_l1-freight_rate,

rate_value_qual1 like zsd_arch_l1-rate_value_qual1,

currency_code like zsd_arch_l1-currency_code,

division_no like zsd_arch_l1-division_no,

end of lty_compare_freight.

types: begin of lty_compare_fuel,

tabix type sytabix,

* lading_line like zsd_arch_l0-lading_line,

lading_line like zsd_arch_l1-lading_line,

currency_code like zsd_arch_l1-currency_code,

division_no like zsd_arch_l1-division_no,

division_versn like zsd_arch_l1-division_versn,

end of lty_compare_fuel.

types: begin of lty_compare_fat,

tabix type sytabix,

lading_line like zsd_arch_l0-lading_line,

weight like zsd_arch_l0-weight,

lading_qty like zsd_arch_l0-lading_qty,

end of lty_compare_fat.

types: begin of lty_rawdata,

tabix type sy-tabix,

sort_order type sy-tabix,

l0 type zsd_arch_l0,

l1 type zsd_arch_l1,

pi type zsd_arch_pi,

end of lty_rawdata.

* Constants

* *********

constants: c_bunch_bill_code like zsd_arch_bnx-billing_code

value 'M'.

constants: begin of c_default,

begin of fuel,

l0_weight_qual like zsd_arch_l0-weight_qual value 'M',

l0_weight like zsd_arch_l0-weight value '1',

end of fuel,

end of c_default.

* Data

* ****

data: l_found type flag,

l_l0 type zsd_arch_l0,

l_l1_row type zva01_l1_row,

l_nlines type i,

l_pi type zsd_arch_pi,

l_prev type lty_rawdata,

l_tabix type sy-tabix,

l_lin type sy-tabix,

l_no_l0 type sy-tabix.

* Extracted freight and fuel data

data: lt_freight type standard table of lty_rawdata,

lt_fuel type standard table of lty_rawdata,

lt_fat type standard table of lty_rawdata.

data: l_freight type lty_rawdata,

l_fuel type lty_rawdata,

l_fat type lty_rawdata,

l_freight_1 type lty_rawdata.

data: begin of l_flag,

freight_added type flag,

fuel_added type flag,

fat_added type flag,

end of l_flag.

data : l_curr_tabix like sy-tabix,

l_prev_tabix like sy-tabix,

l_sort_order like sy-tabix.

* Summarised data

data: lt_freight_s type zva01_l0_tab,

lt_fuel_s type zva01_l0_tab.

data: l_freight_s type zva01_l0_row,

l_fuel_s type zva01_l0_row,

l_fat_s type zva01_l0_row.

data: lt_freight_s1 type standard table of lty_rawdata

with header line.

data: lt_freight_s2 type standard table of lty_rawdata

with header line.

data: lt_fuel_s1 type standard table of lty_rawdata

with header line.

"added by sandhya

* Data to store in summarised tables

data: begin of l_data,

sort_order like sy-tabix,

l0 type zsd_arch_l0,

l1 type zsd_arch_l1,

pi type zsd_arch_pi,

end of l_data.

* Miscellaneous charges

data: lt_miscellaneous type zva01_l0_tab.

* Fields used for comparison in break processing

data: begin of l_compare,

begin of freight,

curr type lty_compare_freight,

prev type lty_compare_freight,

end of freight,

begin of fuel,

curr type lty_compare_fuel,

prev type lty_compare_fuel,

end of fuel,

begin of fat,

curr type lty_compare_freight,

prev type lty_compare_freight,

end of fat,

end of l_compare.

field-symbols: <bnx_row> type zva01_bnx_row,

<lx_row> type zva01_lx_row,

<l0_row> type zva01_l0_row,

<l1_row> type zva01_l1_row.

data : begin of lx_row1 occurs 0,

sort_order like sy-tabix,

lx_row11 type zva01_lx_row,

end of lx_row1.

* We sort the Freight and Fuel data into separate structures;

* summarise each structure; and replace the original data with the

* summaries.

*Find if the overhead waybill

if pxy_waybill-bx-blkug_rev_type = 'OH' and

pxy_waybill-bx-rating_source = space.

w_flag-overhead_waybill = '1'.

endif.

* BNX loop

loop at pxy_waybill-bnx_tab assigning <bnx_row>.

check <bnx_row>-bnx-billing_code eq c_bunch_bill_code.

* LX loop

loop at <bnx_row>-lx_tab assigning <lx_row>.

* L0 loop

l_found = abap_false.

loop at <lx_row>-l0_tab assigning <l0_row>.

describe table <l0_row>-l0_occ lines l_nlines.

clear: l_l0,

l_pi.

move sy-tabix to l_sort_order.

read table <l0_row>-pi_occ index 1 into l_pi.

* Separate the freight and fuel data

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

loop at <l0_row>-l0_occ into l_l0.

l_tabix = sy-tabix.

read table <l0_row>-l1_tab assigning <l1_row>

with key l1-charge_type = c_l1_charge_type-freight.

if sy-subrc eq 0.

l_found = abap_true.

l_freight-tabix = l_tabix.

move-corresponding: l_l0 to l_freight-l0,

<l1_row>-l1 to l_freight-l1,

l_pi to l_freight-pi.

move l_sort_order to l_freight-sort_order.

append l_freight to lt_freight.

clear l_freight.

endif.

read table <l0_row>-l1_tab assigning <l1_row>

with key l1-charge_type = c_l1_charge_type-fuel.

if sy-subrc eq 0.

l_found = abap_true.

l_fuel-tabix = l_tabix.

move-corresponding: l_l0 to l_fuel-l0,

<l1_row>-l1 to l_fuel-l1,

l_pi to l_fuel-pi.

move l_sort_order to l_fuel-sort_order.

append l_fuel to lt_fuel.

clear l_fuel.

endif.

*Overhead Waybills with charge type _FAT

if w_flag-overhead_waybill = '1'.

read table <l0_row>-l1_tab assigning <l1_row>

with key l1-charge_type = c_l1_charge_type-fat.

if sy-subrc eq 0.

l_found = abap_true.

l_fat-tabix = l_tabix.

move-corresponding: l_l0 to l_fat-l0,

<l1_row>-l1 to l_fat-l1,

l_pi to l_fat-pi.

append l_fat to lt_fat.

clear l_fat.

endif.

endif.

endloop.

* And retain the miscellaneous charges

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

read table <l0_row>-l1_tab assigning <l1_row>

with key l1-charge_type = c_l1_charge_type-misc.

if sy-subrc eq 0.

l_found = abap_true.

append <l0_row> to lt_miscellaneous.

endif.

endloop. "L0

if l_found eq abap_true.

clear <lx_row>-l0_tab.

endif.

* Ensure we don't have any extraneous lines in the raw data tables

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

loop at lt_fuel into l_fuel.

if l_fuel-l1-charge_type ne c_l1_charge_type-fuel.

delete lt_fuel.

endif.

endloop.

loop at lt_freight into l_freight.

if l_freight-l1-charge_type ne c_l1_charge_type-freight.

delete lt_freight.

endif.

endloop.

loop at lt_fat into l_fat.

if l_fat-l1-charge_type ne c_l1_charge_type-fat.

delete lt_fat.

endif.

endloop.

* Sort the tables for break processing

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

* (The sort parameters should match the fields of the LTY_COMPARE

* structures)

* sort lt_freight by l0-lading_line

* l0-billd_rated_qual descending

* l1-freight_rate

* l1-rate_value_qual1

* l1-currency_code

* l1-division_no

* tabix.

sort lt_freight by l1-lading_line

l1-freight_rate

l1-rate_value_qual1

l1-currency_code

l1-division_no

tabix

sort_order descending.

sort lt_fuel by l1-lading_line

l1-currency_code

l1-division_no

l1-division_versn

tabix

sort_order descending.

sort lt_fat by l0-lading_line

l0-weight

l0-lading_qty

tabix.

* We've removed freight and fuel from the LX table and

* stored them in temporary tables. Now, let's summarise

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

* Freight

* *******

* loop at lt_freight into l_freight.

* l_tabix = sy-tabix.

* at first.

* clear l_prev.

* endat.

** Note you must assign L1 fields before L0 fields since both

** segments contain BILLD_RATED_QUAL and we use the L0 field here.

** move: l_freight-tabix to l_compare-freight-curr-tabix,

** l_prev-tabix to l_compare-freight-prev-tabix.

* move-corresponding: l_freight-l1 to l_compare-freight-curr,

* l_freight-l0 to l_compare-freight-curr,

* l_prev-l1 to l_compare-freight-prev,

* l_prev-l0 to l_compare-freight-prev.

** Store summary entry when certain values change.

* if l_compare-freight-curr ne l_compare-freight-prev.

* if not l_data is initial

* and l_tabix gt 1.

* perform format_number changing: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

** l_l1_row-l1 = l_data-l1.

** append: l_data-l0 to l_freight_s-l0_occ,

** l_data-pi to l_freight_s-pi_occ.

** clear: l_data,

** l_l1_row.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_freight_s-l0_occ,

* l_l1_row to l_freight_s-l1_tab,

* l_data-pi to l_freight_s-pi_occ.

* append l_freight_s to <lx_row>-l0_tab.

* clear: l_freight_s,

* l_data,

* l_l1_row.

* endif.

** Fields that aren't summarised are just taken

** from the first segment

* move-corresponding: l_freight-l0 to l_data-l0,

* l_freight-l1 to l_data-l1,

* l_freight-pi to l_data-pi.

* clear: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* clear: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* endif.

* add: l_freight-l0-weight to l_data-l0-weight,

* l_freight-l0-volume to l_data-l0-volume,

* l_freight-l0-lading_qty to l_data-l0-lading_qty.

* add: l_freight-l1-amount_charged to l_data-l1-amount_charged,

* l_freight-l1-prepaid_amount to l_data-l1-prepaid_amount.

* move-corresponding l_freight to l_prev.

* endloop.

* if not l_data is initial.

* perform format_number changing: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_freight_s-l0_occ,

* l_l1_row to l_freight_s-l1_tab,

* l_data-pi to l_freight_s-pi_occ.

* append l_freight_s to <lx_row>-l0_tab.

* clear: l_freight_s,

* l_data,

* l_l1_row.

* endif.

*

*added by sandhya

*summarisation of the L1 segments

loop at lt_freight into l_freight.

l_tabix = sy-tabix.

at first.

clear l_prev.

endat.

move: l_freight-tabix to l_curr_tabix.

move-corresponding: l_freight-l1 to l_compare-freight-curr,

l_prev-l1 to l_compare-freight-prev.

if l_compare-freight-curr ne l_compare-freight-prev.

if not l_data is initial

and l_tabix gt 1.

perform format_number changing: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

move-corresponding l_data-l0 to lt_freight_s1-l0.

move-corresponding l_data-l1 to lt_freight_s1-l1.

move-corresponding l_data-pi to lt_freight_s1-pi.

move l_freight-tabix to lt_freight_s1-tabix.

move l_data-sort_order to lt_freight_s1-sort_order.

append lt_freight_s1.

clear: l_freight_s,

l_data,

l_l1_row,

l_freight_1,

l_no_l0,

l_lin.

endif.

* Fields that aren't summarised are just taken

* from the first segment

move-corresponding: l_freight-l0 to l_data-l0,

l_freight-l1 to l_data-l1,

l_freight-pi to l_data-pi.

move l_freight-sort_order to l_data-sort_order.

clear: l_data-l1-amount_charged,

l_data-l1-prepaid_amount,

l_data-sort_order.

endif.

if l_curr_tabix eq 1.

add: l_freight-l1-amount_charged to l_data-l1-amount_charged,

l_freight-l1-prepaid_amount to l_data-l1-prepaid_amount.

move l_freight-sort_order to l_data-sort_order.

endif.

move-corresponding l_freight to l_prev.

endloop.

if not l_data is initial.

perform format_number changing: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

move-corresponding l_data-l0 to lt_freight_s1-l0.

move-corresponding l_data-l1 to lt_freight_s1-l1.

move-corresponding l_data-pi to lt_freight_s1-pi.

move l_data-sort_order to lt_freight_s1-sort_order.

append lt_freight_s1.

clear: l_freight_s,

l_data,

l_l1_row,

l_lin,

l_freight_1,

l_no_l0.

endif.

*summarisation of the L0 segments

loop at lt_freight into l_freight.

l_tabix = sy-tabix.

at first.

clear l_prev.

endat.

* Note you must assign L1 fields before L0 fields since both

* segments contain BILLD_RATED_QUAL and we use the L0 field here.

move: l_freight-tabix to l_compare-freight-curr-tabix,

l_prev-tabix to l_compare-freight-prev-tabix.

move-corresponding: l_freight-l1 to l_compare-freight-curr,

l_prev-l1 to l_compare-freight-prev.

* Store summary entry when certain values change.

if l_compare-freight-curr ne l_compare-freight-prev.

if not l_data is initial

and l_tabix gt 1.

perform format_number changing: l_data-l0-weight,

l_data-l0-volume,

l_data-l0-lading_qty.

move-corresponding l_data-l0 to lt_freight_s2-l0.

move-corresponding l_data-l1 to lt_freight_s2-l1.

move-corresponding l_data-pi to lt_freight_s2-pi.

move l_freight-tabix to lt_freight_s2-tabix.

append lt_freight_s2.

clear: l_freight_s,

l_data,

l_l1_row,

l_freight_1,

l_no_l0,

l_lin.

endif.

* Fields that aren't summarised are just taken

* from the first segment

move-corresponding: l_freight-l0 to l_data-l0,

l_freight-l1 to l_data-l1,

l_freight-pi to l_data-pi.

clear: l_data-l0-weight,

l_data-l0-volume,

l_data-l0-lading_qty.

endif.

add: l_freight-l0-weight to l_data-l0-weight,

l_freight-l0-volume to l_data-l0-volume,

l_freight-l0-lading_qty to l_data-l0-lading_qty.

move-corresponding l_freight to l_prev.

endloop.

if not l_data is initial.

perform format_number changing: l_data-l0-weight,

l_data-l0-volume,

l_data-l0-lading_qty.

move-corresponding l_data-l0 to lt_freight_s2-l0.

move-corresponding l_data-l1 to lt_freight_s2-l1.

move-corresponding l_data-pi to lt_freight_s2-pi.

append lt_freight_s2.

clear: l_freight_s,

l_data,

l_l1_row,

l_lin,

l_freight_1,

l_no_l0.

endif.

*Forming 1510 loop

loop at lt_freight_s1.

move-corresponding lt_freight_s1-l1 to l_compare-freight-curr.

loop at lt_freight_s2.

move-corresponding lt_freight_s2-l1 to l_compare-freight-prev.

if l_compare-freight-curr ne l_compare-freight-prev.

continue.

else.

append lt_freight_s2-l0 to l_freight_s-l0_occ.

endif.

endloop.

l_l1_row-l1 = lt_freight_s1-l1.

l_data-pi = lt_freight_s1-pi.

append: l_l1_row to l_freight_s-l1_tab,

l_data-pi to l_freight_s-pi_occ.

* append l_freight_s to <lx_row>-l0_tab.

append l_freight_s to lx_row1-lx_row11-l0_tab.

move lt_freight_s1-sort_order to lx_row1-sort_order.

append lx_row1.

clear lx_row1-lx_row11.

clear l_freight_s.

endloop.

* sort lx_row1 by sort_order.

*

* loop at lx_row1.

* loop at lx_row1-lx_row11-l0_tab into l_freight_s.

* append l_freight_s to <lx_row>-l0_tab.

* endloop.

* endloop.

*end:added by sandhya

*Added by Sandhya

* loop at lt_freight into l_freight.

* l_tabix = sy-tabix.

* at first.

* clear l_prev.

* endat.

** Note you must assign L1 fields before L0 fields since both

** segments contain BILLD_RATED_QUAL and we use the L0 field here.

** move: l_freight-tabix to l_compare-freight-curr-tabix,

** l_prev-tabix to l_compare-freight-prev-tabix.

* move-corresponding: l_freight-l1 to l_compare-freight-curr,

* l_freight-l0 to l_compare-freight-curr,

* l_prev-l1 to l_compare-freight-prev,

* l_prev-l0 to l_compare-freight-prev.

** Store summary entry when certain values change.

* if l_compare-freight-curr ne l_compare-freight-prev.

* if not l_data is initial

* and l_tabix gt 1.

* perform format_number changing: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

** l_l1_row-l1 = l_data-l1.

** append: l_data-l0 to l_freight_s-l0_occ,

** l_data-pi to l_freight_s-pi_occ.

** clear: l_data,

** l_l1_row.

* l_l1_row-l1 = l_data-l1.

*

* move-corresponding l_data-l0 to lt_freight_s1-l0.

* move-corresponding l_data-l1 to lt_freight_s1-l1.

* move-corresponding l_data-pi to lt_freight_s1-pi.

* append lt_freight_s1.

*

* clear: l_freight_s,

* l_data,

* l_l1_row.

* endif.

** Fields that aren't summarised are just taken

** from the first segment

* move-corresponding: l_freight-l0 to l_data-l0,

* l_freight-l1 to l_data-l1,

* l_freight-pi to l_data-pi.

* clear: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* clear: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* endif.

* add: l_freight-l0-weight to l_data-l0-weight,

* l_freight-l0-volume to l_data-l0-volume,

* l_freight-l0-lading_qty to l_data-l0-lading_qty.

* add: l_freight-l1-amount_charged to l_data-l1-amount_charged,

* l_freight-l1-prepaid_amount to l_data-l1-prepaid_amount.

* move-corresponding l_freight to l_prev.

* endloop.

* if not l_data is initial.

* perform format_number changing: l_data-l0-weight,

* l_data-l0-volume,

* l_data-l0-lading_qty.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* l_l1_row-l1 = l_data-l1.

*

* move-corresponding l_data-l0 to lt_freight_s1-l0.

* move-corresponding l_data-l1 to lt_freight_s1-l1.

* move-corresponding l_data-pi to lt_freight_s1-pi.

* append lt_freight_s1.

*

* clear: l_freight_s,

* l_data,

* l_l1_row.

* endif.

*

* sort lt_freight_s1 by l1-lading_line l1-freight_rate

* l1-rate_value_qual1 l1-currency_code

* l1-division_no.

*

* loop at lt_freight_s1.

* if sy-tabix = 1.

* move-corresponding lt_freight_s1-l1 to l_data-l1.

* continue.

* endif.

* if lt_freight_s1-l1 = l_data-l1.

* clear lt_freight_s1-l1.

* modify lt_freight_s1.

* else.

* move-corresponding lt_freight_s1-l1 to l_data-l1.

* endif.

* endloop.

*

* loop at lt_freight_s1.

* append lt_freight_s1-l0 to l_freight_s-l0_occ.

* endloop.

*

* loop at lt_freight_s1.

* l_l1_row-l1 = lt_freight_s1-l1.

* if not l_l1_row-l1 is initial.

* append l_l1_row to l_freight_s-l1_tab.

* endif.

* endloop.

*

* loop at lt_freight_s1.

* append lt_freight_s1-pi to l_freight_s-pi_occ.

* endloop.

*

* append l_freight_s to <lx_row>-l0_tab.

*

* clear: l_freight_s,

* l_data,

* l_l1_row.

*

***End:Added by Sandhya

** Fuel

** ****

* loop at lt_fuel into l_fuel.

* l_tabix = sy-tabix.

* at first.

* clear l_prev.

* endat.

** Note you must assign L1 fields before L0 fields since both

** segments contain BILLD_RATED_QUAL and we use the L0 field here.

* move: l_fuel-tabix to l_compare-fuel-curr-tabix,

* l_prev-tabix to l_compare-fuel-prev-tabix.

* move-corresponding: l_fuel-l1 to l_compare-fuel-curr,

* l_fuel-l0 to l_compare-fuel-curr,

* l_prev-l1 to l_compare-fuel-prev,

* l_prev-l0 to l_compare-fuel-prev.

** Store summary entry when certain values change.

* if l_compare-fuel-curr ne l_compare-fuel-prev.

* if not l_data is initial

* and l_tabix gt 1.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

** l_l1_row-l1 = l_data-l1.

** append: l_data-l0 to l_fuel_s-l0_occ,

** l_data-pi to l_fuel_s-pi_occ.

** clear: l_data,

** l_l1_row.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_fuel_s-l0_occ,

* l_l1_row to l_fuel_s-l1_tab,

* l_data-pi to l_fuel_s-pi_occ.

* append l_fuel_s to <lx_row>-l0_tab.

* clear: l_fuel_s,

* l_data,

* l_l1_row.

* endif.

** Fields that aren't summarised are just taken

** from the first segment

* move-corresponding: l_fuel-l0 to l_data-l0,

* l_fuel-l1 to l_data-l1,

* l_fuel-pi to l_data-pi.

* l_data-l0-weight_qual = c_default-fuel-l0_weight_qual.

* l_data-l0-weight = c_default-fuel-l0_weight.

* perform format_number changing l_data-l0-weight.

* clear: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* endif.

* add: l_fuel-l1-amount_charged to l_data-l1-amount_charged,

* l_fuel-l1-prepaid_amount to l_data-l1-prepaid_amount.

* move-corresponding l_fuel to l_prev.

* endloop.

* if not l_data is initial.

* perform format_number changing: l_data-l1-amount_charged,

* l_data-l1-prepaid_amount.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_fuel_s-l0_occ,

* l_l1_row to l_fuel_s-l1_tab,

* l_data-pi to l_fuel_s-pi_occ.

* append l_fuel_s to <lx_row>-l0_tab.

* clear: l_fuel_s,

* l_data,

* l_l1_row.

* endif.

* Fuel

* ****

loop at lt_fuel into l_fuel.

l_tabix = sy-tabix.

at first.

clear l_prev.

endat.

move: l_fuel-tabix to l_curr_tabix.

move-corresponding: l_fuel-l1 to l_compare-fuel-curr,

l_prev-l1 to l_compare-fuel-prev.

* Store summary entry when certain values change.

if l_compare-fuel-curr ne l_compare-fuel-prev.

if not l_data is initial

and l_tabix gt 1.

perform format_number changing: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_fuel_s-l0_occ,

* l_data-pi to l_fuel_s-pi_occ.

* clear: l_data,

* l_l1_row.

move-corresponding l_data-l0 to lt_fuel_s1-l0.

move-corresponding l_data-l1 to lt_fuel_s1-l1.

move-corresponding l_data-pi to lt_fuel_s1-pi.

move l_fuel-tabix to lt_freight_s1-tabix.

move l_data-sort_order to lt_fuel_s1-sort_order.

append lt_fuel_s1.

clear: l_fuel_s,

l_data,

l_l1_row.

endif.

* Fields that aren't summarised are just taken

* from the first segment

move-corresponding: l_fuel-l0 to l_data-l0,

l_fuel-l1 to l_data-l1,

l_fuel-pi to l_data-pi.

l_data-l0-weight_qual = c_default-fuel-l0_weight_qual.

l_data-l0-weight = c_default-fuel-l0_weight.

move l_fuel-sort_order to l_data-sort_order.

perform format_number changing l_data-l0-weight.

clear: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

endif.

add: l_fuel-l1-amount_charged to l_data-l1-amount_charged,

l_fuel-l1-prepaid_amount to l_data-l1-prepaid_amount.

move l_fuel-sort_order to l_data-sort_order.

move-corresponding l_fuel to l_prev.

endloop.

if not l_data is initial.

perform format_number changing: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

move-corresponding l_data-l0 to lt_fuel_s1-l0.

move-corresponding l_data-l1 to lt_fuel_s1-l1.

move-corresponding l_data-pi to lt_fuel_s1-pi.

move l_data-sort_order to lt_fuel_s1-sort_order.

append lt_fuel_s1.

clear: l_fuel_s,

l_data,

l_l1_row.

endif.

*forming 1510 loop

loop at lt_fuel_s1.

l_l1_row-l1 = lt_fuel_s1-l1.

l_data-pi = lt_fuel_s1-pi.

append lt_fuel_s1-l0 to l_fuel_s-l0_occ.

append: l_l1_row to l_fuel_s-l1_tab,

l_data-pi to l_fuel_s-pi_occ.

append l_fuel_s to lx_row1-lx_row11-l0_tab.

move lt_fuel_s1-sort_order to lx_row1-sort_order.

append lx_row1.

clear lx_row1-lx_row11.

clear l_fuel_s.

endloop.

sort lx_row1 by sort_order.

*creating idoc from the freight and fuel

loop at lx_row1.

loop at lx_row1-lx_row11-l0_tab into l_freight_s.

append l_freight_s to <lx_row>-l0_tab.

endloop.

endloop.

*added by sandhya

* FAT

* *******

loop at lt_fat into l_fat.

l_tabix = sy-tabix.

at first.

clear l_prev.

endat.

* Note you must assign L1 fields before L0 fields since both

* segments contain BILLD_RATED_QUAL and we use the L0 field here.

move: l_fat-tabix to l_compare-fat-curr-tabix,

l_prev-tabix to l_compare-fat-prev-tabix.

move-corresponding: l_fat-l1 to l_compare-fat-curr,

l_fat-l0 to l_compare-fat-curr,

l_prev-l1 to l_compare-fat-prev,

l_prev-l0 to l_compare-fat-prev.

* Store summary entry when certain values change.

if l_compare-fat-curr ne l_compare-fat-prev.

if not l_data is initial

and l_tabix gt 1.

perform format_number changing: l_data-l0-weight,

l_data-l0-lading_qty.

* l_l1_row-l1 = l_data-l1.

* append: l_data-l0 to l_fat_s-l0_occ,

* l_data-pi to l_fat_s-pi_occ.

* clear: l_data,

* l_l1_row.

l_l1_row-l1 = l_data-l1.

append: l_data-l0 to l_fat_s-l0_occ,

l_l1_row to l_fat_s-l1_tab,

l_data-pi to l_fat_s-pi_occ.

append l_fat_s to <lx_row>-l0_tab.

clear: l_fat_s,

l_data,

l_l1_row.

endif.

* Fields that aren't summarised are just taken

* from the first segment

move-corresponding: l_fat-l0 to l_data-l0,

l_fat-l1 to l_data-l1,

l_fat-pi to l_data-pi.

clear: l_data-l0-weight,

l_data-l0-volume,

l_data-l0-lading_qty.

clear: l_data-l1-amount_charged,

l_data-l1-prepaid_amount.

endif.

add: l_fat-l0-weight to l_data-l0-weight,

l_fat-l0-lading_qty to l_data-l0-lading_qty.

move-corresponding l_fat to l_prev.

endloop.

if not l_data is initial.

perform format_number changing: l_data-l0-weight,

l_data-l0-lading_qty.

l_l1_row-l1 = l_data-l1.

append: l_data-l0 to l_fat_s-l0_occ,

l_l1_row to l_fat_s-l1_tab,

l_data-pi to l_fat_s-pi_occ.

append l_fat_s to <lx_row>-l0_tab.

clear: l_fat_s,

l_data,

l_l1_row.

endif.

*end:added by sandhya

* And, finally, re-instate the miscellaneous charges

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

loop at lt_miscellaneous assigning <l0_row>.

append <l0_row> to <lx_row>-l0_tab.

endloop.

clear: lt_freight,

lt_fuel,

lt_miscellaneous.

endloop. "LX

endloop. "BNX

endform.

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

form test_output.

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

* Display some, obviously not all, of the outbound IDoc data

data: l_n426 type i,

l_segment type char3.

field-symbols: <f> type any,

<s> type any.

check p_test eq abap_true.

new-page line-size 120.

loop at t_edi426 into w_edi426.

w_tabix = sy-tabix.

do 1 times.

case sy-index.

when 1.

l_segment = 'Log'.

assign w_edi426-log to <s>.

* when 2.

* l_segment = 'HDR'.

* assign w_edi426-hdr to <s>.

* when 3.

* l_segment = 'ST '.

* assign w_edi426-st to <s>.

* when others.

* l_segment = 'ZR '.

* assign w_edi426-zr to <s>.

endcase.

if <s> is assigned.

write: / l_segment no-gap, ':'.

hide w_tabix.

do.

assign component sy-index of structure <s> to <f>.

if sy-subrc ne 0.

exit.

endif.

if sy-index gt 1.

write: '*' no-gap.

endif.

if not <f> is initial.

write: <f> no-gap.

endif.

enddo.

endif.

enddo.

* Report any missing required fields.

w_flag-first = abap_true.

loop at t_required into w_required

where arch_set eq w_edi426-arch_set.

if w_flag-first eq abap_true.

write: / 'Required fields missing values:'.

w_flag-first = abap_false.

endif.

write: /10 w_required-seg_id, w_required-compname.

endloop.

uline.

endloop.

describe table t_edi426 lines l_n426.

write: / 'No. of 426 messages generated in test mode:', l_n426.

skip 1.

endform.

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

form top_of_page.

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

CALL METHOD O_IFACE1->WRITE_PAGE_HEADER

EXPORTING

PX_CPROG = sy-cprog

PX_TITLE = sy-title.

endform.

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

form transform_decimal_places using px_seg_id

px_fieldname

px_iss_decs

changing pxy_field.

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

data: l_diff type i,

l_iss_decs type zarch_decimals,

l_lastchar type c,

l_negative type flag,

l_offset type i,

l_wb_decs type atdec.

* Field must be numeric

if pxy_field cn '0123456789- '.

exit.

endif.

* If the field isn't found on both ZSD_WB_DECIMALS and ZFI_ISS_FIELDS

* (i.e. if we haven't specified the no. of implied decimals on both the

* Z tables and on the 426 for ISS), skip the transformation.

select single implied_decimals into l_wb_decs

from zsd_wb_decimals

where segment_name eq px_seg_id

and field_name eq px_fieldname.

if sy-subrc ne 0.

exit.

endif.

l_iss_decs = px_iss_decs.

* If the number of implied decimals is the same on both sides,

* skip the transformation.

if l_wb_decs eq l_iss_decs.

exit.

endif.

* If the number of implied decimals is not the same:

* Convert original value to a decimal

* (i.e. stick a decimal point in it).

* Move it to a target with the correct ISS decimal places.

* Denature the target value and put it in the ISS field.

if pxy_field lt 0. "#EC PORTABLE

l_negative = abap_true.

replace '-' with space into pxy_field.

write pxy_field to pxy_field right-justified.

endif.

l_diff = l_iss_decs - l_wb_decs.

if l_diff gt 0.

* ISS has more decimal places.

do l_diff times.

multiply pxy_field by 10.

write pxy_field to pxy_field right-justified.

enddo.

else.

* ISS has fewer decimal places.

l_diff = abs( l_diff ).

* Capture rightmost character; shift string to right.

* If previous rightmost character was >= 5, round the new value.

describe field pxy_field length l_offset.

subtract 1 from l_offset.

do l_diff times.

l_lastchar = pxy_field+l_offset(1).

shift pxy_field right by 1 places.

if l_lastchar between '5' and '9'.

add 1 to pxy_field.

endif.

enddo.

endif.

do.

replace space with '0' into pxy_field.

if sy-subrc ne 0.

exit.

endif.

enddo.

if l_negative eq abap_true.

pxy_field+0(1) = '-'.

endif.

endform.

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

form update_current_batch_info.

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

constants: lc_seg_id type zarch_seg_id value 'L1',

lc_fieldname type fieldname value 'AMOUNT_CHARGED'.

data: l_decimals type zarch_decimals,

l_total type zar_total_amount,

l_total_c like z1edi426l101-amount_charged.

l_total_c = w_total_l104.

select single decimals into l_decimals

from zfi_iss_fields

where segment eq lc_seg_id

and fieldname eq lc_fieldname.

do l_decimals times.

divide l_total_c by 10.

enddo.

l_total = l_total_c.

CALL METHOD O_IFACE1->UPDATE_CURRENT_BATCH_INFO

EXPORTING

PX_REC_COUNT = w_count-idoc

* PX_TOTAL_CREDITS =

* PX_TOTAL_DEBITS =

PX_TOTAL = l_total

* PX_WAERS =

PX_INCLUDE_UPDATE_COUNTS = abap_false

PX_INCLUDE_DR_CR_TOTALS = abap_false

EXCEPTIONS

UPDATE_ERROR = 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.

*updating the zfi_dt_tm_stamp

wa_dt_tm_stamp-type = 'I'.

wa_dt_tm_stamp-z_key = w_zar_iface_cntl_curr-batch_no.

wa_dt_tm_stamp-start_date = start_dt.

wa_dt_tm_stamp-start_time = start_tm.

wa_dt_tm_stamp-end_date = end_dt.

wa_dt_tm_stamp-end_time = end_tm.

insert into zfi_dt_tm_stamp values wa_dt_tm_stamp.

if sy-subrc ne 0.

write:/ 'ZFI_DT_TM_STAMP table not updated. Please Investigate.'.

else.

commit work.

endif.

clear wa_dt_tm_stamp.

endform.

*&---------------------------------------------------------------------*

*& Form set_date_time

*&---------------------------------------------------------------------*

* text

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

* --> p1 text

* <-- p2 text

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

FORM set_date_time.

select * from zfi_dt_tm_stamp into table itab_dt_tm

where type = 'I'

order by start_date descending

start_time descending.

read table itab_dt_tm index 1.

if sy-subrc eq 0.

start_dt = itab_dt_tm-end_date.

start_tm = itab_dt_tm-end_time + 1.

end_dt = sy-datum.

end_tm = sy-uzeit.

endif.

ENDFORM. " set_date_time

  • No labels