REPORT ZSR_DYNAMIC_RPT1.
TABLES: CEPC, ACDOCA.
DATA: IT_TABLE TYPE TABLE OF ZTABLE,
WA_TABLE TYPE ZTABLE.
TYPES: BEGIN OF TY_DATA,
PRCTR TYPE CEPC-PRCTR,
KOKRS TYPE CEPC-KOKRS,
END OF TY_DATA.
TYPES: BEGIN OF TY_ACDOCA,
RACCT TYPE ACDOCA-RACCT,
PRCTR TYPE ACDOCA-PRCTR,
DRCRK TYPE ACDOCA-DRCRK,
TSL TYPE ACDOCA-TSL,
END OF TY_ACDOCA.
DATA: IT_ACDOCA1 TYPE TABLE OF TY_ACDOCA,
WA_ACDOCA1 TYPE TY_ACDOCA.
TYPES: BEGIN OF TY_ACDOCA2,
RACCT TYPE ACDOCA-RACCT,
PRCTR TYPE ACDOCA-PRCTR,
TSL TYPE ACDOCA-TSL,
END OF TY_ACDOCA2.
DATA: IT_ACDOCA2 TYPE TABLE OF TY_ACDOCA2,
WA_ACDOCA2 TYPE TY_ACDOCA2.
DATA: IT_ACDOCA3 TYPE TABLE OF TY_ACDOCA2,
WA_ACDOCA3 TYPE TY_ACDOCA2.
DATA:
IT_DATA TYPE TABLE OF TY_DATA,
WA_DATA TYPE TY_DATA.
DATA: IT_FCAT TYPE LVC_T_FCAT,
WA_FCAT TYPE LVC_S_FCAT,
LS_LAYO TYPE LVC_S_LAYO.
DATA: LV_LINES TYPE CHAR2,
LV_INDEX TYPE CHAR2.
DATA: LV_POS TYPE I.
DATA: FIELDNAME(20) TYPE C,
FIELDVALUE(60) TYPE C.
FIELD-SYMBOLS : <T_DYNTABLE> TYPE STANDARD TABLE,
<FS_DYNTABLE> TYPE ANY,
<FS_DYT> TYPE ANY,
<FS1> TYPE ANY.
FIELD-SYMBOLS : <T_DATA> TYPE TABLE.
FIELD-SYMBOLS: <FS_FINAL> TYPE ANY.
DATA: T_NEWTABLE TYPE REF TO DATA,
T_NEWLINE TYPE REF TO DATA.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS :
S_KOKRS FOR CEPC-KOKRS OBLIGATORY.",
* S_BUDAT FOR CEPC-ERSDA.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM FETCH_DATA.
PERFORM DISPLAY.
*&---------------------------------------------------------------------*
*& Form Fetch_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FETCH_DATA .
REFRESH IT_DATA[].
SELECT PRCTR, KOKRS FROM CEPC INTO TABLE @IT_DATA
WHERE KOKRS IN @S_KOKRS.
IF SY-SUBRC EQ 0.
SORT IT_DATA ASCENDING BY KOKRS .
DESCRIBE TABLE IT_DATA LINES LV_LINES.
ELSE.
LEAVE LIST-PROCESSING.
ENDIF.
REFRESH IT_TABLE[].
SELECT * FROM ZTABLE INTO TABLE @IT_TABLE.
IF IT_TABLE IS NOT INITIAL.
SORT IT_TABLE BY GLNUMBER.
SELECT RACCT,PRCTR,DRCRK,TSL FROM ACDOCA
INTO TABLE @DATA(IT_ACDOCA)
FOR ALL ENTRIES IN @IT_TABLE
WHERE RBUKRS IN @S_KOKRS
AND RACCT = @IT_TABLE-GLNUMBER.
IF SY-SUBRC EQ 0.
SORT IT_ACDOCA ASCENDING BY RACCT.
LOOP AT IT_ACDOCA INTO DATA(WA_ACDOCA).
IF WA_ACDOCA-DRCRK = 'H'.
COLLECT WA_ACDOCA INTO IT_ACDOCA1 ASSIGNING FIELD-SYMBOL(<LFS>).
CLEAR:WA_ACDOCA.
ELSEIF WA_ACDOCA-DRCRK = 'S'.
COLLECT WA_ACDOCA INTO IT_ACDOCA1 ASSIGNING FIELD-SYMBOL(<LFS1>).
CLEAR:WA_ACDOCA.
ENDIF.
ENDLOOP.
IF IT_ACDOCA1 IS NOT INITIAL.
SORT IT_ACDOCA1 ASCENDING BY RACCT.
DELETE IT_ACDOCA1[] WHERE PRCTR IS INITIAL .
LOOP AT IT_ACDOCA1 INTO WA_ACDOCA1.
MOVE-CORRESPONDING WA_ACDOCA1 TO WA_ACDOCA2 .
COLLECT WA_ACDOCA2 INTO IT_ACDOCA2 .
CLEAR: WA_ACDOCA1,WA_ACDOCA2.
IT_ACDOCA3[] = IT_ACDOCA2[].
ENDLOOP.
ENDIF.
ENDIF.
*********************************
READ TABLE IT_TABLE INTO WA_TABLE INDEX 1.
WA_FCAT-FIELDNAME = 'NAME'.
WA_FCAT-COLTEXT = 'NAME'.
WA_FCAT-OUTPUTLEN = '15'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR:WA_FCAT,WA_TABLE.
LOOP AT IT_ACDOCA2 INTO WA_ACDOCA2.
READ TABLE IT_DATA INTO WA_DATA WITH KEY PRCTR = WA_ACDOCA2-PRCTR.
WA_FCAT-FIELDNAME = WA_DATA-PRCTR.
CONDENSE WA_FCAT-FIELDNAME NO-GAPS.
WA_FCAT-COLTEXT = WA_DATA-PRCTR.
WA_FCAT-OUTPUTLEN = '10'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR:WA_FCAT.
ENDLOOP.
ENDIF.
*****CREATE DYNAMIC INTERNAL TABLE
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FCAT
IMPORTING
EP_TABLE = T_NEWTABLE
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ASSIGN T_NEWTABLE->* TO <T_DYNTABLE>. "Assign field symbol to dynamic internal table.
CREATE DATA T_NEWLINE LIKE LINE OF <T_DYNTABLE>.
ASSIGN T_NEWLINE->* TO <FS_DYNTABLE>. "Assign field symbol to dynamic work area.
LOOP AT IT_TABLE INTO WA_TABLE .
CLEAR:FIELDNAME,FIELDVALUE.
FIELDNAME = 'NAME'.
FIELDVALUE = WA_TABLE-NAME.
CONDENSE FIELDVALUE.
ASSIGN COMPONENT FIELDNAME OF STRUCTURE <FS_DYNTABLE> TO <FS1>.
<FS1> = FIELDVALUE.
* APPEND <FS_DYNTABLE> TO <T_DYNTABLE>.
* CLEAR:WA_TABLE.
* ENDLOOP.
READ TABLE IT_ACDOCA3 INTO WA_ACDOCA3 WITH KEY RACCT = WA_TABLE-GLNUMBER.
READ TABLE IT_DATA INTO WA_DATA WITH KEY PRCTR = WA_ACDOCA3-PRCTR .
IF SY-SUBRC EQ 0.
LOOP AT IT_ACDOCA2 INTO WA_ACDOCA2 WHERE RACCT = WA_TABLE-GLNUMBER ."AND PRCTR = WA_DATA-PRCTR.
CLEAR:FIELDNAME,FIELDVALUE.
FIELDNAME = WA_DATA-PRCTR.
CONDENSE FIELDNAME NO-GAPS.
FIELDVALUE = WA_ACDOCA2-TSL.
CONDENSE FIELDVALUE.
ASSIGN COMPONENT FIELDNAME OF STRUCTURE <FS_DYNTABLE> TO <FS1>.
<FS1> = FIELDVALUE.
APPEND <FS_DYNTABLE> TO <T_DYNTABLE>.
CLEAR: WA_ACDOCA2,FIELDVALUE,FIELDNAME.
CLEAR:<FS_DYNTABLE>.
ENDLOOP.
ELSE.
APPEND <FS_DYNTABLE> TO <T_DYNTABLE>.
ENDIF.
CLEAR:WA_DATA,WA_TABLE.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM DISPLAY .
LS_LAYO-ZEBRA = 'X'.
LS_LAYO-COL_OPT ='X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = 'SY-REPID'
IS_LAYOUT_LVC = LS_LAYO
IT_FIELDCAT_LVC = IT_FCAT[]
I_DEFAULT = 'X'
I_SAVE = 'A'
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = <T_DYNTABLE>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
No comments:
Post a Comment