오전에 일없어서 한번 짜봤네여
주석은 저보기편하게 단거라 이상할수도 있습니다ㅋㅋ
열로 떨어지는 정보 횡으로 이동하여 ALV 생성하는 소스입니다.
도움이 되셨으면 좋겠네요ㅎ
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<style type="text/css">
SPAN {
font-family: "나눔고딕코딩";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-weight: bold;
background: #FFC0CB;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
font-weight: bold;
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}
</style>
REPORT Y_LYS_ASSIGN_COMP.
" MASTER 스트럭쳐 생성
TYPES : BEGIN OF TY_M,
VBELN TYPE VBELN,
END OF TY_M.
DATA: LS_M_STR TYPE TY_M. "마스터 스트럭쳐
DATA: LR_TYPEDESCR TYPE REF TO CL_ABAP_TYPEDESCR, " 스트럭쳐 클래스
LR_STRUCTDESCR TYPE REF TO CL_ABAP_STRUCTDESCR, " 스트럭쳐 상세 속성
LRT_D_TAB TYPE REF TO CL_ABAP_TABLEDESCR, " 동적 테이블
LRS_D_STR TYPE REF TO CL_ABAP_STRUCTDESCR, " 동적 스트럭쳐
LT_COMPONENT TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE, " 스트럭쳐 리스트(테이블구조)
LS_COMPONENT LIKE LINE OF LT_COMPONENT,
LR_DATA TYPE REF TO DATA,
LRS_DATA TYPE REF TO DATA.
DATA: LT_VBAP_M TYPE TABLE OF VBAP,
LS_VBAP_M LIKE LINE OF LT_VBAP_M,
LT_VBAP_I TYPE TABLE OF VBAP,
LS_VBAP_I LIKE LINE OF LT_VBAP_I,
LV_CNT(2) TYPE N,
GV_CNT(2) TYPE N,
LV_FIELD_NM TYPE CHAR30.
DATA: LS_FCAT TYPE LVC_S_FCAT, "필드 카탈로그
LT_FCAT TYPE LVC_T_FCAT. "필드 카탈로그
FIELD-SYMBOLS : <FST_OUTPUT> TYPE TABLE,
<FSS_OUTPUT> TYPE ANY,
<FV_NAME> TYPE ANY,
<FV_VALUE> TYPE ANY.
*-----------------------------------------------------------------------*
" GET 마스터 스트럭쳐
CALL METHOD CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA
EXPORTING
P_DATA = LS_M_STR
RECEIVING
P_DESCR_REF = LR_TYPEDESCR.
CHECK LR_TYPEDESCR IS BOUND.
" 하위 속성 상속
LR_STRUCTDESCR ?= LR_TYPEDESCR.
CHECK LR_STRUCTDESCR IS BOUND.
" 스트럭쳐 리스트
CALL METHOD LR_STRUCTDESCR->GET_COMPONENTS
RECEIVING
P_RESULT = LT_COMPONENT.
REFRESH: LT_VBAP_M, LT_VBAP_I.
SELECT * FROM VBAP
INTO CORRESPONDING FIELDS OF TABLE LT_VBAP_M
WHERE VBELN IN ('0010896340', '0010896339', '0010896447', '0010896443').
CHECK LINES( LT_VBAP_M ) > 0.
SORT LT_VBAP_M BY VBELN MATNR.
LT_VBAP_I[] = LT_VBAP_M[].
DELETE ADJACENT DUPLICATES FROM LT_VBAP_M COMPARING VBELN.
" 출력 테이블 구조로 동적 필드 생성
" 마스터
"""""""""""""""""""""""""""""
" 동적 테이블, 스트럭쳐 구성
"""""""""""""""""""""""""""""
CLEAR: LV_CNT, GV_CNT.
LOOP AT LT_VBAP_M INTO LS_VBAP_M.
" 아이템
CLEAR: LV_CNT, LV_FIELD_NM.
LOOP AT LT_VBAP_I INTO LS_VBAP_I WHERE VBELN EQ LS_VBAP_M-VBELN.
ADD 1 TO LV_CNT.
IF GV_CNT <= LV_CNT.
" 동적 필드명 구성
CONCATENATE 'ARKTX_' LV_CNT INTO LS_COMPONENT-NAME.
" 타입구성
LS_COMPONENT-TYPE = CL_ABAP_ELEMDESCR=>GET_C( 40 ).
APPEND LS_COMPONENT TO LT_COMPONENT.
CLEAR LS_COMPONENT.
ENDIF.
" 필드 MAX값
AT END OF VBELN.
IF GV_CNT < LV_CNT.
GV_CNT = LV_CNT.
ENDIF.
ENDAT.
ENDLOOP.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM LT_COMPONENT COMPARING NAME.
*동적 테이블, 스트럭쳐 생성
CALL METHOD CL_ABAP_STRUCTDESCR=>CREATE
EXPORTING
P_COMPONENTS = LT_COMPONENT
RECEIVING
P_RESULT = LRS_D_STR.
CALL METHOD CL_ABAP_TABLEDESCR=>CREATE
EXPORTING
P_LINE_TYPE = LRS_D_STR
RECEIVING
P_RESULT = LRT_D_TAB.
" TABLE 오브젝트 생성
CREATE DATA LR_DATA TYPE HANDLE LRT_D_TAB.
ASSIGN LR_DATA->* TO <FST_OUTPUT>.
" STR 오브젝트 생성
CREATE DATA LRS_DATA TYPE HANDLE LRS_D_STR.
ASSIGN LRS_DATA->* TO <FSS_OUTPUT>.
CHECK <FST_OUTPUT> IS ASSIGNED.
" DATA 맵핑
REFRESH LT_FCAT.
CLEAR LV_FIELD_NM.
LOOP AT LT_VBAP_M INTO LS_VBAP_M.
" KUNNR 구성
LV_FIELD_NM = 'VBELN'.
ASSIGN LV_FIELD_NM TO <FV_NAME>.
" 필드카타로그
LS_FCAT-FIELDNAME = 'VBELN'.
LS_FCAT-COLTEXT = '오더번호'.
LS_FCAT-COL_OPT = 'X'.
LS_FCAT-COL_POS = 0.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
ASSIGN COMPONENT <FV_NAME> OF STRUCTURE <FSS_OUTPUT> TO <FV_VALUE>.
<FV_VALUE> = LS_VBAP_M-VBELN.
" KUNNR에 따른 유통채널 구성
CLEAR LV_CNT.
LOOP AT LT_VBAP_I INTO LS_VBAP_I WHERE VBELN EQ LS_VBAP_M-VBELN.
ADD 1 TO LV_CNT.
CLEAR LV_FIELD_NM.
CONCATENATE 'ARKTX_' LV_CNT INTO LV_FIELD_NM.
ASSIGN LV_FIELD_NM TO <FV_NAME>.
" 필드카타로그
CONCATENATE 'ARKTX_' LV_CNT INTO LS_FCAT-FIELDNAME.
CONCATENATE '자재_' LV_CNT INTO LS_FCAT-COLTEXT.
LS_FCAT-COL_OPT = 'X'.
LS_FCAT-COL_POS = LV_CNT.
APPEND LS_FCAT TO LT_FCAT.
CLEAR LS_FCAT.
ASSIGN COMPONENT <FV_NAME> OF STRUCTURE <FSS_OUTPUT> TO <FV_VALUE>.
<FV_VALUE> = LS_VBAP_I-ARKTX.
ENDLOOP.
" 출력TABLE APPEND
APPEND <FSS_OUTPUT> TO <FST_OUTPUT>.
ENDLOOP.
SORT LT_FCAT BY FIELDNAME.
DELETE ADJACENT DUPLICATES FROM LT_FCAT COMPARING FIELDNAME.
" CALL ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
IT_FIELDCAT_LVC = LT_FCAT " 필드 카타로그
TABLES
T_OUTTAB = <FST_OUTPUT>.
잘 봤습니다. 감사합니다. ~~