2008 Nov 21 3:15 PM
Hi abappers,
I want fill the ALV with the data of my table internal TAB2:
LOOP AT TAB1.
MOVE TAB1-CAMPO+2(9) TO STCD1_OLD.
MOVE TAB1-CAMPO+11(9) TO STCD1_NEW.
SELECT SINGLE * FROM KNA1 WHERE STCD1 EQ STCD1_OLD.
IF SY-SUBRC = 0.
MOVE KNA1-KUNNR TO TAB2-KUNNR.
MOVE KNA1-KTOKD TO TAB2-KTOKD.
MOVE KNA1-LAND1 TO TAB2-LAND1.
MOVE KNA1-NAME1 TO TAB2-NAME1.
MOVE KNA1-STCD1 TO TAB2-STCD1_OLD.
MOVE STCD1_NEW TO TAB2-STCD1_NEW.
MOVE KNA1-STCEG TO TAB2-STCEG.
MOVE KNA1-STCD4 TO TAB2-STCD4.
MOVE KNA1-YYCTC TO TAB2-YYCTC.
MOVE KNA1-AUFSD TO TAB2-AUFSD.
MOVE KNA1-CASSD TO TAB2-CASSD.
MOVE KNA1-LOEVM TO TAB2-LOEVM.
MOVE KNA1-SPERR TO TAB2-SPERR.
MOVE KNA1-SPERZ TO TAB2-SPERZ.
APPEND TAB2.
ELSE.
WRITE: / TEXT-100, STCD1_OLD.
ENDIF.
ENDLOOP.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'XXXXXXXX'
CHANGING it_outtab = TAB2[].
But when I want call method, I don´t know the structure, and I can not pass the structure fo KNA1, because 2 fields are different STCD1_OLD and STCD1_NEW.
Can you help me, please?
Cordial greetings.
2008 Nov 21 3:21 PM
Then you will not use the structure parameter, instead fill a field catalog and pass that. Here is an example.
REPORT ZRICH_0001.
TABLES: MARA.
DATA: BEGIN OF I_ALV OCCURS 0,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
END OF I_ALV.
DATA: ALV_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: FIELDCAT TYPE LVC_T_FCAT.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_DATA.
CALL SCREEN 100.
************************************************************************
* Module status_0100 OUTPUT
************************************************************************
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS '0100'.
SET TITLEBAR '0100'.
* Create Controls
CREATE OBJECT ALV_CONTAINER
EXPORTING
CONTAINER_NAME = 'ALV_CONTAINER'.
CREATE OBJECT ALV_GRID
EXPORTING
I_PARENT = ALV_CONTAINER.
* ALV Specific. Data selection.
* Populate Field Catalog
PERFORM GET_FIELDCATALOG.
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB = I_ALV[]
IT_FIELDCATALOG = FIELDCAT[].
ENDMODULE.
************************************************************************
* Module USER_COMMAND_0100 INPUT
************************************************************************
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK' OR 'CANC'.
IF NOT ALV_CONTAINER IS INITIAL.
CALL METHOD ALV_CONTAINER->FREE.
CLEAR: ALV_CONTAINER.
FREE : ALV_CONTAINER.
ENDIF.
IF SY-SUBRC = 0.
SET SCREEN 0.
LEAVE SCREEN.
ELSE.
LEAVE PROGRAM.
ENDIF.
WHEN 'EXIT'.
IF NOT ALV_CONTAINER IS INITIAL.
CALL METHOD ALV_CONTAINER->FREE.
CLEAR: ALV_CONTAINER.
FREE : ALV_CONTAINER.
ENDIF.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
************************************************************************
* FORM GET_DATA
************************************************************************
FORM GET_DATA.
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_ALV
FROM MARA
INNER JOIN MAKT
ON MARA~MATNR = MAKT~MATNR
WHERE MARA~MATNR IN S_MATNR
AND MAKT~SPRAS = SY-LANGU.
SORT I_ALV ASCENDING BY MATNR.
ENDFORM.
************************************************************************
* Form Get_Fieldcatalog - Set Up Columns/Headers
************************************************************************
FORM GET_FIELDCATALOG.
DATA: LS_FCAT TYPE LVC_S_FCAT.
REFRESH: FIELDCAT.
CLEAR: LS_FCAT.
LS_FCAT-REPTEXT = 'Material Number'.
LS_FCAT-COLTEXT = 'Material Number'.
LS_FCAT-FIELDNAME = 'MATNR'.
LS_FCAT-REF_TABLE = 'I_ALV'.
LS_FCAT-OUTPUTLEN = '18'.
LS_FCAT-COL_POS = 1.
APPEND LS_FCAT TO FIELDCAT.
CLEAR: LS_FCAT.
LS_FCAT-REPTEXT = 'Material Description'.
LS_FCAT-COLTEXT = 'Material Description'.
LS_FCAT-FIELDNAME = 'MAKTX'.
LS_FCAT-REF_TABLE = 'I_ALV'.
LS_FCAT-OUTPUTLEN = '40'.
LS_FCAT-COL_POS = 2.
APPEND LS_FCAT TO FIELDCAT.
ENDFORM.
Regards,
Rich Heilman
2008 Nov 21 5:21 PM