Skip to content

Instantly share code, notes, and snippets.

@nocubicles
Created October 24, 2016 11:03
Show Gist options
  • Save nocubicles/d497c42df02f5f0e7530ef841b4e24c0 to your computer and use it in GitHub Desktop.
Save nocubicles/d497c42df02f5f0e7530ef841b4e24c0 to your computer and use it in GitHub Desktop.
DATA: it_vttp TYPE STANDARD TABLE OF VTTP WITH HEADER LINE.
SELECT * FROM vttp
INTO TABLE it_vttp
WHERE tknum = u_lv_objky.
TYPES: BEGIN OF ty_cmr_cases,
vbeln TYPE likp-vbeln,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
caseType TYPE i,
pagenr type i,
END OF ty_cmr_cases.
TYPES: BEGIN OF ty_cmr_unique_soldTo,
kunag TYPE likp-kunag,
END OF ty_cmr_unique_soldTo.
TYPES: BEGIN OF ty_cmr_unique_shipTo,
kunnr TYPE likp-kunnr,
END OF ty_cmr_unique_shipTo.
DATA: itt_cmr_cases TYPE TABLE OF ty_cmr_cases WITH HEADER LINE,
wa_cmr_cases LIKE LINE OF itt_cmr_cases.
DATA: t_cmr_unique_soldTo TYPE ty_cmr_unique_soldTo OCCURS 0 WITH HEADER LINE,
wa_cmr_unique_soldTo LIKE LINE OF t_cmr_unique_soldTo.
DATA: t_cmr_unique_shipTo TYPE STANDARD TABLE OF ty_cmr_unique_shipTo,
wa_cmr_unique_shipTo LIKE LINE OF t_cmr_unique_shipTo,
wa_lastSold TYPE i,
wa_index TYPE i.
CLEAR: wa_cmr_cases.
LOOP AT IT_VTTP.
SELECT vbeln kunnr kunag
INTO CORRESPONDING FIELDS OF wa_cmr_cases
FROM likp
WHERE vbeln EQ it_vttp-vbeln.
ENDSELECT.
APPEND wa_cmr_cases TO itt_cmr_cases.
ENDLOOP.
LOOP AT itt_cmr_cases.
MOVE itt_cmr_cases-kunag TO wa_cmr_unique_soldTo-kunag.
MOVE itt_cmr_cases-kunnr TO wa_cmr_unique_shipTo-kunnr.
APPEND wa_cmr_unique_soldTo TO t_cmr_unique_soldTo.
APPEND wa_cmr_unique_shipTo TO t_cmr_unique_shipTo.
ENDLOOP.
SORT t_cmr_unique_shipTo BY kunnr.
SORT t_cmr_unique_soldTo BY kunag.
DELETE ADJACENT DUPLICATES FROM t_cmr_unique_soldTo.
DELETE ADJACENT DUPLICATES FROM t_cmr_unique_shipTo.
DATA: V_TABIX TYPE SYTABIX.
DATA: wa_cmr_ TYPE ty_cmr_cases,
_index TYPE sy-tabix,
wa_cmr__ TYPE ty_cmr_cases.
SORT itt_cmr_cases BY kunag.
LOOP AT t_cmr_unique_soldTo.
READ TABLE itt_cmr_cases WITH KEY kunag = t_cmr_unique_soldTo-kunag.
IF sy-subrc = 0.
_index = sy-tabix.
DO.
IF sy-subrc = 0.
IF itt_cmr_cases-kunag EQ t_cmr_unique_soldTo-kunag AND itt_cmr_cases-kunnr EQ t_cmr_unique_soldTo-kunag.
itt_cmr_cases-casetype = 1.
APPEND itt_cmr_cases.
_index = _index + 1.
READ TABLE itt_cmr_cases INDEX _index.
ELSEIF itt_cmr_cases-kunag EQ t_cmr_unique_soldTo-kunag AND itt_cmr_cases-kunnr NE t_cmr_unique_soldTo-kunag.
itt_cmr_cases-casetype = 2.
APPEND itt_cmr_cases.
_index = _index + 1.
READ TABLE itt_cmr_cases INDEX _index.
ELSE.
EXIT.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
ENDLOOP.
DELETE itt_cmr_cases WHERE caseType = 0. "potential error spot!!!!!!
CLEAR: _index.
_index = 1.
LOOP AT itt_cmr_cases.
WA_CMR_ = itt_cmr_cases.
wa_index = SY-TABIX - 1.
IF sy-tabix EQ 1.
wa_lastSold = wa_cmr_-kunnr.
ELSE.
READ TABLE itt_cmr_cases INDEX wa_index INTO wa_cmr__.
wa_lastSold = wa_cmr__-KUNNR.
ENDIF.
IF ITT_CMR_CASES-KUNNR EQ wa_lastSold.
IF WA_CMR_-KUNNR EQ ITT_CMR_CASES-KUNNR AND ITT_CMR_CASES-CASETYPE EQ 1.
WA_CMR_-PAGENR = _index.
modify ITT_CMR_CASES from WA_CMR_.
CLEAR wa_cmr_.
ELSEIF WA_CMR_-KUNNR EQ ITT_CMR_CASES-KUNNR AND ITT_CMR_CASES-CASETYPE EQ 2.
WA_CMR_-PAGENR = _index.
_index = _index + 1.
modify ITT_CMR_CASES from WA_CMR_.
CLEAR wa_cmr_.
ENDIF.
ELSE.
_index = _index + 1.
IF WA_CMR_-KUNNR EQ ITT_CMR_CASES-KUNNR AND ITT_CMR_CASES-CASETYPE EQ 1.
WA_CMR_-PAGENR = _index.
modify ITT_CMR_CASES from WA_CMR_.
CLEAR wa_cmr_.
ELSEIF WA_CMR_-KUNNR EQ ITT_CMR_CASES-KUNNR AND ITT_CMR_CASES-CASETYPE EQ 2.
WA_CMR_-PAGENR = _index.
modify ITT_CMR_CASES from WA_CMR_.
CLEAR wa_cmr_.
ENDIF.
ENDIF.
ENDLOOP.
APPEND LINES OF itt_cmr_cases TO t_cmr_cases.
*t_cmr_cases = it_cmr_cases.
ENDFORM. "shipment_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment