Hi Experts,
The sceanrio am having trouble with is when i have 2 deliveries among which only one has hazardous material . In this case pv_gt_hazardious_mat has 1 entry , pv_gt_odo_det table has 2 entries (2 deliveries) so when its inside this (loop at pv_gt_odo_det)loop it performs all the steps except the atlast statement since its not the last record once its outside the inner loop since there is only one entry in the
pv_gt_hazardious_mat it doesnt even go into the inner loop. So for the haz material the AT last statements are not exceuted at all. Please help me with this problem . Thanks in advance.
* Moving all the Hazardious HU details first if pv_gt_hazardious_mat is not initial. loop at pv_gt_hazardious_mat into ls_hazardious_mat. * Getting the ODO numbers with the hazardious material loop at pv_gt_odo_det into ls_odo_det * where productno = ls_hazardious_mat-matnr. where productid = ls_hazardious_mat-matnr. * Getting the HU details of the ODO * Reading the TOP_HU value from /SCWM/HUREF table read table pv_gt_href_huid into ls_href_huid with key docid = ls_odo_det-docid binary search. if sy-subrc eq 0. * Getting the external HU number from /SCWM/HUHDR table read table pv_gt_docno_hu into ls_docno_hu with key guid_hu = ls_href_huid-top_hu binary search. if sy-subrc eq 0. else. * Getting the external HU number from /SCWM/HUHDR_LOG table read table pv_gt_docno_hu_log into ls_docno_hu with key guid_hu = ls_href_huid-top_hu binary search. if sy-subrc eq 0. endif. endif. endif. *delete table pv_gt_odo_det_tmp with table key huident = ls_docno_hu-huident. delete pv_gt_odo_det_tmp where huident = ls_docno_hu-huident. * Calculating the number of HUs with the same Hazardious material lv_qty = lv_qty + 1. * Moving the HU identification call function 'CONVERSION_EXIT_HUID_OUTPUT' exporting input = ls_docno_hu-huident importing output = ls_docno_hu-huident. concatenate ls_docno_hu-huident ',' ls_hu_det-huident_str into ls_hu_det-huident_str separated by space. * Moving the HU type read table pv_gt_hu_type into ls_hu_type with key hutyp = ls_docno_hu-letyp. if sy-subrc eq 0. ls_hu_det-hu_type = ls_hu_type-hutyptext. endif. * Caliculating the total quantity of the HUs if ls_docno_hu-unit_gw ne gc_lb. * Call the subroutine to convert the value into LB perform sub_convert_to using gc_lb ls_docno_hu-g_weight ls_docno_hu-unit_gw changing lv_weight. lv_weight1 = lv_weight1 + lv_weight. else. lv_weight1 = lv_weight1 + ls_docno_hu-g_weight. endif. clear: ls_docno_hu, ls_href_huid, ls_odo_det, lv_weight. * At the lat of the loop for each material move the HU details at last. ls_hu_det-qty = lv_qty. * Call the subroutine to convert the weight into KG perform sub_convert_to using gc_kg lv_weight1 lv_unit changing lv_weight. * Get the value before decimals lv_weight1_tmp1 = trunc( lv_weight1 ). * Get the fractional value lv_weight1_tmp2 = frac( lv_weight1 ). clear: lv_weight1, lv_weight_tmp. lv_weight1 = lv_weight1_tmp1 + lv_weight1_tmp2. lv_weight_tmp = trunc( lv_weight1 ). clear: lv_weight1_tmp1, lv_weight1_tmp2, lv_weight1. if lv_weight_tmp eq 0. lv_weight_tmp = '1'. endif. ls_hu_det-g_weight_lb = lv_weight_tmp. * Get the value before decimals lv_weight1_tmp1 = trunc( lv_weight ). * Get the fractional value lv_weight1_tmp2 = frac( lv_weight ). clear: lv_weight, lv_weight_tmp. lv_weight = lv_weight1_tmp1 + lv_weight1_tmp2. lv_weight_tmp = trunc( lv_weight ). clear: lv_weight1_tmp1, lv_weight1_tmp2, lv_weight. if lv_weight_tmp eq 0. lv_weight_tmp = '1'. endif. ls_hu_det-g_weight_kg = lv_weight_tmp. ls_hu_det-hm_x = 'X'. * Getting the Commodity description * Getting from /SAPAPO/MATKEY read table pv_gt_commodity_matkey into ls_commodity_matkey with key matnr = ls_hazardious_mat-matnr. ls_hu_det-brgew = ls_commodity_matkey-brgew. ls_hu_det-gewei = ls_commodity_matkey-gewei. * Getting from DGTMD read table pv_gt_commodity_dgtmd into ls_commodity_dgtmd with key actn = ls_hazardious_mat-actn matnr = ls_hazardious_mat-matnr. ls_hu_det-dgnu = ls_commodity_dgtmd-dgnu. ls_hu_det-dgcl = ls_commodity_dgtmd-dgcl. ls_hu_det-dgsc = ls_commodity_dgtmd-dgsc. ls_hu_det-emsn1 = ls_commodity_dgtmd-emsn1. ls_hu_det-pgro = ls_commodity_dgtmd-pgro. if sy-subrc eq 0. * Getting from DGTM2 read table pv_gt_commodity_dgtm2 into ls_commodity_dgtm2 with key recn = ls_commodity_dgtmd-recn actn = ls_commodity_dgtmd-actn. ls_hu_det-pdgnud = ls_commodity_dgtm2-pdgnud. ls_hu_det-pdain1 = ls_commodity_dgtm2-pdain1. ls_hu_det-pdain2 = ls_commodity_dgtm2-pdain2. ls_hu_det-pdain3 = ls_commodity_dgtm2-pdain3. lv_addinf-valdat = sy-datum. if not ls_hu_det-pdgnud is initial. call function '/SEHS/C14X_PHRASE_TEXT_READ' exporting i_addinf = lv_addinf i_value = ls_hu_det-pdgnud+0(21) i_language = sy-langu i_check_mode = 'V' importing e_phrtext = lv_text. ls_hu_det-pdgnud = lv_text+0(40). endif. if not ls_hu_det-pdain1 is initial. call function '/SEHS/C14X_PHRASE_TEXT_READ' exporting i_addinf = lv_addinf i_value = ls_hu_det-pdain1+0(21) i_language = sy-langu i_check_mode = 'V' importing e_phrtext = lv_text. ls_hu_det-pdain1 = lv_text+0(40). endif. if not ls_hu_det-pdain2 is initial. call function '/SEHS/C14X_PHRASE_TEXT_READ' exporting i_addinf = lv_addinf i_value = ls_hu_det-pdain2+0(21) i_language = sy-langu i_check_mode = 'V' importing e_phrtext = lv_text. ls_hu_det-pdain2 = lv_text+0(40). endif. endif. endat. lv_str = strlen( ls_hu_det-huident_str ). lv_str = lv_str - 2. assign ls_hu_det-huident_str to <fs_huident>. replace section offset lv_str length 1 of <fs_huident> with space. append ls_hu_det to pv_gt_hu_det. clear: lv_weight1, lv_weight, lv_qty, ls_hu_det. endloop. endloop. endif.