Determine the order of Sequences and Operations for BDCs
Handling a Routing through a recording is often the easiest way to touch fields in Sequences and Operations. The only problem is determining the order of Sequences and Operations on the selection screens. This task is especially difficult after change numbers have been used to modify the Routing; the tables PLKO, PLPO, PLAS and PLFL are very sensitive to change numbers and their alignment with what appears on the screen is easily upset.
SAP comes with a relatively easy-to-use function that loads most of the Routing's contents into internal tables. The CARO_ROUTING_READ
function can be used to pull in the Header, Sequences and Operations as they appear on a specific date. The ability to pull the data based on a specific date allows for access to the Routing as it appears on the day that it is to be modified without having to juggle and guess what happened during each of the modifications denoted by a Change number.
The first snippet is a form that accepts the Routing Group, the Group Counter and the Sequence number and returns the number of the box on the Sequence selection screen that represents that Sequence. In the example above the standard Sequence (000000) returns the value 1.
form GetSequenceNo using lvPLNNR lvPLNAL lvPLNFL changing lvSequence. DATA: lo_tsk_tab TYPE STANDARD TABLE OF capp_tsk, lo_seq_tab TYPE STANDARD TABLE OF capp_seq, lo_opr_tab TYPE STANDARD TABLE OF capp_opr, lv_seq_tab like capp_seq, lvCounter type i. CALL FUNCTION 'CARO_ROUTING_READ' EXPORTING date_from = sy-datum plnty = 'N' plnnr = lvPLNNR plnal = lvPLNAL TABLES tsk_tab = lo_tsk_tab seq_tab = lo_seq_tab opr_tab = lo_opr_tab EXCEPTIONS not_found = 1 ref_not_exp = 2 not_valid = 3 OTHERS = 4. if sy-subrc eq 0. loop at lo_seq_tab into lv_seq_tab. add 1 to lvCounter. if lv_seq_tab-PLNFL eq lvPLNFL. move lvCounter to lvSequence. endif. endloop. endif. endform.
The second snippet returns the line number of an Operation within a specified Sequence. The function sorts the internal table by VORNR
to ensure that the Operations are counted in the order that they appear in the Routing. In the example below the Operation 0050 would return the value 11.
form GetOperationNo using lvPLNNR lvPLNAL lvPLNFL lvVORNR changing lvOperation. DATA: lo_tsk_tab TYPE STANDARD TABLE OF capp_tsk, lo_seq_tab TYPE STANDARD TABLE OF capp_seq, lo_opr_tab TYPE STANDARD TABLE OF capp_opr, lv_seq_tab like capp_seq, lv_opr_tab like capp_opr, lvZAEHL like CAPP_OPR-ZAEHL, lvCounter type i. CALL FUNCTION 'CARO_ROUTING_READ' EXPORTING date_from = sy-datum plnty = 'N' plnnr = lvPLNNR plnal = lvPLNAL TABLES tsk_tab = lo_tsk_tab seq_tab = lo_seq_tab opr_tab = lo_opr_tab EXCEPTIONS not_found = 1 ref_not_exp = 2 not_valid = 3 OTHERS = 4. if sy-subrc eq 0. sort lo_opr_tab by PLNFL VORNR. loop at lo_seq_tab into lv_seq_tab where PLNFL eq lvPLNFL. loop at lo_opr_tab into lv_opr_tab where PLNFL eq lvPLNFL. add 1 to lvCounter. if lv_opr_tab-VORNR eq lvVORNR. move lvCounter to lvOperation. endif. endloop. endloop. endif. endform.